Merge pull request #30631 from rallytime/fix-7811

Refactor rabbitmq_cluster states to use test=true functionality correctly
This commit is contained in:
Colton Myers 2016-01-26 09:23:49 -07:00
commit 5bc11d7539
2 changed files with 21 additions and 16 deletions

View file

@ -47,28 +47,31 @@ def joined(name, host, user='rabbit', ram_node=None, runas='root'):
'''
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
result = {}
joined = __salt__['rabbitmq.cluster_status']()
if '{0}@{1}'.format(user, host) in joined:
status = __salt__['rabbitmq.cluster_status']()
if '{0}@{1}'.format(user, host) in status:
ret['comment'] = 'Already in cluster'
return ret
if not __opts__['test']:
result = __salt__['rabbitmq.join_cluster'](host,
user,
ram_node,
runas=runas)
if 'Error' in result:
ret['result'] = False
ret['comment'] = result['Error']
return ret
elif 'Join' in result:
ret['comment'] = result['Join']
# If we've reached this far before returning, we have changes.
ret['changes'] = {'old': '', 'new': '{0}@{1}'.format(user, host)}
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Node is set to join cluster {0}@{1}'.format(
user, host)
return ret
result = __salt__['rabbitmq.join_cluster'](host, user,
ram_node, runas=runas)
if 'Error' in result:
ret['result'] = False
ret['comment'] = result['Error']
elif 'Join' in result:
ret['comment'] = result['Join']
ret['changes'] = {'old': '', 'new': '{0}@{1}'.format(user, host)}
return ret

View file

@ -51,7 +51,8 @@ class RabbitmqClusterTestCase(TestCase):
with patch.dict(rabbitmq_cluster.__opts__, {"test": True}):
ret.update({'result': None,
'comment': 'Node is set to join '
'cluster rahulha@salt'})
'cluster rahulha@salt',
'changes': {'new': 'rahulha@salt', 'old': ''}})
self.assertDictEqual(rabbitmq_cluster.joined('salt', 'salt',
'rahulha'), ret)
@ -60,7 +61,8 @@ class RabbitmqClusterTestCase(TestCase):
with patch.dict(rabbitmq_cluster.__salt__,
{"rabbitmq.join_cluster": mock}):
ret.update({'result': False,
'comment': 'ERR'})
'comment': 'ERR',
'changes': {}})
self.assertDictEqual(rabbitmq_cluster.joined('salt',
'salt',
'rahulha'),