Convergence: Consider resources from old template

While selecting best existing resource from DB, we select the resource
only if it belongs to current or previous template.
But in case of multiple concurrent updates, we could still have the
candidate resource from old template. Hence do not ignore them.

Change-Id: I33243a12aca43242825a256dde2c2969ddb5ef73
Closes-Bug: #1495544
This commit is contained in:
Rakesh H S 2016-02-09 15:36:25 +05:30
parent c8b8ca8bb1
commit 509727fb94
2 changed files with 19 additions and 6 deletions

View File

@ -1213,6 +1213,12 @@ class Stack(collections.Mapping):
self.prev_raw_template_id):
# Current resource is otherwise a good candidate
candidate = ext_rsrc
elif candidate is None:
# In multiple concurrent updates, if candidate is not
# found in current/previous template, it could be found
# in old tmpl.
candidate = ext_rsrc
return candidate
def _update_or_store_resources(self):

View File

@ -416,7 +416,7 @@ class StackConvergenceCreateUpdateDeleteTest(common.HeatTestCase):
convergence=True)
stack.store()
stack.prev_raw_template_id = 2
stack.t.id = 1
stack.t.id = 3
dummy_res = stack.resources['A']
a_res_2 = res.Resource('A', dummy_res.t, stack)
a_res_2.current_template_id = 2
@ -432,17 +432,24 @@ class StackConvergenceCreateUpdateDeleteTest(common.HeatTestCase):
1: a_res_1}
stack.ext_rsrcs_db = existing_res
best_res = stack._get_best_existing_rsrc_db('A')
# should return resource with template id 1 which is current template
self.assertEqual(a_res_1.id, best_res.id)
# should return resource with template id 3 which is current template
self.assertEqual(a_res_3.id, best_res.id)
# no resource with current template id as 1
existing_res = {2: a_res_2,
3: a_res_3}
# no resource with current template id as 3
existing_res = {1: a_res_1,
2: a_res_2}
stack.ext_rsrcs_db = existing_res
best_res = stack._get_best_existing_rsrc_db('A')
# should return resource with template id 2 which is prev template
self.assertEqual(a_res_2.id, best_res.id)
# no resource with current template id as 3 or 2
existing_res = {1: a_res_1}
stack.ext_rsrcs_db = existing_res
best_res = stack._get_best_existing_rsrc_db('A')
# should return resource with template id 1 existing in DB
self.assertEqual(a_res_1.id, best_res.id)
@mock.patch.object(parser.Stack, '_converge_create_or_update')
def test_updated_time_stack_create(self, mock_ccu, mock_cr):
stack = parser.Stack(utils.dummy_context(), 'convg_updated_time_test',