diff --git a/cts/cli/regression.rules.exp b/cts/cli/regression.rules.exp
index 208b56ab4d..74df3bc5ad 100644
--- a/cts/cli/regression.rules.exp
+++ b/cts/cli/regression.rules.exp
@@ -1,157 +1,278 @@
Created new pacemaker configuration
Setting up shadow instance
A new shadow instance was created. To begin using it paste the following into your shell:
CIB_shadow=cts-cli ; export CIB_shadow
=#=#=#= Begin test: crm_rule given no arguments =#=#=#=
crm_rule: No mode operation given
=#=#=#= End test: crm_rule given no arguments - Incorrect usage (64) =#=#=#=
* Passed: crm_rule - crm_rule given no arguments
+=#=#=#= Begin test: crm_rule given no arguments (XML) =#=#=#=
+
+
+
+ crm_rule: No mode operation given
+
+
+
+=#=#=#= End test: crm_rule given no arguments (XML) - Incorrect usage (64) =#=#=#=
+* Passed: crm_rule - crm_rule given no arguments (XML)
=#=#=#= Begin test: crm_rule given no rule to check =#=#=#=
crm_rule: --check requires use of --rule=
=#=#=#= End test: crm_rule given no rule to check - Incorrect usage (64) =#=#=#=
* Passed: crm_rule - crm_rule given no rule to check
+=#=#=#= Begin test: crm_rule given no rule to check (XML) =#=#=#=
+
+
+
+ crm_rule: --check requires use of --rule=
+
+
+
+=#=#=#= End test: crm_rule given no rule to check (XML) - Incorrect usage (64) =#=#=#=
+* Passed: crm_rule - crm_rule given no rule to check (XML)
=#=#=#= Begin test: crm_rule given invalid input XML =#=#=#=
(log_xmllib_err@xml.c:891) error: XML Error: Entity: line 1: parser error : Start tag expected, '<' not found
(log_xmllib_err@xml.c:891) error: XML Error: invalidxml
(log_xmllib_err@xml.c:891) error: XML Error: ^
crm_rule: Couldn't parse input string: invalidxml
=#=#=#= End test: crm_rule given invalid input XML - Invalid data given (65) =#=#=#=
* Passed: crm_rule - crm_rule given invalid input XML
+=#=#=#= Begin test: crm_rule given invalid input XML (XML) =#=#=#=
+(log_xmllib_err@xml.c:891) error: XML Error: Entity: line 1: parser error : Start tag expected, '<' not found
+(log_xmllib_err@xml.c:891) error: XML Error: invalidxml
+(log_xmllib_err@xml.c:891) error: XML Error: ^
+
+
+
+ crm_rule: Couldn't parse input string: invalidxml
+
+
+
+
+=#=#=#= End test: crm_rule given invalid input XML (XML) - Invalid data given (65) =#=#=#=
+* Passed: crm_rule - crm_rule given invalid input XML (XML)
=#=#=#= Begin test: crm_rule given invalid input XML on stdin =#=#=#=
(log_xmllib_err@xml.c:891) error: XML Error: Entity: line 1: parser error : Start tag expected, '<' not found
(log_xmllib_err@xml.c:891) error: XML Error: invalidxml
(log_xmllib_err@xml.c:891) error: XML Error: ^
crm_rule: Couldn't parse input from STDIN
=#=#=#= End test: crm_rule given invalid input XML on stdin - Invalid data given (65) =#=#=#=
* Passed: echo - crm_rule given invalid input XML on stdin
+=#=#=#= Begin test: crm_rule given invalid input XML on stdin (XML) =#=#=#=
+(log_xmllib_err@xml.c:891) error: XML Error: Entity: line 1: parser error : Start tag expected, '<' not found
+(log_xmllib_err@xml.c:891) error: XML Error: invalidxml
+(log_xmllib_err@xml.c:891) error: XML Error: ^
+
+
+
+ crm_rule: Couldn't parse input from STDIN
+
+
+
+
+=#=#=#= End test: crm_rule given invalid input XML on stdin (XML) - Invalid data given (65) =#=#=#=
+* Passed: echo - crm_rule given invalid input XML on stdin (XML)
=#=#=#= Begin test: Try to check a rule that doesn't exist =#=#=#=
-crm_rule: No rule found with ID=blahblah
+Could not determine whether rule blahblah is in effect: Rule not found
=#=#=#= Current cib after: Try to check a rule that doesn't exist =#=#=#=
=#=#=#= End test: Try to check a rule that doesn't exist - No such object (105) =#=#=#=
* Passed: crm_rule - Try to check a rule that doesn't exist
=#=#=#= Begin test: Try to check a rule that doesn't exist, with XML output =#=#=#=
+
- crm_rule: No rule found with ID=blahblah
+ Could not determine whether rule blahblah is in effect: Rule not found
=#=#=#= End test: Try to check a rule that doesn't exist, with XML output - No such object (105) =#=#=#=
* Passed: crm_rule - Try to check a rule that doesn't exist, with XML output
=#=#=#= Begin test: Try to check a rule that has too many date_expressions =#=#=#=
-crm_rule: Can't check rule cli-rule-too-many-date-expressions because it does not have exactly one date_expression
+Could not determine whether rule cli-rule-too-many-date-expressions is in effect: Rule has more than one date expression
=#=#=#= End test: Try to check a rule that has too many date_expressions - Unimplemented (3) =#=#=#=
* Passed: crm_rule - Try to check a rule that has too many date_expressions
+=#=#=#= Begin test: Try to check a rule that has too many date_expressions (XML) =#=#=#=
+
+
+
+
+ Could not determine whether rule cli-rule-too-many-date-expressions is in effect: Rule has more than one date expression
+
+
+
+=#=#=#= End test: Try to check a rule that has too many date_expressions (XML) - Unimplemented (3) =#=#=#=
+* Passed: crm_rule - Try to check a rule that has too many date_expressions (XML)
=#=#=#= Begin test: Verify basic rule is expired =#=#=#=
Rule cli-prefer-rule-dummy-expired is expired
=#=#=#= End test: Verify basic rule is expired - Requested item has expired (110) =#=#=#=
* Passed: crm_rule - Verify basic rule is expired
=#=#=#= Begin test: Verify basic rule is expired, with XML output =#=#=#=
=#=#=#= End test: Verify basic rule is expired, with XML output - Requested item has expired (110) =#=#=#=
* Passed: crm_rule - Verify basic rule is expired, with XML output
=#=#=#= Begin test: Verify basic rule worked in the past =#=#=#=
Rule cli-prefer-rule-dummy-expired is still in effect
=#=#=#= End test: Verify basic rule worked in the past - OK (0) =#=#=#=
* Passed: crm_rule - Verify basic rule worked in the past
+=#=#=#= Begin test: Verify basic rule worked in the past (XML) =#=#=#=
+
+
+
+
+=#=#=#= End test: Verify basic rule worked in the past (XML) - OK (0) =#=#=#=
+* Passed: crm_rule - Verify basic rule worked in the past (XML)
=#=#=#= Begin test: Verify basic rule is not yet in effect =#=#=#=
Rule cli-prefer-rule-dummy-not-yet has not yet taken effect
=#=#=#= End test: Verify basic rule is not yet in effect - Requested item is not yet in effect (111) =#=#=#=
* Passed: crm_rule - Verify basic rule is not yet in effect
+=#=#=#= Begin test: Verify basic rule is not yet in effect (XML) =#=#=#=
+
+
+
+
+=#=#=#= End test: Verify basic rule is not yet in effect (XML) - Requested item is not yet in effect (111) =#=#=#=
+* Passed: crm_rule - Verify basic rule is not yet in effect (XML)
=#=#=#= Begin test: Verify date_spec rule with years has expired =#=#=#=
Rule cli-prefer-rule-dummy-date_spec-only-years is expired
=#=#=#= End test: Verify date_spec rule with years has expired - Requested item has expired (110) =#=#=#=
* Passed: crm_rule - Verify date_spec rule with years has expired
+=#=#=#= Begin test: Verify date_spec rule with years has expired (XML) =#=#=#=
+
+
+
+
+=#=#=#= End test: Verify date_spec rule with years has expired (XML) - Requested item has expired (110) =#=#=#=
+* Passed: crm_rule - Verify date_spec rule with years has expired (XML)
=#=#=#= Begin test: Verify multiple rules at once =#=#=#=
Rule cli-prefer-rule-dummy-not-yet has not yet taken effect
Rule cli-prefer-rule-dummy-date_spec-only-years is expired
=#=#=#= End test: Verify multiple rules at once - Requested item has expired (110) =#=#=#=
* Passed: crm_rule - Verify multiple rules at once
=#=#=#= Begin test: Verify multiple rules at once, with XML output =#=#=#=
=#=#=#= End test: Verify multiple rules at once, with XML output - Requested item has expired (110) =#=#=#=
* Passed: crm_rule - Verify multiple rules at once, with XML output
=#=#=#= Begin test: Verify date_spec rule with years is in effect =#=#=#=
Rule cli-prefer-rule-dummy-date_spec-only-years satisfies conditions
=#=#=#= End test: Verify date_spec rule with years is in effect - OK (0) =#=#=#=
* Passed: crm_rule - Verify date_spec rule with years is in effect
+=#=#=#= Begin test: Verify date_spec rule with years is in effect (XML) =#=#=#=
+
+
+
+
+=#=#=#= End test: Verify date_spec rule with years is in effect (XML) - OK (0) =#=#=#=
+* Passed: crm_rule - Verify date_spec rule with years is in effect (XML)
=#=#=#= Begin test: Try to check a rule whose date_spec does not contain years= =#=#=#=
-crm_rule: Rule either must not use date_spec, or use date_spec with years= but not moon=
-=#=#=#= End test: Try to check a rule whose date_spec does not contain years= - No such object (105) =#=#=#=
+Could not determine whether rule cli-prefer-rule-dummy-date_spec-without-years is in effect: Rule must either not use date_spec, or use date_spec with years= but not moon=
+=#=#=#= End test: Try to check a rule whose date_spec does not contain years= - Unimplemented (3) =#=#=#=
* Passed: crm_rule - Try to check a rule whose date_spec does not contain years=
+=#=#=#= Begin test: Try to check a rule whose date_spec does not contain years= (XML) =#=#=#=
+
+
+
+
+ Could not determine whether rule cli-prefer-rule-dummy-date_spec-without-years is in effect: Rule must either not use date_spec, or use date_spec with years= but not moon=
+
+
+
+=#=#=#= End test: Try to check a rule whose date_spec does not contain years= (XML) - Unimplemented (3) =#=#=#=
+* Passed: crm_rule - Try to check a rule whose date_spec does not contain years= (XML)
=#=#=#= Begin test: Try to check a rule whose date_spec contains years= and moon= =#=#=#=
-crm_rule: Rule either must not use date_spec, or use date_spec with years= but not moon=
-=#=#=#= End test: Try to check a rule whose date_spec contains years= and moon= - No such object (105) =#=#=#=
+Could not determine whether rule cli-prefer-rule-dummy-date_spec-years-moon is in effect: Rule must either not use date_spec, or use date_spec with years= but not moon=
+=#=#=#= End test: Try to check a rule whose date_spec contains years= and moon= - Unimplemented (3) =#=#=#=
* Passed: crm_rule - Try to check a rule whose date_spec contains years= and moon=
+=#=#=#= Begin test: Try to check a rule whose date_spec contains years= and moon= (XML) =#=#=#=
+
+
+
+
+ Could not determine whether rule cli-prefer-rule-dummy-date_spec-years-moon is in effect: Rule must either not use date_spec, or use date_spec with years= but not moon=
+
+
+
+=#=#=#= End test: Try to check a rule whose date_spec contains years= and moon= (XML) - Unimplemented (3) =#=#=#=
+* Passed: crm_rule - Try to check a rule whose date_spec contains years= and moon= (XML)
=#=#=#= Begin test: Try to check a rule with no date_expression =#=#=#=
-crm_rule: Can't check rule cli-no-date_expression-rule because it does not have exactly one date_expression
+Could not determine whether rule cli-no-date_expression-rule is in effect: Rule does not have a date expression
=#=#=#= End test: Try to check a rule with no date_expression - Unimplemented (3) =#=#=#=
* Passed: crm_rule - Try to check a rule with no date_expression
+=#=#=#= Begin test: Try to check a rule with no date_expression (XML) =#=#=#=
+
+
+
+
+ Could not determine whether rule cli-no-date_expression-rule is in effect: Rule does not have a date expression
+
+
+
+=#=#=#= End test: Try to check a rule with no date_expression (XML) - Unimplemented (3) =#=#=#=
+* Passed: crm_rule - Try to check a rule with no date_expression (XML)
diff --git a/cts/cts-cli.in b/cts/cts-cli.in
index 5e07a598ef..87bedbe819 100755
--- a/cts/cts-cli.in
+++ b/cts/cts-cli.in
@@ -1,2214 +1,2262 @@
#!@BASH_PATH@
#
# Copyright 2008-2022 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# or later (GPLv2+) WITHOUT ANY WARRANTY.
#
# Set the exit status of a command to the exit code of the last program to
# exit non-zero. This is bash-specific.
set -o pipefail
#
# Note on portable usage of sed: GNU/POSIX/*BSD sed have a limited subset of
# compatible functionality. Do not use the -i option, alternation (\|),
# \0, or character sequences such as \n or \s.
#
USAGE_TEXT="Usage: cts-cli []
Options:
--help Display this text, then exit
-V, --verbose Display any differences from expected output
-t 'TEST [...]' Run only specified tests (default: 'dates tools crm_mon acls validity upgrade rules feature_set')
-p DIR Look for executables in DIR (may be specified multiple times)
-v, --valgrind Run all commands under valgrind
-s Save actual output as expected output"
# If readlink supports -e (i.e. GNU), use it
readlink -e / >/dev/null 2>/dev/null
if [ $? -eq 0 ]; then
test_home="$(dirname "$(readlink -e "$0")")"
else
test_home="$(dirname "$0")"
fi
: ${shadow=cts-cli}
shadow_dir=$(mktemp -d ${TMPDIR:-/tmp}/cts-cli.shadow.XXXXXXXXXX)
num_errors=0
num_passed=0
verbose=0
tests="dates tools crm_mon acls validity upgrade rules feature_set"
do_save=0
XMLLINT_CMD=
VALGRIND_CMD=
VALGRIND_OPTS="
-q
--gen-suppressions=all
--show-reachable=no
--leak-check=full
--trace-children=no
--time-stamp=yes
--num-callers=20
--suppressions=$test_home/valgrind-pcmk.suppressions
"
# These constants must track crm_exit_t values
CRM_EX_OK=0
CRM_EX_ERROR=1
CRM_EX_INVALID_PARAM=2
CRM_EX_UNIMPLEMENT_FEATURE=3
CRM_EX_INSUFFICIENT_PRIV=4
CRM_EX_USAGE=64
CRM_EX_DATAERR=65
CRM_EX_CONFIG=78
CRM_EX_OLD=103
CRM_EX_DIGEST=104
CRM_EX_NOSUCH=105
CRM_EX_UNSAFE=107
CRM_EX_EXISTS=108
CRM_EX_MULTIPLE=109
CRM_EX_EXPIRED=110
CRM_EX_NOT_YET_IN_EFFECT=111
reset_shadow_cib_version() {
local SHADOWPATH
SHADOWPATH="$(crm_shadow --file)"
# sed -i isn't portable :-(
cp -p "$SHADOWPATH" "${SHADOWPATH}.$$" # preserve permissions
sed -e 's/epoch="[0-9]*"/epoch="1"/g' \
-e 's/num_updates="[0-9]*"/num_updates="0"/g' \
-e 's/admin_epoch="[0-9]*"/admin_epoch="0"/g' \
"$SHADOWPATH" > "${SHADOWPATH}.$$"
mv -- "${SHADOWPATH}.$$" "$SHADOWPATH"
}
# A newly created empty CIB might or might not have a rsc_defaults section
# depending on whether the --with-resource-stickiness-default configure
# option was used. To ensure regression tests behave the same either way,
# delete any rsc_defaults after creating or erasing a CIB.
delete_shadow_resource_defaults() {
cibadmin --delete --xml-text ''
# The above command might or might not bump the CIB version, so reset it
# to ensure future changes result in the same version for comparison.
reset_shadow_cib_version
}
create_shadow_cib() {
local VALIDATE_WITH
local SHADOW_CMD
VALIDATE_WITH="$1"
export CIB_shadow_dir="${shadow_dir}"
SHADOW_CMD="$VALGRIND_CMD crm_shadow --batch --force --create-empty"
if [ -z "$VALIDATE_WITH" ]; then
$SHADOW_CMD "$shadow" 2>&1
else
$SHADOW_CMD "$shadow" --validate-with="${VALIDATE_WITH}" 2>&1
fi
export CIB_shadow="$shadow"
delete_shadow_resource_defaults
}
function _test_assert() {
target=$1; shift
validate=$1; shift
cib=$1; shift
app=`echo "$cmd" | sed 's/\ .*//'`
printf "* Running: $app - $desc\n" 1>&2
printf "=#=#=#= Begin test: $desc =#=#=#=\n"
export outfile=$(mktemp ${TMPDIR:-/tmp}/cts-cli.output.XXXXXXXXXX)
eval $VALGRIND_CMD $cmd 2>&1 | tee $outfile
rc=$?
if [ x$cib != x0 ]; then
printf "=#=#=#= Current cib after: $desc =#=#=#=\n"
CIB_user=root cibadmin -Q
fi
# Do not validate if running under valgrind, even if told to do so. Valgrind
# will output a lot more stuff that is not XML, so it wouldn't validate anyway.
if [ "$validate" = "1" ] && [ "$VALGRIND_CMD" = "" ] && [ $rc = 0 ] && [ "$XMLLINT_CMD" != "" ]; then
# The sed command filters out the "- validates" line that xmllint will output
# on success. grep cannot be used here because "grep -v 'validates$'" will
# return an exit code of 1 if its input consists entirely of "- validates".
$XMLLINT_CMD --noout --relaxng "$PCMK_schema_directory/api/api-result.rng" "$outfile" 2>&1 | sed -n '/validates$/ !p'
rc=$?
if [ $rc = 0 ]; then
printf "=#=#=#= End test: %s - $(crm_error --exit $rc) (%d) =#=#=#=\n" "$desc" $rc
else
printf "=#=#=#= End test: %s - Failed to validate (%d) =#=#=#=\n" "$desc" $rc
fi
else
printf "=#=#=#= End test: %s - $(crm_error --exit $rc) (%d) =#=#=#=\n" "$desc" $rc
fi
rm -f "$outfile"
if [ $rc -ne $target ]; then
num_errors=$(( $num_errors + 1 ))
printf "* Failed (rc=%.3d): %-14s - %s\n" $rc $app "$desc"
printf "* Failed (rc=%.3d): %-14s - %s\n" $rc $app "$desc (`which $app`)" 1>&2
return
exit $CRM_EX_ERROR
else
printf "* Passed: %-14s - %s\n" $app "$desc"
num_passed=$(( $num_passed + 1 ))
fi
}
function test_assert() {
_test_assert $1 0 $2
}
function test_assert_validate() {
_test_assert $1 1 $2
}
function test_crm_mon() {
local TMPXML
export CIB_file="$test_home/cli/crm_mon.xml"
desc="Basic text output"
cmd="crm_mon -1"
test_assert $CRM_EX_OK 0
desc="XML output"
cmd="crm_mon --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output without node section"
cmd="crm_mon -1 --exclude=nodes"
test_assert $CRM_EX_OK 0
desc="XML output without the node section"
cmd="crm_mon --output-as=xml --exclude=nodes"
test_assert_validate $CRM_EX_OK 0
desc="Text output with only the node section"
cmd="crm_mon -1 --exclude=all --include=nodes"
test_assert $CRM_EX_OK 0
# The above test doesn't need to be performed for other output formats. It's
# really just a test to make sure that blank lines are correct.
desc="Complete text output"
cmd="crm_mon -1 --include=all"
test_assert $CRM_EX_OK 0
# XML includes everything already so there's no need for a complete test
desc="Complete text output with detail"
cmd="crm_mon -1R --include=all"
test_assert $CRM_EX_OK 0
# XML includes detailed output already
desc="Complete brief text output"
cmd="crm_mon -1 --include=all --brief"
test_assert $CRM_EX_OK 0
desc="Complete text output grouped by node"
cmd="crm_mon -1 --include=all --group-by-node"
test_assert $CRM_EX_OK 0
# XML does not have a brief output option
desc="Complete brief text output grouped by node"
cmd="crm_mon -1 --include=all --group-by-node --brief"
test_assert $CRM_EX_OK 0
desc="XML output grouped by node"
cmd="crm_mon -1 --output-as=xml --group-by-node"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output filtered by node"
cmd="crm_mon -1 --include=all --node=cluster01"
test_assert $CRM_EX_OK 0
desc="XML output filtered by node"
cmd="crm_mon --output-as xml --include=all --node=cluster01"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output filtered by tag"
cmd="crm_mon -1 --include=all --node=even-nodes"
test_assert $CRM_EX_OK 0
desc="XML output filtered by tag"
cmd="crm_mon --output-as=xml --include=all --node=even-nodes"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output filtered by resource tag"
cmd="crm_mon -1 --include=all --resource=fencing-rscs"
test_assert $CRM_EX_OK 0
desc="XML output filtered by resource tag"
cmd="crm_mon --output-as=xml --include=all --resource=fencing-rscs"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output filtered by node that doesn't exist"
cmd="crm_mon -1 --node=blah"
test_assert $CRM_EX_OK 0
desc="XML output filtered by node that doesn't exist"
cmd="crm_mon --output-as=xml --node=blah"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output with inactive resources"
cmd="crm_mon -1 -r"
test_assert $CRM_EX_OK 0
# XML already includes inactive resources
desc="Basic text output with inactive resources, filtered by node"
cmd="crm_mon -1 -r --node=cluster02"
test_assert $CRM_EX_OK 0
# XML already includes inactive resources
desc="Complete text output filtered by primitive resource"
cmd="crm_mon -1 --include=all --resource=Fencing"
test_assert $CRM_EX_OK 0
desc="XML output filtered by primitive resource"
cmd="crm_mon --output-as=xml --resource=Fencing"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output filtered by group resource"
cmd="crm_mon -1 --include=all --resource=exim-group"
test_assert $CRM_EX_OK 0
desc="XML output filtered by group resource"
cmd="crm_mon --output-as=xml --resource=exim-group"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output filtered by group resource member"
cmd="crm_mon -1 --include=all --resource=Public-IP"
test_assert $CRM_EX_OK 0
desc="XML output filtered by group resource member"
cmd="crm_mon --output-as=xml --resource=Email"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output filtered by clone resource"
cmd="crm_mon -1 --include=all --resource=ping-clone"
test_assert $CRM_EX_OK 0
desc="XML output filtered by clone resource"
cmd="crm_mon --output-as=xml --resource=ping-clone"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output filtered by clone resource instance"
cmd="crm_mon -1 --include=all --resource=ping"
test_assert $CRM_EX_OK 0
desc="XML output filtered by clone resource instance"
cmd="crm_mon --output-as=xml --resource=ping"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output filtered by exact clone resource instance"
cmd="crm_mon -1 --include=all --show-detail --resource=ping:0"
test_assert $CRM_EX_OK 0
desc="XML output filtered by exact clone resource instance"
cmd="crm_mon --output-as=xml --resource=ping:1"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output filtered by resource that doesn't exist"
cmd="crm_mon -1 --resource=blah"
test_assert $CRM_EX_OK 0
desc="XML output filtered by resource that doesn't exist"
cmd="crm_mon --output-as=xml --resource=blah"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output with inactive resources, filtered by tag"
cmd="crm_mon -1 -r --resource=inactive-rscs"
test_assert $CRM_EX_OK 0
desc="Basic text output with inactive resources, filtered by bundle resource"
cmd="crm_mon -1 -r --resource=httpd-bundle"
test_assert $CRM_EX_OK 0
desc="XML output filtered by inactive bundle resource"
cmd="crm_mon --output-as=xml --resource=httpd-bundle"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output with inactive resources, filtered by bundled IP address resource"
cmd="crm_mon -1 -r --resource=httpd-bundle-ip-192.168.122.131"
test_assert $CRM_EX_OK 0
desc="XML output filtered by bundled IP address resource"
cmd="crm_mon --output-as=xml --resource=httpd-bundle-ip-192.168.122.132"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output with inactive resources, filtered by bundled container"
cmd="crm_mon -1 -r --resource=httpd-bundle-docker-1"
test_assert $CRM_EX_OK 0
desc="XML output filtered by bundled container"
cmd="crm_mon --output-as=xml --resource=httpd-bundle-docker-2"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output with inactive resources, filtered by bundle connection"
cmd="crm_mon -1 -r --resource=httpd-bundle-0"
test_assert $CRM_EX_OK 0
desc="XML output filtered by bundle connection"
cmd="crm_mon --output-as=xml --resource=httpd-bundle-0"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output with inactive resources, filtered by bundled primitive resource"
cmd="crm_mon -1 -r --resource=httpd"
test_assert $CRM_EX_OK 0
desc="XML output filtered by bundled primitive resource"
cmd="crm_mon --output-as=xml --resource=httpd"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output, filtered by clone name in cloned group"
cmd="crm_mon -1 --include=all --show-detail --resource=mysql-clone-group"
test_assert $CRM_EX_OK 0
desc="XML output, filtered by clone name in cloned group"
cmd="crm_mon --output-as=xml --resource=mysql-clone-group"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output, filtered by group name in cloned group"
cmd="crm_mon -1 --include=all --show-detail --resource=mysql-group"
test_assert $CRM_EX_OK 0
desc="XML output, filtered by group name in cloned group"
cmd="crm_mon --output-as=xml --resource=mysql-group"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output, filtered by exact group instance name in cloned group"
cmd="crm_mon -1 --include=all --show-detail --resource=mysql-group:1"
test_assert $CRM_EX_OK 0
desc="XML output, filtered by exact group instance name in cloned group"
cmd="crm_mon --output-as=xml --resource=mysql-group:1"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output, filtered by primitive name in cloned group"
cmd="crm_mon -1 --include=all --show-detail --resource=mysql-proxy"
test_assert $CRM_EX_OK 0
desc="XML output, filtered by primitive name in cloned group"
cmd="crm_mon --output-as=xml --resource=mysql-proxy"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output, filtered by exact primitive instance name in cloned group"
cmd="crm_mon -1 --include=all --show-detail --resource=mysql-proxy:1"
test_assert $CRM_EX_OK 0
desc="XML output, filtered by exact primitive instance name in cloned group"
cmd="crm_mon --output-as=xml --resource=mysql-proxy:1"
test_assert_validate $CRM_EX_OK 0
unset CIB_file
export CIB_file="$test_home/cli/crm_mon-partial.xml"
desc="Text output of partially active resources"
cmd="crm_mon -1 --show-detail"
test_assert $CRM_EX_OK 0
desc="XML output of partially active resources"
cmd="crm_mon -1 --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Text output of partially active resources, with inactive resources"
cmd="crm_mon -1 -r --show-detail"
test_assert $CRM_EX_OK 0
# XML already includes inactive resources
desc="Complete brief text output, with inactive resources"
cmd="crm_mon -1 -r --include=all --brief --show-detail"
test_assert $CRM_EX_OK 0
# XML does not have a brief output option
desc="Text output of partially active group"
cmd="crm_mon -1 --resource=partially-active-group"
test_assert $CRM_EX_OK 0
desc="Text output of partially active group, with inactive resources"
cmd="crm_mon -1 --resource=partially-active-group -r"
test_assert $CRM_EX_OK 0
desc="Text output of active member of partially active group"
cmd="crm_mon -1 --resource=dummy-1"
test_assert $CRM_EX_OK 0
desc="Text output of inactive member of partially active group"
cmd="crm_mon -1 --resource=dummy-2 --show-detail"
test_assert $CRM_EX_OK 0
desc="Complete brief text output grouped by node, with inactive resources"
cmd="crm_mon -1 -r --include=all --group-by-node --brief --show-detail"
test_assert $CRM_EX_OK 0
desc="Text output of partially active resources, with inactive resources, filtered by node"
cmd="crm_mon -1 -r --node=cluster01"
test_assert $CRM_EX_OK 0
desc="Text output of partially active resources, filtered by node"
cmd="crm_mon -1 --output-as=xml --node=cluster01"
test_assert_validate $CRM_EX_OK 0
unset CIB_file
export CIB_file="$test_home/cli/crm_mon-unmanaged.xml"
desc="Text output of active unmanaged resource on offline node"
cmd="crm_mon -1"
test_assert $CRM_EX_OK 0
desc="XML output of active unmanaged resource on offline node"
cmd="crm_mon -1 --output-as=xml"
test_assert $CRM_EX_OK 0
desc="Brief text output of active unmanaged resource on offline node"
cmd="crm_mon -1 --brief"
test_assert $CRM_EX_OK 0
desc="Brief text output of active unmanaged resource on offline node, grouped by node"
cmd="crm_mon -1 --brief --group-by-node"
test_assert $CRM_EX_OK 0
export CIB_file=$(mktemp ${TMPDIR:-/tmp}/cts-cli.crm_mon.xml.XXXXXXXXXX)
sed -e '/maintenance-mode/ s/false/true/' "$test_home/cli/crm_mon.xml" > $CIB_file
desc="Text output of all resources with maintenance-mode enabled"
cmd="crm_mon -1 -r"
test_assert $CRM_EX_OK 0
rm -r "$CIB_file"
unset CIB_file
}
function test_tools() {
local TMPXML
local TMPORIG
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
TMPORIG=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.existing.xml.XXXXXXXXXX)
create_shadow_cib
desc="Validate CIB"
cmd="cibadmin -Q"
test_assert $CRM_EX_OK
desc="Query the value of an attribute that does not exist"
cmd="crm_attribute -n ABCD --query --quiet"
test_assert $CRM_EX_NOSUCH 0
desc="Configure something before erasing"
cmd="crm_attribute -n cluster-delay -v 60s"
test_assert $CRM_EX_OK
desc="Require --force for CIB erasure"
cmd="cibadmin -E"
test_assert $CRM_EX_UNSAFE
desc="Allow CIB erasure with --force"
cmd="cibadmin -E --force"
test_assert $CRM_EX_OK 0
# Skip outputting the resulting CIB in the previous command, and delete
# rsc_defaults now, so tests behave the same regardless of build options.
delete_shadow_resource_defaults
# Verify the output after erasure
desc="Query CIB"
cmd="cibadmin -Q"
test_assert $CRM_EX_OK
# Save a copy of the CIB for a later test
cibadmin -Q > "$TMPORIG"
desc="Set cluster option"
cmd="crm_attribute -n cluster-delay -v 60s"
test_assert $CRM_EX_OK
desc="Query new cluster option"
cmd="cibadmin -Q -o crm_config | grep cib-bootstrap-options-cluster-delay"
test_assert $CRM_EX_OK
desc="Query cluster options"
cmd="cibadmin -Q -o crm_config > $TMPXML"
test_assert $CRM_EX_OK
desc="Set no-quorum policy"
cmd="crm_attribute -n no-quorum-policy -v ignore"
test_assert $CRM_EX_OK
desc="Delete nvpair"
cmd="cibadmin -D -o crm_config --xml-text ''"
test_assert $CRM_EX_OK
desc="Create operation should fail"
cmd="cibadmin -C -o crm_config --xml-file $TMPXML"
test_assert $CRM_EX_EXISTS
desc="Modify cluster options section"
cmd="cibadmin -M -o crm_config --xml-file $TMPXML"
test_assert $CRM_EX_OK
desc="Query updated cluster option"
cmd="cibadmin -Q -o crm_config | grep cib-bootstrap-options-cluster-delay"
test_assert $CRM_EX_OK
desc="Set duplicate cluster option"
cmd="crm_attribute -n cluster-delay -v 40s -s duplicate"
test_assert $CRM_EX_OK
desc="Setting multiply defined cluster option should fail"
cmd="crm_attribute -n cluster-delay -v 30s"
test_assert $CRM_EX_MULTIPLE
desc="Set cluster option with -s"
cmd="crm_attribute -n cluster-delay -v 30s -s duplicate"
test_assert $CRM_EX_OK
desc="Delete cluster option with -i"
cmd="crm_attribute -n cluster-delay -D -i cib-bootstrap-options-cluster-delay"
test_assert $CRM_EX_OK
desc="Create node1 and bring it online"
cmd="crm_simulate --live-check --in-place --node-up=node1"
test_assert $CRM_EX_OK
desc="Create node attribute"
cmd="crm_attribute -n ram -v 1024M -N node1 -t nodes"
test_assert $CRM_EX_OK
desc="Query new node attribute"
cmd="cibadmin -Q -o nodes | grep node1-ram"
test_assert $CRM_EX_OK
desc="Set a transient (fail-count) node attribute"
cmd="crm_attribute -n fail-count-foo -v 3 -N node1 -t status"
test_assert $CRM_EX_OK
desc="Query a fail count"
cmd="crm_failcount --query -r foo -N node1"
test_assert $CRM_EX_OK
desc="Show node attributes with crm_simulate"
cmd="crm_simulate --live-check --show-attrs"
test_assert $CRM_EX_OK 0
desc="Set a second transient node attribute"
cmd="crm_attribute -n fail-count-bar -v 5 -N node1 -t status"
test_assert $CRM_EX_OK
desc="Query node attributes by pattern"
cmd="crm_attribute -t status -P fail-count -N node1 --query"
test_assert $CRM_EX_OK 0
desc="Update node attributes by pattern"
cmd="crm_attribute -t status -P fail-count -N node1 -v 10"
test_assert $CRM_EX_OK
desc="Delete node attributes by pattern"
cmd="crm_attribute -t status -P fail-count -N node1 -D"
test_assert $CRM_EX_OK
desc="crm_attribute given invalid pattern usage"
cmd="crm_attribute -t nodes -P fail-count -N node1 -D"
test_assert $CRM_EX_USAGE 0
desc="crm_attribute given invalid delete usage"
cmd="crm_attribute -t nodes -N node1 -D"
test_assert $CRM_EX_USAGE 0
desc="Digest calculation"
cmd="cibadmin -Q | cibadmin -5 -p 2>&1 > /dev/null"
test_assert $CRM_EX_OK
# This update will fail because it has version numbers
desc="Replace operation should fail"
cmd="cibadmin -R --xml-file $TMPORIG"
test_assert $CRM_EX_OLD
desc="Default standby value"
cmd="crm_standby -N node1 -G"
test_assert $CRM_EX_OK
desc="Set standby status"
cmd="crm_standby -N node1 -v true"
test_assert $CRM_EX_OK
desc="Query standby value"
cmd="crm_standby -N node1 -G"
test_assert $CRM_EX_OK
desc="Delete standby value"
cmd="crm_standby -N node1 -D"
test_assert $CRM_EX_OK
desc="Create a resource"
cmd="cibadmin -C -o resources --xml-text ''"
test_assert $CRM_EX_OK
desc="crm_resource run with extra arguments"
cmd="crm_resource foo bar"
test_assert $CRM_EX_USAGE 0
desc="crm_resource given both -r and resource config"
cmd="crm_resource -r xyz --class ocf --provider pacemaker --agent Dummy"
test_assert $CRM_EX_USAGE 0
desc="crm_resource given resource config with invalid action"
cmd="crm_resource --class ocf --provider pacemaker --agent Dummy -D"
test_assert $CRM_EX_USAGE 0
desc="Create a resource meta attribute"
cmd="crm_resource -r dummy --meta -p is-managed -v false"
test_assert $CRM_EX_OK
desc="Query a resource meta attribute"
cmd="crm_resource -r dummy --meta -g is-managed"
test_assert $CRM_EX_OK
desc="Remove a resource meta attribute"
cmd="crm_resource -r dummy --meta -d is-managed"
test_assert $CRM_EX_OK
desc="Create another resource meta attribute"
cmd="crm_resource -r dummy --meta -p target-role -v Stopped --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Show why a resource is not running"
cmd="crm_resource -Y -r dummy --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Remove another resource meta attribute"
cmd="crm_resource -r dummy --meta -d target-role --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Create a resource attribute"
cmd="crm_resource -r dummy -p delay -v 10s"
test_assert $CRM_EX_OK
desc="List the configured resources"
cmd="crm_resource -L"
test_assert $CRM_EX_OK
desc="List the configured resources in XML"
cmd="crm_resource -L --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Implicitly list the configured resources"
cmd="crm_resource"
test_assert $CRM_EX_OK 0
desc="List IDs of instantiated resources"
cmd="crm_resource -l"
test_assert $CRM_EX_OK 0
desc="Show XML configuration of resource"
cmd="crm_resource -q -r dummy"
test_assert $CRM_EX_OK 0
desc="Require a destination when migrating a resource that is stopped"
cmd="crm_resource -r dummy -M"
test_assert $CRM_EX_USAGE
desc="Don't support migration to non-existent locations"
cmd="crm_resource -r dummy -M -N i.do.not.exist"
test_assert $CRM_EX_NOSUCH
desc="Create a fencing resource"
cmd="cibadmin -C -o resources --xml-text ''"
test_assert $CRM_EX_OK
desc="Bring resources online"
cmd="crm_simulate --live-check --in-place -S"
test_assert $CRM_EX_OK
desc="Try to move a resource to its existing location"
cmd="crm_resource -r dummy --move --node node1"
test_assert $CRM_EX_EXISTS
desc="Try to move a resource that doesn't exist"
cmd="crm_resource -r xyz --move --node node1"
test_assert $CRM_EX_NOSUCH 0
desc="Move a resource from its existing location"
cmd="crm_resource -r dummy --move"
test_assert $CRM_EX_OK
desc="Clear out constraints generated by --move"
cmd="crm_resource -r dummy --clear"
test_assert $CRM_EX_OK
desc="Default ticket granted state"
cmd="crm_ticket -t ticketA -G granted -d false"
test_assert $CRM_EX_OK
desc="Set ticket granted state"
cmd="crm_ticket -t ticketA -r --force"
test_assert $CRM_EX_OK
desc="Query ticket granted state"
cmd="crm_ticket -t ticketA -G granted"
test_assert $CRM_EX_OK
desc="Delete ticket granted state"
cmd="crm_ticket -t ticketA -D granted --force"
test_assert $CRM_EX_OK
desc="Make a ticket standby"
cmd="crm_ticket -t ticketA -s"
test_assert $CRM_EX_OK
desc="Query ticket standby state"
cmd="crm_ticket -t ticketA -G standby"
test_assert $CRM_EX_OK
desc="Activate a ticket"
cmd="crm_ticket -t ticketA -a"
test_assert $CRM_EX_OK
desc="Delete ticket standby state"
cmd="crm_ticket -t ticketA -D standby"
test_assert $CRM_EX_OK
desc="Ban a resource on unknown node"
cmd="crm_resource -r dummy -B -N host1"
test_assert $CRM_EX_NOSUCH
desc="Create two more nodes and bring them online"
cmd="crm_simulate --live-check --in-place --node-up=node2 --node-up=node3"
test_assert $CRM_EX_OK
desc="Ban dummy from node1"
cmd="crm_resource -r dummy -B -N node1"
test_assert $CRM_EX_OK
desc="Show where a resource is running"
cmd="crm_resource -r dummy -W"
test_assert $CRM_EX_OK 0
desc="Show constraints on a resource"
cmd="crm_resource -a -r dummy"
test_assert $CRM_EX_OK 0
desc="Ban dummy from node2"
cmd="crm_resource -r dummy -B -N node2 --output-as=xml"
test_assert_validate $CRM_EX_OK
desc="Relocate resources due to ban"
cmd="crm_simulate --live-check --in-place -S"
test_assert $CRM_EX_OK
desc="Move dummy to node1"
cmd="crm_resource -r dummy -M -N node1 --output-as=xml"
test_assert_validate $CRM_EX_OK
desc="Clear implicit constraints for dummy on node2"
cmd="crm_resource -r dummy -U -N node2"
test_assert $CRM_EX_OK
desc="Drop the status section"
cmd="cibadmin -R -o status --xml-text ''"
test_assert $CRM_EX_OK 0
desc="Create a clone"
cmd="cibadmin -C -o resources --xml-text ''"
test_assert $CRM_EX_OK 0
desc="Create a resource meta attribute"
cmd="crm_resource -r test-primitive --meta -p is-managed -v false"
test_assert $CRM_EX_OK
desc="Create a resource meta attribute in the primitive"
cmd="crm_resource -r test-primitive --meta -p is-managed -v false --force"
test_assert $CRM_EX_OK
desc="Update resource meta attribute with duplicates"
cmd="crm_resource -r test-clone --meta -p is-managed -v true"
test_assert $CRM_EX_OK
desc="Update resource meta attribute with duplicates (force clone)"
cmd="crm_resource -r test-clone --meta -p is-managed -v true --force"
test_assert $CRM_EX_OK
desc="Update child resource meta attribute with duplicates"
cmd="crm_resource -r test-primitive --meta -p is-managed -v false"
test_assert $CRM_EX_OK
desc="Delete resource meta attribute with duplicates"
cmd="crm_resource -r test-clone --meta -d is-managed"
test_assert $CRM_EX_OK
desc="Delete resource meta attribute in parent"
cmd="crm_resource -r test-primitive --meta -d is-managed"
test_assert $CRM_EX_OK
desc="Create a resource meta attribute in the primitive"
cmd="crm_resource -r test-primitive --meta -p is-managed -v false --force"
test_assert $CRM_EX_OK
desc="Update existing resource meta attribute"
cmd="crm_resource -r test-clone --meta -p is-managed -v true"
test_assert $CRM_EX_OK
desc="Create a resource meta attribute in the parent"
cmd="crm_resource -r test-clone --meta -p is-managed -v true --force"
test_assert $CRM_EX_OK
desc="Copy resources"
cmd="cibadmin -Q -o resources > $TMPXML"
test_assert $CRM_EX_OK 0
desc="Delete resource parent meta attribute (force)"
cmd="crm_resource -r test-clone --meta -d is-managed --force"
test_assert $CRM_EX_OK
desc="Restore duplicates"
cmd="cibadmin -R -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK
desc="Delete resource child meta attribute"
cmd="crm_resource -r test-primitive --meta -d is-managed"
test_assert $CRM_EX_OK
cibadmin -C -o resources --xml-text ' \
\
\
'
desc="Create a resource meta attribute in dummy1"
cmd="crm_resource -r dummy1 --meta -p is-managed -v true"
test_assert $CRM_EX_OK
desc="Create a resource meta attribute in dummy-group"
cmd="crm_resource -r dummy-group --meta -p is-managed -v false"
test_assert $CRM_EX_OK
cibadmin -D -o resource --xml-text ''
desc="Specify a lifetime when moving a resource"
cmd="crm_resource -r dummy --move --node node2 --lifetime=PT1H"
test_assert $CRM_EX_OK
desc="Try to move a resource previously moved with a lifetime"
cmd="crm_resource -r dummy --move --node node1"
test_assert $CRM_EX_OK
desc="Ban dummy from node1 for a short time"
cmd="crm_resource -r dummy -B -N node1 --lifetime=PT1S"
test_assert $CRM_EX_OK
desc="Remove expired constraints"
sleep 2
cmd="crm_resource --clear --expired"
test_assert $CRM_EX_OK
# Clear has already been tested elsewhere, but we need to get rid of the
# constraints so testing delete works. It won't delete if there's still
# a reference to the resource somewhere.
desc="Clear all implicit constraints for dummy"
cmd="crm_resource -r dummy -U"
test_assert $CRM_EX_OK
desc="Set a node health strategy"
cmd="crm_attribute -n node-health-strategy -v migrate-on-red"
test_assert $CRM_EX_OK
desc="Set a node health attribute"
cmd="crm_attribute -N node3 -n '#health-cts-cli' -v red"
test_assert $CRM_EX_OK
desc="Show why a resource is not running on an unhealthy node"
cmd="crm_resource -N node3 -Y -r dummy --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Delete a resource"
cmd="crm_resource -D -r dummy -t primitive"
test_assert $CRM_EX_OK
unset CIB_shadow
unset CIB_shadow_dir
desc="Create an XML patchset"
cmd="crm_diff -o $test_home/cli/crm_diff_old.xml -n $test_home/cli/crm_diff_new.xml"
test_assert $CRM_EX_ERROR 0
export CIB_file="$test_home/cli/constraints.xml"
for rsc in prim1 prim2 prim3 prim4 prim5 prim6 prim7 prim8 prim9 \
prim10 prim11 prim12 prim13 group clone; do
desc="Check locations and constraints for $rsc"
cmd="crm_resource -a -r $rsc"
test_assert $CRM_EX_OK 0
desc="Recursively check locations and constraints for $rsc"
cmd="crm_resource -A -r $rsc"
test_assert $CRM_EX_OK 0
desc="Check locations and constraints for $rsc in XML"
cmd="crm_resource -a -r $rsc --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Recursively check locations and constraints for $rsc in XML"
cmd="crm_resource -A -r $rsc --output-as=xml"
test_assert_validate $CRM_EX_OK 0
done
unset CIB_file
export CIB_file="$test_home/cli/crm_resource_digests.xml"
desc="Show resource digests"
cmd="crm_resource --digests -r rsc1 -N node1 --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Show resource digests with overrides"
cmd="$cmd CRM_meta_interval=10000 CRM_meta_timeout=20000"
test_assert $CRM_EX_OK 0
unset CIB_file
export CIB_file="$test_home/cli/crmadmin-cluster-remote-guest-nodes.xml"
desc="List all nodes"
cmd="crmadmin -N | wc -l | grep 11"
test_assert $CRM_EX_OK 0
desc="List cluster nodes"
cmd="crmadmin -N cluster | wc -l | grep 6"
test_assert $CRM_EX_OK 0
desc="List guest nodes"
cmd="crmadmin -N guest | wc -l | grep 2"
test_assert $CRM_EX_OK 0
desc="List remote nodes"
cmd="crmadmin -N remote | wc -l | grep 3"
test_assert $CRM_EX_OK 0
desc="List cluster,remote nodes"
cmd="crmadmin -N cluster,remote | wc -l | grep 9"
test_assert $CRM_EX_OK 0
desc="List guest,remote nodes"
cmd="crmadmin -N guest,remote | wc -l | grep 5"
test_assert $CRM_EX_OK 0
unset CIB_file
export CIB_file="$test_home/cli/crm_mon.xml"
export CIB_shadow_dir="${shadow_dir}"
desc="Show allocation scores with crm_simulate"
cmd="crm_simulate -x $CIB_file --show-scores --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Show utilization with crm_simulate"
cmd="crm_simulate -x $CIB_file --show-utilization"
test_assert $CRM_EX_OK 0
desc="Simulate injecting a failure"
cmd="crm_simulate -x $CIB_file -S -i ping_monitor_10000@cluster02=1"
test_assert $CRM_EX_OK 0
desc="Simulate bringing a node down"
cmd="crm_simulate -x $CIB_file -S --node-down=cluster01"
test_assert $CRM_EX_OK 0
desc="Simulate a node failing"
cmd="crm_simulate -x $CIB_file -S --node-fail=cluster02"
test_assert $CRM_EX_OK 0
unset CIB_shadow_dir
desc="List a promotable clone resource"
cmd="crm_resource --locate -r promotable-clone"
test_assert $CRM_EX_OK 0
desc="List the primitive of a promotable clone resource"
cmd="crm_resource --locate -r promotable-rsc"
test_assert $CRM_EX_OK 0
desc="List a single instance of a promotable clone resource"
cmd="crm_resource --locate -r promotable-rsc:0"
test_assert $CRM_EX_OK 0
desc="List another instance of a promotable clone resource"
cmd="crm_resource --locate -r promotable-rsc:1"
test_assert $CRM_EX_OK 0
desc="List a promotable clone resource in XML"
cmd="crm_resource --locate -r promotable-clone --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="List the primitive of a promotable clone resource in XML"
cmd="crm_resource --locate -r promotable-rsc --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="List a single instance of a promotable clone resource in XML"
cmd="crm_resource --locate -r promotable-rsc:0 --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="List another instance of a promotable clone resource in XML"
cmd="crm_resource --locate -r promotable-rsc:1 --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Try to move an instance of a cloned resource"
cmd="crm_resource -r promotable-rsc:0 --move --node node1"
test_assert $CRM_EX_INVALID_PARAM 0
# Create a sandbox copy of crm_mon.xml
cibadmin -Q > "$TMPXML"
export CIB_file="$TMPXML"
desc="Query a nonexistent promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G"
test_assert $CRM_EX_NOSUCH 0
desc="Query a nonexistent promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
desc="Delete a nonexistent promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -D"
test_assert $CRM_EX_OK 0
desc="Delete a nonexistent promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -D --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Query after deleting a nonexistent promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G"
test_assert $CRM_EX_NOSUCH 0
desc="Query after deleting a nonexistent promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
desc="Update a nonexistent promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -v 1"
test_assert $CRM_EX_OK 0
desc="Update a nonexistent promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -v 1 --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Query after updating a nonexistent promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G"
test_assert $CRM_EX_OK 0
desc="Query after updating a nonexistent promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Update an existing promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -v 5"
test_assert $CRM_EX_OK 0
desc="Update an existing promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -v 5 --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Query after updating an existing promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G"
test_assert $CRM_EX_OK 0
desc="Query after updating an existing promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Delete an existing promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -D"
test_assert $CRM_EX_OK 0
desc="Delete an existing promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -D --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Query after deleting an existing promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G"
test_assert $CRM_EX_NOSUCH 0
desc="Query after deleting an existing promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
unset CIB_file
export CIB_file="-"
desc="Check that CIB_file=\"-\" works - crm_mon"
cmd="cat $test_home/cli/crm_mon.xml | crm_mon -1"
test_assert $CRM_EX_OK 0
desc="Check that CIB_file=\"-\" works - crm_resource"
cmd="cat $test_home/cli/crm_resource_digests.xml | crm_resource --digests -r rsc1 -N node1 --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Check that CIB_file=\"-\" works - crmadmin"
cmd="cat $test_home/cli/crmadmin-cluster-remote-guest-nodes.xml | crmadmin -N | wc -l | grep 11"
test_assert $CRM_EX_OK 0
unset CIB_file
rm -f "$TMPXML" "$TMPORIG"
}
INVALID_PERIODS=(
"2019-01-01 00:00:00Z" # Start with no end
"2019-01-01 00:00:00Z/" # Start with only a trailing slash
"PT2S/P1M" # Two durations
"2019-13-01 00:00:00Z/P1M" # Out-of-range month
"20191077T15/P1M" # Out-of-range day
"2019-10-01T25:00:00Z/P1M" # Out-of-range hour
"2019-10-01T24:00:01Z/P1M" # Hour 24 with anything but :00:00
"PT5H/20191001T007000Z" # Out-of-range minute
"2019-10-01 00:00:80Z/P1M" # Out-of-range second
"2019-10-01 00:00:10 +25:00/P1M" # Out-of-range offset hour
"20191001T000010 -00:61/P1M" # Out-of-range offset minute
"P1Y/2019-02-29 00:00:00Z" # Feb. 29 in non-leap-year
"2019-01-01 00:00:00Z/P" # Duration with no values
"P1Z/2019-02-20 00:00:00Z" # Invalid duration unit
"P1YM/2019-02-20 00:00:00Z" # No number for duration unit
)
function test_dates() {
# Ensure invalid period specifications are rejected
for spec in '' "${INVALID_PERIODS[@]}"; do
desc="Invalid period - [$spec]"
cmd="iso8601 -p \"$spec\""
test_assert $CRM_EX_INVALID_PARAM 0
done
desc="2014-01-01 00:30:00 - 1 Hour"
cmd="iso8601 -d '2014-01-01 00:30:00Z' -D P-1H -E '2013-12-31 23:30:00Z'"
test_assert $CRM_EX_OK 0
desc="Valid date - Feb 29 in leap year"
cmd="iso8601 -d '2020-02-29 00:00:00Z' -E '2020-02-29 00:00:00Z'"
test_assert $CRM_EX_OK 0
desc="Valid date - using 'T' and offset"
cmd="iso8601 -d '20191201T131211 -05:00' -E '2019-12-01 18:12:11Z'"
test_assert $CRM_EX_OK 0
desc="24:00:00 equivalent to 00:00:00 of next day"
cmd="iso8601 -d '2019-12-31 24:00:00Z' -E '2020-01-01 00:00:00Z'"
test_assert $CRM_EX_OK 0
for y in 06 07 08 09 10 11 12 13 14 15 16 17 18 40; do
desc="20$y-W01-7"
cmd="iso8601 -d '20$y-W01-7 00Z'"
test_assert $CRM_EX_OK 0
desc="20$y-W01-7 - round-trip"
cmd="iso8601 -d '20$y-W01-7 00Z' -W -E '20$y-W01-7 00:00:00Z'"
test_assert $CRM_EX_OK 0
desc="20$y-W01-1"
cmd="iso8601 -d '20$y-W01-1 00Z'"
test_assert $CRM_EX_OK 0
desc="20$y-W01-1 - round-trip"
cmd="iso8601 -d '20$y-W01-1 00Z' -W -E '20$y-W01-1 00:00:00Z'"
test_assert $CRM_EX_OK 0
done
desc="2009-W53-07"
cmd="iso8601 -d '2009-W53-7 00:00:00Z' -W -E '2009-W53-7 00:00:00Z'"
test_assert $CRM_EX_OK 0
desc="epoch + 2 Years 5 Months 6 Minutes"
cmd="iso8601 -d 'epoch' -D P2Y5MT6M -E '1972-06-01 00:06:00Z'"
test_assert $CRM_EX_OK 0
desc="2009-01-31 + 1 Month"
cmd="iso8601 -d '20090131T000000Z' -D P1M -E '2009-02-28 00:00:00Z'"
test_assert $CRM_EX_OK 0
desc="2009-01-31 + 2 Months"
cmd="iso8601 -d '2009-01-31 00:00:00Z' -D P2M -E '2009-03-31 00:00:00Z'"
test_assert $CRM_EX_OK 0
desc="2009-01-31 + 3 Months"
cmd="iso8601 -d '2009-01-31 00:00:00Z' -D P3M -E '2009-04-30 00:00:00Z'"
test_assert $CRM_EX_OK 0
desc="2009-03-31 - 1 Month"
cmd="iso8601 -d '2009-03-31 01:00:00 +01:00' -D P-1M -E '2009-02-28 00:00:00Z'"
test_assert $CRM_EX_OK 0
desc="2038-01-01 + 3 Months"
cmd="iso8601 -d '2038-01-01 00:00:00Z' -D P3M -E '2038-04-01 00:00:00Z'"
test_assert $CRM_EX_OK 0
}
function test_acl_loop() {
local TMPXML
TMPXML="$1"
# Make sure we're rejecting things for the right reasons
export PCMK_trace_functions=pcmk__check_acl,pcmk__apply_creation_acl
export PCMK_stderr=1
CIB_user=root cibadmin --replace --xml-text ''
### no ACL ###
export CIB_user=unknownguy
desc="$CIB_user: Query configuration"
cmd="cibadmin -Q"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Set enable-acl"
cmd="crm_attribute -n enable-acl -v false"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Set stonith-enabled"
cmd="crm_attribute -n stonith-enabled -v false"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Create a resource"
cmd="cibadmin -C -o resources --xml-text ''"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
### deny /cib permission ###
export CIB_user=l33t-haxor
desc="$CIB_user: Query configuration"
cmd="cibadmin -Q"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Set enable-acl"
cmd="crm_attribute -n enable-acl -v false"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Set stonith-enabled"
cmd="crm_attribute -n stonith-enabled -v false"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Create a resource"
cmd="cibadmin -C -o resources --xml-text ''"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
### observer role ###
export CIB_user=niceguy
desc="$CIB_user: Query configuration"
cmd="cibadmin -Q"
test_assert $CRM_EX_OK 0
desc="$CIB_user: Set enable-acl"
cmd="crm_attribute -n enable-acl -v false"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Set stonith-enabled"
cmd="crm_attribute -n stonith-enabled -v false"
test_assert $CRM_EX_OK
desc="$CIB_user: Create a resource"
cmd="cibadmin -C -o resources --xml-text ''"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
export CIB_user=root
desc="$CIB_user: Query configuration"
cmd="cibadmin -Q"
test_assert $CRM_EX_OK 0
desc="$CIB_user: Set stonith-enabled"
cmd="crm_attribute -n stonith-enabled -v true"
test_assert $CRM_EX_OK
desc="$CIB_user: Create a resource"
cmd="cibadmin -C -o resources --xml-text ''"
test_assert $CRM_EX_OK
### deny /cib permission ###
export CIB_user=l33t-haxor
desc="$CIB_user: Create a resource meta attribute"
cmd="crm_resource -r dummy --meta -p target-role -v Stopped"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Query a resource meta attribute"
cmd="crm_resource -r dummy --meta -g target-role"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Remove a resource meta attribute"
cmd="crm_resource -r dummy --meta -d target-role"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
### observer role ###
export CIB_user=niceguy
desc="$CIB_user: Create a resource meta attribute"
cmd="crm_resource -r dummy --meta -p target-role -v Stopped"
test_assert $CRM_EX_OK
desc="$CIB_user: Query a resource meta attribute"
cmd="crm_resource -r dummy --meta -g target-role"
test_assert $CRM_EX_OK
desc="$CIB_user: Remove a resource meta attribute"
cmd="crm_resource -r dummy --meta -d target-role"
test_assert $CRM_EX_OK
desc="$CIB_user: Create a resource meta attribute"
cmd="crm_resource -r dummy --meta -p target-role -v Started"
test_assert $CRM_EX_OK
### read //meta_attributes ###
export CIB_user=badidea
desc="$CIB_user: Query configuration - implied deny"
cmd="cibadmin -Q"
test_assert $CRM_EX_OK 0
### deny /cib, read //meta_attributes ###
export CIB_user=betteridea
desc="$CIB_user: Query configuration - explicit deny"
cmd="cibadmin -Q"
test_assert $CRM_EX_OK 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --delete --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
### observer role ###
export CIB_user=niceguy
desc="$CIB_user: Replace - remove acls"
cmd="cibadmin --replace --xml-file $TMPXML"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -C -o resources --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - create resource"
cmd="cibadmin --replace --xml-file $TMPXML"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" crm_attribute -n enable-acl -v false
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - modify attribute (deny)"
cmd="cibadmin --replace --xml-file $TMPXML"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - delete attribute (deny)"
cmd="cibadmin --replace --xml-file $TMPXML"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - create attribute (deny)"
cmd="cibadmin --replace --xml-file $TMPXML"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
### admin role ###
CIB_user=bob
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - create attribute (direct allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - modify attribute (direct allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace -o resources --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - delete attribute (direct allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
### super_user role ###
export CIB_user=joe
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - create attribute (inherited allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - modify attribute (inherited allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace -o resources --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - delete attribute (inherited allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
### rsc_writer role ###
export CIB_user=mike
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - create attribute (allow overrides deny)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - modify attribute (allow overrides deny)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace -o resources --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - delete attribute (allow overrides deny)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
### rsc_denied role ###
export CIB_user=chris
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - create attribute (deny overrides allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
# Set as root since setting as chris failed
CIB_user=root cibadmin --modify --xml-text ''
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - modify attribute (deny overrides allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
# Set as root since setting as chris failed
CIB_user=root cibadmin --modify --xml-text ''
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace -o resources --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - delete attribute (deny overrides allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
}
function test_acls() {
local SHADOWPATH
local TMPXML
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.acls.xml.XXXXXXXXXX)
create_shadow_cib pacemaker-1.3
cat < "$TMPXML"
EOF
desc="Configure some ACLs"
cmd="cibadmin -M -o acls --xml-file $TMPXML"
test_assert $CRM_EX_OK
desc="Enable ACLs"
cmd="crm_attribute -n enable-acl -v true"
test_assert $CRM_EX_OK
desc="Set cluster option"
cmd="crm_attribute -n no-quorum-policy -v ignore"
test_assert $CRM_EX_OK
desc="New ACL"
cmd="cibadmin --create -o acls --xml-text ''"
test_assert $CRM_EX_OK
desc="Another ACL"
cmd="cibadmin --create -o acls --xml-text ''"
test_assert $CRM_EX_OK
desc="Updated ACL"
cmd="cibadmin --replace -o acls --xml-text ''"
test_assert $CRM_EX_OK
test_acl_loop "$TMPXML"
printf "\n\n !#!#!#!#! Upgrading to latest CIB schema and re-testing !#!#!#!#!\n"
printf "\nUpgrading to latest CIB schema and re-testing\n" 1>&2
export CIB_user=root
desc="$CIB_user: Upgrade to latest CIB schema"
cmd="cibadmin --upgrade --force -V"
test_assert $CRM_EX_OK
reset_shadow_cib_version
test_acl_loop "$TMPXML"
unset CIB_shadow_dir
rm -f "$TMPXML"
}
function test_validity() {
local TMPGOOD
local TMPBAD
TMPGOOD=$(mktemp ${TMPDIR:-/tmp}/cts-cli.validity.good.xml.XXXXXXXXXX)
TMPBAD=$(mktemp ${TMPDIR:-/tmp}/cts-cli.validity.bad.xml.XXXXXXXXXX)
create_shadow_cib pacemaker-1.2
export PCMK_trace_functions=apply_upgrade,update_validation,cli_config_update
export PCMK_stderr=1
cibadmin -C -o resources --xml-text ''
cibadmin -C -o resources --xml-text ''
cibadmin -C -o constraints --xml-text ''
cibadmin -Q > "$TMPGOOD"
desc="Try to make resulting CIB invalid (enum violation)"
cmd="cibadmin -M -o constraints --xml-text ''"
test_assert $CRM_EX_CONFIG
sed 's|"start"|"break"|' "$TMPGOOD" > "$TMPBAD"
desc="Run crm_simulate with invalid CIB (enum violation)"
cmd="crm_simulate -x $TMPBAD -S"
test_assert $CRM_EX_CONFIG 0
desc="Try to make resulting CIB invalid (unrecognized validate-with)"
cmd="cibadmin -M --xml-text ''"
test_assert $CRM_EX_CONFIG
sed 's|"pacemaker-1.2"|"pacemaker-9999.0"|' "$TMPGOOD" > "$TMPBAD"
desc="Run crm_simulate with invalid CIB (unrecognized validate-with)"
cmd="crm_simulate -x $TMPBAD -S"
test_assert $CRM_EX_CONFIG 0
desc="Try to make resulting CIB invalid, but possibly recoverable (valid with X.Y+1)"
cmd="cibadmin -C -o configuration --xml-text ''"
test_assert $CRM_EX_CONFIG
sed 's|||' "$TMPGOOD" > "$TMPBAD"
desc="Run crm_simulate with invalid, but possibly recoverable CIB (valid with X.Y+1)"
cmd="crm_simulate -x $TMPBAD -S"
test_assert $CRM_EX_OK 0
sed 's|[ ][ ]*validate-with="[^"]*"||' "$TMPGOOD" > "$TMPBAD"
desc="Make resulting CIB valid, although without validate-with attribute"
cmd="cibadmin -R --xml-file $TMPBAD"
test_assert $CRM_EX_OK
desc="Run crm_simulate with valid CIB, but without validate-with attribute"
cmd="crm_simulate -x $TMPBAD -S"
test_assert $CRM_EX_OK 0
# this will just disable validation and accept the config, outputting
# validation errors
sed -e 's|[ ][ ]*validate-with="[^"]*"||' \
-e 's|\([ ][ ]*epoch="[^"]*\)"|\10"|' -e 's|"start"|"break"|' \
"$TMPGOOD" > "$TMPBAD"
desc="Make resulting CIB invalid, and without validate-with attribute"
cmd="cibadmin -R --xml-file $TMPBAD"
test_assert $CRM_EX_OK
desc="Run crm_simulate with invalid CIB, also without validate-with attribute"
cmd="crm_simulate -x $TMPBAD -S"
test_assert $CRM_EX_OK 0
unset CIB_shadow_dir
rm -f "$TMPGOOD" "$TMPBAD"
}
test_upgrade() {
local TMPXML
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
create_shadow_cib pacemaker-2.10
desc="Set stonith-enabled=false"
cmd="crm_attribute -n stonith-enabled -v false"
test_assert $CRM_EX_OK
cat < "$TMPXML"
EOF
desc="Configure the initial resource"
cmd="cibadmin -M -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK
desc="Upgrade to latest CIB schema (trigger 2.10.xsl + the wrapping)"
cmd="cibadmin --upgrade --force -V -V"
test_assert $CRM_EX_OK
desc="Query a resource instance attribute (shall survive)"
cmd="crm_resource -r mySmartFuse -g requires"
test_assert $CRM_EX_OK
unset CIB_shadow_dir
rm -f "$TMPXML"
}
test_rules() {
local TMPXML
create_shadow_cib
cibadmin -C -o crm_config --xml-text ''
cibadmin -C -o resources --xml-text ''
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
cat < "$TMPXML"
EOF
cibadmin -C -o constraints -x "$TMPXML"
rm -f "$TMPXML"
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
cat < "$TMPXML"
EOF
cibadmin -C -o constraints -x "$TMPXML"
rm -f "$TMPXML"
if [ "$(uname)" == "FreeBSD" ]; then
tomorrow=$(date -v+1d +"%F %T %z")
else
tomorrow=$(date --date=tomorrow +"%F %T %z")
fi
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
cat < "$TMPXML"
EOF
cibadmin -C -o constraints -x "$TMPXML"
rm -f "$TMPXML"
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
cat < "$TMPXML"
EOF
cibadmin -C -o constraints -x "$TMPXML"
rm -f "$TMPXML"
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
cat < "$TMPXML"
EOF
cibadmin -C -o constraints -x "$TMPXML"
rm -f "$TMPXML"
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
cat < "$TMPXML"
EOF
cibadmin -C -o constraints -x "$TMPXML"
rm -f "$TMPXML"
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
cat < "$TMPXML"
EOF
cibadmin -C -o constraints -x "$TMPXML"
rm -f "$TMPXML"
desc="crm_rule given no arguments"
cmd="crm_rule"
test_assert $CRM_EX_USAGE 0
+ desc="crm_rule given no arguments (XML)"
+ cmd="crm_rule --output-as=xml"
+ test_assert_validate $CRM_EX_USAGE 0
+
desc="crm_rule given no rule to check"
cmd="crm_rule -c"
test_assert $CRM_EX_USAGE 0
+ desc="crm_rule given no rule to check (XML)"
+ cmd="crm_rule -c --output-as=xml"
+ test_assert_validate $CRM_EX_USAGE 0
+
desc="crm_rule given invalid input XML"
cmd="crm_rule -c -r blahblah -X 'invalidxml'"
test_assert $CRM_EX_DATAERR 0
+ desc="crm_rule given invalid input XML (XML)"
+ cmd="crm_rule -c -r blahblah -X 'invalidxml' --output-as=xml"
+ test_assert_validate $CRM_EX_DATAERR 0
+
desc="crm_rule given invalid input XML on stdin"
cmd="echo 'invalidxml' | crm_rule -c -r blahblah -X -"
test_assert $CRM_EX_DATAERR 0
+ desc="crm_rule given invalid input XML on stdin (XML)"
+ cmd="echo 'invalidxml' | crm_rule -c -r blahblah -X - --output-as=xml"
+ test_assert_validate $CRM_EX_DATAERR 0
+
desc="Try to check a rule that doesn't exist"
cmd="crm_rule -c -r blahblah"
test_assert $CRM_EX_NOSUCH
desc="Try to check a rule that doesn't exist, with XML output"
cmd="crm_rule -c -r blahblah --output-as=xml"
- test_assert $CRM_EX_NOSUCH 0
+ test_assert_validate $CRM_EX_NOSUCH 0
desc="Try to check a rule that has too many date_expressions"
cmd="crm_rule -c -r cli-rule-too-many-date-expressions"
test_assert $CRM_EX_UNIMPLEMENT_FEATURE 0
+ desc="Try to check a rule that has too many date_expressions (XML)"
+ cmd="crm_rule -c -r cli-rule-too-many-date-expressions --output-as=xml"
+ test_assert_validate $CRM_EX_UNIMPLEMENT_FEATURE 0
+
desc="Verify basic rule is expired"
cmd="crm_rule -c -r cli-prefer-rule-dummy-expired"
test_assert $CRM_EX_EXPIRED 0
desc="Verify basic rule is expired, with XML output"
cmd="crm_rule -c -r cli-prefer-rule-dummy-expired --output-as=xml"
- test_assert $CRM_EX_EXPIRED 0
+ test_assert_validate $CRM_EX_EXPIRED 0
desc="Verify basic rule worked in the past"
cmd="crm_rule -c -r cli-prefer-rule-dummy-expired -d 20180101"
test_assert $CRM_EX_OK 0
+ desc="Verify basic rule worked in the past (XML)"
+ cmd="crm_rule -c -r cli-prefer-rule-dummy-expired -d 20180101 --output-as=xml"
+ test_assert_validate $CRM_EX_OK 0
+
desc="Verify basic rule is not yet in effect"
cmd="crm_rule -c -r cli-prefer-rule-dummy-not-yet"
test_assert $CRM_EX_NOT_YET_IN_EFFECT 0
+ desc="Verify basic rule is not yet in effect (XML)"
+ cmd="crm_rule -c -r cli-prefer-rule-dummy-not-yet --output-as=xml"
+ test_assert_validate $CRM_EX_NOT_YET_IN_EFFECT 0
+
desc="Verify date_spec rule with years has expired"
cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-only-years"
test_assert $CRM_EX_EXPIRED 0
+ desc="Verify date_spec rule with years has expired (XML)"
+ cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-only-years --output-as=xml"
+ test_assert_validate $CRM_EX_EXPIRED 0
+
desc="Verify multiple rules at once"
cmd="crm_rule -c -r cli-prefer-rule-dummy-not-yet -r cli-prefer-rule-dummy-date_spec-only-years"
test_assert $CRM_EX_EXPIRED 0
desc="Verify multiple rules at once, with XML output"
cmd="crm_rule -c -r cli-prefer-rule-dummy-not-yet -r cli-prefer-rule-dummy-date_spec-only-years --output-as=xml"
- test_assert $CRM_EX_EXPIRED 0
+ test_assert_validate $CRM_EX_EXPIRED 0
desc="Verify date_spec rule with years is in effect"
cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-only-years -d 20190201"
test_assert $CRM_EX_OK 0
+ desc="Verify date_spec rule with years is in effect (XML)"
+ cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-only-years -d 20190201 --output-as=xml"
+ test_assert_validate $CRM_EX_OK 0
+
desc="Try to check a rule whose date_spec does not contain years="
cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-without-years"
- test_assert $CRM_EX_NOSUCH 0
+ test_assert $CRM_EX_UNIMPLEMENT_FEATURE 0
+
+ desc="Try to check a rule whose date_spec does not contain years= (XML)"
+ cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-without-years --output-as=xml"
+ test_assert_validate $CRM_EX_UNIMPLEMENT_FEATURE 0
desc="Try to check a rule whose date_spec contains years= and moon="
cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-years-moon"
- test_assert $CRM_EX_NOSUCH 0
+ test_assert $CRM_EX_UNIMPLEMENT_FEATURE 0
+
+ desc="Try to check a rule whose date_spec contains years= and moon= (XML)"
+ cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-years-moon --output-as=xml"
+ test_assert_validate $CRM_EX_UNIMPLEMENT_FEATURE 0
desc="Try to check a rule with no date_expression"
cmd="crm_rule -c -r cli-no-date_expression-rule"
test_assert $CRM_EX_UNIMPLEMENT_FEATURE 0
+ desc="Try to check a rule with no date_expression (XML)"
+ cmd="crm_rule -c -r cli-no-date_expression-rule --output-as=xml"
+ test_assert_validate $CRM_EX_UNIMPLEMENT_FEATURE 0
+
unset CIB_shadow_dir
}
# Ensure all command output is in portable locale for comparison
export LC_ALL="C"
test_access_render() {
local TMPXML
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.access_render.xml.XXXXXXXXXX)
export CIB_shadow_dir="${shadow_dir}"
$VALGRIND_CMD crm_shadow --batch --force --create-empty $shadow 2>&1
export CIB_shadow=$shadow
# Create a test CIB that has ACL roles
cat < "$TMPXML"
EOF
desc="Configure some ACLs"
cmd="cibadmin -M -o acls --xml-file $TMPXML"
test_assert $CRM_EX_OK
desc="Enable ACLs"
cmd="crm_attribute -n enable-acl -v true"
test_assert $CRM_EX_OK
unset CIB_user
# Run cibadmin --show-access on the test CIB with different users (tony here)
desc="An instance of ACLs render (into color)"
cmd="cibadmin --force --show-access=color -Q --user tony"
test_assert $CRM_EX_OK 0
desc="An instance of ACLs render (into namespacing)"
cmd="cibadmin --force --show-access=namespace -Q --user tony"
test_assert $CRM_EX_OK 0
desc="An instance of ACLs render (into text)"
cmd="cibadmin --force --show-access=text -Q --user tony"
test_assert $CRM_EX_OK 0
unset CIB_shadow_dir
rm -f "$TMPXML"
}
function test_feature_set() {
create_shadow_cib
# Import the initial test CIB with non-mixed versions
desc="Import the test CIB"
cmd="cibadmin --replace --xml-file $test_home/cli/crm_mon-feature_set.xml"
test_assert $CRM_EX_OK
desc="Complete text output, no mixed status"
cmd="crm_mon -1 --show-detail"
test_assert $CRM_EX_OK 0
desc="XML output, no mixed status"
cmd="crm_mon --output-as=xml"
test_assert $CRM_EX_OK 0
# Modify the CIB to fake that the cluster has mixed versions
desc="Fake inconsistent feature set"
cmd="crm_attribute --node=cluster02 --name=#feature-set --update=3.15.0 --lifetime=reboot"
test_assert $CRM_EX_OK
desc="Complete text output, mixed status"
cmd="crm_mon -1 --show-detail"
test_assert $CRM_EX_OK 0
desc="XML output, mixed status"
cmd="crm_mon --output-as=xml"
test_assert $CRM_EX_OK 0
unset CIB_shadow_dir
}
# Process command-line arguments
while [ $# -gt 0 ]; do
case "$1" in
-t)
tests="$2"
shift 2
;;
-V|--verbose)
verbose=1
shift
;;
-v|--valgrind)
export G_SLICE=always-malloc
VALGRIND_CMD="valgrind $VALGRIND_OPTS"
shift
;;
-s)
do_save=1
shift
;;
-p)
export PATH="$2:$PATH"
shift
;;
--help)
echo "$USAGE_TEXT"
exit $CRM_EX_OK
;;
*)
echo "error: unknown option $1"
echo
echo "$USAGE_TEXT"
exit $CRM_EX_USAGE
;;
esac
done
for t in $tests; do
case "$t" in
dates) ;;
tools) ;;
acls) ;;
validity) ;;
upgrade) ;;
rules) ;;
crm_mon) ;;
feature_set) ;;
*)
echo "error: unknown test $t"
echo
echo "$USAGE_TEXT"
exit $CRM_EX_USAGE
;;
esac
done
XMLLINT_CMD=$(which xmllint 2>/dev/null)
if [ $? -ne 0 ]; then
XMLLINT_CMD=""
echo "xmllint is missing - install it to validate command output"
fi
# Check whether we're running from source directory
SRCDIR=$(dirname $test_home)
if [ -x "$SRCDIR/tools/crm_simulate" ]; then
export PATH="$SRCDIR/tools:$PATH"
echo "Using local binaries from: $SRCDIR/tools"
if [ -x "$SRCDIR/xml" ]; then
export PCMK_schema_directory="$SRCDIR/xml"
echo "Using local schemas from: $PCMK_schema_directory"
fi
else
export PCMK_schema_directory=@CRM_SCHEMA_DIRECTORY@
fi
for t in $tests; do
echo "Testing $t"
TMPFILE=$(mktemp ${TMPDIR:-/tmp}/cts-cli.$t.XXXXXXXXXX)
eval TMPFILE_$t="$TMPFILE"
test_$t > "$TMPFILE"
# last-rc-change= is always numeric in the CIB. However, for the crm_mon
# test we also need to compare against the XML output of the crm_mon
# program. There, these are shown as human readable strings (like the
# output of the `date` command).
sed -e 's/cib-last-written.*>/>/'\
-e 's/Last updated: .*/Last updated:/' \
-e 's/Last change: .*/Last change:/' \
-e 's/(version .*)/(version)/' \
-e 's/last_update time=\".*\"/last_update time=\"\"/' \
-e 's/last_change time=\".*\"/last_change time=\"\"/' \
-e 's/ api-version=\".*\" / api-version=\"X\" /' \
-e 's/ version="[^"]*" / version="" /' \
-e 's/request=\".*\(crm_[a-zA-Z0-9]*\)/request=\"\1/' \
-e 's/crm_feature_set="[^"]*" //'\
-e 's/validate-with="[^"]*" //'\
-e 's/Created new pacemaker-.* configuration/Created new pacemaker configuration/'\
-e 's/.*\(pcmk__.*\)@.*\.c:[0-9][0-9]*)/\1/g' \
-e 's/.*\(unpack_.*\)@.*\.c:[0-9][0-9]*)/\1/g' \
-e 's/.*\(update_validation\)@.*\.c:[0-9][0-9]*)/\1/g' \
-e 's/.*\(apply_upgrade\)@.*\.c:[0-9][0-9]*)/\1/g' \
-e "s/ last-rc-change=['\"][-+A-Za-z0-9: ]*['\"],\{0,1\}//" \
-e 's|^/tmp/cts-cli\.validity\.bad.xml\.[^:]*:|validity.bad.xml:|'\
-e 's/^Entity: line [0-9][0-9]*: //'\
-e 's/\(validation ([0-9][0-9]* of \)[0-9][0-9]*\().*\)/\1X\2/' \
-e 's/^Migration will take effect until: .*/Migration will take effect until:/' \
-e 's/ end=\"[0-9][-+: 0-9]*Z*\"/ end=\"\"/' \
-e 's/ start=\"[0-9][-+: 0-9]*Z*\"/ start=\"\"/' \
-e 's/^Error checking rule: Device not configured/Error checking rule: No such device or address/' \
-e 's/Error performing operation: Device not configured/Error performing operation: No such device or address/' \
-e 's/\(Injecting attribute last-failure-ping#monitor_10000=\)[0-9]*/\1/' \
-e 's/^lt-//' \
-e 's/ocf::/ocf:/' \
-e 's/Masters:/Promoted:/' \
-e 's/Slaves:/Unpromoted:/' \
-e 's/Master/Promoted/' \
-e 's/Slave/Unpromoted/' \
-e 's/\x1b/\\x1b/' \
"$TMPFILE" > "${TMPFILE}.$$"
mv -- "${TMPFILE}.$$" "$TMPFILE"
if [ $do_save -eq 1 ]; then
cp "$TMPFILE" $test_home/cli/regression.$t.exp
fi
done
rm -rf "${shadow_dir}"
failed=0
if [ $verbose -eq 1 ]; then
echo -e "\n\nResults"
fi
for t in $tests; do
eval TMPFILE="\$TMPFILE_$t"
if [ $verbose -eq 1 ]; then
diff -wu $test_home/cli/regression.$t.exp "$TMPFILE"
else
diff -w $test_home/cli/regression.$t.exp "$TMPFILE" >/dev/null 2>&1
fi
if [ $? -ne 0 ]; then
failed=1
fi
done
echo -e "\n\nSummary"
for t in $tests; do
eval TMPFILE="\$TMPFILE_$t"
grep -e '^\* \(Passed\|Failed\)' "$TMPFILE"
done
function print_or_remove_file() {
eval TMPFILE="\$TMPFILE_$1"
if [[ ! $(diff -wq $test_home/cli/regression.$1.exp "$TMPFILE") ]]; then
rm -f "$TMPFILE"
else
echo " $TMPFILE"
fi
}
if [ $num_errors -ne 0 ] && [ $failed -ne 0 ]; then
echo "$num_errors tests failed; see output in:"
for t in $tests; do
print_or_remove_file "$t"
done
exit $CRM_EX_ERROR
elif [ $num_errors -ne 0 ]; then
echo "$num_errors tests failed"
for t in $tests; do
print_or_remove_file "$t"
done
exit $CRM_EX_ERROR
elif [ $failed -eq 1 ]; then
echo "$num_passed tests passed but output was unexpected; see output in:"
for t in $tests; do
print_or_remove_file "$t"
done
exit $CRM_EX_DIGEST
else
echo $num_passed tests passed
for t in $tests; do
eval TMPFILE="\$TMPFILE_$t"
rm -f "$TMPFILE"
done
crm_shadow --force --delete $shadow >/dev/null 2>&1
exit $CRM_EX_OK
fi
diff --git a/include/crm/common/results.h b/include/crm/common/results.h
index d2754d0a31..a1d3ef2d0e 100644
--- a/include/crm/common/results.h
+++ b/include/crm/common/results.h
@@ -1,366 +1,367 @@
/*
* Copyright 2012-2022 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/
#ifndef PCMK__CRM_COMMON_RESULTS__H
# define PCMK__CRM_COMMON_RESULTS__H
#ifdef __cplusplus
extern "C" {
#endif
/*!
* \file
* \brief Function and executable result codes
* \ingroup core
*/
// Lifted from config.h
/* The _Noreturn keyword of C11. */
#ifndef _Noreturn
# if (defined __cplusplus \
&& ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
|| (defined _MSC_VER && 1900 <= _MSC_VER)))
# define _Noreturn [[noreturn]]
# elif ((!defined __cplusplus || defined __clang__) \
&& (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
|| 4 < __GNUC__ + (7 <= __GNUC_MINOR__)))
/* _Noreturn works as-is. */
# elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C
# define _Noreturn __attribute__ ((__noreturn__))
# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
# define _Noreturn __declspec (noreturn)
# else
# define _Noreturn
# endif
#endif
# define CRM_ASSERT(expr) do { \
if (!(expr)) { \
crm_abort(__FILE__, __func__, __LINE__, #expr, TRUE, FALSE); \
abort(); /* crm_abort() doesn't always abort! */ \
} \
} while(0)
/*
* Function return codes
*
* Most Pacemaker API functions return an integer return code. There are two
* alternative interpretations. The legacy interpration is that the absolute
* value of the return code is either a system error number or a custom
* pcmk_err_* number. This is less than ideal because system error numbers are
* constrained only to the positive int range, so there's the possibility that
* system errors and custom errors could collide (which did in fact happen
* already on one architecture). The new intepretation is that negative values
* are from the pcmk_rc_e enum, and positive values are system error numbers.
* Both use 0 for success.
*
* For system error codes, see:
* - /usr/include/asm-generic/errno.h
* - /usr/include/asm-generic/errno-base.h
*/
// Legacy custom return codes for Pacemaker API functions (deprecated)
# define pcmk_ok 0
# define PCMK_ERROR_OFFSET 190 /* Replacements on non-linux systems, see include/portability.h */
# define PCMK_CUSTOM_OFFSET 200 /* Purely custom codes */
# define pcmk_err_generic 201
# define pcmk_err_no_quorum 202
# define pcmk_err_schema_validation 203
# define pcmk_err_transform_failed 204
# define pcmk_err_old_data 205
# define pcmk_err_diff_failed 206
# define pcmk_err_diff_resync 207
# define pcmk_err_cib_modified 208
# define pcmk_err_cib_backup 209
# define pcmk_err_cib_save 210
# define pcmk_err_schema_unchanged 211
# define pcmk_err_cib_corrupt 212
# define pcmk_err_multiple 213
# define pcmk_err_node_unknown 214
# define pcmk_err_already 215
/* On HPPA 215 is ENOSYM (Unknown error 215), which hopefully never happens. */
#ifdef __hppa__
# define pcmk_err_bad_nvpair 250 /* 216 is ENOTSOCK */
# define pcmk_err_unknown_format 252 /* 217 is EDESTADDRREQ */
#else
# define pcmk_err_bad_nvpair 216
# define pcmk_err_unknown_format 217
#endif
/*!
* \enum pcmk_rc_e
* \brief Return codes for Pacemaker API functions
*
* Any Pacemaker API function documented as returning a "standard Pacemaker
* return code" will return pcmk_rc_ok (0) on success, and one of this
* enumeration's other (negative) values or a (positive) system error number
* otherwise. The custom codes are at -1001 and lower, so that the caller may
* use -1 through -1000 for their own custom values if desired. While generally
* referred to as "errors", nonzero values simply indicate a result, which might
* or might not be an error depending on the calling context.
*/
enum pcmk_rc_e {
/* When adding new values, use consecutively lower numbers, update the array
* in lib/common/results.c, and test with crm_error.
*/
+ pcmk_rc_duplicate_id = -1033,
pcmk_rc_unpack_error = -1032,
pcmk_rc_invalid_transition = -1031,
pcmk_rc_graph_error = -1030,
pcmk_rc_dot_error = -1029,
pcmk_rc_underflow = -1028,
pcmk_rc_no_input = -1027,
pcmk_rc_no_output = -1026,
pcmk_rc_after_range = -1025,
pcmk_rc_within_range = -1024,
pcmk_rc_before_range = -1023,
pcmk_rc_undetermined = -1022,
pcmk_rc_op_unsatisfied = -1021,
pcmk_rc_ipc_pid_only = -1020,
pcmk_rc_ipc_unresponsive = -1019,
pcmk_rc_ipc_unauthorized = -1018,
pcmk_rc_no_quorum = -1017,
pcmk_rc_schema_validation = -1016,
pcmk_rc_schema_unchanged = -1015,
pcmk_rc_transform_failed = -1014,
pcmk_rc_old_data = -1013,
pcmk_rc_diff_failed = -1012,
pcmk_rc_diff_resync = -1011,
pcmk_rc_cib_modified = -1010,
pcmk_rc_cib_backup = -1009,
pcmk_rc_cib_save = -1008,
pcmk_rc_cib_corrupt = -1007,
pcmk_rc_multiple = -1006,
pcmk_rc_node_unknown = -1005,
pcmk_rc_already = -1004,
pcmk_rc_bad_nvpair = -1003,
pcmk_rc_unknown_format = -1002,
// Developers: Use a more specific code than pcmk_rc_error whenever possible
pcmk_rc_error = -1001,
// Values -1 through -1000 reserved for caller use
pcmk_rc_ok = 0
// Positive values reserved for system error numbers
};
/*!
* \enum ocf_exitcode
* \brief Exit status codes for resource agents
*
* The OCF Resource Agent API standard enumerates the possible exit status codes
* that agents should return. Besides being used with OCF agents, these values
* are also used by the executor as a universal status for all agent standards;
* actual results are mapped to these before returning them to clients.
*/
enum ocf_exitcode {
PCMK_OCF_OK = 0, //!< Success
PCMK_OCF_UNKNOWN_ERROR = 1, //!< Unspecified error
PCMK_OCF_INVALID_PARAM = 2, //!< Parameter invalid (in local context)
PCMK_OCF_UNIMPLEMENT_FEATURE = 3, //!< Requested action not implemented
PCMK_OCF_INSUFFICIENT_PRIV = 4, //!< Insufficient privileges
PCMK_OCF_NOT_INSTALLED = 5, //!< Dependencies not available locally
PCMK_OCF_NOT_CONFIGURED = 6, //!< Parameter invalid (inherently)
PCMK_OCF_NOT_RUNNING = 7, //!< Service safely stopped
PCMK_OCF_RUNNING_PROMOTED = 8, //!< Service active and promoted
PCMK_OCF_FAILED_PROMOTED = 9, //!< Service failed and possibly in promoted role
PCMK_OCF_DEGRADED = 190, //!< Service active but more likely to fail soon
PCMK_OCF_DEGRADED_PROMOTED = 191, //!< Service promoted but more likely to fail soon
/* These two are Pacemaker extensions, not in the OCF standard. The
* controller records PCMK_OCF_UNKNOWN for pending actions.
* PCMK_OCF_CONNECTION_DIED is used only with older DCs that don't support
* PCMK_EXEC_NOT_CONNECTED.
*/
PCMK_OCF_CONNECTION_DIED = 189, //!< \deprecated See PCMK_EXEC_NOT_CONNECTED
PCMK_OCF_UNKNOWN = 193, //!< Action is pending
#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
// Former Pacemaker extensions
PCMK_OCF_EXEC_ERROR = 192, //!< \deprecated (Unused)
PCMK_OCF_SIGNAL = 194, //!< \deprecated (Unused)
PCMK_OCF_NOT_SUPPORTED = 195, //!< \deprecated (Unused)
PCMK_OCF_PENDING = 196, //!< \deprecated (Unused)
PCMK_OCF_CANCELLED = 197, //!< \deprecated (Unused)
PCMK_OCF_TIMEOUT = 198, //!< \deprecated (Unused)
PCMK_OCF_OTHER_ERROR = 199, //!< \deprecated (Unused)
//! \deprecated Use PCMK_OCF_RUNNING_PROMOTED instead
PCMK_OCF_RUNNING_MASTER = PCMK_OCF_RUNNING_PROMOTED,
//! \deprecated Use PCMK_OCF_FAILED_PROMOTED instead
PCMK_OCF_FAILED_MASTER = PCMK_OCF_FAILED_PROMOTED,
//! \deprecated Use PCMK_OCF_DEGRADED_PROMOTED instead
PCMK_OCF_DEGRADED_MASTER = PCMK_OCF_DEGRADED_PROMOTED,
#endif
};
/*!
* \enum crm_exit_e
* \brief Exit status codes for tools and daemons
*
* We want well-specified (i.e. OS-invariant) exit status codes for our daemons
* and applications so they can be relied on by callers. (Function return codes
* and errno's do not make good exit statuses.)
*
* The only hard rule is that exit statuses must be between 0 and 255; all else
* is convention. Universally, 0 is success, and 1 is generic error (excluding
* OSes we don't support -- for example, OpenVMS considers 1 success!).
*
* For init scripts, the LSB gives meaning to 0-7, and sets aside 150-199 for
* application use. OCF adds 8-9 and 190-191.
*
* sysexits.h was an attempt to give additional meanings, but never really
* caught on. It uses 0 and 64-78.
*
* Bash reserves 2 ("incorrect builtin usage") and 126-255 (126 is "command
* found but not executable", 127 is "command not found", 128 + n is
* "interrupted by signal n").
*
* tldp.org recommends 64-113 for application use.
*
* We try to overlap with the above conventions when practical.
*/
typedef enum crm_exit_e {
// Common convention
CRM_EX_OK = 0, //!< Success
CRM_EX_ERROR = 1, //!< Unspecified error
// LSB + OCF
CRM_EX_INVALID_PARAM = 2, //!< Parameter invalid (in local context)
CRM_EX_UNIMPLEMENT_FEATURE = 3, //!< Requested action not implemented
CRM_EX_INSUFFICIENT_PRIV = 4, //!< Insufficient privileges
CRM_EX_NOT_INSTALLED = 5, //!< Dependencies not available locally
CRM_EX_NOT_CONFIGURED = 6, //!< Parameter invalid (inherently)
CRM_EX_NOT_RUNNING = 7, //!< Service safely stopped
CRM_EX_PROMOTED = 8, //!< Service active and promoted
CRM_EX_FAILED_PROMOTED = 9, //!< Service failed and possibly promoted
// sysexits.h
CRM_EX_USAGE = 64, //!< Command line usage error
CRM_EX_DATAERR = 65, //!< User-supplied data incorrect
CRM_EX_NOINPUT = 66, //!< Input file not available
CRM_EX_NOUSER = 67, //!< User does not exist
CRM_EX_NOHOST = 68, //!< Host unknown
CRM_EX_UNAVAILABLE = 69, //!< Needed service unavailable
CRM_EX_SOFTWARE = 70, //!< Internal software bug
CRM_EX_OSERR = 71, //!< External (OS/environmental) problem
CRM_EX_OSFILE = 72, //!< System file not usable
CRM_EX_CANTCREAT = 73, //!< File couldn't be created
CRM_EX_IOERR = 74, //!< File I/O error
CRM_EX_TEMPFAIL = 75, //!< Try again
CRM_EX_PROTOCOL = 76, //!< Protocol violated
CRM_EX_NOPERM = 77, //!< Non-file permission issue
CRM_EX_CONFIG = 78, //!< Misconfiguration
// Custom
CRM_EX_FATAL = 100, //!< Do not respawn
CRM_EX_PANIC = 101, //!< Panic the local host
CRM_EX_DISCONNECT = 102, //!< Lost connection to something
CRM_EX_OLD = 103, //!< Update older than existing config
CRM_EX_DIGEST = 104, //!< Digest comparison failed
CRM_EX_NOSUCH = 105, //!< Requested item does not exist
CRM_EX_QUORUM = 106, //!< Local partition does not have quorum
CRM_EX_UNSAFE = 107, //!< Requires --force or new conditions
CRM_EX_EXISTS = 108, //!< Requested item already exists
CRM_EX_MULTIPLE = 109, //!< Requested item has multiple matches
CRM_EX_EXPIRED = 110, //!< Requested item has expired
CRM_EX_NOT_YET_IN_EFFECT = 111, //!< Requested item is not in effect
CRM_EX_INDETERMINATE = 112, //!< Could not determine status
CRM_EX_UNSATISFIED = 113, //!< Requested item does not satisfy constraints
// Other
CRM_EX_TIMEOUT = 124, //!< Convention from timeout(1)
/* Anything above 128 overlaps with some shells' use of these values for
* "interrupted by signal N", and so may be unreliable when detected by
* shell scripts.
*/
// OCF Resource Agent API 1.1
CRM_EX_DEGRADED = 190, //!< Service active but more likely to fail soon
CRM_EX_DEGRADED_PROMOTED = 191, //!< Service promoted but more likely to fail soon
/* Custom
*
* This can be used to initialize exit status variables or to indicate that
* a command is pending (which is what the controller uses it for).
*/
CRM_EX_NONE = 193, //!< No exit status available
CRM_EX_MAX = 255, //!< Ensure crm_exit_t can hold this
} crm_exit_t;
/*!
* \enum pcmk_exec_status
* \brief Execution status
*
* These codes are used to specify the result of the attempt to execute an
* agent, rather than the agent's result itself.
*/
enum pcmk_exec_status {
PCMK_EXEC_UNKNOWN = -2, //!< Used only to initialize variables
PCMK_EXEC_PENDING = -1, //!< Action is in progress
PCMK_EXEC_DONE, //!< Action completed, result is known
PCMK_EXEC_CANCELLED, //!< Action was cancelled
PCMK_EXEC_TIMEOUT, //!< Action did not complete in time
PCMK_EXEC_NOT_SUPPORTED, //!< Agent does not implement requested action
PCMK_EXEC_ERROR, //!< Execution failed, may be retried
PCMK_EXEC_ERROR_HARD, //!< Execution failed, do not retry on node
PCMK_EXEC_ERROR_FATAL, //!< Execution failed, do not retry anywhere
PCMK_EXEC_NOT_INSTALLED, //!< Agent or dependency not available locally
PCMK_EXEC_NOT_CONNECTED, //!< No connection to executor
PCMK_EXEC_INVALID, //!< Action cannot be attempted (e.g. shutdown)
PCMK_EXEC_NO_FENCE_DEVICE, //!< No fence device is configured for target
PCMK_EXEC_NO_SECRETS, //!< Necessary CIB secrets are unavailable
// Add new values above here then update this one below
PCMK_EXEC_MAX = PCMK_EXEC_NO_SECRETS, //!< Maximum value for this enum
};
const char *pcmk_rc_name(int rc);
const char *pcmk_rc_str(int rc);
crm_exit_t pcmk_rc2exitc(int rc);
enum ocf_exitcode pcmk_rc2ocf(int rc);
int pcmk_rc2legacy(int rc);
int pcmk_legacy2rc(int legacy_rc);
const char *pcmk_strerror(int rc);
const char *pcmk_errorname(int rc);
const char *bz2_strerror(int rc);
const char *crm_exit_name(crm_exit_t exit_code);
const char *crm_exit_str(crm_exit_t exit_code);
_Noreturn crm_exit_t crm_exit(crm_exit_t rc);
static inline const char *
pcmk_exec_status_str(enum pcmk_exec_status status)
{
switch (status) {
case PCMK_EXEC_PENDING: return "pending";
case PCMK_EXEC_DONE: return "complete";
case PCMK_EXEC_CANCELLED: return "Cancelled";
case PCMK_EXEC_TIMEOUT: return "Timed Out";
case PCMK_EXEC_NOT_SUPPORTED: return "NOT SUPPORTED";
case PCMK_EXEC_ERROR: return "Error";
case PCMK_EXEC_ERROR_HARD: return "Hard error";
case PCMK_EXEC_ERROR_FATAL: return "Fatal error";
case PCMK_EXEC_NOT_INSTALLED: return "Not installed";
case PCMK_EXEC_NOT_CONNECTED: return "Internal communication failure";
case PCMK_EXEC_INVALID: return "Cannot execute now";
case PCMK_EXEC_NO_FENCE_DEVICE: return "No fence device";
case PCMK_EXEC_NO_SECRETS: return "CIB secrets unavailable";
default: return "UNKNOWN!";
}
}
#ifdef __cplusplus
}
#endif
#endif
diff --git a/include/pacemaker-internal.h b/include/pacemaker-internal.h
index 48f0162e1e..c2c603435f 100644
--- a/include/pacemaker-internal.h
+++ b/include/pacemaker-internal.h
@@ -1,25 +1,26 @@
/*
* Copyright 2019-2022 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/
#ifndef PACEMAKER_INTERNAL__H
# define PACEMAKER_INTERNAL__H
# include
# include
# include
# include
# include
+# include
# include
# include
# include
# include
# include
# include
#endif
diff --git a/include/pacemaker.h b/include/pacemaker.h
index 17c68e9099..627f281d7a 100644
--- a/include/pacemaker.h
+++ b/include/pacemaker.h
@@ -1,372 +1,406 @@
/*
* Copyright 2019-2022 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/
#ifndef PCMK__PACEMAKER__H
# define PCMK__PACEMAKER__H
# include
# include
# include
# include
# include
#ifdef __cplusplus
extern "C" {
#endif
/**
* \file
* \brief High Level API
* \ingroup pacemaker
*/
/*!
* \brief Modify operation of running a cluster simulation.
*/
enum pcmk_sim_flags {
pcmk_sim_none = 0,
pcmk_sim_all_actions = 1 << 0,
pcmk_sim_show_pending = 1 << 1,
pcmk_sim_process = 1 << 2,
pcmk_sim_show_scores = 1 << 3,
pcmk_sim_show_utilization = 1 << 4,
pcmk_sim_simulate = 1 << 5,
pcmk_sim_sanitized = 1 << 6,
pcmk_sim_verbose = 1 << 7,
};
/*!
* \brief Synthetic cluster events that can be injected into the cluster
* for running simulations.
*/
typedef struct {
/*! A list of node names (gchar *) to simulate bringing online */
GList *node_up;
/*! A list of node names (gchar *) to simulate bringing offline */
GList *node_down;
/*! A list of node names (gchar *) to simulate failing */
GList *node_fail;
/*! A list of operations (gchar *) to inject. The format of these strings
* is described in the "Operation Specification" section of crm_simulate
* help output.
*/
GList *op_inject;
/*! A list of operations (gchar *) that should return a given error code
* if they fail. The format of these strings is described in the
* "Operation Specification" section of crm_simulate help output.
*/
GList *op_fail;
/*! A list of tickets (gchar *) to simulate granting */
GList *ticket_grant;
/*! A list of tickets (gchar *) to simulate revoking */
GList *ticket_revoke;
/*! A list of tickets (gchar *) to simulate putting on standby */
GList *ticket_standby;
/*! A list of tickets (gchar *) to simulate activating */
GList *ticket_activate;
/*! Does the cluster have an active watchdog device? */
char *watchdog;
/*! Does the cluster have quorum? */
char *quorum;
} pcmk_injections_t;
/*!
* \brief Get controller status
*
* \param[in,out] xml The destination for the result, as an XML tree.
* \param[in] dest_node Destination node for request
* \param[in] message_timeout_ms Message timeout
*
* \return Standard Pacemaker return code
*/
int pcmk_controller_status(xmlNodePtr *xml, char *dest_node, unsigned int message_timeout_ms);
/*!
* \brief Get designated controller
*
* \param[in,out] xml The destination for the result, as an XML tree.
* \param[in] message_timeout_ms Message timeout
*
* \return Standard Pacemaker return code
*/
int pcmk_designated_controller(xmlNodePtr *xml, unsigned int message_timeout_ms);
/*!
* \brief Free a :pcmk_injections_t structure
*
* \param[in,out] injections The structure to be freed
*/
void pcmk_free_injections(pcmk_injections_t *injections);
/*!
* \brief Get pacemakerd status
*
* \param[in,out] xml The destination for the result, as an XML tree.
* \param[in] ipc_name IPC name for request
* \param[in] message_timeout_ms Message timeout
*
* \return Standard Pacemaker return code
*/
int pcmk_pacemakerd_status(xmlNodePtr *xml, char *ipc_name, unsigned int message_timeout_ms);
/*!
* \brief Calculate and output resource operation digests
*
* \param[out] xml Where to store XML with result
* \param[in] rsc Resource to calculate digests for
* \param[in] node Node whose operation history should be used
* \param[in] overrides Hash table of configuration parameters to override
* \param[in] data_set Cluster working set (with status)
*
* \return Standard Pacemaker return code
*/
int pcmk_resource_digests(xmlNodePtr *xml, pe_resource_t *rsc,
pe_node_t *node, GHashTable *overrides,
pe_working_set_t *data_set);
/**
* \brief Simulate a cluster's response to events.
*
* This high-level function essentially implements crm_simulate(8). It operates
* on an input CIB file and various lists of events that can be simulated. It
* optionally writes out a variety of artifacts to show the results of the
* simulation. Output can be modified with various flags.
*
* \param[in,out] xml The destination for the result, as an XML tree.
* \param[in,out] data_set Working set for the cluster.
* \param[in] events A structure containing cluster events
* (node up/down, tickets, injected operations)
* \param[in] flags A bitfield of :pcmk_sim_flags to modify
* operation of the simulation.
* \param[in] section_opts Which portions of the cluster status output
* should be displayed?
* \param[in] use_date The date to set the cluster's time to
* (may be NULL).
* \param[in] input_file The source CIB file, which may be overwritten by
* this function (may be NULL).
* \param[in] graph_file Where to write the XML-formatted transition graph
* (may be NULL, in which case no file will be
* written).
* \param[in] dot_file Where to write the dot(1) formatted transition
* graph (may be NULL, in which case no file will
* be written). See \p pcmk__write_sim_dotfile().
*
* \return Standard Pacemaker return code
*/
int pcmk_simulate(xmlNodePtr *xml, pe_working_set_t *data_set,
pcmk_injections_t *injections, unsigned int flags,
unsigned int section_opts, char *use_date, char *input_file,
char *graph_file, char *dot_file);
/*!
* \brief Get nodes list
*
* \param[in,out] xml The destination for the result, as an XML tree.
* \param[in] node_types Node type(s) to return (default: all)
*
* \return Standard Pacemaker return code
*/
int pcmk_list_nodes(xmlNodePtr *xml, char *node_types);
/*!
* \brief Output the current status of the cluster, formatted in the same way
* that `crm_mon --output-as=xml` would.
*
* \param[in,out] xml The destination for the result, as an XML tree.
*
* \return Standard Pacemaker return code
*/
int pcmk_status(xmlNodePtr *xml);
+/*!
+ * \brief Check whether each rule in a list is in effect
+ *
+ * \param[in,out] xml The destination for the result, as an XML tree
+ * \param[in] input The CIB XML to check (if \c NULL, use current CIB)
+ * \param[in] date Check whether the rule is in effect at this date and
+ * time (if \c NULL, use current date and time)
+ * \param[in] rule_ids The IDs of the rules to check, as a NULL-
+ * terminated list.
+ *
+ * \return Standard Pacemaker return code
+ */
+int pcmk_check_rules(xmlNodePtr *xml, xmlNodePtr input, const crm_time_t *date,
+ const char **rule_ids);
+
+/*!
+ * \brief Check whether a given rule is in effect
+ *
+ * \param[in,out] xml The destination for the result, as an XML tree
+ * \param[in] input The CIB XML to check (if \c NULL, use current CIB)
+ * \param[in] date Check whether the rule is in effect at this date and
+ * time (if \c NULL, use current date and time)
+ * \param[in] rule_ids The ID of the rule to check
+ *
+ * \return Standard Pacemaker return code
+ */
+static inline int
+pcmk_check_rule(xmlNodePtr *xml, xmlNodePtr input, const crm_time_t *date,
+ const char *rule_id)
+{
+ const char *rule_ids[] = {rule_id, NULL};
+ return pcmk_check_rules(xml, input, date, rule_ids);
+}
+
#ifdef BUILD_PUBLIC_LIBPACEMAKER
/*!
* \brief Ask the cluster to perform fencing
*
* \param[in] st A connection to the fencer API
* \param[in] target The node that should be fenced
* \param[in] action The fencing action (on, off, reboot) to perform
* \param[in] name Who requested the fence action?
* \param[in] timeout How long to wait for the operation to complete (in ms)
* \param[in] tolerance If a successful action for \p target happened within
* this many ms, return 0 without performing the action
* again
* \param[in] delay Apply this delay (in milliseconds) before initiating the
* fencing action (a value of -1 applies no delay and also
* disables any fencing delay from pcmk_delay_base and
* pcmk_delay_max)
* \param[out] reason If not NULL, where to put descriptive failure reason
*
* \return Standard Pacemaker return code
* \note If \p reason is not NULL, the caller is responsible for freeing its
* returned value.
*/
int pcmk_request_fencing(stonith_t *st, const char *target, const char *action,
const char *name, unsigned int timeout,
unsigned int tolerance, int delay, char **reason);
/*!
* \brief List the fencing operations that have occurred for a specific node.
*
* \note If \p xml is not NULL, it will be freed first and the previous
* contents lost.
*
* \param[in,out] xml The destination for the result, as an XML tree.
* \param[in] st A connection to the STONITH API.
* \param[in] target The node to get history for.
* \param[in] timeout How long to wait for the operation to complete (in ms).
* \param[in] quiet Suppress most output.
* \param[in] verbose Include additional output.
* \param[in] broadcast Gather fencing history from all nodes.
* \param[in] cleanup Clean up fencing history after listing.
*
* \return Standard Pacemaker return code
*/
int pcmk_fence_history(xmlNodePtr *xml, stonith_t *st, char *target,
unsigned int timeout, bool quiet, int verbose,
bool broadcast, bool cleanup);
/*!
* \brief List all installed STONITH agents.
*
* \note If \p xml is not NULL, it will be freed first and the previous
* contents lost.
*
* \param[in,out] xml The destination for the result, as an XML tree.
* \param[in] st A connection to the STONITH API.
* \param[in] timeout How long to wait for the operation to complete (in ms).
*
* \return Standard Pacemaker return code
*/
int pcmk_fence_installed(xmlNodePtr *xml, stonith_t *st, unsigned int timeout);
/*!
* \brief When was a device last fenced?
*
* \note If \p xml is not NULL, it will be freed first and the previous
* contents lost.
*
* \param[in,out] xml The destination for the result, as an XML tree.
* \param[in] target The node that was fenced.
* \param[in] as_nodeid
*
* \return Standard Pacemaker return code
*/
int pcmk_fence_last(xmlNodePtr *xml, const char *target, bool as_nodeid);
/*!
* \brief List nodes that can be fenced.
*
* \note If \p xml is not NULL, it will be freed first and the previous
* contents lost.
*
* \param[in,out] xml The destination for the result, as an XML tree
* \param[in] st A connection to the STONITH API
* \param[in] device_id Resource ID of fence device to check
* \param[in] timeout How long to wait for the operation to complete (in ms)
*
* \return Standard Pacemaker return code
*/
int pcmk_fence_list_targets(xmlNodePtr *xml, stonith_t *st,
const char *device_id, unsigned int timeout);
/*!
* \brief Get metadata for a resource.
*
* \note If \p xml is not NULL, it will be freed first and the previous
* contents lost.
*
* \param[in,out] xml The destination for the result, as an XML tree.
* \param[in] st A connection to the STONITH API.
* \param[in] agent The fence agent to get metadata for.
* \param[in] timeout How long to wait for the operation to complete (in ms).
*
* \return Standard Pacemaker return code
*/
int pcmk_fence_metadata(xmlNodePtr *xml, stonith_t *st, char *agent,
unsigned int timeout);
/*!
* \brief List registered fence devices.
*
* \note If \p xml is not NULL, it will be freed first and the previous
* contents lost.
*
* \param[in,out] xml The destination for the result, as an XML tree.
* \param[in] st A connection to the STONITH API.
* \param[in] target If not NULL, only return devices that can fence
* this node.
* \param[in] timeout How long to wait for the operation to complete (in ms).
*
* \return Standard Pacemaker return code
*/
int pcmk_fence_registered(xmlNodePtr *xml, stonith_t *st, char *target,
unsigned int timeout);
/*!
* \brief Register a fencing level for a specific node, node regex, or attribute.
*
* \p target can take three different forms:
* - name=value, in which case \p target is an attribute.
* - @pattern, in which case \p target is a node regex.
* - Otherwise, \p target is a node name.
*
* \param[in] st A connection to the STONITH API.
* \param[in] target The object to register a fencing level for.
* \param[in] fence_level Index number of level to add.
* \param[in] devices Devices to use in level.
*
* \return Standard Pacemaker return code
*/
int pcmk_fence_register_level(stonith_t *st, char *target, int fence_level,
stonith_key_value_t *devices);
/*!
* \brief Unregister a fencing level for a specific node, node regex, or attribute.
*
* \p target can take three different forms:
* - name=value, in which case \p target is an attribute.
* - @pattern, in which case \p target is a node regex.
* - Otherwise, \p target is a node name.
*
* \param[in] st A connection to the STONITH API.
* \param[in] target The object to unregister a fencing level for.
* \param[in] fence_level Index number of level to remove.
*
* \return Standard Pacemaker return code
*/
int pcmk_fence_unregister_level(stonith_t *st, char *target, int fence_level);
/*!
* \brief Validate a STONITH device configuration.
*
* \note If \p xml is not NULL, it will be freed first and the previous
* contents lost.
*
* \param[in,out] xml The destination for the result, as an XML tree.
* \param[in] st A connection to the STONITH API.
* \param[in] agent The agent to validate (for example, "fence_xvm").
* \param[in] id STONITH device ID (may be NULL).
* \param[in] params STONITH device configuration parameters.
* \param[in] timeout How long to wait for the operation to complete (in ms).
*
* \return Standard Pacemaker return code
*/
int pcmk_fence_validate(xmlNodePtr *xml, stonith_t *st, const char *agent,
const char *id, stonith_key_value_t *params,
unsigned int timeout);
#endif
#ifdef __cplusplus
}
#endif
#endif
diff --git a/include/pcmki/Makefile.am b/include/pcmki/Makefile.am
index e1db94198a..faa6c6fdc8 100644
--- a/include/pcmki/Makefile.am
+++ b/include/pcmki/Makefile.am
@@ -1,24 +1,25 @@
#
# Copyright 2019-2022 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# or later (GPLv2+) WITHOUT ANY WARRANTY.
#
MAINTAINERCLEANFILES = Makefile.in
noinst_HEADERS = pcmki_acl.h \
pcmki_cluster_queries.h \
pcmki_fence.h \
pcmki_output.h \
pcmki_resource.h \
+ pcmki_rule.h \
pcmki_sched_allocate.h \
pcmki_sched_utils.h \
pcmki_scheduler.h \
pcmki_simulate.h \
pcmki_status.h \
pcmki_transition.h
.PHONY: $(ARCHIVE_VERSION)
diff --git a/include/pcmki/pcmki_cluster_queries.h b/include/pcmki/pcmki_cluster_queries.h
index 0a4c21c816..a99766a1b3 100644
--- a/include/pcmki/pcmki_cluster_queries.h
+++ b/include/pcmki/pcmki_cluster_queries.h
@@ -1,16 +1,25 @@
+/*
+ * Copyright 2020-2022 the Pacemaker project contributors
+ *
+ * The version control history for this file may have further details.
+ *
+ * This source code is licensed under the GNU Lesser General Public License
+ * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
+ */
+
#ifndef PCMK__PCMKI_PCMKI_CLUSTER_QUERIES__H
# define PCMK__PCMKI_PCMKI_CLUSTER_QUERIES__H
#include // gboolean, GMainLoop, etc.
#include
#include
#include
#include
int pcmk__controller_status(pcmk__output_t *out, char *dest_node, guint message_timeout_ms);
int pcmk__designated_controller(pcmk__output_t *out, guint message_timeout_ms);
int pcmk__pacemakerd_status(pcmk__output_t *out, char *ipc_name, guint message_timeout_ms);
int pcmk__list_nodes(pcmk__output_t *out, char *node_types, gboolean BASH_EXPORT);
#endif
diff --git a/include/pcmki/pcmki_rule.h b/include/pcmki/pcmki_rule.h
new file mode 100644
index 0000000000..356278c466
--- /dev/null
+++ b/include/pcmki/pcmki_rule.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2022 the Pacemaker project contributors
+ *
+ * The version control history for this file may have further details.
+ *
+ * This source code is licensed under the GNU Lesser General Public License
+ * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
+ */
+
+#ifndef PCMK__PCMKI_PCMKI_RULE__H
+# define PCMK__PCMKI_PCMKI_RULE__H
+
+#include
+#include
+#include
+
+int pcmk__check_rules(pcmk__output_t *out, xmlNodePtr input,
+ const crm_time_t *date_time, const char **rule_ids);
+
+/*!
+ * \internal
+ * \brief Check whether a given rule is in effect
+ *
+ * \param[in,out] out Output object
+ * \param[in] input The CIB XML to check (if \c NULL, use current CIB)
+ * \param[in] date Check whether the rule is in effect at this date and
+ * time (if \c NULL, use current date and time)
+ * \param[in] rule_ids The ID of the rule to check
+ *
+ * \return Standard Pacemaker return code
+ */
+static inline int
+pcmk__check_rule(pcmk__output_t *out, xmlNodePtr input, const crm_time_t *date,
+ const char *rule_id)
+{
+ const char *rule_ids[] = {rule_id, NULL};
+ return pcmk__check_rules(out, input, date, rule_ids);
+}
+
+#endif // PCMK__PCMKI_PCMKI_RULE__H
diff --git a/lib/common/results.c b/lib/common/results.c
index 422ec9b901..6c38a59bfb 100644
--- a/lib/common/results.c
+++ b/lib/common/results.c
@@ -1,923 +1,930 @@
/*
* Copyright 2004-2022 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/
#include
#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
#include
#include
#include
#include
#include
#include
#include
G_DEFINE_QUARK(pcmk-rc-error-quark, pcmk__rc_error)
G_DEFINE_QUARK(pcmk-exitc-error-quark, pcmk__exitc_error)
// @COMPAT Legacy function return codes
//! \deprecated Use standard return codes and pcmk_rc_name() instead
const char *
pcmk_errorname(int rc)
{
rc = abs(rc);
switch (rc) {
case pcmk_err_generic: return "pcmk_err_generic";
case pcmk_err_no_quorum: return "pcmk_err_no_quorum";
case pcmk_err_schema_validation: return "pcmk_err_schema_validation";
case pcmk_err_transform_failed: return "pcmk_err_transform_failed";
case pcmk_err_old_data: return "pcmk_err_old_data";
case pcmk_err_diff_failed: return "pcmk_err_diff_failed";
case pcmk_err_diff_resync: return "pcmk_err_diff_resync";
case pcmk_err_cib_modified: return "pcmk_err_cib_modified";
case pcmk_err_cib_backup: return "pcmk_err_cib_backup";
case pcmk_err_cib_save: return "pcmk_err_cib_save";
case pcmk_err_cib_corrupt: return "pcmk_err_cib_corrupt";
case pcmk_err_multiple: return "pcmk_err_multiple";
case pcmk_err_node_unknown: return "pcmk_err_node_unknown";
case pcmk_err_already: return "pcmk_err_already";
case pcmk_err_bad_nvpair: return "pcmk_err_bad_nvpair";
case pcmk_err_unknown_format: return "pcmk_err_unknown_format";
default: return pcmk_rc_name(rc); // system errno
}
}
//! \deprecated Use standard return codes and pcmk_rc_str() instead
const char *
pcmk_strerror(int rc)
{
return pcmk_rc_str(pcmk_legacy2rc(rc));
}
// Standard Pacemaker API return codes
/* This array is used only for nonzero values of pcmk_rc_e. Its values must be
* kept in the exact reverse order of the enum value numbering (i.e. add new
* values to the end of the array).
*/
static struct pcmk__rc_info {
const char *name;
const char *desc;
int legacy_rc;
} pcmk__rcs[] = {
{ "pcmk_rc_error",
"Error",
-pcmk_err_generic,
},
{ "pcmk_rc_unknown_format",
"Unknown output format",
-pcmk_err_unknown_format,
},
{ "pcmk_rc_bad_nvpair",
"Bad name/value pair given",
-pcmk_err_bad_nvpair,
},
{ "pcmk_rc_already",
"Already in requested state",
-pcmk_err_already,
},
{ "pcmk_rc_node_unknown",
"Node not found",
-pcmk_err_node_unknown,
},
{ "pcmk_rc_multiple",
"Resource active on multiple nodes",
-pcmk_err_multiple,
},
{ "pcmk_rc_cib_corrupt",
"Could not parse on-disk configuration",
-pcmk_err_cib_corrupt,
},
{ "pcmk_rc_cib_save",
"Could not save new configuration to disk",
-pcmk_err_cib_save,
},
{ "pcmk_rc_cib_backup",
"Could not archive previous configuration",
-pcmk_err_cib_backup,
},
{ "pcmk_rc_cib_modified",
"On-disk configuration was manually modified",
-pcmk_err_cib_modified,
},
{ "pcmk_rc_diff_resync",
"Application of update diff failed, requesting full refresh",
-pcmk_err_diff_resync,
},
{ "pcmk_rc_diff_failed",
"Application of update diff failed",
-pcmk_err_diff_failed,
},
{ "pcmk_rc_old_data",
"Update was older than existing configuration",
-pcmk_err_old_data,
},
{ "pcmk_rc_transform_failed",
"Schema transform failed",
-pcmk_err_transform_failed,
},
{ "pcmk_rc_schema_unchanged",
"Schema is already the latest available",
-pcmk_err_schema_unchanged,
},
{ "pcmk_rc_schema_validation",
"Update does not conform to the configured schema",
-pcmk_err_schema_validation,
},
{ "pcmk_rc_no_quorum",
"Operation requires quorum",
-pcmk_err_no_quorum,
},
{ "pcmk_rc_ipc_unauthorized",
"IPC server is blocked by unauthorized process",
-pcmk_err_generic,
},
{ "pcmk_rc_ipc_unresponsive",
"IPC server is unresponsive",
-pcmk_err_generic,
},
{ "pcmk_rc_ipc_pid_only",
"IPC server process is active but not accepting connections",
-pcmk_err_generic,
},
{ "pcmk_rc_op_unsatisfied",
"Not applicable under current conditions",
-pcmk_err_generic,
},
{ "pcmk_rc_undetermined",
"Result undetermined",
-pcmk_err_generic,
},
{ "pcmk_rc_before_range",
"Result occurs before given range",
-pcmk_err_generic,
},
{ "pcmk_rc_within_range",
"Result occurs within given range",
-pcmk_err_generic,
},
{ "pcmk_rc_after_range",
"Result occurs after given range",
-pcmk_err_generic,
},
{ "pcmk_rc_no_output",
"Output message produced no output",
-pcmk_err_generic,
},
{ "pcmk_rc_no_input",
"Input file not available",
-pcmk_err_generic,
},
{ "pcmk_rc_underflow",
"Value too small to be stored in data type",
-pcmk_err_generic,
},
{ "pcmk_rc_dot_error",
"Error writing dot(1) file",
-pcmk_err_generic,
},
{ "pcmk_rc_graph_error",
"Error writing graph file",
-pcmk_err_generic,
},
{ "pcmk_rc_invalid_transition",
"Cluster simulation produced invalid transition",
-pcmk_err_generic,
},
{ "pcmk_rc_unpack_error",
"Unable to parse CIB XML",
-pcmk_err_generic,
},
+ { "pcmk_rc_duplicate_id",
+ "Two or more XML elements have the same ID",
+ -pcmk_err_generic,
+ },
};
#define PCMK__N_RC (sizeof(pcmk__rcs) / sizeof(struct pcmk__rc_info))
/*!
* \brief Get a return code constant name as a string
*
* \param[in] rc Integer return code to convert
*
* \return String of constant name corresponding to rc
*/
const char *
pcmk_rc_name(int rc)
{
if ((rc <= pcmk_rc_error) && ((pcmk_rc_error - rc) < PCMK__N_RC)) {
return pcmk__rcs[pcmk_rc_error - rc].name;
}
switch (rc) {
case pcmk_rc_ok: return "pcmk_rc_ok";
case E2BIG: return "E2BIG";
case EACCES: return "EACCES";
case EADDRINUSE: return "EADDRINUSE";
case EADDRNOTAVAIL: return "EADDRNOTAVAIL";
case EAFNOSUPPORT: return "EAFNOSUPPORT";
case EAGAIN: return "EAGAIN";
case EALREADY: return "EALREADY";
case EBADF: return "EBADF";
case EBADMSG: return "EBADMSG";
case EBUSY: return "EBUSY";
case ECANCELED: return "ECANCELED";
case ECHILD: return "ECHILD";
case ECOMM: return "ECOMM";
case ECONNABORTED: return "ECONNABORTED";
case ECONNREFUSED: return "ECONNREFUSED";
case ECONNRESET: return "ECONNRESET";
/* case EDEADLK: return "EDEADLK"; */
case EDESTADDRREQ: return "EDESTADDRREQ";
case EDOM: return "EDOM";
case EDQUOT: return "EDQUOT";
case EEXIST: return "EEXIST";
case EFAULT: return "EFAULT";
case EFBIG: return "EFBIG";
case EHOSTDOWN: return "EHOSTDOWN";
case EHOSTUNREACH: return "EHOSTUNREACH";
case EIDRM: return "EIDRM";
case EILSEQ: return "EILSEQ";
case EINPROGRESS: return "EINPROGRESS";
case EINTR: return "EINTR";
case EINVAL: return "EINVAL";
case EIO: return "EIO";
case EISCONN: return "EISCONN";
case EISDIR: return "EISDIR";
case ELIBACC: return "ELIBACC";
case ELOOP: return "ELOOP";
case EMFILE: return "EMFILE";
case EMLINK: return "EMLINK";
case EMSGSIZE: return "EMSGSIZE";
#ifdef EMULTIHOP // Not available on OpenBSD
case EMULTIHOP: return "EMULTIHOP";
#endif
case ENAMETOOLONG: return "ENAMETOOLONG";
case ENETDOWN: return "ENETDOWN";
case ENETRESET: return "ENETRESET";
case ENETUNREACH: return "ENETUNREACH";
case ENFILE: return "ENFILE";
case ENOBUFS: return "ENOBUFS";
case ENODATA: return "ENODATA";
case ENODEV: return "ENODEV";
case ENOENT: return "ENOENT";
case ENOEXEC: return "ENOEXEC";
case ENOKEY: return "ENOKEY";
case ENOLCK: return "ENOLCK";
#ifdef ENOLINK // Not available on OpenBSD
case ENOLINK: return "ENOLINK";
#endif
case ENOMEM: return "ENOMEM";
case ENOMSG: return "ENOMSG";
case ENOPROTOOPT: return "ENOPROTOOPT";
case ENOSPC: return "ENOSPC";
#ifdef ENOSR
case ENOSR: return "ENOSR";
#endif
#ifdef ENOSTR
case ENOSTR: return "ENOSTR";
#endif
case ENOSYS: return "ENOSYS";
case ENOTBLK: return "ENOTBLK";
case ENOTCONN: return "ENOTCONN";
case ENOTDIR: return "ENOTDIR";
case ENOTEMPTY: return "ENOTEMPTY";
case ENOTSOCK: return "ENOTSOCK";
#if ENOTSUP != EOPNOTSUPP
case ENOTSUP: return "ENOTSUP";
#endif
case ENOTTY: return "ENOTTY";
case ENOTUNIQ: return "ENOTUNIQ";
case ENXIO: return "ENXIO";
case EOPNOTSUPP: return "EOPNOTSUPP";
case EOVERFLOW: return "EOVERFLOW";
case EPERM: return "EPERM";
case EPFNOSUPPORT: return "EPFNOSUPPORT";
case EPIPE: return "EPIPE";
case EPROTO: return "EPROTO";
case EPROTONOSUPPORT: return "EPROTONOSUPPORT";
case EPROTOTYPE: return "EPROTOTYPE";
case ERANGE: return "ERANGE";
case EREMOTE: return "EREMOTE";
case EREMOTEIO: return "EREMOTEIO";
case EROFS: return "EROFS";
case ESHUTDOWN: return "ESHUTDOWN";
case ESPIPE: return "ESPIPE";
case ESOCKTNOSUPPORT: return "ESOCKTNOSUPPORT";
case ESRCH: return "ESRCH";
case ESTALE: return "ESTALE";
case ETIME: return "ETIME";
case ETIMEDOUT: return "ETIMEDOUT";
case ETXTBSY: return "ETXTBSY";
#ifdef EUNATCH
case EUNATCH: return "EUNATCH";
#endif
case EUSERS: return "EUSERS";
/* case EWOULDBLOCK: return "EWOULDBLOCK"; */
case EXDEV: return "EXDEV";
#ifdef EBADE // Not available on OS X
case EBADE: return "EBADE";
case EBADFD: return "EBADFD";
case EBADSLT: return "EBADSLT";
case EDEADLOCK: return "EDEADLOCK";
case EBADR: return "EBADR";
case EBADRQC: return "EBADRQC";
case ECHRNG: return "ECHRNG";
#ifdef EISNAM // Not available on OS X, Illumos, Solaris
case EISNAM: return "EISNAM";
case EKEYEXPIRED: return "EKEYEXPIRED";
case EKEYREVOKED: return "EKEYREVOKED";
#endif
case EKEYREJECTED: return "EKEYREJECTED";
case EL2HLT: return "EL2HLT";
case EL2NSYNC: return "EL2NSYNC";
case EL3HLT: return "EL3HLT";
case EL3RST: return "EL3RST";
case ELIBBAD: return "ELIBBAD";
case ELIBMAX: return "ELIBMAX";
case ELIBSCN: return "ELIBSCN";
case ELIBEXEC: return "ELIBEXEC";
#ifdef ENOMEDIUM // Not available on OS X, Illumos, Solaris
case ENOMEDIUM: return "ENOMEDIUM";
case EMEDIUMTYPE: return "EMEDIUMTYPE";
#endif
case ENONET: return "ENONET";
case ENOPKG: return "ENOPKG";
case EREMCHG: return "EREMCHG";
case ERESTART: return "ERESTART";
case ESTRPIPE: return "ESTRPIPE";
#ifdef EUCLEAN // Not available on OS X, Illumos, Solaris
case EUCLEAN: return "EUCLEAN";
#endif
case EXFULL: return "EXFULL";
#endif // EBADE
default: return "Unknown";
}
}
/*!
* \brief Get a user-friendly description of a return code
*
* \param[in] rc Integer return code to convert
*
* \return String description of rc
*/
const char *
pcmk_rc_str(int rc)
{
if (rc == pcmk_rc_ok) {
return "OK";
}
if ((rc <= pcmk_rc_error) && ((pcmk_rc_error - rc) < PCMK__N_RC)) {
return pcmk__rcs[pcmk_rc_error - rc].desc;
}
if (rc < 0) {
return "Error";
}
// Handle values that could be defined by system or by portability.h
switch (rc) {
#ifdef PCMK__ENOTUNIQ
case ENOTUNIQ: return "Name not unique on network";
#endif
#ifdef PCMK__ECOMM
case ECOMM: return "Communication error on send";
#endif
#ifdef PCMK__ELIBACC
case ELIBACC: return "Can not access a needed shared library";
#endif
#ifdef PCMK__EREMOTEIO
case EREMOTEIO: return "Remote I/O error";
#endif
#ifdef PCMK__ENOKEY
case ENOKEY: return "Required key not available";
#endif
#ifdef PCMK__ENODATA
case ENODATA: return "No data available";
#endif
#ifdef PCMK__ETIME
case ETIME: return "Timer expired";
#endif
#ifdef PCMK__EKEYREJECTED
case EKEYREJECTED: return "Key was rejected by service";
#endif
default: return strerror(rc);
}
}
// This returns negative values for errors
//! \deprecated Use standard return codes instead
int
pcmk_rc2legacy(int rc)
{
if (rc >= 0) {
return -rc; // OK or system errno
}
if ((rc <= pcmk_rc_error) && ((pcmk_rc_error - rc) < PCMK__N_RC)) {
return pcmk__rcs[pcmk_rc_error - rc].legacy_rc;
}
return -pcmk_err_generic;
}
//! \deprecated Use standard return codes instead
int
pcmk_legacy2rc(int legacy_rc)
{
legacy_rc = abs(legacy_rc);
switch (legacy_rc) {
case pcmk_err_no_quorum: return pcmk_rc_no_quorum;
case pcmk_err_schema_validation: return pcmk_rc_schema_validation;
case pcmk_err_schema_unchanged: return pcmk_rc_schema_unchanged;
case pcmk_err_transform_failed: return pcmk_rc_transform_failed;
case pcmk_err_old_data: return pcmk_rc_old_data;
case pcmk_err_diff_failed: return pcmk_rc_diff_failed;
case pcmk_err_diff_resync: return pcmk_rc_diff_resync;
case pcmk_err_cib_modified: return pcmk_rc_cib_modified;
case pcmk_err_cib_backup: return pcmk_rc_cib_backup;
case pcmk_err_cib_save: return pcmk_rc_cib_save;
case pcmk_err_cib_corrupt: return pcmk_rc_cib_corrupt;
case pcmk_err_multiple: return pcmk_rc_multiple;
case pcmk_err_node_unknown: return pcmk_rc_node_unknown;
case pcmk_err_already: return pcmk_rc_already;
case pcmk_err_bad_nvpair: return pcmk_rc_bad_nvpair;
case pcmk_err_unknown_format: return pcmk_rc_unknown_format;
case pcmk_err_generic: return pcmk_rc_error;
case pcmk_ok: return pcmk_rc_ok;
default: return legacy_rc; // system errno
}
}
// Exit status codes
const char *
crm_exit_name(crm_exit_t exit_code)
{
switch (exit_code) {
case CRM_EX_OK: return "CRM_EX_OK";
case CRM_EX_ERROR: return "CRM_EX_ERROR";
case CRM_EX_INVALID_PARAM: return "CRM_EX_INVALID_PARAM";
case CRM_EX_UNIMPLEMENT_FEATURE: return "CRM_EX_UNIMPLEMENT_FEATURE";
case CRM_EX_INSUFFICIENT_PRIV: return "CRM_EX_INSUFFICIENT_PRIV";
case CRM_EX_NOT_INSTALLED: return "CRM_EX_NOT_INSTALLED";
case CRM_EX_NOT_CONFIGURED: return "CRM_EX_NOT_CONFIGURED";
case CRM_EX_NOT_RUNNING: return "CRM_EX_NOT_RUNNING";
case CRM_EX_PROMOTED: return "CRM_EX_PROMOTED";
case CRM_EX_FAILED_PROMOTED: return "CRM_EX_FAILED_PROMOTED";
case CRM_EX_USAGE: return "CRM_EX_USAGE";
case CRM_EX_DATAERR: return "CRM_EX_DATAERR";
case CRM_EX_NOINPUT: return "CRM_EX_NOINPUT";
case CRM_EX_NOUSER: return "CRM_EX_NOUSER";
case CRM_EX_NOHOST: return "CRM_EX_NOHOST";
case CRM_EX_UNAVAILABLE: return "CRM_EX_UNAVAILABLE";
case CRM_EX_SOFTWARE: return "CRM_EX_SOFTWARE";
case CRM_EX_OSERR: return "CRM_EX_OSERR";
case CRM_EX_OSFILE: return "CRM_EX_OSFILE";
case CRM_EX_CANTCREAT: return "CRM_EX_CANTCREAT";
case CRM_EX_IOERR: return "CRM_EX_IOERR";
case CRM_EX_TEMPFAIL: return "CRM_EX_TEMPFAIL";
case CRM_EX_PROTOCOL: return "CRM_EX_PROTOCOL";
case CRM_EX_NOPERM: return "CRM_EX_NOPERM";
case CRM_EX_CONFIG: return "CRM_EX_CONFIG";
case CRM_EX_FATAL: return "CRM_EX_FATAL";
case CRM_EX_PANIC: return "CRM_EX_PANIC";
case CRM_EX_DISCONNECT: return "CRM_EX_DISCONNECT";
case CRM_EX_DIGEST: return "CRM_EX_DIGEST";
case CRM_EX_NOSUCH: return "CRM_EX_NOSUCH";
case CRM_EX_QUORUM: return "CRM_EX_QUORUM";
case CRM_EX_UNSAFE: return "CRM_EX_UNSAFE";
case CRM_EX_EXISTS: return "CRM_EX_EXISTS";
case CRM_EX_MULTIPLE: return "CRM_EX_MULTIPLE";
case CRM_EX_EXPIRED: return "CRM_EX_EXPIRED";
case CRM_EX_NOT_YET_IN_EFFECT: return "CRM_EX_NOT_YET_IN_EFFECT";
case CRM_EX_INDETERMINATE: return "CRM_EX_INDETERMINATE";
case CRM_EX_UNSATISFIED: return "CRM_EX_UNSATISFIED";
case CRM_EX_OLD: return "CRM_EX_OLD";
case CRM_EX_TIMEOUT: return "CRM_EX_TIMEOUT";
case CRM_EX_DEGRADED: return "CRM_EX_DEGRADED";
case CRM_EX_DEGRADED_PROMOTED: return "CRM_EX_DEGRADED_PROMOTED";
case CRM_EX_NONE: return "CRM_EX_NONE";
case CRM_EX_MAX: return "CRM_EX_UNKNOWN";
}
return "CRM_EX_UNKNOWN";
}
const char *
crm_exit_str(crm_exit_t exit_code)
{
switch (exit_code) {
case CRM_EX_OK: return "OK";
case CRM_EX_ERROR: return "Error occurred";
case CRM_EX_INVALID_PARAM: return "Invalid parameter";
case CRM_EX_UNIMPLEMENT_FEATURE: return "Unimplemented";
case CRM_EX_INSUFFICIENT_PRIV: return "Insufficient privileges";
case CRM_EX_NOT_INSTALLED: return "Not installed";
case CRM_EX_NOT_CONFIGURED: return "Not configured";
case CRM_EX_NOT_RUNNING: return "Not running";
case CRM_EX_PROMOTED: return "Promoted";
case CRM_EX_FAILED_PROMOTED: return "Failed in promoted role";
case CRM_EX_USAGE: return "Incorrect usage";
case CRM_EX_DATAERR: return "Invalid data given";
case CRM_EX_NOINPUT: return "Input file not available";
case CRM_EX_NOUSER: return "User does not exist";
case CRM_EX_NOHOST: return "Host does not exist";
case CRM_EX_UNAVAILABLE: return "Necessary service unavailable";
case CRM_EX_SOFTWARE: return "Internal software bug";
case CRM_EX_OSERR: return "Operating system error occurred";
case CRM_EX_OSFILE: return "System file not available";
case CRM_EX_CANTCREAT: return "Cannot create output file";
case CRM_EX_IOERR: return "I/O error occurred";
case CRM_EX_TEMPFAIL: return "Temporary failure, try again";
case CRM_EX_PROTOCOL: return "Protocol violated";
case CRM_EX_NOPERM: return "Insufficient privileges";
case CRM_EX_CONFIG: return "Invalid configuration";
case CRM_EX_FATAL: return "Fatal error occurred, will not respawn";
case CRM_EX_PANIC: return "System panic required";
case CRM_EX_DISCONNECT: return "Not connected";
case CRM_EX_DIGEST: return "Digest mismatch";
case CRM_EX_NOSUCH: return "No such object";
case CRM_EX_QUORUM: return "Quorum required";
case CRM_EX_UNSAFE: return "Operation not safe";
case CRM_EX_EXISTS: return "Requested item already exists";
case CRM_EX_MULTIPLE: return "Multiple items match request";
case CRM_EX_EXPIRED: return "Requested item has expired";
case CRM_EX_NOT_YET_IN_EFFECT: return "Requested item is not yet in effect";
case CRM_EX_INDETERMINATE: return "Could not determine status";
case CRM_EX_UNSATISFIED: return "Not applicable under current conditions";
case CRM_EX_OLD: return "Update was older than existing configuration";
case CRM_EX_TIMEOUT: return "Timeout occurred";
case CRM_EX_DEGRADED: return "Service is active but might fail soon";
case CRM_EX_DEGRADED_PROMOTED: return "Service is promoted but might fail soon";
case CRM_EX_NONE: return "No exit status available";
case CRM_EX_MAX: return "Error occurred";
}
if ((exit_code > 128) && (exit_code < CRM_EX_MAX)) {
return "Interrupted by signal";
}
return "Unknown exit status";
}
/*!
* \brief Map a function return code to the most similar exit code
*
* \param[in] rc Function return code
*
* \return Most similar exit code
*/
crm_exit_t
pcmk_rc2exitc(int rc)
{
switch (rc) {
case pcmk_rc_ok:
return CRM_EX_OK;
case pcmk_rc_no_quorum:
return CRM_EX_QUORUM;
case pcmk_rc_old_data:
return CRM_EX_OLD;
case pcmk_rc_schema_validation:
case pcmk_rc_transform_failed:
case pcmk_rc_unpack_error:
return CRM_EX_CONFIG;
case pcmk_rc_bad_nvpair:
return CRM_EX_INVALID_PARAM;
case EACCES:
return CRM_EX_INSUFFICIENT_PRIV;
case EBADF:
case EINVAL:
case EFAULT:
case ENOSYS:
case EOVERFLOW:
case pcmk_rc_underflow:
return CRM_EX_SOFTWARE;
case EBADMSG:
case EMSGSIZE:
case ENOMSG:
case ENOPROTOOPT:
case EPROTO:
case EPROTONOSUPPORT:
case EPROTOTYPE:
return CRM_EX_PROTOCOL;
case ECOMM:
case ENOMEM:
return CRM_EX_OSERR;
case ECONNABORTED:
case ECONNREFUSED:
case ECONNRESET:
case ENOTCONN:
return CRM_EX_DISCONNECT;
case EEXIST:
case pcmk_rc_already:
return CRM_EX_EXISTS;
case EIO:
case pcmk_rc_no_output:
case pcmk_rc_dot_error:
case pcmk_rc_graph_error:
return CRM_EX_IOERR;
case ENOTSUP:
#if EOPNOTSUPP != ENOTSUP
case EOPNOTSUPP:
#endif
return CRM_EX_UNIMPLEMENT_FEATURE;
case ENOTUNIQ:
case pcmk_rc_multiple:
return CRM_EX_MULTIPLE;
case ENXIO:
case pcmk_rc_node_unknown:
case pcmk_rc_unknown_format:
return CRM_EX_NOSUCH;
case ETIME:
case ETIMEDOUT:
return CRM_EX_TIMEOUT;
case EAGAIN:
case EBUSY:
return CRM_EX_UNSATISFIED;
case pcmk_rc_before_range:
return CRM_EX_NOT_YET_IN_EFFECT;
case pcmk_rc_after_range:
return CRM_EX_EXPIRED;
case pcmk_rc_undetermined:
return CRM_EX_INDETERMINATE;
case pcmk_rc_op_unsatisfied:
return CRM_EX_UNSATISFIED;
case pcmk_rc_within_range:
return CRM_EX_OK;
case pcmk_rc_no_input:
return CRM_EX_NOINPUT;
+ case pcmk_rc_duplicate_id:
+ return CRM_EX_MULTIPLE;
+
default:
return CRM_EX_ERROR;
}
}
/*!
* \brief Map a function return code to the most similar OCF exit code
*
* \param[in] rc Function return code
*
* \return Most similar OCF exit code
*/
enum ocf_exitcode
pcmk_rc2ocf(int rc)
{
switch (rc) {
case pcmk_rc_ok:
return PCMK_OCF_OK;
case pcmk_rc_bad_nvpair:
return PCMK_OCF_INVALID_PARAM;
case EACCES:
return PCMK_OCF_INSUFFICIENT_PRIV;
case ENOTSUP:
#if EOPNOTSUPP != ENOTSUP
case EOPNOTSUPP:
#endif
return PCMK_OCF_UNIMPLEMENT_FEATURE;
default:
return PCMK_OCF_UNKNOWN_ERROR;
}
}
// Other functions
const char *
bz2_strerror(int rc)
{
// See ftp://sources.redhat.com/pub/bzip2/docs/manual_3.html#SEC17
switch (rc) {
case BZ_OK:
case BZ_RUN_OK:
case BZ_FLUSH_OK:
case BZ_FINISH_OK:
case BZ_STREAM_END:
return "Ok";
case BZ_CONFIG_ERROR:
return "libbz2 has been improperly compiled on your platform";
case BZ_SEQUENCE_ERROR:
return "library functions called in the wrong order";
case BZ_PARAM_ERROR:
return "parameter is out of range or otherwise incorrect";
case BZ_MEM_ERROR:
return "memory allocation failed";
case BZ_DATA_ERROR:
return "data integrity error is detected during decompression";
case BZ_DATA_ERROR_MAGIC:
return "the compressed stream does not start with the correct magic bytes";
case BZ_IO_ERROR:
return "error reading or writing in the compressed file";
case BZ_UNEXPECTED_EOF:
return "compressed file finishes before the logical end of stream is detected";
case BZ_OUTBUFF_FULL:
return "output data will not fit into the buffer provided";
}
return "Data compression error";
}
crm_exit_t
crm_exit(crm_exit_t rc)
{
/* A compiler could theoretically use any type for crm_exit_t, but an int
* should always hold it, so cast to int to keep static analysis happy.
*/
if ((((int) rc) < 0) || (((int) rc) > CRM_EX_MAX)) {
rc = CRM_EX_ERROR;
}
mainloop_cleanup();
crm_xml_cleanup();
pcmk__cli_option_cleanup();
if (crm_system_name) {
crm_info("Exiting %s " CRM_XS " with status %d", crm_system_name, rc);
free(crm_system_name);
} else {
crm_trace("Exiting with status %d", rc);
}
qb_log_fini(); // Don't log anything after this point
exit(rc);
}
/*
* External action results
*/
/*!
* \internal
* \brief Set the result of an action
*
* \param[out] result Where to set action result
* \param[in] exit_status OCF exit status to set
* \param[in] exec_status Execution status to set
* \param[in] exit_reason Human-friendly description of event to set
*/
void
pcmk__set_result(pcmk__action_result_t *result, int exit_status,
enum pcmk_exec_status exec_status, const char *exit_reason)
{
if (result == NULL) {
return;
}
result->exit_status = exit_status;
result->execution_status = exec_status;
if (!pcmk__str_eq(result->exit_reason, exit_reason, pcmk__str_none)) {
free(result->exit_reason);
result->exit_reason = (exit_reason == NULL)? NULL : strdup(exit_reason);
}
}
/*!
* \internal
* \brief Set the result of an action, with a formatted exit reason
*
* \param[out] result Where to set action result
* \param[in] exit_status OCF exit status to set
* \param[in] exec_status Execution status to set
* \param[in] format printf-style format for a human-friendly
* description of reason for result
* \param[in] ... arguments for \p format
*/
G_GNUC_PRINTF(4, 5)
void
pcmk__format_result(pcmk__action_result_t *result, int exit_status,
enum pcmk_exec_status exec_status,
const char *format, ...)
{
va_list ap;
int len = 0;
char *reason = NULL;
if (result == NULL) {
return;
}
result->exit_status = exit_status;
result->execution_status = exec_status;
if (format != NULL) {
va_start(ap, format);
len = vasprintf(&reason, format, ap);
CRM_ASSERT(len > 0);
va_end(ap);
}
free(result->exit_reason);
result->exit_reason = reason;
}
/*!
* \internal
* \brief Set the output of an action
*
* \param[out] result Action result to set output for
* \param[in] out Action output to set (must be dynamically
* allocated)
* \param[in] err Action error output to set (must be dynamically
* allocated)
*
* \note \p result will take ownership of \p out and \p err, so the caller
* should not free them.
*/
void
pcmk__set_result_output(pcmk__action_result_t *result, char *out, char *err)
{
if (result == NULL) {
return;
}
free(result->action_stdout);
result->action_stdout = out;
free(result->action_stderr);
result->action_stderr = err;
}
/*!
* \internal
* \brief Clear a result's exit reason, output, and error output
*
* \param[in] result Result to reset
*/
void
pcmk__reset_result(pcmk__action_result_t *result)
{
if (result == NULL) {
return;
}
free(result->exit_reason);
result->exit_reason = NULL;
free(result->action_stdout);
result->action_stdout = NULL;
free(result->action_stderr);
result->action_stderr = NULL;
}
/*!
* \internal
* \brief Copy the result of an action
*
* \param[in] src Result to copy
* \param[out] dst Where to copy \p src to
*/
void
pcmk__copy_result(pcmk__action_result_t *src, pcmk__action_result_t *dst)
{
CRM_CHECK((src != NULL) && (dst != NULL), return);
dst->exit_status = src->exit_status;
dst->execution_status = src->execution_status;
pcmk__str_update(&src->exit_reason, dst->exit_reason);
pcmk__str_update(&src->action_stdout, dst->action_stdout);
pcmk__str_update(&src->action_stderr, dst->action_stderr);
}
// Deprecated functions kept only for backward API compatibility
// LCOV_EXCL_START
#include
crm_exit_t
crm_errno2exit(int rc)
{
return pcmk_rc2exitc(pcmk_legacy2rc(rc));
}
// LCOV_EXCL_STOP
// End deprecated API
diff --git a/lib/pacemaker/Makefile.am b/lib/pacemaker/Makefile.am
index 7dbb6c44f2..aaea39bb4b 100644
--- a/lib/pacemaker/Makefile.am
+++ b/lib/pacemaker/Makefile.am
@@ -1,64 +1,65 @@
#
# Copyright 2004-2022 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# or later (GPLv2+) WITHOUT ANY WARRANTY.
#
include $(top_srcdir)/mk/common.mk
AM_CPPFLAGS += -I$(top_builddir) -I$(top_srcdir)
noinst_HEADERS = libpacemaker_private.h
## libraries
lib_LTLIBRARIES = libpacemaker.la
## SOURCES
libpacemaker_la_LDFLAGS = -version-info 5:0:4
libpacemaker_la_CFLAGS = $(CFLAGS_HARDENED_LIB)
libpacemaker_la_LDFLAGS += $(LDFLAGS_HARDENED_LIB)
libpacemaker_la_LIBADD = $(top_builddir)/lib/pengine/libpe_status.la \
$(top_builddir)/lib/cib/libcib.la \
$(top_builddir)/lib/lrmd/liblrmd.la \
$(top_builddir)/lib/fencing/libstonithd.la \
$(top_builddir)/lib/services/libcrmservice.la \
$(top_builddir)/lib/common/libcrmcommon.la
# -L$(top_builddir)/lib/pils -lpils -export-dynamic -module -avoid-version
# Use += rather than backlashed continuation lines for parsing by bumplibs
libpacemaker_la_SOURCES =
libpacemaker_la_SOURCES += pcmk_acl.c
libpacemaker_la_SOURCES += pcmk_cluster_queries.c
libpacemaker_la_SOURCES += pcmk_fence.c
libpacemaker_la_SOURCES += pcmk_graph_consumer.c
libpacemaker_la_SOURCES += pcmk_graph_logging.c
libpacemaker_la_SOURCES += pcmk_graph_producer.c
libpacemaker_la_SOURCES += pcmk_injections.c
libpacemaker_la_SOURCES += pcmk_output.c
libpacemaker_la_SOURCES += pcmk_resource.c
+libpacemaker_la_SOURCES += pcmk_rule.c
libpacemaker_la_SOURCES += pcmk_sched_actions.c
libpacemaker_la_SOURCES += pcmk_sched_allocate.c
libpacemaker_la_SOURCES += pcmk_sched_bundle.c
libpacemaker_la_SOURCES += pcmk_sched_clone.c
libpacemaker_la_SOURCES += pcmk_sched_colocation.c
libpacemaker_la_SOURCES += pcmk_sched_constraints.c
libpacemaker_la_SOURCES += pcmk_sched_fencing.c
libpacemaker_la_SOURCES += pcmk_sched_group.c
libpacemaker_la_SOURCES += pcmk_sched_location.c
libpacemaker_la_SOURCES += pcmk_sched_nodes.c
libpacemaker_la_SOURCES += pcmk_sched_ordering.c
libpacemaker_la_SOURCES += pcmk_sched_primitive.c
libpacemaker_la_SOURCES += pcmk_sched_probes.c
libpacemaker_la_SOURCES += pcmk_sched_promotable.c
libpacemaker_la_SOURCES += pcmk_sched_remote.c
libpacemaker_la_SOURCES += pcmk_sched_resource.c
libpacemaker_la_SOURCES += pcmk_sched_tickets.c
libpacemaker_la_SOURCES += pcmk_sched_utilization.c
libpacemaker_la_SOURCES += pcmk_simulate.c
libpacemaker_la_SOURCES += pcmk_status.c
diff --git a/lib/pacemaker/pcmk_output.c b/lib/pacemaker/pcmk_output.c
index 984b89a937..ffb1f65d22 100644
--- a/lib/pacemaker/pcmk_output.c
+++ b/lib/pacemaker/pcmk_output.c
@@ -1,1923 +1,1984 @@
/*
* Copyright 2019-2022 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU General Public License version 2
* or later (GPLv2+) WITHOUT ANY WARRANTY.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
static char *
colocations_header(pe_resource_t *rsc, pcmk__colocation_t *cons,
gboolean dependents) {
char *retval = NULL;
if (cons->primary_role > RSC_ROLE_STARTED) {
retval = crm_strdup_printf("%s (score=%s, %s role=%s, id=%s)",
rsc->id, pcmk_readable_score(cons->score),
(dependents? "needs" : "with"),
role2text(cons->primary_role), cons->id);
} else {
retval = crm_strdup_printf("%s (score=%s, id=%s)",
rsc->id, pcmk_readable_score(cons->score),
cons->id);
}
return retval;
}
static void
colocations_xml_node(pcmk__output_t *out, pe_resource_t *rsc,
pcmk__colocation_t *cons) {
xmlNodePtr node = NULL;
node = pcmk__output_create_xml_node(out, XML_CONS_TAG_RSC_DEPEND,
"id", cons->id,
"rsc", cons->dependent->id,
"with-rsc", cons->primary->id,
"score", pcmk_readable_score(cons->score),
NULL);
if (cons->node_attribute) {
xmlSetProp(node, (pcmkXmlStr) "node-attribute", (pcmkXmlStr) cons->node_attribute);
}
if (cons->dependent_role != RSC_ROLE_UNKNOWN) {
xmlSetProp(node, (pcmkXmlStr) "rsc-role",
(pcmkXmlStr) role2text(cons->dependent_role));
}
if (cons->primary_role != RSC_ROLE_UNKNOWN) {
xmlSetProp(node, (pcmkXmlStr) "with-rsc-role",
(pcmkXmlStr) role2text(cons->primary_role));
}
}
static int
do_locations_list_xml(pcmk__output_t *out, pe_resource_t *rsc, bool add_header)
{
GList *lpc = NULL;
GList *list = rsc->rsc_location;
int rc = pcmk_rc_no_output;
for (lpc = list; lpc != NULL; lpc = lpc->next) {
pe__location_t *cons = lpc->data;
GList *lpc2 = NULL;
for (lpc2 = cons->node_list_rh; lpc2 != NULL; lpc2 = lpc2->next) {
pe_node_t *node = (pe_node_t *) lpc2->data;
if (add_header) {
PCMK__OUTPUT_LIST_HEADER(out, FALSE, rc, "locations");
}
pcmk__output_create_xml_node(out, XML_CONS_TAG_RSC_LOCATION,
"node", node->details->uname,
"rsc", rsc->id,
"id", cons->id,
"score", pcmk_readable_score(node->weight),
NULL);
}
}
if (add_header) {
PCMK__OUTPUT_LIST_FOOTER(out, rc);
}
return rc;
}
PCMK__OUTPUT_ARGS("rsc-action-item", "const char *", "pe_resource_t *",
"pe_node_t *", "pe_node_t *", "pe_action_t *",
"pe_action_t *")
static int
rsc_action_item(pcmk__output_t *out, va_list args)
{
const char *change = va_arg(args, const char *);
pe_resource_t *rsc = va_arg(args, pe_resource_t *);
pe_node_t *origin = va_arg(args, pe_node_t *);
pe_node_t *destination = va_arg(args, pe_node_t *);
pe_action_t *action = va_arg(args, pe_action_t *);
pe_action_t *source = va_arg(args, pe_action_t *);
int len = 0;
char *reason = NULL;
char *details = NULL;
bool same_host = FALSE;
bool same_role = FALSE;
bool need_role = FALSE;
static int rsc_width = 5;
static int detail_width = 5;
CRM_ASSERT(action);
CRM_ASSERT(destination != NULL || origin != NULL);
if(source == NULL) {
source = action;
}
len = strlen(rsc->id);
if(len > rsc_width) {
rsc_width = len + 2;
}
if ((rsc->role > RSC_ROLE_STARTED)
|| (rsc->next_role > RSC_ROLE_UNPROMOTED)) {
need_role = TRUE;
}
if(origin != NULL && destination != NULL && origin->details == destination->details) {
same_host = TRUE;
}
if(rsc->role == rsc->next_role) {
same_role = TRUE;
}
if (need_role && (origin == NULL)) {
/* Starting and promoting a promotable clone instance */
details = crm_strdup_printf("%s -> %s %s", role2text(rsc->role), role2text(rsc->next_role), destination->details->uname);
} else if (origin == NULL) {
/* Starting a resource */
details = crm_strdup_printf("%s", destination->details->uname);
} else if (need_role && (destination == NULL)) {
/* Stopping a promotable clone instance */
details = crm_strdup_printf("%s %s", role2text(rsc->role), origin->details->uname);
} else if (destination == NULL) {
/* Stopping a resource */
details = crm_strdup_printf("%s", origin->details->uname);
} else if (need_role && same_role && same_host) {
/* Recovering, restarting or re-promoting a promotable clone instance */
details = crm_strdup_printf("%s %s", role2text(rsc->role), origin->details->uname);
} else if (same_role && same_host) {
/* Recovering or Restarting a normal resource */
details = crm_strdup_printf("%s", origin->details->uname);
} else if (need_role && same_role) {
/* Moving a promotable clone instance */
details = crm_strdup_printf("%s -> %s %s", origin->details->uname, destination->details->uname, role2text(rsc->role));
} else if (same_role) {
/* Moving a normal resource */
details = crm_strdup_printf("%s -> %s", origin->details->uname, destination->details->uname);
} else if (same_host) {
/* Promoting or demoting a promotable clone instance */
details = crm_strdup_printf("%s -> %s %s", role2text(rsc->role), role2text(rsc->next_role), origin->details->uname);
} else {
/* Moving and promoting/demoting */
details = crm_strdup_printf("%s %s -> %s %s", role2text(rsc->role), origin->details->uname, role2text(rsc->next_role), destination->details->uname);
}
len = strlen(details);
if(len > detail_width) {
detail_width = len;
}
if(source->reason && !pcmk_is_set(action->flags, pe_action_runnable)) {
reason = crm_strdup_printf("due to %s (blocked)", source->reason);
} else if(source->reason) {
reason = crm_strdup_printf("due to %s", source->reason);
} else if (!pcmk_is_set(action->flags, pe_action_runnable)) {
reason = strdup("blocked");
}
out->list_item(out, NULL, "%-8s %-*s ( %*s )%s%s", change, rsc_width,
rsc->id, detail_width, details, reason ? " " : "", reason ? reason : "");
free(details);
free(reason);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("rsc-action-item", "const char *", "pe_resource_t *",
"pe_node_t *", "pe_node_t *", "pe_action_t *",
"pe_action_t *")
static int
rsc_action_item_xml(pcmk__output_t *out, va_list args)
{
const char *change = va_arg(args, const char *);
pe_resource_t *rsc = va_arg(args, pe_resource_t *);
pe_node_t *origin = va_arg(args, pe_node_t *);
pe_node_t *destination = va_arg(args, pe_node_t *);
pe_action_t *action = va_arg(args, pe_action_t *);
pe_action_t *source = va_arg(args, pe_action_t *);
char *change_str = NULL;
bool same_host = FALSE;
bool same_role = FALSE;
bool need_role = FALSE;
xmlNode *xml = NULL;
CRM_ASSERT(action);
CRM_ASSERT(destination != NULL || origin != NULL);
if (source == NULL) {
source = action;
}
if ((rsc->role > RSC_ROLE_STARTED)
|| (rsc->next_role > RSC_ROLE_UNPROMOTED)) {
need_role = TRUE;
}
if(origin != NULL && destination != NULL && origin->details == destination->details) {
same_host = TRUE;
}
if(rsc->role == rsc->next_role) {
same_role = TRUE;
}
change_str = g_ascii_strdown(change, -1);
xml = pcmk__output_create_xml_node(out, "rsc_action",
"action", change_str,
"resource", rsc->id,
NULL);
g_free(change_str);
if (need_role && (origin == NULL)) {
/* Starting and promoting a promotable clone instance */
pcmk__xe_set_props(xml,
"role", role2text(rsc->role),
"next-role", role2text(rsc->next_role),
"dest", destination->details->uname,
NULL);
} else if (origin == NULL) {
/* Starting a resource */
crm_xml_add(xml, "node", destination->details->uname);
} else if (need_role && (destination == NULL)) {
/* Stopping a promotable clone instance */
pcmk__xe_set_props(xml,
"role", role2text(rsc->role),
"node", origin->details->uname,
NULL);
} else if (destination == NULL) {
/* Stopping a resource */
crm_xml_add(xml, "node", origin->details->uname);
} else if (need_role && same_role && same_host) {
/* Recovering, restarting or re-promoting a promotable clone instance */
pcmk__xe_set_props(xml,
"role", role2text(rsc->role),
"source", origin->details->uname,
NULL);
} else if (same_role && same_host) {
/* Recovering or Restarting a normal resource */
crm_xml_add(xml, "source", origin->details->uname);
} else if (need_role && same_role) {
/* Moving a promotable clone instance */
pcmk__xe_set_props(xml,
"source", origin->details->uname,
"dest", destination->details->uname,
"role", role2text(rsc->role),
NULL);
} else if (same_role) {
/* Moving a normal resource */
pcmk__xe_set_props(xml,
"source", origin->details->uname,
"dest", destination->details->uname,
NULL);
} else if (same_host) {
/* Promoting or demoting a promotable clone instance */
pcmk__xe_set_props(xml,
"role", role2text(rsc->role),
"next-role", role2text(rsc->next_role),
"source", origin->details->uname,
NULL);
} else {
/* Moving and promoting/demoting */
pcmk__xe_set_props(xml,
"role", role2text(rsc->role),
"source", origin->details->uname,
"next-role", role2text(rsc->next_role),
"dest", destination->details->uname,
NULL);
}
if (source->reason && !pcmk_is_set(action->flags, pe_action_runnable)) {
pcmk__xe_set_props(xml,
"reason", source->reason,
"blocked", "true",
NULL);
} else if(source->reason) {
crm_xml_add(xml, "reason", source->reason);
} else if (!pcmk_is_set(action->flags, pe_action_runnable)) {
pcmk__xe_set_bool_attr(xml, "blocked", true);
}
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("rsc-is-colocated-with-list", "pe_resource_t *", "gboolean")
static int
rsc_is_colocated_with_list(pcmk__output_t *out, va_list args) {
pe_resource_t *rsc = va_arg(args, pe_resource_t *);
gboolean recursive = va_arg(args, gboolean);
int rc = pcmk_rc_no_output;
if (pcmk_is_set(rsc->flags, pe_rsc_allocating)) {
return rc;
}
pe__set_resource_flags(rsc, pe_rsc_allocating);
for (GList *lpc = rsc->rsc_cons; lpc != NULL; lpc = lpc->next) {
pcmk__colocation_t *cons = (pcmk__colocation_t *) lpc->data;
char *hdr = NULL;
PCMK__OUTPUT_LIST_HEADER(out, FALSE, rc, "Resources %s is colocated with", rsc->id);
if (pcmk_is_set(cons->primary->flags, pe_rsc_allocating)) {
out->list_item(out, NULL, "%s (id=%s - loop)",
cons->primary->id, cons->id);
continue;
}
hdr = colocations_header(cons->primary, cons, FALSE);
out->list_item(out, NULL, "%s", hdr);
free(hdr);
/* Empty list header just for indentation of information about this resource. */
out->begin_list(out, NULL, NULL, NULL);
out->message(out, "locations-list", cons->primary);
if (recursive) {
out->message(out, "rsc-is-colocated-with-list",
cons->primary, recursive);
}
out->end_list(out);
}
PCMK__OUTPUT_LIST_FOOTER(out, rc);
return rc;
}
PCMK__OUTPUT_ARGS("rsc-is-colocated-with-list", "pe_resource_t *", "gboolean")
static int
rsc_is_colocated_with_list_xml(pcmk__output_t *out, va_list args) {
pe_resource_t *rsc = va_arg(args, pe_resource_t *);
gboolean recursive = va_arg(args, gboolean);
int rc = pcmk_rc_no_output;
if (pcmk_is_set(rsc->flags, pe_rsc_allocating)) {
return rc;
}
pe__set_resource_flags(rsc, pe_rsc_allocating);
for (GList *lpc = rsc->rsc_cons; lpc != NULL; lpc = lpc->next) {
pcmk__colocation_t *cons = (pcmk__colocation_t *) lpc->data;
if (pcmk_is_set(cons->primary->flags, pe_rsc_allocating)) {
colocations_xml_node(out, cons->primary, cons);
continue;
}
colocations_xml_node(out, cons->primary, cons);
do_locations_list_xml(out, cons->primary, false);
if (recursive) {
out->message(out, "rsc-is-colocated-with-list",
cons->primary, recursive);
}
}
return rc;
}
PCMK__OUTPUT_ARGS("rscs-colocated-with-list", "pe_resource_t *", "gboolean")
static int
rscs_colocated_with_list(pcmk__output_t *out, va_list args) {
pe_resource_t *rsc = va_arg(args, pe_resource_t *);
gboolean recursive = va_arg(args, gboolean);
int rc = pcmk_rc_no_output;
if (pcmk_is_set(rsc->flags, pe_rsc_allocating)) {
return rc;
}
pe__set_resource_flags(rsc, pe_rsc_allocating);
for (GList *lpc = rsc->rsc_cons_lhs; lpc != NULL; lpc = lpc->next) {
pcmk__colocation_t *cons = (pcmk__colocation_t *) lpc->data;
char *hdr = NULL;
PCMK__OUTPUT_LIST_HEADER(out, FALSE, rc, "Resources colocated with %s", rsc->id);
if (pcmk_is_set(cons->dependent->flags, pe_rsc_allocating)) {
out->list_item(out, NULL, "%s (id=%s - loop)",
cons->dependent->id, cons->id);
continue;
}
hdr = colocations_header(cons->dependent, cons, TRUE);
out->list_item(out, NULL, "%s", hdr);
free(hdr);
/* Empty list header just for indentation of information about this resource. */
out->begin_list(out, NULL, NULL, NULL);
out->message(out, "locations-list", cons->dependent);
if (recursive) {
out->message(out, "rscs-colocated-with-list",
cons->dependent, recursive);
}
out->end_list(out);
}
PCMK__OUTPUT_LIST_FOOTER(out, rc);
return rc;
}
PCMK__OUTPUT_ARGS("rscs-colocated-with-list", "pe_resource_t *", "gboolean")
static int
rscs_colocated_with_list_xml(pcmk__output_t *out, va_list args) {
pe_resource_t *rsc = va_arg(args, pe_resource_t *);
gboolean recursive = va_arg(args, gboolean);
int rc = pcmk_rc_no_output;
if (pcmk_is_set(rsc->flags, pe_rsc_allocating)) {
return rc;
}
pe__set_resource_flags(rsc, pe_rsc_allocating);
for (GList *lpc = rsc->rsc_cons_lhs; lpc != NULL; lpc = lpc->next) {
pcmk__colocation_t *cons = (pcmk__colocation_t *) lpc->data;
if (pcmk_is_set(cons->dependent->flags, pe_rsc_allocating)) {
colocations_xml_node(out, cons->dependent, cons);
continue;
}
colocations_xml_node(out, cons->dependent, cons);
do_locations_list_xml(out, cons->dependent, false);
if (recursive) {
out->message(out, "rscs-colocated-with-list",
cons->dependent, recursive);
}
}
return rc;
}
PCMK__OUTPUT_ARGS("locations-list", "pe_resource_t *")
static int
locations_list(pcmk__output_t *out, va_list args) {
pe_resource_t *rsc = va_arg(args, pe_resource_t *);
GList *lpc = NULL;
GList *list = rsc->rsc_location;
int rc = pcmk_rc_no_output;
for (lpc = list; lpc != NULL; lpc = lpc->next) {
pe__location_t *cons = lpc->data;
GList *lpc2 = NULL;
for (lpc2 = cons->node_list_rh; lpc2 != NULL; lpc2 = lpc2->next) {
pe_node_t *node = (pe_node_t *) lpc2->data;
PCMK__OUTPUT_LIST_HEADER(out, FALSE, rc, "Locations");
out->list_item(out, NULL, "Node %s (score=%s, id=%s, rsc=%s)",
node->details->uname,
pcmk_readable_score(node->weight), cons->id,
rsc->id);
}
}
PCMK__OUTPUT_LIST_FOOTER(out, rc);
return rc;
}
PCMK__OUTPUT_ARGS("locations-list", "pe_resource_t *")
static int
locations_list_xml(pcmk__output_t *out, va_list args) {
pe_resource_t *rsc = va_arg(args, pe_resource_t *);
return do_locations_list_xml(out, rsc, true);
}
PCMK__OUTPUT_ARGS("stacks-constraints", "pe_resource_t *", "pe_working_set_t *", "gboolean")
static int
stacks_and_constraints(pcmk__output_t *out, va_list args) {
pe_resource_t *rsc = va_arg(args, pe_resource_t *);
pe_working_set_t *data_set = va_arg(args, pe_working_set_t *);
gboolean recursive = va_arg(args, gboolean);
pcmk__unpack_constraints(data_set);
// Constraints apply to group/clone, not member/instance
rsc = uber_parent(rsc);
out->message(out, "locations-list", rsc);
pe__clear_resource_flags_on_all(data_set, pe_rsc_allocating);
out->message(out, "rscs-colocated-with-list", rsc, recursive);
pe__clear_resource_flags_on_all(data_set, pe_rsc_allocating);
out->message(out, "rsc-is-colocated-with-list", rsc, recursive);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("stacks-constraints", "pe_resource_t *", "pe_working_set_t *", "gboolean")
static int
stacks_and_constraints_xml(pcmk__output_t *out, va_list args) {
pe_resource_t *rsc = va_arg(args, pe_resource_t *);
pe_working_set_t *data_set = va_arg(args, pe_working_set_t *);
gboolean recursive = va_arg(args, gboolean);
pcmk__unpack_constraints(data_set);
// Constraints apply to group/clone, not member/instance
rsc = uber_parent(rsc);
pcmk__output_xml_create_parent(out, "constraints", NULL);
do_locations_list_xml(out, rsc, false);
pe__clear_resource_flags_on_all(data_set, pe_rsc_allocating);
out->message(out, "rscs-colocated-with-list", rsc, recursive);
pe__clear_resource_flags_on_all(data_set, pe_rsc_allocating);
out->message(out, "rsc-is-colocated-with-list", rsc, recursive);
pcmk__output_xml_pop_parent(out);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("health", "const char *", "const char *", "const char *", "const char *")
static int
health_text(pcmk__output_t *out, va_list args)
{
const char *sys_from G_GNUC_UNUSED = va_arg(args, const char *);
const char *host_from = va_arg(args, const char *);
const char *fsa_state = va_arg(args, const char *);
const char *result = va_arg(args, const char *);
if (!out->is_quiet(out)) {
return out->info(out, "Controller on %s in state %s: %s",
pcmk__s(host_from, "unknown node"),
pcmk__s(fsa_state, "unknown"),
pcmk__s(result, "unknown result"));
} else if (fsa_state != NULL) {
pcmk__formatted_printf(out, "%s\n", fsa_state);
return pcmk_rc_ok;
}
return pcmk_rc_no_output;
}
PCMK__OUTPUT_ARGS("health", "const char *", "const char *", "const char *", "const char *")
static int
health_xml(pcmk__output_t *out, va_list args)
{
const char *sys_from = va_arg(args, const char *);
const char *host_from = va_arg(args, const char *);
const char *fsa_state = va_arg(args, const char *);
const char *result = va_arg(args, const char *);
pcmk__output_create_xml_node(out, pcmk__s(sys_from, ""),
"node_name", pcmk__s(host_from, ""),
"state", pcmk__s(fsa_state, ""),
"result", pcmk__s(result, ""),
NULL);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("pacemakerd-health", "const char *", "const char *", "const char *")
static int
pacemakerd_health_text(pcmk__output_t *out, va_list args)
{
const char *sys_from = va_arg(args, const char *);
const char *state = va_arg(args, const char *);
const char *last_updated = va_arg(args, const char *);
if (!out->is_quiet(out)) {
return out->info(out, "Status of %s: '%s' (last updated %s)",
pcmk__s(sys_from, "unknown node"),
pcmk__s(state, "unknown state"),
pcmk__s(last_updated, "at unknown time"));
} else {
pcmk__formatted_printf(out, "%s\n", pcmk__s(state, ""));
return pcmk_rc_ok;
}
return pcmk_rc_no_output;
}
PCMK__OUTPUT_ARGS("pacemakerd-health", "const char *", "const char *", "const char *")
static int
pacemakerd_health_xml(pcmk__output_t *out, va_list args)
{
const char *sys_from = va_arg(args, const char *);
const char *state = va_arg(args, const char *);
const char *last_updated = va_arg(args, const char *);
pcmk__output_create_xml_node(out, pcmk__s(sys_from, ""),
"state", pcmk__s(state, ""),
"last_updated", pcmk__s(last_updated, ""),
NULL);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("profile", "const char *", "clock_t", "clock_t")
static int
profile_default(pcmk__output_t *out, va_list args) {
const char *xml_file = va_arg(args, const char *);
clock_t start = va_arg(args, clock_t);
clock_t end = va_arg(args, clock_t);
out->list_item(out, NULL, "Testing %s ... %.2f secs", xml_file,
(end - start) / (float) CLOCKS_PER_SEC);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("profile", "const char *", "clock_t", "clock_t")
static int
profile_xml(pcmk__output_t *out, va_list args) {
const char *xml_file = va_arg(args, const char *);
clock_t start = va_arg(args, clock_t);
clock_t end = va_arg(args, clock_t);
char *duration = pcmk__ftoa((end - start) / (float) CLOCKS_PER_SEC);
pcmk__output_create_xml_node(out, "timing",
"file", xml_file,
"duration", duration,
NULL);
free(duration);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("dc", "const char *")
static int
dc_text(pcmk__output_t *out, va_list args)
{
const char *dc = va_arg(args, const char *);
if (!out->is_quiet(out)) {
return out->info(out, "Designated Controller is: %s",
pcmk__s(dc, "not yet elected"));
} else if (dc != NULL) {
pcmk__formatted_printf(out, "%s\n", pcmk__s(dc, ""));
return pcmk_rc_ok;
}
return pcmk_rc_no_output;
}
PCMK__OUTPUT_ARGS("dc", "const char *")
static int
dc_xml(pcmk__output_t *out, va_list args)
{
const char *dc = va_arg(args, const char *);
pcmk__output_create_xml_node(out, "dc",
"node_name", pcmk__s(dc, ""),
NULL);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("crmadmin-node", "const char *", "const char *", "const char *", "gboolean")
static int
crmadmin_node_text(pcmk__output_t *out, va_list args)
{
const char *type = va_arg(args, const char *);
const char *name = va_arg(args, const char *);
const char *id = va_arg(args, const char *);
gboolean BASH_EXPORT = va_arg(args, gboolean);
if (out->is_quiet(out)) {
pcmk__formatted_printf(out, "%s\n", pcmk__s(name, ""));
return pcmk_rc_ok;
} else if (BASH_EXPORT) {
return out->info(out, "export %s=%s",
pcmk__s(name, ""), pcmk__s(id, ""));
} else {
return out->info(out, "%s node: %s (%s)", type ? type : "cluster",
pcmk__s(name, ""), pcmk__s(id, ""));
}
}
PCMK__OUTPUT_ARGS("crmadmin-node", "const char *", "const char *", "const char *", "gboolean")
static int
crmadmin_node_xml(pcmk__output_t *out, va_list args)
{
const char *type = va_arg(args, const char *);
const char *name = va_arg(args, const char *);
const char *id = va_arg(args, const char *);
pcmk__output_create_xml_node(out, "node",
"type", type ? type : "cluster",
"name", pcmk__s(name, ""),
"id", pcmk__s(id, ""),
NULL);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("digests", "pe_resource_t *", "pe_node_t *", "const char *",
"guint", "op_digest_cache_t *")
static int
digests_text(pcmk__output_t *out, va_list args)
{
pe_resource_t *rsc = va_arg(args, pe_resource_t *);
pe_node_t *node = va_arg(args, pe_node_t *);
const char *task = va_arg(args, const char *);
guint interval_ms = va_arg(args, guint);
op_digest_cache_t *digests = va_arg(args, op_digest_cache_t *);
char *action_desc = NULL;
const char *rsc_desc = "unknown resource";
const char *node_desc = "unknown node";
if (interval_ms != 0) {
action_desc = crm_strdup_printf("%ums-interval %s action", interval_ms,
((task == NULL)? "unknown" : task));
} else if (pcmk__str_eq(task, "monitor", pcmk__str_none)) {
action_desc = strdup("probe action");
} else {
action_desc = crm_strdup_printf("%s action",
((task == NULL)? "unknown" : task));
}
if ((rsc != NULL) && (rsc->id != NULL)) {
rsc_desc = rsc->id;
}
if ((node != NULL) && (node->details->uname != NULL)) {
node_desc = node->details->uname;
}
out->begin_list(out, NULL, NULL, "Digests for %s %s on %s",
rsc_desc, action_desc, node_desc);
free(action_desc);
if (digests == NULL) {
out->list_item(out, NULL, "none");
out->end_list(out);
return pcmk_rc_ok;
}
if (digests->digest_all_calc != NULL) {
out->list_item(out, NULL, "%s (all parameters)",
digests->digest_all_calc);
}
if (digests->digest_secure_calc != NULL) {
out->list_item(out, NULL, "%s (non-private parameters)",
digests->digest_secure_calc);
}
if (digests->digest_restart_calc != NULL) {
out->list_item(out, NULL, "%s (non-reloadable parameters)",
digests->digest_restart_calc);
}
out->end_list(out);
return pcmk_rc_ok;
}
static void
add_digest_xml(xmlNode *parent, const char *type, const char *digest,
xmlNode *digest_source)
{
if (digest != NULL) {
xmlNodePtr digest_xml = create_xml_node(parent, "digest");
crm_xml_add(digest_xml, "type", ((type == NULL)? "unspecified" : type));
crm_xml_add(digest_xml, "hash", digest);
if (digest_source != NULL) {
add_node_copy(digest_xml, digest_source);
}
}
}
PCMK__OUTPUT_ARGS("digests", "pe_resource_t *", "pe_node_t *", "const char *",
"guint", "op_digest_cache_t *")
static int
digests_xml(pcmk__output_t *out, va_list args)
{
pe_resource_t *rsc = va_arg(args, pe_resource_t *);
pe_node_t *node = va_arg(args, pe_node_t *);
const char *task = va_arg(args, const char *);
guint interval_ms = va_arg(args, guint);
op_digest_cache_t *digests = va_arg(args, op_digest_cache_t *);
char *interval_s = crm_strdup_printf("%ums", interval_ms);
xmlNode *xml = NULL;
xml = pcmk__output_create_xml_node(out, "digests",
"resource", pcmk__s(rsc->id, ""),
"node", pcmk__s(node->details->uname, ""),
"task", pcmk__s(task, ""),
"interval", interval_s,
NULL);
free(interval_s);
if (digests != NULL) {
add_digest_xml(xml, "all", digests->digest_all_calc,
digests->params_all);
add_digest_xml(xml, "nonprivate", digests->digest_secure_calc,
digests->params_secure);
add_digest_xml(xml, "nonreloadable", digests->digest_restart_calc,
digests->params_restart);
}
return pcmk_rc_ok;
}
#define STOP_SANITY_ASSERT(lineno) do { \
if(current && current->details->unclean) { \
/* It will be a pseudo op */ \
} else if(stop == NULL) { \
crm_err("%s:%d: No stop action exists for %s", \
__func__, lineno, rsc->id); \
CRM_ASSERT(stop != NULL); \
} else if (pcmk_is_set(stop->flags, pe_action_optional)) { \
crm_err("%s:%d: Action %s is still optional", \
__func__, lineno, stop->uuid); \
CRM_ASSERT(!pcmk_is_set(stop->flags, pe_action_optional)); \
} \
} while(0)
PCMK__OUTPUT_ARGS("rsc-action", "pe_resource_t *", "pe_node_t *", "pe_node_t *")
static int
rsc_action_default(pcmk__output_t *out, va_list args)
{
pe_resource_t *rsc = va_arg(args, pe_resource_t *);
pe_node_t *current = va_arg(args, pe_node_t *);
pe_node_t *next = va_arg(args, pe_node_t *);
GList *possible_matches = NULL;
char *key = NULL;
int rc = pcmk_rc_no_output;
bool moving = false;
pe_node_t *start_node = NULL;
pe_action_t *start = NULL;
pe_action_t *stop = NULL;
pe_action_t *promote = NULL;
pe_action_t *demote = NULL;
if (!pcmk_is_set(rsc->flags, pe_rsc_managed)
|| (current == NULL && next == NULL)) {
pe_rsc_info(rsc, "Leave %s\t(%s%s)",
rsc->id, role2text(rsc->role),
!pcmk_is_set(rsc->flags, pe_rsc_managed)? " unmanaged" : "");
return rc;
}
moving = (current != NULL) && (next != NULL)
&& (current->details != next->details);
possible_matches = pe__resource_actions(rsc, next, RSC_START, FALSE);
if (possible_matches) {
start = possible_matches->data;
g_list_free(possible_matches);
}
if ((start == NULL) || !pcmk_is_set(start->flags, pe_action_runnable)) {
start_node = NULL;
} else {
start_node = current;
}
possible_matches = pe__resource_actions(rsc, start_node, RSC_STOP, FALSE);
if (possible_matches) {
stop = possible_matches->data;
g_list_free(possible_matches);
} else if (pcmk_is_set(rsc->flags, pe_rsc_stop_unexpected)) {
/* The resource is multiply active with multiple-active set to
* stop_unexpected, and not stopping on its current node, but it should
* be stopping elsewhere.
*/
possible_matches = pe__resource_actions(rsc, NULL, RSC_STOP, FALSE);
if (possible_matches != NULL) {
stop = possible_matches->data;
g_list_free(possible_matches);
}
}
possible_matches = pe__resource_actions(rsc, next, RSC_PROMOTE, FALSE);
if (possible_matches) {
promote = possible_matches->data;
g_list_free(possible_matches);
}
possible_matches = pe__resource_actions(rsc, next, RSC_DEMOTE, FALSE);
if (possible_matches) {
demote = possible_matches->data;
g_list_free(possible_matches);
}
if (rsc->role == rsc->next_role) {
pe_action_t *migrate_op = NULL;
CRM_CHECK(next != NULL, return rc);
possible_matches = pe__resource_actions(rsc, next, RSC_MIGRATED, FALSE);
if (possible_matches) {
migrate_op = possible_matches->data;
}
if ((migrate_op != NULL) && (current != NULL)
&& pcmk_is_set(migrate_op->flags, pe_action_runnable)) {
rc = out->message(out, "rsc-action-item", "Migrate", rsc, current,
next, start, NULL);
} else if (pcmk_is_set(rsc->flags, pe_rsc_reload)) {
rc = out->message(out, "rsc-action-item", "Reload", rsc, current,
next, start, NULL);
} else if (start == NULL || pcmk_is_set(start->flags, pe_action_optional)) {
if ((demote != NULL) && (promote != NULL)
&& !pcmk_is_set(demote->flags, pe_action_optional)
&& !pcmk_is_set(promote->flags, pe_action_optional)) {
rc = out->message(out, "rsc-action-item", "Re-promote", rsc,
current, next, promote, demote);
} else {
pe_rsc_info(rsc, "Leave %s\t(%s %s)", rsc->id,
role2text(rsc->role), next->details->uname);
}
} else if (!pcmk_is_set(start->flags, pe_action_runnable)) {
rc = out->message(out, "rsc-action-item", "Stop", rsc, current,
NULL, stop, (stop && stop->reason)? stop : start);
STOP_SANITY_ASSERT(__LINE__);
} else if (moving && current) {
rc = out->message(out, "rsc-action-item", pcmk_is_set(rsc->flags, pe_rsc_failed)? "Recover" : "Move",
rsc, current, next, stop, NULL);
} else if (pcmk_is_set(rsc->flags, pe_rsc_failed)) {
rc = out->message(out, "rsc-action-item", "Recover", rsc, current,
NULL, stop, NULL);
STOP_SANITY_ASSERT(__LINE__);
} else {
rc = out->message(out, "rsc-action-item", "Restart", rsc, current,
next, start, NULL);
/* STOP_SANITY_ASSERT(__LINE__); False positive for migrate-fail-7 */
}
g_list_free(possible_matches);
return rc;
}
if(stop
&& (rsc->next_role == RSC_ROLE_STOPPED
|| (start && !pcmk_is_set(start->flags, pe_action_runnable)))) {
GList *gIter = NULL;
key = stop_key(rsc);
for (gIter = rsc->running_on; gIter != NULL; gIter = gIter->next) {
pe_node_t *node = (pe_node_t *) gIter->data;
pe_action_t *stop_op = NULL;
possible_matches = find_actions(rsc->actions, key, node);
if (possible_matches) {
stop_op = possible_matches->data;
g_list_free(possible_matches);
}
if (stop_op && (stop_op->flags & pe_action_runnable)) {
STOP_SANITY_ASSERT(__LINE__);
}
if (out->message(out, "rsc-action-item", "Stop", rsc, node, NULL,
stop_op, (stop_op && stop_op->reason)? stop_op : start) == pcmk_rc_ok) {
rc = pcmk_rc_ok;
}
}
free(key);
} else if ((stop != NULL)
&& pcmk_all_flags_set(rsc->flags, pe_rsc_failed|pe_rsc_stop)) {
/* 'stop' may be NULL if the failure was ignored */
rc = out->message(out, "rsc-action-item", "Recover", rsc, current,
next, stop, start);
STOP_SANITY_ASSERT(__LINE__);
} else if (moving) {
rc = out->message(out, "rsc-action-item", "Move", rsc, current, next,
stop, NULL);
STOP_SANITY_ASSERT(__LINE__);
} else if (pcmk_is_set(rsc->flags, pe_rsc_reload)) {
rc = out->message(out, "rsc-action-item", "Reload", rsc, current, next,
start, NULL);
} else if (stop != NULL && !pcmk_is_set(stop->flags, pe_action_optional)) {
rc = out->message(out, "rsc-action-item", "Restart", rsc, current,
next, start, NULL);
STOP_SANITY_ASSERT(__LINE__);
} else if (rsc->role == RSC_ROLE_PROMOTED) {
CRM_LOG_ASSERT(current != NULL);
rc = out->message(out, "rsc-action-item", "Demote", rsc, current,
next, demote, NULL);
} else if (rsc->next_role == RSC_ROLE_PROMOTED) {
CRM_LOG_ASSERT(next);
rc = out->message(out, "rsc-action-item", "Promote", rsc, current,
next, promote, NULL);
} else if (rsc->role == RSC_ROLE_STOPPED && rsc->next_role > RSC_ROLE_STOPPED) {
rc = out->message(out, "rsc-action-item", "Start", rsc, current, next,
start, NULL);
}
return rc;
}
PCMK__OUTPUT_ARGS("node-action", "char *", "char *", "char *")
static int
node_action(pcmk__output_t *out, va_list args)
{
char *task = va_arg(args, char *);
char *node_name = va_arg(args, char *);
char *reason = va_arg(args, char *);
if (task == NULL) {
return pcmk_rc_no_output;
} else if (reason) {
out->list_item(out, NULL, "%s %s '%s'", task, node_name, reason);
} else {
crm_notice(" * %s %s", task, node_name);
}
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("node-action", "char *", "char *", "char *")
static int
node_action_xml(pcmk__output_t *out, va_list args)
{
char *task = va_arg(args, char *);
char *node_name = va_arg(args, char *);
char *reason = va_arg(args, char *);
if (task == NULL) {
return pcmk_rc_no_output;
} else if (reason) {
pcmk__output_create_xml_node(out, "node_action",
"task", task,
"node", node_name,
"reason", reason,
NULL);
} else {
crm_notice(" * %s %s", task, node_name);
}
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("inject-cluster-action", "const char *", "const char *", "xmlNodePtr")
static int
inject_cluster_action(pcmk__output_t *out, va_list args)
{
const char *node = va_arg(args, const char *);
const char *task = va_arg(args, const char *);
xmlNodePtr rsc = va_arg(args, xmlNodePtr);
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
if(rsc) {
out->list_item(out, NULL, "Cluster action: %s for %s on %s", task, ID(rsc), node);
} else {
out->list_item(out, NULL, "Cluster action: %s on %s", task, node);
}
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("inject-cluster-action", "const char *", "const char *", "xmlNodePtr")
static int
inject_cluster_action_xml(pcmk__output_t *out, va_list args)
{
const char *node = va_arg(args, const char *);
const char *task = va_arg(args, const char *);
xmlNodePtr rsc = va_arg(args, xmlNodePtr);
xmlNodePtr xml_node = NULL;
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
xml_node = pcmk__output_create_xml_node(out, "cluster_action",
"task", task,
"node", node,
NULL);
if (rsc) {
crm_xml_add(xml_node, "id", ID(rsc));
}
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("inject-fencing-action", "char *", "const char *")
static int
inject_fencing_action(pcmk__output_t *out, va_list args)
{
char *target = va_arg(args, char *);
const char *op = va_arg(args, const char *);
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
out->list_item(out, NULL, "Fencing %s (%s)", target, op);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("inject-fencing-action", "char *", "const char *")
static int
inject_fencing_action_xml(pcmk__output_t *out, va_list args)
{
char *target = va_arg(args, char *);
const char *op = va_arg(args, const char *);
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
pcmk__output_create_xml_node(out, "fencing_action",
"target", target,
"op", op,
NULL);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("inject-attr", "const char *", "const char *", "xmlNodePtr")
static int
inject_attr(pcmk__output_t *out, va_list args)
{
const char *name = va_arg(args, const char *);
const char *value = va_arg(args, const char *);
xmlNodePtr cib_node = va_arg(args, xmlNodePtr);
xmlChar *node_path = NULL;
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
node_path = xmlGetNodePath(cib_node);
out->list_item(out, NULL, "Injecting attribute %s=%s into %s '%s'",
name, value, node_path, ID(cib_node));
free(node_path);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("inject-attr", "const char *", "const char *", "xmlNodePtr")
static int
inject_attr_xml(pcmk__output_t *out, va_list args)
{
const char *name = va_arg(args, const char *);
const char *value = va_arg(args, const char *);
xmlNodePtr cib_node = va_arg(args, xmlNodePtr);
xmlChar *node_path = NULL;
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
node_path = xmlGetNodePath(cib_node);
pcmk__output_create_xml_node(out, "inject_attr",
"name", name,
"value", value,
"node_path", node_path,
"cib_node", ID(cib_node),
NULL);
free(node_path);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("inject-spec", "const char *")
static int
inject_spec(pcmk__output_t *out, va_list args)
{
const char *spec = va_arg(args, const char *);
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
out->list_item(out, NULL, "Injecting %s into the configuration", spec);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("inject-spec", "const char *")
static int
inject_spec_xml(pcmk__output_t *out, va_list args)
{
const char *spec = va_arg(args, const char *);
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
pcmk__output_create_xml_node(out, "inject_spec",
"spec", spec,
NULL);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("inject-modify-config", "char *", "char *")
static int
inject_modify_config(pcmk__output_t *out, va_list args)
{
char *quorum = va_arg(args, char *);
char *watchdog = va_arg(args, char *);
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
out->begin_list(out, NULL, NULL, "Performing Requested Modifications");
if (quorum) {
out->list_item(out, NULL, "Setting quorum: %s", quorum);
}
if (watchdog) {
out->list_item(out, NULL, "Setting watchdog: %s", watchdog);
}
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("inject-modify-config", "char *", "char *")
static int
inject_modify_config_xml(pcmk__output_t *out, va_list args)
{
char *quorum = va_arg(args, char *);
char *watchdog = va_arg(args, char *);
xmlNodePtr node = NULL;
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
node = pcmk__output_xml_create_parent(out, "modifications", NULL);
if (quorum) {
crm_xml_add(node, "quorum", quorum);
}
if (watchdog) {
crm_xml_add(node, "watchdog", watchdog);
}
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("inject-modify-node", "const char *", "char *")
static int
inject_modify_node(pcmk__output_t *out, va_list args)
{
const char *action = va_arg(args, const char *);
char *node = va_arg(args, char *);
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
if (pcmk__str_eq(action, "Online", pcmk__str_none)) {
out->list_item(out, NULL, "Bringing node %s online", node);
return pcmk_rc_ok;
} else if (pcmk__str_eq(action, "Offline", pcmk__str_none)) {
out->list_item(out, NULL, "Taking node %s offline", node);
return pcmk_rc_ok;
} else if (pcmk__str_eq(action, "Failing", pcmk__str_none)) {
out->list_item(out, NULL, "Failing node %s", node);
return pcmk_rc_ok;
}
return pcmk_rc_no_output;
}
PCMK__OUTPUT_ARGS("inject-modify-node", "const char *", "char *")
static int
inject_modify_node_xml(pcmk__output_t *out, va_list args)
{
const char *action = va_arg(args, const char *);
char *node = va_arg(args, char *);
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
pcmk__output_create_xml_node(out, "modify_node",
"action", action,
"node", node,
NULL);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("inject-modify-ticket", "const char *", "char *")
static int
inject_modify_ticket(pcmk__output_t *out, va_list args)
{
const char *action = va_arg(args, const char *);
char *ticket = va_arg(args, char *);
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
if (pcmk__str_eq(action, "Standby", pcmk__str_none)) {
out->list_item(out, NULL, "Making ticket %s standby", ticket);
} else {
out->list_item(out, NULL, "%s ticket %s", action, ticket);
}
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("inject-modify-ticket", "const char *", "char *")
static int
inject_modify_ticket_xml(pcmk__output_t *out, va_list args)
{
const char *action = va_arg(args, const char *);
char *ticket = va_arg(args, char *);
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
pcmk__output_create_xml_node(out, "modify_ticket",
"action", action,
"ticket", ticket,
NULL);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("inject-pseudo-action", "const char *", "const char *")
static int
inject_pseudo_action(pcmk__output_t *out, va_list args)
{
const char *node = va_arg(args, const char *);
const char *task = va_arg(args, const char *);
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
out->list_item(out, NULL, "Pseudo action: %s%s%s", task, node ? " on " : "",
node ? node : "");
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("inject-pseudo-action", "const char *", "const char *")
static int
inject_pseudo_action_xml(pcmk__output_t *out, va_list args)
{
const char *node = va_arg(args, const char *);
const char *task = va_arg(args, const char *);
xmlNodePtr xml_node = NULL;
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
xml_node = pcmk__output_create_xml_node(out, "pseudo_action",
"task", task,
NULL);
if (node) {
crm_xml_add(xml_node, "node", node);
}
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("inject-rsc-action", "const char *", "const char *", "char *", "guint")
static int
inject_rsc_action(pcmk__output_t *out, va_list args)
{
const char *rsc = va_arg(args, const char *);
const char *operation = va_arg(args, const char *);
char *node = va_arg(args, char *);
guint interval_ms = va_arg(args, guint);
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
if (interval_ms) {
out->list_item(out, NULL, "Resource action: %-15s %s=%u on %s",
rsc, operation, interval_ms, node);
} else {
out->list_item(out, NULL, "Resource action: %-15s %s on %s",
rsc, operation, node);
}
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("inject-rsc-action", "const char *", "const char *", "char *", "guint")
static int
inject_rsc_action_xml(pcmk__output_t *out, va_list args)
{
const char *rsc = va_arg(args, const char *);
const char *operation = va_arg(args, const char *);
char *node = va_arg(args, char *);
guint interval_ms = va_arg(args, guint);
xmlNodePtr xml_node = NULL;
if (out->is_quiet(out)) {
return pcmk_rc_no_output;
}
xml_node = pcmk__output_create_xml_node(out, "rsc_action",
"resource", rsc,
"op", operation,
"node", node,
NULL);
if (interval_ms) {
char *interval_s = pcmk__itoa(interval_ms);
crm_xml_add(xml_node, "interval", interval_s);
free(interval_s);
}
return pcmk_rc_ok;
}
#define CHECK_RC(retcode, retval) \
if (retval == pcmk_rc_ok) { \
retcode = pcmk_rc_ok; \
}
PCMK__OUTPUT_ARGS("cluster-status", "pe_working_set_t *", "crm_exit_t", "stonith_history_t *",
"gboolean", "uint32_t", "uint32_t", "const char *", "GList *", "GList *")
int
pcmk__cluster_status_text(pcmk__output_t *out, va_list args)
{
pe_working_set_t *data_set = va_arg(args, pe_working_set_t *);
crm_exit_t history_rc = va_arg(args, crm_exit_t);
stonith_history_t *stonith_history = va_arg(args, stonith_history_t *);
gboolean fence_history = va_arg(args, gboolean);
uint32_t section_opts = va_arg(args, uint32_t);
uint32_t show_opts = va_arg(args, uint32_t);
const char *prefix = va_arg(args, const char *);
GList *unames = va_arg(args, GList *);
GList *resources = va_arg(args, GList *);
int rc = pcmk_rc_no_output;
bool already_printed_failure = false;
CHECK_RC(rc, out->message(out, "cluster-summary", data_set,
section_opts, show_opts));
if (pcmk_is_set(section_opts, pcmk_section_nodes) && unames) {
CHECK_RC(rc, out->message(out, "node-list", data_set->nodes, unames,
resources, show_opts, rc == pcmk_rc_ok));
}
/* Print resources section, if needed */
if (pcmk_is_set(section_opts, pcmk_section_resources)) {
CHECK_RC(rc, out->message(out, "resource-list", data_set, show_opts,
TRUE, unames, resources, rc == pcmk_rc_ok));
}
/* print Node Attributes section if requested */
if (pcmk_is_set(section_opts, pcmk_section_attributes)) {
CHECK_RC(rc, out->message(out, "node-attribute-list", data_set,
show_opts, rc == pcmk_rc_ok, unames, resources));
}
/* If requested, print resource operations (which includes failcounts)
* or just failcounts
*/
if (pcmk_any_flags_set(section_opts, pcmk_section_operations | pcmk_section_failcounts)) {
CHECK_RC(rc, out->message(out, "node-summary", data_set, unames,
resources, section_opts, show_opts, rc == pcmk_rc_ok));
}
/* If there were any failed actions, print them */
if (pcmk_is_set(section_opts, pcmk_section_failures)
&& xml_has_children(data_set->failed)) {
CHECK_RC(rc, out->message(out, "failed-action-list", data_set, unames,
resources, show_opts, rc == pcmk_rc_ok));
}
/* Print failed stonith actions */
if (pcmk_is_set(section_opts, pcmk_section_fence_failed) && fence_history) {
if (history_rc == 0) {
stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_eq,
GINT_TO_POINTER(st_failed));
if (hp) {
CHECK_RC(rc, out->message(out, "failed-fencing-list",
stonith_history, unames, section_opts,
show_opts, rc == pcmk_rc_ok));
}
} else {
PCMK__OUTPUT_SPACER_IF(out, rc == pcmk_rc_ok);
out->begin_list(out, NULL, NULL, "Failed Fencing Actions");
out->list_item(out, NULL, "Failed to get fencing history: %s",
crm_exit_str(history_rc));
out->end_list(out);
already_printed_failure = true;
}
}
/* Print tickets if requested */
if (pcmk_is_set(section_opts, pcmk_section_tickets)) {
CHECK_RC(rc, out->message(out, "ticket-list", data_set, rc == pcmk_rc_ok));
}
/* Print negative location constraints if requested */
if (pcmk_is_set(section_opts, pcmk_section_bans)) {
CHECK_RC(rc, out->message(out, "ban-list", data_set, prefix, resources,
show_opts, rc == pcmk_rc_ok));
}
/* Print stonith history */
if (fence_history && pcmk_any_flags_set(section_opts, pcmk_section_fencing_all)) {
if (history_rc != 0) {
if (!already_printed_failure) {
PCMK__OUTPUT_SPACER_IF(out, rc == pcmk_rc_ok);
out->begin_list(out, NULL, NULL, "Failed Fencing Actions");
out->list_item(out, NULL, "Failed to get fencing history: %s",
crm_exit_str(history_rc));
out->end_list(out);
}
} else if (pcmk_is_set(section_opts, pcmk_section_fence_worked)) {
stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_neq,
GINT_TO_POINTER(st_failed));
if (hp) {
CHECK_RC(rc, out->message(out, "fencing-list", hp, unames,
section_opts, show_opts,
rc == pcmk_rc_ok));
}
} else if (pcmk_is_set(section_opts, pcmk_section_fence_pending)) {
stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_pending, NULL);
if (hp) {
CHECK_RC(rc, out->message(out, "pending-fencing-list", hp,
unames, section_opts, show_opts,
rc == pcmk_rc_ok));
}
}
}
return rc;
}
PCMK__OUTPUT_ARGS("cluster-status", "pe_working_set_t *", "crm_exit_t", "stonith_history_t *",
"gboolean", "uint32_t", "uint32_t", "const char *", "GList *", "GList *")
static int
cluster_status_xml(pcmk__output_t *out, va_list args)
{
pe_working_set_t *data_set = va_arg(args, pe_working_set_t *);
crm_exit_t history_rc = va_arg(args, crm_exit_t);
stonith_history_t *stonith_history = va_arg(args, stonith_history_t *);
gboolean fence_history = va_arg(args, gboolean);
uint32_t section_opts = va_arg(args, uint32_t);
uint32_t show_opts = va_arg(args, uint32_t);
const char *prefix = va_arg(args, const char *);
GList *unames = va_arg(args, GList *);
GList *resources = va_arg(args, GList *);
out->message(out, "cluster-summary", data_set, section_opts, show_opts);
/*** NODES ***/
if (pcmk_is_set(section_opts, pcmk_section_nodes)) {
out->message(out, "node-list", data_set->nodes, unames, resources,
show_opts, FALSE);
}
/* Print resources section, if needed */
if (pcmk_is_set(section_opts, pcmk_section_resources)) {
/* XML output always displays full details. */
uint32_t full_show_opts = show_opts & ~pcmk_show_brief;
out->message(out, "resource-list", data_set, full_show_opts,
FALSE, unames, resources, FALSE);
}
/* print Node Attributes section if requested */
if (pcmk_is_set(section_opts, pcmk_section_attributes)) {
out->message(out, "node-attribute-list", data_set, show_opts, FALSE,
unames, resources);
}
/* If requested, print resource operations (which includes failcounts)
* or just failcounts
*/
if (pcmk_any_flags_set(section_opts, pcmk_section_operations | pcmk_section_failcounts)) {
out->message(out, "node-summary", data_set, unames,
resources, section_opts, show_opts, FALSE);
}
/* If there were any failed actions, print them */
if (pcmk_is_set(section_opts, pcmk_section_failures)
&& xml_has_children(data_set->failed)) {
out->message(out, "failed-action-list", data_set, unames, resources,
show_opts, FALSE);
}
/* Print stonith history */
if (pcmk_is_set(section_opts, pcmk_section_fencing_all) && fence_history) {
out->message(out, "full-fencing-list", history_rc, stonith_history,
unames, section_opts, show_opts, FALSE);
}
/* Print tickets if requested */
if (pcmk_is_set(section_opts, pcmk_section_tickets)) {
out->message(out, "ticket-list", data_set, FALSE);
}
/* Print negative location constraints if requested */
if (pcmk_is_set(section_opts, pcmk_section_bans)) {
out->message(out, "ban-list", data_set, prefix, resources, show_opts,
FALSE);
}
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("cluster-status", "pe_working_set_t *", "crm_exit_t", "stonith_history_t *",
"gboolean", "uint32_t", "uint32_t", "const char *", "GList *",
"GList *")
static int
cluster_status_html(pcmk__output_t *out, va_list args)
{
pe_working_set_t *data_set = va_arg(args, pe_working_set_t *);
crm_exit_t history_rc = va_arg(args, crm_exit_t);
stonith_history_t *stonith_history = va_arg(args, stonith_history_t *);
gboolean fence_history = va_arg(args, gboolean);
uint32_t section_opts = va_arg(args, uint32_t);
uint32_t show_opts = va_arg(args, uint32_t);
const char *prefix = va_arg(args, const char *);
GList *unames = va_arg(args, GList *);
GList *resources = va_arg(args, GList *);
bool already_printed_failure = false;
out->message(out, "cluster-summary", data_set, section_opts, show_opts);
/*** NODE LIST ***/
if (pcmk_is_set(section_opts, pcmk_section_nodes) && unames) {
out->message(out, "node-list", data_set->nodes, unames, resources,
show_opts, FALSE);
}
/* Print resources section, if needed */
if (pcmk_is_set(section_opts, pcmk_section_resources)) {
out->message(out, "resource-list", data_set, show_opts, TRUE, unames,
resources, FALSE);
}
/* print Node Attributes section if requested */
if (pcmk_is_set(section_opts, pcmk_section_attributes)) {
out->message(out, "node-attribute-list", data_set, show_opts, FALSE,
unames, resources);
}
/* If requested, print resource operations (which includes failcounts)
* or just failcounts
*/
if (pcmk_any_flags_set(section_opts, pcmk_section_operations | pcmk_section_failcounts)) {
out->message(out, "node-summary", data_set, unames,
resources, section_opts, show_opts, FALSE);
}
/* If there were any failed actions, print them */
if (pcmk_is_set(section_opts, pcmk_section_failures)
&& xml_has_children(data_set->failed)) {
out->message(out, "failed-action-list", data_set, unames, resources,
show_opts, FALSE);
}
/* Print failed stonith actions */
if (pcmk_is_set(section_opts, pcmk_section_fence_failed) && fence_history) {
if (history_rc == 0) {
stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_eq,
GINT_TO_POINTER(st_failed));
if (hp) {
out->message(out, "failed-fencing-list", stonith_history, unames,
section_opts, show_opts, FALSE);
}
} else {
out->begin_list(out, NULL, NULL, "Failed Fencing Actions");
out->list_item(out, NULL, "Failed to get fencing history: %s",
crm_exit_str(history_rc));
out->end_list(out);
}
}
/* Print stonith history */
if (fence_history && pcmk_any_flags_set(section_opts, pcmk_section_fencing_all)) {
if (history_rc != 0) {
if (!already_printed_failure) {
out->begin_list(out, NULL, NULL, "Failed Fencing Actions");
out->list_item(out, NULL, "Failed to get fencing history: %s",
crm_exit_str(history_rc));
out->end_list(out);
}
} else if (pcmk_is_set(section_opts, pcmk_section_fence_worked)) {
stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_neq,
GINT_TO_POINTER(st_failed));
if (hp) {
out->message(out, "fencing-list", hp, unames, section_opts,
show_opts, FALSE);
}
} else if (pcmk_is_set(section_opts, pcmk_section_fence_pending)) {
stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_pending, NULL);
if (hp) {
out->message(out, "pending-fencing-list", hp, unames,
section_opts, show_opts, FALSE);
}
}
}
/* Print tickets if requested */
if (pcmk_is_set(section_opts, pcmk_section_tickets)) {
out->message(out, "ticket-list", data_set, FALSE);
}
/* Print negative location constraints if requested */
if (pcmk_is_set(section_opts, pcmk_section_bans)) {
out->message(out, "ban-list", data_set, prefix, resources, show_opts,
FALSE);
}
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("attribute", "char *", "char *", "char *", "char *")
static int
attribute_default(pcmk__output_t *out, va_list args)
{
char *scope = va_arg(args, char *);
char *instance = va_arg(args, char *);
char *name = va_arg(args, char *);
char *value = va_arg(args, char *);
char *host = va_arg(args, char *);
GString *s = g_string_sized_new(50);
if (!pcmk__str_empty(scope)) {
g_string_append_printf(s, "scope=\"%s\" ", scope);
}
if (!pcmk__str_empty(instance)) {
g_string_append_printf(s, "id=\"%s\" ", instance);
}
g_string_append_printf(s, "name=\"%s\" ", name);
if (!pcmk__str_empty(host)) {
g_string_append_printf(s, "host=\"%s\" ", host);
}
g_string_append_printf(s, "value=\"%s\"", value ? value : "");
out->info(out, "%s", s->str);
g_string_free(s, TRUE);
return pcmk_rc_ok;
}
PCMK__OUTPUT_ARGS("attribute", "char *", "char *", "char *", "char *")
static int
attribute_xml(pcmk__output_t *out, va_list args)
{
char *scope = va_arg(args, char *);
char *instance = va_arg(args, char *);
char *name = va_arg(args, char *);
char *value = va_arg(args, char *);
char *host = va_arg(args, char *);
xmlNodePtr node = NULL;
node = pcmk__output_create_xml_node(out, "attribute",
"name", name,
"value", value ? value : "",
NULL);
if (!pcmk__str_empty(scope)) {
crm_xml_add(node, "scope", scope);
}
if (!pcmk__str_empty(instance)) {
crm_xml_add(node, "id", instance);
}
if (!pcmk__str_empty(host)) {
crm_xml_add(node, "host", host);
}
return pcmk_rc_ok;
}
+PCMK__OUTPUT_ARGS("rule-check", "const char *", "int", "const char *")
+static int
+rule_check_default(pcmk__output_t *out, va_list args)
+{
+ const char *rule_id = va_arg(args, const char *);
+ int result = va_arg(args, int);
+ const char *error = va_arg(args, const char *);
+
+ switch (result) {
+ case pcmk_rc_within_range:
+ return out->info(out, "Rule %s is still in effect", rule_id);
+ case pcmk_rc_ok:
+ return out->info(out, "Rule %s satisfies conditions", rule_id);
+ case pcmk_rc_after_range:
+ return out->info(out, "Rule %s is expired", rule_id);
+ case pcmk_rc_before_range:
+ return out->info(out, "Rule %s has not yet taken effect", rule_id);
+ case pcmk_rc_op_unsatisfied:
+ return out->info(out, "Rule %s does not satisfy conditions",
+ rule_id);
+ default:
+ out->err(out,
+ "Could not determine whether rule %s is in effect: %s",
+ rule_id, ((error != NULL)? error : "unexpected error"));
+ return pcmk_rc_ok;
+ }
+}
+
+PCMK__OUTPUT_ARGS("rule-check", "const char *", "int", "const char *")
+static int
+rule_check_xml(pcmk__output_t *out, va_list args)
+{
+ const char *rule_id = va_arg(args, const char *);
+ int result = va_arg(args, int);
+ const char *error = va_arg(args, const char *);
+
+ char *rc_str = pcmk__itoa(pcmk_rc2exitc(result));
+
+ pcmk__output_create_xml_node(out, "rule-check",
+ "rule-id", rule_id,
+ "rc", rc_str,
+ NULL);
+ free(rc_str);
+
+ switch (result) {
+ case pcmk_rc_within_range:
+ case pcmk_rc_ok:
+ case pcmk_rc_after_range:
+ case pcmk_rc_before_range:
+ case pcmk_rc_op_unsatisfied:
+ return pcmk_rc_ok;
+ default:
+ out->err(out,
+ "Could not determine whether rule %s is in effect: %s",
+ rule_id, ((error != NULL)? error : "unexpected error"));
+ return pcmk_rc_ok;
+ }
+}
+
static pcmk__message_entry_t fmt_functions[] = {
{ "attribute", "default", attribute_default },
{ "attribute", "xml", attribute_xml },
{ "cluster-status", "default", pcmk__cluster_status_text },
{ "cluster-status", "html", cluster_status_html },
{ "cluster-status", "xml", cluster_status_xml },
{ "crmadmin-node", "default", crmadmin_node_text },
{ "crmadmin-node", "xml", crmadmin_node_xml },
{ "dc", "default", dc_text },
{ "dc", "xml", dc_xml },
{ "digests", "default", digests_text },
{ "digests", "xml", digests_xml },
{ "health", "default", health_text },
{ "health", "xml", health_xml },
{ "inject-attr", "default", inject_attr },
{ "inject-attr", "xml", inject_attr_xml },
{ "inject-cluster-action", "default", inject_cluster_action },
{ "inject-cluster-action", "xml", inject_cluster_action_xml },
{ "inject-fencing-action", "default", inject_fencing_action },
{ "inject-fencing-action", "xml", inject_fencing_action_xml },
{ "inject-modify-config", "default", inject_modify_config },
{ "inject-modify-config", "xml", inject_modify_config_xml },
{ "inject-modify-node", "default", inject_modify_node },
{ "inject-modify-node", "xml", inject_modify_node_xml },
{ "inject-modify-ticket", "default", inject_modify_ticket },
{ "inject-modify-ticket", "xml", inject_modify_ticket_xml },
{ "inject-pseudo-action", "default", inject_pseudo_action },
{ "inject-pseudo-action", "xml", inject_pseudo_action_xml },
{ "inject-rsc-action", "default", inject_rsc_action },
{ "inject-rsc-action", "xml", inject_rsc_action_xml },
{ "inject-spec", "default", inject_spec },
{ "inject-spec", "xml", inject_spec_xml },
{ "locations-list", "default", locations_list },
{ "locations-list", "xml", locations_list_xml },
{ "node-action", "default", node_action },
{ "node-action", "xml", node_action_xml },
{ "pacemakerd-health", "default", pacemakerd_health_text },
{ "pacemakerd-health", "xml", pacemakerd_health_xml },
{ "profile", "default", profile_default, },
{ "profile", "xml", profile_xml },
{ "rsc-action", "default", rsc_action_default },
{ "rsc-action-item", "default", rsc_action_item },
{ "rsc-action-item", "xml", rsc_action_item_xml },
{ "rsc-is-colocated-with-list", "default", rsc_is_colocated_with_list },
{ "rsc-is-colocated-with-list", "xml", rsc_is_colocated_with_list_xml },
{ "rscs-colocated-with-list", "default", rscs_colocated_with_list },
{ "rscs-colocated-with-list", "xml", rscs_colocated_with_list_xml },
+ { "rule-check", "default", rule_check_default },
+ { "rule-check", "xml", rule_check_xml },
{ "stacks-constraints", "default", stacks_and_constraints },
{ "stacks-constraints", "xml", stacks_and_constraints_xml },
{ NULL, NULL, NULL }
};
void
pcmk__register_lib_messages(pcmk__output_t *out) {
pcmk__register_messages(out, fmt_functions);
}
diff --git a/lib/pacemaker/pcmk_rule.c b/lib/pacemaker/pcmk_rule.c
new file mode 100644
index 0000000000..ebf9488d4f
--- /dev/null
+++ b/lib/pacemaker/pcmk_rule.c
@@ -0,0 +1,296 @@
+/*
+ * Copyright 2022 the Pacemaker project contributors
+ *
+ * The version control history for this file may have further details.
+ *
+ * This source code is licensed under the GNU Lesser General Public License
+ * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
+ */
+
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+/*!
+ * \internal
+ * \brief Evaluate a date expression for a specific time
+ *
+ * \param[in] expr date_expression XML
+ * \param[in] now Time for which to evaluate expression
+ *
+ * \return Standard Pacemaker return code
+ */
+static int
+eval_date_expression(xmlNodePtr expr, crm_time_t *now)
+{
+ pe_rule_eval_data_t rule_data = {
+ .node_hash = NULL,
+ .role = RSC_ROLE_UNKNOWN,
+ .now = now,
+ .match_data = NULL,
+ .rsc_data = NULL,
+ .op_data = NULL
+ };
+
+ return pe__eval_date_expr(expr, &rule_data, NULL);
+}
+
+/*!
+ * \internal
+ * \brief Initialize the cluster working set for checking rules
+ *
+ * Make our own copies of the CIB XML and date/time object, if they're not
+ * \c NULL. This way we don't have to take ownership of the objects passed via
+ * the API.
+ *
+ * \param[in,out] out Output object
+ * \param[in] input The CIB XML to check (if \c NULL, use current CIB)
+ * \param[in] date Check whether the rule is in effect at this date
+ * and time (if \c NULL, use current date and time)
+ * \param[out] data_set Where to store the cluster working set
+ *
+ * \return Standard Pacemaker return code
+ */
+static int
+init_rule_check(pcmk__output_t *out, xmlNodePtr input, const crm_time_t *date,
+ pe_working_set_t **data_set)
+{
+ // Allows for cleaner syntax than dereferencing the data_set argument
+ pe_working_set_t *new_data_set = NULL;
+
+ new_data_set = pe_new_working_set();
+ if (new_data_set == NULL) {
+ return ENOMEM;
+ }
+
+ pe__set_working_set_flags(new_data_set,
+ pe_flag_no_counts|pe_flag_no_compat);
+
+ // Populate the working set instance
+
+ // Make our own copy of the given input or fetch the CIB and use that
+ if (input != NULL) {
+ new_data_set->input = copy_xml(input);
+ if (new_data_set->input == NULL) {
+ out->err(out, "Failed to copy input XML");
+ pe_free_working_set(new_data_set);
+ return ENOMEM;
+ }
+
+ } else {
+ int rc = cib__signon_query(NULL, &(new_data_set->input));
+
+ if (rc != pcmk_rc_ok) {
+ out->err(out, "CIB query failed: %s", pcmk_rc_str(rc));
+ pe_free_working_set(new_data_set);
+ return rc;
+ }
+ }
+
+ // Make our own copy of the given crm_time_t object; otherwise
+ // cluster_status() populates with the current time
+ if (date != NULL) {
+ // pcmk_copy_time() guarantees non-NULL
+ new_data_set->now = pcmk_copy_time(date);
+ }
+
+ // Unpack everything
+ cluster_status(new_data_set);
+ *data_set = new_data_set;
+
+ return pcmk_rc_ok;
+}
+
+#define XPATH_NODE_RULE "//" XML_TAG_RULE "[@" XML_ATTR_ID "='%s']"
+
+/*!
+ * \internal
+ * \brief Check whether a given rule is in effect
+ *
+ * \param[in] data_set Cluster working set
+ * \param[in] rule_id The ID of the rule to check
+ * \param[out] error Where to store a rule evaluation error message
+ *
+ * \return Standard Pacemaker return code
+ */
+static int
+eval_rule(pe_working_set_t *data_set, const char *rule_id, const char **error)
+{
+ xmlNodePtr cib_constraints = NULL;
+ xmlNodePtr match = NULL;
+ xmlXPathObjectPtr xpath_obj = NULL;
+ char *xpath = NULL;
+ int rc = pcmk_rc_ok;
+ int num_results = 0;
+
+ *error = NULL;
+
+ /* Rules are under the constraints node in the XML, so first find that. */
+ cib_constraints = pcmk_find_cib_element(data_set->input,
+ XML_CIB_TAG_CONSTRAINTS);
+
+ /* Get all rules matching the given ID that are also simple enough for us
+ * to check. For the moment, these rules must only have a single
+ * date_expression child and:
+ * - Do not have a date_spec operation, or
+ * - Have a date_spec operation that contains years= but does not contain
+ * moon=.
+ *
+ * We do this in steps to provide better error messages. First, check that
+ * there's any rule with the given ID.
+ */
+ xpath = crm_strdup_printf(XPATH_NODE_RULE, rule_id);
+ xpath_obj = xpath_search(cib_constraints, xpath);
+ num_results = numXpathResults(xpath_obj);
+
+ free(xpath);
+ freeXpathObject(xpath_obj);
+
+ if (num_results == 0) {
+ *error = "Rule not found";
+ return ENXIO;
+ }
+
+ if (num_results > 1) {
+ // Should not be possible; schema prevents this
+ *error = "Found more than one rule with matching ID";
+ return pcmk_rc_duplicate_id;
+ }
+
+ /* Next, make sure it has exactly one date_expression. */
+ xpath = crm_strdup_printf(XPATH_NODE_RULE "//date_expression", rule_id);
+ xpath_obj = xpath_search(cib_constraints, xpath);
+ num_results = numXpathResults(xpath_obj);
+
+ free(xpath);
+ freeXpathObject(xpath_obj);
+
+ if (num_results != 1) {
+ if (num_results == 0) {
+ *error = "Rule does not have a date expression";
+ } else {
+ *error = "Rule has more than one date expression";
+ }
+ return EOPNOTSUPP;
+ }
+
+ /* Then, check that it's something we actually support. */
+ xpath = crm_strdup_printf(XPATH_NODE_RULE "//date_expression["
+ "@" XML_EXPR_ATTR_OPERATION "!='date_spec']",
+ rule_id);
+ xpath_obj = xpath_search(cib_constraints, xpath);
+ num_results = numXpathResults(xpath_obj);
+
+ free(xpath);
+
+ if (num_results == 0) {
+ freeXpathObject(xpath_obj);
+
+ xpath = crm_strdup_printf(XPATH_NODE_RULE "//date_expression["
+ "@" XML_EXPR_ATTR_OPERATION "='date_spec' "
+ "and date_spec/@years "
+ "and not(date_spec/@moon)]", rule_id);
+ xpath_obj = xpath_search(cib_constraints, xpath);
+ num_results = numXpathResults(xpath_obj);
+
+ free(xpath);
+
+ if (num_results == 0) {
+ freeXpathObject(xpath_obj);
+ *error = "Rule must either not use date_spec, or use date_spec "
+ "with years= but not moon=";
+ return EOPNOTSUPP;
+ }
+ }
+
+ match = getXpathResult(xpath_obj, 0);
+
+ /* We should have ensured this with the xpath query above, but double-
+ * checking can't hurt.
+ */
+ CRM_ASSERT(match != NULL);
+ CRM_ASSERT(find_expression_type(match) == time_expr);
+
+ rc = eval_date_expression(match, data_set->now);
+ if (rc == pcmk_rc_undetermined) {
+ /* pe__eval_date_expr() should return this only if something is
+ * malformed or missing
+ */
+ *error = "Error parsing rule";
+ }
+
+ freeXpathObject(xpath_obj);
+ return rc;
+}
+
+/*!
+ * \internal
+ * \brief Check whether each rule in a list is in effect
+ *
+ * \param[in,out] out Output object
+ * \param[in] input The CIB XML to check (if \c NULL, use current CIB)
+ * \param[in] date Check whether the rule is in effect at this date and
+ * time (if \c NULL, use current date and time)
+ * \param[in] rule_ids The IDs of the rules to check, as a NULL-
+ * terminated list.
+ *
+ * \return Standard Pacemaker return code
+ */
+int
+pcmk__check_rules(pcmk__output_t *out, xmlNodePtr input, const crm_time_t *date,
+ const char **rule_ids)
+{
+ pe_working_set_t *data_set = NULL;
+ int rc = pcmk_rc_ok;
+
+ CRM_ASSERT(out != NULL);
+
+ if (rule_ids == NULL) {
+ // Trivial case; every rule specified is in effect
+ return pcmk_rc_ok;
+ }
+
+ rc = init_rule_check(out, input, date, &data_set);
+ if (rc != pcmk_rc_ok) {
+ return rc;
+ }
+
+ for (const char **rule_id = rule_ids; *rule_id != NULL; rule_id++) {
+ const char *error = NULL;
+ int last_rc = eval_rule(data_set, *rule_id, &error);
+
+ out->message(out, "rule-check", *rule_id, last_rc, error);
+
+ if (last_rc != pcmk_rc_ok) {
+ rc = last_rc;
+ }
+ }
+
+ pe_free_working_set(data_set);
+ return rc;
+}
+
+// Documented in pacemaker.h
+int
+pcmk_check_rules(xmlNodePtr *xml, xmlNodePtr input, const crm_time_t *date,
+ const char **rule_ids)
+{
+ pcmk__output_t *out = NULL;
+ int rc = pcmk_rc_ok;
+
+ rc = pcmk__xml_output_new(&out, xml);
+ if (rc != pcmk_rc_ok) {
+ return rc;
+ }
+
+ pcmk__register_lib_messages(out);
+
+ rc = pcmk__check_rules(out, input, date, rule_ids);
+ pcmk__xml_output_finish(out, xml);
+ return rc;
+}
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 654009fefb..075cbc0caf 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,177 +1,178 @@
#
# Copyright 2004-2022 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# or later (GPLv2+) WITHOUT ANY WARRANTY.
#
include $(top_srcdir)/mk/common.mk
include $(top_srcdir)/mk/man.mk
if BUILD_SYSTEMD
systemdsystemunit_DATA = crm_mon.service
endif
noinst_HEADERS = crm_mon.h crm_resource.h
pcmkdir = $(datadir)/$(PACKAGE)
pcmk_DATA = report.common report.collector
sbin_SCRIPTS = crm_report crm_standby crm_master crm_failcount
if BUILD_CIBSECRETS
sbin_SCRIPTS += cibsecret
endif
noinst_SCRIPTS = pcmk_simtimes
EXTRA_DIST = attrd_updater.8.inc \
crm_attribute.8.inc \
crm_diff.8.inc \
crm_error.8.inc \
crm_mon.8.inc \
crm_node.8.inc \
crm_resource.8.inc \
crm_rule.8.inc \
crm_simulate.8.inc \
crm_ticket.8.inc \
crm_verify.8.inc \
crmadmin.8.inc \
fix-manpages \
iso8601.8.inc \
stonith_admin.8.inc
sbin_PROGRAMS = attrd_updater \
cibadmin \
crmadmin \
crm_simulate \
crm_attribute \
crm_diff \
crm_error \
crm_mon \
crm_node \
crm_resource \
crm_rule \
crm_shadow \
crm_verify \
crm_ticket \
iso8601 \
stonith_admin
if BUILD_SERVICELOG
sbin_PROGRAMS += notifyServicelogEvent
endif
if BUILD_OPENIPMI_SERVICELOG
sbin_PROGRAMS += ipmiservicelogd
endif
## SOURCES
# A few tools are just thin wrappers around crm_attribute.
# This makes their help get updated when crm_attribute changes
# (see mk/common.mk).
MAN8DEPS = crm_attribute
crmadmin_SOURCES = crmadmin.c
crmadmin_LDADD = $(top_builddir)/lib/pengine/libpe_status.la \
$(top_builddir)/lib/cib/libcib.la \
$(top_builddir)/lib/common/libcrmcommon.la \
$(top_builddir)/lib/pacemaker/libpacemaker.la
crm_error_SOURCES = crm_error.c
crm_error_LDADD = $(top_builddir)/lib/common/libcrmcommon.la
cibadmin_SOURCES = cibadmin.c
cibadmin_LDADD = $(top_builddir)/lib/pacemaker/libpacemaker.la \
$(top_builddir)/lib/cib/libcib.la \
$(top_builddir)/lib/common/libcrmcommon.la
crm_shadow_SOURCES = crm_shadow.c
crm_shadow_LDADD = $(top_builddir)/lib/cib/libcib.la \
$(top_builddir)/lib/common/libcrmcommon.la
crm_node_SOURCES = crm_node.c
crm_node_LDADD = $(top_builddir)/lib/cib/libcib.la \
$(top_builddir)/lib/common/libcrmcommon.la
crm_simulate_SOURCES = crm_simulate.c
crm_simulate_LDADD = $(top_builddir)/lib/pengine/libpe_status.la \
$(top_builddir)/lib/pacemaker/libpacemaker.la \
$(top_builddir)/lib/cib/libcib.la \
$(top_builddir)/lib/common/libcrmcommon.la
crm_diff_SOURCES = crm_diff.c
crm_diff_LDADD = $(top_builddir)/lib/common/libcrmcommon.la
crm_mon_SOURCES = crm_mon.c crm_mon_curses.c
crm_mon_LDADD = $(top_builddir)/lib/pengine/libpe_status.la \
$(top_builddir)/lib/fencing/libstonithd.la \
$(top_builddir)/lib/pacemaker/libpacemaker.la \
$(top_builddir)/lib/cib/libcib.la \
$(top_builddir)/lib/common/libcrmcommon.la \
$(CURSESLIBS)
crm_verify_SOURCES = crm_verify.c
crm_verify_LDADD = $(top_builddir)/lib/pengine/libpe_status.la \
$(top_builddir)/lib/pacemaker/libpacemaker.la \
$(top_builddir)/lib/cib/libcib.la \
$(top_builddir)/lib/common/libcrmcommon.la
crm_attribute_SOURCES = crm_attribute.c
crm_attribute_LDADD = $(top_builddir)/lib/pacemaker/libpacemaker.la \
$(top_builddir)/lib/cib/libcib.la \
$(top_builddir)/lib/common/libcrmcommon.la
crm_resource_SOURCES = crm_resource.c \
crm_resource_ban.c \
crm_resource_print.c \
crm_resource_runtime.c
crm_resource_LDADD = $(top_builddir)/lib/pengine/libpe_rules.la \
$(top_builddir)/lib/fencing/libstonithd.la \
$(top_builddir)/lib/lrmd/liblrmd.la \
$(top_builddir)/lib/services/libcrmservice.la \
$(top_builddir)/lib/pengine/libpe_status.la \
$(top_builddir)/lib/pacemaker/libpacemaker.la \
$(top_builddir)/lib/cib/libcib.la \
$(top_builddir)/lib/common/libcrmcommon.la
crm_rule_SOURCES = crm_rule.c
-crm_rule_LDADD = $(top_builddir)/lib/cib/libcib.la \
+crm_rule_LDADD = $(top_builddir)/lib/pacemaker/libpacemaker.la \
+ $(top_builddir)/lib/cib/libcib.la \
$(top_builddir)/lib/pengine/libpe_rules.la \
$(top_builddir)/lib/pengine/libpe_status.la \
$(top_builddir)/lib/common/libcrmcommon.la
iso8601_SOURCES = iso8601.c
iso8601_LDADD = $(top_builddir)/lib/common/libcrmcommon.la
attrd_updater_SOURCES = attrd_updater.c
attrd_updater_LDADD = $(top_builddir)/lib/pacemaker/libpacemaker.la \
$(top_builddir)/lib/common/libcrmcommon.la
crm_ticket_SOURCES = crm_ticket.c
crm_ticket_LDADD = $(top_builddir)/lib/pengine/libpe_rules.la \
$(top_builddir)/lib/pengine/libpe_status.la \
$(top_builddir)/lib/pacemaker/libpacemaker.la \
$(top_builddir)/lib/cib/libcib.la \
$(top_builddir)/lib/common/libcrmcommon.la
stonith_admin_SOURCES = stonith_admin.c
stonith_admin_LDADD = $(top_builddir)/lib/pacemaker/libpacemaker.la \
$(top_builddir)/lib/cib/libcib.la \
$(top_builddir)/lib/pengine/libpe_status.la \
$(top_builddir)/lib/fencing/libstonithd.la \
$(top_builddir)/lib/common/libcrmcommon.la
if BUILD_SERVICELOG
notifyServicelogEvent_SOURCES = notifyServicelogEvent.c
notifyServicelogEvent_CFLAGS = $(SERVICELOG_CFLAGS)
notifyServicelogEvent_LDADD = $(top_builddir)/lib/common/libcrmcommon.la $(SERVICELOG_LIBS)
endif
if BUILD_OPENIPMI_SERVICELOG
ipmiservicelogd_SOURCES = ipmiservicelogd.c
ipmiservicelogd_CFLAGS = $(OPENIPMI_SERVICELOG_CFLAGS) $(SERVICELOG_CFLAGS)
ipmiservicelogd_LDFLAGS = $(top_builddir)/lib/common/libcrmcommon.la $(OPENIPMI_SERVICELOG_LIBS) $(SERVICELOG_LIBS)
endif
CLEANFILES = $(man8_MANS)
diff --git a/tools/crm_rule.c b/tools/crm_rule.c
index 1d117b88b5..1ce3743fae 100644
--- a/tools/crm_rule.c
+++ b/tools/crm_rule.c
@@ -1,423 +1,226 @@
/*
* Copyright 2019-2022 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU General Public License version 2
* or later (GPLv2+) WITHOUT ANY WARRANTY.
*/
#include
-#include
-#include
#include
#include
#include
#include
#include
#include
#include
#include
#define SUMMARY "evaluate rules from the Pacemaker configuration"
-GError *error = NULL;
-
static pcmk__supported_format_t formats[] = {
PCMK__SUPPORTED_FORMAT_NONE,
PCMK__SUPPORTED_FORMAT_TEXT,
PCMK__SUPPORTED_FORMAT_XML,
{ NULL, NULL, NULL }
};
enum crm_rule_mode {
crm_rule_mode_none,
crm_rule_mode_check
};
struct {
char *date;
char *input_xml;
enum crm_rule_mode mode;
gchar **rules;
} options = {
.mode = crm_rule_mode_none
};
-static int crm_rule_check(pcmk__output_t *out, pe_working_set_t *data_set,
- const char *rule_id, crm_time_t *effective_date);
-
static gboolean mode_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **error);
static GOptionEntry mode_entries[] = {
{ "check", 'c', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, mode_cb,
"Check whether a rule is in effect",
NULL },
{ NULL }
};
static GOptionEntry data_entries[] = {
{ "xml-text", 'X', 0, G_OPTION_ARG_STRING, &options.input_xml,
"Use argument for XML (or stdin if '-')",
NULL },
{ NULL }
};
static GOptionEntry addl_entries[] = {
{ "date", 'd', 0, G_OPTION_ARG_STRING, &options.date,
"Whether the rule is in effect on a given date",
NULL },
{ "rule", 'r', 0, G_OPTION_ARG_STRING_ARRAY, &options.rules,
"The ID of the rule to check (may be specified multiple times)",
NULL },
{ NULL }
};
static gboolean
mode_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **error) {
if (strcmp(option_name, "c")) {
options.mode = crm_rule_mode_check;
}
return TRUE;
}
-/*!
- * \internal
- * \brief Evaluate a date expression for a specific time
- *
- * \param[in] time_expr date_expression XML
- * \param[in] now Time for which to evaluate expression
- * \param[out] next_change If not NULL, set to when evaluation will change
- *
- * \return Standard Pacemaker return code
- */
-static int
-eval_date_expression(xmlNode *expr, crm_time_t *now, crm_time_t *next_change)
-{
- pe_rule_eval_data_t rule_data = {
- .node_hash = NULL,
- .role = RSC_ROLE_UNKNOWN,
- .now = now,
- .match_data = NULL,
- .rsc_data = NULL,
- .op_data = NULL
- };
-
- return pe__eval_date_expr(expr, &rule_data, next_change);
-}
-
-PCMK__OUTPUT_ARGS("rule-check", "const char *", "int")
-static int
-rule_check_default(pcmk__output_t *out, va_list args)
-{
- const char *rule_id = va_arg(args, const char *);
- int result = va_arg(args, int);
-
- if (result == pcmk_rc_within_range) {
- out->info(out, "Rule %s is still in effect", rule_id);
- } else if (result == pcmk_rc_ok) {
- out->info(out, "Rule %s satisfies conditions", rule_id);
- } else if (result == pcmk_rc_after_range) {
- out->info(out, "Rule %s is expired", rule_id);
- } else if (result == pcmk_rc_before_range) {
- out->info(out, "Rule %s has not yet taken effect", rule_id);
- } else if (result == pcmk_rc_op_unsatisfied) {
- out->info(out, "Rule %s does not satisfy conditions", rule_id);
- } else {
- out->info(out, "Could not determine whether rule %s is expired", rule_id);
- }
-
- return pcmk_rc_ok;
-}
-
-PCMK__OUTPUT_ARGS("rule-check", "const char *", "int")
-static int
-rule_check_xml(pcmk__output_t *out, va_list args)
-{
- const char *rule_id = va_arg(args, const char *);
- int result = va_arg(args, int);
-
- char *rc_str = pcmk__itoa(pcmk_rc2exitc(result));
-
- pcmk__output_create_xml_node(out, "rule-check",
- "rule-id", rule_id,
- "rc", rc_str,
- NULL);
-
- free(rc_str);
-
- return pcmk_rc_ok;
-}
-
-static pcmk__message_entry_t fmt_functions[] = {
- { "rule-check", "default", rule_check_default },
- { "rule-check", "xml", rule_check_xml },
-
- { NULL, NULL, NULL }
-};
-
-static int
-crm_rule_check(pcmk__output_t *out, pe_working_set_t *data_set, const char *rule_id,
- crm_time_t *effective_date)
-{
- xmlNode *cib_constraints = NULL;
- xmlNode *match = NULL;
- xmlXPathObjectPtr xpathObj = NULL;
- char *xpath = NULL;
- int rc = pcmk_rc_ok;
- int max = 0;
-
- /* Rules are under the constraints node in the XML, so first find that. */
- cib_constraints = pcmk_find_cib_element(data_set->input,
- XML_CIB_TAG_CONSTRAINTS);
-
- /* Get all rules matching the given ID which are also simple enough for us to check.
- * For the moment, these rules must only have a single date_expression child and:
- * - Do not have a date_spec operation, or
- * - Have a date_spec operation that contains years= but does not contain moon=.
- *
- * We do this in steps to provide better error messages. First, check that there's
- * any rule with the given ID.
- */
- xpath = crm_strdup_printf("//rule[@id='%s']", rule_id);
- xpathObj = xpath_search(cib_constraints, xpath);
- max = numXpathResults(xpathObj);
-
- if (max == 0) {
- rc = ENXIO;
- g_set_error(&error, PCMK__RC_ERROR, rc, "No rule found with ID=%s", rule_id);
- goto done;
- } else if (max > 1) {
- rc = ENXIO;
- g_set_error(&error, PCMK__RC_ERROR, rc, "More than one rule with ID=%s found", rule_id);
- goto done;
- }
-
- free(xpath);
- freeXpathObject(xpathObj);
-
- /* Next, make sure it has exactly one date_expression. */
- xpath = crm_strdup_printf("//rule[@id='%s']//date_expression", rule_id);
- xpathObj = xpath_search(cib_constraints, xpath);
- max = numXpathResults(xpathObj);
-
- if (max != 1) {
- rc = EOPNOTSUPP;
- g_set_error(&error, PCMK__RC_ERROR, rc,
- "Can't check rule %s because it does not have exactly one date_expression", rule_id);
- goto done;
- }
-
- free(xpath);
- freeXpathObject(xpathObj);
-
- /* Then, check that it's something we actually support. */
- xpath = crm_strdup_printf("//rule[@id='%s']//date_expression[@operation!='date_spec']", rule_id);
- xpathObj = xpath_search(cib_constraints, xpath);
- max = numXpathResults(xpathObj);
-
- if (max == 0) {
- free(xpath);
- freeXpathObject(xpathObj);
-
- xpath = crm_strdup_printf("//rule[@id='%s']//date_expression[@operation='date_spec' and date_spec/@years and not(date_spec/@moon)]",
- rule_id);
- xpathObj = xpath_search(cib_constraints, xpath);
- max = numXpathResults(xpathObj);
-
- if (max == 0) {
- rc = ENXIO;
- g_set_error(&error, PCMK__RC_ERROR, rc,
- "Rule either must not use date_spec, or use date_spec with years= but not moon=");
- goto done;
- }
- }
-
- match = getXpathResult(xpathObj, 0);
-
- /* We should have ensured both of these pass with the xpath query above, but
- * double checking can't hurt.
- */
- CRM_ASSERT(match != NULL);
- CRM_ASSERT(find_expression_type(match) == time_expr);
-
- rc = eval_date_expression(match, effective_date, NULL);
- out->message(out, "rule-check", rule_id, rc);
-
-done:
- free(xpath);
- freeXpathObject(xpathObj);
- return rc;
-}
-
static GOptionContext *
build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) {
GOptionContext *context = NULL;
context = pcmk__build_arg_context(args, "text (default), xml", group, NULL);
pcmk__add_arg_group(context, "modes", "Modes (mutually exclusive):",
"Show modes of operation", mode_entries);
pcmk__add_arg_group(context, "data", "Data:",
"Show data options", data_entries);
pcmk__add_arg_group(context, "additional", "Additional Options:",
"Show additional options", addl_entries);
return context;
}
int
main(int argc, char **argv)
{
- pe_working_set_t *data_set = NULL;
-
crm_time_t *rule_date = NULL;
xmlNode *input = NULL;
int rc = pcmk_rc_ok;
crm_exit_t exit_code = CRM_EX_OK;
+ GError *error = NULL;
+
pcmk__output_t *out = NULL;
GOptionGroup *output_group = NULL;
pcmk__common_args_t *args = pcmk__new_common_args(SUMMARY);
GOptionContext *context = build_arg_context(args, &output_group);
gchar **processed_args = pcmk__cmdline_preproc(argv, "drX");
pcmk__register_formats(output_group, formats);
if (!g_option_context_parse_strv(context, &processed_args, &error)) {
exit_code = CRM_EX_USAGE;
goto done;
}
pcmk__cli_init_logging("crm_rule", args->verbosity);
rc = pcmk__output_new(&out, args->output_ty, args->output_dest, argv);
if (rc != pcmk_rc_ok) {
exit_code = CRM_EX_ERROR;
g_set_error(&error, PCMK__EXITC_ERROR, exit_code, "Error creating output format %s: %s",
args->output_ty, pcmk_rc_str(rc));
goto done;
}
- pcmk__register_messages(out, fmt_functions);
+ pcmk__register_lib_messages(out);
if (args->version) {
out->version(out, false);
goto done;
}
/* Check command line arguments before opening a connection to
* the CIB manager or doing anything else important.
*/
switch(options.mode) {
case crm_rule_mode_check:
if (options.rules == NULL) {
exit_code = CRM_EX_USAGE;
g_set_error(&error, PCMK__EXITC_ERROR, exit_code, "--check requires use of --rule=");
goto done;
}
break;
default:
exit_code = CRM_EX_USAGE;
g_set_error(&error, PCMK__EXITC_ERROR, exit_code, "No mode operation given");
goto done;
break;
}
/* Set up some defaults. */
rule_date = crm_time_new(options.date);
if (rule_date == NULL) {
- exit_code = CRM_EX_DATAERR;
- g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
- "No --date given and can't determine current date");
+ if (options.date != NULL) {
+ exit_code = CRM_EX_DATAERR;
+ g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
+ "Invalid date specified: '%s'", options.date);
+
+ } else {
+ // Should never happen
+ exit_code = CRM_EX_OSERR;
+ g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
+ "No --date given and can't determine current date");
+ }
goto done;
}
- /* Where does the XML come from? If one of various command line options were
- * given, use those. Otherwise, connect to the CIB and use that.
- */
+ // Parse the input XML specified by the command-line options, if any
if (pcmk__str_eq(options.input_xml, "-", pcmk__str_casei)) {
input = stdin2xml();
if (input == NULL) {
exit_code = CRM_EX_DATAERR;
g_set_error(&error, PCMK__EXITC_ERROR, exit_code, "Couldn't parse input from STDIN\n");
goto done;
}
} else if (options.input_xml != NULL) {
input = string2xml(options.input_xml);
if (input == NULL) {
exit_code = CRM_EX_DATAERR;
g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
"Couldn't parse input string: %s\n", options.input_xml);
goto done;
}
- } else {
- rc = cib__signon_query(NULL, &input);
-
- if (rc != pcmk_rc_ok) {
- exit_code = pcmk_rc2exitc(rc);
- g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
- "CIB query failed: %s", pcmk_rc_str(rc));
- goto done;
- }
}
- /* Populate the working set instance */
- data_set = pe_new_working_set();
- if (data_set == NULL) {
- exit_code = pcmk_rc2exitc(ENOMEM);
- goto done;
- }
- pe__set_working_set_flags(data_set, pe_flag_no_counts|pe_flag_no_compat);
-
- data_set->input = input;
- data_set->now = rule_date;
-
- /* Unpack everything. */
- cluster_status(data_set);
-
/* Now do whichever operation mode was asked for. There's only one at the
* moment so this looks a little silly, but I expect there will be more
* modes in the future.
*/
switch(options.mode) {
case crm_rule_mode_check:
- for (char **s = options.rules; *s != NULL; s++) {
- int last_rc = crm_rule_check(out, data_set, *s, rule_date);
-
- if (last_rc != pcmk_rc_ok) {
- rc = last_rc;
- }
- }
-
+ rc = pcmk__check_rules(out, input, rule_date,
+ (const char **) options.rules);
exit_code = pcmk_rc2exitc(rc);
break;
default:
break;
}
done:
g_strfreev(processed_args);
pcmk__free_arg_context(context);
- pe_free_working_set(data_set);
+
+ crm_time_free(rule_date);
+ free_xml(input);
pcmk__output_and_clear_error(error, out);
if (out != NULL) {
out->finish(out, exit_code, true, NULL);
pcmk__output_free(out);
}
return crm_exit(exit_code);
}