Blame SOURCES/0004-test-live_test-offer-alternatives-to-crm-pcs-native.patch

24db9e
From b565fb6402af40789762ee281baf2b074c1532e1 Mon Sep 17 00:00:00 2001
24db9e
From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= <jpokorny@redhat.com>
24db9e
Date: Fri, 27 May 2016 23:17:32 +0200
24db9e
Subject: [PATCH 4/4] test: live_test: offer alternatives to crm (pcs + native)
24db9e
24db9e
Note that existing use of crm_ticket can be eventually also extended
24db9e
with higher-level CLI tool usage, following the same pattern.
24db9e
---
24db9e
 test/live_test.sh | 61 +++++++++++++++++++++++++++++++++++++++++++++++++------
24db9e
 1 file changed, 55 insertions(+), 6 deletions(-)
24db9e
24db9e
diff --git a/test/live_test.sh b/test/live_test.sh
24db9e
index 5ee918e..b7f27eb 100755
24db9e
--- a/test/live_test.sh
24db9e
+++ b/test/live_test.sh
24db9e
@@ -50,6 +50,9 @@ logf=test_booth.log
24db9e
 SSH_OPTS="-o StrictHostKeyChecking=no -l root"
24db9e
 iprules=/usr/share/booth/tests/test/booth_path
24db9e
 : ${HA_LOGFACILITY:="syslog"}
24db9e
+cli_driver=native
24db9e
+which crm >/dev/null 2>&1 && cli_driver=crm || :
24db9e
+which pcs >/dev/null 2>&1 && cli_driver=pcs || :
24db9e
 
24db9e
 get_site() {
24db9e
 	local n=$1
24db9e
@@ -159,7 +162,26 @@ runcmd() {
24db9e
 	return $rc
24db9e
 }
24db9e
 manage_site() {
24db9e
-	runcmd $1 crm -w resource $2 booth
24db9e
+	local action=$2 resource=booth cmd
24db9e
+	case "$action" in
24db9e
+	start)
24db9e
+		case "$cli_driver" in
24db9e
+		native) action=Started;;
24db9e
+		pcs)    action=enable;;
24db9e
+		esac;;
24db9e
+	stop)
24db9e
+		case "$cli_driver" in
24db9e
+		native) action=Stopped;;
24db9e
+		pcs)    action=disable;;
24db9e
+		esac;;
24db9e
+	esac
24db9e
+
24db9e
+	case "$cli_driver" in
24db9e
+	native) cmd="crm_resource --wait --resource \"$resource\" --set-parameter target-role --meta --parameter-value \"$action\"";;
24db9e
+	crm)    cmd="crm -w resource \"$action\" \"$resource\"";;
24db9e
+	pcs)    cmd="pcs resource \"$action\" \"$resource\" --wait";;
24db9e
+	esac
24db9e
+	runcmd $1 $cmd
24db9e
 }
24db9e
 manage_arbitrator() {
24db9e
 	if ps 1 | grep -qws systemd; then
24db9e
@@ -211,9 +233,15 @@ cleanup_booth() {
24db9e
 cleanup_dep_rsc() {
24db9e
 	local dep_rsc=`get_rsc`
24db9e
 	test -z "$dep_rsc" && return
24db9e
-	local h procs
24db9e
+	local cmd h procs
24db9e
+	case "$cli_driver" in
24db9e
+	native) cmd="crm_resource --cleanup --resource \"$dep_rsc\"; crm_resource --wait";;
24db9e
+	crm)    cmd="crm -w resource cleanup \"$dep_rsc\"";;
24db9e
+	# XXX pcs does not support --wait here?
24db9e
+	pcs)    cmd="pcs resource cleanup \"$dep_rsc\"; crm_resource --wait";;
24db9e
+	esac
24db9e
 	for h in $sites; do
24db9e
-		runcmd $h crm -w resource cleanup $dep_rsc & procs="$! $procs"
24db9e
+		runcmd $h $cmd & procs="$! $procs"
24db9e
 	done >/dev/null 2>&1
24db9e
 	wait $procs
24db9e
 }
24db9e
@@ -412,13 +440,34 @@ del_site_attr() {
24db9e
 	run_site $site geostore delete $1
24db9e
 }
24db9e
 break_external_prog() {
24db9e
-	run_site $1 crm configure "location $PREFNAME `get_rsc` rule -inf: defined \#uname"
24db9e
+	local cmd
24db9e
+	case "$cli_driver" in
24db9e
+	native) cmd="cibadmin --create --scope constraints --xml-text=\""
24db9e
+	        cmd="$cmd<rsc_location id='$PREFNAME' rsc='`get_rsc`'><rule id='rule_$PREFNAME' score='-INFINITY'>"
24db9e
+		cmd="$cmd<expression id='expr_$PREFNAME' attribute='#uname' operation='define'/>"
24db9e
+		cmd="$cmd</rule></rsc_location>\"";;
24db9e
+	crm)    cmd="crm configure \"location $PREFNAME `get_rsc` rule -inf: defined \#uname\"";;
24db9e
+	pcs)    cmd="pcs constraint location `get_rsc` rule id=$PREFNAME score=-INFINITY defined \#uname";;
24db9e
+	esac
24db9e
+	runcmd $1 $cmd
24db9e
 }
24db9e
 show_pref() {
24db9e
-	run_site $1 crm configure show $PREFNAME > /dev/null
24db9e
+	local cmd
24db9e
+	case "$cli_driver" in
24db9e
+	native) cmd="cibadmin --query --xpath \"//rsc_location[@id = '$PREFNAME']\"";;
24db9e
+	crm)    cmd="crm configure show $PREFNAME > /dev/null";;
24db9e
+	pcs)    cmd="pcs constraint show --full | grep -q $PREFNAME";;
24db9e
+	esac
24db9e
+	runcmd $1 $cmd
24db9e
 }
24db9e
 repair_external_prog() {
24db9e
-	run_site $1 crm configure delete $PREFNAME
24db9e
+	local cmd
24db9e
+	case "$cli_driver" in
24db9e
+	native) cmd="cibadmin --delete --xpath \"//rsc_location[@id = '$PREFNAME']\"";;
24db9e
+	crm)    cmd="crm configure delete $PREFNAME";;
24db9e
+	pcs)    cmd="pcs constraint remove $PREFNAME";;
24db9e
+	esac
24db9e
+	runcmd $1 $cmd
24db9e
 }
24db9e
 get_tkt() {
24db9e
 	grep "^ticket=" | head -1 | sed 's/ticket=//;s/"//g'
24db9e
-- 
24db9e
2.4.11
24db9e