mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Get changes/error message for pkg states from new CommandExecutionError attributes
This commit is contained in:
parent
a2334cdbd7
commit
484c4753af
@ -1140,13 +1140,17 @@ def installed(
|
|||||||
if os.path.isfile(rtag) and refresh:
|
if os.path.isfile(rtag) and refresh:
|
||||||
os.remove(rtag)
|
os.remove(rtag)
|
||||||
except CommandExecutionError as exc:
|
except CommandExecutionError as exc:
|
||||||
ret = {'name': name,
|
ret = {'name': name, 'result': False}
|
||||||
'changes': {},
|
if exc.info:
|
||||||
'result': False,
|
# Get information for state return from the exception.
|
||||||
'comment': 'An error was encountered while installing '
|
ret['changes'] = exc.info.get('changes', {})
|
||||||
'package(s): {0}'.format(exc)}
|
ret['comment'] = exc.strerror_without_changes
|
||||||
|
else:
|
||||||
|
ret['changes'] = {}
|
||||||
|
ret['comment'] = ('An error was encountered while installing '
|
||||||
|
'package(s): {0}'.format(exc))
|
||||||
if warnings:
|
if warnings:
|
||||||
ret['comment'] += '.' + '. '.join(warnings) + '.'
|
ret['comment'] += '\n\n' + '. '.join(warnings) + '.'
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
if isinstance(pkg_ret, dict):
|
if isinstance(pkg_ret, dict):
|
||||||
@ -1779,16 +1783,22 @@ def removed(name, version=None, pkgs=None, normalize=True, **kwargs):
|
|||||||
``name`` parameter will be ignored if this option is passed. It accepts
|
``name`` parameter will be ignored if this option is passed. It accepts
|
||||||
version numbers as well.
|
version numbers as well.
|
||||||
|
|
||||||
.. versionadded:: 0.16.0
|
.. versionadded:: 0.16.0
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
return _uninstall(action='remove', name=name, version=version,
|
return _uninstall(action='remove', name=name, version=version,
|
||||||
pkgs=pkgs, normalize=normalize, **kwargs)
|
pkgs=pkgs, normalize=normalize, **kwargs)
|
||||||
except CommandExecutionError as exc:
|
except CommandExecutionError as exc:
|
||||||
return {'name': name,
|
ret = {'name': name, 'result': False}
|
||||||
'changes': {},
|
if exc.info:
|
||||||
'result': False,
|
# Get information for state return from the exception.
|
||||||
'comment': str(exc)}
|
ret['changes'] = exc.info.get('changes', {})
|
||||||
|
ret['comment'] = exc.strerror_without_changes
|
||||||
|
else:
|
||||||
|
ret['changes'] = {}
|
||||||
|
ret['comment'] = ('An error was encountered while removing '
|
||||||
|
'package(s): {0}'.format(exc))
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def purged(name, version=None, pkgs=None, normalize=True, **kwargs):
|
def purged(name, version=None, pkgs=None, normalize=True, **kwargs):
|
||||||
@ -1826,10 +1836,16 @@ def purged(name, version=None, pkgs=None, normalize=True, **kwargs):
|
|||||||
return _uninstall(action='purge', name=name, version=version,
|
return _uninstall(action='purge', name=name, version=version,
|
||||||
pkgs=pkgs, normalize=normalize, **kwargs)
|
pkgs=pkgs, normalize=normalize, **kwargs)
|
||||||
except CommandExecutionError as exc:
|
except CommandExecutionError as exc:
|
||||||
return {'name': name,
|
ret = {'name': name, 'result': False}
|
||||||
'changes': {},
|
if exc.info:
|
||||||
'result': False,
|
# Get information for state return from the exception.
|
||||||
'comment': str(exc)}
|
ret['changes'] = exc.info.get('changes', {})
|
||||||
|
ret['comment'] = exc.strerror_without_changes
|
||||||
|
else:
|
||||||
|
ret['changes'] = {}
|
||||||
|
ret['comment'] = ('An error was encountered while purging '
|
||||||
|
'package(s): {0}'.format(exc))
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def uptodate(name, refresh=False, **kwargs):
|
def uptodate(name, refresh=False, **kwargs):
|
||||||
@ -1878,7 +1894,19 @@ def uptodate(name, refresh=False, **kwargs):
|
|||||||
ret['result'] = None
|
ret['result'] = None
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
updated = __salt__['pkg.upgrade'](refresh=refresh, **kwargs)
|
try:
|
||||||
|
updated = __salt__['pkg.upgrade'](refresh=refresh, **kwargs)
|
||||||
|
except CommandExecutionError as exc:
|
||||||
|
ret = {'name': name, 'result': False}
|
||||||
|
if exc.info:
|
||||||
|
# Get information for state return from the exception.
|
||||||
|
ret['changes'] = exc.info.get('changes', {})
|
||||||
|
ret['comment'] = exc.strerror_without_changes
|
||||||
|
else:
|
||||||
|
ret['changes'] = {}
|
||||||
|
ret['comment'] = ('An error was encountered while updating '
|
||||||
|
'packages: {0}'.format(exc))
|
||||||
|
return ret
|
||||||
|
|
||||||
if updated.get('result') is False:
|
if updated.get('result') is False:
|
||||||
ret.update(updated)
|
ret.update(updated)
|
||||||
@ -1997,7 +2025,20 @@ def group_installed(name, skip=None, include=None, **kwargs):
|
|||||||
ret['comment'] = 'Group \'{0}\' will be installed'.format(name)
|
ret['comment'] = 'Group \'{0}\' will be installed'.format(name)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
ret['changes'] = __salt__['pkg.install'](pkgs=targets, **kwargs)
|
try:
|
||||||
|
ret['changes'] = __salt__['pkg.install'](pkgs=targets, **kwargs)
|
||||||
|
except CommandExecutionError as exc:
|
||||||
|
ret = {'name': name, 'result': False}
|
||||||
|
if exc.info:
|
||||||
|
# Get information for state return from the exception.
|
||||||
|
ret['changes'] = exc.info.get('changes', {})
|
||||||
|
ret['comment'] = exc.strerror_without_changes
|
||||||
|
else:
|
||||||
|
ret['changes'] = {}
|
||||||
|
ret['comment'] = ('An error was encountered while '
|
||||||
|
'installing/updating group \'{0}\': {1}'
|
||||||
|
.format(name, exc))
|
||||||
|
return ret
|
||||||
|
|
||||||
failed = [x for x in targets if x not in __salt__['pkg.list_pkgs']()]
|
failed = [x for x in targets if x not in __salt__['pkg.list_pkgs']()]
|
||||||
if failed:
|
if failed:
|
||||||
|
Loading…
Reference in New Issue
Block a user