From 2559ff7661dd0a5421d0891a4b7129ae3b353eed Mon Sep 17 00:00:00 2001 From: Jude Cross Date: Tue, 26 Jun 2018 17:19:14 -0700 Subject: [PATCH] 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 --- senlin/engine/actions/cluster_action.py | 2 ++ senlin/tests/unit/engine/actions/test_cluster_action.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/senlin/engine/actions/cluster_action.py b/senlin/engine/actions/cluster_action.py index 6b98ace70..0f5b27b1b 100755 --- a/senlin/engine/actions/cluster_action.py +++ b/senlin/engine/actions/cluster_action.py @@ -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, diff --git a/senlin/tests/unit/engine/actions/test_cluster_action.py b/senlin/tests/unit/engine/actions/test_cluster_action.py index 7bedae163..8745c0f0e 100755 --- a/senlin/tests/unit/engine/actions/test_cluster_action.py +++ b/senlin/tests/unit/engine/actions/test_cluster_action.py @@ -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)