diff --git a/tools/crm_ticket b/tools/crm_ticket index 27c6fd2f8e..640a5412d3 100755 --- a/tools/crm_ticket +++ b/tools/crm_ticket @@ -1,80 +1,122 @@ #!/bin/bash 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 # 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"; echo ""; echo "Grants or revokes the specified ticket for the cluster"; echo ""; echo "Usage: crm_ticket -t ticket_name command [options]"; echo "Options:" echo " -h, --help This text" echo " --version Version information" echo " -V, --verbose Increase debug output" echo " -q, --quiet Print only the value on stdout" echo "" echo " -t, --ticket-id=value The ticket to update" echo "" echo "Commands:" echo " -G, --query Query if the specified ticket is granted or not" echo " -v, --update=value Grant/Revoke the specified ticket" echo " -D, --delete Delete the granting/revoking record" echo " -T, --time Query the time of last granted the specified ticket" 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;; esac done if [ X$last_granted != X ]; then options="$options -n last-granted-$ticket -G -d -1" crm_attribute $options -t tickets rc=$? exit $rc 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 options="$options -n last-granted-$ticket -v `date +%s`" crm_attribute $options -t tickets >/dev/null 2>&1 rc=$? exit $rc else echo "Failed to grant ticket $ticket" exit $rc 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 d277c9de03..9c672fbb37 100755 --- a/tools/regression.exp +++ b/tools/regression.exp @@ -1,969 +1,967 @@ Setting up shadow instance A new shadow instance was created. To begin using it paste the following into your shell: CIB_shadow=tools-regression ; export CIB_shadow The supplied command is considered dangerous. To prevent accidental destruction of the cluster, the --force flag is required in order to proceed. * Passed: cibadmin - Require --force for CIB erasure * Passed: cibadmin - Allow CIB erasure with --force * Passed: cibadmin - Query CIB * Passed: crm_attribute - Set cluster option * Passed: cibadmin - Query new cluster option * Passed: cibadmin - Query cluster options * Passed: cibadmin - Delete nvpair Call failed: The object already exists * Passed: cibadmin - Create operaton should fail with: -21, The object already exists * Passed: cibadmin - Modify cluster options section * Passed: cibadmin - Query updated cluster option * Passed: crm_attribute - Set duplicate cluster option Please choose from one of the matches above and suppy the 'id' with --attr-id * Passed: crm_attribute - Setting multiply defined cluster option should fail with -216, Could not set cluster option * Passed: crm_attribute - Set cluster option with -s Deleted crm_config option: id=(null) name=cluster-delay * Passed: crm_attribute - Delete cluster option with -i * Passed: cibadmin - Create node entry * Passed: cibadmin - Create node status entry * Passed: crm_attribute - Create node attribute * Passed: cibadmin - Query new node attribute Digest: * Passed: cibadmin - Digest calculation Call failed: Update was older than existing configuration * Passed: cibadmin - Replace operation should fail with: -45, Update was older than existing configuration Error performing operation: The object/attribute does not exist scope=status name=standby value=off * Passed: crm_standby - Default standby value * Passed: crm_standby - Set standby status scope=nodes name=standby value=true * Passed: crm_standby - Query standby value Deleted nodes attribute: id=nodes-clusterNode-UUID-standby name=standby * Passed: crm_standby - Delete standby value * Passed: cibadmin - Create a resource * Passed: crm_resource - Create a resource meta attribute false * Passed: crm_resource - Query a resource meta attribute Deleted dummy option: id=dummy-meta_attributes-is-managed name=is-managed * Passed: crm_resource - Remove a resource meta attribute * Passed: crm_resource - Create a resource attribute dummy (ocf::pacemaker:Dummy) Stopped * Passed: crm_resource - List the configured resources * Passed: crm_resource - Set a resource's fail-count Resource dummy not moved: not-active and no preferred location specified. Error performing operation: cib object missing * Passed: crm_resource - Require a destination when migrating a resource that is stopped Error performing operation: i.dont.exist is not a known node Error performing operation: The object/attribute does not exist * Passed: crm_resource - Don't support migration to non-existant locations * Passed: crm_resource - Migrate a resource * Passed: crm_resource - Un-migrate a resource scope=tickets name=granted-ticket-ticketA value=false * Passed: crm_ticket - Default granted-ticket value * Passed: crm_ticket - Set granted-ticket value scope=tickets name=granted-ticket-ticketA value=false * Passed: crm_ticket - Query granted-ticket value -Deleted tickets option: id=status-tickets-granted-ticket-ticketA name=granted-ticket-ticketA - * Passed: crm_ticket - Delete granted-ticket value diff --git a/tools/regression.sh b/tools/regression.sh index 3fc9fb12a3..a6893dc418 100755 --- a/tools/regression.sh +++ b/tools/regression.sh @@ -1,208 +1,208 @@ #!/bin/bash : ${shadow=tools-regression} test_home=`dirname $0` num_errors=0 num_passed=0 GREP_OPTIONS= function assert() { rc=$1; shift target=$1; shift app=$1; shift msg=$1; shift exit_code=$1; shift cibadmin -Q if [ $rc -ne $target ]; then num_errors=`expr $num_errors + 1` printf "* Failed (rc=%.3d): %-14s - %s\n" $rc $app "$msg" if [ ! -z $exit_code ]; then echo "Aborting tests" exit $exit_code fi exit 1 else printf "* Passed: %-14s - %s\n" $app "$msg" num_passed=`expr $num_passed + 1` fi } function usage() { echo "Usage: ./regression.sh [-s(ave)] [-x] [-v(erbose)]" exit $1 } done=0 do_save=0 VALGRIND_CMD= while test "$done" = "0"; do case "$1" in -V|--verbose) verbose=1; shift;; -v|--valgrind) export G_SLICE=always-malloc VALGRIND_CMD="valgrind -q --show-reachable=no --leak-check=full --trace-children=no --time-stamp=yes --num-callers=20 --suppressions=$test_home/cli.supp" shift;; -x) set -x; shift;; -s) do_save=1; shift;; -p) PATH="$2:$PATH"; export PATH; shift 1;; -?) usage 0;; -*) echo "unknown option: $1"; usage 1;; *) done=1;; esac done if [ "x$VALGRIND_CMD" = "x" -a -x $test_home/crm_simulate ]; then echo "Using local binaries from: $test_home" PATH="$test_home:$PATH" fi function test_tools() { export CIB_shadow_dir=$test_home $VALGRIND_CMD crm_shadow --batch --force --create-empty $shadow export CIB_shadow=$shadow $VALGRIND_CMD cibadmin -Q $VALGRIND_CMD cibadmin -E assert $? 1 cibadmin "Require --force for CIB erasure" $VALGRIND_CMD cibadmin -E --force assert $? 0 cibadmin "Allow CIB erasure with --force" $VALGRIND_CMD cibadmin -Q > /tmp/$$.existing.xml assert $? 0 cibadmin "Query CIB" $VALGRIND_CMD crm_attribute -n cluster-delay -v 60s assert $? 0 crm_attribute "Set cluster option" $VALGRIND_CMD cibadmin -Q -o crm_config | grep cib-bootstrap-options-cluster-delay assert $? 0 cibadmin "Query new cluster option" $VALGRIND_CMD cibadmin -Q -o crm_config > /tmp/$$.opt.xml assert $? 0 cibadmin "Query cluster options" $VALGRIND_CMD cibadmin -D -o crm_config --xml-text '' assert $? 0 cibadmin "Delete nvpair" $VALGRIND_CMD cibadmin -C -o crm_config --xml-file /tmp/$$.opt.xml assert $? 21 cibadmin "Create operaton should fail with: -21, The object already exists" $VALGRIND_CMD cibadmin -M -o crm_config --xml-file /tmp/$$.opt.xml assert $? 0 cibadmin "Modify cluster options section" $VALGRIND_CMD cibadmin -Q -o crm_config | grep cib-bootstrap-options-cluster-delay assert $? 0 cibadmin "Query updated cluster option" $VALGRIND_CMD crm_attribute -n cluster-delay -v 40s -s duplicate assert $? 0 crm_attribute "Set duplicate cluster option" $VALGRIND_CMD crm_attribute -n cluster-delay -v 30s assert $? 216 crm_attribute "Setting multiply defined cluster option should fail with -216, Could not set cluster option" $VALGRIND_CMD crm_attribute -n cluster-delay -v 30s -s duplicate assert $? 0 crm_attribute "Set cluster option with -s" $VALGRIND_CMD crm_attribute -n cluster-delay -D -i cib-bootstrap-options-cluster-delay assert $? 0 crm_attribute "Delete cluster option with -i" $VALGRIND_CMD cibadmin -C -o nodes --xml-text '' assert $? 0 cibadmin "Create node entry" $VALGRIND_CMD cibadmin -C -o status --xml-text '' assert $? 0 cibadmin "Create node status entry" $VALGRIND_CMD crm_attribute -n ram -v 1024M -U clusterNode-UNAME -t nodes assert $? 0 crm_attribute "Create node attribute" $VALGRIND_CMD cibadmin -Q -o nodes | grep clusterNode-UUID-ram assert $? 0 cibadmin "Query new node attribute" $VALGRIND_CMD cibadmin -Q | cibadmin -5 -p 2>&1 > /dev/null assert $? 0 cibadmin "Digest calculation" # This update will fail because it has version numbers $VALGRIND_CMD cibadmin -R --xml-file /tmp/$$.existing.xml assert $? 45 cibadmin "Replace operation should fail with: -45, Update was older than existing configuration" crm_standby -N clusterNode-UNAME -G assert $? 0 crm_standby "Default standby value" crm_standby -N clusterNode-UNAME -v true assert $? 0 crm_standby "Set standby status" crm_standby -N clusterNode-UNAME -G assert $? 0 crm_standby "Query standby value" crm_standby -N clusterNode-UNAME -D assert $? 0 crm_standby "Delete standby value" $VALGRIND_CMD cibadmin -C -o resources --xml-text '' assert $? 0 cibadmin "Create a resource" $VALGRIND_CMD crm_resource -r dummy --meta -p is-managed -v false assert $? 0 crm_resource "Create a resource meta attribute" $VALGRIND_CMD crm_resource -r dummy --meta -g is-managed assert $? 0 crm_resource "Query a resource meta attribute" $VALGRIND_CMD crm_resource -r dummy --meta -d is-managed assert $? 0 crm_resource "Remove a resource meta attribute" $VALGRIND_CMD crm_resource -r dummy -p delay -v 10s assert $? 0 crm_resource "Create a resource attribute" $VALGRIND_CMD crm_resource -L assert $? 0 crm_resource "List the configured resources" crm_failcount -r dummy -v 10 -N clusterNode-UNAME assert $? 0 crm_resource "Set a resource's fail-count" $VALGRIND_CMD crm_resource -r dummy -M assert $? 244 crm_resource "Require a destination when migrating a resource that is stopped" $VALGRIND_CMD crm_resource -r dummy -M -N i.dont.exist assert $? 234 crm_resource "Don't support migration to non-existant locations" $VALGRIND_CMD crm_resource -r dummy -M -N clusterNode-UNAME assert $? 0 crm_resource "Migrate a resource" $VALGRIND_CMD crm_resource -r dummy -U assert $? 0 crm_resource "Un-migrate a resource" 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" } test_tools 2>&1 | sed s/cib-last-written.*\>/\>/ > $test_home/regression.out rc=$? if [ $do_save = 1 ]; then cp $test_home/regression.out $test_home/regression.exp fi grep -e "^*" $test_home/regression.out diff -u $test_home/regression.exp $test_home/regression.out diff_rc=$? if [ $rc != 0 ]; then echo Tests failed exit 1 elif [ $diff_rc != 0 ]; then echo Tests passed but diff failed exit 2 else echo Tests passed exit 0 fi