Don't ignore failures when delete nodes

Deleting nodes ignore failures and just prints the results which nodes
are deleted and which are failed.

But in case failure it doesn't propagate exception further, as result
success command execution, return code of cmd is 0.

Closes-Bug: #1552224
Change-Id: I48be1d1ddf199b75cd09f6df6bdff5fef2f24334
This commit is contained in:
Anton Arefiev 2016-03-02 15:08:13 +02:00
parent 26df6c3c37
commit 6a59a30961
3 changed files with 17 additions and 4 deletions

View File

@ -86,7 +86,8 @@ class NodeShellTest(utils.BaseTestCase):
args = mock.MagicMock()
args.node = ['node_uuid1', 'node_uuid2']
n_shell.do_node_delete(client_mock, args)
self.assertRaises(exceptions.ClientException, n_shell.do_node_delete,
client_mock, args)
client_mock.node.delete.assert_has_calls(
[mock.call('node_uuid1'), mock.call('node_uuid2')])

View File

@ -259,14 +259,21 @@ def do_node_create(cc, args):
nargs='+',
help="Name or UUID of the node.")
def do_node_delete(cc, args):
"""Unregister node(s) from the Ironic service."""
"""Unregister node(s) from the Ironic service.
:raises: ClientException, if error happens during the delete
"""
failures = []
for n in args.node:
try:
cc.node.delete(n)
print(_('Deleted node %s') % n)
except exceptions.ClientException as e:
print(_("Failed to delete node %(node)s: %(error)s")
% {'node': n, 'error': e})
failures.append(_("Failed to delete node %(node)s: %(error)s")
% {'node': n, 'error': e})
if failures:
raise exceptions.ClientException("\n".join(failures))
@cliutils.arg('node', metavar='<node>', help="Name or UUID of the node.")

View File

@ -0,0 +1,5 @@
---
fixes:
- Fixes an issue where deleting nodes ignore failures and just prints the results
which nodes are deleted and which are failed, always returning exit code of 0.
This now will return a non-zero exit code if at least one node-delete fails.