Merge "Use XML to get node list"

This commit is contained in:
Zuul 2019-04-03 14:18:40 +00:00 committed by Gerrit Code Review
commit 55548abffb
2 changed files with 23 additions and 7 deletions

View File

@ -103,14 +103,12 @@ def crm_res_running(opt_name):
def list_nodes():
cmd = ['crm', 'node', 'list']
"""List member nodes."""
cmd = ['crm', 'node', 'status']
out = subprocess.check_output(cmd).decode('utf-8')
nodes = []
for line in str(out).split('\n'):
if line != '':
nodes.append(line.split(':')[0])
return nodes
tree = etree.fromstring(out)
nodes = [n.attrib['uname'] for n in tree.iter('node')]
return sorted(nodes)
def _maas_ipmi_stonith_resource(node, power_params):

View File

@ -74,6 +74,14 @@ CRM_CONFIGURE_SHOW_XML_MAINT_MODE_TRUE = '''<?xml version="1.0" ?>
''' # 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):
def setUp(self):
@ -226,3 +234,13 @@ class TestPcmk(unittest.TestCase):
r = pcmk.resource_checksum('res_test', 'IPaddr2',
'params ip=1.2.3.4 cidr_netmask=255.0.0.0')
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'])