def load_state(self, name="runner.pcmk.load_state", filename="crm_mon.minimal.xml", resources=None, raw_resources=None): """ Create call for loading pacemaker state. string name -- key of the call string filename -- points to file with the status in the content string resources -- xml - resources section, will be put to state """ if resources and raw_resources is not None: raise AssertionError( "Cannot use 'resources' and 'raw_resources' together") state = etree.fromstring(open(rc(filename)).read()) if raw_resources is not None: resources = fixture_state_resources_xml(**raw_resources) if resources: state.append(complete_state_resources(etree.fromstring(resources))) self.__calls.place( name, RunnerCall( "crm_mon --one-shot --as-xml --inactive", stdout=etree_to_str(state), ))
def test_group_running(self): resources_state = fixture.complete_state_resources( etree.fromstring(""" <resources> <group id="G" number_resources="2"> <resource id="R1" role="Started" nodes_running_on="1"> <node name="node1" id="1" cached="false" /> </resource> <resource id="R2" role="Started" nodes_running_on="1"> <node name="node1" id="1" cached="false" /> </resource> </group> </resources> """)) self.config.runner.pcmk.load_state( resources=etree_to_str(resources_state)) resource.group_add( self.env_assist.get_env(), "G", ["R1", "R2"], wait=self.timeout, ) self.env_assist.assert_reports([ fixture.report_resource_running("G", {"Started": ["node1"]}), ])
def load_state(self, name="runner.pcmk.load_state", filename="crm_mon.minimal.xml", resources=None): """ Create call for loading pacemaker state. string name -- key of the call string filename -- points to file with the status in the content string resources -- xml - resources section, will be put to state """ state = etree.fromstring(open(rc(filename)).read()) if resources: state.append(complete_state_resources(etree.fromstring(resources))) self.__calls.place( name, RunnerCall( "crm_mon --one-shot --as-xml --inactive", stdout=etree_to_str(state), ))
def load_state( self, name="runner.pcmk.load_state", filename="crm_mon.minimal.xml", resources=None, raw_resources=None, nodes=None, stdout="", stderr="", returncode=0 ): """ Create call for loading pacemaker state. string name -- key of the call string filename -- points to file with the status in the content string resources -- xml - resources section, will be put to state string nodes -- iterable of node dicts string stdout -- crm_mon's stdout string stderr -- crm_mon's stderr int returncode -- crm_mon's returncode """ if ( (resources or raw_resources is not None or nodes) and (stdout or stderr or returncode) ): raise AssertionError( "Cannot specify resources or nodes when stdout, stderr or " "returncode is specified" ) if resources and raw_resources is not None: raise AssertionError( "Cannot use 'resources' and 'raw_resources' together" ) if (stdout or stderr or returncode): self.__calls.place( name, RunnerCall( "crm_mon --one-shot --as-xml --inactive", stdout=stdout, stderr=stderr, returncode=returncode ) ) return state = etree.fromstring(open(rc(filename)).read()) if raw_resources is not None: resources = fixture_state_resources_xml(**raw_resources) if resources: state.append(complete_state_resources(etree.fromstring(resources))) if nodes: nodes_element = state.find("./nodes") for node in nodes: nodes_element.append( etree.fromstring(fixture_state_node_xml(**node)) ) # set correct number of nodes and resources into the status resources_count = len(state.xpath(" | ".join([ "./resources/bundle", "./resources/clone", "./resources/group", "./resources/resource", ]))) nodes_count = len(state.findall("./nodes/node")) state.find("./summary/nodes_configured").set("number", str(nodes_count)) state.find("./summary/resources_configured").set( "number", str(resources_count) ) self.__calls.place( name, RunnerCall( "crm_mon --one-shot --as-xml --inactive", stdout=etree_to_str(state), ) )