1#!/usr/local/bin/bash
2
3: ${shadow=tools-regression}
4test_home=`dirname $0`
5num_errors=0
6num_passed=0
7GREP_OPTIONS=
8verbose=0
9tests="dates tools acls validity"
10
11CRM_EX_OK=0
12CRM_EX_ERROR=1
13
14function test_assert() {
15    target=$1; shift
16    cib=$1; shift
17    app=`echo "$cmd" | sed 's/\ .*//'`
18    printf "* Running: $app - $desc\n" 1>&2
19
20    printf "=#=#=#= Begin test: $desc =#=#=#=\n"
21    eval $VALGRIND_CMD $cmd 2>&1
22    rc=$?
23
24    if [ x$cib != x0 ]; then
25	printf "=#=#=#= Current cib after: $desc =#=#=#=\n"
26	CIB_user=root cibadmin -Q
27    fi
28
29    printf "=#=#=#= End test: $desc - `crm_error $rc` ($rc) =#=#=#=\n"
30
31    if [ $rc -ne $target ]; then
32	num_errors=`expr $num_errors + 1`
33	printf "* Failed (rc=%.3d): %-14s - %s\n" $rc $app "$desc"
34	printf "* Failed (rc=%.3d): %-14s - %s\n" $rc $app "$desc (`which $app`)" 1>&2
35	return
36	exit 1
37    else
38	printf "* Passed: %-14s - %s\n" $app "$desc"
39
40	num_passed=`expr $num_passed + 1`
41    fi
42}
43
44function usage() {
45    echo "Usage: ./regression.sh [-s(ave)] [-x] [-v(erbose)]"
46    exit $1
47}
48
49done=0
50do_save=0
51VALGRIND_CMD=
52while test "$done" = "0"; do
53    case "$1" in
54	-t) tests=$2; shift; shift;;
55	-V|--verbose) verbose=1; shift;;
56	-v|--valgrind)
57	    export G_SLICE=always-malloc
58	    VALGRIND_CMD="valgrind -q --gen-suppressions=all --show-reachable=no --leak-check=full --trace-children=no --time-stamp=yes --num-callers=20 --suppressions=/usr/share/pacemaker/tests/valgrind-pcmk.suppressions"
59	    shift;;
60	-x) set -x; shift;;
61	-s) do_save=1; shift;;
62	-p) PATH="$2:$PATH"; export PATH; shift 1;;
63	-?) usage 0;;
64	-*) echo "unknown option: $1"; usage 1;;
65	*) done=1;;
66    esac
67done
68
69if [ "x$VALGRIND_CMD" = "x" -a -x $test_home/crm_simulate ]; then
70    xml_home=`dirname ${test_home}`
71    echo "Using local binaries from: $test_home, schemas from $xml_home"
72    export PATH="$test_home:$PATH"
73    export PCMK_schema_directory=${xml_home}/xml
74fi
75
76function test_tools() {
77    export CIB_shadow_dir=$test_home
78    $VALGRIND_CMD crm_shadow --batch --force --create-empty $shadow  2>&1
79    export CIB_shadow=$shadow
80
81    desc="Validate CIB"
82    cmd="cibadmin -Q"
83    test_assert 0
84
85    desc="Configure something before erasing"
86    cmd="crm_attribute -n cluster-delay -v 60s"
87    test_assert 0
88
89    desc="Require --force for CIB erasure"
90    cmd="cibadmin -E"
91    test_assert 22
92
93    desc="Allow CIB erasure with --force"
94    cmd="cibadmin -E --force"
95    test_assert 0
96
97    desc="Query CIB"
98    cmd="cibadmin -Q > /tmp/$$.existing.xml"
99    test_assert 0
100
101    desc="Set cluster option"
102    cmd="crm_attribute -n cluster-delay -v 60s"
103    test_assert 0
104
105    desc="Query new cluster option"
106    cmd="cibadmin -Q -o crm_config | grep cib-bootstrap-options-cluster-delay"
107    test_assert 0
108
109    desc="Query cluster options"
110    cmd="cibadmin -Q -o crm_config > /tmp/$$.opt.xml"
111    test_assert 0
112
113    desc="Set no-quorum policy"
114    cmd="crm_attribute -n no-quorum-policy -v ignore"
115    test_assert 0
116
117    desc="Delete nvpair"
118    cmd="cibadmin -D -o crm_config --xml-text '<nvpair id=\"cib-bootstrap-options-cluster-delay\"/>'"
119    test_assert 0
120
121    desc="Create operaton should fail"
122    cmd="cibadmin -C -o crm_config --xml-file /tmp/$$.opt.xml"
123    test_assert 76
124
125    desc="Modify cluster options section"
126    cmd="cibadmin -M -o crm_config --xml-file /tmp/$$.opt.xml"
127    test_assert 0
128
129    desc="Query updated cluster option"
130    cmd="cibadmin -Q -o crm_config | grep cib-bootstrap-options-cluster-delay"
131    test_assert 0
132
133    desc="Set duplicate cluster option"
134    cmd="crm_attribute -n cluster-delay -v 40s -s duplicate"
135    test_assert 0
136
137    desc="Setting multiply defined cluster option should fail"
138    cmd="crm_attribute -n cluster-delay -v 30s"
139    test_assert 76
140
141    desc="Set cluster option with -s"
142    cmd="crm_attribute -n cluster-delay -v 30s -s duplicate"
143    test_assert 0
144
145    desc="Delete cluster option with -i"
146    cmd="crm_attribute -n cluster-delay -D -i cib-bootstrap-options-cluster-delay"
147    test_assert 0
148
149    desc="Create node1 and bring it online"
150    cmd="crm_simulate --live-check --in-place --node-up=node1"
151    test_assert 0
152
153    desc="Create node attribute"
154    cmd="crm_attribute -n ram -v 1024M -U node1 -t nodes"
155    test_assert 0
156
157    desc="Query new node attribute"
158    cmd="cibadmin -Q -o nodes | grep node1-ram"
159    test_assert 0
160
161    desc="Set a transient (fail-count) node attribute"
162    cmd="crm_attribute -n fail-count-foo -v 3 -N node1 -t status"
163    test_assert 0
164
165    desc="Query a fail count"
166    cmd="crm_failcount --query -r foo -N node1"
167    test_assert 0
168
169    desc="Delete a transient (fail-count) node attribute"
170    cmd="crm_attribute -n fail-count-foo -D -N node1 -t status"
171    test_assert 0
172
173    desc="Digest calculation"
174    cmd="cibadmin -Q | cibadmin -5 -p 2>&1 > /dev/null"
175    test_assert 0
176
177    # This update will fail because it has version numbers
178    desc="Replace operation should fail"
179    cmd="cibadmin -R --xml-file /tmp/$$.existing.xml"
180    test_assert 205
181
182    desc="Default standby value"
183    cmd="crm_standby -N node1 -G"
184    test_assert 0
185
186    desc="Set standby status"
187    cmd="crm_standby -N node1 -v true"
188    test_assert 0
189
190    desc="Query standby value"
191    cmd="crm_standby -N node1 -G"
192    test_assert 0
193
194    desc="Delete standby value"
195    cmd="crm_standby -N node1 -D"
196    test_assert 0
197
198    desc="Create a resource"
199    cmd="cibadmin -C -o resources --xml-text '<primitive id=\"dummy\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/>'"
200    test_assert 0
201
202    desc="Create a resource meta attribute"
203    cmd="crm_resource -r dummy --meta -p is-managed -v false"
204    test_assert 0
205
206    desc="Query a resource meta attribute"
207    cmd="crm_resource -r dummy --meta -g is-managed"
208    test_assert 0
209
210    desc="Remove a resource meta attribute"
211    cmd="crm_resource -r dummy --meta -d is-managed"
212    test_assert 0
213
214    desc="Create a resource attribute"
215    cmd="crm_resource -r dummy -p delay -v 10s"
216    test_assert 0
217
218    desc="List the configured resources"
219    cmd="crm_resource -L"
220    test_assert 0
221
222    desc="Require a destination when migrating a resource that is stopped"
223    cmd="crm_resource -r dummy -M"
224    test_assert 22
225
226    desc="Don't support migration to non-existent locations"
227    cmd="crm_resource -r dummy -M -N i.dont.exist"
228    test_assert 6
229
230    desc="Create a fencing resource"
231    cmd="cibadmin -C -o resources --xml-text '<primitive id=\"Fence\" class=\"stonith\" type=\"fence_true\"/>'"
232    test_assert 0
233
234    desc="Bring resources online"
235    cmd="crm_simulate --live-check --in-place -S"
236    test_assert 0
237
238    desc="Try to move a resource to its existing location"
239    cmd="crm_resource -r dummy --move --host node1"
240    test_assert 22
241
242    desc="Move a resource from its existing location"
243    cmd="crm_resource -r dummy --move"
244    test_assert 0
245
246    desc="Clear out constraints generated by --move"
247    cmd="crm_resource -r dummy --clear"
248    test_assert 0
249
250    desc="Default ticket granted state"
251    cmd="crm_ticket -t ticketA -G granted -d false"
252    test_assert 0
253
254    desc="Set ticket granted state"
255    cmd="crm_ticket -t ticketA -r --force"
256    test_assert 0
257
258    desc="Query ticket granted state"
259    cmd="crm_ticket -t ticketA -G granted"
260    test_assert 0
261
262    desc="Delete ticket granted state"
263    cmd="crm_ticket -t ticketA -D granted --force"
264    test_assert 0
265
266    desc="Make a ticket standby"
267    cmd="crm_ticket -t ticketA -s"
268    test_assert 0
269
270    desc="Query ticket standby state"
271    cmd="crm_ticket -t ticketA -G standby"
272    test_assert 0
273
274    desc="Activate a ticket"
275    cmd="crm_ticket -t ticketA -a"
276    test_assert 0
277
278    desc="Delete ticket standby state"
279    cmd="crm_ticket -t ticketA -D standby"
280    test_assert 0
281
282    desc="Ban a resource on unknown node"
283    cmd="crm_resource -r dummy -B -N host1"
284    test_assert 6
285
286    desc="Create two more nodes and bring them online"
287    cmd="crm_simulate --live-check --in-place --node-up=node2 --node-up=node3"
288    test_assert 0
289
290    desc="Ban dummy from node1"
291    cmd="crm_resource -r dummy -B -N node1"
292    test_assert 0
293
294    desc="Ban dummy from node2"
295    cmd="crm_resource -r dummy -B -N node2"
296    test_assert 0
297
298    desc="Relocate resources due to ban"
299    cmd="crm_simulate --live-check --in-place -S"
300    test_assert 0
301
302    desc="Move dummy to node1"
303    cmd="crm_resource -r dummy -M -N node1"
304    test_assert 0
305
306    desc="Clear implicit constraints for dummy on node2"
307    cmd="crm_resource -r dummy -U -N node2"
308    test_assert 0
309
310    desc="Drop the status section"
311    cmd="cibadmin -R -o status --xml-text '<status/>'"
312    test_assert 0 0
313
314    desc="Create a clone"
315    cmd="cibadmin -C -o resources --xml-text '<clone id=\"test-clone\"><primitive id=\"test-primitive\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/></clone>'"
316    test_assert 0 0
317
318    desc="Create a resource meta attribute"
319    cmd="crm_resource -r test-primitive --meta -p is-managed -v false"
320    test_assert 0
321
322    desc="Create a resource meta attribute in the primitive"
323    cmd="crm_resource -r test-primitive --meta -p is-managed -v false --force"
324    test_assert 0
325
326    desc="Update resource meta attribute with duplicates"
327    cmd="crm_resource -r test-clone --meta -p is-managed -v true"
328    test_assert 0
329
330    desc="Update resource meta attribute with duplicates (force clone)"
331    cmd="crm_resource -r test-clone --meta -p is-managed -v true --force"
332    test_assert 0
333
334    desc="Update child resource meta attribute with duplicates"
335    cmd="crm_resource -r test-primitive --meta -p is-managed -v false"
336    test_assert 0
337
338    desc="Delete resource meta attribute with duplicates"
339    cmd="crm_resource -r test-clone --meta -d is-managed"
340    test_assert 0
341
342    desc="Delete resource meta attribute in parent"
343    cmd="crm_resource -r test-primitive --meta -d is-managed"
344    test_assert 0
345
346    desc="Create a resource meta attribute in the primitive"
347    cmd="crm_resource -r test-primitive --meta -p is-managed -v false --force"
348    test_assert 0
349
350    desc="Update existing resource meta attribute"
351    cmd="crm_resource -r test-clone --meta -p is-managed -v true"
352    test_assert 0
353
354    desc="Create a resource meta attribute in the parent"
355    cmd="crm_resource -r test-clone --meta -p is-managed -v true --force"
356    test_assert 0
357
358    desc="Copy resources"
359    cmd="cibadmin -Q -o resources > /tmp/$$.resources.xml"
360    test_assert 0 0
361
362    desc="Delete resource paremt meta attribute (force)"
363    cmd="crm_resource -r test-clone --meta -d is-managed --force"
364    test_assert 0
365
366    desc="Restore duplicates"
367    cmd="cibadmin -R -o resources --xml-file /tmp/$$.resources.xml"
368    test_assert 0
369
370    desc="Delete resource child meta attribute"
371    cmd="crm_resource -r test-primitive --meta -d is-managed"
372    test_assert 0
373
374    desc="Specify a lifetime when moving a resource"
375    cmd="crm_resource -r dummy --move --node node2 --lifetime=PT1H"
376    test_assert $CRM_EX_OK
377
378    desc="Try to move a resource previously moved with a lifetime"
379    cmd="crm_resource -r dummy --move --node node1"
380    test_assert $CRM_EX_OK
381
382    desc="Ban dummy from node1 for a short time"
383    cmd="crm_resource -r dummy -B -N node1 --lifetime=PT1S"
384    test_assert $CRM_EX_OK
385
386    desc="Remove expired constraints"
387    sleep 2
388    cmd="crm_resource --clear --expired"
389    test_assert $CRM_EX_OK
390
391    rm -f /tmp/$$.existing.xml /tmp/$$.resources.xml
392
393    desc="Create an XML patchset"
394    cmd="crm_diff -o $test_home/crm_diff_old.xml -n $test_home/crm_diff_new.xml"
395    test_assert $CRM_EX_ERROR 0
396}
397
398function test_dates() {
399    desc="2014-01-01 00:30:00 - 1 Hour"
400    cmd="iso8601 -d '2014-01-01 00:30:00Z' -D P-1H -E '2013-12-31 23:30:00Z'"
401    test_assert 0 0
402
403    for y in 06 07 08 09 10 11 12 13 14 15 16 17 18; do
404	desc="20$y-W01-7"
405	cmd="iso8601 -d '20$y-W01-7 00Z'"
406	test_assert 0 0
407
408	desc="20$y-W01-7 - round-trip"
409	cmd="iso8601 -d '20$y-W01-7 00Z' -W -E '20$y-W01-7 00:00:00Z'"
410	test_assert 0 0
411
412	desc="20$y-W01-1"
413	cmd="iso8601 -d '20$y-W01-1 00Z'"
414	test_assert 0 0
415
416	desc="20$y-W01-1 - round-trip"
417	cmd="iso8601 -d '20$y-W01-1 00Z' -W -E '20$y-W01-1 00:00:00Z'"
418	test_assert 0 0
419    done
420
421    desc="2009-W53-07"
422    cmd="iso8601 -d '2009-W53-7 00:00:00Z' -W -E '2009-W53-7 00:00:00Z'"
423    test_assert 0 0
424
425    desc="2009-01-31 + 1 Month"
426    cmd="iso8601 -d '2009-01-31 00:00:00Z' -D P1M -E '2009-02-28 00:00:00Z'"
427    test_assert 0 0
428
429    desc="2009-01-31 + 2 Months"
430    cmd="iso8601 -d '2009-01-31 00:00:00Z' -D P2M -E '2009-03-31 00:00:00Z'"
431    test_assert 0 0
432
433    desc="2009-01-31 + 3 Months"
434    cmd="iso8601 -d '2009-01-31 00:00:00Z' -D P3M -E '2009-04-30 00:00:00Z'"
435    test_assert 0 0
436
437    desc="2009-03-31 - 1 Month"
438    cmd="iso8601 -d '2009-03-31 00:00:00Z' -D P-1M -E '2009-02-28 00:00:00Z'"
439    test_assert 0 0
440}
441
442function get_epoch() {
443    CIB_user=root CIB_file=$1 CIB_shadow="" cibadmin -Q | head -n 1 | sed -e 's/.* epoch=\"\([0-9]*\).*/\1/'
444}
445
446function restore_epoch() {
447    infile=$1; shift
448    old=$1; shift
449    new=$(get_epoch $infile)
450
451    sed -i 's/epoch=.$old/epoch=\"$new/g' $infile
452}
453
454function test_acl_loop() {
455    # Make sure we're rejecting things for the right reasons
456    export PCMK_trace_functions=pcmk__check_acl,pcmk__post_process_acl
457    export PCMK_stderr=1
458
459    CIB_user=root cibadmin --replace --xml-text '<resources/>'
460
461    export CIB_user=unknownguy
462    desc="$CIB_user: Query configuration"
463    cmd="cibadmin -Q"
464    test_assert 13 0
465
466    desc="$CIB_user: Set enable-acl"
467    cmd="crm_attribute -n enable-acl -v false"
468    test_assert 13 0
469
470    desc="$CIB_user: Set stonith-enabled"
471    cmd="crm_attribute -n stonith-enabled -v false"
472    test_assert 13 0
473
474    desc="$CIB_user: Create a resource"
475    cmd="cibadmin -C -o resources --xml-text '<primitive id=\"dummy\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/>'"
476    test_assert 13 0
477
478    export CIB_user=l33t-haxor
479    desc="$CIB_user: Query configuration"
480    cmd="cibadmin -Q"
481    test_assert 13 0
482
483    desc="$CIB_user: Set enable-acl"
484    cmd="crm_attribute -n enable-acl -v false"
485    test_assert 13 0
486
487    desc="$CIB_user: Set stonith-enabled"
488    cmd="crm_attribute -n stonith-enabled -v false"
489    test_assert 13 0
490
491    desc="$CIB_user: Create a resource"
492    cmd="cibadmin -C -o resources --xml-text '<primitive id=\"dummy\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/>'"
493    test_assert 13 0
494
495    export CIB_user=niceguy
496    desc="$CIB_user: Query configuration"
497    cmd="cibadmin -Q"
498    test_assert 0 0
499
500    desc="$CIB_user: Set enable-acl"
501    cmd="crm_attribute -n enable-acl -v false"
502    test_assert 13 0
503
504    desc="$CIB_user: Set stonith-enabled"
505    cmd="crm_attribute -n stonith-enabled -v false"
506    test_assert 0
507
508    desc="$CIB_user: Create a resource"
509    cmd="cibadmin -C -o resources --xml-text '<primitive id=\"dummy\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/>'"
510    test_assert 13 0
511
512    export CIB_user=root
513    desc="$CIB_user: Query configuration"
514    cmd="cibadmin -Q"
515    test_assert 0 0
516
517    desc="$CIB_user: Set stonith-enabled"
518    cmd="crm_attribute -n stonith-enabled -v true"
519    test_assert 0
520
521    desc="$CIB_user: Create a resource"
522    cmd="cibadmin -C -o resources --xml-text '<primitive id=\"dummy\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/>'"
523    test_assert 0
524
525    export CIB_user=l33t-haxor
526
527    desc="$CIB_user: Create a resource meta attribute"
528    cmd="crm_resource -r dummy --meta -p target-role -v Stopped"
529    test_assert 13 0
530
531    desc="$CIB_user: Query a resource meta attribute"
532    cmd="crm_resource -r dummy --meta -g target-role"
533    test_assert 13 0
534
535    desc="$CIB_user: Remove a resource meta attribute"
536    cmd="crm_resource -r dummy --meta -d target-role"
537    test_assert 13 0
538
539    export CIB_user=niceguy
540
541    desc="$CIB_user: Create a resource meta attribute"
542    cmd="crm_resource -r dummy --meta -p target-role -v Stopped"
543    test_assert 0
544
545    desc="$CIB_user: Query a resource meta attribute"
546    cmd="crm_resource -r dummy --meta -g target-role"
547    test_assert 0
548
549    desc="$CIB_user: Remove a resource meta attribute"
550    cmd="crm_resource -r dummy --meta -d target-role"
551    test_assert 0
552
553    desc="$CIB_user: Create a resource meta attribute"
554    cmd="crm_resource -r dummy --meta -p target-role -v Started"
555    test_assert 0
556
557    export CIB_user=badidea
558    desc="$CIB_user: Query configuration - implied deny"
559    cmd="cibadmin -Q"
560    test_assert 0 0
561
562    export CIB_user=betteridea
563    desc="$CIB_user: Query configuration - explicit deny"
564    cmd="cibadmin -Q"
565    test_assert 0 0
566
567    CIB_user=root cibadmin -Q > /tmp/$$.haxor.xml
568    CIB_user=root CIB_file=/tmp/$$.haxor.xml CIB_shadow="" cibadmin --delete --xml-text '<acls/>'
569    CIB_user=root CIB_file=/tmp/$$.haxor.xml CIB_shadow="" cibadmin -Ql
570
571    export CIB_user=niceguy
572    desc="$CIB_user: Replace - remove acls"
573    cmd="cibadmin --replace --xml-file /tmp/$$.haxor.xml"
574    test_assert 13 0
575
576    CIB_user=root cibadmin -Q > /tmp/$$.haxor.xml
577    CIB_user=root CIB_file=/tmp/$$.haxor.xml CIB_shadow="" cibadmin -C -o resources --xml-text '<primitive id="dummy2" class="ocf" provider="pacemaker" type="Dummy"/>'
578    CIB_user=root CIB_file=/tmp/$$.haxor.xml CIB_shadow="" cibadmin -Ql
579
580    desc="$CIB_user: Replace - create resource"
581    cmd="cibadmin --replace --xml-file /tmp/$$.haxor.xml"
582    test_assert 13 0
583
584    CIB_user=root cibadmin -Q > /tmp/$$.haxor.xml
585    CIB_user=root CIB_file=/tmp/$$.haxor.xml CIB_shadow="" crm_attribute -n enable-acl -v false
586    CIB_user=root CIB_file=/tmp/$$.haxor.xml CIB_shadow="" cibadmin -Ql
587
588    desc="$CIB_user: Replace - modify attribute (deny)"
589    cmd="cibadmin --replace --xml-file /tmp/$$.haxor.xml"
590    test_assert 13 0
591
592    CIB_user=root cibadmin -Q > /tmp/$$.haxor.xml
593    CIB_user=root CIB_file=/tmp/$$.haxor.xml CIB_shadow="" cibadmin --replace --xml-text '<nvpair id="cib-bootstrap-options-enable-acl" name="enable-acl"/>'
594    CIB_user=root CIB_file=/tmp/$$.haxor.xml CIB_shadow="" cibadmin -Ql
595
596    desc="$CIB_user: Replace - delete attribute (deny)"
597    cmd="cibadmin --replace --xml-file /tmp/$$.haxor.xml"
598    test_assert 13 0
599
600    CIB_user=root cibadmin -Q > /tmp/$$.haxor.xml
601    CIB_user=root CIB_file=/tmp/$$.haxor.xml CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="nothing interesting"/>'
602    CIB_user=root CIB_file=/tmp/$$.haxor.xml CIB_shadow="" cibadmin -Ql
603
604    desc="$CIB_user: Replace - create attribute (deny)"
605    cmd="cibadmin --replace --xml-file /tmp/$$.haxor.xml"
606    test_assert 13 0
607    rm -rf /tmp/$$.haxor.xml
608
609
610    CIB_user=bob
611    CIB_user=root cibadmin -Q > /tmp/$$.haxor.xml
612    CIB_user=root CIB_file=/tmp/$$.haxor.xml CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="nothing interesting"/>'
613    CIB_user=root CIB_file=/tmp/$$.haxor.xml CIB_shadow="" cibadmin -Ql
614
615    desc="$CIB_user: Replace - create attribute (allow)"
616    cmd="cibadmin --replace -o resources --xml-file /tmp/$$.haxor.xml"
617    test_assert 0 0
618
619    CIB_user=root cibadmin -Q > /tmp/$$.haxor.xml
620    CIB_user=root CIB_file=/tmp/$$.haxor.xml CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="something interesting"/>'
621    CIB_user=root CIB_file=/tmp/$$.haxor.xml CIB_shadow="" cibadmin -Ql
622
623    desc="$CIB_user: Replace - modify attribute (allow)"
624    cmd="cibadmin --replace -o resources --xml-file /tmp/$$.haxor.xml"
625    test_assert 0 0
626
627    CIB_user=root cibadmin -Q > /tmp/$$.haxor.xml
628    CIB_user=root CIB_file=/tmp/$$.haxor.xml CIB_shadow="" cibadmin --replace -o resources --xml-text '<primitive id="dummy" class="ocf" provider="pacemaker" type="Dummy"/>'
629    CIB_user=root CIB_file=/tmp/$$.haxor.xml CIB_shadow="" cibadmin -Ql
630
631    desc="$CIB_user: Replace - delete attribute (allow)"
632    cmd="cibadmin --replace -o resources --xml-file /tmp/$$.haxor.xml"
633    test_assert 0 0
634}
635
636function test_acls() {
637    export CIB_shadow_dir=$test_home
638    $VALGRIND_CMD crm_shadow --batch --force --create-empty $shadow --validate-with pacemaker-1.3 2>&1
639    export CIB_shadow=$shadow
640
641    cat <<EOF >/tmp/$$.acls.xml
642    <acls>
643      <acl_user id="l33t-haxor">
644        <deny id="crook-nothing" xpath="/cib"/>
645      </acl_user>
646      <acl_user id="niceguy">
647        <role_ref id="observer"/>
648      </acl_user>
649      <acl_user id="bob">
650        <role_ref id="admin"/>
651      </acl_user>
652      <acl_role id="observer">
653        <read id="observer-read-1" xpath="/cib"/>
654        <write id="observer-write-1" xpath="//nvpair[@name=&apos;stonith-enabled&apos;]"/>
655        <write id="observer-write-2" xpath="//nvpair[@name=&apos;target-role&apos;]"/>
656      </acl_role>
657      <acl_role id="admin">
658        <read id="admin-read-1" xpath="/cib"/>
659        <write id="admin-write-1" xpath="//resources"/>
660      </acl_role>
661    </acls>
662EOF
663
664    desc="Configure some ACLs"
665    cmd="cibadmin -M -o acls --xml-file /tmp/$$.acls.xml"
666    test_assert 0
667
668    desc="Enable ACLs"
669    cmd="crm_attribute -n enable-acl -v true"
670    test_assert 0
671
672    desc="Set cluster option"
673    cmd="crm_attribute -n no-quorum-policy -v ignore"
674    test_assert 0
675
676    desc="New ACL"
677    cmd="cibadmin --create -o acls --xml-text '<acl_user id=\"badidea\"><read id=\"badidea-resources\" xpath=\"//meta_attributes\"/></acl_user>'"
678    test_assert 0
679
680    desc="Another ACL"
681    cmd="cibadmin --create -o acls --xml-text '<acl_user id=\"betteridea\"><read id=\"betteridea-resources\" xpath=\"//meta_attributes\"/></acl_user>'"
682    test_assert 0
683
684    desc="Updated ACL"
685    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>'"
686    test_assert 0
687
688    test_acl_loop
689
690    printf "\n\n    !#!#!#!#! Upgrading to pacemaker-2.0 and retesting !#!#!#!#!\n"
691    printf "\nUpgrading to pacemaker-2.0 and re-testing\n" 1>&2
692
693    export CIB_user=root
694    desc="$CIB_user: Upgrade to pacemaker-2.0"
695    cmd="cibadmin --upgrade --force -V"
696    test_assert 0
697
698    sed -i 's/epoch=.2/epoch=\"6/g' $CIB_shadow_dir/shadow.$CIB_shadow
699    sed -i 's/admin_epoch=.1/admin_epoch=\"0/g' $CIB_shadow_dir/shadow.$CIB_shadow
700
701    test_acl_loop
702}
703
704function test_validity() {
705
706    export CIB_shadow_dir=$test_home
707    $VALGRIND_CMD crm_shadow --batch --force --create-empty $shadow --validate-with pacemaker-1.2 2>&1
708    export CIB_shadow=$shadow
709    export PCMK_trace_functions=update_validation,cli_config_update
710    export PCMK_stderr=1
711
712    cibadmin -C -o resources --xml-text '<primitive id="dummy1" class="ocf" provider="pacemaker" type="Dummy"/>'
713    cibadmin -C -o resources --xml-text '<primitive id="dummy2" class="ocf" provider="pacemaker" type="Dummy"/>'
714    cibadmin -C -o constraints --xml-text '<rsc_order id="ord_1-2" first="dummy1" first-action="start" then="dummy2"/>'
715    cibadmin -Q > /tmp/$$.good-1.2.xml
716
717
718    desc="Try to make resulting CIB invalid (enum violation)"
719    cmd="cibadmin -M -o constraints --xml-text '<rsc_order id=\"ord_1-2\" first=\"dummy1\" first-action=\"break\" then=\"dummy2\"/>'"
720    test_assert 203
721
722    sed 's|"start"|"break"|' /tmp/$$.good-1.2.xml > /tmp/$$.bad-1.2.xml
723    desc="Run crm_simulate with invalid CIB (enum violation)"
724    cmd="crm_simulate -x /tmp/$$.bad-1.2.xml -S"
725    test_assert 126 0
726
727
728    desc="Try to make resulting CIB invalid (unrecognized validate-with)"
729    cmd="cibadmin -M --xml-text '<cib validate-with=\"pacemaker-9999.0\"/>'"
730    test_assert 203
731
732    sed 's|"pacemaker-1.2"|"pacemaker-9999.0"|' /tmp/$$.good-1.2.xml > /tmp/$$.bad-1.2.xml
733    desc="Run crm_simulate with invalid CIB (unrecognized validate-with)"
734    cmd="crm_simulate -x /tmp/$$.bad-1.2.xml -S"
735    test_assert 126 0
736
737
738    desc="Try to make resulting CIB invalid, but possibly recoverable (valid with X.Y+1)"
739    cmd="cibadmin -C -o configuration --xml-text '<tags/>'"
740    test_assert 203
741
742    sed 's|</configuration>|<tags/>\0|' /tmp/$$.good-1.2.xml > /tmp/$$.bad-1.2.xml
743    desc="Run crm_simulate with invalid, but possibly recoverable CIB (valid with X.Y+1)"
744    cmd="crm_simulate -x /tmp/$$.bad-1.2.xml -S"
745    test_assert 0 0
746
747
748    sed 's|\s\s*validate-with="[^"]*"||' /tmp/$$.good-1.2.xml > /tmp/$$.bad-1.2.xml
749    desc="Make resulting CIB valid, although without validate-with attribute"
750    cmd="cibadmin -R --xml-file /tmp/$$.bad-1.2.xml"
751    test_assert 0
752
753    desc="Run crm_simulate with valid CIB, but without validate-with attribute"
754    cmd="crm_simulate -x /tmp/$$.bad-1.2.xml -S"
755    test_assert 0 0
756
757
758    # this will just disable validation and accept the config, outputting
759    # validation errors
760    sed -e 's|\s\s*validate-with="[^"]*"||' \
761        -e 's|\(\s\s*epoch="[^"]*\)"|\10"|' -e 's|"start"|"break"|' \
762        /tmp/$$.good-1.2.xml > /tmp/$$.bad-1.2.xml
763    desc="Make resulting CIB invalid, and without validate-with attribute"
764    cmd="cibadmin -R --xml-file /tmp/$$.bad-1.2.xml"
765    test_assert 0
766
767    desc="Run crm_simulate with invalid CIB, also without validate-with attribute"
768    cmd="crm_simulate -x /tmp/$$.bad-1.2.xml -S"
769    test_assert 0 0
770
771
772    rm -f /tmp/$$.good-1.2.xml /tmp/$$.bad-1.2.xml
773}
774
775for t in $tests; do
776    echo "Testing $t"
777    test_$t > $test_home/regression.$t.out
778
779    sed -E \
780        -i -e 's/cib-last-written.*>/>/'\
781        -e 's/ last-run=\"[0-9]*\"//'\
782        -e 's/crm_feature_set="[^"]*" //'\
783        -e 's/validate-with="[^"]*" //'\
784        -e 's/Created new pacemaker-.* configuration/Created new pacemaker configuration/'\
785        -e 's/.*error: unpack_resources:/error: unpack_resources:/g'\
786        -e 's/ last-rc-change=\"[0-9]*\"//'\
787        -e 's|^/tmp/[0-9][0-9]*\.||'\
788        -e 's/^Entity: line [0-9][0-9]*: //'\
789        -e 's/acl\.c:([0-9][0-9]*)/acl.c:NNN/' \
790        -e 's/schemas\.c:([0-9][0-9]*)/schemas.c:NNN/' \
791        -e 's/constraints\.:([0-9][0-9]*)/constraints.:NNN/' \
792        -e 's/(validation \([0-9][0-9]* of )[0-9][0-9]*(\).*)/\1X\2/' \
793        -e 's/^Migration will take effect until: .*/Migration will take effect until:/' \
794        -e 's/ end=\"[0-9][-+: 0-9]*Z*\"/ end=\"\"/' \
795	$test_home/regression.$t.out
796
797    if [ $do_save = 1 ]; then
798	cp $test_home/regression.$t.out $test_home/regression.$t.exp
799    fi
800done
801
802failed=0
803
804echo -e "\n\nResults"
805for t in $tests; do
806    if [ $do_save = 1 ]; then
807	cp $test_home/regression.$t.out $test_home/regression.$t.exp
808    fi
809    if [ $verbose = 1 ]; then
810	diff -wu $test_home/regression.$t.exp $test_home/regression.$t.out
811    else
812	diff -wu $test_home/regression.$t.exp $test_home/regression.$t.out
813    fi
814    if [ $? != 0 ]; then
815	failed=1
816    fi
817done
818
819
820echo -e "\n\nSummary"
821for t in $tests; do
822    grep -e "^*" $test_home/regression.$t.out
823done
824
825if [ $num_errors != 0 ]; then
826    echo $num_errors tests failed
827    exit 1
828elif [ $failed = 1 ]; then
829    echo $num_passed tests passed but diff failed
830    exit 2
831else
832    echo $num_passed tests passed
833    for t in $tests; do
834        rm -f "$test_home/regression.$t.out"
835    done
836    crm_shadow --force --delete $shadow >/dev/null 2>&1
837    exit 0
838fi
839