Esempio n. 1
0
 def test_inrange_start_duration(self):
     dto = CibRuleExpressionDto(
         "rule",
         CibRuleExpressionType.RULE,
         CibRuleInEffectStatus.UNKNOWN,
         {},
         None,
         None,
         [
             CibRuleExpressionDto(
                 "rule-expr",
                 CibRuleExpressionType.DATE_EXPRESSION,
                 CibRuleInEffectStatus.UNKNOWN,
                 {
                     "operation": "in_range",
                     "start": "2014-06-26",
                 },
                 None,
                 CibRuleDateCommonDto("rule-expr-duration", {"years": "1"}),
                 [],
                 "date in_range 2014-06-26 to duration years=1",
             ),
         ],
         "date in_range 2014-06-26 to duration years=1",
     )
     output = dedent(
         """\
           Rule: (id:rule)
             Expression: date in_range 2014-06-26 to duration (id:rule-expr)
               Duration: years=1 (id:rule-expr-duration)
         """
     )
     self.assert_lines(dto, output)
Esempio n. 2
0
 def test_datespec(self):
     dto = CibRuleExpressionDto(
         "rule",
         CibRuleExpressionType.RULE,
         CibRuleInEffectStatus.UNKNOWN,
         {},
         None,
         None,
         [
             CibRuleExpressionDto(
                 "rule-expr",
                 CibRuleExpressionType.DATE_EXPRESSION,
                 CibRuleInEffectStatus.UNKNOWN,
                 {"operation": "date_spec"},
                 CibRuleDateCommonDto(
                     "rule-expr-datespec",
                     {"hours": "1-14", "monthdays": "20-30", "months": "1"},
                 ),
                 None,
                 [],
                 "date-spec hours=1-14 monthdays=20-30 months=1",
             ),
         ],
         "date-spec hours=1-14 monthdays=20-30 months=1",
     )
     output = dedent(
         """\
           Rule: (id:rule)
             Expression: (id:rule-expr)
               Date Spec: hours=1-14 monthdays=20-30 months=1 (id:rule-expr-datespec)
         """
     )
     self.assert_lines(dto, output)
Esempio n. 3
0
 def test_datespec(self):
     xml = etree.fromstring("""
         <rule id="rule">
             <date_expression id="rule-expr" operation="date_spec">
                 <date_spec id="rule-expr-datespec"
                     hours="1-14" monthdays="20-30" months="1"
                 />
             </date_expression>
         </rule>
     """)
     self.assertEqual(
         rule_element_to_dto(get_in_effect_eval(), xml),
         CibRuleExpressionDto(
             "rule",
             CibRuleExpressionType.RULE,
             CibRuleInEffectStatus.UNKNOWN,
             {},
             None,
             None,
             [
                 CibRuleExpressionDto(
                     "rule-expr",
                     CibRuleExpressionType.DATE_EXPRESSION,
                     CibRuleInEffectStatus.UNKNOWN,
                     {"operation": "date_spec"},
                     CibRuleDateCommonDto(
                         "rule-expr-datespec",
                         {
                             "hours": "1-14",
                             "monthdays": "20-30",
                             "months": "1",
                         },
                     ),
                     None,
                     [],
                     "date-spec hours=1-14 monthdays=20-30 months=1",
                 ),
             ],
             "date-spec hours=1-14 monthdays=20-30 months=1",
         ),
     )
Esempio n. 4
0
 def test_inrange_start_duration(self):
     xml = etree.fromstring("""
         <rule id="rule">
             <date_expression id="rule-expr"
                 operation="in_range" start="2014-06-26"
             >
                 <duration id="rule-expr-duration" years="1"/>
             </date_expression>
         </rule>
     """)
     self.assertEqual(
         rule_element_to_dto(get_in_effect_eval(), xml),
         CibRuleExpressionDto(
             "rule",
             CibRuleExpressionType.RULE,
             CibRuleInEffectStatus.UNKNOWN,
             {},
             None,
             None,
             [
                 CibRuleExpressionDto(
                     "rule-expr",
                     CibRuleExpressionType.DATE_EXPRESSION,
                     CibRuleInEffectStatus.UNKNOWN,
                     {
                         "operation": "in_range",
                         "start": "2014-06-26",
                     },
                     None,
                     CibRuleDateCommonDto(
                         "rule-expr-duration",
                         {"years": "1"},
                     ),
                     [],
                     "date in_range 2014-06-26 to duration years=1",
                 ),
             ],
             "date in_range 2014-06-26 to duration years=1",
         ),
     )
