From e64fa99fc83d5cd03df5527d86ae887371daae69 Mon Sep 17 00:00:00 2001
From: Brian Christiansen <brian@schedmd.com>
Date: Tue, 25 Oct 2016 08:49:25 -0600
Subject: [PATCH] test21.36: clean up created test cluster when done

The test cluster had jobs in the job table which prevented the cluster
from being deleted. This also caused problems for other tests because
accounts would be added to the test cluster and the accounts couldn't be
deleted because the cluster still had jobs.
---
 testsuite/expect/test21.36 | 46 +++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/testsuite/expect/test21.36 b/testsuite/expect/test21.36
index 4f64a07d0cf..60a3310ee9b 100755
--- a/testsuite/expect/test21.36
+++ b/testsuite/expect/test21.36
@@ -52,17 +52,35 @@ set acct_req(cluster) $cluster
 set user_req(account) $account
 set user_req(cluster) $cluster
 
+exec $bin_rm -f $sql_query $sql_query_rem
+
+# DON'T MESS WITH THIS UNLESS YOU REALLY UNDERSTAND WHAT YOU ARE DOING!!!!!
+# THIS COULD SERIOUSLY MESS UP YOUR DATABASE IF YOU ALTER THIS INCORRECTLY
+# JUST A FRIENDLY REMINDER ;)
+
+# Insert a job that has no end time and is still in running state
+set file [open $sql_query "w"]
+puts $file "insert into job_table (jobid, associd, wckey, wckeyid, uid, gid, `partition`, blockid, cluster, account, eligible, submit, start, end, suspended, name, track_steps, state, comp_code, priority, req_cpus, tres_alloc, nodelist, kill_requid, qos, deleted) values"
+puts $file "('65536', '6', 'test21-36wckey', '1', '1002', '1002', 'debug', '', '$cluster', '$account', 1199170800, 1199170800, 1199170800, 0, '0', 'test21.32_job1', '0', '1', '0', '2', 2, '1=2', 'test21.36_node', '0', '0', '0')"
+puts $file "on duplicate key update id=LAST_INSERT_ID(id), eligible=VALUES(eligible), submit=VALUES(submit), start=VALUES(start), end=VALUES(end), associd=VALUES(associd), tres_alloc=VALUES(tres_alloc), wckey=VALUES(wckey), wckeyid=VALUES(wckeyid);"
+close $file
+
+# Make SQL file to remove the inserted job
+set file [open $sql_query_rem "w"]
+puts $file [format "%s%s%s" "truncate table \"" $cluster "_job_table\";"]
+close $file
+
 # Remove pre-existing items
 proc cleanup { } {
-	global cluster account user bin_rm sql_query sql_query_rem
-	remove_cluster "$cluster"
-	remove_acct "" $account
+	global cluster account user sql_query_rem
+	archive_load $sql_query_rem
 	remove_user "" "" $user
-	exec $bin_rm -f $sql_query $sql_query_rem
+	remove_acct "" $account
+	remove_cluster "$cluster"
 }
 
 proc endit { } {
-	global exit_code
+	global exit_code bin_rm sql_query sql_query_rem
 	cleanup
 
 	if {$exit_code == 0} {
@@ -71,6 +89,8 @@ proc endit { } {
 		send_user "\nFAILURE\n"
 	}
 
+	exec $bin_rm -f $sql_query $sql_query_rem
+
 	exit $exit_code
 }
 
@@ -85,22 +105,6 @@ if {[test_using_slurmdbd] == 0} {
 # Remove pre-existing items
 cleanup
 
-# DON'T MESS WITH THIS UNLESS YOU REALLY UNDERSTAND WHAT YOU ARE DOING!!!!!
-# THIS COULD SERIOUSLY MESS UP YOUR DATABASE IF YOU ALTER THIS INCORRECTLY
-# JUST A FRIENDLY REMINDER ;)
-
-# Insert a job that has no end time and is still in running state
-set file [open $sql_query "w"]
-puts $file "insert into job_table (jobid, associd, wckey, wckeyid, uid, gid, `partition`, blockid, cluster, account, eligible, submit, start, end, suspended, name, track_steps, state, comp_code, priority, req_cpus, tres_alloc, nodelist, kill_requid, qos, deleted) values"
-puts $file "('65536', '6', 'test21-36wckey', '1', '1002', '1002', 'debug', '', '$cluster', '$account', 1199170800, 1199170800, 1199170800, 0, '0', 'test21.32_job1', '0', '1', '0', '2', 2, '1=2', 'test21.36_node', '0', '0', '0')"
-puts $file "on duplicate key update id=LAST_INSERT_ID(id), eligible=VALUES(eligible), submit=VALUES(submit), start=VALUES(start), end=VALUES(end), associd=VALUES(associd), tres_alloc=VALUES(tres_alloc), wckey=VALUES(wckey), wckeyid=VALUES(wckeyid);"
-close $file
-
-# Make SQL file to remove the inserted job
-set file [open $sql_query_rem "w"]
-puts $file [format "%s%s%s" "truncate table \"" $cluster "_job_table\";"]
-close $file
-
 # Add Test Cluster
 if {[add_cluster $cluster [array get clus_req]]} {
 	endit
-- 
GitLab