From 07e0dcf9e3dec6885dc2b7a0697fd682b4d31cf6 Mon Sep 17 00:00:00 2001
From: Morris Jette <jette@schedmd.com>
Date: Wed, 7 Mar 2012 11:37:43 -0800
Subject: [PATCH] Add sacct test using node names

---
 testsuite/expect/Makefile.am |   1 +
 testsuite/expect/Makefile.in |   1 +
 testsuite/expect/inc12.3.2   | 151 +++++++++++++++++++++++++++++++++++
 testsuite/expect/test12.3    | 102 +++++++++++------------
 4 files changed, 200 insertions(+), 55 deletions(-)
 create mode 100755 testsuite/expect/inc12.3.2

diff --git a/testsuite/expect/Makefile.am b/testsuite/expect/Makefile.am
index cfc428b1e8d..93608507eab 100644
--- a/testsuite/expect/Makefile.am
+++ b/testsuite/expect/Makefile.am
@@ -248,6 +248,7 @@ EXTRA_DIST = \
 	test12.2			\
 	test12.2.prog.c			\
 	test12.3			\
+	inc12.3.2			\
 	test12.4			\
 	test12.5			\
 	test13.1			\
diff --git a/testsuite/expect/Makefile.in b/testsuite/expect/Makefile.in
index 0b463249c7c..1161c38bafd 100644
--- a/testsuite/expect/Makefile.in
+++ b/testsuite/expect/Makefile.in
@@ -533,6 +533,7 @@ EXTRA_DIST = \
 	test12.2			\
 	test12.2.prog.c			\
 	test12.3			\
+	inc12.3.2			\
 	test12.4			\
 	test12.5			\
 	test13.1			\
diff --git a/testsuite/expect/inc12.3.2 b/testsuite/expect/inc12.3.2
new file mode 100755
index 00000000000..e8c1fe24135
--- /dev/null
+++ b/testsuite/expect/inc12.3.2
@@ -0,0 +1,151 @@
+#!/usr/bin/expect
+############################################################################
+# Purpose: Test for accounting records of specific jobs on specific nodes
+# This is a sub-test of test12.3
+############################################################################
+# Copyright (C) 2012 SchedMD LLC.
+# Written by Nathan Yee <nyee32@schedmd.com>
+#
+# This file is part of SLURM, a resource management program.
+# For details, see <http://www.schedmd.com/slurmdocs/>.
+# 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
+source ./globals_accounting
+
+proc inc12_3_2 {job_id_1 job_id_2 job_name_1 job_name_2 test_acct job_1_node_0 job_1_node_2 job_2_node_1 job_2_node_2} {
+	
+	global alpha_numeric_under sacct
+	global exit_code
+
+	send_user "\nSearch for jobs on node: $job_1_node_0\n"
+	set job_1_match 0
+	set job_2_match 0
+	spawn $sacct -A '$test_acct' -N$job_1_node_0
+	expect {
+	
+		-re "$job_id_1" {
+			incr job_1_match
+		 	exp_continue 
+		}
+		-re "$job_id_2" {
+			incr job_2_match
+			exp_continue
+		}
+		timeout {
+			send_user "\nFAILURE: sacct did not respond\n"
+			set exit_code 1
+		}
+		eof {
+			wait
+		}
+	}
+	if {$job_1_match != 1} {
+		send_user "\nFAILURE:sacct was unable to find the job $job_id_1 on node $job_1_node_0 ($job_1_match != 1)\n"
+		set exit_code 1
+	}
+	if {$job_2_match != 0} {
+		send_user "\nFAILURE:sacct was found job $job_id_2 on node $job_1_node_0 ($job_2_match != 0)\n"
+		set exit_code 1
+	}
+
+
+	send_user "\nSearch for jobs on node: $job_1_node_2\n"
+	set job_1_match 0
+	set job_2_match 0
+	spawn $sacct -A '$test_acct' -N$job_1_node_2
+	expect {
+	
+		-re "$job_id_1" {
+			incr job_1_match
+		 	exp_continue 
+		}
+		-re "$job_id_2" {
+			incr job_2_match
+			exp_continue
+		}
+		timeout {
+			send_user "\nFAILURE: sacct did not respond\n"
+			set exit_code 1
+		}
+		eof {
+			wait
+		}
+	}
+	if {$job_1_match != 1} {
+		send_user "\nFAILURE:sacct was unable to find the job $job_id_1 on node $job_1_node_2 ($job_1_match != 1)\n"
+		set exit_code 1
+	}
+
+
+	send_user "\nSearch for jobs on node: $job_2_node_1\n"
+	set job_1_match 0
+	set job_2_match 0
+	spawn $sacct -A '$test_acct' -N$job_2_node_1
+	expect {
+	
+		-re "$job_id_1" {
+			incr job_1_match
+		 	exp_continue 
+		}
+		-re "$job_id_2" {
+			incr job_2_match
+			exp_continue
+		}
+		timeout {
+			send_user "\nFAILURE: sacct did not respond\n"
+			set exit_code 1
+		}
+		eof {
+			wait
+		}
+	}
+	if {$job_2_match != 1} {
+		send_user "\nFAILURE:sacct was unable to find the job $job_id_2 on node $job_2_node_1 ($job_2_match != 1)\n"
+		set exit_code 1
+	}
+
+
+	send_user "\nSearch for jobs on node: $job_2_node_2\n"
+	set job_1_match 0
+	set job_2_match 0
+	spawn $sacct -A '$test_acct' -N$job_2_node_2
+	expect {
+	
+		-re "$job_id_1" {
+			incr job_1_match
+		 	exp_continue 
+		}
+		-re "$job_id_2" {
+			incr job_2_match
+			exp_continue
+		}
+		timeout {
+			send_user "\nFAILURE: sacct did not respond\n"
+			set exit_code 1
+		}
+		eof {
+			wait
+		}
+	}
+	
+	if {$job_2_match != 1} {
+		send_user "\nFAILURE: sacct was unable to find the job $job_id_2 on node $job_2_node_2 ($job_2_match != 1)\n"
+		set exit_code 1
+	}
+}
+
diff --git a/testsuite/expect/test12.3 b/testsuite/expect/test12.3
index 0fdfc3bcdeb..9e175cdd0a1 100755
--- a/testsuite/expect/test12.3
+++ b/testsuite/expect/test12.3
@@ -34,13 +34,14 @@
 ############################################################################
 source ./globals
 source ./globals_accounting