Esempio n. 5
0
 def test_complex_rule(self):
     dto = CibRuleExpressionDto(
         "complex",
         CibRuleExpressionType.RULE,
         CibRuleInEffectStatus.UNKNOWN,
         {"boolean-op": "or", "score": "INFINITY"},
         None,
         None,
         [
             CibRuleExpressionDto(
                 "complex-rule-1",
                 CibRuleExpressionType.RULE,
                 CibRuleInEffectStatus.UNKNOWN,
                 {"boolean-op": "and", "score": "0"},
                 None,
                 None,
                 [
                     CibRuleExpressionDto(
                         "complex-rule-1-expr",
                         CibRuleExpressionType.DATE_EXPRESSION,
                         CibRuleInEffectStatus.UNKNOWN,
                         {"operation": "date_spec"},
                         CibRuleDateCommonDto(
                             "complex-rule-1-expr-datespec",
                             {"hours": "12-23", "weekdays": "1-5"},
                         ),
                         None,
                         [],
                         "date-spec hours=12-23 weekdays=1-5",
                     ),
                     CibRuleExpressionDto(
                         "complex-rule-1-expr-1",
                         CibRuleExpressionType.DATE_EXPRESSION,
                         CibRuleInEffectStatus.UNKNOWN,
                         {
                             "operation": "in_range",
                             "start": "2014-07-26",
                         },
                         None,
                         CibRuleDateCommonDto(
                             "complex-rule-1-expr-1-durat",
                             {"months": "1"},
                         ),
                         [],
                         "date in_range 2014-07-26 to duration months=1",
                     ),
                 ],
                 "date-spec hours=12-23 weekdays=1-5 and date in_range "
                 "2014-07-26 to duration months=1",
             ),
             CibRuleExpressionDto(
                 "complex-rule",
                 CibRuleExpressionType.RULE,
                 CibRuleInEffectStatus.UNKNOWN,
                 {"boolean-op": "and", "score": "0"},
                 None,
                 None,
                 [
                     CibRuleExpressionDto(
                         "complex-rule-expr-1",
                         CibRuleExpressionType.EXPRESSION,
                         CibRuleInEffectStatus.UNKNOWN,
                         {
                             "attribute": "foo",
                             "operation": "gt",
                             "type": "version",
                             "value": "1.2",
                         },
                         None,
                         None,
                         [],
                         "foo gt version 1.2",
                     ),
                     CibRuleExpressionDto(
                         "complex-rule-expr",
                         CibRuleExpressionType.EXPRESSION,
                         CibRuleInEffectStatus.UNKNOWN,
                         {
                             "attribute": "#uname",
                             "operation": "eq",
                             "value": "node3 4",
                         },
                         None,
                         None,
                         [],
                         "#uname eq 'node3 4'",
                     ),
                     CibRuleExpressionDto(
                         "complex-rule-expr-2",
                         CibRuleExpressionType.EXPRESSION,
                         CibRuleInEffectStatus.UNKNOWN,
                         {
                             "attribute": "#uname",
                             "operation": "eq",
                             "value": "nodeA",
                         },
                         None,
                         None,
                         [],
                         "#uname eq nodeA",
                     ),
                 ],
                 "foo gt version 1.2 and #uname eq 'node3 4' and #uname "
                 "eq nodeA",
             ),
         ],
         "(date-spec hours=12-23 weekdays=1-5 and date in_range "
         "2014-07-26 to duration months=1) or (foo gt version 1.2 and "
         "#uname eq 'node3 4' and #uname eq nodeA)",
     )
     output = dedent(
         """\
         Rule: boolean-op=or score=INFINITY (id:complex)
           Rule: boolean-op=and score=0 (id:complex-rule-1)
             Expression: (id:complex-rule-1-expr)
               Date Spec: hours=12-23 weekdays=1-5 (id:complex-rule-1-expr-datespec)
             Expression: date in_range 2014-07-26 to duration (id:complex-rule-1-expr-1)
               Duration: months=1 (id:complex-rule-1-expr-1-durat)
           Rule: boolean-op=and score=0 (id:complex-rule)
             Expression: foo gt version 1.2 (id:complex-rule-expr-1)
             Expression: #uname eq 'node3 4' (id:complex-rule-expr)
             Expression: #uname eq nodeA (id:complex-rule-expr-2)
         """
     )
     self.assert_lines(dto, output)
