From 5b5f6b3519b7cb96622f84f5bf731654ed31b2c9 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Wed, 10 Feb 2010 21:36:05 +0000
Subject: [PATCH] Add test to set/update a job step's time limit

---
 doc/man/man3/slurm_update_job.3 |   2 +
 testsuite/expect/Makefile.am    |   1 +
 testsuite/expect/Makefile.in    |   1 +
 testsuite/expect/README         |   1 +
 testsuite/expect/test2.13       | 146 ++++++++++++++++++++++++++++++++
 5 files changed, 151 insertions(+)
 create mode 100755 testsuite/expect/test2.13

diff --git a/doc/man/man3/slurm_update_job.3 b/doc/man/man3/slurm_update_job.3
index 789c73478d8..a038fec9da7 100644
--- a/doc/man/man3/slurm_update_job.3
+++ b/doc/man/man3/slurm_update_job.3
@@ -72,6 +72,8 @@ code.
 \fBESLURM_ACCESS_DENIED\fR The requesting user lacks authorization for
 the requested action (e.g. trying to modify another user's job).
 .LP
+\fBESLURM_INVALID_JOB_ID\fR  Invalid job or step ID value.
+.LP
 \fBESLURM_INVALID_TIME_VALUE\fR  Invalid time value.
 
 .SH "EXAMPLE"
diff --git a/testsuite/expect/Makefile.am b/testsuite/expect/Makefile.am
index 5e6d55a3503..3bffcdc84d5 100644
--- a/testsuite/expect/Makefile.am
+++ b/testsuite/expect/Makefile.am
@@ -105,6 +105,7 @@ EXTRA_DIST = \
 	test2.10			\
 	test2.11			\
 	test2.12			\
+	test2.13			\
 	test3.1				\
 	test3.2				\
 	test3.3				\
diff --git a/testsuite/expect/Makefile.in b/testsuite/expect/Makefile.in
index ac1032dd59d..cd312596ddd 100644
--- a/testsuite/expect/Makefile.in
+++ b/testsuite/expect/Makefile.in
@@ -369,6 +369,7 @@ EXTRA_DIST = \
 	test2.10			\
 	test2.11			\
 	test2.12			\
+	test2.13			\
 	test3.1				\
 	test3.2				\
 	test3.3				\
diff --git a/testsuite/expect/README b/testsuite/expect/README
index dce472d9473..3a0214a4647 100644
--- a/testsuite/expect/README
+++ b/testsuite/expect/README
@@ -201,6 +201,7 @@ test2.9    Validate scontrol completing command.
 test2.10   Validate scontrol oneliner mode (--oneliner option).
 test2.11   Validate scontrol listpids command.
 test2.12   Validate scontrol show topology option.
+test2.13   Validate scontrol update command for job steps.
 
 
 test3.#    Testing of scontrol options (best run as SlurmUser or root).
diff --git a/testsuite/expect/test2.13 b/testsuite/expect/test2.13
new file mode 100755
index 00000000000..abbf9d7d530
--- /dev/null
+++ b/testsuite/expect/test2.13
@@ -0,0 +1,146 @@
+#!/usr/bin/expect
+############################################################################
+# Purpose: Test of SLURM functionality
+#          Validate scontrol update command for job steps.
+#
+# Output:  "TEST: #.#" followed by "SUCCESS" if test was successful, OR
+#          "FAILURE: ..." otherwise with an explanation of the failure, OR
+#          anything else indicates a failure mode that must be investigated.
+############################################################################
+# Copyright (C) 2010 Lawrence Livermore National Security.
+# Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
+# Written by Morris Jette <jette1@llnl.gov>
+# CODE-OCEC-09-009. All rights reserved.
+#
+# This file is part of SLURM, a resource management program.
+# For details, see <https://computing.llnl.gov/linux/slurm/>.
+# Please also read the included file: DISCLAIMER.
+#
+# SLURM is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your option)
+# any later version.
+#
+# SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along
+# with SLURM; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
+############################################################################
+source ./globals
+
+set test_id       "2.13"
+set exit_code     0
+set file_in       "test$test_id.input"
+set job_id        0
+set orig_time     0
+set new_time      0
+
+print_header $test_id
+
+#
+# Build input script file
+#
+make_bash_script $file_in "$srun -t5 $bin_sleep 60"
+
+#
+# Submit a job so we have something to work with
+#
+set srun_pid [spawn $sbatch --output=/dev/null --error=/dev/null -t1 $file_in]
+expect {
+	-re "Submitted batch job ($number)" {
+		set job_id $expect_out(1,string)
+		exp_continue
+	}
+	timeout {
+		send_user "\nFAILURE: srun not responding\n"
+		slow_kill $srun_pid
+		set exit_code 1
+	}
+	eof {
+		wait
+	}
+}
+exec $bin_rm -f $file_in
+if {$job_id == 0} {
+	send_user "\nFAILURE: srun failed to initiate job\n"
+	exit 1
+}
+#
+# Wait for job and step to start running
+#
+if {[wait_for_job $job_id "RUNNING"] != 0} {
+        send_user "\nFAILURE: waiting for job to start running\n"
+        exit 1
+}
+sleep 5
+
+#
+# Validate that step's origianl time limit
+#
+spawn  $scontrol show step $job_id.0
+expect {
+	-re "TimeLimit=00:($number):00" {
+		set orig_time $expect_out(1,string)
+		exp_continue
+	}
+	timeout {
+		send_user "\nFAILURE: scontrol not responding\n"
+		set exit_code 1
+	}
+	eof {
+		wait
+	}
+}
+if {$orig_time != 5} {
+        send_user "\nFAILURE: Failed to set step initial time limit\n"
+	set exit_code 1
+}
+
+#
+# Change that job's priority
+#
+spawn $scontrol update StepId=$job_id TimeLimit=12
+expect {
+	timeout {
+		send_user "\nFAILURE: scontrol not responding\n"
+		set exit_code 1
+	}
+	eof {
+		wait
+	}
+}
+
+#
+# Validate that step's new time limit
+#
+spawn  $scontrol show step $job_id.o
+expect {
+	-re "TimeLimit=00:($number):00" {
+		set orig_time $expect_out(1,string)
+		exp_continue
+	}
+	timeout {
+		send_user "\nFAILURE: scontrol not responding\n"
+		set exit_code 1
+	}
+	eof {
+		wait
+	}
+}
+if {$orig_time != 12} {
+        send_user "\nFAILURE: Failed to update step time limit\n"
+	set exit_code 1
+}
+
+if {[cancel_job $job_id] != 0} {
+	set exit_code 1
+}
+if {$exit_code == 0} {
+	send_user "\nSUCCESS\n"
+}
+exit $exit_code
+
-- 
GitLab