+source ./inc12.3.2
 
 set test_id     "12.3"
 set exit_code   0
-set file_in     "test.$test_id.input"
 set job_name_1  "JOB1"
 set job_name_2  "JOB2"
-set ta		"slurm_test-account.1"
+set file_in     "test.$test_id.input"
+set test_acct	"slurm_test-account.1"
 
 print_header $test_id
 
@@ -49,15 +50,27 @@ print_header $test_id
 #
 if { [test_account_storage] == 0 } {
 	send_user "\nWARNING: This test can't be run without a usable AccountStorageType\n"
-	exit 0
+	exit $exit_code
 }
 
 if { [string compare [check_accounting_admin_level] "Administrator"] } {
 	send_user "\nWARNING: This test can't be run without being an Accounting administrator.\n"
 	send_user "Use sacctmgr mod user \$USER_NAME set admin=admin.\n"
-	exit 0
+	exit $exit_code
 }
 
+#
+# Make sure we have enough nodes to test functionality
+#
+set partition [default_partition]
+set node_count [get_node_cnt_in_part $partition]
+if { $node_count < 3 } {
+	send_user "WARNING: system must have at least 3 \
+		   nodes to run this test on.  This system \
+		   only has $node_count.\n"
+	exit $exit_code
+}
+	
 #
 # Identify the user and his current default account
 #
@@ -90,17 +103,17 @@ expect {
 }
 
 #
-# Use sacctmgr to add an account
+# Use sacctmgr to add a test account
 #
 set aamatches 0
-set sadd_pid [spawn $sacctmgr -i add account $ta]
+set sadd_pid [spawn $sacctmgr -i add account $test_acct]
 expect {
 	-re "Adding Account" {
 		incr aamatches
 		exp_continue
 	}
 	-re "Nothing new added" {
-		send_user "\nWARNING: vestigial account $ta found\n"
+		send_user "\nWARNING: vestigial account $test_acct found\n"
 		incr aamatches
 		exp_continue
 	}
@@ -121,7 +134,7 @@ if {$aamatches != 1} {
 #
 # Add self to this new account
 #
-set sadd_pid [spawn $sacctmgr -i create user name=$user_name account=$ta]
+set sadd_pid [spawn $sacctmgr -i create user name=$user_name account=$test_acct]
 expect {
 	 timeout {
 		send_user "\nFAILURE: sacctmgr add not responding\n"
@@ -134,16 +147,18 @@ expect {
 }
 
 #
-# Submit two slurm jobs that will execute 'id'
+# Submit two slurm jobs to capture job info
 #
 set job_id_1 0
+set job_1_node_inx 0
 set timeout $max_job_delay
-set srun_pid [spawn $srun -N1 -t1 -A $ta -J $job_name_1 -v $bin_id]
+set srun_pid [spawn $srun -N2 -t1 -A $test_acct -J $job_name_1 -v $bin_id]
 expect {
-	-re "launching ($number)" {
+	-re "launching ($number).0 on host ($alpha_numeric_under)," {
 		set job_id_1 $expect_out(1,string)
+		set job_1_node($job_1_node_inx) $expect_out(2,string)
+		incr job_1_node_inx
 		exp_continue
-		
 	}
 	timeout {
 		send_user "\nFAILURE: srun not responding\n"
@@ -154,15 +169,24 @@ expect {
 		wait
 	}
 }
+if {$job_1_node_inx != 2} {
+	send_user "\nFAILURE: srun host count bad ($job_1_node_inx != 2)\n"
+	exit 1
+}	
 
+#
+# Second job explicitly excludes node zero from previous job
+#
 set job_id_2 0
-set timeout $max_job_delay
-set srun_pid [spawn $srun -N1 -t1 -A $ta -J $job_name_2 -v $bin_id]
+set job_2_node_inx 0
+set srun_pid [spawn $srun -N2 -x $job_1_node(0) -t1 -A $test_acct -J $job_name_2 -v $bin_id]
 expect {
-	-re "launching ($number)" {
+
+	-re "launching ($number).0 on host ($alpha_numeric_under)," {
 		set job_id_2 $expect_out(1,string)
+		set job_2_node($job_2_node_inx) $expect_out(2,string)
+		incr job_2_node_inx
 		exp_continue
-		
 	}
 	timeout {
 		send_user "\nFAILURE: srun not responding\n"
@@ -173,6 +197,10 @@ expect {
 		wait
 	}
 }
+if {$job_2_node_inx != 2} {
+	send_user "\nFAILURE: srun host count bad ($job_2_node_inx != 2)\n"
+	exit 1
+}
 
 #
 # Wait for accounting data to be propagated to slurmdbd
@@ -180,51 +208,15 @@ expect {
 sleep 5
 
 #
-# Matches the job name with the job id
+# Execute sub-tests based upon these jobs
 #
-set idmatch 0
-send_user "\nJob id1 number: $job_id_1\n"
-spawn $sacct -A '$ta' --name=$job_name_1 -p -o jobid
-expect {
-	-re "$job_id_1" {
-		incr idmatch
-		exp_continue
-	}
-	timeout {
-		send_user "\nFAILURE: sacct not responding\n"
-		set exit_code 1
-	}
-	eof {
-		wait
-	}
-
-}
-
-send_user "\nJob id2 number: $job_id_2\n"
-spawn $sacct -A '$ta' --name=$job_name_2 -p -o jobid
-expect {
-	-re "$job_id_2" {
-		incr idmatch
-		exp_continue
-	}
-	timeout {
-		send_user "\nFAILURE: sacct not responding\n"
-		set exit_code 1
-	}
-	eof {
-		wait
-	}
-}
-if {$idmatch != 2} {
-	send_user "\nFAILURE: sacct could not match job id to job name\n"
-	set exit_code 1
-}
+inc12_3_2 $job_id_1 $job_id_2 $job_name_1 $job_name_2 $test_acct $job_1_node(0) $job_1_node(1) $job_2_node(0) $job_2_node(1)
 
 #
 # Use sacctmgr to delete the test account
 #
 set damatches 0
-set sadel_pid [spawn $sacctmgr -i delete account $ta]
+set sadel_pid [spawn $sacctmgr -i delete account $test_acct]
 expect {
 	-re "Deleting account" {
 		incr damatches
-- 
GitLab