continue to delete next node if failed with previous one

We delete multiple nodes which include the non-exist nodes, ironic
client will break at the node which non-exist, so with this patch,
we will add try-except logic to continue to delete next one, and
print the results which are deleted and which are failed.

Change-Id: Iba48c570e48b51a2b6029ae89e3163ed05184bc1
Close-bug: #1529894
This commit is contained in:
Haomeng, Wang 2015-12-30 06:45:44 +00:00
parent ced49ed5e3
commit 36d2e1360f
3 changed files with 20 additions and 2 deletions

View File

@ -73,6 +73,17 @@ class NodeShellTest(utils.BaseTestCase):
client_mock.node.delete.assert_has_calls(
[mock.call('node_uuid1'), mock.call('node_uuid2')])
def test_do_node_delete_multiple_with_exception(self):
client_mock = mock.MagicMock()
client_mock.node.delete.side_effect = (
[exceptions.ClientException, None])
args = mock.MagicMock()
args.node = ['node_uuid1', 'node_uuid2']
n_shell.do_node_delete(client_mock, args)
client_mock.node.delete.assert_has_calls(
[mock.call('node_uuid1'), mock.call('node_uuid2')])
def test_do_node_update(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()

View File

@ -215,8 +215,12 @@ def do_node_create(cc, args):
def do_node_delete(cc, args):
"""Unregister node(s) from the Ironic service."""
for n in args.node:
cc.node.delete(n)
print(_('Deleted node %s') % n)
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})
@cliutils.arg('node', metavar='<node>', help="Name or UUID of the node.")

View File

@ -0,0 +1,3 @@
---
fixes:
- when deleting multiple nodes, continue with deletes even if one fails.