From 116eeec54a55ab7793836f635526e30bcb2d79f1 Mon Sep 17 00:00:00 2001 From: chohoor Date: Fri, 5 May 2017 15:32:57 +0800 Subject: [PATCH] Check node status before do cluster-recover action This patch add a param 'check' to cluster-recover command. Then user could choise whether the cluster should check it's nodes status before doing cluster-recover action. partial-blueprint: check-before-do-cluster-recover Change-Id: I390c604c15d8fa841a44d905793198b09dbaf08e --- senlinclient/tests/unit/v1/test_cluster.py | 7 ++++--- senlinclient/tests/unit/v1/test_shell.py | 11 +++++++++-- senlinclient/v1/cluster.py | 16 +++++++++++++++- senlinclient/v1/shell.py | 10 +++++++++- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/senlinclient/tests/unit/v1/test_cluster.py b/senlinclient/tests/unit/v1/test_cluster.py index 00ab88e..7308c9e 100644 --- a/senlinclient/tests/unit/v1/test_cluster.py +++ b/senlinclient/tests/unit/v1/test_cluster.py @@ -780,12 +780,13 @@ class TestClusterRecover(TestCluster): return_value=self.response) def test_cluster_recover(self): - arglist = ['cluster1', 'cluster2', 'cluster3'] + arglist = ['cluster1', 'cluster2', 'cluster3', '--check', 'false'] + kwargs = {'check': False} parsed_args = self.check_parser(self.cmd, arglist, []) self.cmd.take_action(parsed_args) self.mock_client.recover_cluster.assert_has_calls( - [mock.call('cluster1'), mock.call('cluster2'), - mock.call('cluster3')] + [mock.call('cluster1', **kwargs), mock.call('cluster2', **kwargs), + mock.call('cluster3', **kwargs)] ) def test_cluster_recover_not_found(self): diff --git a/senlinclient/tests/unit/v1/test_shell.py b/senlinclient/tests/unit/v1/test_shell.py index 94148b5..db16dfd 100644 --- a/senlinclient/tests/unit/v1/test_shell.py +++ b/senlinclient/tests/unit/v1/test_shell.py @@ -1350,13 +1350,20 @@ class ShellTest(testtools.TestCase): def test_do_cluster_recover(self): service = mock.Mock() - args = self._make_args({'id': ['cluster1']}) + args = { + 'id': ['cluster1'], + 'check': 'false' + } + args = self._make_args(args) + params = { + 'check': False + } service.recover_cluster = mock.Mock() service.recover_cluster.return_value = {'action': 'action_id'} sh.do_cluster_recover(service, args) - service.recover_cluster.assert_called_once_with('cluster1') + service.recover_cluster.assert_called_once_with('cluster1', **params) def test_do_cluster_collect(self): service = mock.Mock() diff --git a/senlinclient/v1/cluster.py b/senlinclient/v1/cluster.py index 1d62c3e..fc3c019 100644 --- a/senlinclient/v1/cluster.py +++ b/senlinclient/v1/cluster.py @@ -829,14 +829,28 @@ class RecoverCluster(command.Command): nargs='+', help=_('ID or name of cluster(s) to operate on.') ) + + parser.add_argument( + '--check', + metavar='', + default=False, + help=_("Whether the cluster should check it's nodes status before " + "doing cluster recover. Default is false") + ) + return parser 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 cid in parsed_args.cluster: try: - resp = senlin_client.recover_cluster(cid) + resp = senlin_client.recover_cluster(cid, **params) except sdk_exc.ResourceNotFound: raise exc.CommandError(_('Cluster not found: %s') % cid) print('Cluster recover request on cluster %(cid)s is accepted by ' diff --git a/senlinclient/v1/shell.py b/senlinclient/v1/shell.py index 99702b6..fa2351b 100644 --- a/senlinclient/v1/shell.py +++ b/senlinclient/v1/shell.py @@ -1164,13 +1164,21 @@ def do_cluster_check(service, args): 'action %(action)s.' % {'cid': cid, 'action': resp['action']}) +@utils.arg('-c', '--check', metavar='', default=False, + help=_("Whether the cluster should check it's nodes status before " + "doing cluster recover. Default is false")) @utils.arg('id', metavar='', nargs='+', help=_('ID or name of cluster(s) to operate on.')) def do_cluster_recover(service, args): """Recover the cluster(s).""" show_deprecated('senlin cluster-recover', 'openstack cluster recover') + + params = { + 'check': strutils.bool_from_string(args.check, strict=True) + } + for cid in args.id: - resp = service.recover_cluster(cid) + resp = service.recover_cluster(cid, **params) print('Cluster recover request on cluster %(cid)s is accepted by ' 'action %(action)s.' % {'cid': cid, 'action': resp['action']})