mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Update tests to cover new peering return val.
This commit is contained in:
parent
b2407305e8
commit
730b5ef3e2
3 changed files with 65 additions and 6 deletions
|
@ -65,7 +65,10 @@ def peered(name):
|
|||
ret['result'] = False
|
||||
return ret
|
||||
|
||||
ret['comment'] = __salt__['glusterfs.peer'](name)['output']
|
||||
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.
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue