1#!@BASH_PATH@ 2# 3# Copyright 2008-2021 the Pacemaker project contributors 4# 5# The version control history for this file may have further details. 6# 7# This source code is licensed under the GNU General Public License version 2 8# or later (GPLv2+) WITHOUT ANY WARRANTY. 9# 10 11# Set the exit status of a command to the exit code of the last program to 12# exit non-zero. This is bash-specific. 13set -o pipefail 14 15# 16# Note on portable usage of sed: GNU/POSIX/*BSD sed have a limited subset of 17# compatible functionality. Do not use the -i option, alternation (\|), 18# \0, or character sequences such as \n or \s. 19# 20 21USAGE_TEXT="Usage: cts-cli [<options>] 22Options: 23 --help Display this text, then exit 24 -V, --verbose Display any differences from expected output 25 -t 'TEST [...]' Run only specified tests (default: 'dates tools crm_mon acls validity upgrade rules') 26 -p DIR Look for executables in DIR (may be specified multiple times) 27 -v, --valgrind Run all commands under valgrind 28 -s Save actual output as expected output" 29 30# If readlink supports -e (i.e. GNU), use it 31readlink -e / >/dev/null 2>/dev/null 32if [ $? -eq 0 ]; then 33 test_home="$(dirname "$(readlink -e "$0")")" 34else 35 test_home="$(dirname "$0")" 36fi 37 38: ${shadow=cts-cli} 39shadow_dir=$(mktemp -d ${TMPDIR:-/tmp}/cts-cli.shadow.XXXXXXXXXX) 40num_errors=0 41num_passed=0 42verbose=0 43tests="dates tools crm_mon acls validity upgrade rules" 44do_save=0 45XMLLINT_CMD= 46VALGRIND_CMD= 47VALGRIND_OPTS=" 48 -q 49 --gen-suppressions=all 50 --show-reachable=no 51 --leak-check=full 52 --trace-children=no 53 --time-stamp=yes 54 --num-callers=20 55 --suppressions=$test_home/valgrind-pcmk.suppressions 56" 57 58# These constants must track crm_exit_t values 59CRM_EX_OK=0 60CRM_EX_ERROR=1 61CRM_EX_INVALID_PARAM=2 62CRM_EX_UNIMPLEMENT_FEATURE=3 63CRM_EX_INSUFFICIENT_PRIV=4 64CRM_EX_USAGE=64 65CRM_EX_CONFIG=78 66CRM_EX_OLD=103 67CRM_EX_DIGEST=104 68CRM_EX_NOSUCH=105 69CRM_EX_UNSAFE=107 70CRM_EX_EXISTS=108 71CRM_EX_MULTIPLE=109 72CRM_EX_EXPIRED=110 73CRM_EX_NOT_YET_IN_EFFECT=111 74 75reset_shadow_cib_version() { 76 local SHADOWPATH 77 78 SHADOWPATH="$(crm_shadow --file)" 79 # sed -i isn't portable :-( 80 cp -p "$SHADOWPATH" "${SHADOWPATH}.$$" # preserve permissions 81 sed -e 's/epoch="[0-9]*"/epoch="1"/g' \ 82 -e 's/num_updates="[0-9]*"/num_updates="0"/g' \ 83 -e 's/admin_epoch="[0-9]*"/admin_epoch="0"/g' \ 84 "$SHADOWPATH" > "${SHADOWPATH}.$$" 85 mv -- "${SHADOWPATH}.$$" "$SHADOWPATH" 86} 87 88# A newly created empty CIB might or might not have a rsc_defaults section 89# depending on whether the --with-resource-stickiness-default configure 90# option was used. To ensure regression tests behave the same either way, 91# delete any rsc_defaults after creating or erasing a CIB. 92delete_shadow_resource_defaults() { 93 cibadmin --delete --xml-text '<rsc_defaults/>' 94 95 # The above command might or might not bump the CIB version, so reset it 96 # to ensure future changes result in the same version for comparison. 97 reset_shadow_cib_version 98} 99 100create_shadow_cib() { 101 local VALIDATE_WITH 102 local SHADOW_CMD 103 104 VALIDATE_WITH="$1" 105 106 export CIB_shadow_dir="${shadow_dir}" 107 108 SHADOW_CMD="$VALGRIND_CMD crm_shadow --batch --force --create-empty" 109 if [ -z "$VALIDATE_WITH" ]; then 110 $SHADOW_CMD "$shadow" 2>&1 111 else 112 $SHADOW_CMD "$shadow" --validate-with="${VALIDATE_WITH}" 2>&1 113 fi 114 115 export CIB_shadow="$shadow" 116 delete_shadow_resource_defaults 117} 118 119function _test_assert() { 120 target=$1; shift 121 validate=$1; shift 122 cib=$1; shift 123 app=`echo "$cmd" | sed 's/\ .*//'` 124 printf "* Running: $app - $desc\n" 1>&2 125 126 printf "=#=#=#= Begin test: $desc =#=#=#=\n" 127 128 export outfile=$(mktemp ${TMPDIR:-/tmp}/cts-cli.output.XXXXXXXXXX) 129 eval $VALGRIND_CMD $cmd 2>&1 | tee $outfile 130 rc=$? 131 132 if [ x$cib != x0 ]; then 133 printf "=#=#=#= Current cib after: $desc =#=#=#=\n" 134 CIB_user=root cibadmin -Q 135 fi 136 137 # Do not validate if running under valgrind, even if told to do so. Valgrind 138 # will output a lot more stuff that is not XML, so it wouldn't validate anyway. 139 if [ "$validate" = "1" ] && [ "$VALGRIND_CMD" = "" ] && [ $rc = 0 ] && [ "$XMLLINT_CMD" != "" ]; then 140 # The sed command filters out the "- validates" line that xmllint will output 141 # on success. grep cannot be used here because "grep -v 'validates$'" will 142 # return an exit code of 1 if its input consists entirely of "- validates". 143 $XMLLINT_CMD --noout --relaxng "$PCMK_schema_directory/api/api-result.rng" "$outfile" 2>&1 | sed -n '/validates$/ !p' 144 rc=$? 145 146 if [ $rc = 0 ]; then 147 printf "=#=#=#= End test: %s - $(crm_error --exit $rc) (%d) =#=#=#=\n" "$desc" $rc 148 else 149 printf "=#=#=#= End test: %s - Failed to validate (%d) =#=#=#=\n" "$desc" $rc 150 fi 151 else 152 printf "=#=#=#= End test: %s - $(crm_error --exit $rc) (%d) =#=#=#=\n" "$desc" $rc 153 fi 154 155 rm -f "$outfile" 156 157 if [ $rc -ne $target ]; then 158 num_errors=$(( $num_errors + 1 )) 159 printf "* Failed (rc=%.3d): %-14s - %s\n" $rc $app "$desc" 160 printf "* Failed (rc=%.3d): %-14s - %s\n" $rc $app "$desc (`which $app`)" 1>&2 161 return 162 exit $CRM_EX_ERROR 163 else 164 printf "* Passed: %-14s - %s\n" $app "$desc" 165 num_passed=$(( $num_passed + 1 )) 166 fi 167} 168 169function test_assert() { 170 _test_assert $1 0 $2 171} 172 173function test_assert_validate() { 174 _test_assert $1 1 $2 175} 176 177function test_crm_mon() { 178 local TMPXML 179 export CIB_file="$test_home/cli/crm_mon.xml" 180 181 desc="Basic text output" 182 cmd="crm_mon -1" 183 test_assert $CRM_EX_OK 0 184 185 desc="XML output" 186 cmd="crm_mon --output-as=xml" 187 test_assert_validate $CRM_EX_OK 0 188 189 desc="Basic text output without node section" 190 cmd="crm_mon -1 --exclude=nodes" 191 test_assert $CRM_EX_OK 0 192 193 desc="XML output without the node section" 194 cmd="crm_mon --output-as=xml --exclude=nodes" 195 test_assert_validate $CRM_EX_OK 0 196 197 desc="Text output with only the node section" 198 cmd="crm_mon -1 --exclude=all --include=nodes" 199 test_assert $CRM_EX_OK 0 200 201 # The above test doesn't need to be performed for other output formats. It's 202 # really just a test to make sure that blank lines are correct. 203 204 desc="Complete text output" 205 cmd="crm_mon -1 --include=all" 206 test_assert $CRM_EX_OK 0 207 208 # XML includes everything already so there's no need for a complete test 209 210 desc="Complete text output with detail" 211 cmd="crm_mon -1R --include=all" 212 test_assert $CRM_EX_OK 0 213 214 # XML includes detailed output already 215 216 desc="Complete brief text output" 217 cmd="crm_mon -1 --include=all --brief" 218 test_assert $CRM_EX_OK 0 219 220 desc="Complete text output grouped by node" 221 cmd="crm_mon -1 --include=all --group-by-node" 222 test_assert $CRM_EX_OK 0 223 224 # XML does not have a brief output option 225 226 desc="Complete brief text output grouped by node" 227 cmd="crm_mon -1 --include=all --group-by-node --brief" 228 test_assert $CRM_EX_OK 0 229 230 desc="XML output grouped by node" 231 cmd="crm_mon -1 --output-as=xml --group-by-node" 232 test_assert_validate $CRM_EX_OK 0 233 234 desc="Complete text output filtered by node" 235 cmd="crm_mon -1 --include=all --node=cluster01" 236 test_assert $CRM_EX_OK 0 237 238 desc="XML output filtered by node" 239 cmd="crm_mon --output-as xml --include=all --node=cluster01" 240 test_assert_validate $CRM_EX_OK 0 241 242 desc="Complete text output filtered by tag" 243 cmd="crm_mon -1 --include=all --node=even-nodes" 244 test_assert $CRM_EX_OK 0 245 246 desc="XML output filtered by tag" 247 cmd="crm_mon --output-as=xml --include=all --node=even-nodes" 248 test_assert_validate $CRM_EX_OK 0 249 250 desc="Complete text output filtered by resource tag" 251 cmd="crm_mon -1 --include=all --resource=fencing-rscs" 252 test_assert $CRM_EX_OK 0 253 254 desc="XML output filtered by resource tag" 255 cmd="crm_mon --output-as=xml --include=all --resource=fencing-rscs" 256 test_assert_validate $CRM_EX_OK 0 257 258 desc="Basic text output filtered by node that doesn't exist" 259 cmd="crm_mon -1 --node=blah" 260 test_assert $CRM_EX_OK 0 261 262 desc="XML output filtered by node that doesn't exist" 263 cmd="crm_mon --output-as=xml --node=blah" 264 test_assert_validate $CRM_EX_OK 0 265 266 desc="Basic text output with inactive resources" 267 cmd="crm_mon -1 -r" 268 test_assert $CRM_EX_OK 0 269 270 # XML already includes inactive resources 271 272 desc="Basic text output with inactive resources, filtered by node" 273 cmd="crm_mon -1 -r --node=cluster02" 274 test_assert $CRM_EX_OK 0 275 276 # XML already includes inactive resources 277 278 desc="Complete text output filtered by primitive resource" 279 cmd="crm_mon -1 --include=all --resource=Fencing" 280 test_assert $CRM_EX_OK 0 281 282 desc="XML output filtered by primitive resource" 283 cmd="crm_mon --output-as=xml --resource=Fencing" 284 test_assert_validate $CRM_EX_OK 0 285 286 desc="Complete text output filtered by group resource" 287 cmd="crm_mon -1 --include=all --resource=exim-group" 288 test_assert $CRM_EX_OK 0 289 290 desc="XML output filtered by group resource" 291 cmd="crm_mon --output-as=xml --resource=exim-group" 292 test_assert_validate $CRM_EX_OK 0 293 294 desc="Complete text output filtered by group resource member" 295 cmd="crm_mon -1 --include=all --resource=Public-IP" 296 test_assert $CRM_EX_OK 0 297 298 desc="XML output filtered by group resource member" 299 cmd="crm_mon --output-as=xml --resource=Email" 300 test_assert_validate $CRM_EX_OK 0 301 302 desc="Complete text output filtered by clone resource" 303 cmd="crm_mon -1 --include=all --resource=ping-clone" 304 test_assert $CRM_EX_OK 0 305 306 desc="XML output filtered by clone resource" 307 cmd="crm_mon --output-as=xml --resource=ping-clone" 308 test_assert_validate $CRM_EX_OK 0 309 310 desc="Complete text output filtered by clone resource instance" 311 cmd="crm_mon -1 --include=all --resource=ping" 312 test_assert $CRM_EX_OK 0 313 314 desc="XML output filtered by clone resource instance" 315 cmd="crm_mon --output-as=xml --resource=ping" 316 test_assert_validate $CRM_EX_OK 0 317 318 desc="Complete text output filtered by exact clone resource instance" 319 cmd="crm_mon -1 --include=all --show-detail --resource=ping:0" 320 test_assert $CRM_EX_OK 0 321 322 desc="XML output filtered by exact clone resource instance" 323 cmd="crm_mon --output-as=xml --resource=ping:1" 324 test_assert_validate $CRM_EX_OK 0 325 326 desc="Basic text output filtered by resource that doesn't exist" 327 cmd="crm_mon -1 --resource=blah" 328 test_assert $CRM_EX_OK 0 329 330 desc="XML output filtered by resource that doesn't exist" 331 cmd="crm_mon --output-as=xml --resource=blah" 332 test_assert_validate $CRM_EX_OK 0 333 334 desc="Basic text output with inactive resources, filtered by tag" 335 cmd="crm_mon -1 -r --resource=inactive-rscs" 336 test_assert $CRM_EX_OK 0 337 338 desc="Basic text output with inactive resources, filtered by bundle resource" 339 cmd="crm_mon -1 -r --resource=httpd-bundle" 340 test_assert $CRM_EX_OK 0 341 342 desc="XML output filtered by inactive bundle resource" 343 cmd="crm_mon --output-as=xml --resource=httpd-bundle" 344 test_assert_validate $CRM_EX_OK 0 345 346 desc="Basic text output with inactive resources, filtered by bundled IP address resource" 347 cmd="crm_mon -1 -r --resource=httpd-bundle-ip-192.168.122.131" 348 test_assert $CRM_EX_OK 0 349 350 desc="XML output filtered by bundled IP address resource" 351 cmd="crm_mon --output-as=xml --resource=httpd-bundle-ip-192.168.122.132" 352 test_assert_validate $CRM_EX_OK 0 353 354 desc="Basic text output with inactive resources, filtered by bundled container" 355 cmd="crm_mon -1 -r --resource=httpd-bundle-docker-1" 356 test_assert $CRM_EX_OK 0 357 358 desc="XML output filtered by bundled container" 359 cmd="crm_mon --output-as=xml --resource=httpd-bundle-docker-2" 360 test_assert_validate $CRM_EX_OK 0 361 362 desc="Basic text output with inactive resources, filtered by bundle connection" 363 cmd="crm_mon -1 -r --resource=httpd-bundle-0" 364 test_assert $CRM_EX_OK 0 365 366 desc="XML output filtered by bundle connection" 367 cmd="crm_mon --output-as=xml --resource=httpd-bundle-0" 368 test_assert_validate $CRM_EX_OK 0 369 370 desc="Basic text output with inactive resources, filtered by bundled primitive resource" 371 cmd="crm_mon -1 -r --resource=httpd" 372 test_assert $CRM_EX_OK 0 373 374 desc="XML output filtered by bundled primitive resource" 375 cmd="crm_mon --output-as=xml --resource=httpd" 376 test_assert_validate $CRM_EX_OK 0 377 378 desc="Complete text output, filtered by clone name in cloned group" 379 cmd="crm_mon -1 --include=all --show-detail --resource=mysql-clone-group" 380 test_assert $CRM_EX_OK 0 381 382 desc="XML output, filtered by clone name in cloned group" 383 cmd="crm_mon --output-as=xml --resource=mysql-clone-group" 384 test_assert_validate $CRM_EX_OK 0 385 386 desc="Complete text output, filtered by group name in cloned group" 387 cmd="crm_mon -1 --include=all --show-detail --resource=mysql-group" 388 test_assert $CRM_EX_OK 0 389 390 desc="XML output, filtered by group name in cloned group" 391 cmd="crm_mon --output-as=xml --resource=mysql-group" 392 test_assert_validate $CRM_EX_OK 0 393 394 desc="Complete text output, filtered by exact group instance name in cloned group" 395 cmd="crm_mon -1 --include=all --show-detail --resource=mysql-group:1" 396 test_assert $CRM_EX_OK 0 397 398 desc="XML output, filtered by exact group instance name in cloned group" 399 cmd="crm_mon --output-as=xml --resource=mysql-group:1" 400 test_assert_validate $CRM_EX_OK 0 401 402 desc="Complete text output, filtered by primitive name in cloned group" 403 cmd="crm_mon -1 --include=all --show-detail --resource=mysql-proxy" 404 test_assert $CRM_EX_OK 0 405 406 desc="XML output, filtered by primitive name in cloned group" 407 cmd="crm_mon --output-as=xml --resource=mysql-proxy" 408 test_assert_validate $CRM_EX_OK 0 409 410 desc="Complete text output, filtered by exact primitive instance name in cloned group" 411 cmd="crm_mon -1 --include=all --show-detail --resource=mysql-proxy:1" 412 test_assert $CRM_EX_OK 0 413 414 desc="XML output, filtered by exact primitive instance name in cloned group" 415 cmd="crm_mon --output-as=xml --resource=mysql-proxy:1" 416 test_assert_validate $CRM_EX_OK 0 417 418 unset CIB_file 419 420 export CIB_file="$test_home/cli/crm_mon-partial.xml" 421 422 desc="Text output of partially active resources" 423 cmd="crm_mon -1" 424 test_assert $CRM_EX_OK 0 425 426 desc="XML output of partially active resources" 427 cmd="crm_mon -1 --output-as=xml" 428 test_assert_validate $CRM_EX_OK 0 429 430 desc="Text output of partially active resources, with inactive resources" 431 cmd="crm_mon -1 -r" 432 test_assert $CRM_EX_OK 0 433 434 # XML already includes inactive resources 435 436 desc="Complete brief text output, with inactive resources" 437 cmd="crm_mon -1 -r --include=all --brief" 438 test_assert $CRM_EX_OK 0 439 440 # XML does not have a brief output option 441 442 desc="Text output of partially active group" 443 cmd="crm_mon -1 --resource=partially-active-group" 444 test_assert $CRM_EX_OK 0 445 446 desc="Text output of partially active group, with inactive resources" 447 cmd="crm_mon -1 --resource=partially-active-group -r" 448 test_assert $CRM_EX_OK 0 449 450 desc="Text output of active member of partially active group" 451 cmd="crm_mon -1 --resource=dummy-1" 452 test_assert $CRM_EX_OK 0 453 454 desc="Text output of inactive member of partially active group" 455 cmd="crm_mon -1 --resource=dummy-2" 456 test_assert $CRM_EX_OK 0 457 458 desc="Complete brief text output grouped by node, with inactive resources" 459 cmd="crm_mon -1 -r --include=all --group-by-node --brief" 460 test_assert $CRM_EX_OK 0 461 462 desc="Text output of partially active resources, with inactive resources, filtered by node" 463 cmd="crm_mon -1 -r --node=cluster01" 464 test_assert $CRM_EX_OK 0 465 466 desc="Text output of partially active resources, filtered by node" 467 cmd="crm_mon -1 --output-as=xml --node=cluster01" 468 test_assert_validate $CRM_EX_OK 0 469 470 unset CIB_file 471 472 export CIB_file="$test_home/cli/crm_mon-unmanaged.xml" 473 474 desc="Text output of active unmanaged resource on offline node" 475 cmd="crm_mon -1" 476 test_assert $CRM_EX_OK 0 477 478 desc="XML output of active unmanaged resource on offline node" 479 cmd="crm_mon -1 --output-as=xml" 480 test_assert $CRM_EX_OK 0 481 482 desc="Brief text output of active unmanaged resource on offline node" 483 cmd="crm_mon -1 --brief" 484 test_assert $CRM_EX_OK 0 485 486 desc="Brief text output of active unmanaged resource on offline node, grouped by node" 487 cmd="crm_mon -1 --brief --group-by-node" 488 test_assert $CRM_EX_OK 0 489 490 export CIB_file=$(mktemp ${TMPDIR:-/tmp}/cts-cli.crm_mon.xml.XXXXXXXXXX) 491 sed -e '/maintenance-mode/ s/false/true/' "$test_home/cli/crm_mon.xml" > $CIB_file 492 493 desc="Text output of all resources with maintenance-mode enabled" 494 cmd="crm_mon -1 -r" 495 test_assert $CRM_EX_OK 0 496 497 rm -r "$CIB_file" 498 unset CIB_file 499} 500 501function test_tools() { 502 local TMPXML 503 local TMPORIG 504 505 TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX) 506 TMPORIG=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.existing.xml.XXXXXXXXXX) 507 508 create_shadow_cib 509 510 desc="Validate CIB" 511 cmd="cibadmin -Q" 512 test_assert $CRM_EX_OK 513 514 desc="Configure something before erasing" 515 cmd="crm_attribute -n cluster-delay -v 60s" 516 test_assert $CRM_EX_OK 517 518 desc="Require --force for CIB erasure" 519 cmd="cibadmin -E" 520 test_assert $CRM_EX_UNSAFE 521 522 desc="Allow CIB erasure with --force" 523 cmd="cibadmin -E --force" 524 test_assert $CRM_EX_OK 0 525 526 # Skip outputting the resulting CIB in the previous command, and delete 527 # rsc_defaults now, so tests behave the same regardless of build options. 528 delete_shadow_resource_defaults 529 530 # Verify the output after erasure 531 desc="Query CIB" 532 cmd="cibadmin -Q" 533 test_assert $CRM_EX_OK 534 535 # Save a copy of the CIB for a later test 536 cibadmin -Q > "$TMPORIG" 537 538 desc="Set cluster option" 539 cmd="crm_attribute -n cluster-delay -v 60s" 540 test_assert $CRM_EX_OK 541 542 desc="Query new cluster option" 543 cmd="cibadmin -Q -o crm_config | grep cib-bootstrap-options-cluster-delay" 544 test_assert $CRM_EX_OK 545 546 desc="Query cluster options" 547 cmd="cibadmin -Q -o crm_config > $TMPXML" 548 test_assert $CRM_EX_OK 549 550 desc="Set no-quorum policy" 551 cmd="crm_attribute -n no-quorum-policy -v ignore" 552 test_assert $CRM_EX_OK 553 554 desc="Delete nvpair" 555 cmd="cibadmin -D -o crm_config --xml-text '<nvpair id=\"cib-bootstrap-options-cluster-delay\"/>'" 556 test_assert $CRM_EX_OK 557 558 desc="Create operation should fail" 559 cmd="cibadmin -C -o crm_config --xml-file $TMPXML" 560 test_assert $CRM_EX_EXISTS 561 562 desc="Modify cluster options section" 563 cmd="cibadmin -M -o crm_config --xml-file $TMPXML" 564 test_assert $CRM_EX_OK 565 566 desc="Query updated cluster option" 567 cmd="cibadmin -Q -o crm_config | grep cib-bootstrap-options-cluster-delay" 568 test_assert $CRM_EX_OK 569 570 desc="Set duplicate cluster option" 571 cmd="crm_attribute -n cluster-delay -v 40s -s duplicate" 572 test_assert $CRM_EX_OK 573 574 desc="Setting multiply defined cluster option should fail" 575 cmd="crm_attribute -n cluster-delay -v 30s" 576 test_assert $CRM_EX_MULTIPLE 577 578 desc="Set cluster option with -s" 579 cmd="crm_attribute -n cluster-delay -v 30s -s duplicate" 580 test_assert $CRM_EX_OK 581 582 desc="Delete cluster option with -i" 583 cmd="crm_attribute -n cluster-delay -D -i cib-bootstrap-options-cluster-delay" 584 test_assert $CRM_EX_OK 585 586 desc="Create node1 and bring it online" 587 cmd="crm_simulate --live-check --in-place --node-up=node1" 588 test_assert $CRM_EX_OK 589 590 desc="Create node attribute" 591 cmd="crm_attribute -n ram -v 1024M -N node1 -t nodes" 592 test_assert $CRM_EX_OK 593 594 desc="Query new node attribute" 595 cmd="cibadmin -Q -o nodes | grep node1-ram" 596 test_assert $CRM_EX_OK 597 598 desc="Set a transient (fail-count) node attribute" 599 cmd="crm_attribute -n fail-count-foo -v 3 -N node1 -t status" 600 test_assert $CRM_EX_OK 601 602 desc="Query a fail count" 603 cmd="crm_failcount --query -r foo -N node1" 604 test_assert $CRM_EX_OK 605 606 desc="Delete a transient (fail-count) node attribute" 607 cmd="crm_attribute -n fail-count-foo -D -N node1 -t status" 608 test_assert $CRM_EX_OK 609 610 desc="Digest calculation" 611 cmd="cibadmin -Q | cibadmin -5 -p 2>&1 > /dev/null" 612 test_assert $CRM_EX_OK 613 614 # This update will fail because it has version numbers 615 desc="Replace operation should fail" 616 cmd="cibadmin -R --xml-file $TMPORIG" 617 test_assert $CRM_EX_OLD 618 619 desc="Default standby value" 620 cmd="crm_standby -N node1 -G" 621 test_assert $CRM_EX_OK 622 623 desc="Set standby status" 624 cmd="crm_standby -N node1 -v true" 625 test_assert $CRM_EX_OK 626 627 desc="Query standby value" 628 cmd="crm_standby -N node1 -G" 629 test_assert $CRM_EX_OK 630 631 desc="Delete standby value" 632 cmd="crm_standby -N node1 -D" 633 test_assert $CRM_EX_OK 634 635 desc="Create a resource" 636 cmd="cibadmin -C -o resources --xml-text '<primitive id=\"dummy\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/>'" 637 test_assert $CRM_EX_OK 638 639 desc="Create a resource meta attribute" 640 cmd="crm_resource -r dummy --meta -p is-managed -v false" 641 test_assert $CRM_EX_OK 642 643 desc="Query a resource meta attribute" 644 cmd="crm_resource -r dummy --meta -g is-managed" 645 test_assert $CRM_EX_OK 646 647 desc="Remove a resource meta attribute" 648 cmd="crm_resource -r dummy --meta -d is-managed" 649 test_assert $CRM_EX_OK 650 651 desc="Create another resource meta attribute" 652 cmd="crm_resource -r dummy --meta -p target-role -v Stopped --output-as=xml" 653 test_assert_validate $CRM_EX_OK 0 654 655 desc="Show why a resource is not running" 656 cmd="crm_resource -Y -r dummy" 657 test_assert $CRM_EX_OK 0 658 659 desc="Remove another resource meta attribute" 660 cmd="crm_resource -r dummy --meta -d target-role --output-as=xml" 661 test_assert_validate $CRM_EX_OK 0 662 663 desc="Create a resource attribute" 664 cmd="crm_resource -r dummy -p delay -v 10s" 665 test_assert $CRM_EX_OK 666 667 desc="List the configured resources" 668 cmd="crm_resource -L" 669 test_assert $CRM_EX_OK 670 671 desc="List the configured resources in XML" 672 cmd="crm_resource -L --output-as=xml" 673 test_assert_validate $CRM_EX_OK 0 674 675 desc="List IDs of instantiated resources" 676 cmd="crm_resource -l" 677 test_assert $CRM_EX_OK 0 678 679 desc="Show XML configuration of resource" 680 cmd="crm_resource -q -r dummy" 681 test_assert $CRM_EX_OK 0 682 683 desc="Require a destination when migrating a resource that is stopped" 684 cmd="crm_resource -r dummy -M" 685 test_assert $CRM_EX_USAGE 686 687 desc="Don't support migration to non-existent locations" 688 cmd="crm_resource -r dummy -M -N i.do.not.exist" 689 test_assert $CRM_EX_NOSUCH 690 691 desc="Create a fencing resource" 692 cmd="cibadmin -C -o resources --xml-text '<primitive id=\"Fence\" class=\"stonith\" type=\"fence_true\"/>'" 693 test_assert $CRM_EX_OK 694 695 desc="Bring resources online" 696 cmd="crm_simulate --live-check --in-place -S" 697 test_assert $CRM_EX_OK 698 699 desc="Try to move a resource to its existing location" 700 cmd="crm_resource -r dummy --move --node node1" 701 test_assert $CRM_EX_EXISTS 702 703 desc="Move a resource from its existing location" 704 cmd="crm_resource -r dummy --move" 705 test_assert $CRM_EX_OK 706 707 desc="Clear out constraints generated by --move" 708 cmd="crm_resource -r dummy --clear" 709 test_assert $CRM_EX_OK 710 711 desc="Default ticket granted state" 712 cmd="crm_ticket -t ticketA -G granted -d false" 713 test_assert $CRM_EX_OK 714 715 desc="Set ticket granted state" 716 cmd="crm_ticket -t ticketA -r --force" 717 test_assert $CRM_EX_OK 718 719 desc="Query ticket granted state" 720 cmd="crm_ticket -t ticketA -G granted" 721 test_assert $CRM_EX_OK 722 723 desc="Delete ticket granted state" 724 cmd="crm_ticket -t ticketA -D granted --force" 725 test_assert $CRM_EX_OK 726 727 desc="Make a ticket standby" 728 cmd="crm_ticket -t ticketA -s" 729 test_assert $CRM_EX_OK 730 731 desc="Query ticket standby state" 732 cmd="crm_ticket -t ticketA -G standby" 733 test_assert $CRM_EX_OK 734 735 desc="Activate a ticket" 736 cmd="crm_ticket -t ticketA -a" 737 test_assert $CRM_EX_OK 738 739 desc="Delete ticket standby state" 740 cmd="crm_ticket -t ticketA -D standby" 741 test_assert $CRM_EX_OK 742 743 desc="Ban a resource on unknown node" 744 cmd="crm_resource -r dummy -B -N host1" 745 test_assert $CRM_EX_NOSUCH 746 747 desc="Create two more nodes and bring them online" 748 cmd="crm_simulate --live-check --in-place --node-up=node2 --node-up=node3" 749 test_assert $CRM_EX_OK 750 751 desc="Ban dummy from node1" 752 cmd="crm_resource -r dummy -B -N node1" 753 test_assert $CRM_EX_OK 754 755 desc="Show where a resource is running" 756 cmd="crm_resource -r dummy -W" 757 test_assert $CRM_EX_OK 0 758 759 desc="Show constraints on a resource" 760 cmd="crm_resource -a -r dummy" 761 test_assert $CRM_EX_OK 0 762 763 desc="Ban dummy from node2" 764 cmd="crm_resource -r dummy -B -N node2 --output-as=xml" 765 test_assert_validate $CRM_EX_OK 766 767 desc="Relocate resources due to ban" 768 cmd="crm_simulate --live-check --in-place -S" 769 test_assert $CRM_EX_OK 770 771 desc="Move dummy to node1" 772 cmd="crm_resource -r dummy -M -N node1 --output-as=xml" 773 test_assert_validate $CRM_EX_OK 774 775 desc="Clear implicit constraints for dummy on node2" 776 cmd="crm_resource -r dummy -U -N node2" 777 test_assert $CRM_EX_OK 778 779 desc="Drop the status section" 780 cmd="cibadmin -R -o status --xml-text '<status/>'" 781 test_assert $CRM_EX_OK 0 782 783 desc="Create a clone" 784 cmd="cibadmin -C -o resources --xml-text '<clone id=\"test-clone\"><primitive id=\"test-primitive\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/></clone>'" 785 test_assert $CRM_EX_OK 0 786 787 desc="Create a resource meta attribute" 788 cmd="crm_resource -r test-primitive --meta -p is-managed -v false" 789 test_assert $CRM_EX_OK 790 791 desc="Create a resource meta attribute in the primitive" 792 cmd="crm_resource -r test-primitive --meta -p is-managed -v false --force" 793 test_assert $CRM_EX_OK 794 795 desc="Update resource meta attribute with duplicates" 796 cmd="crm_resource -r test-clone --meta -p is-managed -v true" 797 test_assert $CRM_EX_OK 798 799 desc="Update resource meta attribute with duplicates (force clone)" 800 cmd="crm_resource -r test-clone --meta -p is-managed -v true --force" 801 test_assert $CRM_EX_OK 802 803 desc="Update child resource meta attribute with duplicates" 804 cmd="crm_resource -r test-primitive --meta -p is-managed -v false" 805 test_assert $CRM_EX_OK 806 807 desc="Delete resource meta attribute with duplicates" 808 cmd="crm_resource -r test-clone --meta -d is-managed" 809 test_assert $CRM_EX_OK 810 811 desc="Delete resource meta attribute in parent" 812 cmd="crm_resource -r test-primitive --meta -d is-managed" 813 test_assert $CRM_EX_OK 814 815 desc="Create a resource meta attribute in the primitive" 816 cmd="crm_resource -r test-primitive --meta -p is-managed -v false --force" 817 test_assert $CRM_EX_OK 818 819 desc="Update existing resource meta attribute" 820 cmd="crm_resource -r test-clone --meta -p is-managed -v true" 821 test_assert $CRM_EX_OK 822 823 desc="Create a resource meta attribute in the parent" 824 cmd="crm_resource -r test-clone --meta -p is-managed -v true --force" 825 test_assert $CRM_EX_OK 826 827 desc="Copy resources" 828 cmd="cibadmin -Q -o resources > $TMPXML" 829 test_assert $CRM_EX_OK 0 830 831 desc="Delete resource parent meta attribute (force)" 832 cmd="crm_resource -r test-clone --meta -d is-managed --force" 833 test_assert $CRM_EX_OK 834 835 desc="Restore duplicates" 836 cmd="cibadmin -R -o resources --xml-file $TMPXML" 837 test_assert $CRM_EX_OK 838 839 desc="Delete resource child meta attribute" 840 cmd="crm_resource -r test-primitive --meta -d is-managed" 841 test_assert $CRM_EX_OK 842 843 cibadmin -C -o resources --xml-text '<group id="dummy-group"> \ 844 <primitive id="dummy1" class="ocf" provider="pacemaker" type="Dummy"\/> \ 845 <primitive id="dummy2" class="ocf" provider="pacemaker" type="Dummy"\/> \ 846 </group>' 847 848 desc="Create a resource meta attribute in dummy1" 849 cmd="crm_resource -r dummy1 --meta -p is-managed -v true" 850 test_assert $CRM_EX_OK 851 852 desc="Create a resource meta attribute in dummy-group" 853 cmd="crm_resource -r dummy-group --meta -p is-managed -v false" 854 test_assert $CRM_EX_OK 855 856 cibadmin -D -o resource --xml-text '<group id="dummy-group">' 857 858 desc="Specify a lifetime when moving a resource" 859 cmd="crm_resource -r dummy --move --node node2 --lifetime=PT1H" 860 test_assert $CRM_EX_OK 861 862 desc="Try to move a resource previously moved with a lifetime" 863 cmd="crm_resource -r dummy --move --node node1" 864 test_assert $CRM_EX_OK 865 866 desc="Ban dummy from node1 for a short time" 867 cmd="crm_resource -r dummy -B -N node1 --lifetime=PT1S" 868 test_assert $CRM_EX_OK 869 870 desc="Remove expired constraints" 871 sleep 2 872 cmd="crm_resource --clear --expired" 873 test_assert $CRM_EX_OK 874 875 # Clear has already been tested elsewhere, but we need to get rid of the 876 # constraints so testing delete works. It won't delete if there's still 877 # a reference to the resource somewhere. 878 desc="Clear all implicit constraints for dummy" 879 cmd="crm_resource -r dummy -U" 880 test_assert $CRM_EX_OK 881 882 desc="Delete a resource" 883 cmd="crm_resource -D -r dummy -t primitive" 884 test_assert $CRM_EX_OK 885 886 unset CIB_shadow 887 unset CIB_shadow_dir 888 rm -f "$TMPXML" "$TMPORIG" 889 890 desc="Create an XML patchset" 891 cmd="crm_diff -o $test_home/cli/crm_diff_old.xml -n $test_home/cli/crm_diff_new.xml" 892 test_assert $CRM_EX_ERROR 0 893 894 export CIB_file="$test_home/cli/constraints.xml" 895 896 for rsc in prim1 prim2 prim3 prim4 prim5 prim6 prim7 prim8 prim9 \ 897 prim10 prim11 prim12 prim13 group clone; do 898 desc="Check locations and constraints for $rsc" 899 cmd="crm_resource -a -r $rsc" 900 test_assert $CRM_EX_OK 0 901 902 desc="Recursively check locations and constraints for $rsc" 903 cmd="crm_resource -A -r $rsc" 904 test_assert $CRM_EX_OK 0 905 906 desc="Check locations and constraints for $rsc in XML" 907 cmd="crm_resource -a -r $rsc --output-as=xml" 908 test_assert_validate $CRM_EX_OK 0 909 910 desc="Recursively check locations and constraints for $rsc in XML" 911 cmd="crm_resource -A -r $rsc --output-as=xml" 912 test_assert_validate $CRM_EX_OK 0 913 done 914 915 unset CIB_file 916 917 export CIB_file="$test_home/cli/crm_resource_digests.xml" 918 919 desc="Show resource digests" 920 cmd="crm_resource --digests -r rsc1 -N node1 --output-as=xml" 921 test_assert_validate $CRM_EX_OK 0 922 923 desc="Show resource digests with overrides" 924 cmd="$cmd CRM_meta_interval=10000 CRM_meta_timeout=20000" 925 test_assert $CRM_EX_OK 0 926 927 unset CIB_file 928 929 export CIB_file="$test_home/cli/crmadmin-cluster-remote-guest-nodes.xml" 930 931 desc="List all nodes" 932 cmd="crmadmin -N | wc -l | grep 11" 933 test_assert $CRM_EX_OK 0 934 935 desc="List cluster nodes" 936 cmd="crmadmin -N cluster | wc -l | grep 6" 937 test_assert $CRM_EX_OK 0 938 939 desc="List guest nodes" 940 cmd="crmadmin -N guest | wc -l | grep 2" 941 test_assert $CRM_EX_OK 0 942 943 desc="List remote nodes" 944 cmd="crmadmin -N remote | wc -l | grep 3" 945 test_assert $CRM_EX_OK 0 946 947 desc="List cluster,remote nodes" 948 cmd="crmadmin -N cluster,remote | wc -l | grep 9" 949 test_assert $CRM_EX_OK 0 950 951 desc="List guest,remote nodes" 952 cmd="crmadmin -N guest,remote | wc -l | grep 5" 953 test_assert $CRM_EX_OK 0 954 955 unset CIB_file 956 957 export CIB_file="$test_home/cli/crm_mon.xml" 958 959 desc="List a promotable clone resource" 960 cmd="crm_resource --locate -r promotable-clone" 961 test_assert $CRM_EX_OK 0 962 963 desc="List the primitive of a promotable clone resource" 964 cmd="crm_resource --locate -r promotable-rsc" 965 test_assert $CRM_EX_OK 0 966 967 desc="List a single instance of a promotable clone resource" 968 cmd="crm_resource --locate -r promotable-rsc:0" 969 test_assert $CRM_EX_OK 0 970 971 desc="List another instance of a promotable clone resource" 972 cmd="crm_resource --locate -r promotable-rsc:1" 973 test_assert $CRM_EX_OK 0 974 975 desc="List a promotable clone resource in XML" 976 cmd="crm_resource --locate -r promotable-clone --output-as=xml" 977 test_assert_validate $CRM_EX_OK 0 978 979 desc="List the primitive of a promotable clone resource in XML" 980 cmd="crm_resource --locate -r promotable-rsc --output-as=xml" 981 test_assert_validate $CRM_EX_OK 0 982 983 desc="List a single instance of a promotable clone resource in XML" 984 cmd="crm_resource --locate -r promotable-rsc:0 --output-as=xml" 985 test_assert_validate $CRM_EX_OK 0 986 987 desc="List another instance of a promotable clone resource in XML" 988 cmd="crm_resource --locate -r promotable-rsc:1 --output-as=xml" 989 test_assert_validate $CRM_EX_OK 0 990 991 unset CIB_file 992 993 export CIB_file="-" 994 995 desc="Check that CIB_file=\"-\" works - crm_mon" 996 cmd="cat $test_home/cli/crm_mon.xml | crm_mon -1" 997 test_assert $CRM_EX_OK 0 998 999 desc="Check that CIB_file=\"-\" works - crm_resource" 1000 cmd="cat $test_home/cli/crm_resource_digests.xml | crm_resource --digests -r rsc1 -N node1 --output-as=xml" 1001 test_assert_validate $CRM_EX_OK 0 1002 1003 desc="Check that CIB_file=\"-\" works - crmadmin" 1004 cmd="cat $test_home/cli/crmadmin-cluster-remote-guest-nodes.xml | crmadmin -N | wc -l | grep 11" 1005 test_assert $CRM_EX_OK 0 1006 1007 unset CIB_file 1008} 1009 1010INVALID_PERIODS=( 1011 "2019-01-01 00:00:00Z" # Start with no end 1012 "2019-01-01 00:00:00Z/" # Start with only a trailing slash 1013 "PT2S/P1M" # Two durations 1014 "2019-13-01 00:00:00Z/P1M" # Out-of-range month 1015 "20191077T15/P1M" # Out-of-range day 1016 "2019-10-01T25:00:00Z/P1M" # Out-of-range hour 1017 "2019-10-01T24:00:01Z/P1M" # Hour 24 with anything but :00:00 1018 "PT5H/20191001T007000Z" # Out-of-range minute 1019 "2019-10-01 00:00:80Z/P1M" # Out-of-range second 1020 "2019-10-01 00:00:10 +25:00/P1M" # Out-of-range offset hour 1021 "20191001T000010 -00:61/P1M" # Out-of-range offset minute 1022 "P1Y/2019-02-29 00:00:00Z" # Feb. 29 in non-leap-year 1023 "2019-01-01 00:00:00Z/P" # Duration with no values 1024 "P1Z/2019-02-20 00:00:00Z" # Invalid duration unit 1025 "P1YM/2019-02-20 00:00:00Z" # No number for duration unit 1026) 1027 1028function test_dates() { 1029 # Ensure invalid period specifications are rejected 1030 for spec in '' "${INVALID_PERIODS[@]}"; do 1031 desc="Invalid period - [$spec]" 1032 cmd="iso8601 -p \"$spec\"" 1033 test_assert $CRM_EX_INVALID_PARAM 0 1034 done 1035 1036 desc="2014-01-01 00:30:00 - 1 Hour" 1037 cmd="iso8601 -d '2014-01-01 00:30:00Z' -D P-1H -E '2013-12-31 23:30:00Z'" 1038 test_assert $CRM_EX_OK 0 1039 1040 desc="Valid date - Feb 29 in leap year" 1041 cmd="iso8601 -d '2020-02-29 00:00:00Z' -E '2020-02-29 00:00:00Z'" 1042 test_assert $CRM_EX_OK 0 1043 1044 desc="Valid date - using 'T' and offset" 1045 cmd="iso8601 -d '20191201T131211 -05:00' -E '2019-12-01 18:12:11Z'" 1046 test_assert $CRM_EX_OK 0 1047 1048 desc="24:00:00 equivalent to 00:00:00 of next day" 1049 cmd="iso8601 -d '2019-12-31 24:00:00Z' -E '2020-01-01 00:00:00Z'" 1050 test_assert $CRM_EX_OK 0 1051 1052 for y in 06 07 08 09 10 11 12 13 14 15 16 17 18 40; do 1053 desc="20$y-W01-7" 1054 cmd="iso8601 -d '20$y-W01-7 00Z'" 1055 test_assert $CRM_EX_OK 0 1056 1057 desc="20$y-W01-7 - round-trip" 1058 cmd="iso8601 -d '20$y-W01-7 00Z' -W -E '20$y-W01-7 00:00:00Z'" 1059 test_assert $CRM_EX_OK 0 1060 1061 desc="20$y-W01-1" 1062 cmd="iso8601 -d '20$y-W01-1 00Z'" 1063 test_assert $CRM_EX_OK 0 1064 1065 desc="20$y-W01-1 - round-trip" 1066 cmd="iso8601 -d '20$y-W01-1 00Z' -W -E '20$y-W01-1 00:00:00Z'" 1067 test_assert $CRM_EX_OK 0 1068 done 1069 1070 desc="2009-W53-07" 1071 cmd="iso8601 -d '2009-W53-7 00:00:00Z' -W -E '2009-W53-7 00:00:00Z'" 1072 test_assert $CRM_EX_OK 0 1073 1074 desc="epoch + 2 Years 5 Months 6 Minutes" 1075 cmd="iso8601 -d 'epoch' -D P2Y5MT6M -E '1972-06-01 00:06:00Z'" 1076 test_assert $CRM_EX_OK 0 1077 1078 desc="2009-01-31 + 1 Month" 1079 cmd="iso8601 -d '20090131T000000Z' -D P1M -E '2009-02-28 00:00:00Z'" 1080 test_assert $CRM_EX_OK 0 1081 1082 desc="2009-01-31 + 2 Months" 1083 cmd="iso8601 -d '2009-01-31 00:00:00Z' -D P2M -E '2009-03-31 00:00:00Z'" 1084 test_assert $CRM_EX_OK 0 1085 1086 desc="2009-01-31 + 3 Months" 1087 cmd="iso8601 -d '2009-01-31 00:00:00Z' -D P3M -E '2009-04-30 00:00:00Z'" 1088 test_assert $CRM_EX_OK 0 1089 1090 desc="2009-03-31 - 1 Month" 1091 cmd="iso8601 -d '2009-03-31 01:00:00 +01:00' -D P-1M -E '2009-02-28 00:00:00Z'" 1092 test_assert $CRM_EX_OK 0 1093 1094 desc="2038-01-01 + 3 Months" 1095 cmd="iso8601 -d '2038-01-01 00:00:00Z' -D P3M -E '2038-04-01 00:00:00Z'" 1096 test_assert $CRM_EX_OK 0 1097} 1098 1099function test_acl_loop() { 1100 local TMPXML 1101 1102 TMPXML="$1" 1103 1104 # Make sure we're rejecting things for the right reasons 1105 export PCMK_trace_functions=pcmk__check_acl,pcmk__apply_creation_acl 1106 export PCMK_stderr=1 1107 1108 CIB_user=root cibadmin --replace --xml-text '<resources/>' 1109 1110 ### no ACL ### 1111 export CIB_user=unknownguy 1112 desc="$CIB_user: Query configuration" 1113 cmd="cibadmin -Q" 1114 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1115 1116 desc="$CIB_user: Set enable-acl" 1117 cmd="crm_attribute -n enable-acl -v false" 1118 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1119 1120 desc="$CIB_user: Set stonith-enabled" 1121 cmd="crm_attribute -n stonith-enabled -v false" 1122 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1123 1124 desc="$CIB_user: Create a resource" 1125 cmd="cibadmin -C -o resources --xml-text '<primitive id=\"dummy\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/>'" 1126 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1127 1128 ### deny /cib permission ### 1129 export CIB_user=l33t-haxor 1130 desc="$CIB_user: Query configuration" 1131 cmd="cibadmin -Q" 1132 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1133 1134 desc="$CIB_user: Set enable-acl" 1135 cmd="crm_attribute -n enable-acl -v false" 1136 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1137 1138 desc="$CIB_user: Set stonith-enabled" 1139 cmd="crm_attribute -n stonith-enabled -v false" 1140 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1141 1142 desc="$CIB_user: Create a resource" 1143 cmd="cibadmin -C -o resources --xml-text '<primitive id=\"dummy\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/>'" 1144 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1145 1146 ### observer role ### 1147 export CIB_user=niceguy 1148 desc="$CIB_user: Query configuration" 1149 cmd="cibadmin -Q" 1150 test_assert $CRM_EX_OK 0 1151 1152 desc="$CIB_user: Set enable-acl" 1153 cmd="crm_attribute -n enable-acl -v false" 1154 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1155 1156 desc="$CIB_user: Set stonith-enabled" 1157 cmd="crm_attribute -n stonith-enabled -v false" 1158 test_assert $CRM_EX_OK 1159 1160 desc="$CIB_user: Create a resource" 1161 cmd="cibadmin -C -o resources --xml-text '<primitive id=\"dummy\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/>'" 1162 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1163 1164 export CIB_user=root 1165 desc="$CIB_user: Query configuration" 1166 cmd="cibadmin -Q" 1167 test_assert $CRM_EX_OK 0 1168 1169 desc="$CIB_user: Set stonith-enabled" 1170 cmd="crm_attribute -n stonith-enabled -v true" 1171 test_assert $CRM_EX_OK 1172 1173 desc="$CIB_user: Create a resource" 1174 cmd="cibadmin -C -o resources --xml-text '<primitive id=\"dummy\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/>'" 1175 test_assert $CRM_EX_OK 1176 1177 ### deny /cib permission ### 1178 export CIB_user=l33t-haxor 1179 1180 desc="$CIB_user: Create a resource meta attribute" 1181 cmd="crm_resource -r dummy --meta -p target-role -v Stopped" 1182 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1183 1184 desc="$CIB_user: Query a resource meta attribute" 1185 cmd="crm_resource -r dummy --meta -g target-role" 1186 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1187 1188 desc="$CIB_user: Remove a resource meta attribute" 1189 cmd="crm_resource -r dummy --meta -d target-role" 1190 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1191 1192 ### observer role ### 1193 export CIB_user=niceguy 1194 1195 desc="$CIB_user: Create a resource meta attribute" 1196 cmd="crm_resource -r dummy --meta -p target-role -v Stopped" 1197 test_assert $CRM_EX_OK 1198 1199 desc="$CIB_user: Query a resource meta attribute" 1200 cmd="crm_resource -r dummy --meta -g target-role" 1201 test_assert $CRM_EX_OK 1202 1203 desc="$CIB_user: Remove a resource meta attribute" 1204 cmd="crm_resource -r dummy --meta -d target-role" 1205 test_assert $CRM_EX_OK 1206 1207 desc="$CIB_user: Create a resource meta attribute" 1208 cmd="crm_resource -r dummy --meta -p target-role -v Started" 1209 test_assert $CRM_EX_OK 1210 1211 ### read //meta_attributes ### 1212 export CIB_user=badidea 1213 desc="$CIB_user: Query configuration - implied deny" 1214 cmd="cibadmin -Q" 1215 test_assert $CRM_EX_OK 0 1216 1217 ### deny /cib, read //meta_attributes ### 1218 export CIB_user=betteridea 1219 desc="$CIB_user: Query configuration - explicit deny" 1220 cmd="cibadmin -Q" 1221 test_assert $CRM_EX_OK 0 1222 1223 CIB_user=root cibadmin -Q > "$TMPXML" 1224 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --delete --xml-text '<acls/>' 1225 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql 1226 1227 ### observer role ### 1228 export CIB_user=niceguy 1229 desc="$CIB_user: Replace - remove acls" 1230 cmd="cibadmin --replace --xml-file $TMPXML" 1231 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1232 1233 CIB_user=root cibadmin -Q > "$TMPXML" 1234 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -C -o resources --xml-text '<primitive id="dummy2" class="ocf" provider="pacemaker" type="Dummy"/>' 1235 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql 1236 1237 desc="$CIB_user: Replace - create resource" 1238 cmd="cibadmin --replace --xml-file $TMPXML" 1239 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1240 1241 CIB_user=root cibadmin -Q > "$TMPXML" 1242 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" crm_attribute -n enable-acl -v false 1243 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql 1244 1245 desc="$CIB_user: Replace - modify attribute (deny)" 1246 cmd="cibadmin --replace --xml-file $TMPXML" 1247 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1248 1249 CIB_user=root cibadmin -Q > "$TMPXML" 1250 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace --xml-text '<nvpair id="cib-bootstrap-options-enable-acl" name="enable-acl"/>' 1251 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql 1252 1253 desc="$CIB_user: Replace - delete attribute (deny)" 1254 cmd="cibadmin --replace --xml-file $TMPXML" 1255 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1256 1257 CIB_user=root cibadmin -Q > "$TMPXML" 1258 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="nothing interesting"/>' 1259 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql 1260 1261 desc="$CIB_user: Replace - create attribute (deny)" 1262 cmd="cibadmin --replace --xml-file $TMPXML" 1263 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1264 1265 ### admin role ### 1266 CIB_user=bob 1267 CIB_user=root cibadmin -Q > "$TMPXML" 1268 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="nothing interesting"/>' 1269 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql 1270 1271 desc="$CIB_user: Replace - create attribute (direct allow)" 1272 cmd="cibadmin --replace -o resources --xml-file $TMPXML" 1273 test_assert $CRM_EX_OK 0 1274 1275 CIB_user=root cibadmin -Q > "$TMPXML" 1276 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="something interesting"/>' 1277 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql 1278 1279 desc="$CIB_user: Replace - modify attribute (direct allow)" 1280 cmd="cibadmin --replace -o resources --xml-file $TMPXML" 1281 test_assert $CRM_EX_OK 0 1282 1283 CIB_user=root cibadmin -Q > "$TMPXML" 1284 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace -o resources --xml-text '<primitive id="dummy" class="ocf" provider="pacemaker" type="Dummy"/>' 1285 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql 1286 1287 desc="$CIB_user: Replace - delete attribute (direct allow)" 1288 cmd="cibadmin --replace -o resources --xml-file $TMPXML" 1289 test_assert $CRM_EX_OK 0 1290 1291 ### super_user role ### 1292 export CIB_user=joe 1293 1294 CIB_user=root cibadmin -Q > "$TMPXML" 1295 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="nothing interesting"/>' 1296 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql 1297 1298 desc="$CIB_user: Replace - create attribute (inherited allow)" 1299 cmd="cibadmin --replace -o resources --xml-file $TMPXML" 1300 test_assert $CRM_EX_OK 0 1301 1302 CIB_user=root cibadmin -Q > "$TMPXML" 1303 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="something interesting"/>' 1304 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql 1305 1306 desc="$CIB_user: Replace - modify attribute (inherited allow)" 1307 cmd="cibadmin --replace -o resources --xml-file $TMPXML" 1308 test_assert $CRM_EX_OK 0 1309 1310 CIB_user=root cibadmin -Q > "$TMPXML" 1311 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace -o resources --xml-text '<primitive id="dummy" class="ocf" provider="pacemaker" type="Dummy"/>' 1312 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql 1313 1314 desc="$CIB_user: Replace - delete attribute (inherited allow)" 1315 cmd="cibadmin --replace -o resources --xml-file $TMPXML" 1316 test_assert $CRM_EX_OK 0 1317 1318 ### rsc_writer role ### 1319 export CIB_user=mike 1320 1321 CIB_user=root cibadmin -Q > "$TMPXML" 1322 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="nothing interesting"/>' 1323 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql 1324 1325 desc="$CIB_user: Replace - create attribute (allow overrides deny)" 1326 cmd="cibadmin --replace -o resources --xml-file $TMPXML" 1327 test_assert $CRM_EX_OK 0 1328 1329 CIB_user=root cibadmin -Q > "$TMPXML" 1330 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="something interesting"/>' 1331 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql 1332 1333 desc="$CIB_user: Replace - modify attribute (allow overrides deny)" 1334 cmd="cibadmin --replace -o resources --xml-file $TMPXML" 1335 test_assert $CRM_EX_OK 0 1336 1337 CIB_user=root cibadmin -Q > "$TMPXML" 1338 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace -o resources --xml-text '<primitive id="dummy" class="ocf" provider="pacemaker" type="Dummy"/>' 1339 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql 1340 1341 desc="$CIB_user: Replace - delete attribute (allow overrides deny)" 1342 cmd="cibadmin --replace -o resources --xml-file $TMPXML" 1343 test_assert $CRM_EX_OK 0 1344 1345 ### rsc_denied role ### 1346 export CIB_user=chris 1347 1348 CIB_user=root cibadmin -Q > "$TMPXML" 1349 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="nothing interesting"/>' 1350 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql 1351 1352 desc="$CIB_user: Replace - create attribute (deny overrides allow)" 1353 cmd="cibadmin --replace -o resources --xml-file $TMPXML" 1354 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1355 1356 # Set as root since setting as chris failed 1357 CIB_user=root cibadmin --modify --xml-text '<primitive id="dummy" description="nothing interesting"/>' 1358 1359 CIB_user=root cibadmin -Q > "$TMPXML" 1360 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="something interesting"/>' 1361 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql 1362 1363 desc="$CIB_user: Replace - modify attribute (deny overrides allow)" 1364 cmd="cibadmin --replace -o resources --xml-file $TMPXML" 1365 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1366 1367 # Set as root since setting as chris failed 1368 CIB_user=root cibadmin --modify --xml-text '<primitive id="dummy" description="something interesting"/>' 1369 1370 CIB_user=root cibadmin -Q > "$TMPXML" 1371 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace -o resources --xml-text '<primitive id="dummy" class="ocf" provider="pacemaker" type="Dummy"/>' 1372 CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql 1373 1374 desc="$CIB_user: Replace - delete attribute (deny overrides allow)" 1375 cmd="cibadmin --replace -o resources --xml-file $TMPXML" 1376 test_assert $CRM_EX_INSUFFICIENT_PRIV 0 1377} 1378 1379function test_acls() { 1380 local SHADOWPATH 1381 local TMPXML 1382 1383 TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.acls.xml.XXXXXXXXXX) 1384 1385 create_shadow_cib pacemaker-1.3 1386 1387 cat <<EOF > "$TMPXML" 1388 <acls> 1389 <acl_user id="l33t-haxor"> 1390 <deny id="crook-nothing" xpath="/cib"/> 1391 </acl_user> 1392 <acl_user id="niceguy"> 1393 <role_ref id="observer"/> 1394 </acl_user> 1395 <acl_user id="bob"> 1396 <role_ref id="admin"/> 1397 </acl_user> 1398 <acl_user id="joe"> 1399 <role_ref id="super_user"/> 1400 </acl_user> 1401 <acl_user id="mike"> 1402 <role_ref id="rsc_writer"/> 1403 </acl_user> 1404 <acl_user id="chris"> 1405 <role_ref id="rsc_denied"/> 1406 </acl_user> 1407 <acl_role id="observer"> 1408 <read id="observer-read-1" xpath="/cib"/> 1409 <write id="observer-write-1" xpath="//nvpair[@name='stonith-enabled']"/> 1410 <write id="observer-write-2" xpath="//nvpair[@name='target-role']"/> 1411 </acl_role> 1412 <acl_role id="admin"> 1413 <read id="admin-read-1" xpath="/cib"/> 1414 <write id="admin-write-1" xpath="//resources"/> 1415 </acl_role> 1416 <acl_role id="super_user"> 1417 <write id="super_user-write-1" xpath="/cib"/> 1418 </acl_role> 1419 <acl_role id="rsc_writer"> 1420 <deny id="rsc-writer-deny-1" xpath="/cib"/> 1421 <write id="rsc-writer-write-1" xpath="//resources"/> 1422 </acl_role> 1423 <acl_role id="rsc_denied"> 1424 <write id="rsc-denied-write-1" xpath="/cib"/> 1425 <deny id="rsc-denied-deny-1" xpath="//resources"/> 1426 </acl_role> 1427 </acls> 1428EOF 1429 1430 desc="Configure some ACLs" 1431 cmd="cibadmin -M -o acls --xml-file $TMPXML" 1432 test_assert $CRM_EX_OK 1433 1434 desc="Enable ACLs" 1435 cmd="crm_attribute -n enable-acl -v true" 1436 test_assert $CRM_EX_OK 1437 1438 desc="Set cluster option" 1439 cmd="crm_attribute -n no-quorum-policy -v ignore" 1440 test_assert $CRM_EX_OK 1441 1442 desc="New ACL" 1443 cmd="cibadmin --create -o acls --xml-text '<acl_user id=\"badidea\"><read id=\"badidea-resources\" xpath=\"//meta_attributes\"/></acl_user>'" 1444 test_assert $CRM_EX_OK 1445 1446 desc="Another ACL" 1447 cmd="cibadmin --create -o acls --xml-text '<acl_user id=\"betteridea\"><read id=\"betteridea-resources\" xpath=\"//meta_attributes\"/></acl_user>'" 1448 test_assert $CRM_EX_OK 1449 1450 desc="Updated ACL" 1451 cmd="cibadmin --replace -o acls --xml-text '<acl_user id=\"betteridea\"><deny id=\"betteridea-nothing\" xpath=\"/cib\"/><read id=\"betteridea-resources\" xpath=\"//meta_attributes\"/></acl_user>'" 1452 test_assert $CRM_EX_OK 1453 1454 test_acl_loop "$TMPXML" 1455 1456 printf "\n\n !#!#!#!#! Upgrading to latest CIB schema and re-testing !#!#!#!#!\n" 1457 printf "\nUpgrading to latest CIB schema and re-testing\n" 1>&2 1458 1459 export CIB_user=root 1460 desc="$CIB_user: Upgrade to latest CIB schema" 1461 cmd="cibadmin --upgrade --force -V" 1462 test_assert $CRM_EX_OK 1463 1464 reset_shadow_cib_version 1465 1466 test_acl_loop "$TMPXML" 1467 1468 unset CIB_shadow_dir 1469 rm -f "$TMPXML" 1470} 1471 1472function test_validity() { 1473 local TMPGOOD 1474 local TMPBAD 1475 1476 TMPGOOD=$(mktemp ${TMPDIR:-/tmp}/cts-cli.validity.good.xml.XXXXXXXXXX) 1477 TMPBAD=$(mktemp ${TMPDIR:-/tmp}/cts-cli.validity.bad.xml.XXXXXXXXXX) 1478 1479 create_shadow_cib pacemaker-1.2 1480 export PCMK_trace_functions=apply_upgrade,update_validation,cli_config_update 1481 export PCMK_stderr=1 1482 1483 cibadmin -C -o resources --xml-text '<primitive id="dummy1" class="ocf" provider="pacemaker" type="Dummy"/>' 1484 cibadmin -C -o resources --xml-text '<primitive id="dummy2" class="ocf" provider="pacemaker" type="Dummy"/>' 1485 cibadmin -C -o constraints --xml-text '<rsc_order id="ord_1-2" first="dummy1" first-action="start" then="dummy2"/>' 1486 cibadmin -Q > "$TMPGOOD" 1487 1488 1489 desc="Try to make resulting CIB invalid (enum violation)" 1490 cmd="cibadmin -M -o constraints --xml-text '<rsc_order id=\"ord_1-2\" first=\"dummy1\" first-action=\"break\" then=\"dummy2\"/>'" 1491 test_assert $CRM_EX_CONFIG 1492 1493 sed 's|"start"|"break"|' "$TMPGOOD" > "$TMPBAD" 1494 desc="Run crm_simulate with invalid CIB (enum violation)" 1495 cmd="crm_simulate -x $TMPBAD -S" 1496 test_assert $CRM_EX_CONFIG 0 1497 1498 1499 desc="Try to make resulting CIB invalid (unrecognized validate-with)" 1500 cmd="cibadmin -M --xml-text '<cib validate-with=\"pacemaker-9999.0\"/>'" 1501 test_assert $CRM_EX_CONFIG 1502 1503 sed 's|"pacemaker-1.2"|"pacemaker-9999.0"|' "$TMPGOOD" > "$TMPBAD" 1504 desc="Run crm_simulate with invalid CIB (unrecognized validate-with)" 1505 cmd="crm_simulate -x $TMPBAD -S" 1506 test_assert $CRM_EX_CONFIG 0 1507 1508 1509 desc="Try to make resulting CIB invalid, but possibly recoverable (valid with X.Y+1)" 1510 cmd="cibadmin -C -o configuration --xml-text '<tags/>'" 1511 test_assert $CRM_EX_CONFIG 1512 1513 sed 's|</configuration>|<tags/></configuration>|' "$TMPGOOD" > "$TMPBAD" 1514 desc="Run crm_simulate with invalid, but possibly recoverable CIB (valid with X.Y+1)" 1515 cmd="crm_simulate -x $TMPBAD -S" 1516 test_assert $CRM_EX_OK 0 1517 1518 1519 sed 's|[ ][ ]*validate-with="[^"]*"||' "$TMPGOOD" > "$TMPBAD" 1520 desc="Make resulting CIB valid, although without validate-with attribute" 1521 cmd="cibadmin -R --xml-file $TMPBAD" 1522 test_assert $CRM_EX_OK 1523 1524 desc="Run crm_simulate with valid CIB, but without validate-with attribute" 1525 cmd="crm_simulate -x $TMPBAD -S" 1526 test_assert $CRM_EX_OK 0 1527 1528 1529 # this will just disable validation and accept the config, outputting 1530 # validation errors 1531 sed -e 's|[ ][ ]*validate-with="[^"]*"||' \ 1532 -e 's|\([ ][ ]*epoch="[^"]*\)"|\10"|' -e 's|"start"|"break"|' \ 1533 "$TMPGOOD" > "$TMPBAD" 1534 desc="Make resulting CIB invalid, and without validate-with attribute" 1535 cmd="cibadmin -R --xml-file $TMPBAD" 1536 test_assert $CRM_EX_OK 1537 1538 desc="Run crm_simulate with invalid CIB, also without validate-with attribute" 1539 cmd="crm_simulate -x $TMPBAD -S" 1540 test_assert $CRM_EX_OK 0 1541 1542 unset CIB_shadow_dir 1543 rm -f "$TMPGOOD" "$TMPBAD" 1544} 1545 1546test_upgrade() { 1547 local TMPXML 1548 1549 TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX) 1550 1551 create_shadow_cib pacemaker-2.10 1552 1553 desc="Set stonith-enabled=false" 1554 cmd="crm_attribute -n stonith-enabled -v false" 1555 test_assert $CRM_EX_OK 1556 1557 cat <<EOF > "$TMPXML" 1558 <resources> 1559 <primitive id="mySmartFuse" class="ocf" provider="experiment" type="SmartFuse"> 1560 <operations> 1561 <op id="mySmartFuse-start" name="start" interval="0" timeout="40s"/> 1562 <op id="mySmartFuse-monitor-inputpower" name="monitor" interval="30s"> 1563 <instance_attributes id="mySmartFuse-inputpower-instanceparams"> 1564 <nvpair id="mySmartFuse-inputpower-requires" name="requires" value="inputpower"/> 1565 </instance_attributes> 1566 </op> 1567 <op id="mySmartFuse-monitor-outputpower" name="monitor" interval="2s"> 1568 <instance_attributes id="mySmartFuse-outputpower-instanceparams"> 1569 <nvpair id="mySmartFuse-outputpower-requires" name="requires" value="outputpower"/> 1570 </instance_attributes> 1571 </op> 1572 </operations> 1573 <instance_attributes id="mySmartFuse-params"> 1574 <nvpair id="mySmartFuse-params-ip" name="ip" value="192.0.2.10"/> 1575 </instance_attributes> 1576 <!-- a bit hairy but valid --> 1577 <instance_attributes id-ref="mySmartFuse-outputpower-instanceparams"/> 1578 </primitive> 1579 </resources> 1580EOF 1581 1582 desc="Configure the initial resource" 1583 cmd="cibadmin -M -o resources --xml-file $TMPXML" 1584 test_assert $CRM_EX_OK 1585 1586 desc="Upgrade to latest CIB schema (trigger 2.10.xsl + the wrapping)" 1587 cmd="cibadmin --upgrade --force -V -V" 1588 test_assert $CRM_EX_OK 1589 1590 desc="Query a resource instance attribute (shall survive)" 1591 cmd="crm_resource -r mySmartFuse -g requires" 1592 test_assert $CRM_EX_OK 1593 1594 unset CIB_shadow_dir 1595 rm -f "$TMPXML" 1596} 1597 1598test_rules() { 1599 local TMPXML 1600 1601 create_shadow_cib 1602 1603 cibadmin -C -o resources --xml-text '<primitive class="ocf" id="dummy" provider="heartbeat" type="Dummy" />' 1604 1605 TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX) 1606 cat <<EOF > "$TMPXML" 1607<rsc_location id="cli-too-many-date-expressions" rsc="dummy"> 1608 <rule id="cli-rule-too-many-date-expressions" score="INFINITY" boolean-op="or"> 1609 <date_expression id="cli-date-expression-1" operation="gt" start="2020-01-01 01:00:00 -0500"/> 1610 <date_expression id="cli-date-expression-2" operation="lt" end="2019-01-01 01:00:00 -0500"/> 1611 </rule> 1612</rsc_location> 1613EOF 1614 1615 cibadmin -C -o constraints -x "$TMPXML" 1616 rm -f "$TMPXML" 1617 1618 TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX) 1619 cat <<EOF > "$TMPXML" 1620<rsc_location id="cli-prefer-dummy-expired" rsc="dummy"> 1621 <rule id="cli-prefer-rule-dummy-expired" score="INFINITY"> 1622 <date_expression id="cli-prefer-lifetime-end-dummy-expired" operation="lt" end="2019-01-01 12:00:00 -05:00"/> 1623 </rule> 1624</rsc_location> 1625EOF 1626 1627 cibadmin -C -o constraints -x "$TMPXML" 1628 rm -f "$TMPXML" 1629 1630 if [ "$(uname)" == "FreeBSD" ]; then 1631 tomorrow=$(date -v+1d +"%F %T %z") 1632 else 1633 tomorrow=$(date --date=tomorrow +"%F %T %z") 1634 fi 1635 1636 TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX) 1637 cat <<EOF > "$TMPXML" 1638<rsc_location id="cli-prefer-dummy-not-yet" rsc="dummy"> 1639 <rule id="cli-prefer-rule-dummy-not-yet" score="INFINITY"> 1640 <date_expression id="cli-prefer-lifetime-end-dummy-not-yet" operation="gt" start="${tomorrow}"/> 1641 </rule> 1642</rsc_location> 1643EOF 1644 1645 cibadmin -C -o constraints -x "$TMPXML" 1646 rm -f "$TMPXML" 1647 1648 TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX) 1649 cat <<EOF > "$TMPXML" 1650<rsc_location id="cli-prefer-dummy-date_spec-only-years" rsc="dummy"> 1651 <rule id="cli-prefer-rule-dummy-date_spec-only-years" score="INFINITY"> 1652 <date_expression id="cli-prefer-dummy-date_spec-only-years-expr" operation="date_spec"> 1653 <date_spec id="cli-prefer-dummy-date_spec-only-years-spec" years="2019"/> 1654 </date_expression> 1655 </rule> 1656</rsc_location> 1657EOF 1658 1659 cibadmin -C -o constraints -x "$TMPXML" 1660 rm -f "$TMPXML" 1661 1662 TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX) 1663 cat <<EOF > "$TMPXML" 1664<rsc_location id="cli-prefer-dummy-date_spec-without-years" rsc="dummy"> 1665 <rule id="cli-prefer-rule-dummy-date_spec-without-years" score="INFINITY"> 1666 <date_expression id="cli-prefer-dummy-date_spec-without-years-expr" operation="date_spec"> 1667 <date_spec id="cli-prefer-dummy-date_spec-without-years-spec" hours="20" months="1,3,5,7"/> 1668 </date_expression> 1669 </rule> 1670</rsc_location> 1671EOF 1672 1673 cibadmin -C -o constraints -x "$TMPXML" 1674 rm -f "$TMPXML" 1675 1676 TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX) 1677 cat <<EOF > "$TMPXML" 1678<rsc_location id="cli-prefer-dummy-date_spec-years-moon" rsc="dummy"> 1679 <rule id="cli-prefer-rule-dummy-date_spec-years-moon" score="INFINITY"> 1680 <date_expression id="cli-prefer-dummy-date_spec-years-moon-expr" operation="date_spec"> 1681 <date_spec id="cli-prefer-dummy-date_spec-years-moon-spec" years="2019" moon="1"/> 1682 </date_expression> 1683 </rule> 1684</rsc_location> 1685EOF 1686 1687 cibadmin -C -o constraints -x "$TMPXML" 1688 rm -f "$TMPXML" 1689 1690 TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX) 1691 cat <<EOF > "$TMPXML" 1692<rsc_location id="cli-no-date_expression" rsc="dummy"> 1693 <rule id="cli-no-date_expression-rule" score="INFINITY"> 1694 <expression id="ban-apache-expr" attribute="#uname" operation="eq" value="node3"/> 1695 </rule> 1696</rsc_location> 1697EOF 1698 1699 cibadmin -C -o constraints -x "$TMPXML" 1700 rm -f "$TMPXML" 1701 1702 desc="Try to check a rule that doesn't exist" 1703 cmd="crm_rule -c -r blahblah" 1704 test_assert $CRM_EX_NOSUCH 1705 1706 desc="Try to check a rule that has too many date_expressions" 1707 cmd="crm_rule -c -r cli-rule-too-many-date-expressions" 1708 test_assert $CRM_EX_UNIMPLEMENT_FEATURE 1709 1710 desc="Verify basic rule is expired" 1711 cmd="crm_rule -c -r cli-prefer-rule-dummy-expired" 1712 test_assert $CRM_EX_EXPIRED 1713 1714 desc="Verify basic rule worked in the past" 1715 cmd="crm_rule -c -r cli-prefer-rule-dummy-expired -d 20180101" 1716 test_assert $CRM_EX_OK 1717 1718 desc="Verify basic rule is not yet in effect" 1719 cmd="crm_rule -c -r cli-prefer-rule-dummy-not-yet" 1720 test_assert $CRM_EX_NOT_YET_IN_EFFECT 1721 1722 desc="Verify date_spec rule with years has expired" 1723 cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-only-years" 1724 test_assert $CRM_EX_EXPIRED 1725 1726 desc="Verify date_spec rule with years is in effect" 1727 cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-only-years -d 20190201" 1728 test_assert $CRM_EX_OK 1729 1730 desc="Try to check a rule whose date_spec does not contain years=" 1731 cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-without-years" 1732 test_assert $CRM_EX_NOSUCH 1733 1734 desc="Try to check a rule whose date_spec contains years= and moon=" 1735 cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-years-moon" 1736 test_assert $CRM_EX_NOSUCH 1737 1738 desc="Try to check a rule with no date_expression" 1739 cmd="crm_rule -c -r cli-no-date_expression-rule" 1740 test_assert $CRM_EX_UNIMPLEMENT_FEATURE 1741 1742 unset CIB_shadow_dir 1743} 1744 1745# Process command-line arguments 1746while [ $# -gt 0 ]; do 1747 case "$1" in 1748 -t) 1749 tests="$2" 1750 shift 2 1751 ;; 1752 -V|--verbose) 1753 verbose=1 1754 shift 1755 ;; 1756 -v|--valgrind) 1757 export G_SLICE=always-malloc 1758 VALGRIND_CMD="valgrind $VALGRIND_OPTS" 1759 shift 1760 ;; 1761 -s) 1762 do_save=1 1763 shift 1764 ;; 1765 -p) 1766 export PATH="$2:$PATH" 1767 shift 1768 ;; 1769 --help) 1770 echo "$USAGE_TEXT" 1771 exit $CRM_EX_OK 1772 ;; 1773 *) 1774 echo "error: unknown option $1" 1775 echo 1776 echo "$USAGE_TEXT" 1777 exit $CRM_EX_USAGE 1778 ;; 1779 esac 1780done 1781 1782for t in $tests; do 1783 case "$t" in 1784 dates) ;; 1785 tools) ;; 1786 acls) ;; 1787 validity) ;; 1788 upgrade) ;; 1789 rules) ;; 1790 crm_mon) ;; 1791 *) 1792 echo "error: unknown test $t" 1793 echo 1794 echo "$USAGE_TEXT" 1795 exit $CRM_EX_USAGE 1796 ;; 1797 esac 1798done 1799 1800XMLLINT_CMD=$(which xmllint 2>/dev/null) 1801if [ $? -ne 0 ]; then 1802 XMLLINT_CMD="" 1803 echo "xmllint is missing - install it to validate command output" 1804fi 1805 1806# Check whether we're running from source directory 1807SRCDIR=$(dirname $test_home) 1808if [ -x "$SRCDIR/tools/crm_simulate" ]; then 1809 export PATH="$SRCDIR/tools:$PATH" 1810 echo "Using local binaries from: $SRCDIR/tools" 1811 1812 if [ -x "$SRCDIR/xml" ]; then 1813 export PCMK_schema_directory="$SRCDIR/xml" 1814 echo "Using local schemas from: $PCMK_schema_directory" 1815 fi 1816else 1817 export PCMK_schema_directory=@CRM_SCHEMA_DIRECTORY@ 1818fi 1819 1820for t in $tests; do 1821 echo "Testing $t" 1822 TMPFILE=$(mktemp ${TMPDIR:-/tmp}/cts-cli.$t.XXXXXXXXXX) 1823 eval TMPFILE_$t="$TMPFILE" 1824 test_$t > "$TMPFILE" 1825 1826 # last-rc-change= is always numeric in the CIB. However, for the crm_mon 1827 # test we also need to compare against the XML output of the crm_mon 1828 # program. There, these are shown as human readable strings (like the 1829 # output of the `date` command). 1830 sed -e 's/cib-last-written.*>/>/'\ 1831 -e 's/Last updated: .*/Last updated:/' \ 1832 -e 's/Last change: .*/Last change:/' \ 1833 -e 's/(version .*)/(version)/' \ 1834 -e 's/last_update time=\".*\"/last_update time=\"\"/' \ 1835 -e 's/last_change time=\".*\"/last_change time=\"\"/' \ 1836 -e 's/ api-version=\".*\" / api-version=\"X\" /' \ 1837 -e 's/ version=\".*\" / version=\"\" /' \ 1838 -e 's/request=\".*\(crm_[a-zA-Z0-9]*\)/request=\"\1/' \ 1839 -e 's/crm_feature_set="[^"]*" //'\ 1840 -e 's/validate-with="[^"]*" //'\ 1841 -e 's/Created new pacemaker-.* configuration/Created new pacemaker configuration/'\ 1842 -e 's/.*\(pcmk__.*\)@.*\.c:[0-9][0-9]*)/\1/g' \ 1843 -e 's/.*\(unpack_.*\)@.*\.c:[0-9][0-9]*)/\1/g' \ 1844 -e 's/.*\(update_validation\)@.*\.c:[0-9][0-9]*)/\1/g' \ 1845 -e 's/.*\(apply_upgrade\)@.*\.c:[0-9][0-9]*)/\1/g' \ 1846 -e 's/ last-rc-change=\"[A-Za-z0-9: ]*\"//'\ 1847 -e 's|^/tmp/cts-cli\.validity\.bad.xml\.[^:]*:|validity.bad.xml:|'\ 1848 -e 's/^Entity: line [0-9][0-9]*: //'\ 1849 -e 's/\(validation ([0-9][0-9]* of \)[0-9][0-9]*\().*\)/\1X\2/' \ 1850 -e 's/^Migration will take effect until: .*/Migration will take effect until:/' \ 1851 -e 's/ end=\"[0-9][-+: 0-9]*Z*\"/ end=\"\"/' \ 1852 -e 's/ start=\"[0-9][-+: 0-9]*Z*\"/ start=\"\"/' \ 1853 -e 's/^Error checking rule: Device not configured/Error checking rule: No such device or address/' \ 1854 -e 's/^lt-//' \ 1855 -e 's/ocf::/ocf:/' \ 1856 -e 's/Masters:/Promoted:/' \ 1857 -e 's/Slaves:/Unpromoted:/' \ 1858 -e 's/Master/Promoted/' \ 1859 -e 's/Slave/Unpromoted/' \ 1860 "$TMPFILE" > "${TMPFILE}.$$" 1861 mv -- "${TMPFILE}.$$" "$TMPFILE" 1862 1863 if [ $do_save -eq 1 ]; then 1864 cp "$TMPFILE" $test_home/cli/regression.$t.exp 1865 fi 1866done 1867 1868rm -rf "${shadow_dir}" 1869 1870failed=0 1871 1872if [ $verbose -eq 1 ]; then 1873 echo -e "\n\nResults" 1874fi 1875for t in $tests; do 1876 eval TMPFILE="\$TMPFILE_$t" 1877 if [ $verbose -eq 1 ]; then 1878 diff -wu $test_home/cli/regression.$t.exp "$TMPFILE" 1879 else 1880 diff -w $test_home/cli/regression.$t.exp "$TMPFILE" >/dev/null 2>&1 1881 fi 1882 if [ $? -ne 0 ]; then 1883 failed=1 1884 fi 1885done 1886 1887echo -e "\n\nSummary" 1888for t in $tests; do 1889 eval TMPFILE="\$TMPFILE_$t" 1890 grep -e '^\* \(Passed\|Failed\)' "$TMPFILE" 1891done 1892 1893if [ $num_errors -ne 0 ]; then 1894 echo "$num_errors tests failed; see output in:" 1895 for t in $tests; do 1896 eval TMPFILE="\$TMPFILE_$t" 1897 echo " $TMPFILE" 1898 done 1899 exit $CRM_EX_ERROR 1900 1901elif [ $failed -eq 1 ]; then 1902 echo "$num_passed tests passed but output was unexpected; see output in:" 1903 for t in $tests; do 1904 eval TMPFILE="\$TMPFILE_$t" 1905 echo " $TMPFILE" 1906 done 1907 exit $CRM_EX_DIGEST 1908 1909else 1910 echo $num_passed tests passed 1911 for t in $tests; do 1912 eval TMPFILE="\$TMPFILE_$t" 1913 rm -f "$TMPFILE" 1914 done 1915 crm_shadow --force --delete $shadow >/dev/null 2>&1 1916 exit $CRM_EX_OK 1917fi 1918