From 95c8e74b72beb7cbe6cb5439859faca7807c8ab2 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Sat, 6 Feb 2016 19:36:51 +0100 Subject: [PATCH] make the code a bit simpler --- salt/states/rabbitmq_vhost.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/salt/states/rabbitmq_vhost.py b/salt/states/rabbitmq_vhost.py index 0b3e14cce9..a641ed94bd 100644 --- a/salt/states/rabbitmq_vhost.py +++ b/salt/states/rabbitmq_vhost.py @@ -70,25 +70,22 @@ def present(name): vhost_exists = __salt__['rabbitmq.vhost_exists'](name) - if __opts__['test']: - if vhost_exists: - ret['result'] = True - ret['comment'] = 'VHost {0} already exists'.format(name) - else: - ret['result'] = None - ret['comment'] = 'Creating VHost {0}'.format(name) + if vhost_exists: + ret['comment'] = 'VHost {0} already exists'.format(name) + return ret - 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} + if __opts__['test']: + ret['result'] = None + ret['comment'] = 'Creating VHost {0}'.format(name) + return ret + + 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} return ret