From 7729e89630d595e5d38a35f5ac172636d07d57d2 Mon Sep 17 00:00:00 2001 From: "Jason C. Nucciarone" Date: Thu, 14 Nov 2024 16:33:03 -0500 Subject: [PATCH] tests(slurm_ops): update mocks in unit tests to new package commands 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 --- tests/unit/test_slurm_ops.py | 39 ++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/tests/unit/test_slurm_ops.py b/tests/unit/test_slurm_ops.py index 8afb55a..9994232 100644 --- a/tests/unit/test_slurm_ops.py +++ b/tests/unit/test_slurm_ops.py @@ -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!") @@ -375,7 +395,7 @@ 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, [ @@ -383,7 +403,7 @@ def test_apply_overrides(self, subcmd) -> None: "--system", "--group", "--uid", - 64031, + "64031", "--no-create-home", "--home", "/nonexistent", @@ -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(