Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
test: integrate with slurmrestd on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Jul 18, 2024
1 parent 71a32c4 commit a0756ea
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
21 changes: 21 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
35 changes: 25 additions & 10 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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}",
Expand All @@ -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
Expand All @@ -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"

Expand All @@ -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 != ""

Expand All @@ -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"

0 comments on commit a0756ea

Please sign in to comment.