Skip to content

Commit

Permalink
[MISC] Integration test tweaks (#405)
Browse files Browse the repository at this point in the history
* Remove skipped legacy tests

* Scale down one by one in the legacy test

* Scale down one by one
  • Loading branch information
dragomirp authored Mar 20, 2024
1 parent ee79b52 commit d80ab65
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 75 deletions.
40 changes: 37 additions & 3 deletions tests/integration/new_relations/test_new_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import yaml
from pytest_operator.plugin import OpsTest

from ..helpers import CHARM_SERIES, assert_sync_standbys, scale_application
from ..helpers import CHARM_SERIES, assert_sync_standbys, get_leader_unit, scale_application
from ..juju_ import juju_major_version
from .helpers import (
build_connection_string,
Expand Down Expand Up @@ -362,9 +362,16 @@ async def test_relation_data_is_updated_correctly_when_scaling(ops_test: OpsTest
)

# Remove the original units.
await ops_test.model.applications[DATABASE_APP_NAME].destroy_units(*units_to_remove)
leader_unit = await get_leader_unit(ops_test, DATABASE_APP_NAME)
await ops_test.model.applications[DATABASE_APP_NAME].destroy_units(*[
unit for unit in units_to_remove if unit != leader_unit.name
])
await ops_test.model.wait_for_idle(
apps=[DATABASE_APP_NAME], status="active", timeout=1500, wait_for_exact_units=2
apps=[DATABASE_APP_NAME], status="active", timeout=600, wait_for_exact_units=3
)
await ops_test.model.applications[DATABASE_APP_NAME].destroy_units(leader_unit.name)
await ops_test.model.wait_for_idle(
apps=[DATABASE_APP_NAME], status="active", timeout=600, wait_for_exact_units=2
)

# Get the updated connection data and assert it can be used
Expand Down Expand Up @@ -573,3 +580,30 @@ async def test_invalid_extra_user_roles(ops_test: OpsTest):
raise_on_blocked=False,
timeout=1000,
)


@pytest.mark.group(1)
async def test_nextcloud_db_blocked(ops_test: OpsTest, charm: str) -> None:
async with ops_test.fast_forward():
# Deploy Nextcloud.
await ops_test.model.deploy(
"nextcloud",
channel="edge",
application_name="nextcloud",
num_units=1,
)
await ops_test.model.wait_for_idle(
apps=["nextcloud"],
status="blocked",
raise_on_blocked=False,
timeout=1000,
)

await ops_test.model.relate("nextcloud:database", f"{DATABASE_APP_NAME}:database")

await ops_test.model.wait_for_idle(
apps=[DATABASE_APP_NAME, "nextcloud"],
status="active",
raise_on_blocked=False,
timeout=1000,
)
81 changes: 9 additions & 72 deletions tests/integration/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,16 @@ async def test_relation_data_is_updated_correctly_when_scaling(ops_test: OpsTest
)

# Remove the original units.
await ops_test.model.applications[DATABASE_APP_NAME].destroy_units(*units_to_remove)
leader_unit = await get_leader_unit(ops_test, DATABASE_APP_NAME)
await ops_test.model.applications[DATABASE_APP_NAME].destroy_units(*[
unit for unit in units_to_remove if unit != leader_unit.name
])
await ops_test.model.wait_for_idle(
apps=[DATABASE_APP_NAME], status="active", timeout=1500, wait_for_exact_units=2
apps=[DATABASE_APP_NAME], status="active", timeout=600, wait_for_exact_units=3
)
await ops_test.model.applications[DATABASE_APP_NAME].destroy_units(leader_unit.name)
await ops_test.model.wait_for_idle(
apps=[DATABASE_APP_NAME], status="active", timeout=600, wait_for_exact_units=2
)

# Get the updated connection data and assert it can be used
Expand Down Expand Up @@ -185,48 +192,6 @@ async def test_relation_data_is_updated_correctly_when_scaling(ops_test: OpsTest
psycopg2.connect(primary_connection_string)


@pytest.mark.group(1)
@pytest.mark.skip(reason="Should be ported and moved to the new relation tests")
async def test_nextcloud_db_blocked(ops_test: OpsTest, charm: str) -> None:
async with ops_test.fast_forward():
# Deploy Nextcloud.
await ops_test.model.deploy(
"nextcloud",
channel="edge",
application_name="nextcloud",
num_units=APPLICATION_UNITS,
)
await ops_test.model.wait_for_idle(
apps=["nextcloud"],
status="blocked",
raise_on_blocked=False,
timeout=1000,
)

await ops_test.model.relate("nextcloud:db", f"{DATABASE_APP_NAME}:db")

# Only the leader will block
leader_unit = await find_unit(ops_test, DATABASE_APP_NAME, True)

try:
await ops_test.model.wait_for_idle(
apps=[DATABASE_APP_NAME],
status="blocked",
raise_on_blocked=True,
timeout=1000,
)
assert False, "Leader didn't block"
except JujuUnitError:
pass

assert (
leader_unit.workload_status_message
== "extensions requested through relation, enable them through config options"
)

await ops_test.model.remove_application("nextcloud", block_until_done=True)


@pytest.mark.group(1)
async def test_sentry_db_blocked(ops_test: OpsTest, charm: str) -> None:
async with ops_test.fast_forward():
Expand Down Expand Up @@ -365,34 +330,6 @@ async def test_roles_blocking(ops_test: OpsTest, charm: str) -> None:
)


@pytest.mark.group(1)
@pytest.mark.unstable
async def test_weebl_db(ops_test: OpsTest, charm: str) -> None:
async with ops_test.fast_forward():
await ops_test.model.deploy(
"weebl",
application_name="weebl",
num_units=APPLICATION_UNITS,
)
await ops_test.model.wait_for_idle(
apps=["weebl"],
status="blocked",
raise_on_blocked=False,
timeout=1000,
)

await ops_test.model.relate("weebl:database", f"{DATABASE_APP_NAME}:db")

await ops_test.model.wait_for_idle(
apps=["weebl", DATABASE_APP_NAME],
status="active",
raise_on_blocked=False,
timeout=1000,
)

await ops_test.model.remove_application("weebl", block_until_done=True)


@markers.juju2
@pytest.mark.group(1)
async def test_canonical_livepatch_onprem_bundle_db(ops_test: OpsTest) -> None:
Expand Down

0 comments on commit d80ab65

Please sign in to comment.