summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Herve <therve@redhat.com>2015-10-14 16:44:42 +0200
committerThomas Herve <therve@redhat.com>2016-06-23 22:15:05 +0200
commitc43ae9a7231b5911376d88f3385c8dbb4d869d3d (patch)
treeb68f4021c32a88884190cdf1498134ee235231e7
parente13e00734d2d563b18ed7428527f1c67f5b8e686 (diff)
downloadheat-c43ae9a7231b5911376d88f3385c8dbb4d869d3d.tar.gz
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 (cherry picked from commit 117e5a0e654111de3f28900228d858cd0683cb1f)
-rw-r--r--heat/engine/stack.py5
-rw-r--r--heat/tests/test_stack_update.py11
2 files changed, 14 insertions, 2 deletions
diff --git a/heat/engine/stack.py b/heat/engine/stack.py
index 744c99a83..5b2f61685 100644
--- a/heat/engine/stack.py
+++ b/heat/engine/stack.py
@@ -1213,6 +1213,7 @@ class Stack(collections.Mapping):
existing_params = environment.Environment({env_fmt.PARAMETERS:
self.t.env.params})
should_rollback = False
+ previous_template_id = None
try:
update_task = update.StackUpdate(
self, newstack, backup_stack,
@@ -1269,6 +1270,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)
@@ -1292,6 +1294,9 @@ class Stack(collections.Mapping):
backup_stack.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))
diff --git a/heat/tests/test_stack_update.py b/heat/tests/test_stack_update.py
index 9db318d13..7ff93a1bf 100644
--- a/heat/tests/test_stack_update.py
+++ b/heat/tests/test_stack_update.py
@@ -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',
@@ -860,8 +866,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)