Blame SOURCES/0010-maint-test-polish-live_test.sh.patch

b8c11e
From 4d7278dbd9cf5f9a7d6060eb96e1ba5af6b3d505 Mon Sep 17 00:00:00 2001
b8c11e
From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= <jpokorny@redhat.com>
b8c11e
Date: Thu, 19 Jul 2018 19:44:34 +0200
b8c11e
Subject: [PATCH 2/3] maint: test: polish live_test.sh
b8c11e
MIME-Version: 1.0
b8c11e
Content-Type: text/plain; charset=UTF-8
b8c11e
Content-Transfer-Encoding: 8bit
b8c11e
b8c11e
- from issues found with ShellCheck, fix those marked as important
b8c11e
- suppress some ShellCheck issues, mostly related to the fact that
b8c11e
  some ticket-related variables are established dynamically,
b8c11e
  also drop a never-used local variable (see commits 74a3f5c + 4136682)
b8c11e
  and another global one that was used but consequently ditched
b8c11e
  (see commits 08f56bd + d952b27)
b8c11e
- fix s/boots not uptodate/booths not up-to-date/ spelling
b8c11e
- fix whitespace issues
b8c11e
b8c11e
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
b8c11e
---
b8c11e
 test/live_test.sh | 60 ++++++++++++++++++++++++-----------------------
b8c11e
 1 file changed, 31 insertions(+), 29 deletions(-)
