From 7dfb72499a6fe92d62eaf1de268c4945d328679f Mon Sep 17 00:00:00 2001
From: Isaac Hartung <ihartung@schedmd.com>
Date: Fri, 20 Jan 2017 11:29:41 -0700
Subject: [PATCH] Testsuite: created global proc get_my_id and made tests
 consistent.

---
 testsuite/expect/globals   | 39 ++++++++++++++++++++++++++++++++++++++
 testsuite/expect/test1.1   | 17 +----------------
 testsuite/expect/test1.17  | 17 ++---------------
 testsuite/expect/test1.49  | 13 ++-----------
 testsuite/expect/test1.8   | 17 ++---------------
 testsuite/expect/test15.4  | 17 +----------------
 testsuite/expect/test17.33 | 16 +---------------
 testsuite/expect/test17.4  | 17 +----------------
 8 files changed, 49 insertions(+), 104 deletions(-)

diff --git a/testsuite/expect/globals b/testsuite/expect/globals
index fe874089e14..7e839f3c3f9 100755
--- a/testsuite/expect/globals
+++ b/testsuite/expect/globals
@@ -319,6 +319,45 @@ proc slow_kill { pid } {
 	return 0
 }
 
+################################################################
+#
+# Proc: get_my_id
+#
+# Purpose:  gets the id from the running user
+#
+# Returns: output of id
+#
+#
+################################################################
+
+proc get_my_id {} {
+
+	global bin_id number
+	set login_info -1
+
+	log_user 0
+
+	spawn $bin_id
+	expect {
+		-re "(uid=.*\n)" {
+			set login_info $expect_out(1,string)
+			exp_continue
+		}
+		eof {
+			wait
+		}
+	}
+
+	log_user 1
+
+	if {$login_info == -1} {
+		send_user "\nFAILURE: Unable to get user info\n"
+		exit 1
+	}
+
+	return $login_info
+}
+
 ################################################################
 #
 # Proc: get_my_user_name
diff --git a/testsuite/expect/test1.1 b/testsuite/expect/test1.1
index fc52c3dc54e..c0f0f7adbf4 100755
--- a/testsuite/expect/test1.1
+++ b/testsuite/expect/test1.1
@@ -50,22 +50,7 @@ if {[test_front_end] != 0 && [test_super_user] == 0} {
 # Execute 'id' to determine my user and group ID...
 #
 
-spawn $bin_id
-expect {
-        -re "(uid=.*\n)" {
-		set login_grp_info $expect_out(1,string)
-		set got_login_grps 1
-		exp_continue
-	}
-	eof {
-		wait
-	}
-}
-
-if {$got_login_grps == 0} {
-	send_user "\nFAILURE: Unable to get user and group ID info\n"
-	exit 1
-}
+set login_grp_info [get_my_id]
 
 #
 # Submit a slurm job that will execute 'id'
diff --git a/testsuite/expect/test1.17 b/testsuite/expect/test1.17
index 3af20ad727f..4ed21aa4dab 100755
--- a/testsuite/expect/test1.17
+++ b/testsuite/expect/test1.17
@@ -59,17 +59,8 @@ exec echo "$bin_echo INITIAL_VALUE" >$file_out
 #
 # Get user id and group id for comparison with stdout
 #
-spawn $bin_id
-expect {
-	-re "(uid=$number)" {
-		set login_grp_info $expect_out(1,string)
-		set got_login_grps 1
-		exp_continue
-	}
-	eof {
-		wait
-	}
-}
+
+set login_grp_info "uid=[get_my_uid]"
 
 #
 # Spawn a shell via srun that uses stdin/out/err in truncate mode
@@ -109,10 +100,6 @@ if {[wait_for_file $file_out] == 0} {
 	}
 }
 
