pacemaker/pacemaker-crm_ticket-force.diff
Tim Serong 1589a3e7c3 - Add provides to identify support level for tickets (bnc#752241)
- Resolve coverity RESOURCE_LEAK, REVERSE_INULL and UNREACHABLE defects 

- Tools: crm_simulate - Support to grant/revoke/standby/activate
  tickets from the new ticket state section (bnc#752241)

- Tools: Add crm_ticket to be profiled by valgrind
- Tools: crm_ticket - Display the tickets that are referenced in
  rsc_ticket constraints but have never been granted yet (bnc#752241)
- Tools: crm_mon - Support to display tickets (bnc#752242)

- PE: Move the ticket state section to
  "/cib/status/tickets/ticket_state" (bnc#752241)
- PE: Support to make tickets standby for relinquishing tickets
  gracefully (bnc#752241)
- Tools: Implement a new crm_ticket (bnc#752241)
- Tools: Update CLI regression tests for the new crm_ticket
- Tools: Add CLI regression tests for ticket standby state
- PE: Update regression tests for the new ticket state section
- PE: Support to make tickets standby for relinquishing tickets
  gracefully (regression tests)

- Tools: crm_ticket - Granting/revoking tickets need user to confirm
  unless "--force" option is used (bnc#752269)

- Tools: Implement the support of granting/revoking tickets for
  crm_simulate (bnc#752241)

OBS-URL: https://build.opensuse.org/package/show/network:ha-clustering:Factory/pacemaker?expand=0&rev=34
2012-04-23 11:15:16 +00:00

144 lines
4.5 KiB
Diff

commit e0733a32d39bf673e0ef886dacfbe452f0110967
Author: Gao,Yan <ygao@suse.com>
Date: Wed Mar 14 20:41:34 2012 +0800
Medium: Tools: crm_ticket - Granting/revoking tickets need user to confirm unless "--force" option is used
diff --git a/tools/crm_ticket b/tools/crm_ticket
index 27c6fd2..640a541 100755
--- a/tools/crm_ticket
+++ b/tools/crm_ticket
@@ -2,10 +2,12 @@
options=""
ticket=""
-granted=""
+update_value=""
last_granted=""
+delete_attr="false"
+force="false"
-TEMP=`getopt -o DGQVThU:v:i:t: --long help,version,ticket:,attr-value:,delete-attr,get-value,attr-id:,quiet,time \
+TEMP=`getopt -o DGQVThfv:i:t: --long help,version,ticket:,attr-value:,delete-attr,get-value,attr-id:,force,quiet,time \
-n 'crm_ticket' -- "$@"`
if [ $? != 0 ] ; then echo "crm_ticket - A convenience wrapper for crm_attribute"; echo ""; crm_attribute -?; exit 1 ; fi
@@ -13,13 +15,39 @@ if [ $? != 0 ] ; then echo "crm_ticket - A convenience wrapper for crm_attribute
# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"
+confirm() {
+ action=$1
+ ticket=$2
+
+ if [ X$action = X"grant" ]; then
+ warning="The crm_ticket command cannot help you verify if '$ticket' is already granted elsewhere."
+ word="to"
+ else
+ warning="Revoking '$ticket' will trigger the specified 'loss-policy' relating to '$ticket'."
+ word="from"
+ fi
+
+ while :; do
+ printf "$warning\nAre you sure you want to $action '$ticket' $word this site? (y/n)"
+ read ans
+ if echo $ans | grep -iqs '^[yn]'; then
+ echo $ans | grep -iqs '^y'
+ return $?
+ else
+ echo Please answer with y or n
+ fi
+ done
+}
+
while true ; do
case "$1" in
- -v|--attr-value) options="$options $1 $2"; granted=$2; shift; shift;;
+ -v|--attr-value) options="$options $1 $2"; update_value=$2; shift; shift;;
-i|--attr-id) options="$options $1 $2"; shift; shift;;
- -Q|--quiet|-D|--delete-attr|-G|--get-value|-V) options="$options $1"; shift;;
+ -D|--delete-attr) options="$options $1"; delete_attr="true"; shift;;
+ -Q|--quiet|-G|--get-value|-V) options="$options $1"; shift;;
-t|--ticket-id) ticket=$2; shift; shift;;
-T|--time) last_granted="time"; shift;;
+ -f|--force) force="true"; shift;;
--version) crm_attribute --version; exit 0;;
-h|--help)
echo "crm_ticket - A convenience wrapper for crm_attribute";
@@ -43,6 +71,7 @@ while true ; do
echo ""
echo "Additional Options:"
echo " -i, --id=value (Advanced) The ID used to identify the attribute"
+ echo " -f, --force (Advanced) Force the action to be performed"
exit 0;;
--) shift ; break ;;
*) echo "Unknown option: $1. See --help for details." exit 1;;
@@ -58,8 +87,12 @@ else
options="$options -n granted-ticket-$ticket"
fi
-case "$granted" in
+case "$update_value" in
true|yes|1)
+ if [ X$force != X"true" ]; then
+ confirm "grant" $ticket || exit 1
+ fi
+
crm_attribute $options -t tickets >/dev/null 2>&1
rc=$?
if [ $rc = 0 ]; then
@@ -73,8 +106,17 @@ case "$granted" in
fi
;;
*)
- crm_attribute $options -t tickets -d false
- rc=$?
- exit $rc
+ if [ X$update_value != X -o X$delete_attr = X"true" ]; then
+ if [ X$force != X"true" ]; then
+ confirm "revoke" $ticket || exit 1
+ fi
+ crm_attribute $options -t tickets >/dev/null 2>&1
+ rc=$?
+ exit $rc
+ else
+ crm_attribute $options -t tickets -d false
+ rc=$?
+ exit $rc
+ fi
;;
esac
diff --git a/tools/regression.exp b/tools/regression.exp
index d277c9d..9c672fb 100755
--- a/tools/regression.exp
+++ b/tools/regression.exp
@@ -926,8 +926,6 @@ scope=tickets name=granted-ticket-ticketA value=false
</status>
</cib>
* Passed: crm_ticket - Query granted-ticket value
-Deleted tickets option: id=status-tickets-granted-ticket-ticketA name=granted-ticket-ticketA
-
<cib epoch="18" num_updates="3" admin_epoch="0" validate-with="pacemaker-1.2" >
<configuration>
<crm_config>
diff --git a/tools/regression.sh b/tools/regression.sh
index 3fc9fb1..a6893dc 100755
--- a/tools/regression.sh
+++ b/tools/regression.sh
@@ -173,13 +173,13 @@ function test_tools() {
crm_ticket -t ticketA -G
assert $? 0 crm_ticket "Default granted-ticket value"
- crm_ticket -t ticketA -v false
+ crm_ticket -t ticketA -v false --force
assert $? 0 crm_ticket "Set granted-ticket value"
crm_ticket -t ticketA -G
assert $? 0 crm_ticket "Query granted-ticket value"
- crm_ticket -t ticketA -D
+ crm_ticket -t ticketA -D --force
assert $? 0 crm_ticket "Delete granted-ticket value"
}