Merge "Add support for test mode to keystone_policy"
diff --git a/_states/keystone_policy.py b/_states/keystone_policy.py
index e7a4a6a..ceede27 100644
--- a/_states/keystone_policy.py
+++ b/_states/keystone_policy.py
@@ -32,7 +32,7 @@
def rule_present(name, rule, path, **kwargs):
'''
Ensures that the policy rule exists
-
+
:param name: Rule name
:param rule: Rule
:param path: Path to policy file
@@ -44,17 +44,25 @@
'comment': 'Rule "{0}" already exists and is in correct state'.format(name)}
rule_check = __salt__['keystone_policy.rule_get'](name, path, **kwargs)
if not rule_check:
- __salt__['keystone_policy.rule_set'](name, rule, path, **kwargs)
- ret['comment'] = 'Rule {0} has been created'.format(name)
- ret['changes']['Rule'] = 'Rule %s: "%s" has been created' % (name, rule)
+ if __opts__.get('test'):
+ ret['result'] = None
+ ret['comment'] = 'Rule {0} will be created'.format(name)
+ else:
+ __salt__['keystone_policy.rule_set'](name, rule, path, **kwargs)
+ ret['comment'] = 'Rule {0} has been created'.format(name)
+ ret['changes']['Rule'] = 'Rule %s: "%s" has been created' % (name, rule)
elif 'Error' in rule_check:
ret['comment'] = rule_check.get('Error')
ret['result'] = False
elif rule_check[name] != rule:
- __salt__['keystone_policy.rule_set'](name, rule, path, **kwargs)
- ret['comment'] = 'Rule %s has been changed' % (name,)
- ret['changes']['Old Rule'] = '%s: "%s"' % (name, rule_check[name])
- ret['changes']['New Rule'] = '%s: "%s"' % (name, rule)
+ if __opts__.get('test'):
+ ret['result'] = None
+ ret['comment'] = 'Rule %s will be changed' % (name,)
+ else:
+ __salt__['keystone_policy.rule_set'](name, rule, path, **kwargs)
+ ret['comment'] = 'Rule %s has been changed' % (name,)
+ ret['changes']['Old Rule'] = '%s: "%s"' % (name, rule_check[name])
+ ret['changes']['New Rule'] = '%s: "%s"' % (name, rule)
return ret
@@ -71,9 +79,13 @@
'comment': 'Rule "{0}" is already absent'.format(name)}
rule_check = __salt__['keystone_policy.rule_get'](name, path, **kwargs)
if rule_check:
- __salt__['keystone_policy.rule_delete'](name, path, **kwargs)
- ret['comment'] = 'Rule {0} has been deleted'.format(name)
- ret['changes']['Rule'] = 'Rule %s: "%s" has been deleted' % (name, rule_check[name])
+ if __opts__.get('test'):
+ ret['result'] = None
+ ret['comment'] = 'Rule {0} will be deleted'.format(name)
+ else
+ __salt__['keystone_policy.rule_delete'](name, path, **kwargs)
+ ret['comment'] = 'Rule {0} has been deleted'.format(name)
+ ret['changes']['Rule'] = 'Rule %s: "%s" has been deleted' % (name, rule_check[name])
elif 'Error' in rule_check:
ret['comment'] = rule_check.get('Error')
ret['result'] = False