Add entity refresh to cluster action execute wrapper

This patch adds a cluster entity refresh to the cluster action
execute wrapper. This change makes sure the state of the action
does not become stale while in queue.

Closes-Bug: #1778827

Change-Id: I850cdb38fcd603aa113d2683999dc0fa9c67515e
This commit is contained in:
Jude Cross 2018-06-26 17:19:14 -07:00
parent a19579a6c5
commit 2559ff7661
2 changed files with 8 additions and 2 deletions

View File

@ -1134,6 +1134,8 @@ class ClusterAction(base.Action):
return self.RES_RETRY, 'Failed in locking cluster.'
try:
# Refresh entity state to avoid stale data in action.
self.entity = cluster_mod.Cluster.load(self.context, self.target)
res, reason = self._execute(**kwargs)
finally:
senlin_lock.cluster_lock_release(self.target, self.id,

View File

@ -136,7 +136,9 @@ class ClusterActionTest(base.SenlinTestCase):
self.assertEqual(action.RES_OK, res_code)
self.assertEqual('success', res_msg)
mock_load.assert_called_once_with(action.context, 'FAKE_CLUSTER')
mock_load.assert_has_calls(
[mock.call(action.context, 'FAKE_CLUSTER'),
mock.call(action.context, 'FAKE_CLUSTER')])
mock_acquire.assert_called_once_with(
self.ctx, 'FAKE_CLUSTER', 'ACTION_ID', None,
senlin_lock.CLUSTER_SCOPE, False)
@ -174,7 +176,9 @@ class ClusterActionTest(base.SenlinTestCase):
self.assertEqual(action.RES_ERROR, res_code)
self.assertEqual('Failed execution.', res_msg)
mock_load.assert_called_once_with(action.context, cluster.id)
mock_load.assert_has_calls(
[mock.call(action.context, cluster.id),
mock.call(action.context, cluster.id)])
mock_acquire.assert_called_once_with(
self.ctx, 'CLUSTER_ID', 'ACTION_ID', None,
senlin_lock.CLUSTER_SCOPE, True)