예제 #1
0
 def test_expr_1(self):
     self.assert_cib(
         BoolExpr(
             BOOL_AND,
             [
                 BoolExpr(
                     BOOL_OR,
                     [
                         RscExpr("ocf", "pacemaker", "Dummy"),
                         OpExpr("start", None),
                         RscExpr("systemd", None, "pcsd"),
                         RscExpr("ocf", "heartbeat", "Dummy"),
                     ],
                 ),
                 BoolExpr(
                     BOOL_OR,
                     [
                         OpExpr("monitor", "30s"),
                         RscExpr("ocf", "pacemaker", "Dummy"),
                         OpExpr("start", None),
                         OpExpr("monitor", "2min"),
                     ],
                 ),
             ],
         ),
         """
             <rule id="X-rule" boolean-op="and" score="INFINITY">
               <rule id="X-rule-rule" boolean-op="or" score="0">
                 <rsc_expression id="X-rule-rule-rsc-ocf-pacemaker-Dummy"
                     class="ocf" provider="pacemaker" type="Dummy"
                 />
                 <op_expression id="X-rule-rule-op-start" name="start" />
                 <rsc_expression id="X-rule-rule-rsc-systemd-pcsd"
                     class="systemd" type="pcsd"
                 />
                 <rsc_expression id="X-rule-rule-rsc-ocf-heartbeat-Dummy"
                     class="ocf" provider="heartbeat" type="Dummy"
                 />
               </rule>
               <rule id="X-rule-rule-1" boolean-op="or" score="0">
                 <op_expression id="X-rule-rule-1-op-monitor"
                     name="monitor" interval="30s"
                 />
                 <rsc_expression id="X-rule-rule-1-rsc-ocf-pacemaker-Dummy"
                     class="ocf" provider="pacemaker" type="Dummy"
                 />
                 <op_expression id="X-rule-rule-1-op-start" name="start" />
                 <op_expression id="X-rule-rule-1-op-monitor-1"
                     name="monitor" interval="2min"
                 />
               </rule>
             </rule>
         """,
     )
예제 #2
0
 def test_rule(self):
     context_element = etree.fromstring("""<context id="a" />""")
     id_provider = IdProvider(context_element)
     nvpair_multi.nvset_append_new(
         context_element,
         id_provider,
         nvpair_multi.NVSET_META,
         {},
         {},
         nvset_rule=BoolExpr(
             BOOL_AND,
             [RscExpr("ocf", "pacemaker", "Dummy"),
              OpExpr("start", None)],
         ),
     )
     assert_xml_equal(
         """
             <context id="a">
                 <meta_attributes id="a-meta_attributes">
                     <rule id="a-meta_attributes-rule"
                         boolean-op="and" score="INFINITY"
                     >
                         <rsc_expression
                             id="a-meta_attributes-rule-rsc-ocf-pacemaker-Dummy"
                             class="ocf" provider="pacemaker" type="Dummy"
                         />
                         <op_expression id="a-meta_attributes-rule-op-start" 
                             name="start"
                         />
                     </rule>
                 </meta_attributes>
             </context>
         """,
         etree_to_str(context_element),
     )
예제 #3
0
 def type(self):
     self.assert_cib(
         RscExpr(None, None, "Dummy"),
         """
             <rsc_expression id="X-rsc-Dummy" type="Dummy" />
         """,
     )
예제 #4
0
 def test_class(self):
     self.assert_cib(
         RscExpr("ocf", None, None),
         """
             <rsc_expression id="X-rsc-ocf" class="ocf" />
         """,
     )
예제 #5
0
 def test_provider(self):
     self.assert_cib(
         RscExpr(None, "pacemaker", None),
         """
             <rsc_expression id="X-rsc-pacemaker" provider="pacemaker" />
         """,
     )
예제 #6
0
 def setUp(self):
     self.report_op = fixture.error(
         reports.codes.RULE_EXPRESSION_NOT_ALLOWED,
         expression_type=CibRuleExpressionType.OP_EXPRESSION,
     )
     self.report_rsc = fixture.error(
         reports.codes.RULE_EXPRESSION_NOT_ALLOWED,
         expression_type=CibRuleExpressionType.RSC_EXPRESSION,
     )
     self.rule_rsc = BoolExpr(
         BOOL_OR, [RscExpr(None, None, "a"),
                   RscExpr(None, None, "b")])
     self.rule_op = BoolExpr(BOOL_OR,
                             [OpExpr("start", None),
                              OpExpr("stop", None)])
     self.rule = BoolExpr(BOOL_AND, [self.rule_rsc, self.rule_op])
예제 #7
0
 def test_class_type(self):
     self.assert_cib(
         RscExpr("systemd", None, "pcsd"),
         """
             <rsc_expression id="X-rsc-systemd-pcsd"
                 class="systemd" type="pcsd"
             />
         """,
     )
예제 #8
0
 def test_class_provider(self):
     self.assert_cib(
         RscExpr("ocf", "pacemaker", None),
         """
             <rsc_expression id="X-rsc-ocf-pacemaker"
                 class="ocf" provider="pacemaker"
             />
         """,
     )
예제 #9
0
 def test_provider_type(self):
     self.assert_cib(
         RscExpr(None, "pacemaker", "Dummy"),
         """
             <rsc_expression id="X-rsc-pacemaker-Dummy"
                 provider="pacemaker" type="Dummy"
             />
         """,
     )
예제 #10
0
 def test_class_provider_type(self):
     self.assert_cib(
         RscExpr("ocf", "pacemaker", "Dummy"),
         """
             <rsc_expression id="X-rsc-ocf-pacemaker-Dummy"
                 class="ocf" provider="pacemaker" type="Dummy"
             />
         """,
     )
예제 #11
0
 def fixture_expr_unary(operator):
     return BoolExpr(
         BOOL_AND,
         [
             RscExpr(None, None, "Dummy"),
             NodeAttrExpr(operator, "name", None, None),
             OpExpr("stop", None),
         ],
     )
예제 #12
0
 def fixture_expr_binary(operator):
     return BoolExpr(
         BOOL_AND,
         [
             RscExpr(None, None, "Dummy"),
             NodeAttrExpr(operator, "name", "10", NODE_ATTR_TYPE_INTEGER),
             OpExpr("stop", None),
         ],
     )
예제 #13
0
 def test_no_node_attr(self):
     self.assertFalse(
         tools.has_node_attr_expr_with_type_integer(
             BoolExpr(
                 BOOL_OR,
                 [
                     RscExpr("ocf", "pacemaker", "Dummy"),
                     OpExpr("stop", None),
                 ],
             )))
예제 #14
0
 def test_propagate_errors_from_subexpressions(self):
     # pylint: disable=no-self-use
     assert_report_item_list_equal(
         Validator(
             BoolExpr(
                 BOOL_OR,
                 [
                     BoolExpr(
                         BOOL_AND,
                         [
                             RscExpr(None, None, "Dummy"),
                             OpExpr("stop", None),
                         ],
                     ),
                     BoolExpr(
                         BOOL_AND,
                         [
                             DateUnaryExpr(DATE_OP_GT, "a date"),
                             NodeAttrExpr(
                                 NODE_ATTR_OP_EQ,
                                 "attr",
                                 "10",
                                 NODE_ATTR_TYPE_INTEGER,
                             ),
                         ],
                     ),
                 ],
             ),
         ).get_reports(),
         [
             fixture.error(
                 reports.codes.INVALID_OPTION_VALUE,
                 option_name="date",
                 option_value="a date",
                 allowed_values="ISO 8601 date",
                 cannot_be_empty=False,
                 forbidden_characters=None,
             ),
             fixture.error(
                 reports.codes.RULE_EXPRESSION_NOT_ALLOWED,
                 expression_type=CibRuleExpressionType.OP_EXPRESSION,
             ),
             fixture.error(
                 reports.codes.RULE_EXPRESSION_NOT_ALLOWED,
                 expression_type=CibRuleExpressionType.RSC_EXPRESSION,
             ),
             fixture.error(
                 reports.codes.RULE_EXPRESSION_NOT_ALLOWED,
                 expression_type=CibRuleExpressionType.EXPRESSION,
             ),
         ],
     )
예제 #15
0
 def test_everything(self):
     context_element = etree.fromstring("""<context id="a" />""")
     id_provider = IdProvider(context_element)
     nvpair_multi.nvset_append_new(
         context_element,
         id_provider,
         Version(3, 5, 0),
         nvpair_multi.NVSET_META,
         {
             "attr1": "value1",
             "attr-empty": "",
             "attr2": "value2"
         },
         {
             "id": "custom-id",
             "score": "INFINITY",
             "empty-attr": ""
         },
         nvset_rule=BoolExpr(
             BOOL_AND,
             [RscExpr("ocf", "pacemaker", "Dummy"),
              OpExpr("start", None)],
         ),
     )
     assert_xml_equal(
         """
             <context id="a">
                 <meta_attributes id="custom-id" score="INFINITY">
                     <rule id="custom-id-rule"
                         boolean-op="and" score="INFINITY"
                     >
                         <rsc_expression id="custom-id-rule-rsc-ocf-pacemaker-Dummy"
                             class="ocf" provider="pacemaker" type="Dummy"
                         />
                         <op_expression id="custom-id-rule-op-start" 
                             name="start"
                         />
                     </rule>
                     <nvpair id="custom-id-attr1"
                         name="attr1" value="value1"
                     />
                     <nvpair id="custom-id-attr2"
                         name="attr2" value="value2"
                     />
                 </meta_attributes>
             </context>
         """,
         etree_to_str(context_element),
     )
예제 #16
0
 def fixture_rule(attr_type):
     return BoolExpr(
         BOOL_OR,
         [
             BoolExpr(
                 BOOL_AND,
                 [
                     NodeAttrExpr(NODE_ATTR_OP_EQ, "a", "A", None),
                     NodeAttrExpr(NODE_ATTR_OP_EQ, "b", "B", attr_type),
                 ],
             ),
             BoolExpr(
                 BOOL_AND,
                 [
                     NodeAttrExpr(NODE_ATTR_OP_EQ, "a", "aa", None),
                     RscExpr("ocf", "pacemaker", "Dummy"),
                 ],
             ),
             NodeAttrExpr(NODE_ATTR_OP_EQ, "a", "1", None),
             OpExpr("stop", None),
         ],
     )
예제 #17
0
 def test_rsc_present(self):
     self.assertTrue(
         tools.has_rsc_or_op_expression(
             BoolExpr(
                 BOOL_OR,
                 [
                     BoolExpr(
                         BOOL_AND,
                         [
                             NodeAttrExpr(NODE_ATTR_OP_EQ, "a", "A", None),
                             NodeAttrExpr(NODE_ATTR_OP_EQ, "b", "B", None),
                         ],
                     ),
                     BoolExpr(
                         BOOL_AND,
                         [
                             NodeAttrExpr(NODE_ATTR_OP_EQ, "a", "aa", None),
                             RscExpr("ocf", "pacemaker", "Dummy"),
                         ],
                     ),
                     NodeAttrExpr(NODE_ATTR_OP_EQ, "a", "1", None),
                     NodeAttrExpr(NODE_ATTR_OP_EQ, "b", "2", None),
                 ],
             )))
예제 #18
0
 def test_two_children(self):
     operators = [
         (BOOL_OR, "or"),
         (BOOL_AND, "and"),
     ]
     for op_in, op_out in operators:
         with self.subTest(op_in=op_in, op_out=op_out):
             self.assert_cib(
                 BoolExpr(
                     op_in,
                     [
                         OpExpr("start", None),
                         RscExpr("systemd", None, "pcsd"),
                     ],
                 ),
                 f"""
                     <rule id="X-rule" boolean-op="{op_out}" score="INFINITY">
                         <op_expression id="X-rule-op-start" name="start" />
                         <rsc_expression id="X-rule-rsc-systemd-pcsd"
                             class="systemd" type="pcsd"
                         />
                     </rule>
                 """,
             )
예제 #19
0
 def test_rule(self):
     context_element = etree.fromstring("""<context id="a" />""")
     id_provider = IdProvider(context_element)
     nvpair_multi.nvset_append_new(
         context_element,
         id_provider,
         Version(3, 5, 0),
         nvpair_multi.NVSET_META,
         {},
         {},
         nvset_rule=BoolExpr(
             BOOL_AND,
             [
                 RscExpr("ocf", "pacemaker", "Dummy"),
                 OpExpr("start", None),
                 BoolExpr(
                     BOOL_OR,
                     [
                         NodeAttrExpr(
                             NODE_ATTR_OP_DEFINED, "attr1", None, None
                         ),
                         NodeAttrExpr(
                             NODE_ATTR_OP_GT,
                             "attr2",
                             "5",
                             NODE_ATTR_TYPE_NUMBER,
                         ),
                     ],
                 ),
             ],
         ),
     )
     assert_xml_equal(
         """
             <context id="a">
                 <meta_attributes id="a-meta_attributes">
                     <rule id="a-meta_attributes-rule"
                         boolean-op="and" score="INFINITY"
                     >
                         <rsc_expression
                             id="a-meta_attributes-rule-rsc-ocf-pacemaker-Dummy"
                             class="ocf" provider="pacemaker" type="Dummy"
                         />
                         <op_expression id="a-meta_attributes-rule-op-start" 
                             name="start"
                         />
                         <rule id="a-meta_attributes-rule-rule"
                             boolean-op="or" score="0"
                         >
                             <expression id="a-meta_attributes-rule-rule-expr"
                                 operation="defined" attribute="attr1"
                             />
                             <expression id="a-meta_attributes-rule-rule-expr-1"
                                 attribute="attr2" operation="gt"
                                 type="number" value="5"
                             />
                         </rule>
                     </rule>
                 </meta_attributes>
             </context>
         """,
         etree_to_str(context_element),
     )
예제 #20
0
 def test_rsc_on_top(self):
     self.assertTrue(
         tools.has_rsc_or_op_expression(RscExpr("ocf", "pacemaker",
                                                "Dummy")))