Skip to content

Commit

Permalink
tests(slurm_ops): update mocks in unit tests to new package commands
Browse files Browse the repository at this point in the history
Adds additional test as well to ensure that `/var/lib/slurm`
has the correct file permissions mode if created by the
`charms.hpc_libs.v0.slurm_ops._AptManager._create_state_save_location`
method after the relevant Slurm daemon has been installed.

Signed-off-by: Jason C. Nucciarone <[email protected]>
  • Loading branch information
NucciTheBoss committed Nov 15, 2024
1 parent 8816b6b commit 7729e89
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions tests/unit/test_slurm_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,25 +343,45 @@ def test_install_service(self, add_package, *_) -> None:
self.slurmctld._ops_manager._install_service()
self.assertListEqual(
add_package.call_args[0][0],
["slurmctld", "mungectl", "prometheus-slurm-exporter", "libpmix-dev", "mailutils"],
[
"slurmctld",
"munge",
"mungectl",
"prometheus-slurm-exporter",
"libpmix-dev",
"mailutils",
],
)

self.slurmd._ops_manager._install_service()
self.assertListEqual(
add_package.call_args[0][0],
["slurmd", "mungectl", "prometheus-slurm-exporter", "libpmix-dev", "openmpi-bin"],
[
"slurmd",
"munge",
"mungectl",
"prometheus-slurm-exporter",
"libpmix-dev",
"openmpi-bin",
],
)

self.slurmdbd._ops_manager._install_service()
self.assertListEqual(
add_package.call_args[0][0],
["slurmdbd", "mungectl", "prometheus-slurm-exporter"],
["slurmdbd", "munge", "mungectl", "prometheus-slurm-exporter"],
)

self.slurmrestd._ops_manager._install_service()
self.assertListEqual(
add_package.call_args[0][0],
["slurmrestd", "mungectl", "prometheus-slurm-exporter"],
[
"slurmrestd",
"munge",
"mungectl",
"prometheus-slurm-exporter",
"slurm-wlm-basic-plugins",
],
)

add_package.side_effect = apt.PackageError("failed to install packages!")
Expand All @@ -375,15 +395,15 @@ def test_apply_overrides(self, subcmd) -> None:
groupadd = subcmd.call_args_list[0][0][0]
adduser = subcmd.call_args_list[1][0][0]
systemctl = subcmd.call_args_list[2][0][0]
self.assertListEqual(groupadd, ["groupadd", "--gid", 64031, "slurmrestd"])
self.assertListEqual(groupadd, ["groupadd", "--gid", "64031", "slurmrestd"])
self.assertListEqual(
adduser,
[
"adduser",
"--system",
"--group",
"--uid",
64031,
"64031",
"--no-create-home",
"--home",
"/nonexistent",
Expand All @@ -405,11 +425,14 @@ def test_apply_overrides(self, subcmd) -> None:
@patch("charms.hpc_libs.v0.slurm_ops._AptManager._init_ubuntu_hpc_ppa")
@patch("charms.hpc_libs.v0.slurm_ops._AptManager._install_service")
@patch("charms.hpc_libs.v0.slurm_ops._AptManager._apply_overrides")
@patch("shutil.chown")
def test_install(self, *_) -> None:
"""Test public `install` method that encapsulates service install logic."""
self.slurmctld.install()
f_info = Path("/var/lib/slurm/slurm.state").stat()
self.assertEqual(stat.filemode(f_info.st_mode), "drw-------")
f_info = Path("/var/lib/slurm").stat()
self.assertEqual(stat.filemode(f_info.st_mode), "drwxr-xr-x")
f_info = Path("/var/lib/slurm/checkpoint").stat()
self.assertEqual(stat.filemode(f_info.st_mode), "drwxr-xr-x")


@patch(
Expand Down

0 comments on commit 7729e89

Please sign in to comment.