diff --git a/cts/cli/regression.upgrade.exp b/cts/cli/regression.upgrade.exp
index 6a5b4fc351..00ee754e75 100644
--- a/cts/cli/regression.upgrade.exp
+++ b/cts/cli/regression.upgrade.exp
@@ -1,165 +1,145 @@
Created new pacemaker configuration
A new shadow instance was created. To begin using it, enter the following into your shell:
export CIB_shadow=cts-cli
=#=#=#= Begin test: Set stonith-enabled=false =#=#=#=
=#=#=#= Current cib after: Set stonith-enabled=false =#=#=#=
=#=#=#= End test: Set stonith-enabled=false - OK (0) =#=#=#=
* Passed: crm_attribute - Set stonith-enabled=false
=#=#=#= Begin test: Configure the initial resource =#=#=#=
=#=#=#= Current cib after: Configure the initial resource =#=#=#=
=#=#=#= End test: Configure the initial resource - OK (0) =#=#=#=
* Passed: cibadmin - Configure the initial resource
=#=#=#= Begin test: Upgrade to latest CIB schema (trigger 2.10.xsl + the wrapping) =#=#=#=
-update_validation debug: Testing 'pacemaker-2.10' validation (13 of X)
+pcmk__update_schema debug: Schema pacemaker-2.10 validates
apply_upgrade debug: Upgrading schema from pacemaker-2.10 to pacemaker-3.0: applying pre-upgrade XSL transform upgrade-2.10-enter
apply_upgrade debug: Upgrading schema from pacemaker-2.10 to pacemaker-3.0: applying upgrade XSL transform upgrade-2.10
INFO: Resources-operation instance_attributes: mySmartFuse-monitor-inputpower (rsc=mySmartFuse, meta=mySmartFuse-inputpower-instanceparams): dropping requires
INFO: Resources-operation instance_attributes: ... only start/promote operation taken into account
INFO: Resources-operation instance_attributes: mySmartFuse-monitor-outputpower (rsc=mySmartFuse, meta=mySmartFuse-outputpower-instanceparams): dropping requires
INFO: Resources-operation instance_attributes: ... only start/promote operation taken into account
apply_upgrade debug: Upgrading schema from pacemaker-2.10 to pacemaker-3.0: applying post-upgrade XSL transform upgrade-2.10-leave
DEBUG: instance_attributes: original element pointed to with @id-ref (mySmartFuse-outputpower-instanceparams) disappeared during upgrade
apply_upgrade info: Schema upgrade from pacemaker-2.10 to pacemaker-3.0 succeeded
-update_validation debug: Testing 'pacemaker-3.0' validation (14 of X)
-update_validation debug: pacemaker-3.0-style configuration is also valid for pacemaker-3.1
-update_validation debug: Testing 'pacemaker-3.1' validation (15 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.1
-update_validation debug: pacemaker-3.1-style configuration is also valid for pacemaker-3.2
-update_validation debug: Testing 'pacemaker-3.2' validation (16 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.2
-update_validation debug: pacemaker-3.2-style configuration is also valid for pacemaker-3.3
-update_validation debug: Testing 'pacemaker-3.3' validation (17 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.3
-update_validation debug: pacemaker-3.3-style configuration is also valid for pacemaker-3.4
-update_validation debug: Testing 'pacemaker-3.4' validation (18 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.4
-update_validation debug: pacemaker-3.4-style configuration is also valid for pacemaker-3.5
-update_validation debug: Testing 'pacemaker-3.5' validation (19 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.5
-update_validation debug: pacemaker-3.5-style configuration is also valid for pacemaker-3.6
-update_validation debug: Testing 'pacemaker-3.6' validation (20 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.6
-update_validation debug: pacemaker-3.6-style configuration is also valid for pacemaker-3.7
-update_validation debug: Testing 'pacemaker-3.7' validation (21 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.7
-update_validation debug: pacemaker-3.7-style configuration is also valid for pacemaker-3.8
-update_validation debug: Testing 'pacemaker-3.8' validation (22 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.8
-update_validation debug: pacemaker-3.8-style configuration is also valid for pacemaker-3.9
-update_validation debug: Testing 'pacemaker-3.9' validation (23 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.9
-update_validation debug: pacemaker-3.9-style configuration is also valid for pacemaker-3.10
-update_validation debug: Testing 'pacemaker-3.10' validation (24 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.10
-update_validation info: Transformed the configuration schema to pacemaker-3.10
+pcmk__update_schema debug: Schema pacemaker-3.0 validates
+pcmk__update_schema debug: Schema pacemaker-3.1 validates
+pcmk__update_schema debug: Schema pacemaker-3.2 validates
+pcmk__update_schema debug: Schema pacemaker-3.3 validates
+pcmk__update_schema debug: Schema pacemaker-3.4 validates
+pcmk__update_schema debug: Schema pacemaker-3.5 validates
+pcmk__update_schema debug: Schema pacemaker-3.6 validates
+pcmk__update_schema debug: Schema pacemaker-3.7 validates
+pcmk__update_schema debug: Schema pacemaker-3.8 validates
+pcmk__update_schema debug: Schema pacemaker-3.9 validates
+pcmk__update_schema debug: Schema pacemaker-3.10 validates
+pcmk__update_schema info: Transformed the configuration schema to pacemaker-3.10
=#=#=#= Current cib after: Upgrade to latest CIB schema (trigger 2.10.xsl + the wrapping) =#=#=#=
=#=#=#= End test: Upgrade to latest CIB schema (trigger 2.10.xsl + the wrapping) - OK (0) =#=#=#=
* Passed: cibadmin - Upgrade to latest CIB schema (trigger 2.10.xsl + the wrapping)
=#=#=#= Begin test: Query a resource instance attribute (shall survive) =#=#=#=
outputpower
=#=#=#= Current cib after: Query a resource instance attribute (shall survive) =#=#=#=
=#=#=#= End test: Query a resource instance attribute (shall survive) - OK (0) =#=#=#=
* Passed: crm_resource - Query a resource instance attribute (shall survive)
diff --git a/cts/cli/regression.validity.exp b/cts/cli/regression.validity.exp
index 084c05adbc..763f577296 100644
--- a/cts/cli/regression.validity.exp
+++ b/cts/cli/regression.validity.exp
@@ -1,564 +1,470 @@
Created new pacemaker configuration
A new shadow instance was created. To begin using it, enter the following into your shell:
export CIB_shadow=cts-cli
=#=#=#= Begin test: Try to make resulting CIB invalid (enum violation) =#=#=#=
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Call failed: Update does not conform to the configured schema
=#=#=#= Current cib after: Try to make resulting CIB invalid (enum violation) =#=#=#=
=#=#=#= End test: Try to make resulting CIB invalid (enum violation) - Invalid configuration (78) =#=#=#=
* Passed: cibadmin - Try to make resulting CIB invalid (enum violation)
=#=#=#= Begin test: Run crm_simulate with invalid CIB (enum violation) =#=#=#=
-update_validation debug: Testing 'pacemaker-1.2' validation (1 of X)
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-1.2 validation failed
-update_validation debug: Testing 'pacemaker-1.3' validation (2 of X)
+pcmk__update_schema debug: Schema pacemaker-1.2 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-1.3 validation failed
-update_validation debug: Testing 'pacemaker-2.0' validation (3 of X)
+pcmk__update_schema debug: Schema pacemaker-1.3 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-2.0 validation failed
-update_validation debug: Testing 'pacemaker-2.1' validation (4 of X)
+pcmk__update_schema debug: Schema pacemaker-2.0 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-2.1 validation failed
-update_validation debug: Testing 'pacemaker-2.2' validation (5 of X)
+pcmk__update_schema debug: Schema pacemaker-2.1 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-2.2 validation failed
-update_validation debug: Testing 'pacemaker-2.3' validation (6 of X)
+pcmk__update_schema debug: Schema pacemaker-2.2 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-2.3 validation failed
-update_validation debug: Testing 'pacemaker-2.4' validation (7 of X)
+pcmk__update_schema debug: Schema pacemaker-2.3 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-2.4 validation failed
-update_validation debug: Testing 'pacemaker-2.5' validation (8 of X)
+pcmk__update_schema debug: Schema pacemaker-2.4 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-2.5 validation failed
-update_validation debug: Testing 'pacemaker-2.6' validation (9 of X)
+pcmk__update_schema debug: Schema pacemaker-2.5 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-2.6 validation failed
-update_validation debug: Testing 'pacemaker-2.7' validation (10 of X)
+pcmk__update_schema debug: Schema pacemaker-2.6 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-2.7 validation failed
-update_validation debug: Testing 'pacemaker-2.8' validation (11 of X)
+pcmk__update_schema debug: Schema pacemaker-2.7 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-2.8 validation failed
-update_validation debug: Testing 'pacemaker-2.9' validation (12 of X)
+pcmk__update_schema debug: Schema pacemaker-2.8 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-2.9 validation failed
-update_validation debug: Testing 'pacemaker-2.10' validation (13 of X)
+pcmk__update_schema debug: Schema pacemaker-2.9 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-2.10 validation failed
-update_validation debug: Testing 'pacemaker-3.0' validation (14 of X)
+pcmk__update_schema debug: Schema pacemaker-2.10 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-3.0 validation failed
-update_validation debug: Testing 'pacemaker-3.1' validation (15 of X)
+pcmk__update_schema debug: Schema pacemaker-3.0 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-3.1 validation failed
-update_validation debug: Testing 'pacemaker-3.2' validation (16 of X)
+pcmk__update_schema debug: Schema pacemaker-3.1 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-3.2 validation failed
-update_validation debug: Testing 'pacemaker-3.3' validation (17 of X)
+pcmk__update_schema debug: Schema pacemaker-3.2 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-3.3 validation failed
-update_validation debug: Testing 'pacemaker-3.4' validation (18 of X)
+pcmk__update_schema debug: Schema pacemaker-3.3 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-3.4 validation failed
-update_validation debug: Testing 'pacemaker-3.5' validation (19 of X)
+pcmk__update_schema debug: Schema pacemaker-3.4 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-3.5 validation failed
-update_validation debug: Testing 'pacemaker-3.6' validation (20 of X)
+pcmk__update_schema debug: Schema pacemaker-3.5 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-3.6 validation failed
-update_validation debug: Testing 'pacemaker-3.7' validation (21 of X)
+pcmk__update_schema debug: Schema pacemaker-3.6 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-3.7 validation failed
-update_validation debug: Testing 'pacemaker-3.8' validation (22 of X)
+pcmk__update_schema debug: Schema pacemaker-3.7 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-3.8 validation failed
-update_validation debug: Testing 'pacemaker-3.9' validation (23 of X)
+pcmk__update_schema debug: Schema pacemaker-3.8 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-3.9 validation failed
-update_validation debug: Testing 'pacemaker-3.10' validation (24 of X)
+pcmk__update_schema debug: Schema pacemaker-3.9 does not validate
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
-update_validation trace: pacemaker-3.10 validation failed
-Cannot upgrade configuration (claiming schema pacemaker-1.2) to at least pacemaker-3.0 because it does not validate with any schema from pacemaker-1.2 to pacemaker-3.10
+pcmk__update_schema debug: Schema pacemaker-3.10 does not validate
+Cannot upgrade configuration (claiming pacemaker-1.2 schema) to at least pacemaker-3.0 because it does not validate with any schema from pacemaker-1.2 to pacemaker-3.10
=#=#=#= End test: Run crm_simulate with invalid CIB (enum violation) - Invalid configuration (78) =#=#=#=
* Passed: crm_simulate - Run crm_simulate with invalid CIB (enum violation)
=#=#=#= Begin test: Try to make resulting CIB invalid (unrecognized validate-with) =#=#=#=
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Call failed: Update does not conform to the configured schema
=#=#=#= Current cib after: Try to make resulting CIB invalid (unrecognized validate-with) =#=#=#=
=#=#=#= End test: Try to make resulting CIB invalid (unrecognized validate-with) - Invalid configuration (78) =#=#=#=
* Passed: cibadmin - Try to make resulting CIB invalid (unrecognized validate-with)
=#=#=#= Begin test: Run crm_simulate with invalid CIB (unrecognized validate-with) =#=#=#=
-update_validation debug: Testing 'pacemaker-1.0' validation (0 of X)
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-1.0 validation failed
-update_validation debug: Testing 'pacemaker-1.2' validation (1 of X)
+pcmk__update_schema debug: Schema pacemaker-1.0 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-1.2 validation failed
-update_validation debug: Testing 'pacemaker-1.3' validation (2 of X)
+pcmk__update_schema debug: Schema pacemaker-1.2 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-1.3 validation failed
-update_validation debug: Testing 'pacemaker-2.0' validation (3 of X)
+pcmk__update_schema debug: Schema pacemaker-1.3 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-2.0 validation failed
-update_validation debug: Testing 'pacemaker-2.1' validation (4 of X)
+pcmk__update_schema debug: Schema pacemaker-2.0 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-2.1 validation failed
-update_validation debug: Testing 'pacemaker-2.2' validation (5 of X)
+pcmk__update_schema debug: Schema pacemaker-2.1 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-2.2 validation failed
-update_validation debug: Testing 'pacemaker-2.3' validation (6 of X)
+pcmk__update_schema debug: Schema pacemaker-2.2 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-2.3 validation failed
-update_validation debug: Testing 'pacemaker-2.4' validation (7 of X)
+pcmk__update_schema debug: Schema pacemaker-2.3 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-2.4 validation failed
-update_validation debug: Testing 'pacemaker-2.5' validation (8 of X)
+pcmk__update_schema debug: Schema pacemaker-2.4 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-2.5 validation failed
-update_validation debug: Testing 'pacemaker-2.6' validation (9 of X)
+pcmk__update_schema debug: Schema pacemaker-2.5 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-2.6 validation failed
-update_validation debug: Testing 'pacemaker-2.7' validation (10 of X)
+pcmk__update_schema debug: Schema pacemaker-2.6 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-2.7 validation failed
-update_validation debug: Testing 'pacemaker-2.8' validation (11 of X)
+pcmk__update_schema debug: Schema pacemaker-2.7 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-2.8 validation failed
-update_validation debug: Testing 'pacemaker-2.9' validation (12 of X)
+pcmk__update_schema debug: Schema pacemaker-2.8 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-2.9 validation failed
-update_validation debug: Testing 'pacemaker-2.10' validation (13 of X)
+pcmk__update_schema debug: Schema pacemaker-2.9 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-2.10 validation failed
-update_validation debug: Testing 'pacemaker-3.0' validation (14 of X)
+pcmk__update_schema debug: Schema pacemaker-2.10 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-3.0 validation failed
-update_validation debug: Testing 'pacemaker-3.1' validation (15 of X)
+pcmk__update_schema debug: Schema pacemaker-3.0 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-3.1 validation failed
-update_validation debug: Testing 'pacemaker-3.2' validation (16 of X)
+pcmk__update_schema debug: Schema pacemaker-3.1 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-3.2 validation failed
-update_validation debug: Testing 'pacemaker-3.3' validation (17 of X)
+pcmk__update_schema debug: Schema pacemaker-3.2 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-3.3 validation failed
-update_validation debug: Testing 'pacemaker-3.4' validation (18 of X)
+pcmk__update_schema debug: Schema pacemaker-3.3 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-3.4 validation failed
-update_validation debug: Testing 'pacemaker-3.5' validation (19 of X)
+pcmk__update_schema debug: Schema pacemaker-3.4 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-3.5 validation failed
-update_validation debug: Testing 'pacemaker-3.6' validation (20 of X)
+pcmk__update_schema debug: Schema pacemaker-3.5 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-3.6 validation failed
-update_validation debug: Testing 'pacemaker-3.7' validation (21 of X)
+pcmk__update_schema debug: Schema pacemaker-3.6 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-3.7 validation failed
-update_validation debug: Testing 'pacemaker-3.8' validation (22 of X)
+pcmk__update_schema debug: Schema pacemaker-3.7 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-3.8 validation failed
-update_validation debug: Testing 'pacemaker-3.9' validation (23 of X)
+pcmk__update_schema debug: Schema pacemaker-3.8 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-3.9 validation failed
-update_validation debug: Testing 'pacemaker-3.10' validation (24 of X)
+pcmk__update_schema debug: Schema pacemaker-3.9 does not validate
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
-update_validation trace: pacemaker-3.10 validation failed
-Cannot upgrade configuration (claiming schema pacemaker-9999.0) to at least pacemaker-3.0 because it does not validate with any schema from unknown to pacemaker-3.10
+pcmk__update_schema debug: Schema pacemaker-3.10 does not validate
+Cannot upgrade configuration (claiming pacemaker-9999.0 schema) to at least pacemaker-3.0 because it does not validate with any schema from unknown to pacemaker-3.10
=#=#=#= End test: Run crm_simulate with invalid CIB (unrecognized validate-with) - Invalid configuration (78) =#=#=#=
* Passed: crm_simulate - Run crm_simulate with invalid CIB (unrecognized validate-with)
=#=#=#= Begin test: Try to make resulting CIB invalid, but possibly recoverable (valid with X.Y+1) =#=#=#=
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Call failed: Update does not conform to the configured schema
=#=#=#= Current cib after: Try to make resulting CIB invalid, but possibly recoverable (valid with X.Y+1) =#=#=#=
=#=#=#= End test: Try to make resulting CIB invalid, but possibly recoverable (valid with X.Y+1) - Invalid configuration (78) =#=#=#=
* Passed: cibadmin - Try to make resulting CIB invalid, but possibly recoverable (valid with X.Y+1)
=#=#=#= Begin test: Run crm_simulate with invalid, but possibly recoverable CIB (valid with X.Y+1) =#=#=#=
-update_validation debug: Testing 'pacemaker-1.2' validation (1 of X)
element tags: Relax-NG validity error : Element configuration has extra content: tags
-update_validation trace: pacemaker-1.2 validation failed
-update_validation debug: Testing 'pacemaker-1.3' validation (2 of X)
-update_validation debug: pacemaker-1.3-style configuration is also valid for pacemaker-2.0
-update_validation debug: Testing 'pacemaker-2.0' validation (3 of X)
-update_validation debug: Configuration valid for schema: pacemaker-2.0
-update_validation debug: pacemaker-2.0-style configuration is also valid for pacemaker-2.1
-update_validation debug: Testing 'pacemaker-2.1' validation (4 of X)
-update_validation debug: Configuration valid for schema: pacemaker-2.1
-update_validation debug: pacemaker-2.1-style configuration is also valid for pacemaker-2.2
-update_validation debug: Testing 'pacemaker-2.2' validation (5 of X)
-update_validation debug: Configuration valid for schema: pacemaker-2.2
-update_validation debug: pacemaker-2.2-style configuration is also valid for pacemaker-2.3
-update_validation debug: Testing 'pacemaker-2.3' validation (6 of X)
-update_validation debug: Configuration valid for schema: pacemaker-2.3
-update_validation debug: pacemaker-2.3-style configuration is also valid for pacemaker-2.4
-update_validation debug: Testing 'pacemaker-2.4' validation (7 of X)
-update_validation debug: Configuration valid for schema: pacemaker-2.4
-update_validation debug: pacemaker-2.4-style configuration is also valid for pacemaker-2.5
-update_validation debug: Testing 'pacemaker-2.5' validation (8 of X)
-update_validation debug: Configuration valid for schema: pacemaker-2.5
-update_validation debug: pacemaker-2.5-style configuration is also valid for pacemaker-2.6
-update_validation debug: Testing 'pacemaker-2.6' validation (9 of X)
-update_validation debug: Configuration valid for schema: pacemaker-2.6
-update_validation debug: pacemaker-2.6-style configuration is also valid for pacemaker-2.7
-update_validation debug: Testing 'pacemaker-2.7' validation (10 of X)
-update_validation debug: Configuration valid for schema: pacemaker-2.7
-update_validation debug: pacemaker-2.7-style configuration is also valid for pacemaker-2.8
-update_validation debug: Testing 'pacemaker-2.8' validation (11 of X)
-update_validation debug: Configuration valid for schema: pacemaker-2.8
-update_validation debug: pacemaker-2.8-style configuration is also valid for pacemaker-2.9
-update_validation debug: Testing 'pacemaker-2.9' validation (12 of X)
-update_validation debug: Configuration valid for schema: pacemaker-2.9
-update_validation debug: pacemaker-2.9-style configuration is also valid for pacemaker-2.10
-update_validation debug: Testing 'pacemaker-2.10' validation (13 of X)
-update_validation debug: Configuration valid for schema: pacemaker-2.10
-update_validation debug: pacemaker-2.10-style configuration is also valid for pacemaker-3.0
-update_validation debug: Testing 'pacemaker-3.0' validation (14 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.0
-update_validation debug: pacemaker-3.0-style configuration is also valid for pacemaker-3.1
-update_validation debug: Testing 'pacemaker-3.1' validation (15 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.1
-update_validation debug: pacemaker-3.1-style configuration is also valid for pacemaker-3.2
-update_validation debug: Testing 'pacemaker-3.2' validation (16 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.2
-update_validation debug: pacemaker-3.2-style configuration is also valid for pacemaker-3.3
-update_validation debug: Testing 'pacemaker-3.3' validation (17 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.3
-update_validation debug: pacemaker-3.3-style configuration is also valid for pacemaker-3.4
-update_validation debug: Testing 'pacemaker-3.4' validation (18 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.4
-update_validation debug: pacemaker-3.4-style configuration is also valid for pacemaker-3.5
-update_validation debug: Testing 'pacemaker-3.5' validation (19 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.5
-update_validation debug: pacemaker-3.5-style configuration is also valid for pacemaker-3.6
-update_validation debug: Testing 'pacemaker-3.6' validation (20 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.6
-update_validation debug: pacemaker-3.6-style configuration is also valid for pacemaker-3.7
-update_validation debug: Testing 'pacemaker-3.7' validation (21 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.7
-update_validation debug: pacemaker-3.7-style configuration is also valid for pacemaker-3.8
-update_validation debug: Testing 'pacemaker-3.8' validation (22 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.8
-update_validation debug: pacemaker-3.8-style configuration is also valid for pacemaker-3.9
-update_validation debug: Testing 'pacemaker-3.9' validation (23 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.9
-update_validation debug: pacemaker-3.9-style configuration is also valid for pacemaker-3.10
-update_validation debug: Testing 'pacemaker-3.10' validation (24 of X)
-update_validation debug: Configuration valid for schema: pacemaker-3.10
-update_validation info: Transformed the configuration schema to pacemaker-3.10
+pcmk__update_schema debug: Schema pacemaker-1.2 does not validate
+pcmk__update_schema debug: Schema pacemaker-1.3 validates
+pcmk__update_schema debug: Schema pacemaker-2.0 validates
+pcmk__update_schema debug: Schema pacemaker-2.1 validates
+pcmk__update_schema debug: Schema pacemaker-2.2 validates
+pcmk__update_schema debug: Schema pacemaker-2.3 validates
+pcmk__update_schema debug: Schema pacemaker-2.4 validates
+pcmk__update_schema debug: Schema pacemaker-2.5 validates
+pcmk__update_schema debug: Schema pacemaker-2.6 validates
+pcmk__update_schema debug: Schema pacemaker-2.7 validates
+pcmk__update_schema debug: Schema pacemaker-2.8 validates
+pcmk__update_schema debug: Schema pacemaker-2.9 validates
+pcmk__update_schema debug: Schema pacemaker-2.10 validates
+pcmk__update_schema debug: Schema pacemaker-3.0 validates
+pcmk__update_schema debug: Schema pacemaker-3.1 validates
+pcmk__update_schema debug: Schema pacemaker-3.2 validates
+pcmk__update_schema debug: Schema pacemaker-3.3 validates
+pcmk__update_schema debug: Schema pacemaker-3.4 validates
+pcmk__update_schema debug: Schema pacemaker-3.5 validates
+pcmk__update_schema debug: Schema pacemaker-3.6 validates
+pcmk__update_schema debug: Schema pacemaker-3.7 validates
+pcmk__update_schema debug: Schema pacemaker-3.8 validates
+pcmk__update_schema debug: Schema pacemaker-3.9 validates
+pcmk__update_schema debug: Schema pacemaker-3.10 validates
+pcmk__update_schema info: Transformed the configuration schema to pacemaker-3.10
unpack_resources error: Resource start-up disabled since no STONITH resources have been defined
unpack_resources error: Either configure some or disable STONITH with the stonith-enabled option
unpack_resources error: NOTE: Clusters with shared data need STONITH to ensure data integrity
unpack_resources error: Resource start-up disabled since no STONITH resources have been defined
unpack_resources error: Either configure some or disable STONITH with the stonith-enabled option
unpack_resources error: NOTE: Clusters with shared data need STONITH to ensure data integrity
Current cluster status:
* Full List of Resources:
* dummy1 (ocf:pacemaker:Dummy): Stopped
* dummy2 (ocf:pacemaker:Dummy): Stopped
Transition Summary:
Executing Cluster Transition:
Revised Cluster Status:
* Full List of Resources:
* dummy1 (ocf:pacemaker:Dummy): Stopped
* dummy2 (ocf:pacemaker:Dummy): Stopped
=#=#=#= End test: Run crm_simulate with invalid, but possibly recoverable CIB (valid with X.Y+1) - OK (0) =#=#=#=
* Passed: crm_simulate - Run crm_simulate with invalid, but possibly recoverable CIB (valid with X.Y+1)
=#=#=#= Begin test: Make resulting CIB valid, although without validate-with attribute =#=#=#=
=#=#=#= Current cib after: Make resulting CIB valid, although without validate-with attribute =#=#=#=
=#=#=#= End test: Make resulting CIB valid, although without validate-with attribute - OK (0) =#=#=#=
* Passed: cibadmin - Make resulting CIB valid, although without validate-with attribute
=#=#=#= Begin test: Run crm_simulate with valid CIB, but without validate-with attribute =#=#=#=
Schema validation of configuration is disabled (enabling is encouraged and prevents common misconfigurations)
unpack_resources error: Resource start-up disabled since no STONITH resources have been defined
unpack_resources error: Either configure some or disable STONITH with the stonith-enabled option
unpack_resources error: NOTE: Clusters with shared data need STONITH to ensure data integrity
unpack_resources error: Resource start-up disabled since no STONITH resources have been defined
unpack_resources error: Either configure some or disable STONITH with the stonith-enabled option
unpack_resources error: NOTE: Clusters with shared data need STONITH to ensure data integrity
Current cluster status:
* Full List of Resources:
* dummy1 (ocf:pacemaker:Dummy): Stopped
* dummy2 (ocf:pacemaker:Dummy): Stopped
Transition Summary:
Executing Cluster Transition:
Revised Cluster Status:
* Full List of Resources:
* dummy1 (ocf:pacemaker:Dummy): Stopped
* dummy2 (ocf:pacemaker:Dummy): Stopped
=#=#=#= End test: Run crm_simulate with valid CIB, but without validate-with attribute - OK (0) =#=#=#=
* Passed: crm_simulate - Run crm_simulate with valid CIB, but without validate-with attribute
=#=#=#= Begin test: Make resulting CIB invalid, and without validate-with attribute =#=#=#=
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
=#=#=#= Current cib after: Make resulting CIB invalid, and without validate-with attribute =#=#=#=
=#=#=#= End test: Make resulting CIB invalid, and without validate-with attribute - OK (0) =#=#=#=
* Passed: cibadmin - Make resulting CIB invalid, and without validate-with attribute
=#=#=#= Begin test: Run crm_simulate with invalid CIB, also without validate-with attribute =#=#=#=
Schema validation of configuration is disabled (enabling is encouraged and prevents common misconfigurations)
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attribute first-action for element rsc_order
validity.bad.xml:10: element rsc_order: Relax-NG validity error : Element constraints has extra content: rsc_order
unpack_resources error: Resource start-up disabled since no STONITH resources have been defined
unpack_resources error: Either configure some or disable STONITH with the stonith-enabled option
unpack_resources error: NOTE: Clusters with shared data need STONITH to ensure data integrity
unpack_resources error: Resource start-up disabled since no STONITH resources have been defined
unpack_resources error: Either configure some or disable STONITH with the stonith-enabled option
unpack_resources error: NOTE: Clusters with shared data need STONITH to ensure data integrity
Current cluster status:
* Full List of Resources:
* dummy1 (ocf:pacemaker:Dummy): Stopped
* dummy2 (ocf:pacemaker:Dummy): Stopped
Transition Summary:
Executing Cluster Transition:
Revised Cluster Status:
* Full List of Resources:
* dummy1 (ocf:pacemaker:Dummy): Stopped
* dummy2 (ocf:pacemaker:Dummy): Stopped
=#=#=#= End test: Run crm_simulate with invalid CIB, also without validate-with attribute - OK (0) =#=#=#=
* Passed: crm_simulate - Run crm_simulate with invalid CIB, also without validate-with attribute
diff --git a/cts/cts-cli.in b/cts/cts-cli.in
index 8fc52f2537..519b85fe85 100755
--- a/cts/cts-cli.in
+++ b/cts/cts-cli.in
@@ -1,3613 +1,3612 @@
#!@BASH_PATH@
#
# Copyright 2008-2024 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# or later (GPLv2+) WITHOUT ANY WARRANTY.
#
# Set the exit status of a command to the exit code of the last program to
# exit non-zero. This is bash-specific.
set -o pipefail
#
# Note on portable usage of sed: GNU/POSIX/*BSD sed have a limited subset of
# compatible functionality. Do not use the -i option, alternation (\|),
# \0, or character sequences such as \n or \s.
#
USAGE_TEXT="Usage: cts-cli []
Options:
--help Display this text, then exit
-V, --verbose Display any differences from expected output
-t 'TEST [...]' Run only specified tests
(default: 'access_render daemons dates error_codes tools
crm_mon acls validity upgrade rules feature_set').
Other tests: agents (must be run in an installed environment).
-p DIR Look for executables in DIR (may be specified multiple times)
-v, --valgrind Run all commands under valgrind
-s Save actual output as expected output"
# If readlink supports -e (i.e. GNU), use it
readlink -e / >/dev/null 2>/dev/null
if [ $? -eq 0 ]; then
test_home="$(dirname "$(readlink -e "$0")")"
else
test_home="$(dirname "$0")"
fi
: ${shadow=cts-cli}
shadow_dir=$(mktemp -d ${TMPDIR:-/tmp}/cts-cli.shadow.XXXXXXXXXX)
num_errors=0
num_passed=0
verbose=0
tests="access_render daemons dates error_codes tools crm_mon acls validity"
tests="$tests upgrade rules feature_set"
do_save=0
XMLLINT_CMD=
VALGRIND_CMD=
VALGRIND_OPTS="
-q
--gen-suppressions=all
--show-reachable=no
--leak-check=full
--trace-children=no
--time-stamp=yes
--num-callers=20
--suppressions=$test_home/valgrind-pcmk.suppressions
"
# Temp files for saving a command's stdout/stderr in _test_assert()
test_assert_outfile=$(mktemp ${TMPDIR:-/tmp}/cts-cli.ta_outfile.XXXXXXXXXX)
test_assert_errfile=$(mktemp ${TMPDIR:-/tmp}/cts-cli.ta_errfile.XXXXXXXXXX)
xmllint_outfile=$(mktemp ${TMPDIR:-/tmp}/cts-cli.xmllint_outfile.XXXXXXXXXX)
# Log test errors to stderr
export PCMK_stderr=1
# Output when PCMK_trace_functions is undefined is different from when it's
# empty. Later we save the value of PCMK_trace_functions, do work, and restore
# the original value. Getting back to the initial state is simplest if we assume
# the variable is defined.
: ${PCMK_trace_functions=""}
export PCMK_trace_functions
# These constants must track crm_exit_t values
CRM_EX_OK=0
CRM_EX_ERROR=1
CRM_EX_INVALID_PARAM=2
CRM_EX_UNIMPLEMENT_FEATURE=3
CRM_EX_INSUFFICIENT_PRIV=4
CRM_EX_NOT_CONFIGURED=6
CRM_EX_USAGE=64
CRM_EX_DATAERR=65
CRM_EX_CANTCREAT=73
CRM_EX_CONFIG=78
CRM_EX_OLD=103
CRM_EX_DIGEST=104
CRM_EX_NOSUCH=105
CRM_EX_UNSAFE=107
CRM_EX_EXISTS=108
CRM_EX_MULTIPLE=109
CRM_EX_EXPIRED=110
CRM_EX_NOT_YET_IN_EFFECT=111
reset_shadow_cib_version() {
local SHADOWPATH
SHADOWPATH="$(crm_shadow --file)"
# sed -i isn't portable :-(
cp -p "$SHADOWPATH" "${SHADOWPATH}.$$" # preserve permissions
sed -e 's/epoch="[0-9]*"/epoch="1"/g' \
-e 's/num_updates="[0-9]*"/num_updates="0"/g' \
-e 's/admin_epoch="[0-9]*"/admin_epoch="0"/g' \
"$SHADOWPATH" > "${SHADOWPATH}.$$"
mv -- "${SHADOWPATH}.$$" "$SHADOWPATH"
}
# A newly created empty CIB might or might not have a rsc_defaults section
# depending on whether the --with-resource-stickiness-default configure
# option was used. To ensure regression tests behave the same either way,
# delete any rsc_defaults after creating or erasing a CIB.
delete_shadow_resource_defaults() {
cibadmin --delete --xml-text ''
# The above command might or might not bump the CIB version, so reset it
# to ensure future changes result in the same version for comparison.
reset_shadow_cib_version
}
create_shadow_cib() {
local VALIDATE_WITH
local SHADOW_CMD
CREATE_ARG="$1"
VALIDATE_WITH="$2"
export CIB_shadow_dir="${shadow_dir}"
SHADOW_CMD="$VALGRIND_CMD crm_shadow --batch --force $CREATE_ARG"
if [ -z "$VALIDATE_WITH" ]; then
$SHADOW_CMD "$shadow" 2>&1
else
$SHADOW_CMD "$shadow" --validate-with="${VALIDATE_WITH}" 2>&1
fi
export CIB_shadow="$shadow"
delete_shadow_resource_defaults
}
function _test_assert() {
target=$1; shift
validate=$1; shift
cib=$1; shift
app=$(echo "$cmd" | head -n 1 | sed 's/\ .*//')
printf "* Running: $app - $desc\n" 1>&2
printf "=#=#=#= Begin test: $desc =#=#=#=\n"
# Capture stderr and stdout separately, then print them consecutively
eval $VALGRIND_CMD $cmd > "$test_assert_outfile" 2> "$test_assert_errfile"
rc=$?
cat "$test_assert_errfile"
cat "$test_assert_outfile"
if [ x$cib != x0 ]; then
printf "=#=#=#= Current cib after: $desc =#=#=#=\n"
CIB_user=root cibadmin -Q
fi
# Do not validate if running under valgrind, even if told to do so. Valgrind
# will output a lot more stuff that is not XML, so it wouldn't validate anyway.
if [ "$validate" = "1" ] && [ "$VALGRIND_CMD" = "" ] && [ $rc = 0 ] && [ "$XMLLINT_CMD" != "" ]; then
# The sed command filters out the "- validates" line that xmllint will output
# on success. grep cannot be used here because "grep -v 'validates$'" will
# return an exit code of 1 if its input consists entirely of "- validates".
$XMLLINT_CMD --noout --relaxng \
"$PCMK_schema_directory/api/api-result.rng" "$test_assert_outfile" \
> "$xmllint_outfile" 2>&1
rc=$?
sed -n '/validates$/ !p' "$xmllint_outfile"
if [ $rc = 0 ]; then
printf "=#=#=#= End test: %s - $(crm_error --exit $rc) (%d) =#=#=#=\n" "$desc" $rc
else
printf "=#=#=#= End test: %s - Failed to validate (%d) =#=#=#=\n" "$desc" $rc
fi
else
printf "=#=#=#= End test: %s - $(crm_error --exit $rc) (%d) =#=#=#=\n" "$desc" $rc
fi
if [ $rc -ne $target ]; then
num_errors=$(( $num_errors + 1 ))
printf "* Failed (rc=%.3d): %-14s - %s\n" $rc $app "$desc"
printf "* Failed (rc=%.3d): %-14s - %s\n" $rc $app "$desc (`which $app`)" 1>&2
return
exit $CRM_EX_ERROR
else
printf "* Passed: %-14s - %s\n" $app "$desc"
num_passed=$(( $num_passed + 1 ))
fi
}
function test_assert() {
_test_assert $1 0 $2
}
function test_assert_validate() {
_test_assert $1 1 $2
}
# Tests that depend on resource agents and must be run in an installed
# environment
function test_agents() {
desc="Validate a valid resource configuration"
cmd="crm_resource --validate --class ocf --provider pacemaker --agent Dummy"
test_assert $CRM_EX_OK 0
desc="Validate a valid resource configuration (XML)"
cmd="crm_resource --validate --class ocf --provider pacemaker --agent Dummy"
cmd="$cmd --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Make the Dummy configuration invalid (op_sleep can't be a generic string)
export OCF_RESKEY_op_sleep=asdf
desc="Validate an invalid resource configuration"
cmd="crm_resource --validate --class ocf --provider pacemaker --agent Dummy"
test_assert $CRM_EX_NOT_CONFIGURED 0
desc="Validate an invalid resource configuration (XML)"
cmd="crm_resource --validate --class ocf --provider pacemaker --agent Dummy"
cmd="$cmd --output-as=xml"
test_assert_validate $CRM_EX_NOT_CONFIGURED 0
unset OCF_RESKEY_op_sleep
export OCF_RESKEY_op_sleep
}
function test_daemons() {
desc="Get CIB manager metadata"
cmd="pacemaker-based metadata"
test_assert $CRM_EX_OK 0
desc="Get controller metadata"
cmd="pacemaker-controld metadata"
test_assert $CRM_EX_OK 0
desc="Get fencer metadata"
cmd="pacemaker-fenced metadata"
test_assert $CRM_EX_OK 0
desc="Get scheduler metadata"
cmd="pacemaker-schedulerd metadata"
test_assert $CRM_EX_OK 0
}
function test_crm_mon() {
local TMPXML
export CIB_file="$test_home/cli/crm_mon.xml"
desc="Basic text output"
cmd="crm_mon -1"
test_assert $CRM_EX_OK 0
desc="XML output"
cmd="crm_mon --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output without node section"
cmd="crm_mon -1 --exclude=nodes"
test_assert $CRM_EX_OK 0
desc="XML output without the node section"
cmd="crm_mon --output-as=xml --exclude=nodes"
test_assert_validate $CRM_EX_OK 0
desc="Text output with only the node section"
cmd="crm_mon -1 --exclude=all --include=nodes"
test_assert $CRM_EX_OK 0
# The above test doesn't need to be performed for other output formats. It's
# really just a test to make sure that blank lines are correct.
desc="Complete text output"
cmd="crm_mon -1 --include=all"
test_assert $CRM_EX_OK 0
# XML includes everything already so there's no need for a complete test
desc="Complete text output with detail"
cmd="crm_mon -1R --include=all"
test_assert $CRM_EX_OK 0
# XML includes detailed output already
desc="Complete brief text output"
cmd="crm_mon -1 --include=all --brief"
test_assert $CRM_EX_OK 0
desc="Complete text output grouped by node"
cmd="crm_mon -1 --include=all --group-by-node"
test_assert $CRM_EX_OK 0
# XML does not have a brief output option
desc="Complete brief text output grouped by node"
cmd="crm_mon -1 --include=all --group-by-node --brief"
test_assert $CRM_EX_OK 0
desc="XML output grouped by node"
cmd="crm_mon -1 --output-as=xml --group-by-node"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output filtered by node"
cmd="crm_mon -1 --include=all --node=cluster01"
test_assert $CRM_EX_OK 0
desc="XML output filtered by node"
cmd="crm_mon --output-as xml --include=all --node=cluster01"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output filtered by tag"
cmd="crm_mon -1 --include=all --node=even-nodes"
test_assert $CRM_EX_OK 0
desc="XML output filtered by tag"
cmd="crm_mon --output-as=xml --include=all --node=even-nodes"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output filtered by resource tag"
cmd="crm_mon -1 --include=all --resource=fencing-rscs"
test_assert $CRM_EX_OK 0
desc="XML output filtered by resource tag"
cmd="crm_mon --output-as=xml --include=all --resource=fencing-rscs"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output filtered by node that doesn't exist"
cmd="crm_mon -1 --node=blah"
test_assert $CRM_EX_OK 0
desc="XML output filtered by node that doesn't exist"
cmd="crm_mon --output-as=xml --node=blah"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output with inactive resources"
cmd="crm_mon -1 -r"
test_assert $CRM_EX_OK 0
# XML already includes inactive resources
desc="Basic text output with inactive resources, filtered by node"
cmd="crm_mon -1 -r --node=cluster02"
test_assert $CRM_EX_OK 0
# XML already includes inactive resources
desc="Complete text output filtered by primitive resource"
cmd="crm_mon -1 --include=all --resource=Fencing"
test_assert $CRM_EX_OK 0
desc="XML output filtered by primitive resource"
cmd="crm_mon --output-as=xml --resource=Fencing"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output filtered by group resource"
cmd="crm_mon -1 --include=all --resource=exim-group"
test_assert $CRM_EX_OK 0
desc="XML output filtered by group resource"
cmd="crm_mon --output-as=xml --resource=exim-group"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output filtered by group resource member"
cmd="crm_mon -1 --include=all --resource=Public-IP"
test_assert $CRM_EX_OK 0
desc="XML output filtered by group resource member"
cmd="crm_mon --output-as=xml --resource=Email"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output filtered by clone resource"
cmd="crm_mon -1 --include=all --resource=ping-clone"
test_assert $CRM_EX_OK 0
desc="XML output filtered by clone resource"
cmd="crm_mon --output-as=xml --resource=ping-clone"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output filtered by clone resource instance"
cmd="crm_mon -1 --include=all --resource=ping"
test_assert $CRM_EX_OK 0
desc="XML output filtered by clone resource instance"
cmd="crm_mon --output-as=xml --resource=ping"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output filtered by exact clone resource instance"
cmd="crm_mon -1 --include=all --show-detail --resource=ping:0"
test_assert $CRM_EX_OK 0
desc="XML output filtered by exact clone resource instance"
cmd="crm_mon --output-as=xml --resource=ping:1"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output filtered by resource that doesn't exist"
cmd="crm_mon -1 --resource=blah"
test_assert $CRM_EX_OK 0
desc="XML output filtered by resource that doesn't exist"
cmd="crm_mon --output-as=xml --resource=blah"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output with inactive resources, filtered by tag"
cmd="crm_mon -1 -r --resource=inactive-rscs"
test_assert $CRM_EX_OK 0
desc="Basic text output with inactive resources, filtered by bundle resource"
cmd="crm_mon -1 -r --resource=httpd-bundle"
test_assert $CRM_EX_OK 0
desc="XML output filtered by inactive bundle resource"
cmd="crm_mon --output-as=xml --resource=httpd-bundle"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output with inactive resources, filtered by bundled IP address resource"
cmd="crm_mon -1 -r --resource=httpd-bundle-ip-192.168.122.131"
test_assert $CRM_EX_OK 0
desc="XML output filtered by bundled IP address resource"
cmd="crm_mon --output-as=xml --resource=httpd-bundle-ip-192.168.122.132"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output with inactive resources, filtered by bundled container"
cmd="crm_mon -1 -r --resource=httpd-bundle-docker-1"
test_assert $CRM_EX_OK 0
desc="XML output filtered by bundled container"
cmd="crm_mon --output-as=xml --resource=httpd-bundle-docker-2"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output with inactive resources, filtered by bundle connection"
cmd="crm_mon -1 -r --resource=httpd-bundle-0"
test_assert $CRM_EX_OK 0
desc="XML output filtered by bundle connection"
cmd="crm_mon --output-as=xml --resource=httpd-bundle-0"
test_assert_validate $CRM_EX_OK 0
desc="Basic text output with inactive resources, filtered by bundled primitive resource"
cmd="crm_mon -1 -r --resource=httpd"
test_assert $CRM_EX_OK 0
desc="XML output filtered by bundled primitive resource"
cmd="crm_mon --output-as=xml --resource=httpd"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output, filtered by clone name in cloned group"
cmd="crm_mon -1 --include=all --show-detail --resource=mysql-clone-group"
test_assert $CRM_EX_OK 0
desc="XML output, filtered by clone name in cloned group"
cmd="crm_mon --output-as=xml --resource=mysql-clone-group"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output, filtered by group name in cloned group"
cmd="crm_mon -1 --include=all --show-detail --resource=mysql-group"
test_assert $CRM_EX_OK 0
desc="XML output, filtered by group name in cloned group"
cmd="crm_mon --output-as=xml --resource=mysql-group"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output, filtered by exact group instance name in cloned group"
cmd="crm_mon -1 --include=all --show-detail --resource=mysql-group:1"
test_assert $CRM_EX_OK 0
desc="XML output, filtered by exact group instance name in cloned group"
cmd="crm_mon --output-as=xml --resource=mysql-group:1"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output, filtered by primitive name in cloned group"
cmd="crm_mon -1 --include=all --show-detail --resource=mysql-proxy"
test_assert $CRM_EX_OK 0
desc="XML output, filtered by primitive name in cloned group"
cmd="crm_mon --output-as=xml --resource=mysql-proxy"
test_assert_validate $CRM_EX_OK 0
desc="Complete text output, filtered by exact primitive instance name in cloned group"
cmd="crm_mon -1 --include=all --show-detail --resource=mysql-proxy:1"
test_assert $CRM_EX_OK 0
desc="XML output, filtered by exact primitive instance name in cloned group"
cmd="crm_mon --output-as=xml --resource=mysql-proxy:1"
test_assert_validate $CRM_EX_OK 0
unset CIB_file
export CIB_file="$test_home/cli/crm_mon-partial.xml"
desc="Text output of partially active resources"
cmd="crm_mon -1 --show-detail"
test_assert $CRM_EX_OK 0
desc="XML output of partially active resources"
cmd="crm_mon -1 --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Text output of partially active resources, with inactive resources"
cmd="crm_mon -1 -r --show-detail"
test_assert $CRM_EX_OK 0
# XML already includes inactive resources
desc="Complete brief text output, with inactive resources"
cmd="crm_mon -1 -r --include=all --brief --show-detail"
test_assert $CRM_EX_OK 0
# XML does not have a brief output option
desc="Text output of partially active group"
cmd="crm_mon -1 --resource=partially-active-group"
test_assert $CRM_EX_OK 0
desc="Text output of partially active group, with inactive resources"
cmd="crm_mon -1 --resource=partially-active-group -r"
test_assert $CRM_EX_OK 0
desc="Text output of active member of partially active group"
cmd="crm_mon -1 --resource=dummy-1"
test_assert $CRM_EX_OK 0
desc="Text output of inactive member of partially active group"
cmd="crm_mon -1 --resource=dummy-2 --show-detail"
test_assert $CRM_EX_OK 0
desc="Complete brief text output grouped by node, with inactive resources"
cmd="crm_mon -1 -r --include=all --group-by-node --brief --show-detail"
test_assert $CRM_EX_OK 0
desc="Text output of partially active resources, with inactive resources, filtered by node"
cmd="crm_mon -1 -r --node=cluster01"
test_assert $CRM_EX_OK 0
desc="Text output of partially active resources, filtered by node"
cmd="crm_mon -1 --output-as=xml --node=cluster01"
test_assert_validate $CRM_EX_OK 0
unset CIB_file
export CIB_file="$test_home/cli/crm_mon-unmanaged.xml"
desc="Text output of active unmanaged resource on offline node"
cmd="crm_mon -1"
test_assert $CRM_EX_OK 0
desc="XML output of active unmanaged resource on offline node"
cmd="crm_mon -1 --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Brief text output of active unmanaged resource on offline node"
cmd="crm_mon -1 --brief"
test_assert $CRM_EX_OK 0
desc="Brief text output of active unmanaged resource on offline node, grouped by node"
cmd="crm_mon -1 --brief --group-by-node"
test_assert $CRM_EX_OK 0
# Maintenance mode tests
export CIB_file=$(mktemp ${TMPDIR:-/tmp}/cts-cli.crm_mon.xml.XXXXXXXXXX)
cp "$test_home/cli/crm_mon.xml" "$CIB_file"
crm_attribute -n maintenance-mode -v true
desc="Text output of all resources with maintenance-mode enabled"
cmd="crm_mon -1 -r"
test_assert $CRM_EX_OK 0
desc="XML output of all resources with maintenance-mode enabled"
cmd="crm_mon -1 -r --output-as=xml"
test_assert_validate $CRM_EX_OK 0
crm_attribute -n maintenance-mode -v false
crm_attribute -n maintenance -N cluster02 -v true
desc="Text output of all resources with maintenance enabled for a node"
cmd="crm_mon -1 -r"
test_assert $CRM_EX_OK 0
desc="XML output of all resources with maintenance enabled for a node"
cmd="crm_mon -1 -r --output-as=xml"
test_assert_validate $CRM_EX_OK 0
rm -f "$CIB_file"
unset CIB_file
export CIB_file="$test_home/cli/crm_mon-rsc-maint.xml"
# The fence resource is excluded, for comparison
desc="Text output of all resources with maintenance meta attribute true"
cmd="crm_mon -1 -r"
test_assert $CRM_EX_OK 0
desc="XML output of all resources with maintenance meta attribute true"
cmd="crm_mon -1 -r --output-as=xml"
test_assert_validate $CRM_EX_OK 0
unset CIB_file
export CIB_file="$test_home/cli/crm_mon-T180.xml"
desc="Text output of guest node's container on different node from its"
desc="$desc remote resource"
cmd="crm_mon -1"
test_assert $CRM_EX_OK 0
desc="Complete text output of guest node's container on different node from"
desc="$desc its remote resource"
cmd="crm_mon -1 --show-detail"
test_assert $CRM_EX_OK 0
unset CIB_file
}
function test_error_codes() {
# Note: At the time of this writing, crm_error returns success even for
# unknown error codes. We don't want to cause a regression by changing that.
# Due to the way _test_assert() formats output, we need "crm_error" to be
# the first token of cmd. We can't start with a parenthesis or variable
# assignment. However, in the "list result codes" tests, we also need to
# save some output for later processing. We'll use a temp file for this.
local TMPFILE
TMPFILE=$(mktemp ${TMPDIR:-/tmp}/cts-cli.crm_error_out.XXXXXXXXXX)
# Legacy return codes
#
# Don't test unknown legacy code. FreeBSD includes a colon in strerror(),
# while other distros do not.
desc="Get legacy return code"
cmd="crm_error -- 201"
test_assert $CRM_EX_OK 0
desc="Get legacy return code (XML)"
cmd="crm_error --output-as=xml -- 201"
test_assert_validate $CRM_EX_OK 0
desc="Get legacy return code (with name)"
cmd="crm_error -n -- 201"
test_assert $CRM_EX_OK 0
desc="Get legacy return code (with name) (XML)"
cmd="crm_error -n --output-as=xml -- 201"
test_assert_validate $CRM_EX_OK 0
desc="Get multiple legacy return codes"
cmd="crm_error -- 201 202"
test_assert $CRM_EX_OK 0
desc="Get multiple legacy return codes (XML)"
cmd="crm_error --output-as=xml -- 201 202"
test_assert_validate $CRM_EX_OK 0
desc="Get multiple legacy return codes (with names)"
cmd="crm_error -n -- 201 202"
test_assert $CRM_EX_OK 0
desc="Get multiple legacy return codes (with names) (XML)"
cmd="crm_error -n --output-as=xml -- 201 202"
test_assert_validate $CRM_EX_OK 0
# We can only rely on our custom codes, so we'll spot-check codes 201-209
desc="List legacy return codes (spot check)"
cmd="crm_error -l | grep 20[1-9]"
test_assert $CRM_EX_OK 0
desc="List legacy return codes (spot check) (XML)"
cmd="crm_error -l --output-as=xml > $TMPFILE; rc=$?"
cmd="$cmd; grep -Ev ' "$TMPORIG"
desc="Set cluster option"
cmd="crm_attribute -n cluster-delay -v 60s"
test_assert $CRM_EX_OK
desc="Query new cluster option"
cmd="cibadmin -Q -o crm_config | grep cib-bootstrap-options-cluster-delay"
test_assert $CRM_EX_OK
desc="Query cluster options"
cmd="cibadmin -Q -o crm_config > $TMPXML"
test_assert $CRM_EX_OK
desc="Set no-quorum policy"
cmd="crm_attribute -n no-quorum-policy -v ignore"
test_assert $CRM_EX_OK
desc="Delete nvpair"
cmd="cibadmin -D -o crm_config --xml-text ''"
test_assert $CRM_EX_OK
desc="Create operation should fail"
cmd="cibadmin -C -o crm_config --xml-file $TMPXML"
test_assert $CRM_EX_EXISTS
desc="Modify cluster options section"
cmd="cibadmin -M -o crm_config --xml-file $TMPXML"
test_assert $CRM_EX_OK
desc="Query updated cluster option"
cmd="cibadmin -Q -o crm_config | grep cib-bootstrap-options-cluster-delay"
test_assert $CRM_EX_OK
desc="Set duplicate cluster option"
cmd="crm_attribute -n cluster-delay -v 40s -s duplicate"
test_assert $CRM_EX_OK
desc="Setting multiply defined cluster option should fail"
cmd="crm_attribute -n cluster-delay -v 30s"
test_assert $CRM_EX_MULTIPLE
desc="Set cluster option with -s"
cmd="crm_attribute -n cluster-delay -v 30s -s duplicate"
test_assert $CRM_EX_OK
desc="Delete cluster option with -i"
cmd="crm_attribute -n cluster-delay -D -i cib-bootstrap-options-cluster-delay"
test_assert $CRM_EX_OK
desc="Create node1 and bring it online"
cmd="crm_simulate --live-check --in-place --node-up=node1"
test_assert $CRM_EX_OK
desc="Create node attribute"
cmd="crm_attribute -n ram -v 1024M -N node1 -t nodes"
test_assert $CRM_EX_OK
desc="Query new node attribute"
cmd="cibadmin -Q -o nodes | grep node1-ram"
test_assert $CRM_EX_OK
desc="Create second node attribute"
cmd="crm_attribute -n rattr -v XYZ -N node1 -t nodes"
test_assert $CRM_EX_OK
desc="Query node attributes by pattern"
cmd="crm_attribute -t nodes -P 'ra.*' -N node1 --query"
test_assert $CRM_EX_OK 0
desc="Update node attributes by pattern"
cmd="crm_attribute -t nodes -P 'rat.*' -N node1 -v 10"
test_assert $CRM_EX_OK
desc="Delete node attributes by pattern"
cmd="crm_attribute -t nodes -P 'rat.*' -N node1 -D"
test_assert $CRM_EX_OK
desc="Set a transient (fail-count) node attribute"
cmd="crm_attribute -n fail-count-foo -v 3 -N node1 -t status"
test_assert $CRM_EX_OK
desc="Query a fail count"
cmd="crm_failcount --query -r foo -N node1"
test_assert $CRM_EX_OK
desc="Show node attributes with crm_simulate"
cmd="crm_simulate --live-check --show-attrs"
test_assert $CRM_EX_OK 0
desc="Set a second transient node attribute"
cmd="crm_attribute -n fail-count-bar -v 5 -N node1 -t status"
test_assert $CRM_EX_OK
desc="Query transient node attributes by pattern"
cmd="crm_attribute -t status -P fail-count -N node1 --query"
test_assert $CRM_EX_OK 0
desc="Update transient node attributes by pattern"
cmd="crm_attribute -t status -P fail-count -N node1 -v 10"
test_assert $CRM_EX_OK
desc="Delete transient node attributes by pattern"
cmd="crm_attribute -t status -P fail-count -N node1 -D"
test_assert $CRM_EX_OK
desc="crm_attribute given invalid delete usage"
cmd="crm_attribute -t nodes -N node1 -D"
test_assert $CRM_EX_USAGE 0
desc="Set a utilization node attribute"
cmd="crm_attribute -n cpu -v 1 -N node1 -z"
test_assert $CRM_EX_OK
desc="Query utilization node attribute"
cmd="crm_attribute --query -n cpu -N node1 -z"
test_assert $CRM_EX_OK 0
desc="Digest calculation"
cmd="cibadmin -Q | cibadmin -5 -p 2>&1 > /dev/null"
test_assert $CRM_EX_OK
# This update will fail because it has version numbers
desc="Replace operation should fail"
cmd="cibadmin -R --xml-file $TMPORIG"
test_assert $CRM_EX_OLD
desc="Default standby value"
cmd="crm_standby -N node1 -G"
test_assert $CRM_EX_OK
desc="Set standby status"
cmd="crm_standby -N node1 -v true"
test_assert $CRM_EX_OK
desc="Query standby value"
cmd="crm_standby -N node1 -G"
test_assert $CRM_EX_OK
desc="Delete standby value"
cmd="crm_standby -N node1 -D"
test_assert $CRM_EX_OK
desc="Create a resource"
cmd="cibadmin -C -o resources --xml-text ''"
test_assert $CRM_EX_OK
desc="crm_resource run with extra arguments"
cmd="crm_resource foo bar"
test_assert $CRM_EX_USAGE 0
desc="List all available resource options (invalid type)"
cmd="crm_resource --list-options=asdf"
test_assert $CRM_EX_USAGE 0
desc="List all available resource options (invalid type) (XML)"
cmd="crm_resource --list-options=asdf --output-as=xml"
test_assert_validate $CRM_EX_USAGE 0
desc="List non-advanced primitive meta-attributes"
cmd="crm_resource --list-options=primitive"
test_assert $CRM_EX_OK 0
desc="List non-advanced primitive meta-attributes (XML) (shows all)"
cmd="crm_resource --list-options=primitive --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="List all available primitive meta-attributes"
cmd="crm_resource --list-options=primitive --all"
test_assert $CRM_EX_OK 0
desc="List all available primitive meta-attributes (XML)"
cmd="crm_resource --list-options=primitive --all --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="List non-advanced fencing parameters"
cmd="crm_resource --list-options=fencing"
test_assert $CRM_EX_OK 0
desc="List non-advanced fencing parameters (XML) (shows all)"
cmd="crm_resource --list-options=fencing --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="List all available fencing parameters"
cmd="crm_resource --list-options=fencing --all"
test_assert $CRM_EX_OK 0
desc="List all available fencing parameters (XML)"
cmd="crm_resource --list-options=fencing --all --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="crm_resource given both -r and resource config"
cmd="crm_resource -r xyz --class ocf --provider pacemaker --agent Dummy"
test_assert $CRM_EX_USAGE 0
desc="crm_resource given resource config with invalid action"
cmd="crm_resource --class ocf --provider pacemaker --agent Dummy -D"
test_assert $CRM_EX_USAGE 0
desc="Create a resource meta attribute"
cmd="crm_resource -r dummy --meta -p is-managed -v false"
test_assert $CRM_EX_OK
desc="Query a resource meta attribute"
cmd="crm_resource -r dummy --meta -g is-managed"
test_assert $CRM_EX_OK
desc="Remove a resource meta attribute"
cmd="crm_resource -r dummy --meta -d is-managed"
test_assert $CRM_EX_OK
desc="Create another resource meta attribute"
cmd="crm_resource -r dummy --meta -p target-role -v Stopped --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Show why a resource is not running"
cmd="crm_resource -Y -r dummy --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Remove another resource meta attribute"
cmd="crm_resource -r dummy --meta -d target-role --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Get a non-existent attribute from a resource element with output-as=xml"
cmd="crm_resource -r dummy --get-parameter nonexistent --element --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Get a non-existent attribute from a resource element without output-as=xml"
cmd="crm_resource -r dummy --get-parameter nonexistent --element"
test_assert $CRM_EX_OK
desc="Get an existent attribute from a resource element with output-as=xml"
cmd="crm_resource -r dummy --get-parameter class --element --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Get an existent attribute from a resource element without output-as=xml"
cmd="crm_resource -r dummy --get-parameter class --element"
test_assert $CRM_EX_OK
desc="Set a non-existent attribute for a resource element with output-as=xml"
cmd="crm_resource -r dummy --set-parameter=description -v test_description --element --output-as=xml"
test_assert_validate $CRM_EX_OK
desc="Set an existent attribute for a resource element with output-as=xml"
cmd="crm_resource -r dummy --set-parameter=description -v test_description --element --output-as=xml"
test_assert_validate $CRM_EX_OK
desc="Delete an existent attribute for a resource element with output-as=xml"
cmd="crm_resource -r dummy -d description --element --output-as=xml"
test_assert_validate $CRM_EX_OK
desc="Delete a non-existent attribute for a resource element with output-as=xml"
cmd="crm_resource -r dummy -d description --element --output-as=xml"
test_assert_validate $CRM_EX_OK
desc="Set a non-existent attribute for a resource element without output-as=xml"
cmd="crm_resource -r dummy --set-parameter=description -v test_description --element"
test_assert $CRM_EX_OK
desc="Set an existent attribute for a resource element without output-as=xml"
cmd="crm_resource -r dummy --set-parameter=description -v test_description --element"
test_assert $CRM_EX_OK
desc="Delete an existent attribute for a resource element without output-as=xml"
cmd="crm_resource -r dummy -d description --element"
test_assert $CRM_EX_OK
desc="Delete a non-existent attribute for a resource element without output-as=xml"
cmd="crm_resource -r dummy -d description --element"
test_assert $CRM_EX_OK
desc="Create a resource attribute"
cmd="crm_resource -r dummy -p delay -v 10s"
test_assert $CRM_EX_OK
desc="List the configured resources"
cmd="crm_resource -L"
test_assert $CRM_EX_OK
desc="List the configured resources in XML"
cmd="crm_resource -L --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Implicitly list the configured resources"
cmd="crm_resource"
test_assert $CRM_EX_OK 0
desc="List IDs of instantiated resources"
cmd="crm_resource -l"
test_assert $CRM_EX_OK 0
desc="Show XML configuration of resource"
cmd="crm_resource -q -r dummy"
test_assert $CRM_EX_OK 0
desc="Show XML configuration of resource, output as XML"
cmd="crm_resource -q -r dummy --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Require a destination when migrating a resource that is stopped"
cmd="crm_resource -r dummy -M"
test_assert $CRM_EX_USAGE
desc="Don't support migration to non-existent locations"
cmd="crm_resource -r dummy -M -N i.do.not.exist"
test_assert $CRM_EX_NOSUCH
desc="Create a fencing resource"
cmd="cibadmin -C -o resources --xml-text ''"
test_assert $CRM_EX_OK
desc="Bring resources online"
cmd="crm_simulate --live-check --in-place -S"
test_assert $CRM_EX_OK
desc="Try to move a resource to its existing location"
cmd="crm_resource -r dummy --move --node node1"
test_assert $CRM_EX_EXISTS
desc="Try to move a resource that doesn't exist"
cmd="crm_resource -r xyz --move --node node1"
test_assert $CRM_EX_NOSUCH 0
desc="Move a resource from its existing location"
cmd="crm_resource -r dummy --move"
test_assert $CRM_EX_OK
desc="Clear out constraints generated by --move"
cmd="crm_resource -r dummy --clear"
test_assert $CRM_EX_OK
desc="Default ticket granted state"
cmd="crm_ticket -t ticketA -G granted -d false"
test_assert $CRM_EX_OK
desc="Set ticket granted state"
cmd="crm_ticket -t ticketA -r --force"
test_assert $CRM_EX_OK
desc="List ticket IDs"
cmd="crm_ticket -w"
test_assert $CRM_EX_OK 0
desc="List ticket IDs, outputting in XML"
cmd="crm_ticket -w --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Query ticket state"
cmd="crm_ticket -t ticketA -q"
test_assert $CRM_EX_OK 0
desc="Query ticket state, outputting as xml"
cmd="crm_ticket -t ticketA -q --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Query ticket granted state"
cmd="crm_ticket -t ticketA -G granted"
test_assert $CRM_EX_OK
desc="Query ticket granted state, outputting as xml"
cmd="crm_ticket -t ticketA -G granted --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Delete ticket granted state"
cmd="crm_ticket -t ticketA -D granted --force"
test_assert $CRM_EX_OK
desc="Make a ticket standby"
cmd="crm_ticket -t ticketA -s"
test_assert $CRM_EX_OK
desc="Query ticket standby state"
cmd="crm_ticket -t ticketA -G standby"
test_assert $CRM_EX_OK
desc="Activate a ticket"
cmd="crm_ticket -t ticketA -a"
test_assert $CRM_EX_OK
desc="List ticket details"
cmd="crm_ticket -L -t ticketA"
test_assert $CRM_EX_OK 0
desc="List ticket details, outputting as XML"
cmd="crm_ticket -L -t ticketA --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Add a second ticket"
cmd="crm_ticket -t ticketB -G granted -d false"
test_assert $CRM_EX_OK
desc="Set second ticket granted state"
cmd="crm_ticket -t ticketB -r --force"
test_assert $CRM_EX_OK
desc="List tickets"
cmd="crm_ticket -l"
test_assert $CRM_EX_OK 0
desc="List tickets, outputting as XML"
cmd="crm_ticket -l --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Delete second ticket"
cmd="cibadmin --delete --xml-text ''"
test_assert $CRM_EX_OK
desc="Delete ticket standby state"
cmd="crm_ticket -t ticketA -D standby"
test_assert $CRM_EX_OK
esc="Add a constraint to a ticket"
cmd="cibadmin -C -o constraints --xml-text ''"
test_assert $CRM_EX_OK
desc="Query ticket constraints"
cmd="crm_ticket -t ticketA -c"
test_assert $CRM_EX_OK 0
desc="Query ticket constraints, outputting as xml"
cmd="crm_ticket -t ticketA -c --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Delete ticket constraint"
cmd="cibadmin --delete --xml-text ''"
test_assert $CRM_EX_OK
desc="Ban a resource on unknown node"
cmd="crm_resource -r dummy -B -N host1"
test_assert $CRM_EX_NOSUCH
desc="Create two more nodes and bring them online"
cmd="crm_simulate --live-check --in-place --node-up=node2 --node-up=node3"
test_assert $CRM_EX_OK
desc="Ban dummy from node1"
cmd="crm_resource -r dummy -B -N node1"
test_assert $CRM_EX_OK
desc="Show where a resource is running"
cmd="crm_resource -r dummy -W"
test_assert $CRM_EX_OK 0
desc="Show constraints on a resource"
cmd="crm_resource -a -r dummy"
test_assert $CRM_EX_OK 0
desc="Ban dummy from node2"
cmd="crm_resource -r dummy -B -N node2 --output-as=xml"
test_assert_validate $CRM_EX_OK
desc="Relocate resources due to ban"
cmd="crm_simulate --live-check --in-place -S"
test_assert $CRM_EX_OK
desc="Move dummy to node1"
cmd="crm_resource -r dummy -M -N node1 --output-as=xml"
test_assert_validate $CRM_EX_OK
desc="Clear implicit constraints for dummy on node2"
cmd="crm_resource -r dummy -U -N node2"
test_assert $CRM_EX_OK
desc="Drop the status section"
cmd="cibadmin -R -o status --xml-text ''"
test_assert $CRM_EX_OK 0
desc="Create a clone"
cmd="cibadmin -C -o resources --xml-text ''"
test_assert $CRM_EX_OK 0
desc="Create a resource meta attribute"
cmd="crm_resource -r test-primitive --meta -p is-managed -v false"
test_assert $CRM_EX_OK
desc="Create a resource meta attribute in the primitive"
cmd="crm_resource -r test-primitive --meta -p is-managed -v false --force"
test_assert $CRM_EX_OK
desc="Update resource meta attribute with duplicates"
cmd="crm_resource -r test-clone --meta -p is-managed -v true"
test_assert $CRM_EX_OK
desc="Update resource meta attribute with duplicates (force clone)"
cmd="crm_resource -r test-clone --meta -p is-managed -v true --force"
test_assert $CRM_EX_OK
desc="Update child resource meta attribute with duplicates"
cmd="crm_resource -r test-primitive --meta -p is-managed -v false"
test_assert $CRM_EX_OK
desc="Delete resource meta attribute with duplicates"
cmd="crm_resource -r test-clone --meta -d is-managed"
test_assert $CRM_EX_OK
desc="Delete resource meta attribute in parent"
cmd="crm_resource -r test-primitive --meta -d is-managed"
test_assert $CRM_EX_OK
desc="Create a resource meta attribute in the primitive"
cmd="crm_resource -r test-primitive --meta -p is-managed -v false --force"
test_assert $CRM_EX_OK
desc="Update existing resource meta attribute"
cmd="crm_resource -r test-clone --meta -p is-managed -v true"
test_assert $CRM_EX_OK
desc="Create a resource meta attribute in the parent"
cmd="crm_resource -r test-clone --meta -p is-managed -v true --force"
test_assert $CRM_EX_OK
desc="Copy resources"
cmd="cibadmin -Q -o resources > $TMPXML"
test_assert $CRM_EX_OK 0
desc="Delete resource parent meta attribute (force)"
cmd="crm_resource -r test-clone --meta -d is-managed --force"
test_assert $CRM_EX_OK
desc="Restore duplicates"
cmd="cibadmin -R -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK
desc="Delete resource child meta attribute"
cmd="crm_resource -r test-primitive --meta -d is-managed"
test_assert $CRM_EX_OK
desc="Create the dummy-group resource group"
cmd="cibadmin -C -o resources --xml-text '"
cmd="$cmd "
cmd="$cmd "
cmd="$cmd '"
test_assert $CRM_EX_OK
desc="Create a resource meta attribute in dummy1"
cmd="crm_resource -r dummy1 --meta -p is-managed -v true"
test_assert $CRM_EX_OK
desc="Create a resource meta attribute in dummy-group"
cmd="crm_resource -r dummy-group --meta -p is-managed -v false"
test_assert $CRM_EX_OK
desc="Delete the dummy-group resource group"
cmd="cibadmin -D -o resources --xml-text ''"
test_assert $CRM_EX_OK
desc="Specify a lifetime when moving a resource"
cmd="crm_resource -r dummy --move --node node2 --lifetime=PT1H"
test_assert $CRM_EX_OK
desc="Try to move a resource previously moved with a lifetime"
cmd="crm_resource -r dummy --move --node node1"
test_assert $CRM_EX_OK
desc="Ban dummy from node1 for a short time"
cmd="crm_resource -r dummy -B -N node1 --lifetime=PT1S"
test_assert $CRM_EX_OK
desc="Remove expired constraints"
sleep 2
cmd="crm_resource --clear --expired"
test_assert $CRM_EX_OK
# Clear has already been tested elsewhere, but we need to get rid of the
# constraints so testing delete works. It won't delete if there's still
# a reference to the resource somewhere.
desc="Clear all implicit constraints for dummy"
cmd="crm_resource -r dummy -U"
test_assert $CRM_EX_OK
desc="Set a node health strategy"
cmd="crm_attribute -n node-health-strategy -v migrate-on-red"
test_assert $CRM_EX_OK
desc="Set a node health attribute"
cmd="crm_attribute -N node3 -n '#health-cts-cli' -v red"
test_assert $CRM_EX_OK
desc="Show why a resource is not running on an unhealthy node"
cmd="crm_resource -N node3 -Y -r dummy --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Delete a resource"
cmd="crm_resource -D -r dummy -t primitive"
test_assert $CRM_EX_OK
unset CIB_shadow
unset CIB_shadow_dir
desc="Create an XML patchset"
cmd="crm_diff -o $test_home/cli/crm_diff_old.xml -n $test_home/cli/crm_diff_new.xml"
test_assert $CRM_EX_ERROR 0
export CIB_file="$test_home/cli/constraints.xml"
for rsc in prim1 prim2 prim3 prim4 prim5 prim6 prim7 prim8 prim9 \
prim10 prim11 prim12 prim13 group clone; do
desc="Check locations and constraints for $rsc"
cmd="crm_resource -a -r $rsc"
test_assert $CRM_EX_OK 0
desc="Recursively check locations and constraints for $rsc"
cmd="crm_resource -A -r $rsc"
test_assert $CRM_EX_OK 0
desc="Check locations and constraints for $rsc in XML"
cmd="crm_resource -a -r $rsc --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Recursively check locations and constraints for $rsc in XML"
cmd="crm_resource -A -r $rsc --output-as=xml"
test_assert_validate $CRM_EX_OK 0
done
desc="Check locations and constraints for group member (referring to group)"
cmd="crm_resource -a -r gr2"
test_assert $CRM_EX_OK 0
desc="Check locations and constraints for group member (without referring to group)"
cmd="crm_resource -a -r gr2 --force"
test_assert $CRM_EX_OK 0
# Create a shadow CIB based on constraints.xml
create_shadow_cib --create
unset CIB_file
desc="Set a meta-attribute for primitive and resources colocated with it"
cmd="crm_resource -r prim5 --meta --set-parameter=target-role -v Stopped --recursive"
test_assert $CRM_EX_OK 0
desc="Set a meta-attribute for group and resource colocated with it"
cmd="crm_resource -r group --meta --set-parameter=target-role -v Stopped --recursive"
test_assert $CRM_EX_OK 0
desc="Set a meta-attribute for clone and resource colocated with it"
cmd="crm_resource -r clone --meta --set-parameter=target-role -v Stopped --recursive"
test_assert $CRM_EX_OK 0
unset CIB_shadow
unset CIB_shadow_dir
export CIB_file="$test_home/cli/crm_resource_digests.xml"
desc="Show resource digests"
cmd="crm_resource --digests -r rsc1 -N node1 --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Show resource digests with overrides"
cmd="$cmd CRM_meta_interval=10000 CRM_meta_timeout=20000"
test_assert $CRM_EX_OK 0
desc="Show resource operations"
cmd="crm_resource --list-operations"
test_assert $CRM_EX_OK 0
desc="Show resource operations (XML)"
cmd="crm_resource --list-operations --output-as=xml"
test_assert_validate $CRM_EX_OK 0
unset CIB_file
export CIB_file="$test_home/cli/crmadmin-cluster-remote-guest-nodes.xml"
desc="List all nodes"
cmd="crmadmin -N"
test_assert $CRM_EX_OK 0
desc="Minimally list all nodes"
cmd="crmadmin -N -q"
test_assert $CRM_EX_OK 0
desc="List all nodes as bash exports"
cmd="crmadmin -N -B"
test_assert $CRM_EX_OK 0
desc="List cluster nodes"
cmd="crmadmin -N cluster | wc -l | grep 6"
test_assert $CRM_EX_OK 0
desc="List guest nodes"
cmd="crmadmin -N guest | wc -l | grep 2"
test_assert $CRM_EX_OK 0
desc="List remote nodes"
cmd="crmadmin -N remote | wc -l | grep 3"
test_assert $CRM_EX_OK 0
desc="List cluster,remote nodes"
cmd="crmadmin -N cluster,remote | wc -l | grep 9"
test_assert $CRM_EX_OK 0
desc="List guest,remote nodes"
cmd="crmadmin -N guest,remote | wc -l | grep 5"
test_assert $CRM_EX_OK 0
unset CIB_file
export CIB_file="$test_home/cli/crm_mon.xml"
export CIB_shadow_dir="${shadow_dir}"
desc="Show allocation scores with crm_simulate"
cmd="crm_simulate -x $CIB_file --show-scores --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Show utilization with crm_simulate"
cmd="crm_simulate -x $CIB_file --show-utilization"
test_assert $CRM_EX_OK 0
desc="Simulate injecting a failure"
cmd="crm_simulate -x $CIB_file -S -i ping_monitor_10000@cluster02=1"
test_assert $CRM_EX_OK 0
desc="Simulate bringing a node down"
cmd="crm_simulate -x $CIB_file -S --node-down=cluster01"
test_assert $CRM_EX_OK 0
desc="Simulate a node failing"
cmd="crm_simulate -x $CIB_file -S --node-fail=cluster02"
test_assert $CRM_EX_OK 0
unset CIB_shadow_dir
desc="List a promotable clone resource"
cmd="crm_resource --locate -r promotable-clone"
test_assert $CRM_EX_OK 0
desc="List the primitive of a promotable clone resource"
cmd="crm_resource --locate -r promotable-rsc"
test_assert $CRM_EX_OK 0
desc="List a single instance of a promotable clone resource"
cmd="crm_resource --locate -r promotable-rsc:0"
test_assert $CRM_EX_OK 0
desc="List another instance of a promotable clone resource"
cmd="crm_resource --locate -r promotable-rsc:1"
test_assert $CRM_EX_OK 0
desc="List a promotable clone resource in XML"
cmd="crm_resource --locate -r promotable-clone --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="List the primitive of a promotable clone resource in XML"
cmd="crm_resource --locate -r promotable-rsc --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="List a single instance of a promotable clone resource in XML"
cmd="crm_resource --locate -r promotable-rsc:0 --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="List another instance of a promotable clone resource in XML"
cmd="crm_resource --locate -r promotable-rsc:1 --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Try to move an instance of a cloned resource"
cmd="crm_resource -r promotable-rsc:0 --move --node node1"
test_assert $CRM_EX_INVALID_PARAM 0
# Create a sandbox copy of crm_mon.xml
cibadmin -Q > "$TMPXML"
export CIB_file="$TMPXML"
desc="Query a nonexistent promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G"
test_assert $CRM_EX_NOSUCH 0
desc="Query a nonexistent promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
desc="Delete a nonexistent promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -D"
test_assert $CRM_EX_OK 0
desc="Delete a nonexistent promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -D --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Query after deleting a nonexistent promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G"
test_assert $CRM_EX_NOSUCH 0
desc="Query after deleting a nonexistent promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
desc="Update a nonexistent promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -v 1"
test_assert $CRM_EX_OK 0
desc="Update a nonexistent promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -v 1 --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Query after updating a nonexistent promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G"
test_assert $CRM_EX_OK 0
desc="Query after updating a nonexistent promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Update an existing promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -v 5"
test_assert $CRM_EX_OK 0
desc="Update an existing promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -v 5 --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Query after updating an existing promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G"
test_assert $CRM_EX_OK 0
desc="Query after updating an existing promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Delete an existing promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -D"
test_assert $CRM_EX_OK 0
desc="Delete an existing promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -D --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Query after deleting an existing promotable score attribute"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G"
test_assert $CRM_EX_NOSUCH 0
desc="Query after deleting an existing promotable score attribute (XML)"
cmd="crm_attribute -N cluster01 -p promotable-rsc -G --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
# Test for an issue with legacy command line parsing when the resource is
# specified in the environment (CLBZ#5509)
export OCF_RESOURCE_INSTANCE=promotable-rsc
desc="Update a promotable score attribute to -INFINITY"
cmd="crm_attribute -N cluster01 -p -v -INFINITY"
test_assert $CRM_EX_OK 0
desc="Update a promotable score attribute to -INFINITY (XML)"
cmd="crm_attribute -N cluster01 -p -v -INFINITY --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Query after updating a promotable score attribute to -INFINITY"
cmd="crm_attribute -N cluster01 -p -G"
test_assert $CRM_EX_OK 0
desc="Query after updating a promotable score attribute to -INFINITY (XML)"
cmd="crm_attribute -N cluster01 -p -G --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Try OCF_RESOURCE_INSTANCE if -p is specified with an empty string"
cmd="crm_attribute -N cluster01 -p '' -G"
test_assert $CRM_EX_OK 0
export OCF_RESOURCE_INSTANCE=""
desc="Return usage error if both -p and OCF_RESOURCE_INSTANCE are empty strings"
cmd="crm_attribute -N cluster01 -p '' -G"
test_assert $CRM_EX_USAGE 0
unset CIB_file
unset OCF_RESOURCE_INSTANCE
export CIB_file="-"
desc="Check that CIB_file=\"-\" works - crm_mon"
cmd="cat $test_home/cli/crm_mon.xml | crm_mon -1"
test_assert $CRM_EX_OK 0
desc="Check that CIB_file=\"-\" works - crm_resource"
cmd="cat $test_home/cli/crm_resource_digests.xml | crm_resource --digests -r rsc1 -N node1 --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Check that CIB_file=\"-\" works - crmadmin"
cmd="cat $test_home/cli/crmadmin-cluster-remote-guest-nodes.xml | crmadmin -N | wc -l | grep 11"
test_assert $CRM_EX_OK 0
unset CIB_file
rm -f "$TMPXML" "$TMPORIG"
# crm_shadow tests
unset CIB_shadow
unset CIB_shadow_dir
# Query with no active shadow instance
desc="Get active shadow instance (no active instance)"
cmd="crm_shadow --which"
test_assert $CRM_EX_NOSUCH 0
desc="Get active shadow instance (no active instance) (XML)"
cmd="crm_shadow --which --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
desc="Get active shadow instance's file name (no active instance)"
cmd="crm_shadow --file"
test_assert $CRM_EX_NOSUCH 0
desc="Get active shadow instance's file name (no active instance) (XML)"
cmd="crm_shadow --file --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
desc="Get active shadow instance's contents (no active instance)"
cmd="crm_shadow --display"
test_assert $CRM_EX_NOSUCH 0
desc="Get active shadow instance's contents (no active instance) (XML)"
cmd="crm_shadow --display --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
desc="Get active shadow instance's diff (no active instance)"
cmd="crm_shadow --diff"
test_assert $CRM_EX_NOSUCH 0
desc="Get active shadow instance's diff (no active instance) (XML)"
cmd="crm_shadow --diff --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
# Create new shadow instance based on active CIB
# Don't use create_shadow_cib() here; test explicitly
export CIB_file="$test_home/cli/crm_mon.xml"
export CIB_shadow="$shadow"
export CIB_shadow_dir="$shadow_dir"
# Delete the shadow file if it already exists
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
desc="Create copied shadow instance"
cmd="crm_shadow --create $shadow --batch"
test_assert $CRM_EX_OK 0
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
desc="Create copied shadow instance (XML)"
cmd="crm_shadow --create $shadow --batch --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Query shadow instance based on active CIB
desc="Get active shadow instance (copied)"
cmd="crm_shadow --which"
test_assert $CRM_EX_OK 0
desc="Get active shadow instance (copied) (XML)"
cmd="crm_shadow --which --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Get active shadow instance's file name (copied)"
cmd="crm_shadow --file"
test_assert $CRM_EX_OK 0
desc="Get active shadow instance's file name (copied) (XML)"
cmd="crm_shadow --file --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Get active shadow instance's contents (copied)"
cmd="crm_shadow --display"
test_assert $CRM_EX_OK 0
desc="Get active shadow instance's contents (copied) (XML)"
cmd="crm_shadow --display --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Get active shadow instance's diff (copied)"
cmd="crm_shadow --diff"
test_assert $CRM_EX_OK 0
desc="Get active shadow instance's diff (copied) (XML)"
cmd="crm_shadow --diff --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Make some changes to the shadow file
export CIB_file="$(crm_shadow --file)"
cibadmin --modify --xml-text ''
cibadmin --delete --xml-text ''
cibadmin --create -o resources --xml-text \
''
state=""
cibadmin --create -o status --xml-text "$state"
unset state
export CIB_file="$test_home/cli/crm_mon.xml"
desc="Get active shadow instance's diff (after changes)"
cmd="crm_shadow --diff"
test_assert $CRM_EX_ERROR 0
desc="Get active shadow instance's diff (after changes) (XML)"
cmd="crm_shadow --diff --output-as=xml"
test_assert_validate $CRM_EX_ERROR 0
# Commit the modified shadow CIB to a temp active CIB file
cp "$test_home/cli/crm_mon.xml" "$TMPXML"
export CIB_file="$TMPXML"
desc="Commit shadow instance"
cmd="crm_shadow --commit $shadow"
test_assert $CRM_EX_USAGE 0
desc="Commit shadow instance (force)"
cmd="crm_shadow --commit $shadow --force"
test_assert $CRM_EX_OK 0
desc="Get active shadow instance's diff (after commit)"
cmd="crm_shadow --diff"
test_assert $CRM_EX_ERROR 0
desc="Commit shadow instance (force) (all)"
cmd="crm_shadow --commit $shadow --force --all"
test_assert $CRM_EX_OK 0
desc="Get active shadow instance's diff (after commit all)"
cmd="crm_shadow --diff"
test_assert $CRM_EX_ERROR 0
# Repeat sequence with XML output
cp "$test_home/cli/crm_mon.xml" "$TMPXML"
export CIB_file="$TMPXML"
desc="Commit shadow instance (XML)"
cmd="crm_shadow --commit $shadow --output-as=xml"
test_assert_validate $CRM_EX_USAGE 0
desc="Commit shadow instance (force) (XML)"
cmd="crm_shadow --commit $shadow --force --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Get active shadow instance's diff (after commit) (XML)"
cmd="crm_shadow --diff --output-as=xml"
test_assert_validate $CRM_EX_ERROR 0
desc="Commit shadow instance (force) (all) (XML)"
cmd="crm_shadow --commit $shadow --force --all --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Get active shadow instance's diff (after commit all) (XML)"
cmd="crm_shadow --diff --output-as=xml"
test_assert_validate $CRM_EX_ERROR 0
# Commit an inactive shadow instance with no active instance
unset CIB_shadow
desc="Commit shadow instance (no active instance)"
cmd="crm_shadow --commit $shadow"
test_assert $CRM_EX_USAGE 0
desc="Commit shadow instance (no active instance) (force)"
cmd="crm_shadow --commit $shadow --force"
test_assert $CRM_EX_OK 0
desc="Commit shadow instance (no active instance) (XML)"
cmd="crm_shadow --commit $shadow --output-as=xml"
test_assert_validate $CRM_EX_USAGE 0
desc="Commit shadow instance (no active instance) (force) (XML)"
cmd="crm_shadow --commit $shadow --force --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Commit an inactive shadow instance with an active instance
export CIB_shadow="nonexistent_shadow"
desc="Commit shadow instance (mismatch)"
cmd="crm_shadow --commit $shadow"
test_assert $CRM_EX_USAGE 0
desc="Commit shadow instance (mismatch) (force)"
cmd="crm_shadow --commit $shadow --force"
test_assert $CRM_EX_OK 0
desc="Commit shadow instance (mismatch) (XML)"
cmd="crm_shadow --commit $shadow --output-as=xml"
test_assert_validate $CRM_EX_USAGE 0
desc="Commit shadow instance (mismatch) (force) (XML)"
cmd="crm_shadow --commit $shadow --force --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Commit an active shadow instance whose shadow file is missing
desc="Commit shadow instance (nonexistent shadow file)"
cmd="crm_shadow --commit $CIB_shadow"
test_assert $CRM_EX_USAGE 0
desc="Commit shadow instance (nonexistent shadow file) (force)"
cmd="crm_shadow --commit $CIB_shadow --force"
test_assert $CRM_EX_NOSUCH 0
desc="Get active shadow instance's diff (nonexistent shadow file)"
cmd="crm_shadow --diff"
test_assert $CRM_EX_NOSUCH 0
desc="Commit shadow instance (nonexistent shadow file) (XML)"
cmd="crm_shadow --commit $CIB_shadow --output-as=xml"
test_assert_validate $CRM_EX_USAGE 0
desc="Commit shadow instance (nonexistent shadow file) (force) (XML)"
cmd="crm_shadow --commit $CIB_shadow --force --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
desc="Get active shadow instance's diff (nonexistent shadow file) (XML)"
cmd="crm_shadow --diff --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
# Commit an active shadow instance when the CIB file is missing
export CIB_file="$test_home/cli/nonexistent_cib.xml"
export CIB_shadow="$shadow"
desc="Commit shadow instance (nonexistent CIB file)"
cmd="crm_shadow --commit $shadow"
test_assert $CRM_EX_USAGE 0
desc="Commit shadow instance (nonexistent CIB file) (force)"
cmd="crm_shadow --commit $shadow --force"
test_assert $CRM_EX_NOSUCH 0
desc="Get active shadow instance's diff (nonexistent CIB file)"
cmd="crm_shadow --diff"
test_assert $CRM_EX_NOSUCH 0
desc="Commit shadow instance (nonexistent CIB file) (XML)"
cmd="crm_shadow --commit $shadow --output-as=xml"
test_assert_validate $CRM_EX_USAGE 0
desc="Commit shadow instance (nonexistent CIB file) (force) (XML)"
cmd="crm_shadow --commit $shadow --force --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
desc="Get active shadow instance's diff (nonexistent CIB file) (XML)"
cmd="crm_shadow --diff --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
rm -f "$TMPXML"
# Delete an active shadow instance
export CIB_file="$test_home/cli/crm_mon.xml"
export CIB_shadow="$shadow"
desc="Delete shadow instance"
cmd="crm_shadow --delete $shadow"
test_assert $CRM_EX_USAGE 0
desc="Delete shadow instance (force)"
cmd="crm_shadow --delete $shadow --force"
test_assert $CRM_EX_OK 0
create_shadow_cib --create
desc="Delete shadow instance (XML)"
cmd="crm_shadow --delete $shadow --output-as=xml"
test_assert_validate $CRM_EX_USAGE 0
desc="Delete shadow instance (force) (XML)"
cmd="crm_shadow --delete $shadow --force --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Delete an inactive shadow instance with no active instance
create_shadow_cib --create
unset CIB_shadow
desc="Delete shadow instance (no active instance)"
cmd="crm_shadow --delete $shadow"
test_assert $CRM_EX_USAGE 0
desc="Delete shadow instance (no active instance) (force)"
cmd="crm_shadow --delete $shadow --force"
test_assert $CRM_EX_OK 0
create_shadow_cib --create
unset CIB_shadow
desc="Delete shadow instance (no active instance) (XML)"
cmd="crm_shadow --delete $shadow --output-as=xml"
test_assert_validate $CRM_EX_USAGE 0
desc="Delete shadow instance (no active instance) (force) (XML)"
cmd="crm_shadow --delete $shadow --force --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Delete an inactive shadow instance with an active instance
create_shadow_cib --create
export CIB_shadow="nonexistent_shadow"
desc="Delete shadow instance (mismatch)"
cmd="crm_shadow --delete $shadow"
test_assert $CRM_EX_USAGE 0
desc="Delete shadow instance (mismatch) (force)"
cmd="crm_shadow --delete $shadow --force"
test_assert $CRM_EX_OK 0
create_shadow_cib --create
export CIB_shadow="nonexistent_shadow"
desc="Delete shadow instance (mismatch) (XML)"
cmd="crm_shadow --delete $shadow --output-as=xml"
test_assert_validate $CRM_EX_USAGE 0
desc="Delete shadow instance (mismatch) (force) (XML)"
cmd="crm_shadow --delete $shadow --force --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Delete an active shadow instance whose shadow file is missing
desc="Delete shadow instance (nonexistent shadow file)"
cmd="crm_shadow --delete $CIB_shadow"
test_assert $CRM_EX_USAGE 0
desc="Delete shadow instance (nonexistent shadow file) (force)"
cmd="crm_shadow --delete $CIB_shadow --force"
test_assert $CRM_EX_OK 0
desc="Delete shadow instance (nonexistent shadow file) (XML)"
cmd="crm_shadow --delete $CIB_shadow --output-as=xml"
test_assert_validate $CRM_EX_USAGE 0
desc="Delete shadow instance (nonexistent shadow file) (force) (XML)"
cmd="crm_shadow --delete $CIB_shadow --force --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Delete an active shadow instance when the CIB file is missing
export CIB_file="$test_home/cli/crm_mon.xml"
create_shadow_cib --create
export CIB_file="$test_home/cli/nonexistent_cib.xml"
desc="Delete shadow instance (nonexistent CIB file)"
cmd="crm_shadow --delete $shadow"
test_assert $CRM_EX_USAGE 0
desc="Delete shadow instance (nonexistent CIB file) (force)"
cmd="crm_shadow --delete $shadow --force"
test_assert $CRM_EX_OK 0
export CIB_file="$test_home/cli/crm_mon.xml"
create_shadow_cib --create
export CIB_file="$test_home/cli/nonexistent_cib.xml"
desc="Delete shadow instance (nonexistent CIB file) (XML)"
cmd="crm_shadow --delete $shadow --output-as=xml"
test_assert_validate $CRM_EX_USAGE 0
desc="Delete shadow instance (nonexistent CIB file) (force) (XML)"
cmd="crm_shadow --delete $shadow --force --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Create new shadow instance based on active CIB with no instance active
export CIB_file="$test_home/cli/crm_mon.xml"
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
unset CIB_shadow
desc="Create copied shadow instance (no active instance)"
cmd="crm_shadow --create $shadow --batch"
test_assert $CRM_EX_OK 0
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
unset CIB_shadow
desc="Create copied shadow instance (no active instance) (XML)"
cmd="crm_shadow --create $shadow --batch --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Create new shadow instance based on active CIB with other instance active
export CIB_file="$test_home/cli/crm_mon.xml"
export CIB_shadow="nonexistent_shadow"
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
desc="Create copied shadow instance (mismatch)"
cmd="crm_shadow --create $shadow --batch"
test_assert $CRM_EX_OK 0
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
desc="Create copied shadow instance (mismatch) (XML)"
cmd="crm_shadow --create $shadow --batch --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Create new shadow instance based on CIB (shadow file already exists)
export CIB_file="$test_home/cli/crm_mon.xml"
desc="Create copied shadow instance (file already exists)"
cmd="crm_shadow --create $shadow --batch"
test_assert $CRM_EX_CANTCREAT 0
desc="Create copied shadow instance (file already exists) (force)"
cmd="crm_shadow --create $shadow --batch --force"
test_assert $CRM_EX_OK 0
desc="Create copied shadow instance (file already exists) (XML)"
cmd="crm_shadow --create $shadow --batch --output-as=xml"
test_assert_validate $CRM_EX_CANTCREAT 0
desc="Create copied shadow instance (file already exists) (force) (XML)"
cmd="crm_shadow --create $shadow --batch --force --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Create new shadow instance based on active CIB when the CIB file is missing
export CIB_file="$test_home/cli/nonexistent_cib.xml"
export CIB_shadow="$shadow"
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
desc="Create copied shadow instance (nonexistent CIB file) (force)"
cmd="crm_shadow --create $shadow --batch --force"
test_assert $CRM_EX_NOSUCH 0
desc="Create copied shadow instance (nonexistent CIB file) (force) (XML)"
cmd="crm_shadow --create $shadow --batch --force --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
# Create new empty shadow instance
export CIB_shadow="$shadow"
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
desc="Create empty shadow instance"
cmd="crm_shadow --create-empty $shadow --batch"
test_assert $CRM_EX_OK 0
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
desc="Create empty shadow instance (XML)"
cmd="crm_shadow --create-empty $shadow --batch --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Create empty shadow instance with no active instance
unset CIB_shadow
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
desc="Create empty shadow instance (no active instance)"
cmd="crm_shadow --create-empty $shadow --batch"
test_assert $CRM_EX_OK 0
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
desc="Create empty shadow instance (no active instance) (XML)"
cmd="crm_shadow --create-empty $shadow --batch --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Create empty shadow instance with other instance active
export CIB_shadow="nonexistent_shadow"
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
desc="Create empty shadow instance (mismatch)"
cmd="crm_shadow --create-empty $shadow --batch"
test_assert $CRM_EX_OK 0
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
desc="Create empty shadow instance (mismatch) (XML)"
cmd="crm_shadow --create-empty $shadow --batch --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Create empty shadow instance when the CIB file is missing
export CIB_file="$test_home/cli/nonexistent_cib.xml"
export CIB_shadow="$shadow"
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
desc="Create empty shadow instance (nonexistent CIB file)"
cmd="crm_shadow --create-empty $shadow --batch"
test_assert $CRM_EX_OK 0
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
desc="Create empty shadow instance (nonexistent CIB file) (XML)"
cmd="crm_shadow --create-empty $shadow --batch --force --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Create empty shadow instance (shadow file already exists)
export CIB_file="$test_home/cli/crm_mon.xml"
desc="Create empty shadow instance (file already exists)"
cmd="crm_shadow --create-empty $shadow --batch"
test_assert $CRM_EX_CANTCREAT 0
desc="Create empty shadow instance (file already exists) (force)"
cmd="crm_shadow --create-empty $shadow --batch --force"
test_assert $CRM_EX_OK 0
desc="Create empty shadow instance (file already exists) (XML)"
cmd="crm_shadow --create-empty $shadow --batch --output-as=xml"
test_assert_validate $CRM_EX_CANTCREAT 0
desc="Create empty shadow instance (file already exists) (force) (XML)"
cmd="crm_shadow --create-empty $shadow --batch --force --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Query shadow instance with an empty CIB.
# --which and --file queries were done earlier.
delete_shadow_resource_defaults
desc="Get active shadow instance's contents (empty CIB)"
cmd="crm_shadow --display"
test_assert $CRM_EX_OK 0
desc="Get active shadow instance's contents (empty CIB) (XML)"
cmd="crm_shadow --display --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Get active shadow instance's diff (empty CIB)"
cmd="crm_shadow --diff"
test_assert $CRM_EX_ERROR 0
desc="Get active shadow instance's diff (empty CIB) (XML)"
cmd="crm_shadow --diff --output-as=xml"
test_assert_validate $CRM_EX_ERROR 0
# Reset shadow instance (overwrite existing shadow file based on active CIB)
export CIB_file="$test_home/cli/crm_mon.xml"
export CIB_shadow="$shadow"
desc="Reset shadow instance"
cmd="crm_shadow --reset $shadow --batch"
test_assert $CRM_EX_OK 0
desc="Get active shadow instance's diff (after reset)"
cmd="crm_shadow --diff"
test_assert $CRM_EX_OK 0
create_shadow_cib --create-empty
desc="Reset shadow instance (XML)"
cmd="crm_shadow --reset $shadow --batch --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Get active shadow instance's diff (after reset) (XML)"
cmd="crm_shadow --diff --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Reset an inactive shadow instance with no active instance
unset CIB_shadow
desc="Reset shadow instance (no active instance)"
cmd="crm_shadow --reset $shadow --batch"
test_assert $CRM_EX_OK 0
create_shadow_cib --create-empty
unset CIB_shadow
desc="Reset shadow instance (no active instance) (XML)"
cmd="crm_shadow --reset $shadow --batch --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Reset an inactive shadow instance with an active instance
export CIB_shadow="nonexistent_shadow"
desc="Reset shadow instance (mismatch)"
cmd="crm_shadow --reset $shadow --batch"
test_assert $CRM_EX_USAGE 0
desc="Reset shadow instance (mismatch) (force)"
cmd="crm_shadow --reset $shadow --batch --force"
test_assert $CRM_EX_OK 0
create_shadow_cib --create-empty
export CIB_shadow="nonexistent_shadow"
desc="Reset shadow instance (mismatch) (XML)"
cmd="crm_shadow --reset $shadow --batch --output-as=xml"
test_assert_validate $CRM_EX_USAGE 0
desc="Reset shadow instance (mismatch) (force) (XML)"
cmd="crm_shadow --reset $shadow --batch --force --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Reset an active shadow instance when the CIB file is missing
create_shadow_cib --create-empty
export CIB_file="$test_home/cli/nonexistent_cib.xml"
desc="Reset shadow instance (nonexistent CIB file)"
cmd="crm_shadow --reset $CIB_shadow --batch"
test_assert $CRM_EX_NOSUCH 0
desc="Reset shadow instance (nonexistent CIB file) (XML)"
cmd="crm_shadow --reset $CIB_shadow --batch --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
desc="Reset shadow instance (nonexistent CIB file) (force)"
cmd="crm_shadow --reset $CIB_shadow --batch --force"
test_assert $CRM_EX_NOSUCH 0
desc="Reset shadow instance (nonexistent CIB file) (force) (XML)"
cmd="crm_shadow --reset $CIB_shadow --batch --force --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
# Reset an active shadow instance whose shadow file is missing
export CIB_file="$test_home/cli/crm_mon.xml"
export CIB_shadow="$shadow"
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
desc="Reset shadow instance (nonexistent shadow file)"
cmd="crm_shadow --reset $CIB_shadow --batch"
test_assert $CRM_EX_NOSUCH 0
desc="Reset shadow instance (nonexistent shadow file) (force)"
cmd="crm_shadow --reset $CIB_shadow --batch --force"
test_assert $CRM_EX_OK 0
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
desc="Reset shadow instance (nonexistent shadow file) (XML)"
cmd="crm_shadow --reset $CIB_shadow --batch --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
desc="Reset shadow instance (nonexistent shadow file) (force) (XML)"
cmd="crm_shadow --reset $CIB_shadow --batch --force --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Switch shadow instances
# In batch mode, this only displays a message
create_shadow_cib --create-empty
# Makes no difference now, just future-proofing
CIB_shadow="nonexistent_shadow"
desc="Switch to new shadow instance"
cmd="crm_shadow --switch $shadow --batch"
test_assert $CRM_EX_OK 0
CIB_shadow="nonexistent_shadow"
desc="Switch to new shadow instance (XML)"
cmd="crm_shadow --switch $shadow --batch --output-as=xml"
test_assert_validate $CRM_EX_OK 0
crm_shadow --delete "$shadow" --force >/dev/null 2>&1
desc="Switch to nonexistent shadow instance"
cmd="crm_shadow --switch $shadow --batch"
test_assert $CRM_EX_NOSUCH 0
desc="Switch to nonexistent shadow instance (force)"
cmd="crm_shadow --switch $shadow --batch --force"
test_assert $CRM_EX_NOSUCH 0
desc="Switch to nonexistent shadow instance (XML)"
cmd="crm_shadow --switch $shadow --batch --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
desc="Switch to nonexistent shadow instance (force) (XML)"
cmd="crm_shadow --switch $shadow --batch --force --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
CIB_file_invalid_1="$test_home/cli/crm_verify_invalid_bz.xml"
CIB_file_invalid_2="$test_home/cli/crm_verify_invalid_no_stonith.xml"
desc="Verify a file-specified invalid configuration, outputting as xml"
cmd="crm_verify --xml-file '$CIB_file_invalid_1' --output-as=xml"
test_assert_validate $CRM_EX_CONFIG 0
desc="Verify another file-specified invalid configuration, outputting as xml"
cmd="crm_verify --xml-file '$CIB_file_invalid_2' --output-as=xml"
test_assert_validate $CRM_EX_CONFIG 0
desc="Verbosely verify a file-specified invalid configuration, outputting as xml"
cmd="crm_verify --xml-file '$CIB_file_invalid_1' --output-as=xml --verbose"
test_assert_validate $CRM_EX_CONFIG 0
desc="Verbosely verify another file-specified invalid configuration, outputting as xml"
cmd="crm_verify --xml-file '$CIB_file_invalid_2' --output-as=xml --verbose"
test_assert_validate $CRM_EX_CONFIG 0
export CIB_file="$test_home/cli/crm_mon.xml"
desc="Verify a file-specified valid configuration, outputting as xml"
cmd="crm_verify --xml-file '$CIB_file' --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Verify a piped-in valid configuration, outputting as xml"
cmd="cat '$CIB_file' | crm_verify -p --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Verbosely verify a file-specified valid configuration, outputting as xml"
cmd="crm_verify --xml-file '$CIB_file' --output-as=xml --verbose"
test_assert_validate $CRM_EX_OK 0
desc="Verbosely verify a piped-in valid configuration, outputting as xml"
cmd="cat '$CIB_file' | crm_verify -p --output-as=xml --verbose"
test_assert_validate $CRM_EX_OK 0
CIB_file_contents=$(cat "$CIB_file")
desc="Verify a string-supplied valid configuration, outputting as xml"
cmd="crm_verify -X '$CIB_file_contents' --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Verbosely verify a string-supplied valid configuration, outputting as xml"
cmd="crm_verify -X '$CIB_file_contents' --output-as=xml --verbose"
test_assert_validate $CRM_EX_OK 0
unset CIB_file
unset CIB_shadow
unset CIB_shadow_dir
}
INVALID_PERIODS=(
"2019-01-01 00:00:00Z" # Start with no end
"2019-01-01 00:00:00Z/" # Start with only a trailing slash
"PT2S/P1M" # Two durations
"2019-13-01 00:00:00Z/P1M" # Out-of-range month
"20191077T15/P1M" # Out-of-range day
"2019-10-01T25:00:00Z/P1M" # Out-of-range hour
"2019-10-01T24:00:01Z/P1M" # Hour 24 with anything but :00:00
"PT5H/20191001T007000Z" # Out-of-range minute
"2019-10-01 00:00:80Z/P1M" # Out-of-range second
"2019-10-01 00:00:10 +25:00/P1M" # Out-of-range offset hour
"20191001T000010 -00:61/P1M" # Out-of-range offset minute
"P1Y/2019-02-29 00:00:00Z" # Feb. 29 in non-leap-year
"2019-01-01 00:00:00Z/P" # Duration with no values
"P1Z/2019-02-20 00:00:00Z" # Invalid duration unit
"P1YM/2019-02-20 00:00:00Z" # No number for duration unit
)
function test_dates() {
# Ensure invalid period specifications are rejected
for spec in '' "${INVALID_PERIODS[@]}"; do
desc="Invalid period - [$spec]"
cmd="iso8601 -p \"$spec\""
test_assert $CRM_EX_INVALID_PARAM 0
done
desc="2014-01-01 00:30:00 - 1 Hour"
cmd="iso8601 -d '2014-01-01 00:30:00Z' -D P-1H -E '2013-12-31 23:30:00Z'"
test_assert $CRM_EX_OK 0
desc="Valid date - Feb 29 in leap year"
cmd="iso8601 -d '2020-02-29 00:00:00Z' -E '2020-02-29 00:00:00Z'"
test_assert $CRM_EX_OK 0
desc="Valid date - using 'T' and offset"
cmd="iso8601 -d '20191201T131211 -05:00' -E '2019-12-01 18:12:11Z'"
test_assert $CRM_EX_OK 0
desc="24:00:00 equivalent to 00:00:00 of next day"
cmd="iso8601 -d '2019-12-31 24:00:00Z' -E '2020-01-01 00:00:00Z'"
test_assert $CRM_EX_OK 0
for y in 06 07 08 09 10 11 12 13 14 15 16 17 18 40; do
desc="20$y-W01-7"
cmd="iso8601 -d '20$y-W01-7 00Z'"
test_assert $CRM_EX_OK 0
desc="20$y-W01-7 - round-trip"
cmd="iso8601 -d '20$y-W01-7 00Z' -W -E '20$y-W01-7 00:00:00Z'"
test_assert $CRM_EX_OK 0
desc="20$y-W01-1"
cmd="iso8601 -d '20$y-W01-1 00Z'"
test_assert $CRM_EX_OK 0
desc="20$y-W01-1 - round-trip"
cmd="iso8601 -d '20$y-W01-1 00Z' -W -E '20$y-W01-1 00:00:00Z'"
test_assert $CRM_EX_OK 0
done
desc="2009-W53-07"
cmd="iso8601 -d '2009-W53-7 00:00:00Z' -W -E '2009-W53-7 00:00:00Z'"
test_assert $CRM_EX_OK 0
desc="epoch + 2 Years 5 Months 6 Minutes"
cmd="iso8601 -d 'epoch' -D P2Y5MT6M -E '1972-06-01 00:06:00Z'"
test_assert $CRM_EX_OK 0
desc="2009-01-31 + 1 Month"
cmd="iso8601 -d '20090131T000000Z' -D P1M -E '2009-02-28 00:00:00Z'"
test_assert $CRM_EX_OK 0
desc="2009-01-31 + 2 Months"
cmd="iso8601 -d '2009-01-31 00:00:00Z' -D P2M -E '2009-03-31 00:00:00Z'"
test_assert $CRM_EX_OK 0
desc="2009-01-31 + 3 Months"
cmd="iso8601 -d '2009-01-31 00:00:00Z' -D P3M -E '2009-04-30 00:00:00Z'"
test_assert $CRM_EX_OK 0
desc="2009-03-31 - 1 Month"
cmd="iso8601 -d '2009-03-31 01:00:00 +01:00' -D P-1M -E '2009-02-28 00:00:00Z'"
test_assert $CRM_EX_OK 0
desc="2038-01-01 + 3 Months"
cmd="iso8601 -d '2038-01-01 00:00:00Z' -D P3M -E '2038-04-01 00:00:00Z'"
test_assert $CRM_EX_OK 0
}
function test_acl_loop() {
local TMPXML
TMPXML="$1"
# Make sure we're rejecting things for the right reasons
orig_trace_fns="$PCMK_trace_functions"
export PCMK_trace_functions=pcmk__check_acl,pcmk__apply_creation_acl
CIB_user=root cibadmin --replace --xml-text ''
### no ACL ###
export CIB_user=unknownguy
desc="$CIB_user: Query configuration"
cmd="cibadmin -Q"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Set enable-acl"
cmd="crm_attribute -n enable-acl -v false"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Set stonith-enabled"
cmd="crm_attribute -n stonith-enabled -v false"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Create a resource"
cmd="cibadmin -C -o resources --xml-text ''"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
### deny /cib permission ###
export CIB_user=l33t-haxor
desc="$CIB_user: Query configuration"
cmd="cibadmin -Q"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Set enable-acl"
cmd="crm_attribute -n enable-acl -v false"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Set stonith-enabled"
cmd="crm_attribute -n stonith-enabled -v false"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Create a resource"
cmd="cibadmin -C -o resources --xml-text ''"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
### observer role ###
export CIB_user=niceguy
desc="$CIB_user: Query configuration"
cmd="cibadmin -Q"
test_assert $CRM_EX_OK 0
desc="$CIB_user: Set enable-acl"
cmd="crm_attribute -n enable-acl -v false"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Set stonith-enabled"
cmd="crm_attribute -n stonith-enabled -v false"
test_assert $CRM_EX_OK
desc="$CIB_user: Create a resource"
cmd="cibadmin -C -o resources --xml-text ''"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
export CIB_user=root
desc="$CIB_user: Query configuration"
cmd="cibadmin -Q"
test_assert $CRM_EX_OK 0
desc="$CIB_user: Set stonith-enabled"
cmd="crm_attribute -n stonith-enabled -v true"
test_assert $CRM_EX_OK
desc="$CIB_user: Create a resource"
cmd="cibadmin -C -o resources --xml-text ''"
test_assert $CRM_EX_OK
### deny /cib permission ###
export CIB_user=l33t-haxor
desc="$CIB_user: Create a resource meta attribute"
cmd="crm_resource -r dummy --meta -p target-role -v Stopped"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Query a resource meta attribute"
cmd="crm_resource -r dummy --meta -g target-role"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
desc="$CIB_user: Remove a resource meta attribute"
cmd="crm_resource -r dummy --meta -d target-role"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
### observer role ###
export CIB_user=niceguy
desc="$CIB_user: Create a resource meta attribute"
cmd="crm_resource -r dummy --meta -p target-role -v Stopped"
test_assert $CRM_EX_OK
desc="$CIB_user: Query a resource meta attribute"
cmd="crm_resource -r dummy --meta -g target-role"
test_assert $CRM_EX_OK
desc="$CIB_user: Remove a resource meta attribute"
cmd="crm_resource -r dummy --meta -d target-role"
test_assert $CRM_EX_OK
desc="$CIB_user: Create a resource meta attribute"
cmd="crm_resource -r dummy --meta -p target-role -v Started"
test_assert $CRM_EX_OK
### read //meta_attributes ###
export CIB_user=badidea
desc="$CIB_user: Query configuration - implied deny"
cmd="cibadmin -Q"
test_assert $CRM_EX_OK 0
### deny /cib, read //meta_attributes ###
export CIB_user=betteridea
desc="$CIB_user: Query configuration - explicit deny"
cmd="cibadmin -Q"
test_assert $CRM_EX_OK 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --delete --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
### observer role ###
export CIB_user=niceguy
desc="$CIB_user: Replace - remove acls"
cmd="cibadmin --replace --xml-file $TMPXML"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -C -o resources --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - create resource"
cmd="cibadmin --replace --xml-file $TMPXML"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" crm_attribute -n enable-acl -v false
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - modify attribute (deny)"
cmd="cibadmin --replace --xml-file $TMPXML"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - delete attribute (deny)"
cmd="cibadmin --replace --xml-file $TMPXML"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - create attribute (deny)"
cmd="cibadmin --replace --xml-file $TMPXML"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
### admin role ###
CIB_user=bob
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - create attribute (direct allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - modify attribute (direct allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace -o resources --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - delete attribute (direct allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
### super_user role ###
export CIB_user=joe
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - create attribute (inherited allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - modify attribute (inherited allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace -o resources --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - delete attribute (inherited allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
### rsc_writer role ###
export CIB_user=mike
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - create attribute (allow overrides deny)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - modify attribute (allow overrides deny)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace -o resources --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - delete attribute (allow overrides deny)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK 0
### rsc_denied role ###
export CIB_user=chris
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - create attribute (deny overrides allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
# Set as root since setting as chris failed
CIB_user=root cibadmin --modify --xml-text ''
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - modify attribute (deny overrides allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
# Set as root since setting as chris failed
CIB_user=root cibadmin --modify --xml-text ''
CIB_user=root cibadmin -Q > "$TMPXML"
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace -o resources --xml-text ''
CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
desc="$CIB_user: Replace - delete attribute (deny overrides allow)"
cmd="cibadmin --replace -o resources --xml-file $TMPXML"
test_assert $CRM_EX_INSUFFICIENT_PRIV 0
export PCMK_trace_functions="$orig_trace_fns"
}
function test_acls() {
local SHADOWPATH
local TMPXML
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.acls.xml.XXXXXXXXXX)
create_shadow_cib --create-empty pacemaker-1.3
cat < "$TMPXML"
EOF
desc="Configure some ACLs"
cmd="cibadmin -M -o acls --xml-file $TMPXML"
test_assert $CRM_EX_OK
desc="Enable ACLs"
cmd="crm_attribute -n enable-acl -v true"
test_assert $CRM_EX_OK
desc="Set cluster option"
cmd="crm_attribute -n no-quorum-policy -v ignore"
test_assert $CRM_EX_OK
desc="New ACL"
cmd="cibadmin --create -o acls --xml-text ''"
test_assert $CRM_EX_OK
desc="Another ACL"
cmd="cibadmin --create -o acls --xml-text ''"
test_assert $CRM_EX_OK
desc="Updated ACL"
cmd="cibadmin --replace -o acls --xml-text ''"
test_assert $CRM_EX_OK
test_acl_loop "$TMPXML"
printf "\n\n !#!#!#!#! Upgrading to latest CIB schema and re-testing !#!#!#!#!\n"
printf "\nUpgrading to latest CIB schema and re-testing\n" 1>&2
export CIB_user=root
desc="$CIB_user: Upgrade to latest CIB schema"
cmd="cibadmin --upgrade --force -V"
test_assert $CRM_EX_OK
reset_shadow_cib_version
test_acl_loop "$TMPXML"
unset CIB_shadow_dir
rm -f "$TMPXML"
}
function test_validity() {
local TMPGOOD
local TMPBAD
TMPGOOD=$(mktemp ${TMPDIR:-/tmp}/cts-cli.validity.good.xml.XXXXXXXXXX)
TMPBAD=$(mktemp ${TMPDIR:-/tmp}/cts-cli.validity.bad.xml.XXXXXXXXXX)
create_shadow_cib --create-empty pacemaker-1.2
orig_trace_fns="$PCMK_trace_functions"
- export PCMK_trace_functions=apply_upgrade,update_validation
+ export PCMK_trace_functions=apply_upgrade,pcmk__update_schema
cibadmin -C -o resources --xml-text ''
cibadmin -C -o resources --xml-text ''
cibadmin -C -o constraints --xml-text ''
cibadmin -Q > "$TMPGOOD"
desc="Try to make resulting CIB invalid (enum violation)"
cmd="cibadmin -M -o constraints --xml-text ''"
test_assert $CRM_EX_CONFIG
sed 's|"start"|"break"|' "$TMPGOOD" > "$TMPBAD"
desc="Run crm_simulate with invalid CIB (enum violation)"
cmd="crm_simulate -x $TMPBAD -S"
test_assert $CRM_EX_CONFIG 0
desc="Try to make resulting CIB invalid (unrecognized validate-with)"
cmd="cibadmin -M --xml-text ''"
test_assert $CRM_EX_CONFIG
sed 's|"pacemaker-1.2"|"pacemaker-9999.0"|' "$TMPGOOD" > "$TMPBAD"
desc="Run crm_simulate with invalid CIB (unrecognized validate-with)"
cmd="crm_simulate -x $TMPBAD -S"
test_assert $CRM_EX_CONFIG 0
desc="Try to make resulting CIB invalid, but possibly recoverable (valid with X.Y+1)"
cmd="cibadmin -C -o configuration --xml-text ''"
test_assert $CRM_EX_CONFIG
sed 's|||' "$TMPGOOD" > "$TMPBAD"
desc="Run crm_simulate with invalid, but possibly recoverable CIB (valid with X.Y+1)"
cmd="crm_simulate -x $TMPBAD -S"
test_assert $CRM_EX_OK 0
sed 's|[ ][ ]*validate-with="[^"]*"||' "$TMPGOOD" > "$TMPBAD"
desc="Make resulting CIB valid, although without validate-with attribute"
cmd="cibadmin -R --xml-file $TMPBAD"
test_assert $CRM_EX_OK
desc="Run crm_simulate with valid CIB, but without validate-with attribute"
cmd="crm_simulate -x $TMPBAD -S"
test_assert $CRM_EX_OK 0
# this will just disable validation and accept the config, outputting
# validation errors
sed -e 's|[ ][ ]*validate-with="[^"]*"||' \
-e 's|\([ ][ ]*epoch="[^"]*\)"|\10"|' -e 's|"start"|"break"|' \
"$TMPGOOD" > "$TMPBAD"
desc="Make resulting CIB invalid, and without validate-with attribute"
cmd="cibadmin -R --xml-file $TMPBAD"
test_assert $CRM_EX_OK
desc="Run crm_simulate with invalid CIB, also without validate-with attribute"
cmd="crm_simulate -x $TMPBAD -S"
test_assert $CRM_EX_OK 0
unset CIB_shadow_dir
rm -f "$TMPGOOD" "$TMPBAD"
export PCMK_trace_functions="$orig_trace_fns"
}
test_upgrade() {
local TMPXML
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
create_shadow_cib --create-empty pacemaker-2.10
orig_trace_fns="$PCMK_trace_functions"
- export PCMK_trace_functions=apply_upgrade,update_validation
+ export PCMK_trace_functions=apply_upgrade,pcmk__update_schema
desc="Set stonith-enabled=false"
cmd="crm_attribute -n stonith-enabled -v false"
test_assert $CRM_EX_OK
cat < "$TMPXML"
EOF
desc="Configure the initial resource"
cmd="cibadmin -M -o resources --xml-file $TMPXML"
test_assert $CRM_EX_OK
desc="Upgrade to latest CIB schema (trigger 2.10.xsl + the wrapping)"
cmd="cibadmin --upgrade --force -V -V"
test_assert $CRM_EX_OK
desc="Query a resource instance attribute (shall survive)"
cmd="crm_resource -r mySmartFuse -g requires"
test_assert $CRM_EX_OK
unset CIB_shadow_dir
rm -f "$TMPXML"
export PCMK_trace_functions="$orig_trace_fns"
}
test_rules() {
local TMPXML
create_shadow_cib --create-empty
cibadmin -C -o crm_config --xml-text ''
cibadmin -C -o resources --xml-text ''
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
cat < "$TMPXML"
EOF
cibadmin -C -o constraints -x "$TMPXML"
rm -f "$TMPXML"
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
cat < "$TMPXML"
EOF
cibadmin -C -o constraints -x "$TMPXML"
rm -f "$TMPXML"
if [ "$(uname)" == "FreeBSD" ]; then
tomorrow=$(date -v+1d +"%F %T %z")
else
tomorrow=$(date --date=tomorrow +"%F %T %z")
fi
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
cat < "$TMPXML"
EOF
cibadmin -C -o constraints -x "$TMPXML"
rm -f "$TMPXML"
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
cat < "$TMPXML"
EOF
cibadmin -C -o constraints -x "$TMPXML"
rm -f "$TMPXML"
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
cat < "$TMPXML"
EOF
cibadmin -C -o constraints -x "$TMPXML"
rm -f "$TMPXML"
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
cat < "$TMPXML"
EOF
cibadmin -C -o constraints -x "$TMPXML"
rm -f "$TMPXML"
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
cat < "$TMPXML"
EOF
cibadmin -C -o constraints -x "$TMPXML"
rm -f "$TMPXML"
desc="crm_rule given no arguments"
cmd="crm_rule"
test_assert $CRM_EX_USAGE 0
desc="crm_rule given no arguments (XML)"
cmd="crm_rule --output-as=xml"
test_assert_validate $CRM_EX_USAGE 0
desc="crm_rule given no rule to check"
cmd="crm_rule -c"
test_assert $CRM_EX_USAGE 0
desc="crm_rule given no rule to check (XML)"
cmd="crm_rule -c --output-as=xml"
test_assert_validate $CRM_EX_USAGE 0
desc="crm_rule given invalid input XML"
cmd="crm_rule -c -r blahblah -X 'invalidxml'"
test_assert $CRM_EX_DATAERR 0
desc="crm_rule given invalid input XML (XML)"
cmd="crm_rule -c -r blahblah -X 'invalidxml' --output-as=xml"
test_assert_validate $CRM_EX_DATAERR 0
desc="crm_rule given invalid input XML on stdin"
cmd="echo 'invalidxml' | crm_rule -c -r blahblah -X -"
test_assert $CRM_EX_DATAERR 0
desc="crm_rule given invalid input XML on stdin (XML)"
cmd="echo 'invalidxml' | crm_rule -c -r blahblah -X - --output-as=xml"
test_assert_validate $CRM_EX_DATAERR 0
desc="Try to check a rule that doesn't exist"
cmd="crm_rule -c -r blahblah"
test_assert $CRM_EX_NOSUCH
desc="Try to check a rule that doesn't exist, with XML output"
cmd="crm_rule -c -r blahblah --output-as=xml"
test_assert_validate $CRM_EX_NOSUCH 0
desc="Try to check a rule that has too many date_expressions"
cmd="crm_rule -c -r cli-rule-too-many-date-expressions"
test_assert $CRM_EX_UNIMPLEMENT_FEATURE 0
desc="Try to check a rule that has too many date_expressions (XML)"
cmd="crm_rule -c -r cli-rule-too-many-date-expressions --output-as=xml"
test_assert_validate $CRM_EX_UNIMPLEMENT_FEATURE 0
desc="Verify basic rule is expired"
cmd="crm_rule -c -r cli-prefer-rule-dummy-expired"
test_assert $CRM_EX_EXPIRED 0
desc="Verify basic rule is expired, with XML output"
cmd="crm_rule -c -r cli-prefer-rule-dummy-expired --output-as=xml"
test_assert_validate $CRM_EX_EXPIRED 0
desc="Verify basic rule worked in the past"
cmd="crm_rule -c -r cli-prefer-rule-dummy-expired -d 20180101"
test_assert $CRM_EX_OK 0
desc="Verify basic rule worked in the past (XML)"
cmd="crm_rule -c -r cli-prefer-rule-dummy-expired -d 20180101 --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Verify basic rule is not yet in effect"
cmd="crm_rule -c -r cli-prefer-rule-dummy-not-yet"
test_assert $CRM_EX_NOT_YET_IN_EFFECT 0
desc="Verify basic rule is not yet in effect (XML)"
cmd="crm_rule -c -r cli-prefer-rule-dummy-not-yet --output-as=xml"
test_assert_validate $CRM_EX_NOT_YET_IN_EFFECT 0
desc="Verify date_spec rule with years has expired"
cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-only-years"
test_assert $CRM_EX_EXPIRED 0
desc="Verify date_spec rule with years has expired (XML)"
cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-only-years --output-as=xml"
test_assert_validate $CRM_EX_EXPIRED 0
desc="Verify multiple rules at once"
cmd="crm_rule -c -r cli-prefer-rule-dummy-not-yet -r cli-prefer-rule-dummy-date_spec-only-years"
test_assert $CRM_EX_EXPIRED 0
desc="Verify multiple rules at once, with XML output"
cmd="crm_rule -c -r cli-prefer-rule-dummy-not-yet -r cli-prefer-rule-dummy-date_spec-only-years --output-as=xml"
test_assert_validate $CRM_EX_EXPIRED 0
desc="Verify date_spec rule with years is in effect"
cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-only-years -d 20190201"
test_assert $CRM_EX_OK 0
desc="Verify date_spec rule with years is in effect (XML)"
cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-only-years -d 20190201 --output-as=xml"
test_assert_validate $CRM_EX_OK 0
desc="Try to check a rule whose date_spec does not contain years="
cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-without-years"
test_assert $CRM_EX_UNIMPLEMENT_FEATURE 0
desc="Try to check a rule whose date_spec does not contain years= (XML)"
cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-without-years --output-as=xml"
test_assert_validate $CRM_EX_UNIMPLEMENT_FEATURE 0
desc="Try to check a rule whose date_spec contains years= and moon="
cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-years-moon"
test_assert $CRM_EX_UNIMPLEMENT_FEATURE 0
desc="Try to check a rule whose date_spec contains years= and moon= (XML)"
cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-years-moon --output-as=xml"
test_assert_validate $CRM_EX_UNIMPLEMENT_FEATURE 0
desc="Try to check a rule with no date_expression"
cmd="crm_rule -c -r cli-no-date_expression-rule"
test_assert $CRM_EX_UNIMPLEMENT_FEATURE 0
desc="Try to check a rule with no date_expression (XML)"
cmd="crm_rule -c -r cli-no-date_expression-rule --output-as=xml"
test_assert_validate $CRM_EX_UNIMPLEMENT_FEATURE 0
unset CIB_shadow_dir
}
# Ensure all command output is in portable locale for comparison
export LC_ALL="C"
test_access_render() {
local TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.access_render.xml.XXXXXXXXXX)
create_shadow_cib --create-empty
# Create a test CIB that has ACL roles
cat < "$TMPXML"
EOF
desc="Configure some ACLs"
cmd="cibadmin -M -o acls --xml-file $TMPXML"
test_assert $CRM_EX_OK
desc="Enable ACLs"
cmd="crm_attribute -n enable-acl -v true"
test_assert $CRM_EX_OK
unset CIB_user
# Run cibadmin --show-access on the test CIB as an ACL-restricted user
desc="An instance of ACLs render (into color)"
cmd="cibadmin --force --show-access=color -Q --user tony"
test_assert $CRM_EX_OK 0
desc="An instance of ACLs render (into namespacing)"
cmd="cibadmin --force --show-access=namespace -Q --user tony"
test_assert $CRM_EX_OK 0
desc="An instance of ACLs render (into text)"
cmd="cibadmin --force --show-access=text -Q --user tony"
test_assert $CRM_EX_OK 0
unset CIB_shadow_dir
rm -f "$TMPXML"
}
function test_feature_set() {
create_shadow_cib --create-empty
# Import the initial test CIB with non-mixed versions
desc="Import the test CIB"
cmd="cibadmin --replace --xml-file $test_home/cli/crm_mon-feature_set.xml"
test_assert $CRM_EX_OK
desc="Complete text output, no mixed status"
cmd="crm_mon -1 --show-detail"
test_assert $CRM_EX_OK 0
desc="XML output, no mixed status"
cmd="crm_mon --output-as=xml"
test_assert_validate $CRM_EX_OK 0
# Modify the CIB to fake that the cluster has mixed versions
desc="Fake inconsistent feature set"
cmd="crm_attribute --node=cluster02 --name=#feature-set --update=3.15.0 --lifetime=reboot"
test_assert $CRM_EX_OK
desc="Complete text output, mixed status"
cmd="crm_mon -1 --show-detail"
test_assert $CRM_EX_OK 0
desc="XML output, mixed status"
cmd="crm_mon --output-as=xml"
test_assert_validate $CRM_EX_OK 0
unset CIB_shadow_dir
}
# Process command-line arguments
while [ $# -gt 0 ]; do
case "$1" in
-t)
tests="$2"
shift 2
;;
-V|--verbose)
verbose=1
shift
;;
-v|--valgrind)
export G_SLICE=always-malloc
VALGRIND_CMD="valgrind $VALGRIND_OPTS"
shift
;;
-s)
do_save=1
shift
;;
-p)
export PATH="$2:$PATH"
shift
;;
--help)
echo "$USAGE_TEXT"
exit $CRM_EX_OK
;;
*)
echo "error: unknown option $1"
echo
echo "$USAGE_TEXT"
exit $CRM_EX_USAGE
;;
esac
done
for t in $tests; do
case "$t" in
access_render) ;;
agents) ;;
daemons) ;;
dates) ;;
error_codes) ;;
tools) ;;
acls) ;;
validity) ;;
upgrade) ;;
rules) ;;
crm_mon) ;;
feature_set) ;;
*)
echo "error: unknown test $t"
echo
echo "$USAGE_TEXT"
exit $CRM_EX_USAGE
;;
esac
done
XMLLINT_CMD=$(which xmllint 2>/dev/null)
if [ $? -ne 0 ]; then
XMLLINT_CMD=""
echo "xmllint is missing - install it to validate command output"
fi
# Check whether we're running from source directory
SRCDIR=$(dirname $test_home)
if [ -x "$SRCDIR/tools/crm_simulate" ]; then
path_dirs="$SRCDIR/tools"
for daemon in based controld fenced schedulerd; do
if [ -x "$SRCDIR/daemons/$daemon/pacemaker-${daemon}" ]; then
path_dirs="$path_dirs:$SRCDIR/daemons/$daemon"
fi
done
export PATH="$path_dirs:$PATH"
echo "Using local binaries from: ${path_dirs//:/ }"
if [ -x "$SRCDIR/xml" ]; then
export PCMK_schema_directory="$SRCDIR/xml"
echo "Using local schemas from: $PCMK_schema_directory"
fi
else
export PATH="@CRM_DAEMON_DIR@:$PATH"
export PCMK_schema_directory=@CRM_SCHEMA_DIRECTORY@
fi
for t in $tests; do
echo "Testing $t"
TMPFILE=$(mktemp ${TMPDIR:-/tmp}/cts-cli.$t.XXXXXXXXXX)
eval TMPFILE_$t="$TMPFILE"
test_$t > "$TMPFILE"
# @TODO Add a way to suppress this message within cibadmin, and then drop
# the handling here.
suppress="The supplied command can provide skewed result since it is run"
suppress="$suppress under user that also gets guarded per ACLs on their"
suppress="$suppress own right. Continuing since --force flag was provided."
# This giant sed replaces content expected to change for each run
# (timestamps, source file line numbers, etc.), build (configure options,
# version numbers, etc.), or platform (system messages, etc.).
#
# last-rc-change= is always numeric in the CIB. However, for the crm_mon
# test we also need to compare against the XML output of the crm_mon
# program. There, these are shown as human readable strings (like the
# output of the `date` command).
sed -e 's|\(|\1/>|' \
-e 's|\(|\1>|' \
-e 's/Last updated: .*/Last updated:/' \
-e 's/Last change: .*/Last change:/' \
-e 's/(version .*)/(version)/' \
-e 's/last_update time=\".*\"/last_update time=\"\"/' \
-e 's/last_change time=\".*\"/last_change time=\"\"/' \
-e 's/ api-version="[^"]*"/ api-version="X"/' \
-e 's/ default="[^"]*"/ default=""/' \
-e 's/\(\* Possible values.*: .*\)(default: [^)]*)/\1(default: )/g' \
-e 's/ version="[^"]*"/ version=""/' \
-e 's/request=\".*\(crm_[a-zA-Z0-9]*\)/request=\"\1/' \
-e 's/crm_feature_set="[^"]*" //'\
-e 's/@crm_feature_set=[0-9.]*, //'\
-e 's/\( "${TMPFILE}.$$"
mv -- "${TMPFILE}.$$" "$TMPFILE"
if [ $do_save -eq 1 ]; then
cp "$TMPFILE" $test_home/cli/regression.$t.exp
fi
done
rm -rf "${shadow_dir}"
rm -f "${test_assert_outfile}"
rm -f "${test_assert_errfile}"
rm -f "${xmllint_outfile}"
failed=0
if [ $verbose -eq 1 ]; then
echo -e "\n\nResults"
fi
for t in $tests; do
eval TMPFILE="\$TMPFILE_$t"
if [ $verbose -eq 1 ]; then
diff -wu $test_home/cli/regression.$t.exp "$TMPFILE"
else
diff -w $test_home/cli/regression.$t.exp "$TMPFILE" >/dev/null 2>&1
fi
if [ $? -ne 0 ]; then
failed=1
fi
done
echo -e "\n\nSummary"
for t in $tests; do
eval TMPFILE="\$TMPFILE_$t"
grep -e '^\* \(Passed\|Failed\)' "$TMPFILE"
done
function print_or_remove_file() {
eval TMPFILE="\$TMPFILE_$1"
if [[ ! $(diff -wq $test_home/cli/regression.$1.exp "$TMPFILE") ]]; then
rm -f "$TMPFILE"
else
echo " $TMPFILE"
if [ $verbose -ne 0 ]; then
echo "======================================================"
cat "$TMPFILE"
echo "======================================================"
fi
fi
}
if [ $num_errors -ne 0 ] && [ $failed -ne 0 ]; then
echo "$num_errors tests failed; see output in:"
for t in $tests; do
print_or_remove_file "$t"
done
exit $CRM_EX_ERROR
elif [ $num_errors -ne 0 ]; then
echo "$num_errors tests failed"
for t in $tests; do
print_or_remove_file "$t"
done
exit $CRM_EX_ERROR
elif [ $failed -eq 1 ]; then
echo "$num_passed tests passed but output was unexpected; see output in:"
for t in $tests; do
print_or_remove_file "$t"
done
exit $CRM_EX_DIGEST
else
echo $num_passed tests passed
for t in $tests; do
eval TMPFILE="\$TMPFILE_$t"
rm -f "$TMPFILE"
done
crm_shadow --force --delete $shadow >/dev/null 2>&1
exit $CRM_EX_OK
fi
diff --git a/daemons/based/based_io.c b/daemons/based/based_io.c
index 71aab6e32c..0f8f03fd33 100644
--- a/daemons/based/based_io.c
+++ b/daemons/based/based_io.c
@@ -1,478 +1,477 @@
/*
* Copyright 2004-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU General Public License version 2
* or later (GPLv2+) WITHOUT ANY WARRANTY.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
crm_trigger_t *cib_writer = NULL;
int write_cib_contents(gpointer p);
static void
cib_rename(const char *old)
{
int new_fd;
char *new = crm_strdup_printf("%s/cib.auto.XXXXXX", cib_root);
umask(S_IWGRP | S_IWOTH | S_IROTH);
new_fd = mkstemp(new);
if ((new_fd < 0) || (rename(old, new) < 0)) {
crm_err("Couldn't archive unusable file %s (disabling disk writes and continuing)",
old);
cib_writes_enabled = FALSE;
} else {
crm_err("Archived unusable file %s as %s", old, new);
}
if (new_fd > 0) {
close(new_fd);
}
free(new);
}
/*
* It is the callers responsibility to free the output of this function
*/
static xmlNode *
retrieveCib(const char *filename, const char *sigfile)
{
xmlNode *root = NULL;
crm_info("Reading cluster configuration file %s (digest: %s)",
filename, sigfile);
switch (cib_file_read_and_verify(filename, sigfile, &root)) {
case -pcmk_err_cib_corrupt:
crm_warn("Continuing but %s will NOT be used.", filename);
break;
case -pcmk_err_cib_modified:
/* Archive the original files so the contents are not lost */
crm_warn("Continuing but %s will NOT be used.", filename);
cib_rename(filename);
cib_rename(sigfile);
break;
}
return root;
}
/*
* for OSs without support for direntry->d_type, like Solaris
*/
#ifndef DT_UNKNOWN
# define DT_UNKNOWN 0
# define DT_FIFO 1
# define DT_CHR 2
# define DT_DIR 4
# define DT_BLK 6
# define DT_REG 8
# define DT_LNK 10
# define DT_SOCK 12
# define DT_WHT 14
#endif /*DT_UNKNOWN*/
static int cib_archive_filter(const struct dirent * a)
{
int rc = 0;
/* Looking for regular files (d_type = 8) starting with 'cib-' and not ending in .sig */
struct stat s;
char *a_path = crm_strdup_printf("%s/%s", cib_root, a->d_name);
if(stat(a_path, &s) != 0) {
rc = errno;
crm_trace("%s - stat failed: %s (%d)", a->d_name, pcmk_rc_str(rc), rc);
rc = 0;
} else if ((s.st_mode & S_IFREG) != S_IFREG) {
unsigned char dtype;
#ifdef HAVE_STRUCT_DIRENT_D_TYPE
dtype = a->d_type;
#else
switch (s.st_mode & S_IFMT) {
case S_IFREG: dtype = DT_REG; break;
case S_IFDIR: dtype = DT_DIR; break;
case S_IFCHR: dtype = DT_CHR; break;
case S_IFBLK: dtype = DT_BLK; break;
case S_IFLNK: dtype = DT_LNK; break;
case S_IFIFO: dtype = DT_FIFO; break;
case S_IFSOCK: dtype = DT_SOCK; break;
default: dtype = DT_UNKNOWN; break;
}
#endif
crm_trace("%s - wrong type (%d)", a->d_name, dtype);
} else if(strstr(a->d_name, "cib-") != a->d_name) {
crm_trace("%s - wrong prefix", a->d_name);
} else if (pcmk__ends_with_ext(a->d_name, ".sig")) {
crm_trace("%s - wrong suffix", a->d_name);
} else {
crm_debug("%s - candidate", a->d_name);
rc = 1;
}
free(a_path);
return rc;
}
static int cib_archive_sort(const struct dirent ** a, const struct dirent **b)
{
/* Order by creation date - most recently created file first */
int rc = 0;
struct stat buf;
time_t a_age = 0;
time_t b_age = 0;
char *a_path = crm_strdup_printf("%s/%s", cib_root, a[0]->d_name);
char *b_path = crm_strdup_printf("%s/%s", cib_root, b[0]->d_name);
if(stat(a_path, &buf) == 0) {
a_age = buf.st_ctime;
}
if(stat(b_path, &buf) == 0) {
b_age = buf.st_ctime;
}
free(a_path);
free(b_path);
if(a_age > b_age) {
rc = 1;
} else if(a_age < b_age) {
rc = -1;
}
crm_trace("%s (%lu) vs. %s (%lu) : %d",
a[0]->d_name, (unsigned long)a_age,
b[0]->d_name, (unsigned long)b_age, rc);
return rc;
}
xmlNode *
readCibXmlFile(const char *dir, const char *file, gboolean discard_status)
{
struct dirent **namelist = NULL;
int lpc = 0;
char *sigfile = NULL;
char *sigfilepath = NULL;
char *filename = NULL;
const char *name = NULL;
const char *value = NULL;
const char *validation = NULL;
const char *use_valgrind = pcmk__env_option(PCMK__ENV_VALGRIND_ENABLED);
xmlNode *root = NULL;
xmlNode *status = NULL;
sigfile = crm_strdup_printf("%s.sig", file);
if (pcmk__daemon_can_write(dir, file) == FALSE
|| pcmk__daemon_can_write(dir, sigfile) == FALSE) {
cib_status = -EACCES;
return NULL;
}
filename = crm_strdup_printf("%s/%s", dir, file);
sigfilepath = crm_strdup_printf("%s/%s", dir, sigfile);
free(sigfile);
cib_status = pcmk_ok;
root = retrieveCib(filename, sigfilepath);
free(filename);
free(sigfilepath);
if (root == NULL) {
crm_warn("Primary configuration corrupt or unusable, trying backups in %s", cib_root);
lpc = scandir(cib_root, &namelist, cib_archive_filter, cib_archive_sort);
if (lpc < 0) {
crm_err("scandir(%s) failed: %s", cib_root, pcmk_rc_str(errno));
}
}
while (root == NULL && lpc > 1) {
crm_debug("Testing %d candidates", lpc);
lpc--;
filename = crm_strdup_printf("%s/%s", cib_root, namelist[lpc]->d_name);
sigfile = crm_strdup_printf("%s.sig", filename);
crm_info("Reading cluster configuration file %s (digest: %s)",
filename, sigfile);
if (cib_file_read_and_verify(filename, sigfile, &root) < 0) {
crm_warn("Continuing but %s will NOT be used.", filename);
} else {
crm_notice("Continuing with last valid configuration archive: %s", filename);
}
free(namelist[lpc]);
free(filename);
free(sigfile);
}
free(namelist);
if (root == NULL) {
root = createEmptyCib(0);
crm_warn("Continuing with an empty configuration.");
}
if (cib_writes_enabled && use_valgrind &&
(crm_is_true(use_valgrind) || strstr(use_valgrind, "pacemaker-based"))) {
cib_writes_enabled = FALSE;
crm_err("*** Disabling disk writes to avoid confusing Valgrind ***");
}
status = pcmk__xe_first_child(root, PCMK_XE_STATUS, NULL, NULL);
if (discard_status && status != NULL) {
// Strip out the PCMK_XE_STATUS section if there is one
free_xml(status);
status = NULL;
}
if (status == NULL) {
pcmk__xe_create(root, PCMK_XE_STATUS);
}
/* Do this before schema validation happens */
/* fill in some defaults */
name = PCMK_XA_ADMIN_EPOCH;
value = crm_element_value(root, name);
if (value == NULL) {
crm_warn("No value for %s was specified in the configuration.", name);
crm_warn("The recommended course of action is to shutdown,"
" run crm_verify and fix any errors it reports.");
crm_warn("We will default to zero and continue but may get"
" confused about which configuration to use if"
" multiple nodes are powered up at the same time.");
crm_xml_add_int(root, name, 0);
}
name = PCMK_XA_EPOCH;
value = crm_element_value(root, name);
if (value == NULL) {
crm_xml_add_int(root, name, 0);
}
name = PCMK_XA_NUM_UPDATES;
value = crm_element_value(root, name);
if (value == NULL) {
crm_xml_add_int(root, name, 0);
}
// Unset (DC should set appropriate value)
pcmk__xe_remove_attr(root, PCMK_XA_DC_UUID);
if (discard_status) {
crm_log_xml_trace(root, "[on-disk]");
}
validation = crm_element_value(root, PCMK_XA_VALIDATE_WITH);
if (validate_xml(root, NULL, TRUE) == FALSE) {
crm_err("CIB does not validate with %s",
pcmk__s(validation, "no schema specified"));
cib_status = -pcmk_err_schema_validation;
} else if (validation == NULL) {
- int version = 0;
-
- update_validation(&root, &version, 0, FALSE, FALSE);
- if (version > 0) {
+ pcmk__update_schema(&root, NULL, false, false);
+ validation = crm_element_value(root, PCMK_XA_VALIDATE_WITH);
+ if (validation != NULL) {
crm_notice("Enabling %s validation on"
- " the existing (sane) configuration", get_schema_name(version));
+ " the existing (sane) configuration", validation);
} else {
crm_err("CIB does not validate with any known schema");
cib_status = -pcmk_err_schema_validation;
}
}
return root;
}
gboolean
uninitializeCib(void)
{
xmlNode *tmp_cib = the_cib;
if (tmp_cib == NULL) {
crm_debug("The CIB has already been deallocated.");
return FALSE;
}
the_cib = NULL;
crm_debug("Deallocating the CIB.");
free_xml(tmp_cib);
crm_debug("The CIB has been deallocated.");
return TRUE;
}
/*
* This method will free the old CIB pointer on success and the new one
* on failure.
*/
int
activateCibXml(xmlNode * new_cib, gboolean to_disk, const char *op)
{
if (new_cib) {
xmlNode *saved_cib = the_cib;
CRM_ASSERT(new_cib != saved_cib);
the_cib = new_cib;
free_xml(saved_cib);
if (cib_writes_enabled && cib_status == pcmk_ok && to_disk) {
crm_debug("Triggering CIB write for %s op", op);
mainloop_set_trigger(cib_writer);
}
return pcmk_ok;
}
crm_err("Ignoring invalid CIB");
if (the_cib) {
crm_warn("Reverting to last known CIB");
} else {
crm_crit("Could not write out new CIB and no saved version to revert to");
}
return -ENODATA;
}
static void
cib_diskwrite_complete(mainloop_child_t * p, pid_t pid, int core, int signo, int exitcode)
{
const char *errmsg = "Could not write CIB to disk";
if ((exitcode != 0) && cib_writes_enabled) {
cib_writes_enabled = FALSE;
errmsg = "Disabling CIB disk writes after failure";
}
if ((signo == 0) && (exitcode == 0)) {
crm_trace("Disk write [%d] succeeded", (int) pid);
} else if (signo == 0) {
crm_err("%s: process %d exited %d", errmsg, (int) pid, exitcode);
} else {
crm_err("%s: process %d terminated with signal %d (%s)%s",
errmsg, (int) pid, signo, strsignal(signo),
(core? " and dumped core" : ""));
}
mainloop_trigger_complete(cib_writer);
}
int
write_cib_contents(gpointer p)
{
int exit_rc = pcmk_ok;
xmlNode *cib_local = NULL;
/* Make a copy of the CIB to write (possibly in a forked child) */
if (p) {
/* Synchronous write out */
cib_local = pcmk__xml_copy(NULL, p);
} else {
int pid = 0;
int bb_state = qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_STATE_GET, 0);
/* Turn it off before the fork() to avoid:
* - 2 processes writing to the same shared mem
* - the child needing to disable it
* (which would close it from underneath the parent)
* This way, the shared mem files are already closed
*/
qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, QB_FALSE);
pid = fork();
if (pid < 0) {
crm_err("Disabling disk writes after fork failure: %s", pcmk_rc_str(errno));
cib_writes_enabled = FALSE;
return FALSE;
}
if (pid) {
/* Parent */
mainloop_child_add(pid, 0, "disk-writer", NULL, cib_diskwrite_complete);
if (bb_state == QB_LOG_STATE_ENABLED) {
/* Re-enable now that it it safe */
qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, QB_TRUE);
}
return -1; /* -1 means 'still work to do' */
}
/* Asynchronous write-out after a fork() */
/* In theory, we can scribble on the_cib here and not affect the parent,
* but let's be safe anyway.
*/
cib_local = pcmk__xml_copy(NULL, the_cib);
}
/* Write the CIB */
exit_rc = cib_file_write_with_digest(cib_local, cib_root, "cib.xml");
/* A nonzero exit code will cause further writes to be disabled */
free_xml(cib_local);
if (p == NULL) {
crm_exit_t exit_code = CRM_EX_OK;
switch (exit_rc) {
case pcmk_ok:
exit_code = CRM_EX_OK;
break;
case pcmk_err_cib_modified:
exit_code = CRM_EX_DIGEST; // Existing CIB doesn't match digest
break;
case pcmk_err_cib_backup: // Existing CIB couldn't be backed up
case pcmk_err_cib_save: // New CIB couldn't be saved
exit_code = CRM_EX_CANTCREAT;
break;
default:
exit_code = CRM_EX_ERROR;
break;
}
/* Use _exit() because exit() could affect the parent adversely */
_exit(exit_code);
}
return exit_rc;
}
diff --git a/daemons/based/based_messages.c b/daemons/based/based_messages.c
index bedf8c90f7..58de8abd59 100644
--- a/daemons/based/based_messages.c
+++ b/daemons/based/based_messages.c
@@ -1,541 +1,539 @@
/*
* Copyright 2004-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU General Public License version 2
* or later (GPLv2+) WITHOUT ANY WARRANTY.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
/* Maximum number of diffs to ignore while waiting for a resync */
#define MAX_DIFF_RETRY 5
bool based_is_primary = false;
xmlNode *the_cib = NULL;
int
cib_process_shutdown_req(const char *op, int options, const char *section, xmlNode * req,
xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
xmlNode ** answer)
{
const char *host = crm_element_value(req, PCMK__XA_SRC);
*answer = NULL;
if (crm_element_value(req, PCMK__XA_CIB_ISREPLYTO) == NULL) {
crm_info("Peer %s is requesting to shut down", host);
return pcmk_ok;
}
if (cib_shutdown_flag == FALSE) {
crm_err("Peer %s mistakenly thinks we wanted to shut down", host);
return -EINVAL;
}
crm_info("Peer %s has acknowledged our shutdown request", host);
terminate_cib(__func__, 0);
return pcmk_ok;
}
// @COMPAT: Remove when PCMK__CIB_REQUEST_NOOP is removed
int
cib_process_noop(const char *op, int options, const char *section, xmlNode *req,
xmlNode *input, xmlNode *existing_cib, xmlNode **result_cib,
xmlNode **answer)
{
crm_trace("Processing \"%s\" event", op);
*answer = NULL;
return pcmk_ok;
}
int
cib_process_readwrite(const char *op, int options, const char *section, xmlNode * req,
xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
xmlNode ** answer)
{
int result = pcmk_ok;
crm_trace("Processing \"%s\" event", op);
if (pcmk__str_eq(op, PCMK__CIB_REQUEST_IS_PRIMARY, pcmk__str_none)) {
if (based_is_primary) {
result = pcmk_ok;
} else {
result = -EPERM;
}
return result;
}
if (pcmk__str_eq(op, PCMK__CIB_REQUEST_PRIMARY, pcmk__str_none)) {
if (!based_is_primary) {
crm_info("We are now in R/W mode");
based_is_primary = true;
} else {
crm_debug("We are still in R/W mode");
}
} else if (based_is_primary) {
crm_info("We are now in R/O mode");
based_is_primary = false;
}
return result;
}
/* Set to 1 when a sync is requested, incremented when a diff is ignored,
* reset to 0 when a sync is received
*/
static int sync_in_progress = 0;
void
send_sync_request(const char *host)
{
xmlNode *sync_me = pcmk__xe_create(NULL, "sync-me");
crm_node_t *peer = NULL;
crm_info("Requesting re-sync from %s", (host? host : "all peers"));
sync_in_progress = 1;
crm_xml_add(sync_me, PCMK__XA_T, PCMK__VALUE_CIB);
crm_xml_add(sync_me, PCMK__XA_CIB_OP, PCMK__CIB_REQUEST_SYNC_TO_ONE);
crm_xml_add(sync_me, PCMK__XA_CIB_DELEGATED_FROM,
stand_alone? "localhost" : crm_cluster->uname);
if (host != NULL) {
peer = pcmk__get_node(0, host, NULL, pcmk__node_search_cluster);
}
send_cluster_message(peer, crm_msg_cib, sync_me, FALSE);
free_xml(sync_me);
}
int
cib_process_ping(const char *op, int options, const char *section, xmlNode * req, xmlNode * input,
xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
{
const char *host = crm_element_value(req, PCMK__XA_SRC);
const char *seq = crm_element_value(req, PCMK__XA_CIB_PING_ID);
char *digest = calculate_xml_versioned_digest(the_cib, FALSE, TRUE, CRM_FEATURE_SET);
xmlNode *wrapper = NULL;
crm_trace("Processing \"%s\" event %s from %s", op, seq, host);
*answer = pcmk__xe_create(NULL, PCMK__XE_PING_RESPONSE);
crm_xml_add(*answer, PCMK_XA_CRM_FEATURE_SET, CRM_FEATURE_SET);
crm_xml_add(*answer, PCMK__XA_DIGEST, digest);
crm_xml_add(*answer, PCMK__XA_CIB_PING_ID, seq);
wrapper = pcmk__xe_create(*answer, PCMK__XE_CIB_CALLDATA);
if (the_cib != NULL) {
pcmk__if_tracing(
{
/* Append additional detail so the receiver can log the
* differences
*/
pcmk__xml_copy(wrapper, the_cib);
},
{
// Always include at least the version details
const char *name = (const char *) the_cib->name;
xmlNode *shallow = pcmk__xe_create(wrapper, name);
copy_in_properties(shallow, the_cib);
}
);
}
crm_info("Reporting our current digest to %s: %s for %s.%s.%s",
host, digest,
crm_element_value(existing_cib, PCMK_XA_ADMIN_EPOCH),
crm_element_value(existing_cib, PCMK_XA_EPOCH),
crm_element_value(existing_cib, PCMK_XA_NUM_UPDATES));
free(digest);
return pcmk_ok;
}
int
cib_process_sync(const char *op, int options, const char *section, xmlNode * req, xmlNode * input,
xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
{
return sync_our_cib(req, TRUE);
}
int
cib_process_upgrade_server(const char *op, int options, const char *section, xmlNode * req, xmlNode * input,
xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
{
int rc = pcmk_ok;
*answer = NULL;
if (crm_element_value(req, PCMK__XA_CIB_SCHEMA_MAX) != NULL) {
/* The originator of an upgrade request sends it to the DC, without
* PCMK__XA_CIB_SCHEMA_MAX. If an upgrade is needed, the DC
* re-broadcasts the request with PCMK__XA_CIB_SCHEMA_MAX, and each node
* performs the upgrade (and notifies its local clients) here.
*/
return cib_process_upgrade(
op, options, section, req, input, existing_cib, result_cib, answer);
} else {
- int new_version = 0;
- int current_version = 0;
xmlNode *scratch = pcmk__xml_copy(NULL, existing_cib);
const char *host = crm_element_value(req, PCMK__XA_SRC);
- const char *value = crm_element_value(existing_cib,
- PCMK_XA_VALIDATE_WITH);
+ const char *original_schema = NULL;
+ const char *new_schema = NULL;
const char *client_id = crm_element_value(req, PCMK__XA_CIB_CLIENTID);
const char *call_opts = crm_element_value(req, PCMK__XA_CIB_CALLOPT);
const char *call_id = crm_element_value(req, PCMK__XA_CIB_CALLID);
crm_trace("Processing \"%s\" event", op);
- if (value != NULL) {
- current_version = get_schema_version(value);
- }
+ original_schema = crm_element_value(existing_cib,
+ PCMK_XA_VALIDATE_WITH);
+ rc = pcmk__update_schema(&scratch, NULL, true, true);
+ rc = pcmk_rc2legacy(rc);
+ new_schema = crm_element_value(scratch, PCMK_XA_VALIDATE_WITH);
- rc = update_validation(&scratch, &new_version, 0, TRUE, TRUE);
- if (new_version > current_version) {
+ if (pcmk__cmp_schemas_by_name(new_schema, original_schema) > 0) {
xmlNode *up = pcmk__xe_create(NULL, __func__);
rc = pcmk_ok;
crm_notice("Upgrade request from %s verified", host);
crm_xml_add(up, PCMK__XA_T, PCMK__VALUE_CIB);
crm_xml_add(up, PCMK__XA_CIB_OP, PCMK__CIB_REQUEST_UPGRADE);
- crm_xml_add(up, PCMK__XA_CIB_SCHEMA_MAX,
- get_schema_name(new_version));
+ crm_xml_add(up, PCMK__XA_CIB_SCHEMA_MAX, new_schema);
crm_xml_add(up, PCMK__XA_CIB_DELEGATED_FROM, host);
crm_xml_add(up, PCMK__XA_CIB_CLIENTID, client_id);
crm_xml_add(up, PCMK__XA_CIB_CALLOPT, call_opts);
crm_xml_add(up, PCMK__XA_CIB_CALLID, call_id);
if (cib_legacy_mode() && based_is_primary) {
rc = cib_process_upgrade(
op, options, section, up, input, existing_cib, result_cib, answer);
} else {
send_cluster_message(NULL, crm_msg_cib, up, FALSE);
}
free_xml(up);
} else if(rc == pcmk_ok) {
rc = -pcmk_err_schema_unchanged;
}
if (rc != pcmk_ok) {
// Notify originating peer so it can notify its local clients
crm_node_t *origin = NULL;
origin = pcmk__search_node_caches(0, host,
pcmk__node_search_cluster);
crm_info("Rejecting upgrade request from %s: %s "
CRM_XS " rc=%d peer=%s", host, pcmk_strerror(rc), rc,
(origin? origin->uname : "lost"));
if (origin) {
xmlNode *up = pcmk__xe_create(NULL, __func__);
crm_xml_add(up, PCMK__XA_T, PCMK__VALUE_CIB);
crm_xml_add(up, PCMK__XA_CIB_OP, PCMK__CIB_REQUEST_UPGRADE);
crm_xml_add(up, PCMK__XA_CIB_DELEGATED_FROM, host);
crm_xml_add(up, PCMK__XA_CIB_ISREPLYTO, host);
crm_xml_add(up, PCMK__XA_CIB_CLIENTID, client_id);
crm_xml_add(up, PCMK__XA_CIB_CALLOPT, call_opts);
crm_xml_add(up, PCMK__XA_CIB_CALLID, call_id);
crm_xml_add_int(up, PCMK__XA_CIB_UPGRADE_RC, rc);
if (send_cluster_message(origin, crm_msg_cib, up, TRUE)
== FALSE) {
crm_warn("Could not send CIB upgrade result to %s", host);
}
free_xml(up);
}
}
free_xml(scratch);
}
return rc;
}
int
cib_process_sync_one(const char *op, int options, const char *section, xmlNode * req,
xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
xmlNode ** answer)
{
return sync_our_cib(req, FALSE);
}
int
cib_server_process_diff(const char *op, int options, const char *section, xmlNode * req,
xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
xmlNode ** answer)
{
int rc = pcmk_ok;
if (sync_in_progress > MAX_DIFF_RETRY) {
/* Don't ignore diffs forever; the last request may have been lost.
* If the diff fails, we'll ask for another full resync.
*/
sync_in_progress = 0;
}
// The primary instance should never ignore a diff
if (sync_in_progress && !based_is_primary) {
int diff_add_updates = 0;
int diff_add_epoch = 0;
int diff_add_admin_epoch = 0;
int diff_del_updates = 0;
int diff_del_epoch = 0;
int diff_del_admin_epoch = 0;
cib_diff_version_details(input,
&diff_add_admin_epoch, &diff_add_epoch, &diff_add_updates,
&diff_del_admin_epoch, &diff_del_epoch, &diff_del_updates);
sync_in_progress++;
crm_notice("Not applying diff %d.%d.%d -> %d.%d.%d (sync in progress)",
diff_del_admin_epoch, diff_del_epoch, diff_del_updates,
diff_add_admin_epoch, diff_add_epoch, diff_add_updates);
return -pcmk_err_diff_resync;
}
rc = cib_process_diff(op, options, section, req, input, existing_cib, result_cib, answer);
crm_trace("result: %s (%d), %s", pcmk_strerror(rc), rc,
(based_is_primary? "primary": "secondary"));
if ((rc == -pcmk_err_diff_resync) && !based_is_primary) {
free_xml(*result_cib);
*result_cib = NULL;
send_sync_request(NULL);
} else if (rc == -pcmk_err_diff_resync) {
rc = -pcmk_err_diff_failed;
if (options & cib_force_diff) {
crm_warn("Not requesting full refresh in R/W mode");
}
} else if ((rc != pcmk_ok) && !based_is_primary && cib_legacy_mode()) {
crm_warn("Requesting full CIB refresh because update failed: %s"
CRM_XS " rc=%d", pcmk_strerror(rc), rc);
pcmk__log_xml_patchset(LOG_INFO, input);
free_xml(*result_cib);
*result_cib = NULL;
send_sync_request(NULL);
}
return rc;
}
int
cib_process_replace_svr(const char *op, int options, const char *section, xmlNode * req,
xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
xmlNode ** answer)
{
int rc =
cib_process_replace(op, options, section, req, input, existing_cib, result_cib, answer);
if ((rc == pcmk_ok) && pcmk__xe_is(input, PCMK_XE_CIB)) {
sync_in_progress = 0;
}
return rc;
}
// @COMPAT: Remove when PCMK__CIB_REQUEST_ABS_DELETE is removed
int
cib_process_delete_absolute(const char *op, int options, const char *section, xmlNode * req,
xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
xmlNode ** answer)
{
return -EINVAL;
}
static xmlNode *
cib_msg_copy(xmlNode *msg)
{
static const char *field_list[] = {
PCMK__XA_T,
PCMK__XA_CIB_CLIENTID,
PCMK__XA_CIB_CALLOPT,
PCMK__XA_CIB_CALLID,
PCMK__XA_CIB_OP,
PCMK__XA_CIB_ISREPLYTO,
PCMK__XA_CIB_SECTION,
PCMK__XA_CIB_HOST,
PCMK__XA_CIB_RC,
PCMK__XA_CIB_DELEGATED_FROM,
PCMK__XA_CIB_OBJECT,
PCMK__XA_CIB_OBJECT_TYPE,
PCMK__XA_CIB_UPDATE,
PCMK__XA_CIB_CLIENTNAME,
PCMK__XA_CIB_USER,
PCMK__XA_CIB_NOTIFY_TYPE,
PCMK__XA_CIB_NOTIFY_ACTIVATE,
};
xmlNode *copy = pcmk__xe_create(NULL, PCMK__XE_COPY);
for (int lpc = 0; lpc < PCMK__NELEM(field_list); lpc++) {
const char *field = field_list[lpc];
const char *value = crm_element_value(msg, field);
if (value != NULL) {
crm_xml_add(copy, field, value);
}
}
return copy;
}
int
sync_our_cib(xmlNode * request, gboolean all)
{
int result = pcmk_ok;
char *digest = NULL;
const char *host = crm_element_value(request, PCMK__XA_SRC);
const char *op = crm_element_value(request, PCMK__XA_CIB_OP);
crm_node_t *peer = NULL;
xmlNode *replace_request = NULL;
xmlNode *wrapper = NULL;
CRM_CHECK(the_cib != NULL, return -EINVAL);
CRM_CHECK(all || (host != NULL), return -EINVAL);
crm_debug("Syncing CIB to %s", all ? "all peers" : host);
replace_request = cib_msg_copy(request);
if (host != NULL) {
crm_xml_add(replace_request, PCMK__XA_CIB_ISREPLYTO, host);
}
if (all) {
pcmk__xe_remove_attr(replace_request, PCMK__XA_CIB_HOST);
}
crm_xml_add(replace_request, PCMK__XA_CIB_OP, PCMK__CIB_REQUEST_REPLACE);
// @TODO Keep for tracing, or drop?
crm_xml_add(replace_request, PCMK__XA_ORIGINAL_CIB_OP, op);
pcmk__xe_set_bool_attr(replace_request, PCMK__XA_CIB_UPDATE, true);
crm_xml_add(replace_request, PCMK_XA_CRM_FEATURE_SET, CRM_FEATURE_SET);
digest = calculate_xml_versioned_digest(the_cib, FALSE, TRUE, CRM_FEATURE_SET);
crm_xml_add(replace_request, PCMK__XA_DIGEST, digest);
wrapper = pcmk__xe_create(replace_request, PCMK__XE_CIB_CALLDATA);
pcmk__xml_copy(wrapper, the_cib);
if (!all) {
peer = pcmk__get_node(0, host, NULL, pcmk__node_search_cluster);
}
if (!send_cluster_message(peer, crm_msg_cib, replace_request, FALSE)) {
result = -ENOTCONN;
}
free_xml(replace_request);
free(digest);
return result;
}
int
cib_process_commit_transaction(const char *op, int options, const char *section,
xmlNode *req, xmlNode *input,
xmlNode *existing_cib, xmlNode **result_cib,
xmlNode **answer)
{
/* On success, our caller will activate *result_cib locally, trigger a
* replace notification if appropriate, and sync *result_cib to all nodes.
* On failure, our caller will free *result_cib.
*/
int rc = pcmk_rc_ok;
const char *client_id = crm_element_value(req, PCMK__XA_CIB_CLIENTID);
const char *origin = crm_element_value(req, PCMK__XA_SRC);
pcmk__client_t *client = pcmk__find_client_by_id(client_id);
rc = based_commit_transaction(input, client, origin, result_cib);
if (rc != pcmk_rc_ok) {
char *source = based_transaction_source_str(client, origin);
crm_err("Could not commit transaction for %s: %s",
source, pcmk_rc_str(rc));
free(source);
}
return pcmk_rc2legacy(rc);
}
int
cib_process_schemas(const char *op, int options, const char *section, xmlNode *req,
xmlNode *input, xmlNode *existing_cib, xmlNode **result_cib,
xmlNode **answer)
{
xmlNode *wrapper = NULL;
xmlNode *data = NULL;
const char *after_ver = NULL;
GList *schemas = NULL;
GList *already_included = NULL;
*answer = pcmk__xe_create(NULL, PCMK__XA_SCHEMAS);
wrapper = pcmk__xe_first_child(req, PCMK__XE_CIB_CALLDATA, NULL, NULL);
data = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
if (data == NULL) {
crm_warn("No data specified in request");
return -EPROTO;
}
after_ver = crm_element_value(data, PCMK_XA_VERSION);
if (after_ver == NULL) {
crm_warn("No version specified in request");
return -EPROTO;
}
/* The client requested all schemas after the latest one we know about, which
* means the client is fully up-to-date. Return a properly formatted reply
* with no schemas.
*/
if (pcmk__str_eq(after_ver, xml_latest_schema(), pcmk__str_none)) {
return pcmk_ok;
}
schemas = pcmk__schema_files_later_than(after_ver);
for (GList *iter = schemas; iter != NULL; iter = iter->next) {
pcmk__build_schema_xml_node(*answer, iter->data, &already_included);
}
g_list_free_full(schemas, free);
g_list_free_full(already_included, free);
return pcmk_ok;
}
diff --git a/include/crm/common/Makefile.am b/include/crm/common/Makefile.am
index 1cef64c405..64adbf526a 100644
--- a/include/crm/common/Makefile.am
+++ b/include/crm/common/Makefile.am
@@ -1,53 +1,54 @@
#
# Copyright 2004-2024 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# or later (GPLv2+) WITHOUT ANY WARRANTY.
#
MAINTAINERCLEANFILES = Makefile.in
headerdir=$(pkgincludedir)/crm/common
header_HEADERS = acl.h \
actions.h \
agents.h \
agents_compat.h \
cib.h \
ipc.h \
ipc_controld.h \
ipc_pacemakerd.h \
ipc_schedulerd.h \
iso8601.h \
logging.h \
logging_compat.h \
mainloop.h \
mainloop_compat.h \
nodes.h \
nodes_internal.h \
nvpair.h \
options.h \
output.h \
resources.h \
results.h \
results_compat.h \
roles.h \
rules.h \
scheduler.h \
scheduler_types.h \
schemas.h \
+ schemas_compat.h \
scores.h \
scores_compat.h \
tags.h \
tickets.h \
util.h \
util_compat.h \
xml.h \
xml_compat.h \
xml_io.h \
xml_io_compat.h \
xml_names.h
noinst_HEADERS = $(wildcard *internal.h)
diff --git a/include/crm/common/schemas.h b/include/crm/common/schemas.h
index 423a8cc407..ade23829ad 100644
--- a/include/crm/common/schemas.h
+++ b/include/crm/common/schemas.h
@@ -1,69 +1,33 @@
/*
* Copyright 2004-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/
#ifndef PCMK__CRM_COMMON_SCHEMAS__H
# define PCMK__CRM_COMMON_SCHEMAS__H
#include // gboolean
#include // xmlNode
-/*!
- * \brief Update CIB XML to most recent schema version
- *
- * "Update" means either actively employ XSLT-based transformation(s)
- * (if intermediate product to transform valid per its declared schema version,
- * transformation available, proceeded successfully with a result valid per
- * expectated newer schema version), or just try to bump the marked validating
- * schema until all gradually rising schema versions attested or the first
- * such attempt subsequently fails to validate. Which of the two styles will
- * be used depends on \p transform parameter (positive/negative, respectively).
- *
- * \param[in,out] xml_blob XML tree representing CIB, may be swapped with
- * an "updated" one
- * \param[out] best The highest configuration version (per its index
- * in the global schemas table) it was possible to
- * reach during the update steps while ensuring
- * the validity of the result; if no validation
- * success was observed against possibly multiple
- * schemas, the value is less or equal the result
- * of \c get_schema_version applied on the input
- * \p xml_blob value (unless that function maps it
- * to -1, then 0 would be used instead)
- * \param[in] max When \p transform is positive, this allows to
- * set upper boundary schema (per its index in the
- * global schemas table) beyond which it's forbidden
- * to update by the means of XSLT transformation
- * \param[in] transform Whether to employ XSLT-based transformation so
- * as to allow overcoming possible incompatibilities
- * between major schema versions (see above)
- * \param[in] to_logs If true, output notable progress info to
- * internal log streams; if false, to stderr
- *
- * \return \c pcmk_ok if no non-recoverable error encountered (up to
- * caller to evaluate if the update satisfies the requirements
- * per returned \p best value), negative value carrying the reason
- * otherwise
- */
-int update_validation(xmlNode **xml_blob, int *best, int max,
- gboolean transform, gboolean to_logs);
-
gboolean validate_xml(xmlNode *xml_blob, const char *validation,
gboolean to_logs);
gboolean validate_xml_verbose(const xmlNode *xml_blob);
int get_schema_version(const char *name);
const char *get_schema_name(int version);
const char *xml_latest_schema(void);
gboolean cli_config_update(xmlNode ** xml, int *best_version, gboolean to_logs);
+#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
+#include
+#endif
+
#ifdef __cplusplus
}
#endif
#endif // PCMK__CRM_COMMON_SCHEMAS__H
diff --git a/include/crm/common/schemas_compat.h b/include/crm/common/schemas_compat.h
new file mode 100644
index 0000000000..39ff71cd89
--- /dev/null
+++ b/include/crm/common/schemas_compat.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2024 the Pacemaker project contributors
+ *
+ * The version control history for this file may have further details.
+ *
+ * This source code is licensed under the GNU Lesser General Public License
+ * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
+ */
+
+#ifndef PCMK__CRM_COMMON_SCHEMAS_COMPAT__H
+#define PCMK__CRM_COMMON_SCHEMAS_COMPAT__H
+
+#include // xmlNode
+#include // gboolean
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \file
+ * \brief Deprecated Pacemaker XML schemas API
+ * \ingroup core
+ * \deprecated Do not include this header directly. The APIs in this header, and
+ * the header itself, will be removed in a future release.
+ */
+
+//! \deprecated Do not use
+int update_validation(xmlNode **xml_blob, int *best, int max,
+ gboolean transform, gboolean to_logs);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // PCMK__CRM_COMMON_SCHEMAS_COMPAT__H
diff --git a/include/crm/common/schemas_internal.h b/include/crm/common/schemas_internal.h
index 89736474d2..4c398f7dcb 100644
--- a/include/crm/common/schemas_internal.h
+++ b/include/crm/common/schemas_internal.h
@@ -1,32 +1,34 @@
/*
* Copyright 2006-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/
#ifndef PCMK__SCHEMAS_INTERNAL__H
# define PCMK__SCHEMAS_INTERNAL__H
#include // GList, gboolean
#include // xmlNode, xmlRelaxNGValidityErrorFunc
void crm_schema_init(void);
void crm_schema_cleanup(void);
void pcmk__load_schemas_from_dir(const char *dir);
void pcmk__sort_schemas(void);
GList *pcmk__schema_files_later_than(const char *name);
void pcmk__build_schema_xml_node(xmlNode *parent, const char *name,
GList **already_included);
const char *pcmk__remote_schema_dir(void);
GList *pcmk__get_schema(const char *name);
int pcmk__cmp_schemas_by_name(const char *schema1_name,
const char *schema2_name);
gboolean pcmk__validate_xml(xmlNode *xml_blob, const char *validation,
xmlRelaxNGValidityErrorFunc error_handler,
void *error_handler_context);
+int pcmk__update_schema(xmlNode **xml, const char *max_schema_name,
+ bool transform, bool to_logs);
#endif // PCMK__SCHEMAS_INTERNAL__H
diff --git a/lib/cib/cib_ops.c b/lib/cib/cib_ops.c
index 593d6c97fd..5f92b78cbd 100644
--- a/lib/cib/cib_ops.c
+++ b/lib/cib/cib_ops.c
@@ -1,904 +1,898 @@
/*
* Copyright 2004-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
// @TODO: Free this via crm_exit() when libcib gets merged with libcrmcommon
static GHashTable *operation_table = NULL;
static const cib__operation_t cib_ops[] = {
{
PCMK__CIB_REQUEST_ABS_DELETE, cib__op_abs_delete,
cib__op_attr_modifies|cib__op_attr_privileged
},
{
PCMK__CIB_REQUEST_APPLY_PATCH, cib__op_apply_patch,
cib__op_attr_modifies
|cib__op_attr_privileged
|cib__op_attr_transaction
},
{
PCMK__CIB_REQUEST_BUMP, cib__op_bump,
cib__op_attr_modifies
|cib__op_attr_privileged
|cib__op_attr_transaction
},
{
PCMK__CIB_REQUEST_COMMIT_TRANSACT, cib__op_commit_transact,
cib__op_attr_modifies
|cib__op_attr_privileged
|cib__op_attr_replaces
|cib__op_attr_writes_through
},
{
PCMK__CIB_REQUEST_CREATE, cib__op_create,
cib__op_attr_modifies
|cib__op_attr_privileged
|cib__op_attr_transaction
},
{
PCMK__CIB_REQUEST_DELETE, cib__op_delete,
cib__op_attr_modifies
|cib__op_attr_privileged
|cib__op_attr_transaction
},
{
PCMK__CIB_REQUEST_ERASE, cib__op_erase,
cib__op_attr_modifies
|cib__op_attr_privileged
|cib__op_attr_replaces
|cib__op_attr_transaction
},
{
PCMK__CIB_REQUEST_IS_PRIMARY, cib__op_is_primary,
cib__op_attr_privileged
},
{
PCMK__CIB_REQUEST_MODIFY, cib__op_modify,
cib__op_attr_modifies
|cib__op_attr_privileged
|cib__op_attr_transaction
},
{
PCMK__CIB_REQUEST_NOOP, cib__op_noop, cib__op_attr_none
},
{
CRM_OP_PING, cib__op_ping, cib__op_attr_none
},
{
// @COMPAT: Drop cib__op_attr_modifies when we drop legacy mode support
PCMK__CIB_REQUEST_PRIMARY, cib__op_primary,
cib__op_attr_modifies|cib__op_attr_privileged|cib__op_attr_local
},
{
PCMK__CIB_REQUEST_QUERY, cib__op_query, cib__op_attr_none
},
{
PCMK__CIB_REQUEST_REPLACE, cib__op_replace,
cib__op_attr_modifies
|cib__op_attr_privileged
|cib__op_attr_replaces
|cib__op_attr_writes_through
|cib__op_attr_transaction
},
{
PCMK__CIB_REQUEST_SECONDARY, cib__op_secondary,
cib__op_attr_privileged|cib__op_attr_local
},
{
PCMK__CIB_REQUEST_SHUTDOWN, cib__op_shutdown, cib__op_attr_privileged
},
{
PCMK__CIB_REQUEST_SYNC_TO_ALL, cib__op_sync_all, cib__op_attr_privileged
},
{
PCMK__CIB_REQUEST_SYNC_TO_ONE, cib__op_sync_one, cib__op_attr_privileged
},
{
PCMK__CIB_REQUEST_UPGRADE, cib__op_upgrade,
cib__op_attr_modifies
|cib__op_attr_privileged
|cib__op_attr_writes_through
|cib__op_attr_transaction
},
{
PCMK__CIB_REQUEST_SCHEMAS, cib__op_schemas, cib__op_attr_local
}
};
/*!
* \internal
* \brief Get the \c cib__operation_t object for a given CIB operation name
*
* \param[in] op CIB operation name
* \param[out] operation Where to store CIB operation object
*
* \return Standard Pacemaker return code
*/
int
cib__get_operation(const char *op, const cib__operation_t **operation)
{
CRM_ASSERT((op != NULL) && (operation != NULL));
if (operation_table == NULL) {
operation_table = pcmk__strkey_table(NULL, NULL);
for (int lpc = 0; lpc < PCMK__NELEM(cib_ops); lpc++) {
const cib__operation_t *oper = &(cib_ops[lpc]);
g_hash_table_insert(operation_table, (gpointer) oper->name,
(gpointer) oper);
}
}
*operation = g_hash_table_lookup(operation_table, op);
if (*operation == NULL) {
crm_err("Operation %s is invalid", op);
return EINVAL;
}
return pcmk_rc_ok;
}
int
cib_process_query(const char *op, int options, const char *section, xmlNode * req, xmlNode * input,
xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
{
xmlNode *obj_root = NULL;
int result = pcmk_ok;
crm_trace("Processing %s for %s section",
op, pcmk__s(section, "unspecified"));
if (options & cib_xpath) {
return cib_process_xpath(op, options, section, req, input,
existing_cib, result_cib, answer);
}
CRM_CHECK(*answer == NULL, free_xml(*answer));
*answer = NULL;
if (pcmk__str_eq(PCMK__XE_ALL, section, pcmk__str_casei)) {
section = NULL;
}
obj_root = pcmk_find_cib_element(existing_cib, section);
if (obj_root == NULL) {
result = -ENXIO;
} else if (options & cib_no_children) {
xmlNode *shallow = pcmk__xe_create(*answer,
(const char *) obj_root->name);
copy_in_properties(shallow, obj_root);
*answer = shallow;
} else {
*answer = obj_root;
}
if (result == pcmk_ok && *answer == NULL) {
crm_err("Error creating query response");
result = -ENOMSG;
}
return result;
}
static int
update_counter(xmlNode *xml_obj, const char *field, bool reset)
{
char *new_value = NULL;
char *old_value = NULL;
int int_value = -1;
if (!reset && crm_element_value(xml_obj, field) != NULL) {
old_value = crm_element_value_copy(xml_obj, field);
}
if (old_value != NULL) {
int_value = atoi(old_value);
new_value = pcmk__itoa(++int_value);
} else {
new_value = pcmk__str_copy("1");
}
crm_trace("Update %s from %s to %s",
field, pcmk__s(old_value, "unset"), new_value);
crm_xml_add(xml_obj, field, new_value);
free(new_value);
free(old_value);
return pcmk_ok;
}
int
cib_process_erase(const char *op, int options, const char *section, xmlNode * req, xmlNode * input,
xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
{
int result = pcmk_ok;
crm_trace("Processing \"%s\" event", op);
if (*result_cib != existing_cib) {
free_xml(*result_cib);
}
*result_cib = createEmptyCib(0);
copy_in_properties(*result_cib, existing_cib);
update_counter(*result_cib, PCMK_XA_ADMIN_EPOCH, false);
*answer = NULL;
return result;
}
int
cib_process_upgrade(const char *op, int options, const char *section, xmlNode * req,
xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
xmlNode ** answer)
{
int rc = 0;
- int new_version = 0;
- int current_version = 0;
- int max_version = 0;
- const char *max = crm_element_value(req, PCMK__XA_CIB_SCHEMA_MAX);
- const char *value = crm_element_value(existing_cib, PCMK_XA_VALIDATE_WITH);
+ const char *max_schema = crm_element_value(req, PCMK__XA_CIB_SCHEMA_MAX);
+ const char *original_schema = NULL;
+ const char *new_schema = NULL;
*answer = NULL;
- crm_trace("Processing \"%s\" event with max=%s", op, max);
+ crm_trace("Processing \"%s\" event with max=%s", op, max_schema);
- if (value != NULL) {
- current_version = get_schema_version(value);
- }
-
- if (max) {
- max_version = get_schema_version(max);
- }
+ original_schema = crm_element_value(existing_cib, PCMK_XA_VALIDATE_WITH);
+ rc = pcmk__update_schema(result_cib, max_schema, true,
+ !pcmk_is_set(options, cib_verbose));
+ rc = pcmk_rc2legacy(rc);
+ new_schema = crm_element_value(*result_cib, PCMK_XA_VALIDATE_WITH);
- rc = update_validation(result_cib, &new_version, max_version, TRUE,
- !(options & cib_verbose));
- if (new_version > current_version) {
+ if (pcmk__cmp_schemas_by_name(new_schema, original_schema) > 0) {
update_counter(*result_cib, PCMK_XA_ADMIN_EPOCH, false);
update_counter(*result_cib, PCMK_XA_EPOCH, true);
update_counter(*result_cib, PCMK_XA_NUM_UPDATES, true);
return pcmk_ok;
}
return rc;
}
int
cib_process_bump(const char *op, int options, const char *section, xmlNode * req, xmlNode * input,
xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
{
int result = pcmk_ok;
crm_trace("Processing %s for epoch='%s'", op,
pcmk__s(crm_element_value(existing_cib, PCMK_XA_EPOCH), ""));
*answer = NULL;
update_counter(*result_cib, PCMK_XA_EPOCH, false);
return result;
}
int
cib_process_replace(const char *op, int options, const char *section, xmlNode * req,
xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
xmlNode ** answer)
{
int result = pcmk_ok;
crm_trace("Processing %s for %s section",
op, pcmk__s(section, "unspecified"));
if (options & cib_xpath) {
return cib_process_xpath(op, options, section, req, input,
existing_cib, result_cib, answer);
}
*answer = NULL;
if (input == NULL) {
return -EINVAL;
}
if (pcmk__str_eq(PCMK__XE_ALL, section, pcmk__str_casei)) {
section = NULL;
} else if (pcmk__xe_is(input, section)) {
section = NULL;
}
if (pcmk__xe_is(input, PCMK_XE_CIB)) {
int updates = 0;
int epoch = 0;
int admin_epoch = 0;
int replace_updates = 0;
int replace_epoch = 0;
int replace_admin_epoch = 0;
const char *reason = NULL;
const char *peer = crm_element_value(req, PCMK__XA_SRC);
const char *digest = crm_element_value(req, PCMK__XA_DIGEST);
if (digest) {
const char *version = crm_element_value(req,
PCMK_XA_CRM_FEATURE_SET);
char *digest_verify = calculate_xml_versioned_digest(input, FALSE, TRUE,
version ? version :
CRM_FEATURE_SET);
if (!pcmk__str_eq(digest_verify, digest, pcmk__str_casei)) {
crm_err("Digest mis-match on replace from %s: %s vs. %s (expected)", peer,
digest_verify, digest);
reason = "digest mismatch";
} else {
crm_info("Digest matched on replace from %s: %s", peer, digest);
}
free(digest_verify);
} else {
crm_trace("No digest to verify");
}
cib_version_details(existing_cib, &admin_epoch, &epoch, &updates);
cib_version_details(input, &replace_admin_epoch, &replace_epoch, &replace_updates);
if (replace_admin_epoch < admin_epoch) {
reason = PCMK_XA_ADMIN_EPOCH;
} else if (replace_admin_epoch > admin_epoch) {
/* no more checks */
} else if (replace_epoch < epoch) {
reason = PCMK_XA_EPOCH;
} else if (replace_epoch > epoch) {
/* no more checks */
} else if (replace_updates < updates) {
reason = PCMK_XA_NUM_UPDATES;
}
if (reason != NULL) {
crm_info("Replacement %d.%d.%d from %s not applied to %d.%d.%d:"
" current %s is greater than the replacement",
replace_admin_epoch, replace_epoch,
replace_updates, peer, admin_epoch, epoch, updates, reason);
result = -pcmk_err_old_data;
} else {
crm_info("Replaced %d.%d.%d with %d.%d.%d from %s",
admin_epoch, epoch, updates,
replace_admin_epoch, replace_epoch, replace_updates, peer);
}
if (*result_cib != existing_cib) {
free_xml(*result_cib);
}
*result_cib = pcmk__xml_copy(NULL, input);
} else {
xmlNode *obj_root = NULL;
obj_root = pcmk_find_cib_element(*result_cib, section);
result = pcmk__xe_replace_match(obj_root, input);
result = pcmk_rc2legacy(result);
if (result != pcmk_ok) {
crm_trace("No matching object to replace");
}
}
return result;
}
static int
delete_child(xmlNode *child, void *userdata)
{
xmlNode *obj_root = userdata;
if (pcmk__xe_delete_match(obj_root, child) != pcmk_rc_ok) {
crm_trace("No matching object to delete: %s=%s",
child->name, pcmk__xe_id(child));
}
return pcmk_rc_ok;
}
int
cib_process_delete(const char *op, int options, const char *section, xmlNode * req, xmlNode * input,
xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
{
xmlNode *obj_root = NULL;
crm_trace("Processing \"%s\" event", op);
if (options & cib_xpath) {
return cib_process_xpath(op, options, section, req, input,
existing_cib, result_cib, answer);
}
if (input == NULL) {
crm_err("Cannot perform modification with no data");
return -EINVAL;
}
obj_root = pcmk_find_cib_element(*result_cib, section);
if (pcmk__xe_is(input, section)) {
pcmk__xe_foreach_child(input, NULL, delete_child, obj_root);
} else {
delete_child(input, obj_root);
}
return pcmk_ok;
}
int
cib_process_modify(const char *op, int options, const char *section, xmlNode * req, xmlNode * input,
xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
{
xmlNode *obj_root = NULL;
crm_trace("Processing \"%s\" event", op);
if (options & cib_xpath) {
return cib_process_xpath(op, options, section, req, input,
existing_cib, result_cib, answer);
}
if (input == NULL) {
crm_err("Cannot perform modification with no data");
return -EINVAL;
}
obj_root = pcmk_find_cib_element(*result_cib, section);
if (obj_root == NULL) {
xmlNode *tmp_section = NULL;
const char *path = pcmk_cib_parent_name_for(section);
if (path == NULL) {
return -EINVAL;
}
tmp_section = pcmk__xe_create(NULL, section);
cib_process_xpath(PCMK__CIB_REQUEST_CREATE, 0, path, NULL, tmp_section,
NULL, result_cib, answer);
free_xml(tmp_section);
obj_root = pcmk_find_cib_element(*result_cib, section);
}
CRM_CHECK(obj_root != NULL, return -EINVAL);
if (pcmk__xe_update_match(obj_root, input) != pcmk_rc_ok) {
if (options & cib_can_create) {
pcmk__xml_copy(obj_root, input);
} else {
return -ENXIO;
}
}
// @COMPAT cib_mixed_update is deprecated as of 2.1.7
if (pcmk_is_set(options, cib_mixed_update)) {
int max = 0, lpc;
xmlXPathObjectPtr xpathObj = xpath_search(*result_cib, "//@__delete__");
if (xpathObj) {
max = numXpathResults(xpathObj);
crm_log_xml_trace(*result_cib, "Mixed result");
}
for (lpc = 0; lpc < max; lpc++) {
xmlNode *match = getXpathResult(xpathObj, lpc);
xmlChar *match_path = xmlGetNodePath(match);
crm_debug("Destroying %s", match_path);
free(match_path);
free_xml(match);
}
freeXpathObject(xpathObj);
}
return pcmk_ok;
}
static int
add_cib_object(xmlNode * parent, xmlNode * new_obj)
{
const char *object_name = NULL;
const char *object_id = NULL;
if ((parent == NULL) || (new_obj == NULL)) {
return -EINVAL;
}
object_name = (const char *) new_obj->name;
if (object_name == NULL) {
return -EINVAL;
}
object_id = pcmk__xe_id(new_obj);
if (pcmk__xe_first_child(parent, object_name,
((object_id != NULL)? PCMK_XA_ID : NULL),
object_id)) {
return -EEXIST;
}
if (object_id != NULL) {
crm_trace("Processing creation of <%s " PCMK_XA_ID "='%s'>",
object_name, object_id);
} else {
crm_trace("Processing creation of <%s>", object_name);
}
/* @COMPAT PCMK__XA_REPLACE is deprecated since 2.1.6. Due to a legacy use
* case, PCMK__XA_REPLACE has special meaning and should not be included in
* the newly created object until we can break behavioral backward
* compatibility.
*
* At a compatibility break, drop this and drop the definition of
* PCMK__XA_REPLACE. Treat it like any other attribute.
*/
pcmk__xml_tree_foreach(new_obj, pcmk__xe_remove_attr_cb,
(void *) PCMK__XA_REPLACE);
pcmk__xml_copy(parent, new_obj);
return pcmk_ok;
}
static bool
update_results(xmlNode *failed, xmlNode *target, const char *operation,
int return_code)
{
xmlNode *xml_node = NULL;
bool was_error = false;
const char *error_msg = NULL;
if (return_code != pcmk_ok) {
error_msg = pcmk_strerror(return_code);
was_error = true;
xml_node = pcmk__xe_create(failed, PCMK__XE_FAILED_UPDATE);
pcmk__xml_copy(xml_node, target);
crm_xml_add(xml_node, PCMK_XA_ID, pcmk__xe_id(target));
crm_xml_add(xml_node, PCMK_XA_OBJECT_TYPE, (const char *) target->name);
crm_xml_add(xml_node, PCMK_XA_OPERATION, operation);
crm_xml_add(xml_node, PCMK_XA_REASON, error_msg);
crm_warn("Action %s failed: %s (cde=%d)",
operation, error_msg, return_code);
}
return was_error;
}
int
cib_process_create(const char *op, int options, const char *section, xmlNode * req, xmlNode * input,
xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
{
xmlNode *failed = NULL;
int result = pcmk_ok;
xmlNode *update_section = NULL;
crm_trace("Processing %s for %s section",
op, pcmk__s(section, "unspecified"));
if (pcmk__str_eq(PCMK__XE_ALL, section, pcmk__str_casei)) {
section = NULL;
} else if (pcmk__str_eq(section, PCMK_XE_CIB, pcmk__str_casei)) {
section = NULL;
} else if (pcmk__xe_is(input, PCMK_XE_CIB)) {
section = NULL;
}
CRM_CHECK(strcmp(op, PCMK__CIB_REQUEST_CREATE) == 0, return -EINVAL);
if (input == NULL) {
crm_err("Cannot perform modification with no data");
return -EINVAL;
}
if (section == NULL) {
return cib_process_modify(op, options, section, req, input, existing_cib, result_cib,
answer);
}
// @COMPAT Deprecated since 2.1.8
failed = pcmk__xe_create(NULL, PCMK__XE_FAILED);
update_section = pcmk_find_cib_element(*result_cib, section);
if (pcmk__xe_is(input, section)) {
xmlNode *a_child = NULL;
for (a_child = pcmk__xml_first_child(input); a_child != NULL;
a_child = pcmk__xml_next(a_child)) {
result = add_cib_object(update_section, a_child);
if (update_results(failed, a_child, op, result)) {
break;
}
}
} else {
result = add_cib_object(update_section, input);
update_results(failed, input, op, result);
}
if ((result == pcmk_ok) && (failed->children != NULL)) {
result = -EINVAL;
}
if (result != pcmk_ok) {
crm_log_xml_err(failed, "CIB Update failures");
*answer = failed;
} else {
free_xml(failed);
}
return result;
}
int
cib_process_diff(const char *op, int options, const char *section, xmlNode * req, xmlNode * input,
xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
{
const char *originator = NULL;
if (req != NULL) {
originator = crm_element_value(req, PCMK__XA_SRC);
}
crm_trace("Processing \"%s\" event from %s%s",
op, originator,
(pcmk_is_set(options, cib_force_diff)? " (global update)" : ""));
if (*result_cib != existing_cib) {
free_xml(*result_cib);
}
*result_cib = pcmk__xml_copy(NULL, existing_cib);
return xml_apply_patchset(*result_cib, input, TRUE);
}
// @COMPAT: v1-only
bool
cib__config_changed_v1(xmlNode *last, xmlNode *next, xmlNode **diff)
{
int lpc = 0, max = 0;
bool config_changes = false;
xmlXPathObject *xpathObj = NULL;
int format = 1;
CRM_ASSERT(diff != NULL);
if (*diff == NULL && last != NULL && next != NULL) {
*diff = pcmk__diff_v1_xml_object(last, next, false);
}
if (*diff == NULL) {
goto done;
}
crm_element_value_int(*diff, PCMK_XA_FORMAT, &format);
CRM_LOG_ASSERT(format == 1);
xpathObj = xpath_search(*diff, "//" PCMK_XE_CONFIGURATION);
if (numXpathResults(xpathObj) > 0) {
config_changes = true;
goto done;
}
freeXpathObject(xpathObj);
/*
* Do not check PCMK__XE_DIFF_ADDED "//" PCMK_XE_CIB
* This always contains every field and would produce a false positive
* every time if the checked value existed
*/
xpathObj = xpath_search(*diff, "//" PCMK__XE_DIFF_REMOVED "//" PCMK_XE_CIB);
max = numXpathResults(xpathObj);
for (lpc = 0; lpc < max; lpc++) {
xmlNode *top = getXpathResult(xpathObj, lpc);
if (crm_element_value(top, PCMK_XA_EPOCH) != NULL) {
config_changes = true;
goto done;
}
if (crm_element_value(top, PCMK_XA_ADMIN_EPOCH) != NULL) {
config_changes = true;
goto done;
}
if (crm_element_value(top, PCMK_XA_VALIDATE_WITH) != NULL) {
config_changes = true;
goto done;
}
if (crm_element_value(top, PCMK_XA_CRM_FEATURE_SET) != NULL) {
config_changes = true;
goto done;
}
if (crm_element_value(top, PCMK_XA_REMOTE_CLEAR_PORT) != NULL) {
config_changes = true;
goto done;
}
if (crm_element_value(top, PCMK_XA_REMOTE_TLS_PORT) != NULL) {
config_changes = true;
goto done;
}
}
done:
freeXpathObject(xpathObj);
return config_changes;
}
int
cib_process_xpath(const char *op, int options, const char *section,
const xmlNode *req, xmlNode *input, xmlNode *existing_cib,
xmlNode **result_cib, xmlNode **answer)
{
int lpc = 0;
int max = 0;
int rc = pcmk_ok;
bool is_query = pcmk__str_eq(op, PCMK__CIB_REQUEST_QUERY, pcmk__str_none);
xmlXPathObjectPtr xpathObj = NULL;
crm_trace("Processing \"%s\" event", op);
if (is_query) {
xpathObj = xpath_search(existing_cib, section);
} else {
xpathObj = xpath_search(*result_cib, section);
}
max = numXpathResults(xpathObj);
if ((max < 1)
&& pcmk__str_eq(op, PCMK__CIB_REQUEST_DELETE, pcmk__str_none)) {
crm_debug("%s was already removed", section);
} else if (max < 1) {
crm_debug("%s: %s does not exist", op, section);
rc = -ENXIO;
} else if (is_query) {
if (max > 1) {
*answer = pcmk__xe_create(NULL, PCMK__XE_XPATH_QUERY);
}
}
if (pcmk_is_set(options, cib_multiple)
&& pcmk__str_eq(op, PCMK__CIB_REQUEST_DELETE, pcmk__str_none)) {
dedupXpathResults(xpathObj);
}
for (lpc = 0; lpc < max; lpc++) {
xmlChar *path = NULL;
xmlNode *match = getXpathResult(xpathObj, lpc);
if (match == NULL) {
continue;
}
path = xmlGetNodePath(match);
crm_debug("Processing %s op for %s with %s", op, section, path);
free(path);
if (pcmk__str_eq(op, PCMK__CIB_REQUEST_DELETE, pcmk__str_none)) {
if (match == *result_cib) {
/* Attempting to delete the whole "/cib" */
crm_warn("Cannot perform %s for %s: The xpath is addressing the whole /cib", op, section);
rc = -EINVAL;
break;
}
free_xml(match);
if ((options & cib_multiple) == 0) {
break;
}
} else if (pcmk__str_eq(op, PCMK__CIB_REQUEST_MODIFY, pcmk__str_none)) {
if (pcmk__xe_update_match(match, input) != pcmk_rc_ok) {
rc = -ENXIO;
} else if ((options & cib_multiple) == 0) {
break;
}
} else if (pcmk__str_eq(op, PCMK__CIB_REQUEST_CREATE, pcmk__str_none)) {
pcmk__xml_copy(match, input);
break;
} else if (pcmk__str_eq(op, PCMK__CIB_REQUEST_QUERY, pcmk__str_none)) {
if (options & cib_no_children) {
xmlNode *shallow = pcmk__xe_create(*answer,
(const char *) match->name);
copy_in_properties(shallow, match);
if (*answer == NULL) {
*answer = shallow;
}
} else if (options & cib_xpath_address) {
char *path = NULL;
xmlNode *parent = match;
while (parent && parent->type == XML_ELEMENT_NODE) {
const char *id = crm_element_value(parent, PCMK_XA_ID);
char *new_path = NULL;
if (id) {
new_path = crm_strdup_printf("/%s[@" PCMK_XA_ID "='%s']"
"%s",
parent->name, id,
pcmk__s(path, ""));
} else {
new_path = crm_strdup_printf("/%s%s", parent->name,
pcmk__s(path, ""));
}
free(path);
path = new_path;
parent = parent->parent;
}
crm_trace("Got: %s", path);
if (*answer == NULL) {
*answer = pcmk__xe_create(NULL, PCMK__XE_XPATH_QUERY);
}
parent = pcmk__xe_create(*answer, PCMK__XE_XPATH_QUERY_PATH);
crm_xml_add(parent, PCMK_XA_ID, path);
free(path);
} else if (*answer) {
pcmk__xml_copy(*answer, match);
} else {
*answer = match;
}
} else if (pcmk__str_eq(op, PCMK__CIB_REQUEST_REPLACE,
pcmk__str_none)) {
xmlNode *parent = match->parent;
free_xml(match);
pcmk__xml_copy(parent, input);
if ((options & cib_multiple) == 0) {
break;
}
}
}
freeXpathObject(xpathObj);
return rc;
}
diff --git a/lib/common/schemas.c b/lib/common/schemas.c
index 41fb24ea1f..a75f719e96 100644
--- a/lib/common/schemas.c
+++ b/lib/common/schemas.c
@@ -1,1672 +1,1654 @@
/*
* Copyright 2004-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include /* PCMK__XML_LOG_BASE */
#include "crmcommon_private.h"
#define SCHEMA_ZERO { .v = { 0, 0 } }
#define schema_strdup_printf(prefix, version, suffix) \
crm_strdup_printf(prefix "%u.%u" suffix, (version).v[0], (version).v[1])
typedef struct {
xmlRelaxNGPtr rng;
xmlRelaxNGValidCtxtPtr valid;
xmlRelaxNGParserCtxtPtr parser;
} relaxng_ctx_cache_t;
static GList *known_schemas = NULL;
static bool silent_logging = FALSE;
static void G_GNUC_PRINTF(2, 3)
xml_log(int priority, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
if (silent_logging == FALSE) {
/* XXX should not this enable dechunking as well? */
PCMK__XML_LOG_BASE(priority, FALSE, 0, NULL, fmt, ap);
}
va_end(ap);
}
static int
xml_latest_schema_index(void)
{
/* This function assumes that crm_schema_init() has been called beforehand,
* so we have at least three schemas (one real schema, the "pacemaker-next"
* schema, and the "none" schema).
*
* @COMPAT: pacemaker-next is deprecated since 2.1.5.
* Update this when we drop that schema.
*/
return g_list_length(known_schemas) - 3;
}
/* Return the index of the most recent X.0 schema. */
int
pcmk__find_x_0_schema_index(void)
{
/* We can't just use best to determine whether we've found the index
* or not. What if we have a very long list of schemas all in the
* same major version series? We'd return 0 for that, which means
* we would still run this function every time.
*/
#if defined(PCMK__UNIT_TESTING)
/* If we're unit testing, these can't be static because they'll stick
* around from one test run to the next. They need to be cleared out
* every time.
*/
bool found = false;
int best = 0;
#else
static bool found = false;
static int best = 0;
#endif
int i;
GList *best_node = NULL;
pcmk__schema_t *best_schema = NULL;
if (found) {
return best;
}
CRM_ASSERT(known_schemas != NULL);
/* Get the most recent schema so we can look at its version number. */
best = xml_latest_schema_index();
best_node = g_list_nth(known_schemas, best);
best_schema = best_node->data;
/* The "pacemaker-next" and "none" schemas are added to the real schemas,
* so a list of length three actually only has one useful schema.
*
* @COMPAT pacemaker-next is deprecated since 2.1.5.
* Update this when we drop that schema.
*/
if (g_list_length(known_schemas) == 3) {
goto done;
}
/* Start comparing the list from the node before the best schema (there's
* no point in comparing something to itself). Then, 'i' is an index
* starting at the best schema and will always point at the node after
* 'iter'. This makes it the value we want to return when we find what
* we're looking for.
*/
i = best;
for (GList *iter = best_node->prev; iter != NULL; iter = iter->prev) {
pcmk__schema_t *schema = iter->data;
/* We've found a schema in an older major version series. Return
* the index of the first one in the same major version series as
* the best schema.
*/
if (schema->version.v[0] < best_schema->version.v[0]) {
best = i;
goto done;
/* We're out of list to examine. This probably means there was only
* one major version series, so return index 0.
*/
} else if (iter->prev == NULL) {
best = 0;
goto done;
}
i--;
}
done:
found = true;
return best;
}
const char *
xml_latest_schema(void)
{
return get_schema_name(xml_latest_schema_index());
}
static inline bool
version_from_filename(const char *filename, pcmk__schema_version_t *version)
{
if (pcmk__ends_with(filename, ".rng")) {
return sscanf(filename, "pacemaker-%hhu.%hhu.rng", &(version->v[0]), &(version->v[1])) == 2;
} else {
return sscanf(filename, "pacemaker-%hhu.%hhu", &(version->v[0]), &(version->v[1])) == 2;
}
}
static int
schema_filter(const struct dirent *a)
{
int rc = 0;
pcmk__schema_version_t version = SCHEMA_ZERO;
if (strstr(a->d_name, "pacemaker-") != a->d_name) {
/* crm_trace("%s - wrong prefix", a->d_name); */
} else if (!pcmk__ends_with_ext(a->d_name, ".rng")) {
/* crm_trace("%s - wrong suffix", a->d_name); */
} else if (!version_from_filename(a->d_name, &version)) {
/* crm_trace("%s - wrong format", a->d_name); */
} else {
/* crm_debug("%s - candidate", a->d_name); */
rc = 1;
}
return rc;
}
static int
schema_cmp(pcmk__schema_version_t a_version, pcmk__schema_version_t b_version)
{
for (int i = 0; i < 2; ++i) {
if (a_version.v[i] < b_version.v[i]) {
return -1;
} else if (a_version.v[i] > b_version.v[i]) {
return 1;
}
}
return 0;
}
static int
schema_cmp_directory(const struct dirent **a, const struct dirent **b)
{
pcmk__schema_version_t a_version = SCHEMA_ZERO;
pcmk__schema_version_t b_version = SCHEMA_ZERO;
if (!version_from_filename(a[0]->d_name, &a_version)
|| !version_from_filename(b[0]->d_name, &b_version)) {
// Shouldn't be possible, but makes static analysis happy
return 0;
}
return schema_cmp(a_version, b_version);
}
/*!
* \internal
* \brief Add given schema + auxiliary data to internal bookkeeping.
*
* \note When providing \p version, should not be called directly but
* through \c add_schema_by_version.
*/
static void
add_schema(enum pcmk__schema_validator validator, const pcmk__schema_version_t *version,
const char *name, const char *transform,
const char *transform_enter, bool transform_onleave)
{
pcmk__schema_t *schema = NULL;
schema = pcmk__assert_alloc(1, sizeof(pcmk__schema_t));
schema->validator = validator;
schema->version.v[0] = version->v[0];
schema->version.v[1] = version->v[1];
schema->transform_onleave = transform_onleave;
// schema->schema_index is set after all schemas are loaded and sorted
if (version->v[0] || version->v[1]) {
schema->name = schema_strdup_printf("pacemaker-", *version, "");
} else {
schema->name = pcmk__str_copy(name);
}
if (transform) {
schema->transform = pcmk__str_copy(transform);
}
if (transform_enter) {
schema->transform_enter = pcmk__str_copy(transform_enter);
}
known_schemas = g_list_prepend(known_schemas, schema);
}
/*!
* \internal
* \brief Add version-specified schema + auxiliary data to internal bookkeeping.
* \return Standard Pacemaker return value (the only possible values are
* \c ENOENT when no upgrade schema is associated, or \c pcmk_rc_ok otherwise.
*
* \note There's no reliance on the particular order of schemas entering here.
*
* \par A bit of theory
* We track 3 XSLT stylesheets that differ per usage:
* - "upgrade":
* . sparsely spread over the sequence of all available schemas,
* as they are only relevant when major version of the schema
* is getting bumped -- in that case, it MUST be set
* . name convention: upgrade-X.Y.xsl
* - "upgrade-enter":
* . may only accompany "upgrade" occurrence, but doesn't need to
* be present anytime such one is, i.e., it MAY not be set when
* "upgrade" is
* . name convention: upgrade-X.Y-enter.xsl,
* when not present: upgrade-enter.xsl
* - "upgrade-leave":
* . like "upgrade-enter", but SHOULD be present whenever
* "upgrade-enter" is (and vice versa, but that's only
* to prevent confusion based on observing the files,
* it would get ignored regardless)
* . name convention: (see "upgrade-enter")
*/
static int
add_schema_by_version(const pcmk__schema_version_t *version, bool transform_expected)
{
bool transform_onleave = FALSE;
int rc = pcmk_rc_ok;
struct stat s;
char *xslt = NULL,
*transform_upgrade = NULL,
*transform_enter = NULL;
/* prologue for further transform_expected handling */
if (transform_expected) {
/* check if there's suitable "upgrade" stylesheet */
transform_upgrade = schema_strdup_printf("upgrade-", *version, );
xslt = pcmk__xml_artefact_path(pcmk__xml_artefact_ns_legacy_xslt,
transform_upgrade);
}
if (!transform_expected) {
/* jump directly to the end */
} else if (stat(xslt, &s) == 0) {
/* perhaps there's also a targeted "upgrade-enter" stylesheet */
transform_enter = schema_strdup_printf("upgrade-", *version, "-enter");
free(xslt);
xslt = pcmk__xml_artefact_path(pcmk__xml_artefact_ns_legacy_xslt,
transform_enter);
if (stat(xslt, &s) != 0) {
/* or initially, at least a generic one */
crm_debug("Upgrade-enter transform %s.xsl not found", xslt);
free(xslt);
free(transform_enter);
transform_enter = strdup("upgrade-enter");
xslt = pcmk__xml_artefact_path(pcmk__xml_artefact_ns_legacy_xslt,
transform_enter);
if (stat(xslt, &s) != 0) {
crm_debug("Upgrade-enter transform %s.xsl not found, either", xslt);
free(xslt);
xslt = NULL;
}
}
/* xslt contains full path to "upgrade-enter" stylesheet */
if (xslt != NULL) {
/* then there should be "upgrade-leave" counterpart (enter->leave) */
memcpy(strrchr(xslt, '-') + 1, "leave", sizeof("leave") - 1);
transform_onleave = (stat(xslt, &s) == 0);
free(xslt);
} else {
free(transform_enter);
transform_enter = NULL;
}
} else {
crm_err("Upgrade transform %s not found", xslt);
free(xslt);
free(transform_upgrade);
transform_upgrade = NULL;
rc = ENOENT;
}
add_schema(pcmk__schema_validator_rng, version, NULL,
transform_upgrade, transform_enter, transform_onleave);
free(transform_upgrade);
free(transform_enter);
return rc;
}
static void
wrap_libxslt(bool finalize)
{
static xsltSecurityPrefsPtr secprefs;
int ret = 0;
/* security framework preferences */
if (!finalize) {
CRM_ASSERT(secprefs == NULL);
secprefs = xsltNewSecurityPrefs();
ret = xsltSetSecurityPrefs(secprefs, XSLT_SECPREF_WRITE_FILE,
xsltSecurityForbid)
| xsltSetSecurityPrefs(secprefs, XSLT_SECPREF_CREATE_DIRECTORY,
xsltSecurityForbid)
| xsltSetSecurityPrefs(secprefs, XSLT_SECPREF_READ_NETWORK,
xsltSecurityForbid)
| xsltSetSecurityPrefs(secprefs, XSLT_SECPREF_WRITE_NETWORK,
xsltSecurityForbid);
if (ret != 0) {
return;
}
} else {
xsltFreeSecurityPrefs(secprefs);
secprefs = NULL;
}
/* cleanup only */
if (finalize) {
xsltCleanupGlobals();
}
}
void
pcmk__load_schemas_from_dir(const char *dir)
{
int lpc, max;
struct dirent **namelist = NULL;
max = scandir(dir, &namelist, schema_filter, schema_cmp_directory);
if (max < 0) {
crm_warn("Could not load schemas from %s: %s", dir, strerror(errno));
return;
}
for (lpc = 0; lpc < max; lpc++) {
bool transform_expected = false;
pcmk__schema_version_t version = SCHEMA_ZERO;
if (!version_from_filename(namelist[lpc]->d_name, &version)) {
// Shouldn't be possible, but makes static analysis happy
crm_warn("Skipping schema '%s': could not parse version",
namelist[lpc]->d_name);
continue;
}
if ((lpc + 1) < max) {
pcmk__schema_version_t next_version = SCHEMA_ZERO;
if (version_from_filename(namelist[lpc+1]->d_name, &next_version)
&& (version.v[0] < next_version.v[0])) {
transform_expected = true;
}
}
if (add_schema_by_version(&version, transform_expected) != pcmk_rc_ok) {
break;
}
}
for (lpc = 0; lpc < max; lpc++) {
free(namelist[lpc]);
}
free(namelist);
}
static gint
schema_sort_GCompareFunc(gconstpointer a, gconstpointer b)
{
const pcmk__schema_t *schema_a = a;
const pcmk__schema_t *schema_b = b;
if (pcmk__str_eq(schema_a->name, "pacemaker-next", pcmk__str_none)) {
if (pcmk__str_eq(schema_b->name, PCMK_VALUE_NONE, pcmk__str_none)) {
return -1;
} else {
return 1;
}
} else if (pcmk__str_eq(schema_a->name, PCMK_VALUE_NONE, pcmk__str_none)) {
return 1;
} else if (pcmk__str_eq(schema_b->name, "pacemaker-next", pcmk__str_none)) {
return -1;
} else {
return schema_cmp(schema_a->version, schema_b->version);
}
}
/*!
* \internal
* \brief Sort the list of known schemas such that all pacemaker-X.Y are in
* version order, then pacemaker-next, then none
*
* This function should be called whenever additional schemas are loaded using
* pcmk__load_schemas_from_dir(), after the initial sets in crm_schema_init().
*/
void
pcmk__sort_schemas(void)
{
known_schemas = g_list_sort(known_schemas, schema_sort_GCompareFunc);
}
/*!
* \internal
* \brief Load pacemaker schemas into cache
*
* \note This currently also serves as an entry point for the
* generic initialization of the libxslt library.
*/
void
crm_schema_init(void)
{
const char *remote_schema_dir = pcmk__remote_schema_dir();
char *base = pcmk__xml_artefact_root(pcmk__xml_artefact_ns_legacy_rng);
const pcmk__schema_version_t zero = SCHEMA_ZERO;
int schema_index = 0;
wrap_libxslt(false);
pcmk__load_schemas_from_dir(base);
pcmk__load_schemas_from_dir(remote_schema_dir);
// @COMPAT: Deprecated since 2.1.5
add_schema(pcmk__schema_validator_rng, &zero, "pacemaker-next",
NULL, NULL, FALSE);
add_schema(pcmk__schema_validator_none, &zero, PCMK_VALUE_NONE,
NULL, NULL, FALSE);
/* add_schema() prepends items to the list, so in the simple case, this just
* reverses the list. However if there were any remote schemas, sorting is
* necessary.
*/
pcmk__sort_schemas();
// Now set the schema indexes and log the final result
for (GList *iter = known_schemas; iter != NULL; iter = iter->next) {
pcmk__schema_t *schema = iter->data;
if (schema->transform == NULL) {
crm_debug("Loaded schema %d: %s", schema_index, schema->name);
} else {
crm_debug("Loaded schema %d: %s (upgrades with %s.xsl)",
schema_index, schema->name, schema->transform);
}
schema->schema_index = schema_index++;
}
}
static gboolean
validate_with_relaxng(xmlDocPtr doc, xmlRelaxNGValidityErrorFunc error_handler, void *error_handler_context, const char *relaxng_file,
relaxng_ctx_cache_t **cached_ctx)
{
int rc = 0;
gboolean valid = TRUE;
relaxng_ctx_cache_t *ctx = NULL;
CRM_CHECK(doc != NULL, return FALSE);
CRM_CHECK(relaxng_file != NULL, return FALSE);
if (cached_ctx && *cached_ctx) {
ctx = *cached_ctx;
} else {
crm_debug("Creating RNG parser context");
ctx = pcmk__assert_alloc(1, sizeof(relaxng_ctx_cache_t));
ctx->parser = xmlRelaxNGNewParserCtxt(relaxng_file);
CRM_CHECK(ctx->parser != NULL, goto cleanup);
if (error_handler) {
xmlRelaxNGSetParserErrors(ctx->parser,
(xmlRelaxNGValidityErrorFunc) error_handler,
(xmlRelaxNGValidityWarningFunc) error_handler,
error_handler_context);
} else {
xmlRelaxNGSetParserErrors(ctx->parser,
(xmlRelaxNGValidityErrorFunc) fprintf,
(xmlRelaxNGValidityWarningFunc) fprintf,
stderr);
}
ctx->rng = xmlRelaxNGParse(ctx->parser);
CRM_CHECK(ctx->rng != NULL,
crm_err("Could not find/parse %s", relaxng_file);
goto cleanup);
ctx->valid = xmlRelaxNGNewValidCtxt(ctx->rng);
CRM_CHECK(ctx->valid != NULL, goto cleanup);
if (error_handler) {
xmlRelaxNGSetValidErrors(ctx->valid,
(xmlRelaxNGValidityErrorFunc) error_handler,
(xmlRelaxNGValidityWarningFunc) error_handler,
error_handler_context);
} else {
xmlRelaxNGSetValidErrors(ctx->valid,
(xmlRelaxNGValidityErrorFunc) fprintf,
(xmlRelaxNGValidityWarningFunc) fprintf,
stderr);
}
}
rc = xmlRelaxNGValidateDoc(ctx->valid, doc);
if (rc > 0) {
valid = FALSE;
} else if (rc < 0) {
crm_err("Internal libxml error during validation");
}
cleanup:
if (cached_ctx) {
*cached_ctx = ctx;
} else {
if (ctx->parser != NULL) {
xmlRelaxNGFreeParserCtxt(ctx->parser);
}
if (ctx->valid != NULL) {
xmlRelaxNGFreeValidCtxt(ctx->valid);
}
if (ctx->rng != NULL) {
xmlRelaxNGFree(ctx->rng);
}
free(ctx);
}
return valid;
}
static void
free_schema(gpointer data)
{
pcmk__schema_t *schema = data;
relaxng_ctx_cache_t *ctx = NULL;
switch (schema->validator) {
case pcmk__schema_validator_none: // not cached
break;
case pcmk__schema_validator_rng: // cached
ctx = (relaxng_ctx_cache_t *) schema->cache;
if (ctx == NULL) {
break;
}
if (ctx->parser != NULL) {
xmlRelaxNGFreeParserCtxt(ctx->parser);
}
if (ctx->valid != NULL) {
xmlRelaxNGFreeValidCtxt(ctx->valid);
}
if (ctx->rng != NULL) {
xmlRelaxNGFree(ctx->rng);
}
free(ctx);
schema->cache = NULL;
break;
}
free(schema->name);
free(schema->transform);
free(schema->transform_enter);
}
/*!
* \internal
* \brief Clean up global memory associated with XML schemas
*/
void
crm_schema_cleanup(void)
{
g_list_free_full(known_schemas, free_schema);
known_schemas = NULL;
wrap_libxslt(true);
}
/*!
* \internal
* \brief Get schema list entry corresponding to a schema name
*
* \param[in] name Name of schema to get
*
* \return Schema list entry corresponding to \p name, or NULL if unknown
*/
GList *
pcmk__get_schema(const char *name)
{
if (name == NULL) {
name = PCMK_VALUE_NONE;
}
for (GList *iter = known_schemas; iter != NULL; iter = iter->next) {
pcmk__schema_t *schema = iter->data;
if (pcmk__str_eq(name, schema->name, pcmk__str_casei)) {
return iter;
}
}
return NULL;
}
/*!
* \internal
* \brief Compare two schema version numbers given the schema names
*
* \param[in] schema1 Name of first schema to compare
* \param[in] schema2 Name of second schema to compare
*
* \return Standard comparison result (negative integer if \p schema1 has the
* lower version number, positive integer if \p schema1 has the higher
* version number, of 0 if the version numbers are equal)
*/
int
pcmk__cmp_schemas_by_name(const char *schema1_name, const char *schema2_name)
{
GList *entry1 = pcmk__get_schema(schema1_name);
GList *entry2 = pcmk__get_schema(schema2_name);
if (entry1 == NULL) {
return (entry2 == NULL)? 0 : -1;
} else if (entry2 == NULL) {
return 1;
} else {
pcmk__schema_t *schema1 = entry1->data;
pcmk__schema_t *schema2 = entry2->data;
return schema1->schema_index - schema2->schema_index;
}
}
static gboolean
validate_with(xmlNode *xml, pcmk__schema_t *schema, xmlRelaxNGValidityErrorFunc error_handler, void* error_handler_context)
{
gboolean valid = FALSE;
char *file = NULL;
relaxng_ctx_cache_t **cache = NULL;
if (schema == NULL) {
return FALSE;
}
if (schema->validator == pcmk__schema_validator_none) {
return TRUE;
}
if (pcmk__str_eq(schema->name, "pacemaker-next", pcmk__str_none)) {
crm_warn("The pacemaker-next schema is deprecated and will be removed "
"in a future release.");
}
file = pcmk__xml_artefact_path(pcmk__xml_artefact_ns_legacy_rng,
schema->name);
crm_trace("Validating with %s (type=%d)",
pcmk__s(file, "missing schema"), schema->validator);
switch (schema->validator) {
case pcmk__schema_validator_rng:
cache = (relaxng_ctx_cache_t **) &(schema->cache);
valid = validate_with_relaxng(xml->doc, error_handler, error_handler_context, file, cache);
break;
default:
crm_err("Unknown validator type: %d", schema->validator);
break;
}
free(file);
return valid;
}
static bool
validate_with_silent(xmlNode *xml, pcmk__schema_t *schema)
{
bool rc, sl_backup = silent_logging;
silent_logging = TRUE;
rc = validate_with(xml, schema, (xmlRelaxNGValidityErrorFunc) xml_log, GUINT_TO_POINTER(LOG_ERR));
silent_logging = sl_backup;
return rc;
}
static void
dump_file(const char *filename)
{
FILE *fp = NULL;
int ch, line = 0;
CRM_CHECK(filename != NULL, return);
fp = fopen(filename, "r");
if (fp == NULL) {
crm_perror(LOG_ERR, "Could not open %s for reading", filename);
return;
}
fprintf(stderr, "%4d ", ++line);
do {
ch = getc(fp);
if (ch == EOF) {
putc('\n', stderr);
break;
} else if (ch == '\n') {
fprintf(stderr, "\n%4d ", ++line);
} else {
putc(ch, stderr);
}
} while (1);
fclose(fp);
}
gboolean
validate_xml_verbose(const xmlNode *xml_blob)
{
int fd = 0;
xmlDoc *doc = NULL;
xmlNode *xml = NULL;
gboolean rc = FALSE;
char *filename = NULL;
filename = crm_strdup_printf("%s/cib-invalid.XXXXXX", pcmk__get_tmpdir());
umask(S_IWGRP | S_IWOTH | S_IROTH);
fd = mkstemp(filename);
pcmk__xml_write_fd(xml_blob, filename, fd, false, NULL);
dump_file(filename);
doc = xmlReadFile(filename, NULL, 0);
xml = xmlDocGetRootElement(doc);
rc = validate_xml(xml, NULL, FALSE);
free_xml(xml);
unlink(filename);
free(filename);
return rc;
}
gboolean
validate_xml(xmlNode *xml_blob, const char *validation, gboolean to_logs)
{
return pcmk__validate_xml(xml_blob, validation, to_logs ? (xmlRelaxNGValidityErrorFunc) xml_log : NULL, GUINT_TO_POINTER(LOG_ERR));
}
gboolean
pcmk__validate_xml(xmlNode *xml_blob, const char *validation,
xmlRelaxNGValidityErrorFunc error_handler,
void *error_handler_context)
{
GList *entry = NULL;
pcmk__schema_t *schema = NULL;
CRM_CHECK((xml_blob != NULL) && (xml_blob->doc != NULL), return FALSE);
if (validation == NULL) {
validation = crm_element_value(xml_blob, PCMK_XA_VALIDATE_WITH);
}
if (validation == NULL) {
bool valid = FALSE;
for (entry = known_schemas; entry != NULL; entry = entry->next) {
schema = entry->data;
if (validate_with(xml_blob, schema, NULL, NULL)) {
valid = TRUE;
crm_xml_add(xml_blob, PCMK_XA_VALIDATE_WITH, schema->name);
crm_info("XML validated against %s", schema->name);
}
}
return valid;
}
entry = pcmk__get_schema(validation);
if (entry != NULL) {
schema = entry->data;
return validate_with(xml_blob, schema, error_handler,
error_handler_context);
}
crm_err("Unknown validator: %s", validation);
return FALSE;
}
/* With this arrangement, an attempt to identify the message severity
as explicitly signalled directly from XSLT is performed in rather
a smart way (no reliance on formatting string + arguments being
always specified as ["%s", purposeful_string], as it can also be
["%s: %s", some_prefix, purposeful_string] etc. so every argument
pertaining %s specifier is investigated), and if such a mark found,
the respective level is determined and, when the messages are to go
to the native logs, the mark itself gets dropped
(by the means of string shift).
NOTE: whether the native logging is the right sink is decided per
the ctx parameter -- NULL denotes this case, otherwise it
carries a pointer to the numeric expression of the desired
target logging level (messages with higher level will be
suppressed)
NOTE: on some architectures, this string shift may not have any
effect, but that's an acceptable tradeoff
The logging level for not explicitly designated messages
(suspicious, likely internal errors or some runaways) is
LOG_WARNING.
*/
static void G_GNUC_PRINTF(2, 3)
cib_upgrade_err(void *ctx, const char *fmt, ...)
{
va_list ap, aq;
char *arg_cur;
bool found = FALSE;
const char *fmt_iter = fmt;
uint8_t msg_log_level = LOG_WARNING; /* default for runaway messages */
const unsigned * log_level = (const unsigned *) ctx;
enum {
escan_seennothing,
escan_seenpercent,
} scan_state = escan_seennothing;
va_start(ap, fmt);
va_copy(aq, ap);
while (!found && *fmt_iter != '\0') {
/* while casing schema borrowed from libqb:qb_vsnprintf_serialize */
switch (*fmt_iter++) {
case '%':
if (scan_state == escan_seennothing) {
scan_state = escan_seenpercent;
} else if (scan_state == escan_seenpercent) {
scan_state = escan_seennothing;
}
break;
case 's':
if (scan_state == escan_seenpercent) {
scan_state = escan_seennothing;
arg_cur = va_arg(aq, char *);
if (arg_cur != NULL) {
switch (arg_cur[0]) {
case 'W':
if (!strncmp(arg_cur, "WARNING: ",
sizeof("WARNING: ") - 1)) {
msg_log_level = LOG_WARNING;
}
if (ctx == NULL) {
memmove(arg_cur, arg_cur + sizeof("WARNING: ") - 1,
strlen(arg_cur + sizeof("WARNING: ") - 1) + 1);
}
found = TRUE;
break;
case 'I':
if (!strncmp(arg_cur, "INFO: ",
sizeof("INFO: ") - 1)) {
msg_log_level = LOG_INFO;
}
if (ctx == NULL) {
memmove(arg_cur, arg_cur + sizeof("INFO: ") - 1,
strlen(arg_cur + sizeof("INFO: ") - 1) + 1);
}
found = TRUE;
break;
case 'D':
if (!strncmp(arg_cur, "DEBUG: ",
sizeof("DEBUG: ") - 1)) {
msg_log_level = LOG_DEBUG;
}
if (ctx == NULL) {
memmove(arg_cur, arg_cur + sizeof("DEBUG: ") - 1,
strlen(arg_cur + sizeof("DEBUG: ") - 1) + 1);
}
found = TRUE;
break;
}
}
}
break;
case '#': case '-': case ' ': case '+': case '\'': case 'I': case '.':
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case '*':
break;
case 'l':
case 'z':
case 't':
case 'j':
case 'd': case 'i':
case 'o':
case 'u':
case 'x': case 'X':
case 'e': case 'E':
case 'f': case 'F':
case 'g': case 'G':
case 'a': case 'A':
case 'c':
case 'p':
if (scan_state == escan_seenpercent) {
(void) va_arg(aq, void *); /* skip forward */
scan_state = escan_seennothing;
}
break;
default:
scan_state = escan_seennothing;
break;
}
}
if (log_level != NULL) {
/* intention of the following offset is:
cibadmin -V -> start showing INFO labelled messages */
if (*log_level + 4 >= msg_log_level) {
vfprintf(stderr, fmt, ap);
}
} else {
PCMK__XML_LOG_BASE(msg_log_level, TRUE, 0, "CIB upgrade: ", fmt, ap);
}
va_end(aq);
va_end(ap);
}
/*!
* \internal
* \brief Apply a single XSL transformation to given XML
*
* \param[in] xml XML to transform
* \param[in] transform XSL name
* \param[in] to_logs If false, certain validation errors will be sent to
* stderr rather than logged
*
* \return Transformed XML on success, otherwise NULL
*/
static xmlNode *
apply_transformation(const xmlNode *xml, const char *transform,
gboolean to_logs)
{
char *xform = NULL;
xmlNode *out = NULL;
xmlDocPtr res = NULL;
xsltStylesheet *xslt = NULL;
xform = pcmk__xml_artefact_path(pcmk__xml_artefact_ns_legacy_xslt,
transform);
/* for capturing, e.g., what's emitted via */
if (to_logs) {
xsltSetGenericErrorFunc(NULL, cib_upgrade_err);
} else {
xsltSetGenericErrorFunc(&crm_log_level, cib_upgrade_err);
}
xslt = xsltParseStylesheetFile((pcmkXmlStr) xform);
CRM_CHECK(xslt != NULL, goto cleanup);
res = xsltApplyStylesheet(xslt, xml->doc, NULL);
CRM_CHECK(res != NULL, goto cleanup);
xsltSetGenericErrorFunc(NULL, NULL); /* restore default one */
out = xmlDocGetRootElement(res);
cleanup:
if (xslt) {
xsltFreeStylesheet(xslt);
}
free(xform);
return out;
}
/*!
* \internal
* \brief Perform all transformations needed to upgrade XML to next schema
*
* A schema upgrade can require up to three XSL transformations: an "enter"
* transform, the main upgrade transform, and a "leave" transform. Perform
* all needed transforms to upgrade given XML to the next schema.
*
* \param[in] original_xml XML to transform
* \param[in] schema_index Index of schema that successfully validates
* \p original_xml
* \param[in] to_logs If false, certain validation errors will be sent to
* stderr rather than logged
*
* \return XML result of schema transforms if successful, otherwise NULL
*/
static xmlNode *
apply_upgrade(const xmlNode *original_xml, int schema_index, gboolean to_logs)
{
pcmk__schema_t *schema = g_list_nth_data(known_schemas, schema_index);
pcmk__schema_t *upgraded_schema = g_list_nth_data(known_schemas,
schema_index + 1);
bool transform_onleave = false;
char *transform_leave;
const xmlNode *xml = original_xml;
xmlNode *upgrade = NULL;
xmlNode *final = NULL;
xmlRelaxNGValidityErrorFunc error_handler = NULL;
CRM_ASSERT((schema != NULL) && (upgraded_schema != NULL));
if (to_logs) {
error_handler = (xmlRelaxNGValidityErrorFunc) xml_log;
}
transform_onleave = schema->transform_onleave;
if (schema->transform_enter != NULL) {
crm_debug("Upgrading schema from %s to %s: "
"applying pre-upgrade XSL transform %s",
schema->name, upgraded_schema->name, schema->transform_enter);
upgrade = apply_transformation(xml, schema->transform_enter, to_logs);
if (upgrade == NULL) {
crm_warn("Pre-upgrade XSL transform %s failed, "
"will skip post-upgrade transform",
schema->transform_enter);
transform_onleave = FALSE;
} else {
xml = upgrade;
}
}
crm_debug("Upgrading schema from %s to %s: "
"applying upgrade XSL transform %s",
schema->name, upgraded_schema->name, schema->transform);
final = apply_transformation(xml, schema->transform, to_logs);
if (upgrade != xml) {
free_xml(upgrade);
upgrade = NULL;
}
if ((final != NULL) && transform_onleave) {
upgrade = final;
/* following condition ensured in add_schema_by_version */
CRM_ASSERT(schema->transform_enter != NULL);
transform_leave = strdup(schema->transform_enter);
/* enter -> leave */
memcpy(strrchr(transform_leave, '-') + 1, "leave", sizeof("leave") - 1);
crm_debug("Upgrading schema from %s to %s: "
"applying post-upgrade XSL transform %s",
schema->name, upgraded_schema->name, transform_leave);
final = apply_transformation(upgrade, transform_leave, to_logs);
if (final == NULL) {
crm_warn("Ignoring failure of post-upgrade XSL transform %s",
transform_leave);
final = upgrade;
} else {
free_xml(upgrade);
}
free(transform_leave);
}
if (final == NULL) {
return NULL;
}
// Ensure result validates with its new schema
if (!validate_with(final, upgraded_schema, error_handler,
GUINT_TO_POINTER(LOG_ERR))) {
crm_err("Schema upgrade from %s to %s failed: "
"XSL transform %s produced an invalid configuration",
schema->name, upgraded_schema->name, schema->transform);
crm_log_xml_debug(final, "bad-transform-result");
free_xml(final);
return NULL;
}
crm_info("Schema upgrade from %s to %s succeeded",
schema->name, upgraded_schema->name);
return final;
}
const char *
get_schema_name(int version)
{
pcmk__schema_t *schema = g_list_nth_data(known_schemas, version);
return (schema != NULL)? schema->name : "unknown";
}
int
get_schema_version(const char *name)
{
int lpc = 0;
if (name == NULL) {
name = PCMK_VALUE_NONE;
}
for (GList *iter = known_schemas; iter != NULL; iter = iter->next) {
pcmk__schema_t *schema = iter->data;
if (pcmk__str_eq(name, schema->name, pcmk__str_casei)) {
return lpc;
}
lpc++;
}
return -1;
}
/*!
* \internal
* \brief Get the schema list entry corresponding to XML configuration
*
* \param[in] xml CIB XML to check
*
* \return List entry of schema configured in \p xml
*/
static GList *
get_configured_schema(const xmlNode *xml)
{
const char *schema_name = crm_element_value(xml, PCMK_XA_VALIDATE_WITH);
if (schema_name == NULL) {
return NULL;
}
return pcmk__get_schema(schema_name);
}
-/* set which validation to use */
/*!
* \brief Update CIB XML to latest schema that validates it
*
- * \param[in,out] xml_blob XML to update (may be freed and replaced after
- * being transformed)
- * \param[out] best If not NULL, set to schema index of latest schema
- * that validates \p xml_blob
- * \param[in] max If positive, do not update \p xml_blob to any
- * schema past this index
- * \param[in] transform If false, do not update \p xml_blob to any schema
- * that requires an XSL transform
- * \param[in] to_logs If false, certain validation errors will be sent to
- * stderr rather than logged
+ * \param[in,out] xml XML to update (may be freed and replaced
+ * after being transformed)
+ * \param[in] max_schema_name If not NULL, do not update \p xml to any
+ * schema later than this one
+ * \param[in] transform If false, do not update \p xml to any schema
+ * that requires an XSL transform
+ * \param[in] to_logs If false, certain validation errors will be
+ * sent to stderr rather than logged
*
- * \return Legacy Pacemaker return code
+ * \return Standard Pacemaker return code
*/
int
-update_validation(xmlNode **xml_blob, int *best, int max, gboolean transform,
- gboolean to_logs)
+pcmk__update_schema(xmlNode **xml, const char *max_schema_name, bool transform,
+ bool to_logs)
{
- xmlNode *xml = NULL;
int max_stable_schemas = xml_latest_schema_index();
- int rc = pcmk_ok;
- int local_best = 0;
+ int max_schema_index = 0;
+ int rc = pcmk_rc_ok;
GList *entry = NULL;
- pcmk__schema_t *current_schema = NULL;
+ pcmk__schema_t *best_schema = NULL;
pcmk__schema_t *original_schema = NULL;
- pcmk__schema_t *next_higher_schema = NULL;
xmlRelaxNGValidityErrorFunc error_handler =
to_logs ? (xmlRelaxNGValidityErrorFunc) xml_log : NULL;
- if (best != NULL) {
- *best = 0;
- }
+ CRM_CHECK((xml != NULL) && (*xml != NULL) && ((*xml)->doc != NULL),
+ return EINVAL);
- CRM_CHECK((xml_blob != NULL) && (*xml_blob != NULL)
- && ((*xml_blob)->doc != NULL),
- return -EINVAL);
+ if (max_schema_name != NULL) {
+ GList *max_entry = pcmk__get_schema(max_schema_name);
- xml = *xml_blob;
+ if (max_entry != NULL) {
+ pcmk__schema_t *max_schema = max_entry->data;
- if ((max < 1) || (max > max_stable_schemas)) {
- max = max_stable_schemas;
+ max_schema_index = max_schema->schema_index;
+ }
+ }
+ if ((max_schema_index < 1) || (max_schema_index > max_stable_schemas)) {
+ max_schema_index = max_stable_schemas;
}
- // entry now tracks current_schema
-
- entry = get_configured_schema(xml);
+ entry = get_configured_schema(*xml);
if (entry == NULL) {
entry = known_schemas;
- current_schema = entry->data;
} else {
original_schema = entry->data;
- current_schema = original_schema;
- if (original_schema->schema_index >= max) {
- // No higher version is available
- if (best != NULL) {
- *best = original_schema->schema_index;
- }
- return pcmk_ok;
+ if (original_schema->schema_index >= max_schema_index) {
+ return pcmk_rc_ok;
}
}
- while (current_schema->schema_index <= max) {
+ for (; entry != NULL; entry = entry->next) {
+ pcmk__schema_t *current_schema = entry->data;
xmlNode *upgrade = NULL;
- crm_debug("Testing '%s' validation (%d of %d)",
- current_schema->name, current_schema->schema_index, max);
+ if (current_schema->schema_index > max_schema_index) {
+ break;
+ }
- if (!validate_with(xml, current_schema, error_handler,
+ if (!validate_with(*xml, current_schema, error_handler,
GUINT_TO_POINTER(LOG_ERR))) {
- if (next_higher_schema != NULL) {
- crm_info("Configuration not valid for schema: %s",
- current_schema->name);
- next_higher_schema = NULL;
- } else {
- crm_trace("%s validation failed", current_schema->name);
- }
- if (local_best > 0) {
+ crm_debug("Schema %s does not validate", current_schema->name);
+ if (best_schema != NULL) {
/* we've satisfied the validation, no need to check further */
break;
}
- rc = -pcmk_err_schema_validation;
-
- // Try again with the next higher schema
- entry = entry->next;
- current_schema = entry->data;
- continue;
- }
-
- if (next_higher_schema != NULL) {
- crm_debug("Configuration valid for schema: %s",
- current_schema->name);
- next_higher_schema = NULL;
- }
- rc = pcmk_ok;
-
- local_best = current_schema->schema_index;
-
- if (!transform) {
- /* Validation with this schema succeeded. We are not doing
- * transforms, so try the next schema using the same XML.
- */
- entry = entry->next;
- current_schema = entry->data;
- continue;
+ rc = pcmk_rc_schema_validation;
+ continue; // Try again with the next higher schema
}
- if (current_schema->schema_index == max) {
+ crm_debug("Schema %s validates", current_schema->name);
+ rc = pcmk_rc_ok;
+ best_schema = current_schema;
+ if (current_schema->schema_index == max_schema_index) {
break; // No further transformations possible
}
- next_higher_schema = entry->next->data;
-
- if ((current_schema->transform == NULL)
- || validate_with_silent(xml, next_higher_schema)) {
- /* The next schema either doesn't require a transform, or validates
- * successfully even without doing the transform. We can skip the
- * transform and use it with the same XML in the next iteration.
+ if (!transform || (current_schema->transform == NULL)
+ || validate_with_silent(*xml, entry->next->data)) {
+ /* The next schema either doesn't require a transform or validates
+ * successfully even without the transform. Skip the transform and
+ * try the next schema with the same XML.
*/
- crm_debug("%s-style configuration is also valid for %s",
- current_schema->name, next_higher_schema->name);
- entry = entry->next;
- current_schema = entry->data;
continue;
}
- upgrade = apply_upgrade(xml, current_schema->schema_index, to_logs);
+ upgrade = apply_upgrade(*xml, current_schema->schema_index, to_logs);
if (upgrade == NULL) {
- rc = -pcmk_err_transform_failed;
- } else {
- entry = entry->next;
- current_schema = entry->data;
- local_best = current_schema->schema_index;
- free_xml(xml);
- xml = upgrade;
- }
- next_higher_schema = NULL;
- if (rc != pcmk_ok) {
/* The transform failed, so this schema can't be used. Later
* schemas are unlikely to validate, but try anyway until we
* run out of options.
*/
- entry = entry->next;
- current_schema = entry->data;
+ rc = pcmk_rc_transform_failed;
+ } else {
+ best_schema = current_schema;
+ free_xml(*xml);
+ *xml = upgrade;
}
}
- if ((local_best > 0)
- && ((original_schema == NULL)
- || (local_best > original_schema->schema_index))) {
- pcmk__schema_t *best_schema = g_list_nth_data(known_schemas,
- local_best);
-
- crm_info("%s the configuration schema to %s",
- (transform? "Transformed" : "Upgraded"), best_schema->name);
- crm_xml_add(xml, PCMK_XA_VALIDATE_WITH, best_schema->name);
- }
-
- *xml_blob = xml;
-
- if (best != NULL) {
- *best = local_best;
+ if (best_schema != NULL) {
+ if ((original_schema == NULL)
+ || (best_schema->schema_index > original_schema->schema_index)) {
+ crm_info("%s the configuration schema to %s",
+ (transform? "Transformed" : "Upgraded"),
+ best_schema->name);
+ crm_xml_add(*xml, PCMK_XA_VALIDATE_WITH, best_schema->name);
+ }
}
return rc;
}
gboolean
cli_config_update(xmlNode **xml, int *best_version, gboolean to_logs)
{
gboolean rc = TRUE;
- const char *value = crm_element_value(*xml, PCMK_XA_VALIDATE_WITH);
- char *const orig_value = strdup(value == NULL ? "(none)" : value);
-
- int version = get_schema_version(value);
- int orig_version = version;
+ char *original_schema_name = NULL;
+ int version = 0;
+ int orig_version = 0;
int min_version = pcmk__find_x_0_schema_index();
+ original_schema_name = crm_element_value_copy(*xml, PCMK_XA_VALIDATE_WITH);
+ version = get_schema_version(original_schema_name);
+ orig_version = version;
if (version < min_version) {
// Current configuration schema is not acceptable, try to update
xmlNode *converted = NULL;
+ const char *new_schema_name = NULL;
converted = pcmk__xml_copy(NULL, *xml);
- update_validation(&converted, &version, 0, TRUE, to_logs);
+ if (pcmk__update_schema(&converted, NULL, true, to_logs) == pcmk_rc_ok) {
+ new_schema_name = crm_element_value(converted,
+ PCMK_XA_VALIDATE_WITH);
+ version = get_schema_version(new_schema_name);
+ } else {
+ version = 0;
+ }
- value = crm_element_value(converted, PCMK_XA_VALIDATE_WITH);
if (version < min_version) {
// Updated configuration schema is still not acceptable
if (version < orig_version || orig_version == -1) {
// We couldn't validate any schema at all
if (to_logs) {
pcmk__config_err("Cannot upgrade configuration (claiming "
- "schema %s) to at least %s because it "
+ "%s schema) to at least %s because it "
"does not validate with any schema from "
"%s to %s",
- orig_value,
+ pcmk__s(original_schema_name, "no"),
get_schema_name(min_version),
get_schema_name(orig_version),
xml_latest_schema());
} else {
fprintf(stderr, "Cannot upgrade configuration (claiming "
- "schema %s) to at least %s because it "
+ "%s schema) to at least %s because it "
"does not validate with any schema from "
"%s to %s\n",
- orig_value,
+ pcmk__s(original_schema_name, "no"),
get_schema_name(min_version),
get_schema_name(orig_version),
xml_latest_schema());
}
} else {
// We updated configuration successfully, but still too low
if (to_logs) {
pcmk__config_err("Cannot upgrade configuration (claiming "
- "schema %s) to at least %s because it "
+ "%s schema) to at least %s because it "
"would not upgrade past %s",
- orig_value,
+ pcmk__s(original_schema_name, "no"),
get_schema_name(min_version),
- pcmk__s(value, "unspecified version"));
+ pcmk__s(new_schema_name, "unspecified version"));
} else {
fprintf(stderr, "Cannot upgrade configuration (claiming "
- "schema %s) to at least %s because it "
+ "%s schema) to at least %s because it "
"would not upgrade past %s\n",
- orig_value,
+ pcmk__s(original_schema_name, "no"),
get_schema_name(min_version),
- pcmk__s(value, "unspecified version"));
+ pcmk__s(new_schema_name, "unspecified version"));
}
}
free_xml(converted);
converted = NULL;
rc = FALSE;
} else {
// Updated configuration schema is acceptable
free_xml(*xml);
*xml = converted;
if (version < xml_latest_schema_index()) {
if (to_logs) {
- pcmk__config_warn("Configuration with schema %s was "
+ pcmk__config_warn("Configuration with %s schema was "
"internally upgraded to acceptable (but "
"not most recent) %s",
- orig_value, get_schema_name(version));
+ pcmk__s(original_schema_name, "no"),
+ get_schema_name(version));
}
} else {
if (to_logs) {
- crm_info("Configuration with schema %s was internally "
+ crm_info("Configuration with %s schema was internally "
"upgraded to latest version %s",
- orig_value, get_schema_name(version));
+ pcmk__s(original_schema_name, "no"),
+ get_schema_name(version));
}
}
}
} else if (version >= get_schema_version(PCMK_VALUE_NONE)) {
// Schema validation is disabled
if (to_logs) {
pcmk__config_warn("Schema validation of configuration is disabled "
"(enabling is encouraged and prevents common "
"misconfigurations)");
} else {
fprintf(stderr, "Schema validation of configuration is disabled "
"(enabling is encouraged and prevents common "
"misconfigurations)\n");
}
}
if (best_version) {
*best_version = version;
}
- free(orig_value);
+ free(original_schema_name);
return rc;
}
/*!
* \internal
* \brief Return a list of all schema files and any associated XSLT files
* later than the given one
* \brief Return a list of all schema versions later than the given one
*
* \param[in] schema The schema to compare against (for example,
* "pacemaker-3.1.rng" or "pacemaker-3.1")
*
* \note The caller is responsible for freeing both the returned list and
* the elements of the list
*/
GList *
pcmk__schema_files_later_than(const char *name)
{
GList *lst = NULL;
pcmk__schema_version_t ver;
if (!version_from_filename(name, &ver)) {
return lst;
}
for (GList *iter = g_list_nth(known_schemas, xml_latest_schema_index());
iter != NULL; iter = iter->prev) {
pcmk__schema_t *schema = iter->data;
char *s = NULL;
if (schema_cmp(ver, schema->version) != -1) {
continue;
}
s = crm_strdup_printf("%s.rng", schema->name);
lst = g_list_prepend(lst, s);
if (schema->transform != NULL) {
char *xform = crm_strdup_printf("%s.xsl", schema->transform);
lst = g_list_prepend(lst, xform);
}
if (schema->transform_enter != NULL) {
char *enter = crm_strdup_printf("%s.xsl", schema->transform_enter);
lst = g_list_prepend(lst, enter);
if (schema->transform_onleave) {
int last_dash = strrchr(enter, '-') - enter;
char *leave = crm_strdup_printf("%.*s-leave.xsl", last_dash, enter);
lst = g_list_prepend(lst, leave);
}
}
}
return lst;
}
static void
append_href(xmlNode *xml, void *user_data)
{
GList **list = user_data;
char *href = crm_element_value_copy(xml, "href");
if (href == NULL) {
return;
}
*list = g_list_prepend(*list, href);
}
static void
external_refs_in_schema(GList **list, const char *contents)
{
/* local-name()= is needed to ignore the xmlns= setting at the top of
* the XML file. Otherwise, the xpath query will always return nothing.
*/
const char *search = "//*[local-name()='externalRef'] | //*[local-name()='include']";
xmlNode *xml = pcmk__xml_parse(contents);
crm_foreach_xpath_result(xml, search, append_href, list);
free_xml(xml);
}
static int
read_file_contents(const char *file, char **contents)
{
int rc = pcmk_rc_ok;
char *path = NULL;
if (pcmk__ends_with(file, ".rng")) {
path = pcmk__xml_artefact_path(pcmk__xml_artefact_ns_legacy_rng, file);
} else {
path = pcmk__xml_artefact_path(pcmk__xml_artefact_ns_legacy_xslt, file);
}
rc = pcmk__file_contents(path, contents);
free(path);
return rc;
}
static void
add_schema_file_to_xml(xmlNode *parent, const char *file, GList **already_included)
{
char *contents = NULL;
char *path = NULL;
xmlNode *file_node = NULL;
GList *includes = NULL;
int rc = pcmk_rc_ok;
/* If we already included this file, don't do so again. */
if (g_list_find_custom(*already_included, file, (GCompareFunc) strcmp) != NULL) {
return;
}
/* Ensure whatever file we were given has a suffix we know about. If not,
* just assume it's an RNG file.
*/
if (!pcmk__ends_with(file, ".rng") && !pcmk__ends_with(file, ".xsl")) {
path = crm_strdup_printf("%s.rng", file);
} else {
path = pcmk__str_copy(file);
}
rc = read_file_contents(path, &contents);
if (rc != pcmk_rc_ok || contents == NULL) {
crm_warn("Could not read schema file %s: %s", file, pcmk_rc_str(rc));
free(path);
return;
}
/* Create a new node with the contents of the file
* as a CDATA block underneath it.
*/
file_node = pcmk__xe_create(parent, PCMK_XA_FILE);
crm_xml_add(file_node, PCMK_XA_PATH, path);
*already_included = g_list_prepend(*already_included, path);
xmlAddChild(file_node, xmlNewCDataBlock(parent->doc, (pcmkXmlStr) contents,
strlen(contents)));
/* Scan the file for any or nodes and build up
* a list of the files they reference.
*/
external_refs_in_schema(&includes, contents);
/* For each referenced file, recurse to add it (and potentially anything it
* references, ...) to the XML.
*/
for (GList *iter = includes; iter != NULL; iter = iter->next) {
add_schema_file_to_xml(parent, iter->data, already_included);
}
free(contents);
g_list_free_full(includes, free);
}
/*!
* \internal
* \brief Add an XML schema file and all the files it references as children
* of a given XML node
*
* \param[in,out] parent The parent XML node
* \param[in] name The schema version to compare against
* (for example, "pacemaker-3.1" or "pacemaker-3.1.rng")
* \param[in,out] already_included A list of names that have already been added
* to the parent node.
*
* \note The caller is responsible for freeing both the returned list and
* the elements of the list
*/
void
pcmk__build_schema_xml_node(xmlNode *parent, const char *name, GList **already_included)
{
/* First, create an unattached node to add all the schema files to as children. */
xmlNode *schema_node = pcmk__xe_create(NULL, PCMK__XA_SCHEMA);
crm_xml_add(schema_node, PCMK_XA_VERSION, name);
add_schema_file_to_xml(schema_node, name, already_included);
/* Then, if we actually added any children, attach the node to parent. If
* we did not add any children (for instance, name was invalid), this prevents
* us from returning a document with additional empty children.
*/
if (schema_node->children != NULL) {
xmlAddChild(parent, schema_node);
} else {
free_xml(schema_node);
}
}
/*!
* \internal
* \brief Return the directory containing any extra schema files that a
* Pacemaker Remote node fetched from the cluster
*/
const char *
pcmk__remote_schema_dir(void)
{
const char *dir = pcmk__env_option(PCMK__ENV_REMOTE_SCHEMA_DIRECTORY);
if (pcmk__str_empty(dir)) {
return PCMK__REMOTE_SCHEMA_DIR;
}
return dir;
}
+
+// Deprecated functions kept only for backward API compatibility
+// LCOV_EXCL_START
+
+#include
+
+int
+update_validation(xmlNode **xml, int *best, int max, gboolean transform,
+ gboolean to_logs)
+{
+ int rc = pcmk__update_schema(xml, get_schema_name(max), transform, to_logs);
+
+ if ((best != NULL) && (xml != NULL) && (rc == pcmk_rc_ok)) {
+ const char *schema_name = crm_element_value(*xml,
+ PCMK_XA_VALIDATE_WITH);
+ GList *schema_entry = pcmk__get_schema(schema_name);
+
+ if (schema_entry != NULL) {
+ *best = ((pcmk__schema_t *)(schema_entry->data))->schema_index;
+ }
+ }
+
+ return pcmk_rc2legacy(rc);
+}
+
+// LCOV_EXCL_STOP
+// End deprecated API
diff --git a/tools/cibadmin.c b/tools/cibadmin.c
index 7837564425..1e7dcbfdf7 100644
--- a/tools/cibadmin.c
+++ b/tools/cibadmin.c
@@ -1,953 +1,953 @@
/*
* Copyright 2004-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU General Public License version 2
* or later (GPLv2+) WITHOUT ANY WARRANTY.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#define SUMMARY "query and edit the Pacemaker configuration"
#define INDENT " "
enum cibadmin_section_type {
cibadmin_section_all = 0,
cibadmin_section_scope,
cibadmin_section_xpath,
};
static int request_id = 0;
static cib_t *the_cib = NULL;
static GMainLoop *mainloop = NULL;
static crm_exit_t exit_code = CRM_EX_OK;
static struct {
const char *cib_action;
int cmd_options;
enum cibadmin_section_type section_type;
char *cib_section;
char *validate_with;
gint message_timeout_sec;
enum pcmk__acl_render_how acl_render_mode;
gchar *cib_user;
gchar *dest_node;
gchar *input_file;
gchar *input_xml;
gboolean input_stdin;
bool delete_all;
gboolean allow_create;
gboolean force;
gboolean get_node_path;
gboolean local;
gboolean no_children;
gboolean sync_call;
/* @COMPAT: For "-!" version option. Not advertised nor marked as
* deprecated, but accepted.
*/
gboolean extended_version;
//! \deprecated
gboolean no_bcast;
} options;
int do_init(void);
static int do_work(xmlNode *input, xmlNode **output);
void cibadmin_op_callback(xmlNode *msg, int call_id, int rc, xmlNode *output,
void *user_data);
static void
print_xml_output(xmlNode * xml)
{
if (!xml) {
return;
} else if (xml->type != XML_ELEMENT_NODE) {
return;
}
if (pcmk_is_set(options.cmd_options, cib_xpath_address)) {
const char *id = crm_element_value(xml, PCMK_XA_ID);
if (pcmk__xe_is(xml, PCMK__XE_XPATH_QUERY)) {
xmlNode *child = NULL;
for (child = xml->children; child; child = child->next) {
print_xml_output(child);
}
} else if (id) {
printf("%s\n", id);
}
} else {
GString *buf = g_string_sized_new(1024);
pcmk__xml_string(xml, pcmk__xml_fmt_pretty, buf, 0);
fprintf(stdout, "%s", buf->str);
g_string_free(buf, TRUE);
}
}
// Upgrade requested but already at latest schema
static void
report_schema_unchanged(void)
{
const char *err = pcmk_rc_str(pcmk_rc_schema_unchanged);
crm_info("Upgrade unnecessary: %s\n", err);
printf("Upgrade unnecessary: %s\n", err);
exit_code = CRM_EX_OK;
}
/*!
* \internal
* \brief Check whether the current CIB action is dangerous
* \return true if \p options.cib_action is dangerous, or false otherwise
*/
static inline bool
cib_action_is_dangerous(void)
{
return options.no_bcast || options.delete_all
|| pcmk__str_any_of(options.cib_action,
PCMK__CIB_REQUEST_UPGRADE,
PCMK__CIB_REQUEST_ERASE,
NULL);
}
/*!
* \internal
* \brief Determine whether the given CIB scope is valid for \p cibadmin
*
* \param[in] scope Scope to validate
*
* \return true if \p scope is valid, or false otherwise
* \note An invalid scope applies the operation to the entire CIB.
*/
static inline bool
scope_is_valid(const char *scope)
{
return pcmk__str_any_of(scope,
PCMK_XE_CONFIGURATION,
PCMK_XE_NODES,
PCMK_XE_RESOURCES,
PCMK_XE_CONSTRAINTS,
PCMK_XE_CRM_CONFIG,
PCMK_XE_RSC_DEFAULTS,
PCMK_XE_OP_DEFAULTS,
PCMK_XE_ACLS,
PCMK_XE_FENCING_TOPOLOGY,
PCMK_XE_TAGS,
PCMK_XE_ALERTS,
PCMK_XE_STATUS,
NULL);
}
static gboolean
command_cb(const gchar *option_name, const gchar *optarg, gpointer data,
GError **error)
{
options.delete_all = false;
if (pcmk__str_any_of(option_name, "-u", "--upgrade", NULL)) {
options.cib_action = PCMK__CIB_REQUEST_UPGRADE;
} else if (pcmk__str_any_of(option_name, "-Q", "--query", NULL)) {
options.cib_action = PCMK__CIB_REQUEST_QUERY;
} else if (pcmk__str_any_of(option_name, "-E", "--erase", NULL)) {
options.cib_action = PCMK__CIB_REQUEST_ERASE;
} else if (pcmk__str_any_of(option_name, "-B", "--bump", NULL)) {
options.cib_action = PCMK__CIB_REQUEST_BUMP;
} else if (pcmk__str_any_of(option_name, "-C", "--create", NULL)) {
options.cib_action = PCMK__CIB_REQUEST_CREATE;
} else if (pcmk__str_any_of(option_name, "-M", "--modify", NULL)) {
options.cib_action = PCMK__CIB_REQUEST_MODIFY;
} else if (pcmk__str_any_of(option_name, "-P", "--patch", NULL)) {
options.cib_action = PCMK__CIB_REQUEST_APPLY_PATCH;
} else if (pcmk__str_any_of(option_name, "-R", "--replace", NULL)) {
options.cib_action = PCMK__CIB_REQUEST_REPLACE;
} else if (pcmk__str_any_of(option_name, "-D", "--delete", NULL)) {
options.cib_action = PCMK__CIB_REQUEST_DELETE;
} else if (pcmk__str_any_of(option_name, "-d", "--delete-all", NULL)) {
options.cib_action = PCMK__CIB_REQUEST_DELETE;
options.delete_all = true;
} else if (pcmk__str_any_of(option_name, "-a", "--empty", NULL)) {
options.cib_action = "empty";
pcmk__str_update(&options.validate_with, optarg);
} else if (pcmk__str_any_of(option_name, "-5", "--md5-sum", NULL)) {
options.cib_action = "md5-sum";
} else if (pcmk__str_any_of(option_name, "-6", "--md5-sum-versioned",
NULL)) {
options.cib_action = "md5-sum-versioned";
} else {
// Should be impossible
return FALSE;
}
return TRUE;
}
static gboolean
show_access_cb(const gchar *option_name, const gchar *optarg, gpointer data,
GError **error)
{
if (pcmk__str_eq(optarg, "auto", pcmk__str_null_matches)) {
options.acl_render_mode = pcmk__acl_render_default;
} else if (g_strcmp0(optarg, "namespace") == 0) {
options.acl_render_mode = pcmk__acl_render_namespace;
} else if (g_strcmp0(optarg, "text") == 0) {
options.acl_render_mode = pcmk__acl_render_text;
} else if (g_strcmp0(optarg, "color") == 0) {
options.acl_render_mode = pcmk__acl_render_color;
} else {
g_set_error(error, PCMK__EXITC_ERROR, CRM_EX_USAGE,
"Invalid value '%s' for option '%s'",
optarg, option_name);
return FALSE;
}
return TRUE;
}
static gboolean
section_cb(const gchar *option_name, const gchar *optarg, gpointer data,
GError **error)
{
if (pcmk__str_any_of(option_name, "-o", "--scope", NULL)) {
options.section_type = cibadmin_section_scope;
} else if (pcmk__str_any_of(option_name, "-A", "--xpath", NULL)) {
options.section_type = cibadmin_section_xpath;
} else {
// Should be impossible
return FALSE;
}
pcmk__str_update(&options.cib_section, optarg);
return TRUE;
}
static GOptionEntry command_entries[] = {
{ "upgrade", 'u', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, command_cb,
"Upgrade the configuration to the latest syntax", NULL },
{ "query", 'Q', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, command_cb,
"Query the contents of the CIB", NULL },
{ "erase", 'E', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, command_cb,
"Erase the contents of the whole CIB", NULL },
{ "bump", 'B', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, command_cb,
"Increase the CIB's epoch value by 1", NULL },
{ "create", 'C', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, command_cb,
"Create an object in the CIB (will fail if object already exists)",
NULL },
{ "modify", 'M', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, command_cb,
"Find object somewhere in CIB's XML tree and update it (fails if object "
"does not exist unless -c is also specified)",
NULL },
{ "patch", 'P', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, command_cb,
"Supply an update in the form of an XML diff (see crm_diff(8))", NULL },
{ "replace", 'R', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, command_cb,
"Recursively replace an object in the CIB", NULL },
{ "delete", 'D', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, command_cb,
"Delete first object matching supplied criteria (for example, "
"<" PCMK_XE_OP " " PCMK_XA_ID "=\"rsc1_op1\" "
PCMK_XA_NAME "=\"monitor\"/>).\n"
INDENT "The XML element name and all attributes must match in order for "
"the element to be deleted.",
NULL },
{ "delete-all", 'd', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
command_cb,
"When used with --xpath, remove all matching objects in the "
"configuration instead of just the first one",
NULL },
{ "empty", 'a', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK,
command_cb,
"Output an empty CIB. Accepts an optional schema name argument to use as "
"the " PCMK_XA_VALIDATE_WITH " value.\n"
INDENT "If no schema is given, the latest will be used.",
"[schema]" },
{ "md5-sum", '5', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, command_cb,
"Calculate the on-disk CIB digest", NULL },
{ "md5-sum-versioned", '6', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
command_cb, "Calculate an on-the-wire versioned CIB digest", NULL },
{ NULL }
};
static GOptionEntry data_entries[] = {
/* @COMPAT: These arguments should be last-wins. We can have an enum option
* that stores the input type, along with a single string option that stores
* the XML string for --xml-text, filename for --xml-file, or NULL for
* --xml-pipe.
*/
{ "xml-text", 'X', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING,
&options.input_xml, "Retrieve XML from the supplied string", "value" },
{ "xml-file", 'x', G_OPTION_FLAG_NONE, G_OPTION_ARG_FILENAME,
&options.input_file, "Retrieve XML from the named file", "value" },
{ "xml-pipe", 'p', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE,
&options.input_stdin, "Retrieve XML from stdin", NULL },
{ NULL }
};
static GOptionEntry addl_entries[] = {
{ "force", 'f', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &options.force,
"Force the action to be performed", NULL },
{ "timeout", 't', G_OPTION_FLAG_NONE, G_OPTION_ARG_INT,
&options.message_timeout_sec,
"Time (in seconds) to wait before declaring the operation failed",
"value" },
{ "user", 'U', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &options.cib_user,
"Run the command with permissions of the named user (valid only for the "
"root and " CRM_DAEMON_USER " accounts)", "value" },
{ "sync-call", 's', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE,
&options.sync_call, "Wait for call to complete before returning", NULL },
{ "local", 'l', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &options.local,
"Command takes effect locally (should be used only for queries)", NULL },
{ "scope", 'o', G_OPTION_FLAG_NONE, G_OPTION_ARG_CALLBACK, section_cb,
"Limit scope of operation to specific section of CIB\n"
INDENT "Valid values: " PCMK_XE_CONFIGURATION ", " PCMK_XE_NODES
", " PCMK_XE_RESOURCES ", " PCMK_XE_CONSTRAINTS
", " PCMK_XE_CRM_CONFIG ", " PCMK_XE_RSC_DEFAULTS ",\n"
INDENT " " PCMK_XE_OP_DEFAULTS ", " PCMK_XE_ACLS
", " PCMK_XE_FENCING_TOPOLOGY ", " PCMK_XE_TAGS ", " PCMK_XE_ALERTS
", " PCMK_XE_STATUS "\n"
INDENT "If both --scope/-o and --xpath/-a are specified, the last one to "
"appear takes effect",
"value" },
{ "xpath", 'A', G_OPTION_FLAG_NONE, G_OPTION_ARG_CALLBACK, section_cb,
"A valid XPath to use instead of --scope/-o\n"
INDENT "If both --scope/-o and --xpath/-a are specified, the last one to "
"appear takes effect",
"value" },
{ "node-path", 'e', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE,
&options.get_node_path,
"When performing XPath queries, return paths of any matches found\n"
INDENT "(for example, "
"\"/" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION
"/" PCMK_XE_RESOURCES "/" PCMK_XE_CLONE
"[@" PCMK_XA_ID "='dummy-clone']"
"/" PCMK_XE_PRIMITIVE "[@" PCMK_XA_ID "='dummy']\")",
NULL },
{ "show-access", 'S', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK,
show_access_cb,
"Whether to use syntax highlighting for ACLs (with -Q/--query and "
"-U/--user)\n"
INDENT "Allowed values: 'color' (default for terminal), 'text' (plain text, "
"default for non-terminal),\n"
INDENT " 'namespace', or 'auto' (use default value)\n"
INDENT "Default value: 'auto'",
"[value]" },
{ "allow-create", 'c', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE,
&options.allow_create,
"(Advanced) Allow target of --modify/-M to be created if it does not "
"exist",
NULL },
{ "no-children", 'n', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE,
&options.no_children,
"(Advanced) When querying an object, do not include its children in the "
"result",
NULL },
{ "node", 'N', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &options.dest_node,
"(Advanced) Send command to the specified host", "value" },
// @COMPAT: Deprecated
{ "no-bcast", 'b', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE,
&options.no_bcast, "deprecated", NULL },
// @COMPAT: Deprecated
{ "host", 'h', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING,
&options.dest_node, "deprecated", NULL },
{ NULL }
};
static GOptionContext *
build_arg_context(pcmk__common_args_t *args)
{
const char *desc = NULL;
GOptionContext *context = NULL;
GOptionEntry extra_prog_entries[] = {
// @COMPAT: Deprecated
{ "extended-version", '!', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE,
&options.extended_version, "deprecated", NULL },
{ NULL }
};
desc = "Examples:\n\n"
"Query the configuration from the local node:\n\n"
"\t# cibadmin --query --local\n\n"
"Query just the cluster options configuration:\n\n"
"\t# cibadmin --query --scope " PCMK_XE_CRM_CONFIG "\n\n"
"Query all '" PCMK_META_TARGET_ROLE "' settings:\n\n"
"\t# cibadmin --query --xpath "
"\"//" PCMK_XE_NVPAIR
"[@" PCMK_XA_NAME "='" PCMK_META_TARGET_ROLE"']\"\n\n"
"Remove all '" PCMK_META_IS_MANAGED "' settings:\n\n"
"\t# cibadmin --delete-all --xpath "
"\"//" PCMK_XE_NVPAIR
"[@" PCMK_XA_NAME "='" PCMK_META_IS_MANAGED "']\"\n\n"
"Remove the resource named 'old':\n\n"
"\t# cibadmin --delete --xml-text "
"'<" PCMK_XE_PRIMITIVE " " PCMK_XA_ID "=\"old\"/>'\n\n"
"Remove all resources from the configuration:\n\n"
"\t# cibadmin --replace --scope " PCMK_XE_RESOURCES
" --xml-text '<" PCMK_XE_RESOURCES "/>'\n\n"
"Replace complete configuration with contents of "
"$HOME/pacemaker.xml:\n\n"
"\t# cibadmin --replace --xml-file $HOME/pacemaker.xml\n\n"
"Replace " PCMK_XE_CONSTRAINTS " section of configuration with "
"contents of $HOME/constraints.xml:\n\n"
"\t# cibadmin --replace --scope " PCMK_XE_CONSTRAINTS
" --xml-file $HOME/constraints.xml\n\n"
"Increase configuration version to prevent old configurations from "
"being loaded accidentally:\n\n"
"\t# cibadmin --modify --xml-text "
"'<" PCMK_XE_CIB " " PCMK_XA_ADMIN_EPOCH
"=\"" PCMK_XA_ADMIN_EPOCH "++\"/>'\n\n"
"Edit the configuration with your favorite $EDITOR:\n\n"
"\t# cibadmin --query > $HOME/local.xml\n\n"
"\t# $EDITOR $HOME/local.xml\n\n"
"\t# cibadmin --replace --xml-file $HOME/local.xml\n\n"
"Assuming terminal, render configuration in color (green for "
"writable, blue for readable, red for\n"
"denied) to visualize permissions for user tony:\n\n"
"\t# cibadmin --show-access=color --query --user tony | less -r\n\n"
"SEE ALSO:\n"
" crm(8), pcs(8), crm_shadow(8), crm_diff(8)\n";
context = pcmk__build_arg_context(args, NULL, NULL, "");
g_option_context_set_description(context, desc);
pcmk__add_main_args(context, extra_prog_entries);
pcmk__add_arg_group(context, "commands", "Commands:", "Show command help",
command_entries);
pcmk__add_arg_group(context, "data", "Data:", "Show data help",
data_entries);
pcmk__add_arg_group(context, "additional", "Additional Options:",
"Show additional options", addl_entries);
return context;
}
int
main(int argc, char **argv)
{
int rc = pcmk_rc_ok;
const char *source = NULL;
xmlNode *output = NULL;
xmlNode *input = NULL;
gchar *acl_cred = NULL;
GError *error = NULL;
pcmk__common_args_t *args = pcmk__new_common_args(SUMMARY);
gchar **processed_args = pcmk__cmdline_preproc(argv, "ANSUXhotx");
GOptionContext *context = build_arg_context(args);
if (!g_option_context_parse_strv(context, &processed_args, &error)) {
exit_code = CRM_EX_USAGE;
goto done;
}
if (g_strv_length(processed_args) > 1) {
gchar *help = g_option_context_get_help(context, TRUE, NULL);
GString *extra = g_string_sized_new(128);
for (int lpc = 1; processed_args[lpc] != NULL; lpc++) {
if (extra->len > 0) {
g_string_append_c(extra, ' ');
}
g_string_append(extra, processed_args[lpc]);
}
exit_code = CRM_EX_USAGE;
g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
"non-option ARGV-elements: %s\n\n%s", extra->str, help);
g_free(help);
g_string_free(extra, TRUE);
goto done;
}
if (args->version || options.extended_version) {
g_strfreev(processed_args);
pcmk__free_arg_context(context);
/* FIXME: When cibadmin is converted to use formatted output, this can
* be replaced by out->version with the appropriate boolean flag.
*
* options.extended_version is deprecated and will be removed in a
* future release.
*/
pcmk__cli_help(options.extended_version? '!' : 'v');
}
/* At LOG_ERR, stderr for CIB calls is rather verbose. Several lines like
*
* (func@file:line) error: CIB failures
*
* In cibadmin we explicitly output the XML portion without the prefixes. So
* we default to LOG_CRIT.
*/
pcmk__cli_init_logging("cibadmin", 0);
set_crm_log_level(LOG_CRIT);
if (args->verbosity > 0) {
cib__set_call_options(options.cmd_options, crm_system_name,
cib_verbose);
for (int i = 0; i < args->verbosity; i++) {
crm_bump_log_level(argc, argv);
}
}
if (options.cib_action == NULL) {
// @COMPAT: Create a default command if other tools have one
gchar *help = g_option_context_get_help(context, TRUE, NULL);
exit_code = CRM_EX_USAGE;
g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
"Must specify a command option\n\n%s", help);
g_free(help);
goto done;
}
if (strcmp(options.cib_action, "empty") == 0) {
// Output an empty CIB
GString *buf = g_string_sized_new(1024);
output = createEmptyCib(1);
crm_xml_add(output, PCMK_XA_VALIDATE_WITH, options.validate_with);
pcmk__xml_string(output, pcmk__xml_fmt_pretty, buf, 0);
fprintf(stdout, "%s", buf->str);
g_string_free(buf, TRUE);
goto done;
}
if (cib_action_is_dangerous() && !options.force) {
exit_code = CRM_EX_UNSAFE;
g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
"The supplied command is considered dangerous. To prevent "
"accidental destruction of the cluster, the --force flag "
"is required in order to proceed.");
goto done;
}
if (options.message_timeout_sec < 1) {
// Set default timeout
options.message_timeout_sec = 30;
}
if (options.section_type == cibadmin_section_xpath) {
// Enable getting section by XPath
cib__set_call_options(options.cmd_options, crm_system_name,
cib_xpath);
} else if (options.section_type == cibadmin_section_scope) {
if (!scope_is_valid(options.cib_section)) {
// @COMPAT: Consider requiring --force to proceed
fprintf(stderr,
"Invalid value '%s' for '--scope'. Operation will apply "
"to the entire CIB.\n", options.cib_section);
}
}
if (options.allow_create) {
// Allow target of --modify/-M to be created if it does not exist
cib__set_call_options(options.cmd_options, crm_system_name,
cib_can_create);
}
if (options.delete_all) {
// With cibadmin_section_xpath, remove all matching objects
cib__set_call_options(options.cmd_options, crm_system_name,
cib_multiple);
}
if (options.get_node_path) {
/* Enable getting node path of XPath query matches.
* Meaningful only if options.section_type == cibadmin_section_xpath.
*/
cib__set_call_options(options.cmd_options, crm_system_name,
cib_xpath_address);
}
if (options.local) {
// Configure command to take effect only locally
cib__set_call_options(options.cmd_options, crm_system_name,
cib_scope_local);
}
// @COMPAT: Deprecated option
if (options.no_bcast) {
// Configure command to take effect only locally and not to broadcast
cib__set_call_options(options.cmd_options, crm_system_name,
cib_inhibit_bcast|cib_scope_local);
}
if (options.no_children) {
// When querying an object, don't include its children in the result
cib__set_call_options(options.cmd_options, crm_system_name,
cib_no_children);
}
if (options.sync_call
|| (options.acl_render_mode != pcmk__acl_render_none)) {
/* Wait for call to complete before returning.
*
* The ACL render modes work only with sync calls due to differences in
* output handling between sync/async. It shouldn't matter to the user
* whether the call is synchronous; for a CIB query, we have to wait for
* the result in order to display it in any case.
*/
cib__set_call_options(options.cmd_options, crm_system_name,
cib_sync_call);
}
if (options.input_file != NULL) {
input = pcmk__xml_read(options.input_file);
source = options.input_file;
} else if (options.input_xml != NULL) {
input = pcmk__xml_parse(options.input_xml);
source = "input string";
} else if (options.input_stdin) {
input = pcmk__xml_read(NULL);
source = "STDIN";
} else if (options.acl_render_mode != pcmk__acl_render_none) {
char *username = pcmk__uid2username(geteuid());
bool required = pcmk_acl_required(username);
free(username);
if (required) {
if (options.force) {
fprintf(stderr, "The supplied command can provide skewed"
" result since it is run under user that also"
" gets guarded per ACLs on their own right."
" Continuing since --force flag was"
" provided.\n");
} else {
exit_code = CRM_EX_UNSAFE;
g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
"The supplied command can provide skewed result "
"since it is run under user that also gets guarded "
"per ACLs in their own right. To accept the risk "
"of such a possible distortion (without even "
"knowing it at this time), use the --force flag.");
goto done;
}
}
if (options.cib_user == NULL) {
exit_code = CRM_EX_USAGE;
g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
"The supplied command requires -U user specified.");
goto done;
}
/* We already stopped/warned ACL-controlled users about consequences.
*
* Note: acl_cred takes ownership of options.cib_user here.
* options.cib_user is set to NULL so that the CIB is obtained as the
* user running the cibadmin command. The CIB must be obtained as a user
* with full permissions in order to show the CIB correctly annotated
* for the options.cib_user's permissions.
*/
acl_cred = options.cib_user;
options.cib_user = NULL;
}
if (input != NULL) {
crm_log_xml_debug(input, "[admin input]");
} else if (source != NULL) {
exit_code = CRM_EX_CONFIG;
g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
"Couldn't parse input from %s.", source);
goto done;
}
if (pcmk__str_eq(options.cib_action, "md5-sum", pcmk__str_casei)) {
char *digest = NULL;
if (input == NULL) {
exit_code = CRM_EX_USAGE;
g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
"Please supply XML to process with -X, -x, or -p");
goto done;
}
digest = calculate_on_disk_digest(input);
fprintf(stderr, "Digest: ");
fprintf(stdout, "%s\n", pcmk__s(digest, ""));
free(digest);
goto done;
} else if (strcmp(options.cib_action, "md5-sum-versioned") == 0) {
char *digest = NULL;
const char *version = NULL;
if (input == NULL) {
exit_code = CRM_EX_USAGE;
g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
"Please supply XML to process with -X, -x, or -p");
goto done;
}
version = crm_element_value(input, PCMK_XA_CRM_FEATURE_SET);
digest = calculate_xml_versioned_digest(input, FALSE, TRUE, version);
fprintf(stderr, "Versioned (%s) digest: ", version);
fprintf(stdout, "%s\n", pcmk__s(digest, ""));
free(digest);
goto done;
}
rc = do_init();
if (rc != pcmk_ok) {
rc = pcmk_legacy2rc(rc);
exit_code = pcmk_rc2exitc(rc);
crm_err("Init failed, could not perform requested operations: %s",
pcmk_rc_str(rc));
g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
"Init failed, could not perform requested operations: %s",
pcmk_rc_str(rc));
goto done;
}
rc = do_work(input, &output);
if (rc > 0) {
/* wait for the reply by creating a mainloop and running it until
* the callbacks are invoked...
*/
request_id = rc;
the_cib->cmds->register_callback(the_cib, request_id,
options.message_timeout_sec, FALSE,
NULL, "cibadmin_op_callback",
cibadmin_op_callback);
mainloop = g_main_loop_new(NULL, FALSE);
crm_trace("%s waiting for reply from the local CIB", crm_system_name);
crm_info("Starting mainloop");
g_main_loop_run(mainloop);
} else if ((rc == -pcmk_err_schema_unchanged)
&& (strcmp(options.cib_action,
PCMK__CIB_REQUEST_UPGRADE) == 0)) {
report_schema_unchanged();
} else if (rc < 0) {
rc = pcmk_legacy2rc(rc);
crm_err("Call failed: %s", pcmk_rc_str(rc));
fprintf(stderr, "Call failed: %s\n", pcmk_rc_str(rc));
if (rc == pcmk_rc_schema_validation) {
if (strcmp(options.cib_action, PCMK__CIB_REQUEST_UPGRADE) == 0) {
xmlNode *obj = NULL;
if (the_cib->cmds->query(the_cib, NULL, &obj,
options.cmd_options) == pcmk_ok) {
- update_validation(&obj, NULL, 0, TRUE, FALSE);
+ pcmk__update_schema(&obj, NULL, true, false);
}
free_xml(obj);
} else if (output) {
validate_xml_verbose(output);
}
}
exit_code = pcmk_rc2exitc(rc);
}
if ((output != NULL)
&& (options.acl_render_mode != pcmk__acl_render_none)) {
xmlDoc *acl_evaled_doc;
rc = pcmk__acl_annotate_permissions(acl_cred, output->doc, &acl_evaled_doc);
if (rc == pcmk_rc_ok) {
xmlChar *rendered = NULL;
rc = pcmk__acl_evaled_render(acl_evaled_doc,
options.acl_render_mode, &rendered);
if (rc != pcmk_rc_ok) {
exit_code = CRM_EX_CONFIG;
g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
"Could not render evaluated access: %s",
pcmk_rc_str(rc));
goto done;
}
printf("%s\n", (char *) rendered);
free(rendered);
} else {
exit_code = CRM_EX_CONFIG;
g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
"Could not evaluate access per request (%s, error: %s)",
acl_cred, pcmk_rc_str(rc));
goto done;
}
} else if (output != NULL) {
print_xml_output(output);
}
crm_trace("%s exiting normally", crm_system_name);
done:
g_strfreev(processed_args);
pcmk__free_arg_context(context);
g_free(options.cib_user);
g_free(options.dest_node);
g_free(options.input_file);
g_free(options.input_xml);
free(options.cib_section);
free(options.validate_with);
g_free(acl_cred);
free_xml(input);
free_xml(output);
rc = cib__clean_up_connection(&the_cib);
if (exit_code == CRM_EX_OK) {
exit_code = pcmk_rc2exitc(rc);
}
pcmk__output_and_clear_error(&error, NULL);
crm_exit(exit_code);
}
static int
do_work(xmlNode *input, xmlNode **output)
{
/* construct the request */
the_cib->call_timeout = options.message_timeout_sec;
if ((strcmp(options.cib_action, PCMK__CIB_REQUEST_REPLACE) == 0)
&& pcmk__xe_is(input, PCMK_XE_CIB)) {
xmlNode *status = pcmk_find_cib_element(input, PCMK_XE_STATUS);
if (status == NULL) {
pcmk__xe_create(input, PCMK_XE_STATUS);
}
}
crm_trace("Passing \"%s\" to variant_op...", options.cib_action);
return cib_internal_op(the_cib, options.cib_action, options.dest_node,
options.cib_section, input, output,
options.cmd_options, options.cib_user);
}
int
do_init(void)
{
int rc = pcmk_ok;
the_cib = cib_new();
rc = the_cib->cmds->signon(the_cib, crm_system_name, cib_command);
if (rc != pcmk_ok) {
crm_err("Could not connect to the CIB: %s", pcmk_strerror(rc));
fprintf(stderr, "Could not connect to the CIB: %s\n",
pcmk_strerror(rc));
}
return rc;
}
void
cibadmin_op_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void *user_data)
{
rc = pcmk_legacy2rc(rc);
exit_code = pcmk_rc2exitc(rc);
if (rc == pcmk_rc_schema_unchanged) {
report_schema_unchanged();
} else if (rc != pcmk_rc_ok) {
crm_warn("Call %s failed: %s " CRM_XS " rc=%d",
options.cib_action, pcmk_rc_str(rc), rc);
fprintf(stderr, "Call %s failed: %s\n",
options.cib_action, pcmk_rc_str(rc));
print_xml_output(output);
} else if ((strcmp(options.cib_action, PCMK__CIB_REQUEST_QUERY) == 0)
&& (output == NULL)) {
crm_err("Query returned no output");
crm_log_xml_err(msg, "no output");
} else if (output == NULL) {
crm_info("Call passed");
} else {
crm_info("Call passed");
print_xml_output(output);
}
if (call_id == request_id) {
g_main_loop_quit(mainloop);
} else {
crm_info("Message was not the response we were looking for (%d vs. %d)",
call_id, request_id);
}
}