Clean action records after deleting cluster/node

This patch revises do_delete method of of cluster_action
and node_action. Now all action records target on deleted
cluster/node except the on-going CLUSTER/NODE_DELETE
action will be removed from DB after cluster/node is
deleted successfully. The purpose is to prevent action
history increasing too fast.

Implements: blueprint improve-action-event
Change-Id: Id9895be72b226a74d5cd57a8fc8d0f0adde4a629
This commit is contained in:
jonnary 2017-02-18 13:54:30 +08:00
parent 9c665660cb
commit 969990f6b7
4 changed files with 42 additions and 7 deletions

View File

@ -18,7 +18,7 @@ from oslo_utils import timeutils
from osprofiler import profiler
from senlin.common import consts
from senlin.common.i18n import _, _LI
from senlin.common.i18n import _, _LI, _LW
from senlin.common import scaleutils
from senlin.common import utils
from senlin.engine.actions import base
@ -361,6 +361,17 @@ class ClusterAction(base.Action):
self.entity.eval_status(self.context, consts.CLUSTER_DELETE)
return self.RES_ERROR, _('Cannot delete cluster object.')
# Remove all action records which target on deleted
# cluster except the on-going CLUSTER_DELETE action from DB
try:
ao.Action.delete_by_target(
self.context, self.target,
action_excluded=[consts.CLUSTER_DELETE],
status=[consts.ACTION_SUCCEEDED,
consts.ACTION_FAILED])
except Exception as ex:
LOG.warning(_LW('Failed to clean cluster action records: %s'),
ex)
return self.RES_OK, reason
@profiler.trace('ClusterAction.do_add_nodes', hide_args=False)

View File

@ -12,19 +12,23 @@
import eventlet
from oslo_log import log as logging
from osprofiler import profiler
from senlin.common import consts
from senlin.common.i18n import _
from senlin.common.i18n import _, _LW
from senlin.common import scaleutils as su
from senlin.engine.actions import base
from senlin.engine import cluster as cm
from senlin.engine import event as EVENT
from senlin.engine import node as node_mod
from senlin.engine import senlin_lock
from senlin.objects import action as ao
from senlin.objects import node as no
from senlin.policies import base as pb
LOG = logging.getLogger(__name__)
class NodeAction(base.Action):
"""An action that can be performed on a cluster member (node)."""
@ -115,11 +119,21 @@ class NodeAction(base.Action):
params = {'desired_capacity': desired}
cluster.eval_status(self.context, consts.NODE_DELETE, **params)
if res:
return self.RES_OK, _('Node deleted successfully.')
else:
if not res:
return self.RES_ERROR, _('Node deletion failed.')
# Remove all action records which target on deleted
# node except the on-going NODE_DELETE action from DB
try:
ao.Action.delete_by_target(
self.context, self.target,
action_excluded=[consts.NODE_DELETE],
status=[consts.ACTION_SUCCEEDED, consts.ACTION_FAILED])
except Exception as ex:
LOG.warning(_LW('Failed to clean node action records: %s'),
ex)
return self.RES_OK, _('Node deleted successfully.')
@profiler.trace('NodeAction.do_update', hide_args=False)
def do_update(self):
"""Handler for the NODE_UPDATE action.

View File

@ -175,7 +175,8 @@ class ClusterDeleteTest(base.SenlinTestCase):
self.assertEqual('Failed in deleting nodes.', res_msg)
self.assertEqual({}, action.data)
def test_do_delete_success(self, mock_load):
@mock.patch.object(ao.Action, 'delete_by_target')
def test_do_delete_success(self, mock_action, mock_load):
node1 = mock.Mock(id='NODE_1')
node2 = mock.Mock(id='NODE_2')
cluster = mock.Mock(id='FAKE_CLUSTER', nodes=[node1, node2],
@ -200,6 +201,10 @@ class ClusterDeleteTest(base.SenlinTestCase):
'Deletion in progress.')
mock_delete.assert_called_once_with(['NODE_1', 'NODE_2'])
cluster.do_delete.assert_called_once_with(action.context)
mock_action.assert_called_once_with(
action.context, 'FAKE_CLUSTER',
action_excluded=['CLUSTER_DELETE'],
status=['SUCCEEDED', 'FAILED'])
def test_do_delete_with_batch_policy(self, mock_load):
node1 = mock.Mock(id='NODE_1')

View File

@ -21,6 +21,7 @@ from senlin.engine import cluster as cluster_mod
from senlin.engine import event as EVENT
from senlin.engine import node as node_mod
from senlin.engine import senlin_lock as lock
from senlin.objects import action as ao
from senlin.objects import node as node_obj
from senlin.policies import base as policy_mod
from senlin.tests.unit.common import base
@ -146,7 +147,8 @@ class NodeActionTest(base.SenlinTestCase):
cluster.eval_status.assert_called_once_with(
action.context, consts.NODE_CREATE, desired_capacity=11)
def test_do_delete_okay(self, mock_load):
@mock.patch.object(ao.Action, 'delete_by_target')
def test_do_delete_okay(self, mock_action, mock_load):
node = mock.Mock(id='NID')
node.do_delete = mock.Mock(return_value=True)
mock_load.return_value = node
@ -159,6 +161,9 @@ class NodeActionTest(base.SenlinTestCase):
self.assertEqual(action.RES_OK, res_code)
self.assertEqual('Node deleted successfully.', res_msg)
node.do_delete.assert_called_once_with(action.context)
mock_action.assert_called_once_with(
action.context, 'ID', action_excluded=['NODE_DELETE'],
status=['SUCCEEDED', 'FAILED'])
def test_do_delete_failed(self, mock_load):
node = mock.Mock(id='NID')