Esempio n. 6
0
 def test_complex_rule(self):
     xml = etree.fromstring("""
         <rule id="complex" boolean-op="or" score="INFINITY">
             <rule id="complex-rule-1" boolean-op="and" score="0">
                 <date_expression id="complex-rule-1-expr"
                     operation="date_spec"
                 >
                     <date_spec id="complex-rule-1-expr-datespec"
                         weekdays="1-5" hours="12-23"
                     />
                 </date_expression>
                 <date_expression id="complex-rule-1-expr-1"
                     operation="in_range" start="2014-07-26"
                 >
                     <duration id="complex-rule-1-expr-1-durat" months="1"/>
                 </date_expression>
             </rule>
             <rule id="complex-rule" boolean-op="and" score="0">
                 <expression id="complex-rule-expr-1"
                     attribute="foo" operation="gt" type="version" value="1.2"
                 />
                 <expression id="complex-rule-expr"
                     attribute="#uname" operation="eq" value="node3 4"
                 />
                 <expression id="complex-rule-expr-2"
                     attribute="#uname" operation="eq" value="nodeA"
                 />
             </rule>
         </rule>
     """)
     self.assertEqual(
         rule_element_to_dto(get_in_effect_eval(), xml),
         CibRuleExpressionDto(
             "complex",
             CibRuleExpressionType.RULE,
             CibRuleInEffectStatus.UNKNOWN,
             {
                 "boolean-op": "or",
                 "score": "INFINITY"
             },
             None,
             None,
             [
                 CibRuleExpressionDto(
                     "complex-rule-1",
                     CibRuleExpressionType.RULE,
                     CibRuleInEffectStatus.UNKNOWN,
                     {
                         "boolean-op": "and",
                         "score": "0"
                     },
                     None,
                     None,
                     [
                         CibRuleExpressionDto(
                             "complex-rule-1-expr",
                             CibRuleExpressionType.DATE_EXPRESSION,
                             CibRuleInEffectStatus.UNKNOWN,
                             {"operation": "date_spec"},
                             CibRuleDateCommonDto(
                                 "complex-rule-1-expr-datespec",
                                 {
                                     "hours": "12-23",
                                     "weekdays": "1-5"
                                 },
                             ),
                             None,
                             [],
                             "date-spec hours=12-23 weekdays=1-5",
                         ),
                         CibRuleExpressionDto(
                             "complex-rule-1-expr-1",
                             CibRuleExpressionType.DATE_EXPRESSION,
                             CibRuleInEffectStatus.UNKNOWN,
                             {
                                 "operation": "in_range",
                                 "start": "2014-07-26",
                             },
                             None,
                             CibRuleDateCommonDto(
                                 "complex-rule-1-expr-1-durat",
                                 {"months": "1"},
                             ),
                             [],
                             "date in_range 2014-07-26 to duration months=1",
                         ),
                     ],
                     "date-spec hours=12-23 weekdays=1-5 and date in_range "
                     "2014-07-26 to duration months=1",
                 ),
                 CibRuleExpressionDto(
                     "complex-rule",
                     CibRuleExpressionType.RULE,
                     CibRuleInEffectStatus.UNKNOWN,
                     {
                         "boolean-op": "and",
                         "score": "0"
                     },
                     None,
                     None,
                     [
                         CibRuleExpressionDto(
                             "complex-rule-expr-1",
                             CibRuleExpressionType.EXPRESSION,
                             CibRuleInEffectStatus.UNKNOWN,
                             {
                                 "attribute": "foo",
                                 "operation": "gt",
                                 "type": "version",
                                 "value": "1.2",
                             },
                             None,
                             None,
                             [],
                             "foo gt version 1.2",
                         ),
                         CibRuleExpressionDto(
                             "complex-rule-expr",
                             CibRuleExpressionType.EXPRESSION,
                             CibRuleInEffectStatus.UNKNOWN,
                             {
                                 "attribute": "#uname",
                                 "operation": "eq",
                                 "value": "node3 4",
                             },
                             None,
                             None,
                             [],
                             '#uname eq "node3 4"',
                         ),
                         CibRuleExpressionDto(
                             "complex-rule-expr-2",
                             CibRuleExpressionType.EXPRESSION,
                             CibRuleInEffectStatus.UNKNOWN,
                             {
                                 "attribute": "#uname",
                                 "operation": "eq",
                                 "value": "nodeA",
                             },
                             None,
                             None,
                             [],
                             "#uname eq nodeA",
                         ),
                     ],
                     'foo gt version 1.2 and #uname eq "node3 4" and #uname '
                     "eq nodeA",
                 ),
             ],
             "(date-spec hours=12-23 weekdays=1-5 and date in_range "
             "2014-07-26 to duration months=1) or (foo gt version 1.2 and "
             '#uname eq "node3 4" and #uname eq nodeA)',
         ),
     )
