Delete previous template upon update
During stack update, we flip the stack raw_template a number of times. In case of success, we leave the old active raw_template row unlinked to anything, so it needs to be deleted. This patch does so. Change-Id: I6f3ff5bfbac417e3bd6032cabfbc00bd6dec8b02 Closes-Bug: #1506077
This commit is contained in:
parent
dda94d7681
commit
117e5a0e65
|
@ -1186,6 +1186,7 @@ class Stack(collections.Mapping):
|
|||
backup_stack = self._backup_stack()
|
||||
existing_params = environment.Environment({env_fmt.PARAMETERS:
|
||||
self.t.env.params})
|
||||
previous_template_id = None
|
||||
try:
|
||||
update_task = update.StackUpdate(
|
||||
self, newstack, backup_stack,
|
||||
|
@ -1239,6 +1240,7 @@ class Stack(collections.Mapping):
|
|||
backup_stack.delete(backup=True)
|
||||
|
||||
# flip the template to the newstack values
|
||||
previous_template_id = self.t.id
|
||||
self.t = newstack.t
|
||||
template_outputs = self.t[self.t.OUTPUTS]
|
||||
self.outputs = self.resolve_static_data(template_outputs)
|
||||
|
@ -1257,6 +1259,10 @@ class Stack(collections.Mapping):
|
|||
self.t.store(self.context)
|
||||
self.store()
|
||||
|
||||
if previous_template_id is not None:
|
||||
raw_template_object.RawTemplate.delete(self.context,
|
||||
previous_template_id)
|
||||
|
||||
lifecycle_plugin_utils.do_post_ops(self.context, self,
|
||||
newstack, action,
|
||||
(self.status == self.FAILED))
|
||||
|
|
|
@ -17,6 +17,7 @@ import mock
|
|||
|
||||
from heat.common import exception
|
||||
from heat.common import template_format
|
||||
from heat.db.sqlalchemy import api as db_api
|
||||
from heat.engine import environment
|
||||
from heat.engine import resource
|
||||
from heat.engine import scheduler
|
||||
|
@ -50,6 +51,7 @@ class StackUpdateTest(common.HeatTestCase):
|
|||
template.Template(tmpl))
|
||||
self.stack.store()
|
||||
self.stack.create()
|
||||
raw_template_id = self.stack.t.id
|
||||
self.assertEqual((stack.Stack.CREATE, stack.Stack.COMPLETE),
|
||||
self.stack.state)
|
||||
|
||||
|
@ -63,6 +65,10 @@ class StackUpdateTest(common.HeatTestCase):
|
|||
self.assertEqual((stack.Stack.UPDATE, stack.Stack.COMPLETE),
|
||||
self.stack.state)
|
||||
self.assertIn('BResource', self.stack)
|
||||
self.assertNotEqual(raw_template_id, self.stack.t.id)
|
||||
self.assertNotEqual(raw_template_id, self.stack.prev_raw_template_id)
|
||||
self.assertRaises(exception.NotFound,
|
||||
db_api.raw_template_get, self.ctx, raw_template_id)
|
||||
|
||||
def test_update_remove(self):
|
||||
tmpl = {'HeatTemplateFormatVersion': '2012-12-12',
|
||||
|
@ -859,8 +865,9 @@ class StackUpdateTest(common.HeatTestCase):
|
|||
mock_create = self.patchobject(generic_rsrc.ResourceWithProps,
|
||||
'handle_create', side_effect=Exception)
|
||||
|
||||
with mock.patch.object(stack_object.Stack,
|
||||
'update_by_id') as mock_db_update:
|
||||
with mock.patch.object(
|
||||
stack_object.Stack, 'update_by_id',
|
||||
wraps=stack_object.Stack.update_by_id) as mock_db_update:
|
||||
self.stack.update(updated_stack)
|
||||
self.assertEqual((stack.Stack.ROLLBACK, stack.Stack.COMPLETE),
|
||||
self.stack.state)
|
||||
|
|
Loading…
Reference in New Issue