remove batch-policy decision from CLUSTER_DELETE

this patch removes batch-policy logic from CLUSTER_DELETE.

The batch policy cannot apply to CLUSTER_DELETE action since it is not
allowed to delete cluster with policies attached to it.

Change-Id: I715a03c5fc0856b06a6267b302dcddd1eb7d61c7
This commit is contained in:
RUIJIE YUAN 2017-06-04 11:29:07 +08:00
parent dd0fb27794
commit 8dd682aa2c
2 changed files with 4 additions and 62 deletions

View File

@ -330,8 +330,6 @@ class ClusterAction(base.Action):
:returns: A tuple containing the result and the corresponding reason.
"""
pause = 0
batch = 0
reason = _('Deletion in progress.')
self.entity.set_status(self.context, consts.CS_DELETING, reason)
node_ids = [node.id for node in self.entity.nodes]
@ -343,25 +341,11 @@ class ClusterAction(base.Action):
}
}
self.data.update(data)
bp = self.data.get('delete', None)
# use policy data if any, or we specify batch as the length of
# nodes' list which means we treat is as one batch.
if bp is not None:
pause = bp.get('pause_time', 0)
batch = bp.get('batch_size', 0)
else:
batch = len(node_ids)
if batch != 0:
# sleep if needed
self._sleep(pause)
for start in range(0, len(node_ids), batch):
end = start + batch
result, reason = self._delete_nodes(node_ids[start:end])
if result != self.RES_OK:
self.entity.eval_status(self.context,
consts.CLUSTER_DELETE)
return result, reason
result, reason = self._delete_nodes(node_ids)
if result != self.RES_OK:
self.entity.eval_status(self.context, consts.CLUSTER_DELETE)
return result, reason
res = self.entity.do_delete(self.context)
if not res:

View File

@ -206,48 +206,6 @@ class ClusterDeleteTest(base.SenlinTestCase):
action_excluded=['CLUSTER_DELETE'],
status=['SUCCEEDED', 'FAILED'])
def test_do_delete_with_batch_policy(self, mock_load):
node1 = mock.Mock(id='NODE_1')
node2 = mock.Mock(id='NODE_2')
cluster = mock.Mock(id='FAKE_CLUSTER', nodes=[node1, node2],
DELETING='DELETING')
cluster.do_delete.return_value = True
mock_load.return_value = cluster
action = ca.ClusterAction(cluster.id, 'CLUSTER_DELETE', self.ctx)
action.data = {
'delete': {
'pause_time': 2,
'batch_size': 1
}
}
mock_delete = self.patchobject(action, '_delete_nodes',
return_value=(action.RES_OK, 'Good'))
# do it
res_code, res_msg = action.do_delete()
expected_data = {
'delete': {
'pause_time': 2,
'batch_size': 1
},
'deletion': {
'destroy_after_deletion': True
}
}
self.assertEqual(action.RES_OK, res_code)
self.assertEqual('Good', res_msg)
self.assertEqual(expected_data, action.data)
cluster.set_status.assert_called_once_with(action.context, 'DELETING',
'Deletion in progress.')
mock_delete.assert_has_calls([
mock.call(['NODE_1']),
mock.call(['NODE_2'])
])
cluster.do_delete.assert_called_once_with(action.context)
def test_do_delete_failed_delete_nodes_timeout(self, mock_load):
node = mock.Mock(id='NODE_1')
cluster = mock.Mock(id='CID', nodes=[node], ACTIVE='ACTIVE',