From a0756eabe8846f94b68ac06fec76d6998cea48d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Juli=C3=A1n=20Espina?= Date: Thu, 18 Jul 2024 15:13:25 -0600 Subject: [PATCH] test: integrate with slurmrestd on tests --- tests/integration/conftest.py | 21 ++++++++++++++++++++ tests/integration/test_charm.py | 35 +++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index ac9ac77..64a4704 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -26,6 +26,7 @@ logger = logging.getLogger(__name__) SLURMD_DIR = Path(os.getenv("SLURMD_DIR", "../slurmd-operator")) SLURMDBD_DIR = Path(os.getenv("SLURMDBD_DIR", "../slurmdbd-operator")) +SLURMRESTD_DIR = Path(os.getenv("SLURMRESTD_DIR", "../slurmrestd-operator")) def pytest_addoption(parser) -> None: @@ -93,3 +94,23 @@ async def slurmdbd_charm(request, ops_test: OpsTest) -> Union[str, Path]: ) return "slurmdbd" + + +@pytest.fixture(scope="module") +async def slurmrestd_charm(request, ops_test: OpsTest) -> Union[str, Path]: + """Pack slurmrestd charm to use for integration tests when --use-local is specified. + + Returns: + `str` "slurmrestd" if --use-local not specified or if SLURMRESTD_DIR does not exist. + """ + if request.config.option.use_local: + logger.info("Using local slurmrestd operator rather than pulling from Charmhub") + if SLURMRESTD_DIR.exists(): + return await ops_test.build_charm(SLURMRESTD_DIR) + else: + logger.warning( + f"{SLURMRESTD_DIR} not found. " + f"Defaulting to latest/edge slurmrestd operator from Charmhub" + ) + + return "slurmrestd" diff --git a/tests/integration/test_charm.py b/tests/integration/test_charm.py index c34dba3..e5f274b 100644 --- a/tests/integration/test_charm.py +++ b/tests/integration/test_charm.py @@ -27,22 +27,29 @@ SLURMCTLD = "slurmctld" SLURMD = "slurmd" SLURMDBD = "slurmdbd" +SLURMRESTD = "slurmrestd" DATABASE = "mysql" ROUTER = "mysql-router" -UNIT_NAME = f"{SLURMCTLD}/0" @pytest.mark.abort_on_fail @pytest.mark.skip_if_deployed @pytest.mark.order(1) async def test_build_and_deploy_against_edge( - ops_test: OpsTest, charm_base: str, slurmctld_charm, slurmd_charm, slurmdbd_charm + ops_test: OpsTest, + charm_base: str, + slurmctld_charm, + slurmd_charm, + slurmdbd_charm, + slurmrestd_charm, ) -> None: - """Test that the slurmctld charm can stabilize against slurmd, slurmdbd, and MySQL.""" - logger.info(f"Deploying {SLURMCTLD} against {SLURMD}, {SLURMDBD}, and {DATABASE}") + """Test that the slurmctld charm can stabilize against slurmd, slurmdbd, slurmrestd, and MySQL.""" + logger.info( + f"Deploying {SLURMCTLD} against {SLURMD}, {SLURMDBD}, {SLURMRESTD}, and {DATABASE}" + ) # Pack charms and download NHC resource for the slurmd operator. - slurmctld, slurmd, slurmdbd = await asyncio.gather( - slurmctld_charm, slurmd_charm, slurmdbd_charm + slurmctld, slurmd, slurmdbd, slurmrestd = await asyncio.gather( + slurmctld_charm, slurmd_charm, slurmdbd_charm, slurmrestd_charm ) # Deploy the test Charmed SLURM cloud. await asyncio.gather( @@ -66,6 +73,13 @@ async def test_build_and_deploy_against_edge( num_units=1, base=charm_base, ), + ops_test.model.deploy( + str(slurmrestd), + application_name=SLURMRESTD, + channel="edge" if isinstance(slurmrestd, str) else None, + num_units=1, + base=charm_base, + ), ops_test.model.deploy( ROUTER, application_name=f"{SLURMDBD}-{ROUTER}", @@ -84,12 +98,13 @@ async def test_build_and_deploy_against_edge( # Set integrations for charmed applications. await ops_test.model.integrate(f"{SLURMCTLD}:{SLURMD}", f"{SLURMD}:{SLURMCTLD}") await ops_test.model.integrate(f"{SLURMCTLD}:{SLURMDBD}", f"{SLURMDBD}:{SLURMCTLD}") + await ops_test.model.integrate(f"{SLURMCTLD}:{SLURMRESTD}", f"{SLURMRESTD}:{SLURMCTLD}") await ops_test.model.integrate(f"{SLURMDBD}-{ROUTER}:backend-database", f"{DATABASE}:database") await ops_test.model.integrate(f"{SLURMDBD}:database", f"{SLURMDBD}-{ROUTER}:database") # Reduce the update status frequency to accelerate the triggering of deferred events. async with ops_test.fast_forward(): await ops_test.model.wait_for_idle(apps=[SLURMCTLD], status="active", timeout=1000) - assert ops_test.model.units.get(UNIT_NAME).workload_status == "active" + assert ops_test.model.applications["slurmctld"].units[0].workload_status == "active" @pytest.mark.abort_on_fail @@ -102,7 +117,7 @@ async def test_build_and_deploy_against_edge( async def test_slurmctld_is_active(ops_test: OpsTest) -> None: """Test that slurmctld is active inside Juju unit.""" logger.info("Checking that slurmctld is active inside Juju unit") - slurmctld_unit = ops_test.model.units.get(UNIT_NAME) + slurmctld_unit = ops_test.model.applications["slurmctld"].units[0] res = (await slurmctld_unit.ssh("systemctl is-active slurmctld")).strip("\n") assert res == "active" @@ -117,7 +132,7 @@ async def test_slurmctld_is_active(ops_test: OpsTest) -> None: async def test_slurmctld_port_listen(ops_test: OpsTest) -> None: """Test that slurmctld is listening on port 6817.""" logger.info("Checking that slurmctld is listening on port 6817") - slurmctld_unit = ops_test.model.units.get(UNIT_NAME) + slurmctld_unit = ops_test.model.applications["slurmctld"].units[0] res = await slurmctld_unit.ssh("sudo lsof -t -n -iTCP:6817 -sTCP:LISTEN") assert res != "" @@ -132,6 +147,6 @@ async def test_slurmctld_port_listen(ops_test: OpsTest) -> None: async def test_munge_is_active(ops_test: OpsTest) -> None: """Test that munge is active inside Juju unit.""" logger.info("Checking that munge is active inside Juju unit") - slurmctld_unit = ops_test.model.units.get(UNIT_NAME) + slurmctld_unit = ops_test.model.applications["slurmctld"].units[0] res = (await slurmctld_unit.ssh("systemctl is-active munge")).strip("\n") assert res == "active"