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
This commit is contained in:
chohoor 2017-05-05 15:32:57 +08:00
parent 913e48c303
commit 116eeec54a
4 changed files with 37 additions and 7 deletions

View File

@ -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):

View File

@ -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()

View File

@ -829,14 +829,28 @@ class RecoverCluster(command.Command):
nargs='+',
help=_('ID or name of cluster(s) to operate on.')
)
parser.add_argument(
'--check',
metavar='<boolean>',
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 '

View File

@ -1164,13 +1164,21 @@ def do_cluster_check(service, args):
'action %(action)s.' % {'cid': cid, 'action': resp['action']})
@utils.arg('-c', '--check', metavar='<BOOLEAN>', default=False,
help=_("Whether the cluster should check it's nodes status before "
"doing cluster recover. Default is false"))
@utils.arg('id', metavar='<CLUSTER>', 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']})