Esempio n. 7
0
 def test_full(self):
     for tag, nvtype in self.tag_type:
         with self.subTest(tag=tag, nvset_type=nvtype):
             xml = etree.fromstring(
                 f"""
                 <{tag} id="my-id" score="150">
                     <rule id="my-id-rule" boolean-op="and">
                         <rsc_expression
                             id="my-id-rule-rsc-ocf-pacemaker-Dummy"
                             class="ocf" provider="pacemaker" type="Dummy"
                         />
                         <op_expression id="my-id-rule-op" name="monitor" />
                         <rule id="my-id-rule-rule" boolean-op="or">
                             <expression id="my-id-rule-rule-expr"
                                 operation="defined" attribute="attr1"
                             />
                             <expression id="my-id-rule-rule-expr-1"
                                 attribute="attr2" operation="gt"
                                 type="integer" value="5"
                             />
                             <date_expression id="my-id-rule-rule-expr-2"
                                 operation="lt" end="2020-08-07"
                             />
                             <date_expression id="my-id-rule-rule-expr-3"
                                 operation="in_range"
                                 start="2020-09-01" end="2020-09-11"
                             />
                             <date_expression id="my-id-rule-rule-expr-4"
                                 operation="in_range" start="2020-10-01"
                             >
                                 <duration id="my-id-rule-rule-expr-4-duration"
                                     months="1"
                                 />
                             </date_expression>
                             <date_expression id="my-id-rule-rule-expr-5"
                                 operation="date_spec"
                             >
                                 <date_spec id="my-id-rule-rule-expr-5-datespec"
                                     years="2021-2022"
                                 />
                             </date_expression>
                             <date_expression id="my-id-rule-rule-expr-6"
                                 operation="in_range" end="2020-09-11"
                             />
                         </rule>
                     </rule>
                     <nvpair id="my-id-pair1" name="name1" value="value1" />
                     <nvpair id="my-id-pair2" name="name2" value="value2" />
                 </{tag}>
             """
             )
             self.assertEqual(
                 nvpair_multi.nvset_element_to_dto(
                     xml, get_in_effect_eval()
                 ),
                 CibNvsetDto(
                     "my-id",
                     nvtype,
                     {"score": "150"},
                     CibRuleExpressionDto(
                         "my-id-rule",
                         CibRuleExpressionType.RULE,
                         CibRuleInEffectStatus.UNKNOWN,
                         {"boolean-op": "and"},
                         None,
                         None,
                         [
                             CibRuleExpressionDto(
                                 "my-id-rule-rsc-ocf-pacemaker-Dummy",
                                 CibRuleExpressionType.RSC_EXPRESSION,
                                 CibRuleInEffectStatus.UNKNOWN,
                                 {
                                     "class": "ocf",
                                     "provider": "pacemaker",
                                     "type": "Dummy",
                                 },
                                 None,
                                 None,
                                 [],
                                 "resource ocf:pacemaker:Dummy",
                             ),
                             CibRuleExpressionDto(
                                 "my-id-rule-op",
                                 CibRuleExpressionType.OP_EXPRESSION,
                                 CibRuleInEffectStatus.UNKNOWN,
                                 {"name": "monitor"},
                                 None,
                                 None,
                                 [],
                                 "op monitor",
                             ),
                             CibRuleExpressionDto(
                                 "my-id-rule-rule",
                                 CibRuleExpressionType.RULE,
                                 CibRuleInEffectStatus.UNKNOWN,
                                 {"boolean-op": "or"},
                                 None,
                                 None,
                                 [
                                     CibRuleExpressionDto(
                                         "my-id-rule-rule-expr",
                                         CibRuleExpressionType.EXPRESSION,
                                         CibRuleInEffectStatus.UNKNOWN,
                                         {
                                             "operation": "defined",
                                             "attribute": "attr1",
                                         },
                                         None,
                                         None,
                                         [],
                                         "defined attr1",
                                     ),
                                     CibRuleExpressionDto(
                                         "my-id-rule-rule-expr-1",
                                         CibRuleExpressionType.EXPRESSION,
                                         CibRuleInEffectStatus.UNKNOWN,
                                         {
                                             "attribute": "attr2",
                                             "operation": "gt",
                                             "type": "integer",
                                             "value": "5",
                                         },
                                         None,
                                         None,
                                         [],
                                         "attr2 gt integer 5",
                                     ),
                                     CibRuleExpressionDto(
                                         "my-id-rule-rule-expr-2",
                                         CibRuleExpressionType.DATE_EXPRESSION,
                                         CibRuleInEffectStatus.UNKNOWN,
                                         {
                                             "operation": "lt",
                                             "end": "2020-08-07",
                                         },
                                         None,
                                         None,
                                         [],
                                         "date lt 2020-08-07",
                                     ),
                                     CibRuleExpressionDto(
                                         "my-id-rule-rule-expr-3",
                                         CibRuleExpressionType.DATE_EXPRESSION,
                                         CibRuleInEffectStatus.UNKNOWN,
                                         {
                                             "operation": "in_range",
                                             "start": "2020-09-01",
                                             "end": "2020-09-11",
                                         },
                                         None,
                                         None,
                                         [],
                                         "date in_range 2020-09-01 to 2020-09-11",
                                     ),
                                     CibRuleExpressionDto(
                                         "my-id-rule-rule-expr-4",
                                         CibRuleExpressionType.DATE_EXPRESSION,
                                         CibRuleInEffectStatus.UNKNOWN,
                                         {
                                             "operation": "in_range",
                                             "start": "2020-10-01",
                                         },
                                         None,
                                         CibRuleDateCommonDto(
                                             "my-id-rule-rule-expr-4-duration",
                                             {"months": "1"},
                                         ),
                                         [],
                                         "date in_range 2020-10-01 to duration months=1",
                                     ),
                                     CibRuleExpressionDto(
                                         "my-id-rule-rule-expr-5",
                                         CibRuleExpressionType.DATE_EXPRESSION,
                                         CibRuleInEffectStatus.UNKNOWN,
                                         {"operation": "date_spec"},
                                         CibRuleDateCommonDto(
                                             "my-id-rule-rule-expr-5-datespec",
                                             {"years": "2021-2022"},
                                         ),
                                         None,
                                         [],
                                         "date-spec years=2021-2022",
                                     ),
                                     CibRuleExpressionDto(
                                         "my-id-rule-rule-expr-6",
                                         CibRuleExpressionType.DATE_EXPRESSION,
                                         CibRuleInEffectStatus.UNKNOWN,
                                         {
                                             "operation": "in_range",
                                             "end": "2020-09-11",
                                         },
                                         None,
                                         None,
                                         [],
                                         "date in_range to 2020-09-11",
                                     ),
                                 ],
                                 "defined attr1 or attr2 gt integer 5 or "
                                 "date lt 2020-08-07 or "
                                 "date in_range 2020-09-01 to 2020-09-11 or "
                                 "date in_range 2020-10-01 to duration months=1 or "
                                 "date-spec years=2021-2022 or "
                                 "date in_range to 2020-09-11",
                             ),
                         ],
                         "resource ocf:pacemaker:Dummy and op monitor and "
                         "(defined attr1 or attr2 gt integer 5 or "
                         "date lt 2020-08-07 or "
                         "date in_range 2020-09-01 to 2020-09-11 or "
                         "date in_range 2020-10-01 to duration months=1 "
                         "or date-spec years=2021-2022 or "
                         "date in_range to 2020-09-11)",
                     ),
                     [
                         CibNvpairDto("my-id-pair1", "name1", "value1"),
                         CibNvpairDto("my-id-pair2", "name2", "value2"),
                     ],
                 ),
             )
Esempio n. 8
0
 def test_full(self):
     defaults_xml = f"""
         <{self.tag}>
             <meta_attributes id="{self.tag}-meta_attributes">
                 <rule id="{self.tag}-meta_attributes-rule"
                     boolean-op="and" score="INFINITY"
                 >
                     <rsc_expression
                         id="{self.tag}-meta_attributes-rule-rsc-Dummy"
                         class="ocf" provider="pacemaker" type="Dummy"
                     />
                     <rule id="{self.tag}-meta_attributes-rule-rule"
                         boolean-op="or"
                     >
                         <expression
                             id="{self.tag}-meta_attributes-rule-rule-expr"
                             operation="defined" attribute="attr1"
                         />
                         <expression
                             id="{self.tag}-meta_attributes-rule-rule-expr-1"
                             attribute="attr2" operation="gt"
                             type="integer" value="5"
                         />
                         <date_expression
                             id="{self.tag}-meta_attributes-rule-rule-expr-2"
                             operation="lt" end="2020-08-07"
                         />
                         <date_expression
                             id="{self.tag}-meta_attributes-rule-rule-expr-3"
                             operation="in_range"
                             start="2020-09-01" end="2020-09-11"
                         />
                         <date_expression
                             id="{self.tag}-meta_attributes-rule-rule-expr-4"
                             operation="in_range" start="2020-10-01"
                         >
                             <duration
                                 id="{self.tag}-meta_attributes-rule-rule-expr-4-duration"
                                 months="1"
                             />
                         </date_expression>
                         <date_expression
                             id="{self.tag}-meta_attributes-rule-rule-expr-5"
                             operation="date_spec"
                         >
                             <date_spec
                                 id="{self.tag}-meta_attributes-rule-rule-expr-5-datespec"
                                 years="2021-2022"
                             />
                         </date_expression>
                         <date_expression
                             id="{self.tag}-meta_attributes-rule-rule-expr-6"
                             operation="in_range" end="2020-12-11"
                         />
                     </rule>
                 </rule>
                 <nvpair id="my-id-pair1" name="name1" value="value1" />
                 <nvpair id="my-id-pair2" name="name2" value="value2" />
             </meta_attributes>
             <instance_attributes id="instance">
                 <nvpair id="instance-pair" name="inst" value="ance" />
             </instance_attributes>
             <meta_attributes id="meta-plain" score="123">
                 <nvpair id="my-id-pair3" name="name1" value="value1" />
             </meta_attributes>
         </{self.tag}>
     """
     self.config.runner.cib.load(
         filename="cib-empty-3.4.xml", optional_in_conf=defaults_xml
     )
     self.config.fs.isfile(
         (os.path.join(settings.pacemaker_binaries, "crm_rule")),
         return_value=False,
     )
     self.assertEqual(
         [
             CibNvsetDto(
                 f"{self.tag}-meta_attributes",
                 CibNvsetType.META,
                 {},
                 CibRuleExpressionDto(
                     f"{self.tag}-meta_attributes-rule",
                     CibRuleExpressionType.RULE,
                     CibRuleInEffectStatus.UNKNOWN,
                     {"boolean-op": "and", "score": "INFINITY"},
                     None,
                     None,
                     [
                         CibRuleExpressionDto(
                             f"{self.tag}-meta_attributes-rule-rsc-Dummy",
                             CibRuleExpressionType.RSC_EXPRESSION,
                             CibRuleInEffectStatus.UNKNOWN,
                             {
                                 "class": "ocf",
                                 "provider": "pacemaker",
                                 "type": "Dummy",
                             },
                             None,
                             None,
                             [],
                             "resource ocf:pacemaker:Dummy",
                         ),
                         CibRuleExpressionDto(
                             f"{self.tag}-meta_attributes-rule-rule",
                             CibRuleExpressionType.RULE,
                             CibRuleInEffectStatus.UNKNOWN,
                             {"boolean-op": "or"},
                             None,
                             None,
                             [
                                 CibRuleExpressionDto(
                                     f"{self.tag}-meta_attributes-rule-rule-expr",
                                     CibRuleExpressionType.EXPRESSION,
                                     CibRuleInEffectStatus.UNKNOWN,
                                     {
                                         "operation": "defined",
                                         "attribute": "attr1",
                                     },
                                     None,
                                     None,
                                     [],
                                     "defined attr1",
                                 ),
                                 CibRuleExpressionDto(
                                     f"{self.tag}-meta_attributes-rule-rule-expr-1",
                                     CibRuleExpressionType.EXPRESSION,
                                     CibRuleInEffectStatus.UNKNOWN,
                                     {
                                         "attribute": "attr2",
                                         "operation": "gt",
                                         "type": "integer",
                                         "value": "5",
                                     },
                                     None,
                                     None,
                                     [],
                                     "attr2 gt integer 5",
                                 ),
                                 CibRuleExpressionDto(
                                     f"{self.tag}-meta_attributes-rule-rule-expr-2",
                                     CibRuleExpressionType.DATE_EXPRESSION,
                                     CibRuleInEffectStatus.UNKNOWN,
                                     {
                                         "operation": "lt",
                                         "end": "2020-08-07",
                                     },
                                     None,
                                     None,
                                     [],
                                     "date lt 2020-08-07",
                                 ),
                                 CibRuleExpressionDto(
                                     f"{self.tag}-meta_attributes-rule-rule-expr-3",
                                     CibRuleExpressionType.DATE_EXPRESSION,
                                     CibRuleInEffectStatus.UNKNOWN,
                                     {
                                         "operation": "in_range",
                                         "start": "2020-09-01",
                                         "end": "2020-09-11",
                                     },
                                     None,
                                     None,
                                     [],
                                     "date in_range 2020-09-01 to 2020-09-11",
                                 ),
                                 CibRuleExpressionDto(
                                     f"{self.tag}-meta_attributes-rule-rule-expr-4",
                                     CibRuleExpressionType.DATE_EXPRESSION,
                                     CibRuleInEffectStatus.UNKNOWN,
                                     {
                                         "operation": "in_range",
                                         "start": "2020-10-01",
                                     },
                                     None,
                                     CibRuleDateCommonDto(
                                         f"{self.tag}-meta_attributes-rule-rule-expr-4-duration",
                                         {"months": "1"},
                                     ),
                                     [],
                                     "date in_range 2020-10-01 to duration months=1",
                                 ),
                                 CibRuleExpressionDto(
                                     f"{self.tag}-meta_attributes-rule-rule-expr-5",
                                     CibRuleExpressionType.DATE_EXPRESSION,
                                     CibRuleInEffectStatus.UNKNOWN,
                                     {"operation": "date_spec"},
                                     CibRuleDateCommonDto(
                                         f"{self.tag}-meta_attributes-rule-rule-expr-5-datespec",
                                         {"years": "2021-2022"},
                                     ),
                                     None,
                                     [],
                                     "date-spec years=2021-2022",
                                 ),
                                 CibRuleExpressionDto(
                                     f"{self.tag}-meta_attributes-rule-rule-expr-6",
                                     CibRuleExpressionType.DATE_EXPRESSION,
                                     CibRuleInEffectStatus.UNKNOWN,
                                     {
                                         "operation": "in_range",
                                         "end": "2020-12-11",
                                     },
                                     None,
                                     None,
                                     [],
                                     "date in_range to 2020-12-11",
                                 ),
                             ],
                             "defined attr1 or attr2 gt integer 5 or "
                             "date lt 2020-08-07 or "
                             "date in_range 2020-09-01 to 2020-09-11 or "
                             "date in_range 2020-10-01 to duration months=1 "
                             "or date-spec years=2021-2022 or "
                             "date in_range to 2020-12-11",
                         ),
                     ],
                     "resource ocf:pacemaker:Dummy and "
                     "(defined attr1 or attr2 gt integer 5 or "
                     "date lt 2020-08-07 or "
                     "date in_range 2020-09-01 to 2020-09-11 or "
                     "date in_range 2020-10-01 to duration months=1 or "
                     "date-spec years=2021-2022 or "
                     "date in_range to 2020-12-11)",
                 ),
                 [
                     CibNvpairDto("my-id-pair1", "name1", "value1"),
                     CibNvpairDto("my-id-pair2", "name2", "value2"),
                 ],
             ),
             CibNvsetDto(
                 "instance",
                 CibNvsetType.INSTANCE,
                 {},
                 None,
                 [CibNvpairDto("instance-pair", "inst", "ance")],
             ),
             CibNvsetDto(
                 "meta-plain",
                 CibNvsetType.META,
                 {"score": "123"},
                 None,
                 [CibNvpairDto("my-id-pair3", "name1", "value1")],
             ),
         ],
         self.command(self.env_assist.get_env(), True),
     )
     self.env_assist.assert_reports(
         [
             fixture.warn(
                 reports.codes.RULE_IN_EFFECT_STATUS_DETECTION_NOT_SUPPORTED
             ),
         ]
     )
Esempio n. 9
0
def _date_common_to_dto(expr_el: Element) -> CibRuleDateCommonDto:
    return CibRuleDateCommonDto(
        expr_el.get("id", ""),
        export_attributes(expr_el, with_id=False),
    )