Revise issue in do_del_nodes

This patch fixes conditional and return msg when do_del_nodes.

Change-Id: Iaeb08cf5935a9958fd211acf8c11132f1bc0c1f4
This commit is contained in:
jonnary 2017-01-06 23:43:59 +08:00
parent 83452d7be5
commit 6ae58362ef
2 changed files with 7 additions and 7 deletions

View File

@ -451,9 +451,8 @@ class ClusterAction(base.Action):
grace_period = 0
reduce_desired_capacity = True
pd = self.data.get('deletion', None)
if pd:
if 'destroy_after_deletion' in pd:
destroy_after_deletion = pd['destroy_after_deletion']
if pd is not None:
destroy_after_deletion = pd.get('destroy_after_deletion', False)
grace_period = pd.get('grace_period', 0)
reduce_desired_capacity = pd.get('reduce_desired_capacity', True)
@ -474,14 +473,15 @@ class ClusterAction(base.Action):
# The return value is None if node not found
if not node:
errors.append(_('Node %s is not found.') % node_id)
errors.append(node_id)
continue
if ((not node.cluster_id) or (node.cluster_id != self.target)):
nodes.remove(node_id)
if len(errors) > 0:
return self.RES_ERROR, ''.join(errors)
msg = _("Nodes not found: %s.") % errors
return self.RES_ERROR, msg
reason = _('Completed deleting nodes.')
if len(nodes) == 0:

View File

@ -126,7 +126,7 @@ class ClusterDelNodesTest(base.SenlinTestCase):
cluster = mock.Mock()
mock_load.return_value = cluster
action = ca.ClusterAction('ID', 'CLUSTER_ACTION', self.ctx,
inputs={'candidates': ['NODE_1']})
inputs={'candidates': ['NODE_1', 'NODE_2']})
mock_get.return_value = None
# do it
@ -134,7 +134,7 @@ class ClusterDelNodesTest(base.SenlinTestCase):
# assertions
self.assertEqual(action.RES_ERROR, res_code)
self.assertEqual("Node NODE_1 is not found.", res_msg)
self.assertEqual("Nodes not found: ['NODE_1', 'NODE_2'].", res_msg)
expected = {
'deletion': {
'destroy_after_deletion': False,