def test_defined(self): self.assert_cib( NodeAttrExpr(NODE_ATTR_OP_DEFINED, "pingd", None, None), """ <expression attribute="pingd" id="X-expr" operation="defined" /> """, )
def test_lte(self): self.assert_cib( NodeAttrExpr(NODE_ATTR_OP_LTE, "#uname", "node1", None), """ <expression attribute="#uname" id="X-expr" operation="lte" value="node1" /> """, )
def fixture_expr_binary(operator): return BoolExpr( BOOL_AND, [ RscExpr(None, None, "Dummy"), NodeAttrExpr(operator, "name", "10", NODE_ATTR_TYPE_INTEGER), OpExpr("stop", None), ], )
def fixture_expr_unary(operator): return BoolExpr( BOOL_AND, [ RscExpr(None, None, "Dummy"), NodeAttrExpr(operator, "name", None, None), OpExpr("stop", None), ], )
def test_type_version(self): self.assert_cib( NodeAttrExpr(NODE_ATTR_OP_EQ, "#uname", "1.2.3", NODE_ATTR_TYPE_VERSION), """ <expression attribute="#uname" id="X-expr" operation="eq" type="version" value="1.2.3" /> """, )
def test_type_string(self): self.assert_cib( NodeAttrExpr(NODE_ATTR_OP_EQ, "#uname", "node1", NODE_ATTR_TYPE_STRING), """ <expression attribute="#uname" id="X-expr" operation="eq" type="string" value="node1" /> """, )
def test_type_number(self): self.assert_cib( NodeAttrExpr(NODE_ATTR_OP_EQ, "#uname", "12345", NODE_ATTR_TYPE_NUMBER), """ <expression attribute="#uname" id="X-expr" operation="eq" type="number" value="12345" /> """, )
def test_type_integer_old_schema(self): self.assert_cib( NodeAttrExpr(NODE_ATTR_OP_EQ, "#uname", "12345", NODE_ATTR_TYPE_INTEGER), """ <expression attribute="#uname" id="X-expr" operation="eq" type="number" value="12345" /> """, Version(3, 4, 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, ), ], )
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), ], )
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), ], )))
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), ], )))
def test_no_rsc_op(self): self.assertFalse( 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), NodeAttrExpr(NODE_ATTR_OP_EQ, "b", "bb", None), ], ), NodeAttrExpr(NODE_ATTR_OP_EQ, "a", "1", None), NodeAttrExpr(NODE_ATTR_OP_EQ, "b", "2", None), ], )))
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), )
def fixture_expr(type_, value): return BoolExpr(BOOL_AND, [NodeAttrExpr(NODE_ATTR_OP_EQ, "name", value, type_)])