mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge pull request #26263 from rallytime/fix-24882
Don't make changes when test=True for openstack present/absent funcs
This commit is contained in:
commit
65ab5aa495
@ -8,10 +8,12 @@ Manage OpenStack configuration file settings.
|
||||
:platform: linux
|
||||
|
||||
'''
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import salt libs
|
||||
import salt.exceptions
|
||||
# Import Salt Libs
|
||||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
|
||||
def __virtual__():
|
||||
@ -48,18 +50,30 @@ def present(name, filename, section, value, parameter=None):
|
||||
if parameter is None:
|
||||
parameter = name
|
||||
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': False,
|
||||
'comment': ''}
|
||||
|
||||
try:
|
||||
old_value = __salt__['openstack_config.get'](filename=filename,
|
||||
section=section,
|
||||
parameter=parameter)
|
||||
|
||||
if old_value == value:
|
||||
return {'name': name,
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': 'The value is already set to the correct value'}
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'The value is already set to the correct value'
|
||||
return ret
|
||||
|
||||
except salt.exceptions.CommandExecutionError as e:
|
||||
if __opts__['test']:
|
||||
ret['result'] = None
|
||||
ret['comment'] = 'Value \'{0}\' is set to be changed to \'{1}\'.'.format(
|
||||
old_value,
|
||||
value
|
||||
)
|
||||
return ret
|
||||
|
||||
except CommandExecutionError as e:
|
||||
if not str(e).lower().startswith('parameter not found:'):
|
||||
raise
|
||||
|
||||
@ -68,10 +82,11 @@ def present(name, filename, section, value, parameter=None):
|
||||
parameter=parameter,
|
||||
value=value)
|
||||
|
||||
return {'name': name,
|
||||
'changes': {'Value': 'Updated'},
|
||||
'result': True,
|
||||
'comment': 'The value has been updated'}
|
||||
ret['changes'] = {'Value': 'Updated'}
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'The value has been updated'
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def absent(name, filename, section, parameter=None):
|
||||
@ -92,23 +107,35 @@ def absent(name, filename, section, parameter=None):
|
||||
if parameter is None:
|
||||
parameter = name
|
||||
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': False,
|
||||
'comment': ''}
|
||||
|
||||
try:
|
||||
old_value = __salt__['openstack_config.get'](filename=filename,
|
||||
section=section,
|
||||
parameter=parameter)
|
||||
except salt.exceptions.CommandExecutionError as e:
|
||||
except CommandExecutionError as e:
|
||||
if str(e).lower().startswith('parameter not found:'):
|
||||
return {'name': name,
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': 'The value is already absent'}
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'The value is already absent'
|
||||
return ret
|
||||
raise
|
||||
|
||||
if __opts__['test']:
|
||||
ret['result'] = None
|
||||
ret['comment'] = 'Value \'{0}\' is set to be deleted.'.format(
|
||||
old_value
|
||||
)
|
||||
return ret
|
||||
|
||||
__salt__['openstack_config.delete'](filename=filename,
|
||||
section=section,
|
||||
parameter=parameter)
|
||||
|
||||
return {'name': name,
|
||||
'changes': {'Value': 'Deleted'},
|
||||
'result': True,
|
||||
'comment': 'The value has been deleted'}
|
||||
ret['changes'] = {'Value': 'Deleted'}
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'The value has been deleted'
|
||||
|
||||
return ret
|
||||
|
@ -22,7 +22,7 @@ ensure_in_syspath('../../')
|
||||
from salt.states import openstack_config
|
||||
|
||||
openstack_config.__salt__ = {}
|
||||
openstack_config.__opts__ = {}
|
||||
openstack_config.__opts__ = {'test': False}
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
|
Loading…
Reference in New Issue
Block a user