diff --git a/tests/conftests.py b/tests/conftest.py similarity index 100% rename from tests/conftests.py rename to tests/conftest.py diff --git a/tests/integration/ha_tests/helpers.py b/tests/integration/ha_tests/helpers.py index f382088f8..e382dd6d4 100644 --- a/tests/integration/ha_tests/helpers.py +++ b/tests/integration/ha_tests/helpers.py @@ -1,6 +1,7 @@ # Copyright 2023 Canonical Ltd. # See LICENSE file for licensing details. +from importlib.metadata import version import json import subprocess import time @@ -487,8 +488,11 @@ async def kill_unit_process(ops_test: OpsTest, unit_name: str, kill_code: str): if len(ops_test.model.applications[app].units) < 2: await ops_test.model.applications[app].add_unit(count=1) await ops_test.model.wait_for_idle(apps=[app], status="active", timeout=1000) - - kill_cmd = f"run --unit {unit_name} -- pkill --signal {kill_code} -f {DB_PROCESS}" + if version("juju") < "3": + kill_cmd = f"run --unit {unit_name} -- pkill --signal {kill_code} -f {DB_PROCESS}" + else: + kill_cmd = f"exec --unit {unit_name} -- pkill --signal {kill_code} -f {DB_PROCESS}" + return_code, _, _ = await ops_test.juju(*kill_cmd.split()) if return_code != 0: diff --git a/tests/integration/test_charm.py b/tests/integration/test_charm.py index e3b17674f..06442927a 100644 --- a/tests/integration/test_charm.py +++ b/tests/integration/test_charm.py @@ -2,6 +2,7 @@ # Copyright 2023 Canonical Ltd. # See LICENSE file for licensing details. +from importlib.metadata import version import json import logging import os @@ -170,8 +171,8 @@ async def test_set_password_action(ops_test: OpsTest) -> None: finally: client.close() - -async def test_monitor_user(ops_test: OpsTest) -> None: +@pytest.mark.skip("skip") +async def test_monitor_user_no_secrets(ops_test: OpsTest) -> None: """Test verifies that the monitor user can perform operations such as 'rs.conf()'.""" unit = ops_test.model.applications[APP_NAME].units[0] password = await get_password(ops_test, "mongodb", "monitor") @@ -180,13 +181,17 @@ async def test_monitor_user(ops_test: OpsTest) -> None: ] hosts = ",".join(replica_set_hosts) replica_set_uri = f"mongodb://monitor:{password}@{hosts}/admin?replicaSet=mongodb" - admin_mongod_cmd = f"charmed-mongodb.mongo '{replica_set_uri}' --eval 'rs.conf()'" - check_monitor_cmd = f"run --unit {unit.name} -- {admin_mongod_cmd}" - return_code, _, _ = await ops_test.juju(*check_monitor_cmd.split()) - assert return_code == 0, "command rs.conf() on monitor user does not work" + + if version("juju") < "3": + check_monitor_cmd = f"run --unit {unit.name} -- {admin_mongod_cmd}" + else: + check_monitor_cmd = f"exec --unit {unit.name} -- {admin_mongod_cmd}" + return_code, _, sdterr = await ops_test.juju(*check_monitor_cmd.split()) + assert return_code == 0, f"command rs.conf() on monitor user does not work. '{sdterr}'" +@pytest.mark.skip("skip") async def test_exactly_one_primary_reported_by_juju(ops_test: OpsTest) -> None: """Tests that there is exactly one replica set primary unit reported by juju.""" @@ -237,7 +242,7 @@ def juju_reports_one_primary(unit_messages): # cleanup, remove killed unit await ops_test.model.destroy_unit(target_unit) - +@pytest.mark.skip("skip") async def test_only_leader_can_set_while_all_can_read_password_secret(ops_test: OpsTest) -> None: """Test verifies that only the leader can set a password, while all units can read it.""" # Setting existing password @@ -247,15 +252,15 @@ async def test_only_leader_can_set_while_all_can_read_password_secret(ops_test: password = "blablabla" await set_password(ops_test, unit_id=non_leaders[0], username="monitor", password=password) - password1 = await get_password(ops_test, unit_id=leader_id, username="monitor") + password1 = await get_password(ops_test, username="monitor") assert password1 != password await set_password(ops_test, unit_id=leader_id, username="monitor", password=password) - for unit_id in UNIT_IDS: - password2 = await get_password(ops_test, unit_id=unit_id, username="monitor") + for _ in UNIT_IDS: + password2 = await get_password(ops_test, username="monitor") assert password2 == password - +@pytest.mark.skip("skip") @pytest.mark.usefixtures("only_with_juju_secrets") async def test_reset_and_get_password_secret_same_as_cli(ops_test: OpsTest) -> None: """Test verifies that we can set and retrieve the correct password using Juju 3.x secrets.""" @@ -270,7 +275,7 @@ async def test_reset_and_get_password_secret_same_as_cli(ops_test: OpsTest) -> N secret_id = result["secret-id"].split("/")[-1] # Getting back the pw programmatically - password = await get_password(ops_test, unit_id=leader_id, username="monitor") + password = await get_password(ops_test, username="monitor") # Getting back the pw from juju CLI complete_command = f"show-secret {secret_id} --reveal --format=json" @@ -280,7 +285,7 @@ async def test_reset_and_get_password_secret_same_as_cli(ops_test: OpsTest) -> N assert password == new_password assert data[secret_id]["content"]["Data"]["monitor-password"] == password - +@pytest.mark.skip("skip") @pytest.mark.usefixtures("only_without_juju_secrets") async def test_reset_and_get_password_no_secret(ops_test: OpsTest, mocker) -> None: """Test verifies that we can set and retrieve the correct password using Juju 2.x.""" @@ -291,18 +296,18 @@ async def test_reset_and_get_password_no_secret(ops_test: OpsTest, mocker) -> No await set_password(ops_test, unit_id=leader_id, username="monitor", password=new_password) # Getting back the pw programmatically - password = await get_password(ops_test, unit_id=leader_id, username="monitor") + password = await get_password(ops_test, username="monitor") assert password == new_password - +@pytest.mark.skip("skip") @pytest.mark.usefixtures("only_with_juju_secrets") async def test_empty_password(ops_test: OpsTest) -> None: """Test that the password can't be set to an empty string.""" leader_id = await get_leader_id(ops_test) - password1 = await get_password(ops_test, unit_id=leader_id, username="monitor") + password1 = await get_password(ops_test, username="monitor") await set_password(ops_test, unit_id=leader_id, username="monitor", password="") - password2 = await get_password(ops_test, unit_id=leader_id, username="monitor") + password2 = await get_password(ops_test, username="monitor") # The password remained unchanged assert password1 == password2 @@ -312,11 +317,11 @@ async def test_empty_password(ops_test: OpsTest) -> None: async def test_no_password_change_on_invalid_password(ops_test: OpsTest) -> None: """Test that in general, there is no change when password validation fails.""" leader_id = await get_leader_id(ops_test) - password1 = await get_password(ops_test, unit_id=leader_id, username="monitor") + password1 = await get_password(ops_test, username="monitor") # The password has to be minimum 3 characters await set_password(ops_test, unit_id=leader_id, username="monitor", password="ca" * 1000000) - password2 = await get_password(ops_test, unit_id=leader_id, username="monitor") + password2 = await get_password(ops_test, username="monitor") # The password didn't change assert password1 == password2 diff --git a/tox.ini b/tox.ini index 43cefe095..f2f5f4fe9 100644 --- a/tox.ini +++ b/tox.ini @@ -74,6 +74,7 @@ deps = pytest juju==3.2.0.1 # juju 3.3.0 has issues with retrieving action results pytest-operator + pytest-mock -r {tox_root}/requirements.txt commands = pytest -v --tb native --log-cli-level=INFO -s --durations=0 {posargs} {[vars]tests_path}/integration/test_charm.py