mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #43723 from nicholasmhughes/ini_manage-error-handling
Fix ini_manage error and change handling
This commit is contained in:
commit
dd4fc52f1e
2 changed files with 10 additions and 11 deletions
|
@ -373,10 +373,11 @@ class _Ini(_Section):
|
|||
with salt.utils.fopen(self.name) as rfh:
|
||||
inicontents = rfh.read()
|
||||
except (OSError, IOError) as exc:
|
||||
raise CommandExecutionError(
|
||||
"Unable to open file '{0}'. "
|
||||
"Exception: {1}".format(self.name, exc)
|
||||
)
|
||||
if __opts__['test'] is False:
|
||||
raise CommandExecutionError(
|
||||
"Unable to open file '{0}'. "
|
||||
"Exception: {1}".format(self.name, exc)
|
||||
)
|
||||
if not inicontents:
|
||||
return
|
||||
# Remove anything left behind from a previous run.
|
||||
|
|
|
@ -93,7 +93,7 @@ def options_present(name, sections=None, separator='=', strict=False):
|
|||
del changes[section_name]
|
||||
else:
|
||||
changes = __salt__['ini.set_option'](name, sections, separator)
|
||||
except IOError as err:
|
||||
except (IOError, KeyError) as err:
|
||||
ret['comment'] = "{0}".format(err)
|
||||
ret['result'] = False
|
||||
return ret
|
||||
|
@ -102,12 +102,10 @@ def options_present(name, sections=None, separator='=', strict=False):
|
|||
ret['comment'] = 'Errors encountered. {0}'.format(changes['error'])
|
||||
ret['changes'] = {}
|
||||
else:
|
||||
if changes:
|
||||
ret['changes'] = changes
|
||||
ret['comment'] = 'Changes take effect'
|
||||
else:
|
||||
ret['changes'] = {}
|
||||
ret['comment'] = 'No changes take effect'
|
||||
for name, body in changes.items():
|
||||
if body:
|
||||
ret['comment'] = 'Changes take effect'
|
||||
ret['changes'].update({name: changes[name]})
|
||||
return ret
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue