def setUp(self): # pylint: disable=invalid-name self.temp_cib = get_tmp_file("tier1_cib_resource_group_ungroup") self.pcs_runner = PcsRunner(self.temp_cib.name) xml_manip = XmlManipulation.from_file(self.empty_cib) xml_manip.append_to_first_tag_name( "resources", FIXTURE_CLONE, FIXTURE_DUMMY, ) xml_manip.append_to_first_tag_name( "configuration", FIXTURE_TAGS_CONFIG_XML, ) xml_manip.append_to_first_tag_name( "constraints", """ <rsc_location id="location-C-clone-rh7-1-INFINITY" node="rh7-1" rsc="C-clone" score="INFINITY"/> """, """ <rsc_location id="location-TagCloneOnly-rh7-1-INFINITY" node="rh7-1" rsc="TagCloneOnly" score="INFINITY"/> """, ) write_data_to_tmpfile(str(xml_manip), self.temp_cib)
def test_error(self): xml = "<xml/>" expected_stdout = "expected output" expected_stderr = "expected stderr" expected_retval = 1 mock_runner = get_runner( expected_stdout, expected_stderr, expected_retval ) assert_raise_library_error( lambda: lib.replace_cib_configuration( mock_runner, XmlManipulation.from_str(xml).tree ) , ( Severity.ERROR, report_codes.CIB_PUSH_ERROR, { "reason": expected_stderr, "pushed_cib": expected_stdout, } ) ) mock_runner.run.assert_called_once_with( [ self.path("cibadmin"), "--replace", "--verbose", "--xml-pipe", "--scope", "configuration" ], stdin_string=xml )
def test_success_rules_rsc_op(self): xml = """ <op_defaults> <meta_attributes id="X"> <rule id="X-rule" boolean-op="and" score="INFINITY"> <rsc_expression id="X-rule-rsc-Dummy" type="Dummy"/> <op_expression id="X-rule-op-monitor" name="monitor"/> </rule> <nvpair id="X-nam1" name="nam1" value="val1"/> </meta_attributes> </op_defaults> """ xml_manip = XmlManipulation.from_file(empty_cib_rules) xml_manip.append_to_first_tag_name("configuration", xml) write_data_to_tmpfile(str(xml_manip), self.temp_cib) self.assert_pcs_success( self.cli_command, stdout_full=dedent("""\ Meta Attrs: X nam1=val1 Rule: boolean-op=and score=INFINITY Expression: resource ::Dummy Expression: op monitor """), )
def setUp(self): # pylint: disable=invalid-name self.temp_cib = get_tmp_file("tier1_cib_resource_group_ungroup") self.pcs_runner = PcsRunner(self.temp_cib.name) xml_manip = XmlManipulation.from_file(self.empty_cib) xml_manip.append_to_first_tag_name("resources", FIXTURE_AGROUP_XML) xml_manip.append_to_first_tag_name( "configuration", """ <tags> <tag id="T1"> <obj_ref id="AGroup"/> </tag> <tag id="T2"> <obj_ref id="AGroup"/> </tag> </tags> """, ) xml_manip.append_to_first_tag_name( "constraints", """ <rsc_location id="location-AGroup-rh7-1-INFINITY" node="rh7-1" rsc="AGroup" score="INFINITY"/> """, """ <rsc_location id="location-T1-rh7-1-INFINITY" node="rh7-1" rsc="T1" score="INFINITY"/> """, ) write_data_to_tmpfile(str(xml_manip), self.temp_cib)
def setUp(self): self.env_assist, self.config = get_env_tools(self) self.config.env.set_known_hosts_dests(KNOWN_HOSTS_DESTS) cib_xml_man = XmlManipulation.from_file(rc("cib-empty.xml")) cib_xml_man.append_to_first_tag_name( "resources", """ <primitive class="ocf" id="{0}" provider="heartbeat" type="VirtualDomain" /> """.format(VIRTUAL_MACHINE_ID)) self.config.env.set_cib_data(str(cib_xml_man))
def setUp(self): self.env_assist, self.config = get_env_tools(self) self.config.env.set_known_hosts_dests(KNOWN_HOSTS_DESTS) cib_xml_man = XmlManipulation.from_file(rc("cib-empty.xml")) cib_xml_man.append_to_first_tag_name( "resources", """ <primitive class="ocf" id="{0}" provider="heartbeat" type="VirtualDomain" /> """.format(VIRTUAL_MACHINE_ID) ) self.config.env.set_cib_data(str(cib_xml_man))
def setUp(self): # pylint: disable=invalid-name self.temp_cib = get_tmp_file("tier1_cib_resource_move") self.pcs_runner = PcsRunner(self.temp_cib.name) xml_manip = XmlManipulation.from_file(self.empty_cib) xml_manip.append_to_first_tag_name("resources", fixture_primitive) xml_manip.append_to_first_tag_name( "constraints", *fixture_constraints, ) xml_manip.append_to_first_tag_name( "nodes", *fixture_nodes, ) write_data_to_tmpfile(str(xml_manip), self.temp_cib)
def test_success(self): xml = "<xml/>" expected_stdout = "expected output" expected_stderr = "" expected_retval = 0 mock_runner = get_runner(expected_stdout, expected_stderr, expected_retval) lib.replace_cib_configuration(mock_runner, XmlManipulation.from_str(xml).tree) mock_runner.run.assert_called_once_with([ self.path("cibadmin"), "--replace", "--verbose", "--xml-pipe", "--scope", "configuration" ], stdin_string=xml)
def test_success_rule_expired(self): xml_rsc = self.xml_expired_template.format(tag="rsc") xml_op = self.xml_expired_template.format(tag="op") xml_manip = XmlManipulation.from_file(empty_cib) xml_manip.append_to_first_tag_name("configuration", xml_rsc, xml_op) write_data_to_tmpfile(str(xml_manip), self.temp_cib) self.assert_pcs_success( self.cli_command, stdout_full=dedent(f"""\ Meta Attrs (not yet in effect): {self.prefix}-set1 name1=value1 Rule (not yet in effect): boolean-op=and score=INFINITY Expression: date gt 3000-01-01 Meta Attrs: {self.prefix}-set3 name3=value3 Rule: boolean-op=and score=INFINITY Expression: date in_range 1000-01-01 to 3000-01-01 """), )
def setUp(self): super().setUp() xml_rsc = """ <rsc_defaults> <meta_attributes id="rsc-set1" /> <meta_attributes id="rsc-set2" /> <meta_attributes id="rsc-set3" /> <meta_attributes id="rsc-set4" /> </rsc_defaults> """ xml_op = """ <op_defaults> <meta_attributes id="op-set1" /> <meta_attributes id="op-set2" /> <meta_attributes id="op-set3" /> <meta_attributes id="op-set4" /> </op_defaults> """ xml_manip = XmlManipulation.from_file(empty_cib) xml_manip.append_to_first_tag_name("configuration", xml_rsc, xml_op) write_data_to_tmpfile(str(xml_manip), self.temp_cib)
def test_success(self): xml = f""" <{self.cib_tag}> <meta_attributes id="my-set"> <nvpair id="my-set-name1" name="name1" value="value1" /> <nvpair id="my-set-name2" name="name2" value="value2" /> <nvpair id="my-set-name3" name="name3" value="value3" /> </meta_attributes> </{self.cib_tag}> """ xml_manip = XmlManipulation.from_file(empty_cib) xml_manip.append_to_first_tag_name("configuration", xml) write_data_to_tmpfile(str(xml_manip), self.temp_cib) warnings = ( "Warning: Defaults do not apply to resources which override " "them with their own defined values\n") self.assert_effect( self.cli_command + "set update my-set meta name2=value2A name3=".split(), dedent(f"""\ <{self.cib_tag}> <meta_attributes id="my-set"> <nvpair id="my-set-name1" name="name1" value="value1" /> <nvpair id="my-set-name2" name="name2" value="value2A" /> </meta_attributes> </{self.cib_tag}> """), output=warnings, ) self.assert_effect( self.cli_command + "set update my-set meta name1= name2=".split(), dedent(f"""\ <{self.cib_tag}> <meta_attributes id="my-set" /> </{self.cib_tag}> """), output=warnings, )
def test_success(self): xml_rsc = """ <rsc_defaults> <meta_attributes id="rsc-set1" score="10"> <nvpair id="rsc-set1-nv1" name="name1" value="rsc1"/> <nvpair id="rsc-set1-nv2" name="name2" value="rsc2"/> </meta_attributes> <meta_attributes id="rsc-setA"> <nvpair id="rsc-setA-nv1" name="name1" value="rscA"/> <nvpair id="rsc-setA-nv2" name="name2" value="rscB"/> </meta_attributes> </rsc_defaults> """ xml_op = """ <op_defaults> <meta_attributes id="op-set1" score="10"> <nvpair id="op-set1-nv1" name="name1" value="op1"/> <nvpair id="op-set1-nv2" name="name2" value="op2"/> </meta_attributes> <meta_attributes id="op-setA"> <nvpair id="op-setA-nv1" name="name1" value="opA"/> <nvpair id="op-setA-nv2" name="name2" value="opB"/> </meta_attributes> </op_defaults> """ xml_manip = XmlManipulation.from_file(empty_cib) xml_manip.append_to_first_tag_name("configuration", xml_rsc, xml_op) write_data_to_tmpfile(str(xml_manip), self.temp_cib) self.assert_pcs_success( self.cli_command, stdout_full=dedent(f"""\ Meta Attrs: {self.prefix}-set1 score=10 name1={self.prefix}1 name2={self.prefix}2 Meta Attrs: {self.prefix}-setA name1={self.prefix}A name2={self.prefix}B """), )
def test_success(self): xml = "<xml/>" expected_stdout = "expected output" expected_stderr = "" expected_retval = 0 mock_runner = get_runner( expected_stdout, expected_stderr, expected_retval ) lib.replace_cib_configuration( mock_runner, XmlManipulation.from_str(xml).tree ) mock_runner.run.assert_called_once_with( [ self.path("cibadmin"), "--replace", "--verbose", "--xml-pipe", "--scope", "configuration" ], stdin_string=xml )
def test_success_rule(self): xml_template = """<{tag}_defaults> <meta_attributes id="{tag}-set1"> <rule id="{tag}-set1-rule" boolean-op="and" score="INFINITY"> <rule id="{tag}-set1-rule-rule" boolean-op="or" score="0"> <expression id="{tag}-set1-rule-rule-expr" operation="defined" attribute="attr1" /> <expression id="{tag}-set1-rule-rule-expr-1" attribute="attr2" operation="gte" type="number" value="12" /> <expression id="{tag}-set1-rule-rule-expr-2" attribute="attr3" operation="lt" type="version" value="3.2.1" /> <expression id="{tag}-set1-rule-rule-expr-3" attribute="attr4" operation="ne" type="string" value="test" /> <expression id="{tag}-set1-rule-rule-expr-4" attribute="attr5" operation="lt" value="3" /> </rule> <rule id="{tag}-set1-rule-rule-1" boolean-op="or" score="0"> <date_expression id="{tag}-set1-rule-rule-1-expr" operation="gt" start="2018-05-17T13:28:19" /> <date_expression id="{tag}-set1-rule-rule-1-expr-1" operation="in_range" start="2019-01-01" end="2019-03-15" /> <date_expression id="{tag}-set1-rule-rule-1-expr-2" operation="in_range" start="2019-05-01" > <duration id="{tag}-set1-rule-rule-1-expr-2-duration" months="2" /> </date_expression> <date_expression id="{tag}-set1-rule-rule-1-expr-3" operation="date_spec" > <date_spec id="{tag}-set1-rule-rule-1-expr-3-datespec" months="7-8" weekdays="6-7" years="2019" /> </date_expression> <date_expression id="{tag}-set1-rule-rule-1-expr-4" operation="in_range" end="2019-12-15" /> </rule> </rule> <nvpair id="{tag}-set1-nam1" name="nam1" value="val1"/> <nvpair id="{tag}-set1-nam2" name="nam2" value="val2"/> </meta_attributes> </{tag}_defaults>""" xml_rsc = xml_template.format(tag="rsc") xml_op = xml_template.format(tag="op") xml_manip = XmlManipulation.from_file(empty_cib) xml_manip.append_to_first_tag_name("configuration", xml_rsc, xml_op) write_data_to_tmpfile(str(xml_manip), self.temp_cib) self.assert_pcs_success( self.cli_command, stdout_full=dedent(f"""\ Meta Attrs: {self.prefix}-set1 nam1=val1 nam2=val2 Rule: boolean-op=and score=INFINITY Rule: boolean-op=or score=0 Expression: defined attr1 Expression: attr2 gte number 12 Expression: attr3 lt version 3.2.1 Expression: attr4 ne string test Expression: attr5 lt 3 Rule: boolean-op=or score=0 Expression: date gt 2018-05-17T13:28:19 Expression: date in_range 2019-01-01 to 2019-03-15 Expression: date in_range 2019-05-01 to duration Duration: months=2 Expression: Date Spec: months=7-8 weekdays=6-7 years=2019 Expression: date in_range to 2019-12-15 """), )
def fixture_status_xml(self, nodes, resources): xml_man = XmlManipulation.from_file(rc("crm_mon.minimal.xml")) doc = xml_man.tree.getroottree() doc.find("/summary/nodes_configured").set("number", str(nodes)) doc.find("/summary/resources_configured").set("number", str(resources)) return str(XmlManipulation(doc))
def test_success(self): xml = "<xml />" assert_xml_equal(xml, str(XmlManipulation((lib.get_cib(xml)))))
def set_cib_file(self, *xml_string_list): xml_manip = XmlManipulation.from_file(self.empty_cib) xml_manip.append_to_first_tag_name("resources", *xml_string_list) write_data_to_tmpfile(str(xml_manip), self.temp_cib)