Skip to content

Commit

Permalink
Check user existence after relation broken for db and db-admin in…
Browse files Browse the repository at this point in the history
…terfaces (#425)

* Check user existence after relation broken for `db` and `db-admin` interfaces

* Add remove relation and validate users existence before removing application

* fix lint
  • Loading branch information
TakoB222 authored Mar 22, 2024
1 parent 1668283 commit 40d8796
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
22 changes: 15 additions & 7 deletions tests/integration/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,27 @@ async def test_finos_waltz_db(ops_test: OpsTest) -> None:
ops_test, finos_waltz_users + another_finos_waltz_users, []
)

# Scale down the second deployment of Finos Waltz and confirm that the first deployment
# is still active.
await ops_test.model.remove_application(
ANOTHER_FINOS_WALTZ_APP_NAME, block_until_done=True
# Remove second relation and validate that related users were deleted
await ops_test.model.applications[DATABASE_APP_NAME].remove_relation(
f"{DATABASE_APP_NAME}:db", f"{ANOTHER_FINOS_WALTZ_APP_NAME}"
)

another_finos_waltz_users = []
await ops_test.model.wait_for_idle(apps=[DATABASE_APP_NAME], status="active", timeout=1000)
await check_database_users_existence(
ops_test, finos_waltz_users, another_finos_waltz_users
)

# Remove the first deployment of Finos Waltz.
# Remove first relation and validate that related users were deleted
await ops_test.model.applications[DATABASE_APP_NAME].remove_relation(
f"{DATABASE_APP_NAME}:db", f"{FINOS_WALTZ_APP_NAME}"
)
await ops_test.model.wait_for_idle(apps=[DATABASE_APP_NAME], status="active", timeout=1000)
await check_database_users_existence(ops_test, [], finos_waltz_users)

# Remove the first and second deployment of Finos Waltz.
await ops_test.model.remove_application(FINOS_WALTZ_APP_NAME, block_until_done=True)
await ops_test.model.remove_application(
ANOTHER_FINOS_WALTZ_APP_NAME, block_until_done=True
)


@pytest.mark.group(1)
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/test_db_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,13 @@ async def test_discourse_from_discourse_charmers(ops_test: OpsTest):
await check_database_creation(ops_test, "discourse-charmers-discourse-k8s")
discourse_users = [f"relation_id_{relation.id}"]
await check_database_users_existence(ops_test, discourse_users, [], admin=True)

# Remove Discourse relation and validate that related users were deleted
await ops_test.model.applications[DATABASE_APP_NAME].remove_relation(
f"{DATABASE_APP_NAME}:db-admin", f"{DISCOURSE_APP_NAME}"
)
await ops_test.model.wait_for_idle(apps=[DATABASE_APP_NAME], status="active", timeout=1000)
await check_database_users_existence(ops_test, [], discourse_users)

# Remove the deployment of Discourse.
await ops_test.model.remove_application(DISCOURSE_APP_NAME, block_until_done=True)

0 comments on commit 40d8796

Please sign in to comment.