Esempio n. 1
0
 def fixture_expired_dto(expired):
     return CibNvsetDto(
         "my-id",
         CibNvsetType.META,
         {},
         CibRuleExpressionDto(
             "my-id-rule",
             CibRuleExpressionType.RULE,
             expired,
             {"boolean-op": "and"},
             None,
             None,
             [
                 CibRuleExpressionDto(
                     "my-id-rule-expr",
                     CibRuleExpressionType.EXPRESSION,
                     CibRuleInEffectStatus.UNKNOWN,
                     {"operation": "defined", "attribute": "attr1",},
                     None,
                     None,
                     [],
                     "defined attr1",
                 ),
             ],
             "defined attr1",
         ),
         [CibNvpairDto("my-id-pair1", "name1", "value1")],
     )
Esempio n. 2
0
 def fixture_dto(nvtype, in_effect):
     return CibNvsetDto(
         f"id-{in_effect}",
         nvtype,
         {"score": "150"},
         CibRuleExpressionDto(
             f"id-{in_effect}-rule",
             CibRuleExpressionType.RULE,
             in_effect,
             {"boolean-op": "or"},
             None,
             None,
             [
                 CibRuleExpressionDto(
                     f"id-{in_effect}-rule-op",
                     CibRuleExpressionType.OP_EXPRESSION,
                     CibRuleInEffectStatus.UNKNOWN,
                     {"name": "monitor"},
                     None,
                     None,
                     [],
                     "op monitor",
                 ),
             ],
             "op monitor",
         ),
         [CibNvpairDto(f"id-{in_effect}-pair1", "name1", "value1")],
     )
Esempio n. 3
0
def action_to_operation_dto(
    action: ResourceAgentAction, ) -> CibResourceOperationDto:
    """
    Transform agent action data to CIB operation data
    """
    instance_attributes = []
    if action.depth not in (None, "0"):
        instance_attributes = [
            CibNvsetDto(
                id="",
                options={},
                rule=None,
                nvpairs=[
                    CibNvpairDto(id="",
                                 name="OCF_CHECK_LEVEL",
                                 value=str(action.depth))
                ],
            )
        ]
    return CibResourceOperationDto(
        id="",
        name=action.name,
        interval=(action.interval if action.interval else
                  get_default_operation_interval(action.name)),
        description=None,
        start_delay=action.start_delay,
        interval_origin=None,
        timeout=action.timeout,
        enabled=None,
        record_pending=None,
        role=PcmkRoleType(action.role) if action.role else None,
        on_fail=None,
        meta_attributes=[],
        instance_attributes=instance_attributes,
    )
Esempio n. 4
0
 def test_minimal(self):
     for tag, nvtype in self.tag_type:
         with self.subTest(tag=tag, nvset_type=nvtype):
             xml = etree.fromstring(f"""<{tag} id="my-id" />""")
             self.assertEqual(
                 nvpair_multi.nvset_element_to_dto(xml),
                 CibNvsetDto("my-id", nvtype, {}, None, []),
             )
Esempio n. 5
0
 def test_minimal(self):
     for nvtype, label in type_to_label:
         with self.subTest(nvset_type=nvtype, label=label):
             dto = CibNvsetDto("my-id", nvtype, {}, None, [])
             output = dedent(f"""\
                   {label}: my-id
                 """)
             self.assert_lines(dto, output)
Esempio n. 6
0
 def test_minimal(self):
     for tag in nvpair_multi.NVSETS_ALL:
         with self.subTest(tag=tag):
             xml = etree.fromstring(f"""<{tag} id="my-id" />""")
             self.assertEqual(
                 nvpair_multi.nvset_element_to_dto(xml,
                                                   get_in_effect_eval()),
                 CibNvsetDto("my-id", {}, None, []),
             )
