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-2780] Tests for unpermitted config server rels #296

Merged
merged 9 commits into from
Nov 3, 2023
72 changes: 38 additions & 34 deletions tests/integration/sharding_tests/test_sharding_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
APP_CHARM_NAME = "application"
LEGACY_APP_CHARM_NAME = "legacy-application"

SHARDING_COMPONENTS = [SHARD_ONE_APP_NAME, CONFIG_SERVER_ONE_APP_NAME]

CONFIG_SERVER_REL_NAME = "config-server"
SHARD_REL_NAME = "sharding"
DATABASE_REL_NAME = "first-database"
Expand Down Expand Up @@ -75,65 +77,67 @@ async def test_only_one_config_server_relation(ops_test: OpsTest) -> None:


async def test_cannot_use_db_relation(ops_test: OpsTest) -> None:
"""Verify that a shard cannot use the DB relation."""
await ops_test.model.integrate(
f"{APP_CHARM_NAME}:{DATABASE_REL_NAME}",
SHARD_ONE_APP_NAME,
)
"""Verify that sharding components cannot use the DB relation."""
for sharded_component in SHARDING_COMPONENTS:
await ops_test.model.integrate(f"{APP_CHARM_NAME}:{DATABASE_REL_NAME}", sharded_component)

await ops_test.model.wait_for_idle(
apps=[SHARD_ONE_APP_NAME],
apps=SHARDING_COMPONENTS,
idle_period=20,
raise_on_blocked=False,
timeout=TIMEOUT,
)

shard_unit = ops_test.model.applications[SHARD_ONE_APP_NAME].units[0]
assert (
shard_unit.workload_status_message == "Sharding roles do not support database interface."
), "Shard cannot be related using the database relation"

# clean up relation
await ops_test.model.applications[SHARD_ONE_APP_NAME].remove_relation(
f"{APP_CHARM_NAME}:{DATABASE_REL_NAME}",
SHARD_ONE_APP_NAME,
)
for sharded_component in SHARDING_COMPONENTS:
sharded_component_unit = ops_test.model.applications[sharded_component].units[0]
assert (
sharded_component_unit.workload_status_message
== "Sharding roles do not support database interface."
), f"{sharded_component} cannot be related using the database relation"

# clean up relations
for sharded_component in SHARDING_COMPONENTS:
await ops_test.model.applications[sharded_component].remove_relation(
f"{APP_CHARM_NAME}:{DATABASE_REL_NAME}",
sharded_component,
)

await ops_test.model.wait_for_idle(
apps=[SHARD_ONE_APP_NAME],
apps=SHARDING_COMPONENTS,
idle_period=20,
raise_on_blocked=False,
timeout=TIMEOUT,
)


async def test_cannot_use_legacy_db_relation(ops_test: OpsTest) -> None:
"""Verify that a shard cannot use the legcy DB relation."""
await ops_test.model.integrate(
LEGACY_APP_CHARM_NAME,
SHARD_ONE_APP_NAME,
)
"""Verify that sharding components cannot use the legacy DB relation."""
for sharded_component in SHARDING_COMPONENTS:
await ops_test.model.integrate(LEGACY_APP_CHARM_NAME, sharded_component)

await ops_test.model.wait_for_idle(
apps=[SHARD_ONE_APP_NAME],
apps=SHARDING_COMPONENTS,
idle_period=20,
raise_on_blocked=False,
timeout=TIMEOUT,
)

shard_unit = ops_test.model.applications[SHARD_ONE_APP_NAME].units[0]
assert (
shard_unit.workload_status_message == "Sharding roles do not support obsolete interface."
), "Shard cannot be related using the mongodb relation"

# clean up relation
await ops_test.model.applications[SHARD_ONE_APP_NAME].remove_relation(
f"{SHARD_ONE_APP_NAME}:{LEGACY_RELATION_NAME}",
f"{LEGACY_APP_CHARM_NAME}:{LEGACY_RELATION_NAME}",
)
for sharded_component in SHARDING_COMPONENTS:
sharded_component_unit = ops_test.model.applications[sharded_component].units[0]
assert (
sharded_component_unit.workload_status_message
== "Sharding roles do not support obsolete interface."
), f"{sharded_component} cannot be related using the mongodb relation"

# clean up relations
for sharded_component in SHARDING_COMPONENTS:
await ops_test.model.applications[sharded_component].remove_relation(
f"{sharded_component}:{LEGACY_RELATION_NAME}",
f"{LEGACY_APP_CHARM_NAME}:{LEGACY_RELATION_NAME}",
)

await ops_test.model.wait_for_idle(
apps=[SHARD_ONE_APP_NAME],
apps=SHARDING_COMPONENTS,
idle_period=20,
raise_on_blocked=False,
timeout=TIMEOUT,
Expand Down
Loading