Skip to content

Commit

Permalink
Test: cts-cli: Add tests for timezone in date_expression of rule
Browse files Browse the repository at this point in the history
Ref T646

Signed-off-by: Reid Wahl <[email protected]>
  • Loading branch information
nrwahl2 committed Apr 5, 2023
1 parent 473ca76 commit c2c90e9
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 7 deletions.
53 changes: 52 additions & 1 deletion cts/cli/regression.rules.exp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ log_xmllib_err error: XML Error: ^
=#=#=#= Begin test: Try to check a rule that doesn't exist =#=#=#=
Could not determine whether rule blahblah is in effect: Rule not found
=#=#=#= Current cib after: Try to check a rule that doesn't exist =#=#=#=
<cib epoch="10" num_updates="0" admin_epoch="0">
<cib epoch="11" num_updates="0" admin_epoch="0">
<configuration>
<crm_config>
<cluster_property_set id="cib-bootstrap-options">
Expand Down Expand Up @@ -111,6 +111,13 @@ Could not determine whether rule blahblah is in effect: Rule not found
</date_expression>
</rule>
</rsc_location>
<rsc_location id="cli-prefer-dummy-date_spec-timezone" rsc="dummy">
<rule id="cli-prefer-rule-dummy-date_spec-timezone" score="INFINITY">
<date_expression id="cli-prefer-dummy-date_spec-timezone-expr" operation="date_spec" timezone="pcmk+04">
<date_spec id="cli-prefer-dummy-date_spec-timezone-spec" years="2023" hours="12"/>
</date_expression>
</rule>
</rsc_location>
<rsc_location id="cli-prefer-dummy-date_spec-without-years" rsc="dummy">
<rule id="cli-prefer-rule-dummy-date_spec-without-years" score="INFINITY">
<date_expression id="cli-prefer-dummy-date_spec-without-years-expr" operation="date_spec">
Expand Down Expand Up @@ -230,6 +237,50 @@ Rule cli-prefer-rule-dummy-date_spec-only-years satisfies conditions
</pacemaker-result>
=#=#=#= End test: Verify date_spec rule with years is in effect (XML) - OK (0) =#=#=#=
* Passed: crm_rule - Verify date_spec rule with years is in effect (XML)
=#=#=#= Begin test: Verify date_spec rule with timezone is in effect (same TZ) =#=#=#=
Rule cli-prefer-rule-dummy-date_spec-timezone satisfies conditions
=#=#=#= End test: Verify date_spec rule with timezone is in effect (same TZ) - OK (0) =#=#=#=
* Passed: crm_rule - Verify date_spec rule with timezone is in effect (same TZ)
=#=#=#= Begin test: Verify date_spec rule with timezone is in effect (same TZ) (XML) =#=#=#=
<pacemaker-result api-version="X" request="crm_rule -c -r cli-prefer-rule-dummy-date_spec-timezone -d 20230404T12:00:00 --output-as=xml">
<rule-check rule-id="cli-prefer-rule-dummy-date_spec-timezone" rc="0"/>
<status code="0" message="OK"/>
</pacemaker-result>
=#=#=#= End test: Verify date_spec rule with timezone is in effect (same TZ) (XML) - OK (0) =#=#=#=
* Passed: crm_rule - Verify date_spec rule with timezone is in effect (same TZ) (XML)
=#=#=#= Begin test: Verify date_spec rule with timezone is not in effect (same TZ) =#=#=#=
Rule cli-prefer-rule-dummy-date_spec-timezone has not yet taken effect
=#=#=#= End test: Verify date_spec rule with timezone is not in effect (same TZ) - Requested item is not yet in effect (111) =#=#=#=
* Passed: crm_rule - Verify date_spec rule with timezone is not in effect (same TZ)
=#=#=#= Begin test: Verify date_spec rule with timezone is not in effect (same TZ) (XML) =#=#=#=
<pacemaker-result api-version="X" request="crm_rule -c -r cli-prefer-rule-dummy-date_spec-timezone -d 20230404T09:00:00 --output-as=xml">
<rule-check rule-id="cli-prefer-rule-dummy-date_spec-timezone" rc="111"/>
<status code="111" message="Requested item is not yet in effect"/>
</pacemaker-result>
=#=#=#= End test: Verify date_spec rule with timezone is not in effect (same TZ) (XML) - Requested item is not yet in effect (111) =#=#=#=
* Passed: crm_rule - Verify date_spec rule with timezone is not in effect (same TZ) (XML)
=#=#=#= Begin test: Verify date_spec rule with timezone is in effect (diff TZ) =#=#=#=
Rule cli-prefer-rule-dummy-date_spec-timezone satisfies conditions
=#=#=#= End test: Verify date_spec rule with timezone is in effect (diff TZ) - OK (0) =#=#=#=
* Passed: crm_rule - Verify date_spec rule with timezone is in effect (diff TZ)
=#=#=#= Begin test: Verify date_spec rule with timezone is in effect (diff TZ) (XML) =#=#=#=
<pacemaker-result api-version="X" request="crm_rule -c -r cli-prefer-rule-dummy-date_spec-timezone -d 20230404T09:00:00 --output-as=xml">
<rule-check rule-id="cli-prefer-rule-dummy-date_spec-timezone" rc="0"/>
<status code="0" message="OK"/>
</pacemaker-result>
=#=#=#= End test: Verify date_spec rule with timezone is in effect (diff TZ) (XML) - OK (0) =#=#=#=
* Passed: crm_rule - Verify date_spec rule with timezone is in effect (diff TZ) (XML)
=#=#=#= Begin test: Verify date_spec rule with timezone is not in effect (diff TZ) =#=#=#=
Rule cli-prefer-rule-dummy-date_spec-timezone is expired
=#=#=#= End test: Verify date_spec rule with timezone is not in effect (diff TZ) - Requested item has expired (110) =#=#=#=
* Passed: crm_rule - Verify date_spec rule with timezone is not in effect (diff TZ)
=#=#=#= Begin test: Verify date_spec rule with timezone is not in effect (diff TZ) (XML) =#=#=#=
<pacemaker-result api-version="X" request="crm_rule -c -r cli-prefer-rule-dummy-date_spec-timezone -d 20230404T12:00:00 --output-as=xml">
<rule-check rule-id="cli-prefer-rule-dummy-date_spec-timezone" rc="110"/>
<status code="110" message="Requested item has expired"/>
</pacemaker-result>
=#=#=#= End test: Verify date_spec rule with timezone is not in effect (diff TZ) (XML) - Requested item has expired (110) =#=#=#=
* Passed: crm_rule - Verify date_spec rule with timezone is not in effect (diff TZ) (XML)
=#=#=#= Begin test: Try to check a rule whose date_spec does not contain years= =#=#=#=
Could not determine whether rule cli-prefer-rule-dummy-date_spec-without-years is in effect: Rule must either not use date_spec, or use date_spec with years= but not moon=
=#=#=#= End test: Try to check a rule whose date_spec does not contain years= - Unimplemented (3) =#=#=#=
Expand Down
7 changes: 5 additions & 2 deletions cts/cli/regression.upgrade.exp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ 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 trace: Stopping at pacemaker-3.9
update_validation info: Transformed the configuration from pacemaker-2.10 to 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 trace: Stopping at pacemaker-3.10
update_validation info: Transformed the configuration from pacemaker-2.10 to pacemaker-3.10
=#=#=#= Current cib after: Upgrade to latest CIB schema (trigger 2.10.xsl + the wrapping) =#=#=#=
<cib epoch="2" num_updates="0" admin_epoch="1">
<configuration>
Expand Down
22 changes: 18 additions & 4 deletions cts/cli/regression.validity.exp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ update_validation debug: Testing 'pacemaker-3.9' validation (23 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-3.9 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.9
update_validation debug: Testing 'pacemaker-3.10' validation (24 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-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
=#=#=#= 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) =#=#=#=
Expand Down Expand Up @@ -239,7 +243,10 @@ update_validation trace: pacemaker-3.8 validation failed
update_validation debug: Testing 'pacemaker-3.9' validation (23 of X)
element cib: Relax-NG validity error : Invalid attribute validate-with for element cib
update_validation trace: pacemaker-3.9 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.9
update_validation debug: Testing 'pacemaker-3.10' validation (24 of X)
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
=#=#=#= 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) =#=#=#=
Expand Down Expand Up @@ -345,8 +352,11 @@ 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 trace: Stopping at pacemaker-3.9
update_validation info: Transformed the configuration from pacemaker-1.2 to 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 trace: Stopping at pacemaker-3.10
update_validation info: Transformed the configuration from pacemaker-1.2 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
Expand Down Expand Up @@ -460,6 +470,8 @@ element rsc_order: Relax-NG validity error : Invalid attribute first-action for
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 =#=#=#=
<cib epoch="41" num_updates="0" admin_epoch="0" validate-with="none">
<configuration>
Expand Down Expand Up @@ -529,6 +541,8 @@ validity.bad.xml:10: element rsc_order: Relax-NG validity error : Invalid attrib
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
Expand Down
71 changes: 71 additions & 0 deletions cts/cts-cli.in
Original file line number Diff line number Diff line change
Expand Up @@ -2891,6 +2891,9 @@ EOF

test_rules() {
local TMPXML
local old_TZ
local rule
local dt_string

create_shadow_cib --create-empty

Expand Down Expand Up @@ -2954,6 +2957,24 @@ EOF
cibadmin -C -o constraints -x "$TMPXML"
rm -f "$TMPXML"

# This date_expression passes in hour 12 in the UTC-4 timezone.
# UTC offsets are inverted in the TZ variable syntax.
TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
cat <<EOF > "$TMPXML"
<rsc_location id="cli-prefer-dummy-date_spec-timezone" rsc="dummy">
<rule id="cli-prefer-rule-dummy-date_spec-timezone" score="INFINITY">
<date_expression id="cli-prefer-dummy-date_spec-timezone-expr"
operation="date_spec" timezone="pcmk+04">
<date_spec id="cli-prefer-dummy-date_spec-timezone-spec" years="2023"
hours="12"/>
</date_expression>
</rule>
</rsc_location>
EOF

cibadmin -C -o constraints -x "$TMPXML"
rm -f "$TMPXML"

TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
cat <<EOF > "$TMPXML"
<rsc_location id="cli-prefer-dummy-date_spec-without-years" rsc="dummy">
Expand Down Expand Up @@ -3090,6 +3111,56 @@ EOF
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

old_TZ=$TZ

# UTC-4
# Note: 12:00 in UTC-4 timezone == 09:00 in UTC-7 timezone
export TZ="pcmk+04"

rule="cli-prefer-rule-dummy-date_spec-timezone"
dt_string="20230404T12:00:00"

desc="Verify date_spec rule with timezone is in effect (same TZ)"
cmd="crm_rule -c -r $rule -d $dt_string"
test_assert $CRM_EX_OK 0

desc="Verify date_spec rule with timezone is in effect (same TZ) (XML)"
cmd="crm_rule -c -r $rule -d $dt_string --output-as=xml"
test_assert_validate $CRM_EX_OK 0

dt_string="20230404T09:00:00"

desc="Verify date_spec rule with timezone is not in effect (same TZ)"
cmd="crm_rule -c -r $rule -d $dt_string"
test_assert $CRM_EX_NOT_YET_IN_EFFECT 0

desc="Verify date_spec rule with timezone is not in effect (same TZ) (XML)"
cmd="crm_rule -c -r $rule -d $dt_string --output-as=xml"
test_assert_validate $CRM_EX_NOT_YET_IN_EFFECT 0

# UTC-7
export TZ="pcmk+07"

desc="Verify date_spec rule with timezone is in effect (diff TZ)"
cmd="crm_rule -c -r $rule -d $dt_string"
test_assert $CRM_EX_OK 0

desc="Verify date_spec rule with timezone is in effect (diff TZ) (XML)"
cmd="crm_rule -c -r $rule -d $dt_string --output-as=xml"
test_assert_validate $CRM_EX_OK 0

dt_string="20230404T12:00:00"

desc="Verify date_spec rule with timezone is not in effect (diff TZ)"
cmd="crm_rule -c -r $rule -d $dt_string"
test_assert $CRM_EX_EXPIRED 0

desc="Verify date_spec rule with timezone is not in effect (diff TZ) (XML)"
cmd="crm_rule -c -r $rule -d $dt_string --output-as=xml"
test_assert_validate $CRM_EX_EXPIRED 0

export TZ="$old_TZ"

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
Expand Down

0 comments on commit c2c90e9

Please sign in to comment.