From 8ca170092c22ec0ecdfb13b2800582c0231395ba Mon Sep 17 00:00:00 2001 From: chohoor Date: Fri, 10 Mar 2017 13:31:43 +0800 Subject: [PATCH] Support check before do node-recover action This patch add a parameter 'check' to node-recover command. Then user could choice whether check physical resource status before do node-recover action. partial-blueprint: refresh-status-before-do-node-recover Change-Id: I94e33351593ffc49458ad85abde8acba5dc972e9 --- senlinclient/tests/unit/v1/test_node.py | 7 ++++--- senlinclient/tests/unit/v1/test_shell.py | 17 ++++++++++++++--- senlinclient/v1/node.py | 15 ++++++++++++++- senlinclient/v1/shell.py | 9 ++++++++- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/senlinclient/tests/unit/v1/test_node.py b/senlinclient/tests/unit/v1/test_node.py index 4941f3f..a07a984 100644 --- a/senlinclient/tests/unit/v1/test_node.py +++ b/senlinclient/tests/unit/v1/test_node.py @@ -440,12 +440,13 @@ class TestNodeRecover(TestNode): self.mock_client.recover_node = mock.Mock(return_value=fake_res) def test_node_recover(self): - arglist = ['node1', 'node2', 'node3'] + arglist = ['node1', 'node2', 'node3', '--check', 'false'] + kwargs = {'check': False} parsed_args = self.check_parser(self.cmd, arglist, []) self.cmd.take_action(parsed_args) self.mock_client.recover_node.assert_has_calls( - [mock.call('node1'), mock.call('node2'), - mock.call('node3')] + [mock.call('node1', **kwargs), mock.call('node2', **kwargs), + mock.call('node3', **kwargs)] ) def test_node_recover_not_found(self): diff --git a/senlinclient/tests/unit/v1/test_shell.py b/senlinclient/tests/unit/v1/test_shell.py index 50c5964..448c209 100644 --- a/senlinclient/tests/unit/v1/test_shell.py +++ b/senlinclient/tests/unit/v1/test_shell.py @@ -1534,19 +1534,30 @@ class ShellTest(testtools.TestCase): def test_do_node_recover(self): service = mock.Mock() - args = self._make_args({'id': ['node1']}) + args = { + 'id': ['node1'], + 'check': 'false' + } + args = self._make_args(args) + attrs = { + 'check': False + } service.check_node = mock.Mock() sh.do_node_recover(service, args) - service.recover_node.assert_called_once_with('node1') + service.recover_node.assert_called_once_with('node1', **attrs) def test_do_node_recover_not_found(self): service = mock.Mock() ex = exc.HTTPNotFound service.recover_node.side_effect = ex + args = { + 'id': ['node1'], + 'check': 'false' + } + args = self._make_args(args) - args = self._make_args({'id': ['node1']}) ex = self.assertRaises(exc.CommandError, sh.do_node_recover, service, args) msg = _('Failed to recover some of the specified nodes.') diff --git a/senlinclient/v1/node.py b/senlinclient/v1/node.py index e7e47f2..95e328d 100644 --- a/senlinclient/v1/node.py +++ b/senlinclient/v1/node.py @@ -19,6 +19,7 @@ from openstack import exceptions as sdk_exc from osc_lib.command import command from osc_lib import exceptions as exc from osc_lib import utils +from oslo_utils import strutils import six from senlinclient.common.i18n import _ @@ -365,6 +366,13 @@ class RecoverNode(command.Command): def get_parser(self, prog_name): parser = super(RecoverNode, self).get_parser(prog_name) + parser.add_argument( + '--check', + metavar='', + default=False, + help=_('Whether the node(s) should check physical resource status ' + 'before doing node recover. Default is false') + ) parser.add_argument( 'node', metavar='', @@ -376,9 +384,14 @@ class RecoverNode(command.Command): def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) senlin_client = self.app.client_manager.clustering + + params = { + 'check': strutils.bool_from_string(parsed_args.check, strict=True) + } + for nid in parsed_args.node: try: - resp = senlin_client.recover_node(nid) + resp = senlin_client.recover_node(nid, **params) except sdk_exc.ResourceNotFound: raise exc.CommandError(_('Node not found: %s') % nid) print('Node recover request on node %(nid)s is accepted by ' diff --git a/senlinclient/v1/shell.py b/senlinclient/v1/shell.py index a8b8462..352dc76 100644 --- a/senlinclient/v1/shell.py +++ b/senlinclient/v1/shell.py @@ -1352,6 +1352,9 @@ def do_node_check(service, args): print('Request accepted') +@utils.arg('-c', '--check', metavar='', default=False, + help=_("Whether the node(s) should check physical resource status " + "before doing node recover.Default is false")) @utils.arg('id', metavar='', nargs='+', help=_('ID or name of node(s) to recover.')) def do_node_recover(service, args): @@ -1359,9 +1362,13 @@ def do_node_recover(service, args): show_deprecated('senlin node-recover', 'openstack cluster node recover') failure_count = 0 + params = { + 'check': strutils.bool_from_string(args.check, strict=True) + } + for nid in args.id: try: - service.recover_node(nid) + service.recover_node(nid, **params) except exc.HTTPNotFound: failure_count += 1 print('Node id "%s" not found' % nid)