| ############################################################################ | |
| # Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | |
| ############################################################################ | |
| """Test that jobs suspended during a live upgrade resume and complete.""" | |
| import pytest | |
| import atf | |
| @pytest.fixture(scope="module", autouse=True) | |
| def setup(): | |
| atf.require_upgrades() | |
| atf.require_accounting() | |
| atf.require_config_parameter_excludes("PreemptMode", "GANG") | |
| atf.require_nodes(3) | |
| atf.require_slurm_running() | |
| def get_ticks(job_id, ntasks): | |
| """Return the number of ticks of each task of the job.""" | |
| return [ | |
| len( | |
| atf.run_command_output(f"cat tick.{job_id}.{task}", fatal=True).splitlines() | |
| ) | |
| for task in range(ntasks) | |
| ] | |
| def get_stopped_ticks(job_id, ntasks): | |
| """Return the ticks of the job once no task writes more, or None.""" | |
| prev = None | |
| for _ in atf.timer(): | |
| ticks = get_ticks(job_id, ntasks) | |
| if ticks == prev: | |
| return ticks | |
| prev = ticks | |
| return None | |
| def runs_again(job_id, ntasks, stopped): | |
| """Return True once every task of the job writes a new tick.""" | |
| for _ in atf.timer(): | |
| ticks = get_ticks(job_id, ntasks) | |
| if all(now > then for now, then in zip(ticks, stopped)): | |
| return True | |
| return False | |
| @pytest.fixture | |
| def suspended_jobs(): | |
| """Suspend a batch job and a 2-node srun job, then upgrade Slurm. | |
| Returns {job_id: (ntasks, ticks while suspended)}. | |
| """ | |
| # Each task ticks once per second of run time until the test ends it | |
| atf.make_bash_script( | |
| "tick.sh", | |
| """while [ ! -e finish ]; do | |
| echo tick >> tick.$SLURM_JOB_ID.$SLURM_PROCID | |
| sleep 1 | |
| done | |
| """, | |
| ) | |
| jobs = { | |
| atf.submit_job_sbatch("-N1 -t2 tick.sh", fatal=True): 1, | |
| atf.submit_job_sbatch( | |
| "-N2 --ntasks-per-node=1 -t2 --wrap 'srun ./tick.sh'", fatal=True | |
| ): 2, | |
| } | |
| for job_id, ntasks in jobs.items(): | |
| atf.wait_for_job_state(job_id, "RUNNING", fatal=True) | |
| for task in range(ntasks): | |
| atf.wait_for_file(f"tick.{job_id}.{task}", fatal=True) | |
| atf.run_command( | |
| f"scontrol suspend {','.join(map(str, jobs))}", | |
| user=atf.properties["slurm-user"], | |
| fatal=True, | |
| ) | |
| stopped = {} | |
| for job_id, ntasks in jobs.items(): | |
| atf.wait_for_job_state(job_id, "SUSPENDED", fatal=True) | |
| ticks = get_stopped_ticks(job_id, ntasks) | |
| if ticks is None: | |
| pytest.fail(f"Job {job_id} did not stop when suspended") | |
| stopped[job_id] = (ntasks, ticks) | |
| atf.upgrade_component("sbin/slurmdbd") | |
| atf.upgrade_component("sbin/slurmctld") | |
| atf.upgrade_component("sbin/slurmd") | |
| atf.upgrade_component("sbin/slurmstepd") | |
| for node in atf.get_nodes(fatal=True): | |
| atf.start_slurmd(node) | |
| atf.upgrade_component("bin/scontrol") | |
| # The old slurmstepds of the jobs must talk to a new slurmd | |
| version = atf.run_command_output( | |
| f"{atf.properties['new-slurm-prefix']}/sbin/slurmd -V", | |
| user="root", | |
| fatal=True, | |
| ).split()[-1] | |
| for node, info in atf.get_nodes(fatal=True).items(): | |
| if info.get("version") != version: | |
| pytest.fail(f"Node {node} runs slurmd {info.get('version')}, not {version}") | |
| return stopped | |
| def test_resume_after_upgrade(suspended_jobs): | |
| """Verify jobs suspended during an upgrade resume, suspend again and complete.""" | |
| job_list = ",".join(map(str, suspended_jobs)) | |
| for job_id, (ntasks, stopped) in suspended_jobs.items(): | |
| assert ( | |
| atf.get_job_parameter(job_id, "JobState", fatal=True) == "SUSPENDED" | |
| ), f"Job {job_id} should stay SUSPENDED during the upgrade" | |
| assert ( | |
| get_ticks(job_id, ntasks) == stopped | |
| ), f"Job {job_id} should not run while SUSPENDED" | |
| result = atf.run_command( | |
| f"scontrol resume {job_list}", user=atf.properties["slurm-user"] | |
| ) | |
| assert result["exit_code"] == 0, f"scontrol resume failed: {result['stderr']}" | |
| for job_id, (ntasks, stopped) in suspended_jobs.items(): | |
| assert runs_again( | |
| job_id, ntasks, stopped | |
| ), f"Job {job_id} should run again after resume" | |
| # The new slurmd also suspends the old slurmstepds | |
| result = atf.run_command( | |
| f"scontrol suspend {job_list}", user=atf.properties["slurm-user"] | |
| ) | |
| assert result["exit_code"] == 0, f"scontrol suspend failed: {result['stderr']}" | |
| stopped = {} | |
| for job_id, (ntasks, _) in suspended_jobs.items(): | |
| stopped[job_id] = get_stopped_ticks(job_id, ntasks) | |
| assert stopped[job_id] is not None, f"Job {job_id} should stop when suspended" | |
| result = atf.run_command( | |
| f"scontrol resume {job_list}", user=atf.properties["slurm-user"] | |
| ) | |
| assert result["exit_code"] == 0, f"scontrol resume failed: {result['stderr']}" | |
| for job_id, (ntasks, _) in suspended_jobs.items(): | |
| assert runs_again( | |
| job_id, ntasks, stopped[job_id] | |
| ), f"Job {job_id} should run again after resume" | |
| atf.run_command("touch finish", fatal=True) | |
| for job_id in suspended_jobs: | |
| assert atf.wait_for_job_state( | |
| job_id, "COMPLETED" | |
| ), f"Job {job_id} should complete after resume" |