def test_resources_count(self): with open(rc("crm_mon.minimal.xml")) as crm_mon_file: crm_mon_xml = crm_mon_file.read() self.assertEqual( 0, ClusterState( complete_state(crm_mon_xml)).summary.resources.attrs.count, )
def load_state( self, name="runner.pcmk.load_state", filename="crm_mon.minimal.xml", resources=None, nodes=None, stdout="", stderr="", returncode=0, env=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 string nodes -- xml - nodes section, will be put to state string stdout -- crm_mon's stdout string stderr -- crm_mon's stderr int returncode -- crm_mon's returncode dict env -- CommandRunner environment variables """ if (resources or nodes) and (stdout or stderr or returncode): raise AssertionError( "Cannot specify resources or nodes when stdout, stderr or " "returncode is specified" ) command = ["crm_mon", "--one-shot", "--inactive", "--output-as", "xml"] if stdout or stderr or returncode: self.__calls.place( name, RunnerCall( command, stdout=stdout, stderr=stderr, returncode=returncode, env=env, ), ) return with open(rc(filename)) as a_file: state_xml = a_file.read() self.__calls.place( name, RunnerCall( command, stdout=etree_to_str( complete_state(state_xml, resources, nodes) ), env=env, ), )
def get_status(self): with open(rc("crm_mon.minimal.xml")) as crm_mon_file: crm_mon_xml = crm_mon_file.read() return ClusterState( fixture_crm_mon.complete_state( crm_mon_xml, nodes_xml=""" <nodes> <node name="nodeA" id="1" is_dc="true" /> <node name="nodeB" id="2" /> </nodes> """, )).node_section.nodes
def test_can_get_node_names(self): with open(rc("crm_mon.minimal.xml")) as crm_mon_file: crm_mon_xml = crm_mon_file.read() state_dom = complete_state( crm_mon_xml, nodes_xml=""" <nodes> <node name="node1" id="1" /> <node name="node2" id="2" /> </nodes> """, ) self.assertEqual( ["node1", "node2"], [ node.attrs.name for node in ClusterState(state_dom).node_section.nodes ], )