From a15ee51670aa75d23e15791cf748d19436c7dfa4 Mon Sep 17 00:00:00 2001 From: "Jason C. Nucciarone" Date: Wed, 18 Sep 2024 13:53:18 -0400 Subject: [PATCH] tests(slurm_ops): add tests for `scontrol` method Signed-off-by: Jason C. Nucciarone --- tests/unit/test_slurm_ops.py | 181 +++++++++++++++++++---------------- 1 file changed, 97 insertions(+), 84 deletions(-) diff --git a/tests/unit/test_slurm_ops.py b/tests/unit/test_slurm_ops.py index 14bbbbc..c72ce2d 100644 --- a/tests/unit/test_slurm_ops.py +++ b/tests/unit/test_slurm_ops.py @@ -6,6 +6,7 @@ import base64 import subprocess +import textwrap from pathlib import Path from unittest import TestCase from unittest.mock import patch @@ -211,6 +212,12 @@ def test_hostname(self, gethostname, *_) -> None: gethostname.return_value = "machine.domain.com" self.assertEqual(self.manager.hostname, "machine") + def test_scontrol(self, subcmd) -> None: + """Test that manager correctly calls scontrol.""" + self.manager.scontrol("reconfigure") + args = subcmd.call_args[0][0] + self.assertEqual(args, ["scontrol", "reconfigure"]) + parameters = [ (_SlurmManagerBase(_ServiceType.SLURMCTLD, snap=True), "slurm"), @@ -235,55 +242,58 @@ def test_hostname(self, gethostname, *_) -> None: class TestSlurmctldConfig(FsTestCase): """Test the Slurmctld service config manager.""" - EXAMPLE_SLURM_CONF = """# -# `slurm.conf` file generated at 2024-01-30 17:18:36.171652 by slurmutils. -# -SlurmctldHost=juju-c9fc6f-0(10.152.28.20) -SlurmctldHost=juju-c9fc6f-1(10.152.28.100) - -ClusterName=charmed-hpc -AuthType=auth/munge -Epilog=/usr/local/slurm/epilog -Prolog=/usr/local/slurm/prolog -FirstJobId=65536 -InactiveLimit=120 -JobCompType=jobcomp/filetxt -JobCompLoc=/var/log/slurm/jobcomp -KillWait=30 -MaxJobCount=10000 -MinJobAge=3600 -PluginDir=/usr/local/lib:/usr/local/slurm/lib -ReturnToService=0 -SchedulerType=sched/backfill -SlurmctldLogFile=/var/log/slurm/slurmctld.log -SlurmdLogFile=/var/log/slurm/slurmd.log -SlurmctldPort=7002 -SlurmdPort=7003 -SlurmdSpoolDir=/var/spool/slurmd.spool -StateSaveLocation=/var/spool/slurm.state -SwitchType=switch/none -TmpFS=/tmp -WaitTime=30 - -# -# Node configurations -# -NodeName=juju-c9fc6f-2 NodeAddr=10.152.28.48 CPUs=1 RealMemory=1000 TmpDisk=10000 -NodeName=juju-c9fc6f-3 NodeAddr=10.152.28.49 CPUs=1 RealMemory=1000 TmpDisk=10000 -NodeName=juju-c9fc6f-4 NodeAddr=10.152.28.50 CPUs=1 RealMemory=1000 TmpDisk=10000 -NodeName=juju-c9fc6f-5 NodeAddr=10.152.28.51 CPUs=1 RealMemory=1000 TmpDisk=10000 - -# -# Down node configurations -# -DownNodes=juju-c9fc6f-5 State=DOWN Reason="Maintenance Mode" - -# -# Partition configurations -# -PartitionName=DEFAULT MaxTime=30 MaxNodes=10 State=UP -PartitionName=batch Nodes=juju-c9fc6f-2,juju-c9fc6f-3,juju-c9fc6f-4,juju-c9fc6f-5 MinNodes=4 MaxTime=120 AllowGroups=admin -""" + EXAMPLE_SLURM_CONF = textwrap.dedent( + """ + # + # `slurm.conf` file generated at 2024-01-30 17:18:36.171652 by slurmutils. + # + SlurmctldHost=juju-c9fc6f-0(10.152.28.20) + SlurmctldHost=juju-c9fc6f-1(10.152.28.100) + + ClusterName=charmed-hpc + AuthType=auth/munge + Epilog=/usr/local/slurm/epilog + Prolog=/usr/local/slurm/prolog + FirstJobId=65536 + InactiveLimit=120 + JobCompType=jobcomp/filetxt + JobCompLoc=/var/log/slurm/jobcomp + KillWait=30 + MaxJobCount=10000 + MinJobAge=3600 + PluginDir=/usr/local/lib:/usr/local/slurm/lib + ReturnToService=0 + SchedulerType=sched/backfill + SlurmctldLogFile=/var/log/slurm/slurmctld.log + SlurmdLogFile=/var/log/slurm/slurmd.log + SlurmctldPort=7002 + SlurmdPort=7003 + SlurmdSpoolDir=/var/spool/slurmd.spool + StateSaveLocation=/var/spool/slurm.state + SwitchType=switch/none + TmpFS=/tmp + WaitTime=30 + + # + # Node configurations + # + NodeName=juju-c9fc6f-2 NodeAddr=10.152.28.48 CPUs=1 RealMemory=1000 TmpDisk=10000 + NodeName=juju-c9fc6f-3 NodeAddr=10.152.28.49 CPUs=1 RealMemory=1000 TmpDisk=10000 + NodeName=juju-c9fc6f-4 NodeAddr=10.152.28.50 CPUs=1 RealMemory=1000 TmpDisk=10000 + NodeName=juju-c9fc6f-5 NodeAddr=10.152.28.51 CPUs=1 RealMemory=1000 TmpDisk=10000 + + # + # Down node configurations + # + DownNodes=juju-c9fc6f-5 State=DOWN Reason="Maintenance Mode" + + # + # Partition configurations + # + PartitionName=DEFAULT MaxTime=30 MaxNodes=10 State=UP + PartitionName=batch Nodes=juju-c9fc6f-2,juju-c9fc6f-3,juju-c9fc6f-4,juju-c9fc6f-5 MinNodes=4 MaxTime=120 AllowGroups=admin + """ + ).strip() def setUp(self): self.manager = SlurmctldManager(snap=True) @@ -327,41 +337,44 @@ def test_config(self, *_) -> None: class TestSlurmdbdConfig(FsTestCase): """Test the Slurmdbd service config manager.""" - EXAMPLE_SLURMDBD_CONF = """# -# `slurmdbd.conf` file generated at 2024-01-30 17:18:36.171652 by slurmutils. -# -ArchiveEvents=yes -ArchiveJobs=yes -ArchiveResvs=yes -ArchiveSteps=no -ArchiveTXN=no -ArchiveUsage=no -ArchiveScript=/usr/sbin/slurm.dbd.archive -AuthInfo=/var/run/munge/munge.socket.2 -AuthType=auth/munge -AuthAltTypes=auth/jwt -AuthAltParameters=jwt_key=16549684561684@ -DbdHost=slurmdbd-0 -DbdBackupHost=slurmdbd-1 -DebugLevel=info -PluginDir=/all/these/cool/plugins -PurgeEventAfter=1month -PurgeJobAfter=12month -PurgeResvAfter=1month -PurgeStepAfter=1month -PurgeSuspendAfter=1month -PurgeTXNAfter=12month -PurgeUsageAfter=24month -LogFile=/var/log/slurmdbd.log -PidFile=/var/run/slurmdbd.pid -SlurmUser=slurm -StoragePass=supersecretpasswd -StorageType=accounting_storage/mysql -StorageUser=slurm -StorageHost=127.0.0.1 -StoragePort=3306 -StorageLoc=slurm_acct_db -""" + EXAMPLE_SLURMDBD_CONF = textwrap.dedent( + """ + # + # `slurmdbd.conf` file generated at 2024-01-30 17:18:36.171652 by slurmutils. + # + ArchiveEvents=yes + ArchiveJobs=yes + ArchiveResvs=yes + ArchiveSteps=no + ArchiveTXN=no + ArchiveUsage=no + ArchiveScript=/usr/sbin/slurm.dbd.archive + AuthInfo=/var/run/munge/munge.socket.2 + AuthType=auth/munge + AuthAltTypes=auth/jwt + AuthAltParameters=jwt_key=16549684561684@ + DbdHost=slurmdbd-0 + DbdBackupHost=slurmdbd-1 + DebugLevel=info + PluginDir=/all/these/cool/plugins + PurgeEventAfter=1month + PurgeJobAfter=12month + PurgeResvAfter=1month + PurgeStepAfter=1month + PurgeSuspendAfter=1month + PurgeTXNAfter=12month + PurgeUsageAfter=24month + LogFile=/var/log/slurmdbd.log + PidFile=/var/run/slurmdbd.pid + SlurmUser=slurm + StoragePass=supersecretpasswd + StorageType=accounting_storage/mysql + StorageUser=slurm + StorageHost=127.0.0.1 + StoragePort=3306 + StorageLoc=slurm_acct_db + """ + ).strip() def setUp(self): self.manager = SlurmdbdManager(snap=True)