Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DPE-4808] Update integration tests #92

Merged
merged 9 commits into from
Jul 4, 2024
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ jobs:
tox-environments:
- integration-charm
- integration-password
- integration-redis-relation
# Skipping until issues in `discourse-k8s-operator` are resolved. Issue:
# "https://github.com/canonical/discourse-k8s-operator/issues/268"
# - integration-redis-relation
name: ${{ matrix.tox-environments }}
needs:
- lint
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Upload charm to charmhub
uses: canonical/charming-actions/[email protected]
with:
resource-overrides: "redis-image:4"
resource-overrides: "redis-image:5"
credentials: "${{ secrets.CHARMHUB_TOKEN }}"
github-token: "${{ secrets.GITHUB_TOKEN }}"
channel: "${{ steps.channel.outputs.name }}"
66 changes: 14 additions & 52 deletions tests/integration/test_redis_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
check_application_status,
get_address,
get_unit_map,
get_unit_number,
query_url,
)

FIRST_DISCOURSE_APP_NAME = "discourse-k8s"
SECOND_DISCOURSE_APP_NAME = "discourse-charmers-discourse-k8s"
DISCOURSE_APP_NAME = "discourse-k8s"
POSTGRESQL_APP_NAME = "postgresql-k8s"

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -59,7 +57,10 @@ async def test_build_and_deploy(ops_test: OpsTest, num_units: int):
series="focal",
),
ops_test.model.deploy(
FIRST_DISCOURSE_APP_NAME, application_name=FIRST_DISCOURSE_APP_NAME, series="focal"
DISCOURSE_APP_NAME,
application_name=DISCOURSE_APP_NAME,
series="focal",
channel="latest/stable",
),
ops_test.model.deploy(
POSTGRESQL_APP_NAME,
Expand All @@ -74,12 +75,10 @@ async def test_build_and_deploy(ops_test: OpsTest, num_units: int):
)
# Discourse becomes blocked waiting for relations.
await ops_test.model.wait_for_idle(
apps=[FIRST_DISCOURSE_APP_NAME], status="waiting", idle_period=20, timeout=3000
apps=[DISCOURSE_APP_NAME], status="waiting", idle_period=20, timeout=3000
)

assert (
ops_test.model.applications[FIRST_DISCOURSE_APP_NAME].units[0].workload_status == "waiting"
)
assert ops_test.model.applications[DISCOURSE_APP_NAME].units[0].workload_status == "waiting"
assert ops_test.model.applications[POSTGRESQL_APP_NAME].units[0].workload_status == "active"


Expand All @@ -88,22 +87,22 @@ async def test_discourse_relation(ops_test: OpsTest):
# Test the first Discourse charm.
# Add both relations to Discourse (PostgreSQL and Redis)
# and wait for it to be ready.
await ops_test.model.relate(f"{POSTGRESQL_APP_NAME}:database", FIRST_DISCOURSE_APP_NAME)
await ops_test.model.relate(f"{POSTGRESQL_APP_NAME}:database", DISCOURSE_APP_NAME)
# Wait until discourse handles all relation events related to postgresql
await ops_test.model.relate(APP_NAME, FIRST_DISCOURSE_APP_NAME)
await ops_test.model.relate(APP_NAME, DISCOURSE_APP_NAME)

# This won't work: model.applications[app_name].units[0].workload_status returns wrong status
"""
await ops_test.model.wait_for_idle(
apps=[APP_NAME, FIRST_DISCOURSE_APP_NAME, POSTGRESQL_APP_NAME],
apps=[APP_NAME, DISCOURSE_APP_NAME, POSTGRESQL_APP_NAME],
status="active",
idle_period=30,
timeout=3000, # Discourse takes a longer time to become active (a lot of setup).
)
"""

await ops_test.model.block_until(
lambda: check_application_status(ops_test, FIRST_DISCOURSE_APP_NAME) == "active",
lambda: check_application_status(ops_test, DISCOURSE_APP_NAME) == "active",
timeout=900,
wait_period=5,
)
Expand All @@ -116,7 +115,7 @@ async def test_discourse_relation(ops_test: OpsTest):

async def test_discourse_request(ops_test: OpsTest):
"""Try to connect to discourse after the bundle is deployed."""
discourse_ip = await get_address(ops_test, app_name=FIRST_DISCOURSE_APP_NAME)
discourse_ip = await get_address(ops_test, app_name=DISCOURSE_APP_NAME)
url = f"http://{discourse_ip}:3000/site.json"
response = query_url(url)

Expand All @@ -141,52 +140,15 @@ async def test_delete_redis_pod(ops_test: OpsTest):
apps=[APP_NAME], status="active", timeout=1000, idle_period=60
)
await ops_test.model.block_until(
lambda: check_application_status(ops_test, FIRST_DISCOURSE_APP_NAME) == "active",
lambda: check_application_status(ops_test, DISCOURSE_APP_NAME) == "active",
timeout=1200,
wait_period=5,
)

redis_ip_after = await get_address(ops_test, app_name=APP_NAME, unit_num=leader_unit_num)
discourse_ip = await get_address(ops_test, app_name=FIRST_DISCOURSE_APP_NAME)
discourse_ip = await get_address(ops_test, app_name=DISCOURSE_APP_NAME)
url = f"http://{discourse_ip}:3000/site.json"
response = query_url(url)

assert redis_ip_before != redis_ip_after
assert response.status == 200


async def test_discourse_from_discourse_charmers(ops_test: OpsTest):
"""Test the second Discourse charm."""
unit_map = await get_unit_map(ops_test)

# Get the Redis instance IP address.
redis_host = await get_address(ops_test, unit_num=get_unit_number(unit_map["leader"]))

# Deploy Discourse and wait for it to be blocked waiting for database relation.
await ops_test.model.deploy(
SECOND_DISCOURSE_APP_NAME,
application_name=SECOND_DISCOURSE_APP_NAME,
config={
"redis_host": redis_host,
"developer_emails": "[email protected]",
"external_hostname": "foo.internal",
"smtp_address": "127.0.0.1",
"smtp_domain": "foo.internal",
},
series="focal",
)
# Discourse becomes blocked waiting for PostgreSQL relation.
await ops_test.model.wait_for_idle(
apps=[SECOND_DISCOURSE_APP_NAME], status="blocked", timeout=3000
)

# Relate PostgreSQL and Discourse, waiting for Discourse to be ready.
await ops_test.model.add_relation(
f"{POSTGRESQL_APP_NAME}:db-admin",
SECOND_DISCOURSE_APP_NAME,
)
await ops_test.model.wait_for_idle(
apps=[POSTGRESQL_APP_NAME, SECOND_DISCOURSE_APP_NAME, APP_NAME],
status="active",
timeout=3000, # Discourse takes a longer time to become active (a lot of setup).
)
Loading