mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #30631 from rallytime/fix-7811
Refactor rabbitmq_cluster states to use test=true functionality correctly
This commit is contained in:
commit
5bc11d7539
2 changed files with 21 additions and 16 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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'),
|
||||
|
|
Loading…
Add table
Reference in a new issue