From 92f8e464363e4c48f9df35b5083fecc94c8760ac Mon Sep 17 00:00:00 2001
From: Marshall Garey <marshall@schedmd.com>
Date: Fri, 5 Jan 2018 16:18:01 -0700
Subject: [PATCH] Add tests for resv FIRST_CORES & IGNORE_JOBS

Bug 4329
Bug 4312
---
 testsuite/expect/inc3.11.9 | 205 +++++++++++++++++++++++++++++++++++++
 1 file changed, 205 insertions(+)

diff --git a/testsuite/expect/inc3.11.9 b/testsuite/expect/inc3.11.9
index 83e686040b4..3b8468ac635 100644
--- a/testsuite/expect/inc3.11.9
+++ b/testsuite/expect/inc3.11.9
@@ -572,4 +572,209 @@ proc inc3_11_9 {} {
 
 	set ret_code [delete_res $res_name1]
 	set ret_code [delete_res $res_name]
+	if { $ret_code != 0 } {
+		send_user "FAILURE: failed to delete reservations.\n"
+		exit $ret_code
+	}
+
+	# Create a job that uses all cores in the node range and is not
+	# part of a reservation.
+	set sbatch_pid [spawn $sbatch --ntasks-per-node=$cores_per_node --nodelist=$def_node_name\[$min_node_inx\-$max_node_inx\] --output=/dev/null $file_in]
+	expect {
+		-re "Submitted batch job ($number)" {
+			set job_id $expect_out(1,string)
+			exp_continue
+		}
+		timeout {
+			send_user "\nFAILURE: sbatch not responding (within: inc3.11.9)\n"
+			slow_kill $sbatch_pid
+			set exit_code 1
+		}
+		eof {
+			wait
+		}
+	}
+	if {$job_id == 0} {
+		send_user "\nFAILURE: batch submit failure\n"
+		exit 1
+	}
+
+	sleep 10
+
+	# Verify the job is running.
+	spawn $scontrol show job $job_id
+	expect {
+		-re "Invalid job id specified" {
+			send_user "\nFAILURE: Job $job_id not found (Within: inc3.11.9)\n"
+			set exit_code 1
+			exp_continue
+		}
+		-re "JobState=RUNNING" {
+			send_user "\nJob is RUNNING as expected (Within: inc3.11.9)\n"
+			exp_continue
+		}
+		timeout {
+			send_user "\nFAILURE: scontrol not responding (Within: inc3.11.9)\n"
+			set exit_code 1
+		}
+		eof {
+			wait
+		}
+	}
+	if { $exit_code == 1 } {
+		exit $exit_code
+	}
+
+	# Make the reservation using more cores than free, but use the
+	# IGNORE_JOBS and FIRST_CORES flags. Verify that it is created with the
+	# correct nodes, CoreCnt, and CoreIDs.
+
+	set ret_code [create_res "StartTime=now Duration=60 Nodes=$def_node_name\[$min_node_inx\-$max_node_inx\] CoreCnt=2,2,2,2,$cores_per_node User=$user_name Flags=IGNORE_JOBS,FIRST_CORES" 0]
+	if {$ret_code == 1} {
+		send_user "\nFAILURE: Reservation can not be created when it should (Within: inc3.11.9)\n"
+		cancel_job $job_id
+		exit $ret_code
+	}
+	send_user "\nSUCCESS: Reservation can be created as expected (Within 3.11.9)\n"
+
+	set exp_node_cnt [expr {$max_node_inx-$min_node_inx+1}]
+	set exp_core_cnt [expr {8+$cores_per_node}]
+	set hosts_correct 0
+	set node_cnt_correct 0
+	set core_cnt_correct 0
+	set core_ids_correct 0
+
+	set node_inxs [subst {
+		$min_node_inx
+		[expr {$min_node_inx+1}]
+		[expr {$min_node_inx+2}]
+		[expr {$min_node_inx+3}]
+		$max_node_inx
+	}]
+	set exp_core_ids [subst {
+		0-1 0-1 0-1 0-1 0-[expr {$cores_per_node-1}]
+	}]
+
+	sleep 5
+
+	spawn $scontrol show res
+	expect {
+		-re "Nodes=$def_node_name\\\[$min_node_inx\-$max_node_inx" {
+			set hosts_correct 1
+			exp_continue
+		}
+		-re "NodeCnt=$exp_node_cnt" {
+			set node_cnt_correct 1
+			exp_continue
+		}
+		-re "CoreCnt=$exp_core_cnt" {
+			set core_cnt_correct  1
+			exp_continue
+		}
+		-re "NodeName=$def_node_name\(\\d+\) CoreIDs=\(0-\\d+\)" {
+			set node_id $expect_out(1,string)
+			set core_id $expect_out(2,string)
+			if { $node_id == [lindex $node_inxs $core_ids_correct] &&
+				$core_id == [lindex $exp_core_ids $core_ids_correct]} {
+				incr core_ids_correct
+			}
+			exp_continue
+		}
+		timeout {
+			send_user "\nFAILURE: scontrol not responding (Within: inc3.11.9)\n"
+			set exit_code 1
+		}
+		eof {
+			wait
+		}
+	}
+	if {$hosts_correct != 1} {
+		send_user "\nFAILURE: Reservation has incorrect node list\n"
+		set exit_code 1
+	}
+	if {$node_cnt_correct != 1} {
+		send_user "\nFAILURE: Reservation has incorrect node count\n"
+		set exit_code 1
+	}
+	if {$core_cnt_correct != 1} {
+		send_user "\nFAILURE: Reservation has incorrect core cnt\n"
+		set exit_code 1
+	}
+	if {$core_ids_correct != $exp_node_cnt} {
+		send_user "\nFAILURE: Reservation has incorrect core ids\n"
+		set exit_code 1
+	}
+	if {$exit_code == 0} {
+		send_user "\nSUCCESS: Reservation has correct nodes, CoreCnt, and CoreIDs.\n"
+	}
+
+	cancel_job $job_id
+	set ret_code [delete_res $res_name]
+
+	if { $ret_code != 0 } {
+		send_user "\nFAILURE: Error $ret_code deleting reservation.\n"
+		set exit_code 1
+	}
+	if { $exit_code == 1 } {
+		exit $exit_code
+	}
+
+
+	# Create a job that runs on a single core on all nodes in the reservation.
+
+	set sbatch_pid [spawn $sbatch --ntasks-per-node=1 --nodelist=$def_node_name\[$min_node_inx\-$max_node_inx\] --output=/dev/null $file_in]
+	expect {
+		-re "Submitted batch job ($number)" {
+			set job_id $expect_out(1,string)
+			exp_continue
+		}
+		timeout {
+			send_user "\nFAILURE: sbatch not responding (within: inc3.11.9)\n"
+			slow_kill $sbatch_pid
+			set exit_code 1
+		}
+		eof {
+			wait
+		}
+	}
+	if {$job_id == 0} {
+		send_user "\nFAILURE: batch submit failure\n"
+		exit 1
+	}
+
+	sleep 10
+
+	spawn $scontrol show job $job_id
+	expect {
+		-re "Invalid job id specified" {
+			send_user "\nFAILURE: Job $job_id not found (Within: inc3.11.9)\n"
+			set exit_code 1
+			exp_continue
+		}
+		-re "JobState=RUNNING" {
+			send_user "\nJob is RUNNING as expected (Within: inc3.11.9)\n"
+			exp_continue
+		}
+		timeout {
+			send_user "\nFAILURE: scontrol not responding (Within: inc3.11.9)\n"
+			set exit_code 1
+		}
+		eof {
+			wait
+		}
+	}
+	if { $exit_code == 1 } {
+		exit $exit_code
+	}
+
+	# Make the reservation with the FIRST_CORES flag. It should fail
+	# to be created even though there are enough cores because the
+	# FIRST_CORES flag requires the lowest numbered cores.
+	set ret_code [create_res "StartTime=now Duration=60 Nodes=$def_node_name\[$min_node_inx\-$max_node_inx\] CoreCnt=1,1,1,1,1 User=$user_name Flags=FIRST_CORES" 1]
+	if {$ret_code == 0} {
+		send_user "\nFAILURE: Reservation can be created when it should not (Within: inc3.11.9)\n"
+		exit 1
+	}
+	send_user "\nSUCCESS: Reservation can not be created as expected (Within 3.11.9)\n"
+	cancel_job $job_id
 }
-- 
GitLab