Merge pull request #30987 from youngnick/add-back-localhost-peer-handling

Changed glusterfs.peer() module so state can handle localhost peering attempts.
This commit is contained in:
Mike Place 2016-02-09 10:51:58 -07:00
commit c3f115724a
4 changed files with 71 additions and 7 deletions

View file

@ -159,7 +159,12 @@ def peer(name):
'Invalid characters in peer name "{0}"'.format(name))
cmd = 'peer probe {0}'.format(name)
return _gluster_xml(cmd).find('opRet').text == '0'
op_result = {
"exitval": _gluster_xml(cmd).find('opRet').text,
"output": _gluster_xml(cmd).find('output').text
}
return op_result
def create(name, bricks, stripe=False, replica=False, device_vg=False,

View file

@ -65,7 +65,10 @@ def peered(name):
ret['result'] = False
return ret
ret['comment'] = __salt__['glusterfs.peer'](name)
if 'output' in __salt__['glusterfs.peer'](name):
ret['comment'] = __salt__['glusterfs.peer'](name)['output']
else:
ret['comment'] = ''
newpeers = __salt__['glusterfs.list_peers']()
#if newpeers was null, we know something didn't work.

View file

@ -147,6 +147,45 @@ xml_volume_info_stopped = """
</cliOutput>
"""
xml_peer_probe_success = """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cliOutput>
<opRet>0</opRet>
<opErrno>0</opErrno>
<opErrstr/>
<output/>
</cliOutput>
"""
xml_peer_probe_fail_already_member = """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cliOutput>
<opRet>0</opRet>
<opErrno>2</opErrno>
<opErrstr/>
<output>Host salt port 24007 already in peer list</output>
</cliOutput>
"""
xml_peer_probe_fail_localhost = """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cliOutput>
<opRet>0</opRet>
<opErrno>1</opErrno>
<opErrstr/>
<output>Probe on localhost not needed</output>
</cliOutput>
"""
xml_peer_probe_fail_cant_connect = """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cliOutput>
<opRet>-1</opRet>
<opErrno>107</opErrno>
<opErrstr>Probe returned with Transport endpoint is not connected</opErrstr>
</cliOutput>
"""
xml_command_success = """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cliOutput>
@ -190,9 +229,26 @@ class GlusterfsTestCase(TestCase):
'''
Test if it adds another node into the peer list.
'''
mock = MagicMock(return_value=xml_command_success)
# Peers can be added successfully, already present, be the localhost, or not be connected.
mock = MagicMock(return_value=xml_peer_probe_success)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
self.assertTrue(glusterfs.peer('salt'))
self.assertEqual(glusterfs.peer('salt'),
{'exitval': '0', 'output': None})
mock = MagicMock(return_value=xml_peer_probe_fail_already_member)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
self.assertEqual(glusterfs.peer('salt'),
{'exitval': '0', 'output': 'Host salt port 24007 already in peer list'})
mock = MagicMock(return_value=xml_peer_probe_fail_localhost)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
self.assertEqual(glusterfs.peer('salt'),
{'exitval': '0', 'output': 'Probe on localhost not needed'})
mock = MagicMock(return_value=xml_peer_probe_fail_cant_connect)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
self.assertRaises(CommandExecutionError, glusterfs.peer, 'salt')
mock = MagicMock(return_value=True)
with patch.object(suc, 'check_name', mock):

View file

@ -67,15 +67,15 @@ class GlusterfsTestCase(TestCase):
with patch.object(socket, 'gethostname',
MagicMock(side_effect=[name, 'salt.host',
'salt.host'])):
ret.update({'comment': [], 'result': True})
ret.update({'comment': '', 'result': True})
self.assertDictEqual(glusterfs.peered(name), ret)
comt = ('Host {0} already peered'.format(name))
ret.update({'comment': [], 'result': True})
ret.update({'comment': '', 'result': True})
self.assertDictEqual(glusterfs.peered(name), ret)
comt = ('Host {0} already peered'.format(name))
ret.update({'comment': [], 'result': True,
ret.update({'comment': '', 'result': True,
'changes': {'new': ['salt'], 'old': []}})
self.assertDictEqual(glusterfs.peered(name), ret)