Merge pull request #30567 from rallytime/fix-25363

Make sure rabbitmq_vhost states are using test=true properly.
This commit is contained in:
Colton Myers 2016-01-25 16:19:45 -07:00
commit 94bf7790cf
2 changed files with 37 additions and 33 deletions

View file

@ -14,9 +14,9 @@ Example:
- write: .*
- read: .*
'''
from __future__ import absolute_import
# Import python libs
from __future__ import absolute_import
import logging
# Import salt libs
@ -70,24 +70,25 @@ def present(name):
vhost_exists = __salt__['rabbitmq.vhost_exists'](name)
if vhost_exists:
ret['comment'] = 'Virtual Host \'{0}\' already exists.'.format(name)
return ret
if not __opts__['test']:
result = __salt__['rabbitmq.add_vhost'](name)
if 'Error' in result:
ret['result'] = False
ret['comment'] = result['Error']
return ret
elif 'Added' in result:
ret['comment'] = result['Added']
# If we've reached this far before returning, we have changes.
ret['changes'] = {'old': '', 'new': name}
if __opts__['test']:
ret['result'] = None
if vhost_exists:
ret['comment'] = 'VHost {0} already exists'.format(name)
else:
ret['comment'] = 'Creating VHost {0}'.format(name)
else:
if vhost_exists:
ret['comment'] = 'VHost {0} already exists'.format(name)
else:
result = __salt__['rabbitmq.add_vhost'](name)
if 'Error' in result:
ret['result'] = False
ret['comment'] = result['Error']
elif 'Added' in result:
ret['comment'] = result['Added']
ret['changes'] = {'old': '', 'new': name}
ret['comment'] = 'Virtual Host \'{0}\' will be created.'.format(name)
return ret
@ -108,20 +109,23 @@ def absent(name):
vhost_exists = __salt__['rabbitmq.vhost_exists'](name)
if not vhost_exists:
ret['comment'] = 'Virtual Host {0} is not present'.format(name)
ret['comment'] = 'Virtual Host \'{0}\' is not present.'.format(name)
return ret
elif __opts__['test']:
if not __opts__['test']:
result = __salt__['rabbitmq.delete_vhost'](name)
if 'Error' in result:
ret['result'] = False
ret['comment'] = result['Error']
return ret
elif 'Deleted' in result:
ret['comment'] = result['Deleted']
# If we've reached this far before returning, we have changes.
ret['changes'] = {'new': '', 'old': name}
if __opts__['test']:
ret['result'] = None
if vhost_exists:
ret['comment'] = 'Removing Virtual Host {0}'.format(name)
ret['comment'] = 'Virtual Host \'{0}\' will be removed.'.format(name)
else:
if vhost_exists:
result = __salt__['rabbitmq.delete_vhost'](name)
if 'Error' in result:
ret['result'] = False
ret['comment'] = result['Error']
elif 'Deleted' in result:
ret['comment'] = result['Deleted']
ret['changes'] = {'new': '', 'old': name}
return ret

View file

@ -39,9 +39,9 @@ class RabbitmqVhostTestCase(TestCase):
name = 'virtual_host'
ret = {'name': name,
'changes': {},
'changes': {'new': 'virtual_host', 'old': ''},
'result': None,
'comment': 'Creating VHost virtual_host'}
'comment': 'Virtual Host \'virtual_host\' will be created.'}
mock = MagicMock(return_value=False)
with patch.dict(rabbitmq_vhost.__salt__,
@ -60,7 +60,7 @@ class RabbitmqVhostTestCase(TestCase):
ret = {'name': name,
'changes': {},
'result': True,
'comment': 'Virtual Host {0} is not present'.format(name)}
'comment': 'Virtual Host \'{0}\' is not present.'.format(name)}
mock = MagicMock(return_value=False)
with patch.dict(rabbitmq_vhost.__salt__,