-if {$got_login_grps == 0} {
-	send_user "\nFAILURE: Unable to get user and group ID info\n"
-	set exit_code 1
-}
 if {$got_job_grps != 1} {
 	send_user "\nFAILURE: User and group ID info missing from stdout\n"
 	set exit_code 1
diff --git a/testsuite/expect/test1.49 b/testsuite/expect/test1.49
index 4be5a790798..8bba283ad5c 100755
--- a/testsuite/expect/test1.49
+++ b/testsuite/expect/test1.49
@@ -135,17 +135,8 @@ if {$matches != $exp_matches} {
 #
 # Get my id to compare with output
 #
-set my_uid -1
-spawn $bin_id
-expect {
-	-re "uid=($number)" {
-		set my_uid $expect_out(1,string)
-		exp_continue
-	}
-	eof {
-		wait
-	}
-}
+
+set my_uid [get_my_uid]
 
 #
 # Make sure we have two records in both prolog and epilog output (one for each task)
diff --git a/testsuite/expect/test1.8 b/testsuite/expect/test1.8
index 7abe5a5a68b..61413948faf 100755
--- a/testsuite/expect/test1.8
+++ b/testsuite/expect/test1.8
@@ -89,17 +89,8 @@ expect {
 #
 # Check user id and group id in stdout
 #
-spawn $bin_id
-expect {
-	-re "(uid=.*\n)" {
-		set login_grp_info $expect_out(1,string)
-		set got_login_grps 1
-		exp_continue
-	}
-	eof {
-		wait
-	}
-}
+
+set login_grp_info [get_my_id]
 
 if {[wait_for_file $file_out] == 0} {
 	spawn $bin_cat $file_out
@@ -115,10 +106,6 @@ if {[wait_for_file $file_out] == 0} {
 	}
 }
 
-if {$got_login_grps == 0} {
-	send_user "\nFAILURE: Unable to get user and group ID info\n"
-	set exit_code 1
-}
 if {$got_job_grps == 0} {
 	send_user "\nFAILURE: User and group ID info missing from stdout\n"
 	set exit_code 1
diff --git a/testsuite/expect/test15.4 b/testsuite/expect/test15.4
index 7807f54521b..a8adfc822c0 100755
--- a/testsuite/expect/test15.4
+++ b/testsuite/expect/test15.4
@@ -50,22 +50,7 @@ if {[test_front_end] != 0} {
 # Execute 'id' to determine my user and group ID...
 #
 
-spawn $bin_id
-expect {
-        -re "(uid=.*\n)" {
-		set login_grp_info $expect_out(1,string)
-		set got_login_grps 1
-		exp_continue
-	}
-	eof {
-		wait
-	}
-}
-
-if {$got_login_grps == 0} {
-	send_user "\nFAILURE: Unable to get user and group ID info\n"
-	exit 1
-}
+set login_grp_info [get_my_id]
 
 #
 # Submit a slurm job that will execute 'id'
diff --git a/testsuite/expect/test17.33 b/testsuite/expect/test17.33
index e2c2087f7be..da52bb1296f 100755
--- a/testsuite/expect/test17.33
+++ b/testsuite/expect/test17.33
@@ -59,17 +59,7 @@ exec echo "$bin_echo INITIAL_VALUE" >$file_out
 #
 # Get user id and group id for comparison with stdout
 #
-spawn $bin_id
-expect {
-	-re "(uid=$number)" {
-		set login_grp_info $expect_out(1,string)
-		set got_login_grps 1
-		exp_continue
-	}
-	eof {
-		wait
-	}
-}
+set login_grp_info "uid=[get_my_uid]"
 
 #
 # Spawn a shell via srun that uses stdin/out/err in truncate mode
@@ -113,10 +103,6 @@ if {[wait_for_file $file_out] == 0} {
 	}
 }
 
-if {$got_login_grps == 0} {
-	send_user "\nFAILURE: Unable to get user and group ID info\n"
-	set exit_code 1
-}
 if {$got_job_grps != 1} {
 	send_user "\nFAILURE: User and group ID info missing from stdout\n"
 	set exit_code 1
diff --git a/testsuite/expect/test17.4 b/testsuite/expect/test17.4
index 885ec57e95b..b7d73d5cc54 100755
--- a/testsuite/expect/test17.4
+++ b/testsuite/expect/test17.4
@@ -49,22 +49,7 @@ print_header $test_id
 # Execute 'id' to determine my user and group ID...
 #
 
-spawn $bin_id
-expect {
-        -re "(uid=.*\n)" {
-		set login_grp_info $expect_out(1,string)
-		set got_login_grps 1
-		exp_continue
-	}
-	eof {
-		wait
-	}
-}
-
-if {$got_login_grps == 0} {
-	send_user "\nFAILURE: Unable to get user and group ID info\n"
-	exit 1
-}
+set login_grp_info [get_my_id]
 
 #
 # Submit a slurm job that will execute 'id'
-- 
GitLab