Commit 8c7786a6 by Bach Dániel

vm: improve error handling in UpdateNodeOperation

parent 857316e0
...@@ -1213,7 +1213,8 @@ class UpdateNodeOperation(NodeOperation): ...@@ -1213,7 +1213,8 @@ class UpdateNodeOperation(NodeOperation):
data = data[name] data = data[name]
except KeyError: except KeyError:
raise HumanReadableException.create(ugettext_noop( raise HumanReadableException.create(ugettext_noop(
"No minions matched the target.")) "No minions matched the target (%(target)s). "
"Data: (%(data)s)"), target=name, data=data)
if not isinstance(data, dict): if not isinstance(data, dict):
raise HumanReadableException.create(ugettext_noop( raise HumanReadableException.create(ugettext_noop(
...@@ -1226,18 +1227,24 @@ class UpdateNodeOperation(NodeOperation): ...@@ -1226,18 +1227,24 @@ class UpdateNodeOperation(NodeOperation):
'upgrade_packages', 'upgrade_packages',
readable_name=ugettext_noop('upgrade packages')) as sa: readable_name=ugettext_noop('upgrade packages')) as sa:
data = self.minion_cmd('pkg.upgrade', []) data = self.minion_cmd('pkg.upgrade', [])
upgraded = len(filter(lambda x: x['old'] and x['new'], if not data.get('result'):
data.values())) raise HumanReadableException.create(ugettext_noop(
installed = len(filter(lambda x: not x['old'] and x['new'], "Unhandled exception: %(msg)s"), msg=unicode(data))
data.values()))
removed = len(filter(lambda x: x['old'] and not x['new'], # data = {'vim': {'new': '1.2.7', 'old': '1.3.7'}}
data.values())) data = [v for v in data.values() if isinstance(v, dict)]
upgraded = len([x for x in data
if x.get('old') and x.get('new')])
installed = len([x for x in data
if not x.get('old') and x.get('new')])
removed = len([x for x in data
if x.get('old') and not x.get('new')])
sa.result = create_readable(ugettext_noop( sa.result = create_readable(ugettext_noop(
"Upgraded: %(upgraded)s, Installed: %(installed)s, " "Upgraded: %(upgraded)s, Installed: %(installed)s, "
"Removed: %(removed)s"), upgraded=upgraded, "Removed: %(removed)s"), upgraded=upgraded,
installed=installed, removed=removed) installed=installed, removed=removed)
data = self.minion_cmd('state.sls', ['node', 'nfs-client']) data = self.minion_cmd('state.sls', ['node'])
failed = 0 failed = 0
for k, v in data.iteritems(): for k, v in data.iteritems():
logger.debug('salt state %s %s', k, v) logger.debug('salt state %s %s', k, v)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment