From 3b414d4bde94b416e2213645dcec763beb12ebb2 Mon Sep 17 00:00:00 2001 From: Woody Date: Wed, 22 Nov 2023 04:55:47 +0800 Subject: [PATCH] Added Admin Comment field to Job Information Table (#101) Added Admin Comment field to Job Information Table --- etc/slurm-mail/templates/job-table.tpl | 4 ++ src/slurmmail/cli.py | 3 ++ src/slurmmail/slurm.py | 1 + tests/unit/test_cli.py | 56 +++++++++++++------------- 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/etc/slurm-mail/templates/job-table.tpl b/etc/slurm-mail/templates/job-table.tpl index 85d6af3..aeb544f 100644 --- a/etc/slurm-mail/templates/job-table.tpl +++ b/etc/slurm-mail/templates/job-table.tpl @@ -35,6 +35,10 @@ Work dir: $WORKDIR + + Admin Comment: + $ADMIN_COMMENT + Comment: $COMMENT diff --git a/src/slurmmail/cli.py b/src/slurmmail/cli.py index de60e20..5ec3b99 100644 --- a/src/slurmmail/cli.py +++ b/src/slurmmail/cli.py @@ -184,6 +184,7 @@ def __process_spool_file( "WorkDir", "Elapsed", "ExitCode", + "AdminComment", "Comment", "Cluster", "NodeList", @@ -244,6 +245,7 @@ def __process_spool_file( job = Job(options.datetime_format, job_id) job.cluster = sacct_dict["Cluster"] + job.admin_comment = sacct_dict["AdminComment"] job.comment = sacct_dict["Comment"] job.cpus = int(sacct_dict["NCPUS"]) job.group = sacct_dict["Group"] @@ -379,6 +381,7 @@ def __process_spool_file( ELAPSED=str(timedelta(seconds=job.elapsed)), EXIT_STATE=job.state, EXIT_CODE=job.exit_code, + ADMIN_COMMENT=job.admin_comment, COMMENT=job.comment, MEMORY=job.requested_mem_str, MAX_MEMORY=job.max_rss_str, diff --git a/src/slurmmail/slurm.py b/src/slurmmail/slurm.py index 702a575..a332768 100644 --- a/src/slurmmail/slurm.py +++ b/src/slurmmail/slurm.py @@ -87,6 +87,7 @@ def __init__( self.array_id: Optional[int] = array_id self.cluster: Optional[str] = None + self.admin_comment: Optional[str] = None self.comment: Optional[str] = None self.elapsed: Optional[int] = 0 self.exit_code: Optional[int] = None diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index c67985f..cb67489 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -476,8 +476,8 @@ def test_job_began( } """, ): - sacct_output = "1|root|root|all|1674333232|Unknown|RUNNING|500M||1|00:00:00|1|/|00:00:11|0:0||test|node01|01:00:00|60|1|test.jcf\n" # noqa - sacct_output += "1.batch||||1674333232|Unknown|RUNNING|||1|00:00:00|1||00:00:11|0:0||test|node01|||1.batch|batch" # noqa + sacct_output = "1|root|root|all|1674333232|Unknown|RUNNING|500M||1|00:00:00|1|/|00:00:11|0:0|||test|node01|01:00:00|60|1|test.jcf\n" # noqa + sacct_output += "1.batch||||1674333232|Unknown|RUNNING|||1|00:00:00|1||00:00:11|0:0|||test|node01|||1.batch|batch" # noqa mock_slurmmail_cli_run_command.side_effect = [(0, sacct_output, "")] slurmmail.cli.__dict__["__process_spool_file"]( pathlib.Path("/tmp/foo"), @@ -511,8 +511,8 @@ def test_job_ended( } """, ): - sacct_output = "2|root|root|all|1674340451|1674340571|COMPLETED|500M||1|00:00.010|1|/root|00:02:00|0:0||test|node01|01:00:00|60|2|test.jcf\n" # noqa - sacct_output += "2.batch||||1674340451|1674340571|COMPLETED||4880K|1|00:00.010|1||00:02:00|0:0||test|node01|||2.batch|batch" # noqa + sacct_output = "2|root|root|all|1674340451|1674340571|COMPLETED|500M||1|00:00.010|1|/root|00:02:00|0:0|||test|node01|01:00:00|60|2|test.jcf\n" # noqa + sacct_output += "2.batch||||1674340451|1674340571|COMPLETED||4880K|1|00:00.010|1||00:02:00|0:0|||test|node01|||2.batch|batch" # noqa scontrol_output = ( "JobId=2 JobName=test.jcf UserId=root(0) GroupId=root(0) MCS_label=N/A" " Priority=4294901758 Nice=0 Account=root QOS=normal JobState=COMPLETED" @@ -579,8 +579,8 @@ def test_job_ended_tail_file( mock_slurmmail_cli_process_spool_file_options.tail_exe = pathlib.Path( "/usr/bin/tail" ) - sacct_output = "2|root|root|all|1674340451|1674340571|COMPLETED|500M||1|00:00.010|1|/root|00:02:00|0:0||test|node01|01:00:00|60|2|test.jcf\n" # noqa - sacct_output += "2.batch||||1674340451|1674340571|COMPLETED||4880K|1|00:00.010|1||00:02:00|0:0||test|node01|||2.batch|batch" # noqa + sacct_output = "2|root|root|all|1674340451|1674340571|COMPLETED|500M||1|00:00.010|1|/root|00:02:00|0:0|||test|node01|01:00:00|60|2|test.jcf\n" # noqa + sacct_output += "2.batch||||1674340451|1674340571|COMPLETED||4880K|1|00:00.010|1||00:02:00|0:0|||test|node01|||2.batch|batch" # noqa scontrol_output = ( "JobId=2 JobName=test.jcf UserId=root(0) GroupId=root(0) MCS_label=N/A" " Priority=4294901758 Nice=0 Account=root QOS=normal JobState=COMPLETED" @@ -640,8 +640,8 @@ def test_job_array_began_summary( } """, ): - sacct_output = "7_0|root|root|all|1675460419|Unknown|RUNNING|500M||1|00:00:00|1|/root|00:00:43|0:0||test|node01|00:05:00|5|8|test.jcf\n" # noqa - sacct_output += "7_0.batch||||1675460419|Unknown|RUNNING|||1|00:00:00|1||00:00:43|0:0||test|node01|||8.batch|batch\n" # noqa + sacct_output = "7_0|root|root|all|1675460419|Unknown|RUNNING|500M||1|00:00:00|1|/root|00:00:43|0:0|||test|node01|00:05:00|5|8|test.jcf\n" # noqa + sacct_output += "7_0.batch||||1675460419|Unknown|RUNNING|||1|00:00:00|1||00:00:43|0:0|||test|node01|||8.batch|batch\n" # noqa sacct_output += ( "7_1|root|root|all|Unknown|Unknown|PENDING|500M||1|00:00:00|1|/root|00:00:00|0:0||test|None" # noqa " assigned|00:05:00|5|7|test.jcf" @@ -679,10 +679,10 @@ def test_job_array_ended_summary( } """, ): - sacct_output = "7_0|root|root|all|1675460419|1675460599|COMPLETED|500M||1|00:00.010|1|/root|00:03:00|0:0||test|node01|00:05:00|5|8|test.jcf\n" # noqa - sacct_output += "7_0.batch||||1675460419|1675460599|COMPLETED||4832K|1|00:00.010|1||00:03:00|0:0||test|node01|||8.batch|batch\n" # noqa - sacct_output += "7_1|root|root|all|1675460599|1675460779|COMPLETED|500M||1|00:00.010|1|/root|00:03:00|0:0||test|node01|00:05:00|5|7|test.jcf\n" # noqa - sacct_output += "7_1.batch||||1675460599|1675460779|COMPLETED||4784K|1|00:00.010|1||00:03:00|0:0||test|node01|||7.batch|batch" # noqa + sacct_output = "7_0|root|root|all|1675460419|1675460599|COMPLETED|500M||1|00:00.010|1|/root|00:03:00|0:0|||test|node01|00:05:00|5|8|test.jcf\n" # noqa + sacct_output += "7_0.batch||||1675460419|1675460599|COMPLETED||4832K|1|00:00.010|1||00:03:00|0:0|||test|node01|||8.batch|batch\n" # noqa + sacct_output += "7_1|root|root|all|1675460599|1675460779|COMPLETED|500M||1|00:00.010|1|/root|00:03:00|0:0|||test|node01|00:05:00|5|7|test.jcf\n" # noqa + sacct_output += "7_1.batch||||1675460599|1675460779|COMPLETED||4784K|1|00:00.010|1||00:03:00|0:0|||test|node01|||7.batch|batch" # noqa scontrol_output_1 = ( "JobId=8 ArrayJobId=7 ArrayTaskId=0 JobName=test.jcf UserId=root(0)" " GroupId=root(0) MCS_label=N/A Priority=4294901756 Nice=0 Account=root" @@ -777,10 +777,10 @@ def test_job_array_ended_no_summary( } """, ): - sacct_output = "7_0|root|root|all|1675460419|1675460599|COMPLETED|500M||1|00:00.010|1|/root|00:03:00|0:0||test|node01|00:05:00|5|8|test.jcf\n" # noqa - sacct_output += "7_0.batch||||1675460419|1675460599|COMPLETED||4832K|1|00:00.010|1||00:03:00|0:0||test|node01|||8.batch|batch\n" # noqa - sacct_output += "7_1|root|root|all|1675460599|1675460779|COMPLETED|500M||1|00:00.010|1|/root|00:03:00|0:0||test|node01|00:05:00|5|7|test.jcf\n" # noqa - sacct_output += "7_1.batch||||1675460599|1675460779|COMPLETED||4784K|1|00:00.010|1||00:03:00|0:0||test|node01|||7.batch|batch" # noqa + sacct_output = "7_0|root|root|all|1675460419|1675460599|COMPLETED|500M||1|00:00.010|1|/root|00:03:00|0:0|||test|node01|00:05:00|5|8|test.jcf\n" # noqa + sacct_output += "7_0.batch||||1675460419|1675460599|COMPLETED||4832K|1|00:00.010|1||00:03:00|0:0|||test|node01|||8.batch|batch\n" # noqa + sacct_output += "7_1|root|root|all|1675460599|1675460779|COMPLETED|500M||1|00:00.010|1|/root|00:03:00|0:0|||test|node01|00:05:00|5|7|test.jcf\n" # noqa + sacct_output += "7_1.batch||||1675460599|1675460779|COMPLETED||4784K|1|00:00.010|1||00:03:00|0:0|||test|node01|||7.batch|batch" # noqa scontrol_output_1 = ( "JobId=8 ArrayJobId=7 ArrayTaskId=0 JobName=test.jcf UserId=root(0)" " GroupId=root(0) MCS_label=N/A Priority=4294901756 Nice=0 Account=root" @@ -879,8 +879,8 @@ def test_job_ended_scontrol_failure( } """, ): - sacct_output = "2|root|root|all|1674340451|1674340571|COMPLETED|500M||1|00:00.010|1|/root|00:02:00|0:0||test|node01|01:00:00|60|2|test.jcf\n" # noqa - sacct_output += "2.batch||||1674340451|1674340571|COMPLETED||4880K|1|00:00.010|1||00:02:00|0:0||test|node01|||2.batch|batch" # noqa + sacct_output = "2|root|root|all|1674340451|1674340571|COMPLETED|500M||1|00:00.010|1|/root|00:02:00|0:0|||test|node01|01:00:00|60|2|test.jcf\n" # noqa + sacct_output += "2.batch||||1674340451|1674340571|COMPLETED||4880K|1|00:00.010|1||00:02:00|0:0|||test|node01|||2.batch|batch" # noqa mock_slurmmail_cli_run_command.side_effect = [ (0, sacct_output, ""), (1, "error", "error"), @@ -918,8 +918,8 @@ def test_job_ended_unlimited_wallclock( } """, ): - sacct_output = "2|root|root|all|1674340451|1674340571|COMPLETED|500M||1|00:00.010|1|/root|00:02:00|0:0||test|node01|UNLIMITED||2|test.jcf\n" # noqa - sacct_output += "2.batch||||1674340451|1674340571|COMPLETED||4880K|1|00:00.010|1||00:02:00|0:0||test|node01|||2.batch|batch" # noqa + sacct_output = "2|root|root|all|1674340451|1674340571|COMPLETED|500M||1|00:00.010|1|/root|00:02:00|0:0|||test|node01|UNLIMITED||2|test.jcf\n" # noqa + sacct_output += "2.batch||||1674340451|1674340571|COMPLETED||4880K|1|00:00.010|1||00:02:00|0:0|||test|node01|||2.batch|batch" # noqa scontrol_output = ( "JobId=2 JobName=test.jcf UserId=root(0) GroupId=root(0) MCS_label=N/A" " Priority=4294901758 Nice=0 Account=root QOS=normal JobState=COMPLETED" @@ -977,8 +977,8 @@ def test_job_ended_bad_wallclock( } """, ): - sacct_output = "2|root|root|all|1674340451|1674340571|COMPLETED|500M||1|00:00.010|1|/root|00:02:00|0:0||test|node01|01:00:00|bad_wc|2|test.jcf\n" # noqa - sacct_output += "2.batch||||1674340451|1674340571|COMPLETED||4880K|1|00:00.010|1||00:02:00|0:0||test|node01|||2.batch|batch" # noqa + sacct_output = "2|root|root|all|1674340451|1674340571|COMPLETED|500M||1|00:00.010|1|/root|00:02:00|0:0|||test|node01|01:00:00|bad_wc|2|test.jcf\n" # noqa + sacct_output += "2.batch||||1674340451|1674340571|COMPLETED||4880K|1|00:00.010|1||00:02:00|0:0|||test|node01|||2.batch|batch" # noqa scontrol_output = ( "JobId=2 JobName=test.jcf UserId=root(0) GroupId=root(0) MCS_label=N/A" " Priority=4294901758 Nice=0 Account=root QOS=normal JobState=COMPLETED" @@ -1037,8 +1037,8 @@ def test_job_ended_bad_end_ts( } """, ): - sacct_output = "2|root|root|all|1674340451|bad_ts|COMPLETED|500M||1|00:00.010|1|/root|00:02:00|0:0||test|node01|01:00:00|60|2|test.jcf\n" # noqa - sacct_output += "2.batch||||1674340451|bad_ts|COMPLETED||4880K|1|00:00.010|1||00:02:00|0:0||test|node01|||2.batch|batch" # noqa + sacct_output = "2|root|root|all|1674340451|bad_ts|COMPLETED|500M||1|00:00.010|1|/root|00:02:00|0:0|||test|node01|01:00:00|60|2|test.jcf\n" # noqa + sacct_output += "2.batch||||1674340451|bad_ts|COMPLETED||4880K|1|00:00.010|1||00:02:00|0:0|||test|node01|||2.batch|batch" # noqa scontrol_output = ( "JobId=2 JobName=test.jcf UserId=root(0) GroupId=root(0) MCS_label=N/A" " Priority=4294901758 Nice=0 Account=root QOS=normal JobState=COMPLETED" @@ -1096,8 +1096,8 @@ def test_job_timelimit_reached( } """, ): - sacct_output = "3|root|root|all|1674340908|1674340980|TIMEOUT|500M||1|00:00.009|1|/root|00:01:12|0:0||test|node01|00:01:00|1|3|test.jcf\n" # noqa - sacct_output += "3.batch||||1674340908|1674340980|CANCELLED||4876K|1|00:00.009|1||00:01:12|0:15||test|node01|||3.batch|batch" # noqa + sacct_output = "3|root|root|all|1674340908|1674340980|TIMEOUT|500M||1|00:00.009|1|/root|00:01:12|0:0|||test|node01|00:01:00|1|3|test.jcf\n" # noqa + sacct_output += "3.batch||||1674340908|1674340980|CANCELLED||4876K|1|00:00.009|1||00:01:12|0:15|||test|node01|||3.batch|batch" # noqa scontrol_output = ( "JobId=3 JobName=test.jcf UserId=root(0) GroupId=root(0) MCS_label=N/A" " Priority=4294901757 Nice=0 Account=root QOS=normal JobState=TIMEOUT" @@ -1154,8 +1154,8 @@ def test_job_timelimit_50pc_reached( } """, ): - sacct_output = "3|root|root|all|1674770321|Unknown|RUNNING|500M||1|00:00:00|1|/root|00:02:22|0:0||test|node01|00:04:00|4|3|test.jcf\n" # noqa - sacct_output += "3.batch||||1674770321|Unknown|RUNNING|||1|00:00:00|1||00:02:22|0:0||test|node01|||3.batch|batch" # noqa + sacct_output = "3|root|root|all|1674770321|Unknown|RUNNING|500M||1|00:00:00|1|/root|00:02:22|0:0|||test|node01|00:04:00|4|3|test.jcf\n" # noqa + sacct_output += "3.batch||||1674770321|Unknown|RUNNING|||1|00:00:00|1||00:02:22|0:0|||test|node01|||3.batch|batch" # noqa mock_slurmmail_cli_run_command.side_effect = [(0, sacct_output, "")] slurmmail.cli.__dict__["__process_spool_file"]( pathlib.Path("/tmp/foo"),