Skip to content

Commit

Permalink
Update tests to make them work on juju 3
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-ratushnyy committed Sep 8, 2023
1 parent 0a67844 commit 377ec57
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions tests/integration/ha_tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ async def reused_storage(ops_test: OpsTest, unit_name, removal_time) -> bool:
If member transitions to STARTUP2 from REMOVED then it is re-using the storage we
provided.
"""
cat_cmd = f"run --unit {unit_name} -- cat {MONGODB_LOG_PATH}"
cat_cmd = f"exec --unit {unit_name} -- cat {MONGODB_LOG_PATH}"
return_code, output, _ = await ops_test.juju(*cat_cmd.split())

if return_code != 0:
Expand Down Expand Up @@ -521,7 +521,7 @@ async def db_step_down(ops_test: OpsTest, old_primary_unit: str, sigterm_time: i
app = await app_name(ops_test)
for unit in ops_test.model.applications[app].units:
# verify log file exists on this machine
search_file = f"run --unit {unit.name} ls {MONGODB_LOG_PATH}"
search_file = f"exec --unit {unit.name} ls {MONGODB_LOG_PATH}"
return_code, _, _ = await ops_test.juju(*search_file.split())
if return_code == 2:
continue
Expand Down Expand Up @@ -559,7 +559,7 @@ async def all_db_processes_down(ops_test: OpsTest) -> bool:
for attempt in Retrying(stop=stop_after_attempt(60), wait=wait_fixed(3)):
with attempt:
for unit in ops_test.model.applications[app].units:
search_db_process = f"run --unit {unit.name} pgrep -x mongod"
search_db_process = f"exec --unit {unit.name} pgrep -x mongod"
_, processes, _ = await ops_test.juju(*search_db_process.split())
# splitting processes by "\n" results in one or more empty lines, hence we
# need to process these lines accordingly.
Expand Down Expand Up @@ -593,7 +593,7 @@ async def update_restart_delay(ops_test: OpsTest, unit, delay: int):
# MONGOD_SERVICE_DEFAULT_PATH since this directory has strict permissions, instead we scp it
# elsewhere and then move it to MONGOD_SERVICE_DEFAULT_PATH.
await unit.scp_to(source=TMP_SERVICE_PATH, destination="mongod.service")
mv_cmd = f"run --unit {unit.name} mv /home/ubuntu/mongod.service {MONGOD_SERVICE_DEFAULT_PATH}"
mv_cmd = f"exec --unit {unit.name} mv /home/ubuntu/mongod.service {MONGOD_SERVICE_DEFAULT_PATH}"
return_code, _, _ = await ops_test.juju(*mv_cmd.split())
if return_code != 0:
raise ProcessError(f"Command: {mv_cmd} failed on unit: {unit.name}.")
Expand All @@ -602,7 +602,7 @@ async def update_restart_delay(ops_test: OpsTest, unit, delay: int):
subprocess.call(["rm", TMP_SERVICE_PATH])

# reload the daemon for systemd otherwise changes are not saved
reload_cmd = f"run --unit {unit.name} systemctl daemon-reload"
reload_cmd = f"exec --unit {unit.name} systemctl daemon-reload"
return_code, _, _ = await ops_test.juju(*reload_cmd.split())
if return_code != 0:
raise ProcessError(f"Command: {reload_cmd} failed on unit: {unit.name}.")
Expand Down Expand Up @@ -634,7 +634,7 @@ async def update_service_logging(ops_test: OpsTest, unit, logging: bool):
# MONGOD_SERVICE_DEFAULT_PATH since this directory has strict permissions, instead we scp it
# elsewhere and then move it to MONGOD_SERVICE_DEFAULT_PATH.
await unit.scp_to(source=TMP_SERVICE_PATH, destination="mongod.service")
mv_cmd = f"run --unit {unit.name} mv /home/ubuntu/mongod.service {MONGOD_SERVICE_DEFAULT_PATH}"
mv_cmd = f"exec --unit {unit.name} mv /home/ubuntu/mongod.service {MONGOD_SERVICE_DEFAULT_PATH}"
return_code, _, _ = await ops_test.juju(*mv_cmd.split())
if return_code != 0:
raise ProcessError(f"Command: {mv_cmd} failed on unit: {unit.name}.")
Expand All @@ -643,21 +643,21 @@ async def update_service_logging(ops_test: OpsTest, unit, logging: bool):
subprocess.call(["rm", TMP_SERVICE_PATH])

# reload the daemon for systemd otherwise changes are not saved
reload_cmd = f"run --unit {unit.name} systemctl daemon-reload"
reload_cmd = f"exec --unit {unit.name} systemctl daemon-reload"
return_code, _, _ = await ops_test.juju(*reload_cmd.split())
if return_code != 0:
raise ProcessError(f"Command: {reload_cmd} failed on unit: {unit.name}.")


async def stop_mongod(ops_test: OpsTest, unit) -> None:
"""Safely stops the mongod process."""
stop_db_process = f"run --unit {unit.name} snap stop charmed-mongodb.mongod"
stop_db_process = f"exec --unit {unit.name} snap stop charmed-mongodb.mongod"
await ops_test.juju(*stop_db_process.split())


async def start_mongod(ops_test: OpsTest, unit) -> None:
"""Safely starts the mongod process."""
start_db_process = f"run --unit {unit.name} snap start charmed-mongodb.mongod"
start_db_process = f"exec --unit {unit.name} snap start charmed-mongodb.mongod"
await ops_test.juju(*start_db_process.split())


Expand Down
2 changes: 1 addition & 1 deletion tests/integration/ha_tests/test_ha.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def change_logging(ops_test: OpsTest):
time.sleep(15)

# remove the log file as to not clog up space on the replicas.
rm_cmd = f"run --unit {unit.name} rm {helpers.MONGODB_LOG_PATH}"
rm_cmd = f"exec --unit {unit.name} rm {helpers.MONGODB_LOG_PATH}"
await ops_test.juju(*rm_cmd.split())


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ async def check_tls(ops_test: OpsTest, unit: ops.model.Unit, enabled: bool) -> b
):
with attempt:
mongod_tls_check = await mongo_tls_command(ops_test)
check_tls_cmd = f"run --unit {unit.name} -- {mongod_tls_check}"
check_tls_cmd = f"exec --unit {unit.name} -- {mongod_tls_check}"
return_code, _, _ = await ops_test.juju(*check_tls_cmd.split())
tls_enabled = return_code == 0
if enabled != tls_enabled:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async def test_add_unit_joins_without_auth(ops_test: OpsTest):
"""Verify scaling mongodb with legacy relations supports no auth."""
await ops_test.model.applications[DATABASE_APP_NAME].add_unit(count=1)
await ops_test.model.wait_for_idle(
apps=[DATABASE_APP_NAME], status="active", timeout=1000, wait_for_units=3
apps=[DATABASE_APP_NAME], status="active", timeout=1000, wait_for_exact_units=3
)

# verify auth is still disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def test_deploy_charms(ops_test: OpsTest, application_charm, database_char
application_name=ANOTHER_DATABASE_APP_NAME,
),
)
await ops_test.model.wait_for_idle(apps=APP_NAMES, status="active", wait_for_units=1)
await ops_test.model.wait_for_idle(apps=APP_NAMES, status="active", wait_for_at_least_units=1)


@pytest.mark.abort_on_fail
Expand Down

0 comments on commit 377ec57

Please sign in to comment.