Use XML to get node list
The current list_nodes command tries to parse the output of "crm node list" to get a list of nodes. But the output is messy if remote nodes are present so use "crm node status" to get properly formatted XML which can be reliably parsed. Change-Id: Iea7ef3dca194e7440dc2cde2624d07e990006685
This commit is contained in:
parent
f3873fe67f
commit
6e3cec799f
|
@ -103,14 +103,12 @@ def crm_res_running(opt_name):
|
||||||
|
|
||||||
|
|
||||||
def list_nodes():
|
def list_nodes():
|
||||||
cmd = ['crm', 'node', 'list']
|
"""List member nodes."""
|
||||||
|
cmd = ['crm', 'node', 'status']
|
||||||
out = subprocess.check_output(cmd).decode('utf-8')
|
out = subprocess.check_output(cmd).decode('utf-8')
|
||||||
nodes = []
|
tree = etree.fromstring(out)
|
||||||
for line in str(out).split('\n'):
|
nodes = [n.attrib['uname'] for n in tree.iter('node')]
|
||||||
if line != '':
|
return sorted(nodes)
|
||||||
nodes.append(line.split(':')[0])
|
|
||||||
|
|
||||||
return nodes
|
|
||||||
|
|
||||||
|
|
||||||
def _maas_ipmi_stonith_resource(node, power_params):
|
def _maas_ipmi_stonith_resource(node, power_params):
|
||||||
|
|
|
@ -74,6 +74,14 @@ CRM_CONFIGURE_SHOW_XML_MAINT_MODE_TRUE = '''<?xml version="1.0" ?>
|
||||||
|
|
||||||
''' # noqa
|
''' # noqa
|
||||||
|
|
||||||
|
CRM_NODE_STATUS_XML = b'''
|
||||||
|
<nodes>
|
||||||
|
<node id="1000" uname="juju-982848-zaza-ce47c58f6c88-10"/>
|
||||||
|
<node id="1001" uname="juju-982848-zaza-ce47c58f6c88-9"/>
|
||||||
|
<node id="1002" uname="juju-982848-zaza-ce47c58f6c88-11"/>
|
||||||
|
</nodes>
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
class TestPcmk(unittest.TestCase):
|
class TestPcmk(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -226,3 +234,13 @@ class TestPcmk(unittest.TestCase):
|
||||||
r = pcmk.resource_checksum('res_test', 'IPaddr2',
|
r = pcmk.resource_checksum('res_test', 'IPaddr2',
|
||||||
'params ip=1.2.3.4 cidr_netmask=255.0.0.0')
|
'params ip=1.2.3.4 cidr_netmask=255.0.0.0')
|
||||||
self.assertEqual(r, 'ef395293b1b7c29c5bf1c99774f75cf4')
|
self.assertEqual(r, 'ef395293b1b7c29c5bf1c99774f75cf4')
|
||||||
|
|
||||||
|
@mock.patch('subprocess.check_output', return_value=CRM_NODE_STATUS_XML)
|
||||||
|
def test_list_nodes(self, mock_check_output):
|
||||||
|
self.assertSequenceEqual(
|
||||||
|
pcmk.list_nodes(),
|
||||||
|
[
|
||||||
|
'juju-982848-zaza-ce47c58f6c88-10',
|
||||||
|
'juju-982848-zaza-ce47c58f6c88-11',
|
||||||
|
'juju-982848-zaza-ce47c58f6c88-9'])
|
||||||
|
mock_check_output.assert_called_once_with(['crm', 'node', 'status'])
|
||||||
|
|
Loading…
Reference in New Issue