openbsdpkg.py: raise exception if changes fail

This uses the new 'info' param for the CommandExecutionError exception
to allow us to report partial changes when there are errors.
This commit is contained in:
Erik Johnson 2015-12-15 09:58:39 -06:00
parent 9469f2c790
commit 801f457301

View File

@ -173,16 +173,31 @@ def install(name=None, pkgs=None, sources=None, **kwargs):
return {}
old = list_pkgs()
errors = []
for pkg in pkg_params:
if pkg_type == 'repository':
stem, flavor = (pkg.split('--') + [''])[:2]
pkg = '--'.join((stem, flavor))
cmd = 'pkg_add -x {0}'.format(pkg)
__salt__['cmd.run'](cmd, python_shell=False, output_loglevel='trace')
out = __salt__['cmd.run_all'](
cmd,
python_shell=False,
output_loglevel='trace'
)
if out['retcode'] != 0 and out['stderr']:
errors.append(out['stderr'])
__context__.pop('pkg.list_pkgs', None)
new = list_pkgs()
return salt.utils.compare_dicts(old, new)
ret = salt.utils.compare_dicts(old, new)
if errors:
raise CommandExecutionError(
'Problem encountered installing package(s)',
info={'errors': errors, 'changes': ret}
)
return ret
def remove(name=None, pkgs=None, **kwargs):
@ -220,10 +235,28 @@ def remove(name=None, pkgs=None, **kwargs):
return {}
cmd = 'pkg_delete -xD dependencies {0}'.format(' '.join(targets))
__salt__['cmd.run'](cmd, python_shell=False, output_loglevel='trace')
out = __salt__['cmd.run_all'](
cmd,
python_shell=False,
output_loglevel='trace'
)
if out['retcode'] != 0 and out['stderr']:
errors = [out['stderr']]
else:
errors = []
__context__.pop('pkg.list_pkgs', None)
new = list_pkgs()
return salt.utils.compare_dicts(old, new)
ret = salt.utils.compare_dicts(old, new)
if errors:
raise CommandExecutionError(
'Problem encountered removing package(s)',
info={'errors': errors, 'changes': ret}
)
return ret
def purge(name=None, pkgs=None, **kwargs):