Esempio n. 7
0
 def test_expired(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"
                         />
                     </rule>
                     <nvpair id="my-id-pair1" name="name1" value="value1" />
                 </{tag}>
             """
             )
             self.assertEqual(
                 nvpair_multi.nvset_element_to_dto(
                     xml,
                     get_in_effect_eval(
                         {"my-id-rule": CibRuleInEffectStatus.EXPIRED}
                     ),
                 ),
                 CibNvsetDto(
                     "my-id",
                     nvtype,
                     {"score": "150"},
                     CibRuleExpressionDto(
                         "my-id-rule",
                         CibRuleExpressionType.RULE,
                         CibRuleInEffectStatus.EXPIRED,
                         {"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",
                             ),
                         ],
                         "resource ocf:pacemaker:Dummy",
                     ),
                     [CibNvpairDto("my-id-pair1", "name1", "value1")],
                 ),
             )
Esempio n. 8
0
def nvset_element_to_dto(nvset_el: _Element) -> CibNvsetDto:
    """
    Export an nvset xml element to its DTO
    """
    rule_el = nvset_el.find("./rule")
    return CibNvsetDto(
        str(nvset_el.get("id", "")),
        _tag_to_type[str(nvset_el.tag)],
        export_attributes(nvset_el, with_id=False),
        None if rule_el is None else rule_element_to_dto(rule_el),
        [
            nvpair_element_to_dto(nvpair_el)
            for nvpair_el in nvset_el.iterfind("./nvpair")
        ],
    )
Esempio n. 9
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="or">
                         <op_expression id="my-id-rule-op" name="monitor" />
                     </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),
                 CibNvsetDto(
                     "my-id",
                     nvtype,
                     {"score": "150"},
                     CibRuleExpressionDto(
                         "my-id-rule",
                         CibRuleExpressionType.RULE,
                         False,
                         {"boolean-op": "or"},
                         None,
                         None,
                         [
                             CibRuleExpressionDto(
                                 "my-id-rule-op",
                                 CibRuleExpressionType.OP_EXPRESSION,
                                 False,
                                 {"name": "monitor"},
                                 None,
                                 None,
                                 [],
                                 "op monitor",
                             ),
                         ],
                         "op monitor",
                     ),
                     [
                         CibNvpairDto("my-id-pair1", "name1", "value1"),
                         CibNvpairDto("my-id-pair2", "name2", "value2"),
                     ],
                 ),
             )
Esempio n. 10
0
 def test_full(self):
     for nvtype, label in type_to_label:
         with self.subTest(nvset_type=nvtype, label=label):
             dto = CibNvsetDto(
                 "my-id",
                 nvtype,
                 {"score": "150"},
                 CibRuleExpressionDto(
                     "my-id-rule",
                     CibRuleExpressionType.RULE,
                     CibRuleInEffectStatus.UNKNOWN,
                     {"boolean-op": "or"},
                     None,
                     None,
                     [
                         CibRuleExpressionDto(
                             "my-id-rule-op",
                             CibRuleExpressionType.OP_EXPRESSION,
                             CibRuleInEffectStatus.UNKNOWN,
                             {"name": "monitor"},
                             None,
                             None,
                             [],
                             "op monitor",
                         ),
                     ],
                     "op monitor",
                 ),
                 [
                     CibNvpairDto("my-id-pair1", "name1", "value1"),
                     CibNvpairDto("my-id-pair2", "name 2", "value 2"),
                     CibNvpairDto("my-id-pair3", "name=3", "value=3"),
                 ],
             )
             output = dedent(f"""\
                 {label}: my-id score=150
                   "name 2"="value 2"
                   name1=value1
                   "name=3"="value=3"
                   Rule: boolean-op=or (id:my-id-rule)
                     Expression: op monitor (id:my-id-rule-op)
                 """)
             self.assert_lines(dto, output)
Esempio n. 11
0
def nvset_element_to_dto(nvset_el: _Element,
                         rule_in_effect_eval: RuleInEffectEval) -> CibNvsetDto:
    """
    Export an nvset xml element to its DTO

    nvset_el -- an nvset element to be exported
    rule_in_effect_eval -- a class for evaluating if a rule is in effect
    """
    rule_dto = None
    rule_el = nvset_el.find("./rule")
    if rule_el is not None:
        rule_dto = rule_element_to_dto(rule_in_effect_eval, rule_el)
    return CibNvsetDto(
        str(nvset_el.get("id", "")),
        export_attributes(nvset_el, with_id=False),
        rule_dto,
        [
            nvpair_element_to_dto(nvpair_el)
            for nvpair_el in nvset_el.iterfind("./nvpair")
        ],
    )
Esempio n. 12
0
class DefaultsConfigMixin(DefaultsBaseMixin):
    dto_list = [
        CibNvsetDto(
            "my-meta_attributes",
            CibNvsetType.META,
            {},
            CibRuleExpressionDto(
                "my-meta-rule",
                CibRuleExpressionType.RULE,
                CibRuleInEffectStatus.EXPIRED,
                {
                    "boolean-op": "and",
                    "score": "INFINITY"
                },
                None,
                None,
                [
                    CibRuleExpressionDto(
                        "my-meta-rule-rsc",
                        CibRuleExpressionType.RSC_EXPRESSION,
                        CibRuleInEffectStatus.UNKNOWN,
                        {
                            "class": "ocf",
                            "provider": "pacemaker",
                            "type": "Dummy",
                        },
                        None,
                        None,
                        [],
                        "resource ocf:pacemaker:Dummy",
                    ),
                ],
                "resource ocf:pacemaker:Dummy",
            ),
            [
                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", "name 1", "value 1")],
        ),
    ]

    def test_no_args(self, mock_print):
        self.lib_command.return_value = []
        self._call_cmd([])
        self.lib_command.assert_called_once_with(True)
        mock_print.assert_called_once_with("No defaults set")

    def test_usage(self, mock_print):
        with self.assertRaises(CmdLineInputError) as cm:
            self._call_cmd(["arg"])
        self.assertIsNone(cm.exception.message)
        self.lib_command.assert_not_called()
        mock_print.assert_not_called()

    def test_full(self, mock_print):
        self.lib_command.return_value = []
        self._call_cmd([], {"full": True})
        self.lib_command.assert_called_once_with(True)
        mock_print.assert_called_once_with("No defaults set")

    def test_no_expire_check(self, mock_print):
        self.lib_command.return_value = []
        self._call_cmd([], {"no-expire-check": True})
        self.lib_command.assert_called_once_with(False)
        mock_print.assert_called_once_with("No defaults set")

    def test_print(self, mock_print):
        self.lib_command.return_value = self.dto_list
        self._call_cmd([], {"all": True})
        self.lib_command.assert_called_once_with(True)
        mock_print.assert_called_once_with(
            dedent('''\
                Meta Attrs (expired): my-meta_attributes
                  name1=value1
                  name2=value2
                  Rule (expired): boolean-op=and score=INFINITY
                    Expression: resource ocf:pacemaker:Dummy
                Attributes: instance
                  inst=ance
                Meta Attrs: meta-plain score=123
                  "name 1"="value 1"'''))

    def test_print_exclude_expired(self, mock_print):
        self.lib_command.return_value = self.dto_list
        self._call_cmd([], {"all": False})
        self.lib_command.assert_called_once_with(True)
        mock_print.assert_called_once_with(
            dedent('''\
                Attributes: instance
                  inst=ance
                Meta Attrs: meta-plain score=123
                  "name 1"="value 1"'''))

    def test_print_full(self, mock_print):
        self.lib_command.return_value = self.dto_list
        self._call_cmd([], {"all": True, "full": True})
        self.lib_command.assert_called_once_with(True)
        mock_print.assert_called_once_with(
            dedent('''\
                Meta Attrs (expired): my-meta_attributes
                  name1=value1
                  name2=value2
                  Rule (expired): boolean-op=and score=INFINITY (id:my-meta-rule)
                    Expression: resource ocf:pacemaker:Dummy (id:my-meta-rule-rsc)
                Attributes: instance
                  inst=ance
                Meta Attrs: meta-plain score=123
                  "name 1"="value 1"'''))
Esempio n. 13
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. 14
0
 def test_minimal(self):
     dto = CibNvsetDto("my-id", {}, None, [])
     output = dedent(f"""\
           {self.label}: my-id
         """)
     self.assert_lines(dto, output)
Esempio n. 15
0
     description=None,
     start_delay=None,
     interval_origin=None,
     timeout=None,
     enabled=None,
     record_pending=None,
     role=None,
     on_fail=None,
     meta_attributes=[],
     instance_attributes=[
         CibNvsetDto(
             id="R7-custom_action-interval-10s-instance_attributes",
             options={},
             rule=None,
             nvpairs=[
                 CibNvpairDto(
                     id="R7-custom_action-interval-10s-instance_attributes-OCF_CHECK_LEVEL",
                     name="OCF_CHECK_LEVEL",
                     value="2",
                 )
             ],
         )
     ],
 ),
 CibResourceOperationDto(
     id="R7-migrate_from-interval-0s",
     name="migrate_from",
     interval="0s",
     description=None,
     start_delay=None,
     interval_origin=None,
     timeout="20s",
Esempio n. 16
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. 17
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>
                 <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.assertEqual(
         [
             CibNvsetDto(
                 f"{self.tag}-meta_attributes",
                 CibNvsetType.META,
                 {},
                 CibRuleExpressionDto(
                     f"{self.tag}-meta_attributes-rule",
                     CibRuleExpressionType.RULE,
                     False,
                     {
                         "boolean-op": "and",
                         "score": "INFINITY"
                     },
                     None,
                     None,
                     [
                         CibRuleExpressionDto(
                             f"{self.tag}-meta_attributes-rule-rsc-Dummy",
                             CibRuleExpressionType.RSC_EXPRESSION,
                             False,
                             {
                                 "class": "ocf",
                                 "provider": "pacemaker",
                                 "type": "Dummy",
                             },
                             None,
                             None,
                             [],
                             "resource ocf:pacemaker:Dummy",
                         ),
                     ],
                     "resource ocf:pacemaker:Dummy",
                 ),
                 [
                     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()),
     )