b8c11e
b8c11e
diff --git a/test/live_test.sh b/test/live_test.sh
b8c11e
index f8644a2..c131f8c 100755
b8c11e
--- a/test/live_test.sh
b8c11e
+++ b/test/live_test.sh
b8c11e
@@ -41,7 +41,6 @@ EOF
b8c11e
 [ $# -eq 0 ] && usage 0
b8c11e
 
b8c11e
 cnf=$1
b8c11e
-BOOTH_DIR="/etc/booth"
b8c11e
 run_cnf="/etc/booth/booth.conf"
b8c11e
 
b8c11e
 shift 1
b8c11e
@@ -62,9 +61,9 @@ get_internal_site() {
b8c11e
 
b8c11e
 logmsg() {
b8c11e
 	if [ "$WE_SERVER" -o "$_JUST_NETEM" ]; then
b8c11e
-		logger -t "BOOTHTEST" -p $HA_LOGFACILITY.info -- $@
b8c11e
+		logger -t "BOOTHTEST" -p $HA_LOGFACILITY.info -- "$@"
b8c11e
 	else
b8c11e
-		ssh $SSH_OPTS `get_site 1` logger -t "BOOTHTEST" -p $HA_LOGFACILITY.info -- $@
b8c11e
+		ssh $SSH_OPTS `get_site 1` logger -t "BOOTHTEST" -p $HA_LOGFACILITY.info -- "$@"
b8c11e
 	fi
b8c11e
 }
b8c11e
 
b8c11e
@@ -141,20 +140,20 @@ local_netem_env() {
b8c11e
 }
b8c11e
 
b8c11e
 is_function() {
b8c11e
-    test z"`command -v $1`" = z"$1"
b8c11e
+	test z"`command -v $1`" = z"$1"
b8c11e
 }
b8c11e
 runcmd() {
b8c11e
 	local h=$1 rc
b8c11e
 	shift 1
b8c11e
-	echo "$h: running '$@'" | logmsg
b8c11e
+	echo "$h: running '$*'" | logmsg
b8c11e
 	if ip a l | fgrep -wq $h; then
b8c11e
-		eval $@
b8c11e
+		eval "$@"
b8c11e
 	else
b8c11e
-		ssh $SSH_OPTS $h $@
b8c11e
+		ssh $SSH_OPTS $h "$@"
b8c11e
 	fi
b8c11e
 	rc=$?
b8c11e
 	if [ $rc -ne 0 ]; then
b8c11e
-		echo "$h: '$@' failed (exit code $rc)" | logmsg
b8c11e
+		echo "$h: '$*' failed (exit code $rc)" | logmsg
b8c11e
 	fi
b8c11e
 	return $rc
b8c11e
 }
b8c11e
@@ -306,7 +305,7 @@ dump_conf() {
b8c11e
 forall() {
b8c11e
 	local h rc=0
b8c11e
 	for h in $sites $arbitrators; do
b8c11e
-		runcmd $h $@
b8c11e
+		runcmd $h "$@"
b8c11e
 		rc=$((rc|$?))
b8c11e
 	done
b8c11e
 	return $rc
b8c11e
@@ -314,7 +313,7 @@ forall() {
b8c11e
 forall_withname() {
b8c11e
 	local h rc=0 output
b8c11e
 	for h in $sites $arbitrators; do
b8c11e
-		output=`runcmd $h $@`
b8c11e
+		output=`runcmd $h "$@"`
b8c11e
 		rc=$((rc|$?))
b8c11e
 		echo $h: $output
b8c11e
 	done
b8c11e
@@ -323,7 +322,7 @@ forall_withname() {
b8c11e
 forall_sites() {
b8c11e
 	local h rc=0
b8c11e
 	for h in $sites; do
b8c11e
-		runcmd $h $@
b8c11e
+		runcmd $h "$@"
b8c11e
 		rc=$((rc|$?))
b8c11e
 	done
b8c11e
 	return $rc
b8c11e
@@ -343,7 +342,7 @@ forall_fun2() {
b8c11e
 	f=$1
b8c11e
 	shift 1
b8c11e
 	for h in $sites $arbitrators; do
b8c11e
-		$f $@ | ssh $SSH_OPTS $h
b8c11e
+		$f "$@" | ssh $SSH_OPTS $h
b8c11e
 		rc=$((rc|$?))
b8c11e
 		[ $rc -ne 0 ] && break
b8c11e
 	done
b8c11e
@@ -353,13 +352,13 @@ run_site() {
b8c11e
 	local n=$1 h
b8c11e
 	shift 1
b8c11e
 	h=`echo $sites | awk '{print $'$n'}'`
b8c11e
-	runcmd $h $@
b8c11e
+	runcmd $h "$@"
b8c11e
 }
b8c11e
 run_arbitrator() {
b8c11e
 	local n=$1 h
b8c11e
 	shift 1
b8c11e
 	h=`echo $arbitrators | awk '{print $'$n'}'`
b8c11e
-	runcmd $h $@
b8c11e
+	runcmd $h "$@"
b8c11e
 }
b8c11e
 
b8c11e
 # need to get logs from _all_ clusters' nodes
b8c11e
@@ -450,6 +449,8 @@ n && (/^$/ || /^ticket.*/) {exit}
b8c11e
 ' $1
b8c11e
 }
b8c11e
 wait_exp() {
b8c11e
+	# shellcheck disable=SC2154
b8c11e
+	# (T_expire: defined with get_tkt_settings)
b8c11e
 	sleep $T_expire
b8c11e
 }
b8c11e
 wait_renewal() {
b8c11e
@@ -593,7 +594,7 @@ booth_leader_consistency_2() {
b8c11e
 # b) some booths not uptodate (have no leader for the ticket)
b8c11e
 # c) ticket expiry times differ
b8c11e
 check_booth_consistency() {
b8c11e
-	local tlist tlist_validate rc rc_lead maxdiff
b8c11e
+	local tlist rc rc_lead maxdiff
b8c11e
 	tlist=`forall_withname booth list 2>/dev/null | grep $tkt`
b8c11e
 
b8c11e
 	# Check time consistency
b8c11e
@@ -620,7 +621,7 @@ check_booth_consistency() {
b8c11e
 `if [ $rc -ge 4 ]; then
b8c11e
 	echo "booth list consistency failed (more than one leader!):"
b8c11e
 elif [ $rc -ge 2 ]; then
b8c11e
-	echo "booth list consistency failed (some boots not uptodate):"
b8c11e
+	echo "booth list consistency failed (some booths not up-to-date):"
b8c11e
 else
b8c11e
 	echo "booth list consistency failed (max valid time diff: $maxdiff):"
b8c11e
 fi`
b8c11e
@@ -677,11 +678,10 @@ run_report() {
b8c11e
 runtest() {
b8c11e
 	local start_ts end_ts
b8c11e
 	local rc booth_status dep_rsc_status
b8c11e
-	local start_time end_time
b8c11e
 	local usrmsg
b8c11e
 	rc=0
b8c11e
 	TEST=$1
b8c11e
-	start_time=`date`
b8c11e
+	start_ts=`date`  # to have the expanded form in the logfile
b8c11e
 	start_ts=`date +%s`
b8c11e
 	echo -n "Testing: $1 (ticket: $tkt)... "
b8c11e
 	can_run_test $1 || return 0
b8c11e
@@ -719,7 +719,7 @@ runtest() {
b8c11e
 		usrmsg="test FAIL: $rc"
b8c11e
 		;;
b8c11e
 	esac
b8c11e
-	end_time=`date`
b8c11e
+	end_ts=`date`  # to have the expanded form in the logfile
b8c11e
 	end_ts=`date +%s`
b8c11e
 	echo "finished booth test $1 ($tkt): $usrmsg" | logmsg
b8c11e
 	echo "==================================================" | logmsg
b8c11e
@@ -791,6 +791,8 @@ setup_longgrant2() {
b8c11e
 }
b8c11e
 test_longgrant2() {
b8c11e
 	local i
b8c11e
+	# shellcheck disable=SC2034
b8c11e
+	# (variable exists merely out of necessity)
b8c11e
 	for i in `seq 10`; do
b8c11e
 		wait_exp
b8c11e
 	done
b8c11e
@@ -1033,14 +1035,14 @@ setup_split_leader() {
b8c11e
 	return 0
b8c11e
 }
b8c11e
 test_split_leader() {
b8c11e
-	run_site 1 $iprules stop $port   >/dev/null
b8c11e
+	run_site 1 $iprules stop $port >/dev/null
b8c11e
 	wait_exp
b8c11e
 	wait_timeout
b8c11e
 	wait_timeout
b8c11e
 	wait_timeout
b8c11e
 	wait_timeout
b8c11e
 	check_cib any || return 1
b8c11e
-	run_site 1 $iprules start $port  >/dev/null
b8c11e
+	run_site 1 $iprules start $port >/dev/null
b8c11e
 	wait_timeout
b8c11e
 	wait_timeout
b8c11e
 	wait_timeout
b8c11e
@@ -1049,7 +1051,7 @@ check_split_leader() {
b8c11e
 	check_consistency any
b8c11e
 }
b8c11e
 recover_split_leader() {
b8c11e
-	run_site 1 $iprules start $port  >/dev/null
b8c11e
+	run_site 1 $iprules start $port >/dev/null
b8c11e
 }
b8c11e
 
b8c11e
 ## TEST: split_follower ##
b8c11e
@@ -1059,10 +1061,10 @@ setup_split_follower() {
b8c11e
 	grant_ticket_cib 1
b8c11e
 }
b8c11e
 test_split_follower() {
b8c11e
-	run_site 2 $iprules stop $port  >/dev/null
b8c11e
+	run_site 2 $iprules stop $port >/dev/null
b8c11e
 	wait_exp
b8c11e
 	wait_timeout
b8c11e
-	run_site 2 $iprules start $port  >/dev/null
b8c11e
+	run_site 2 $iprules start $port >/dev/null
b8c11e
 	wait_timeout
b8c11e
 }
b8c11e
 check_split_follower() {
b8c11e
@@ -1076,9 +1078,9 @@ setup_split_edge() {
b8c11e
 	grant_ticket_cib 1
b8c11e
 }
b8c11e
 test_split_edge() {
b8c11e
-	run_site 1 $iprules stop $port  >/dev/null
b8c11e
+	run_site 1 $iprules stop $port >/dev/null
b8c11e
 	wait_exp
b8c11e
-	run_site 1 $iprules start $port  >/dev/null
b8c11e
+	run_site 1 $iprules start $port >/dev/null
b8c11e
 	wait_timeout
b8c11e
 	wait_timeout
b8c11e
 }
b8c11e
@@ -1215,13 +1217,11 @@ internal_arbitrators=`get_value arbitrator < $cnf`
b8c11e
 all_nodes=`get_all_nodes`
b8c11e
 port=`get_value port < $cnf`
b8c11e
 : ${port:=9929}
b8c11e
-site_cnt=`echo $internal_sites | wc -w`
b8c11e
-arbitrator_cnt=`echo $internal_arbitrators | wc -w`
b8c11e
 
b8c11e
 if [ "$1" = "__netem__" ]; then
b8c11e
 	shift 1
b8c11e
 	_JUST_NETEM=1
b8c11e
-	local_netem_env $@
b8c11e
+	local_netem_env "$@"
b8c11e
 	exit
b8c11e
 fi
b8c11e
 
b8c11e
@@ -1314,6 +1314,8 @@ do
b8c11e
 
b8c11e
 	eval `get_tkt_settings booth_${i}.conf`
b8c11e
 
b8c11e
+	# shellcheck disable=SC2154
b8c11e
+	# (T_timeout: defined with get_tkt_settings)
b8c11e
 	MIN_TIMEOUT=`awk -v tm=$T_timeout 'BEGIN{
b8c11e
 			if (tm >= 2) print tm;
b8c11e
 			else print 2*tm;
b8c11e
-- 
b8c11e
2.18.0.rc2
b8c11e