2
############################################################################
3
# Purpose: Test of SLURM functionality
4
# Test scancel --nodelist option.
6
# Output: "TEST: #.#" followed by "SUCCESS" if test was successful, OR
7
# "FAILURE: ..." otherwise with an explanation of the failure, OR
8
# anything else indicates a failure mode that must be investigated.
9
############################################################################
10
# Copyright (C) 2008 Lawrence Livermore National Security
11
# Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
12
# Written by David Bremer <dbremer@llnl.gov>
13
# CODE-OCEC-09-009. All rights reserved.
15
# This file is part of SLURM, a resource management program.
16
# For details, see <https://computing.llnl.gov/linux/slurm/>.
17
# Please also read the included file: DISCLAIMER.
19
# SLURM is free software; you can redistribute it and/or modify it under
20
# the terms of the GNU General Public License as published by the Free
21
# Software Foundation; either version 2 of the License, or (at your option)
24
# SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
25
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
26
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
29
# You should have received a copy of the GNU General Public License along
30
# with SLURM; if not, write to the Free Software Foundation, Inc.,
31
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32
############################################################################
37
set file_in "test$test_id.input"
52
# Build input script file
54
make_bash_script $file_in "$srun $bin_sleep 600"
57
# Submit some jobs so we have something to work with
60
for {set ii 0} {$ii < $num_procs} {incr ii} {
61
set sbatch_pid [spawn $sbatch --output=/dev/null --error=/dev/null -n1 -N1 $file_in]
63
-re "Submitted batch job ($number)" {
64
set job_id $expect_out(1,string)
65
lappend submitted_jobs $job_id
69
send_user "\nFAILURE: sbatch not responding\n"
78
send_user "\nFAILURE: job submit failure\n"
84
# Run squeue and build a map, implemented as a list of list of lists, like so:
85
# { {node1 {job1 job2 job3}}
89
# Only put jobs into the map if they were submitted by this test.
92
spawn $squeue -h -t running -u $env(USER) -o "%10i %40N"
94
-re "($number) *($alpha_numeric) *\r\n" {
95
set job_id $expect_out(1,string)
96
set node_name $expect_out(2,string)
98
#This test doesn't need to track jobs that it didn't submit.
99
if { [lsearch $submitted_jobs $job_id] == -1 } {
102
#send_user "job $job_id: node $node_name\n"
103
#Insert into a table with node_name as the key, job_id as the value
105
for {set ii 0} {$ii < [llength $job_map]} {incr ii} {
106
if { [lindex [lindex $job_map $ii] 0] == $node_name } {
107
set tmp_map_entry [list $node_name [concat [lindex [lindex $job_map $ii] 1] $job_id]]
108
set job_map [lreplace $job_map $ii $ii $tmp_map_entry]
114
lappend job_map [list $node_name [list $job_id] ]
119
#send_user "job map: $job_map\n"
123
# Issue an scancel command against each node in the map described above.
124
# Remove entries from the internal list, and ensure that the list is
125
# empty at the end of the scancel call.
128
for {set ii 0} {$ii < [llength $job_map]} {incr ii} {
129
set node_name [lindex [lindex $job_map $ii] 0]
130
set job_list [lindex [lindex $job_map $ii] 1]
133
spawn $scancel -v -u $env(USER) --nodelist $node_name
135
spawn $scancel -v -u $env(USER) -w $node_name
138
-re "scancel: Terminating job ($number)" {
139
#Search for the terminated job in the list recently
140
#returned from squeue. Don't worry if an unknown job
141
#gets cancelled, because maybe one of our submitted
142
#jobs will start running while we cancel other jobs
143
#Issue cancel commands node by node until all the
144
#jobs submitted for this test are gone.
146
set job_id $expect_out(1,string)
147
set job_index [lsearch $job_list $job_id]
148
if {$job_index != -1} {
149
set job_list [lreplace $job_list $job_index $job_index]
151
set job_index [lsearch $submitted_jobs $job_id]
152
if {$job_index != -1} {
153
set submitted_jobs [lreplace $submitted_jobs $job_index $job_index]
158
send_user "\nFAILURE: scancel not responding while cancelling for node $node_name\n"
165
if { [llength $job_list] != 0 } {
166
send_user "\nFAILURE: scancel did not remove jobs $job_list from node $node_name\n"
172
# Clean up any jobs submitted by this test, which were not mapped to a node,
173
# and thus not cancelled in the previous block of code
176
foreach job_id $submitted_jobs {
177
spawn $scancel $job_id
180
send_user "\nFAILURE: scancel not responding while cancelling job $job_id\n"
191
if {$exit_code == 0} {
192
send_user "\nSUCCESS\n"