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:
@@ -780,12 +780,13 @@ class TestClusterRecover(TestCluster):
|
|||||||
return_value=self.response)
|
return_value=self.response)
|
||||||
|
|
||||||
def test_cluster_recover(self):
|
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, [])
|
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||||
self.cmd.take_action(parsed_args)
|
self.cmd.take_action(parsed_args)
|
||||||
self.mock_client.recover_cluster.assert_has_calls(
|
self.mock_client.recover_cluster.assert_has_calls(
|
||||||
[mock.call('cluster1'), mock.call('cluster2'),
|
[mock.call('cluster1', **kwargs), mock.call('cluster2', **kwargs),
|
||||||
mock.call('cluster3')]
|
mock.call('cluster3', **kwargs)]
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_cluster_recover_not_found(self):
|
def test_cluster_recover_not_found(self):
|
||||||
|
@@ -1350,13 +1350,20 @@ class ShellTest(testtools.TestCase):
|
|||||||
|
|
||||||
def test_do_cluster_recover(self):
|
def test_do_cluster_recover(self):
|
||||||
service = mock.Mock()
|
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 = mock.Mock()
|
||||||
service.recover_cluster.return_value = {'action': 'action_id'}
|
service.recover_cluster.return_value = {'action': 'action_id'}
|
||||||
|
|
||||||
sh.do_cluster_recover(service, args)
|
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):
|
def test_do_cluster_collect(self):
|
||||||
service = mock.Mock()
|
service = mock.Mock()
|
||||||
|
@@ -829,14 +829,28 @@ class RecoverCluster(command.Command):
|
|||||||
nargs='+',
|
nargs='+',
|
||||||
help=_('ID or name of cluster(s) to operate on.')
|
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
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug("take_action(%s)", parsed_args)
|
self.log.debug("take_action(%s)", parsed_args)
|
||||||
senlin_client = self.app.client_manager.clustering
|
senlin_client = self.app.client_manager.clustering
|
||||||
|
|
||||||
|
params = {
|
||||||
|
'check': strutils.bool_from_string(parsed_args.check, strict=True)
|
||||||
|
}
|
||||||
|
|
||||||
for cid in parsed_args.cluster:
|
for cid in parsed_args.cluster:
|
||||||
try:
|
try:
|
||||||
resp = senlin_client.recover_cluster(cid)
|
resp = senlin_client.recover_cluster(cid, **params)
|
||||||
except sdk_exc.ResourceNotFound:
|
except sdk_exc.ResourceNotFound:
|
||||||
raise exc.CommandError(_('Cluster not found: %s') % cid)
|
raise exc.CommandError(_('Cluster not found: %s') % cid)
|
||||||
print('Cluster recover request on cluster %(cid)s is accepted by '
|
print('Cluster recover request on cluster %(cid)s is accepted by '
|
||||||
|
@@ -1164,13 +1164,21 @@ def do_cluster_check(service, args):
|
|||||||
'action %(action)s.' % {'cid': cid, 'action': resp['action']})
|
'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='+',
|
@utils.arg('id', metavar='<CLUSTER>', nargs='+',
|
||||||
help=_('ID or name of cluster(s) to operate on.'))
|
help=_('ID or name of cluster(s) to operate on.'))
|
||||||
def do_cluster_recover(service, args):
|
def do_cluster_recover(service, args):
|
||||||
"""Recover the cluster(s)."""
|
"""Recover the cluster(s)."""
|
||||||
show_deprecated('senlin cluster-recover', 'openstack cluster recover')
|
show_deprecated('senlin cluster-recover', 'openstack cluster recover')
|
||||||
|
|
||||||
|
params = {
|
||||||
|
'check': strutils.bool_from_string(args.check, strict=True)
|
||||||
|
}
|
||||||
|
|
||||||
for cid in args.id:
|
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 '
|
print('Cluster recover request on cluster %(cid)s is accepted by '
|
||||||
'action %(action)s.' % {'cid': cid, 'action': resp['action']})
|
'action %(action)s.' % {'cid': cid, 'action': resp['action']})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user