Exemplo n.º 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>
         """,
     )
Exemplo n.º 2
0
 def test_minimal(self):
     self.assert_cib(
         OpExpr("start", None),
         """
             <op_expression id="X-op-start" name="start" />
         """,
     )
Exemplo n.º 3
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])
Exemplo n.º 4
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),
     )
Exemplo n.º 5
0
 def test_one_child(self):
     self.assert_cib(
         BoolExpr(BOOL_AND, [OpExpr("start", None)]),
         """
             <rule id="X-rule" boolean-op="and" score="INFINITY">
                 <op_expression id="X-rule-op-start" name="start" />
             </rule>
         """,
     )
Exemplo n.º 6
0
 def test_interval(self):
     self.assert_cib(
         OpExpr("monitor", "2min"),
         """
             <op_expression id="X-op-monitor" name="monitor"
                 interval="2min"
             />
         """,
     )
Exemplo n.º 7
0
 def fixture_expr_unary(operator):
     return BoolExpr(
         BOOL_AND,
         [
             RscExpr(None, None, "Dummy"),
             NodeAttrExpr(operator, "name", None, None),
             OpExpr("stop", None),
         ],
     )
Exemplo n.º 8
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),
         ],
     )
Exemplo n.º 9
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),
                 ],
             )))
Exemplo n.º 10
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,
             ),
         ],
     )
Exemplo n.º 11
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),
     )
Exemplo n.º 12
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),
         ],
     )
Exemplo n.º 13
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>
                 """,
             )
Exemplo n.º 14
0
 def test_op_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,
                         [
                             OpExpr("stop", None),
                             NodeAttrExpr(NODE_ATTR_OP_EQ, "b", "bb", None),
                         ],
                     ),
                     NodeAttrExpr(NODE_ATTR_OP_EQ, "a", "1", None),
                     NodeAttrExpr(NODE_ATTR_OP_EQ, "b", "2", None),
                 ],
             )))
Exemplo n.º 15
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),
     )
Exemplo n.º 16
0
 def test_op_on_top(self):
     self.assertTrue(tools.has_rsc_or_op_expression(OpExpr("stop", None)))