summaryrefslogtreecommitdiff
path: root/heat/tests/test_stack_update.py
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-08-21 09:57:41 +0000
committerGerrit Code Review <review@openstack.org>2015-08-21 09:57:41 +0000
commitfd1d005296098e109f15d12540275eab79c490c4 (patch)
treefd403e4234626439e22ff66099879b6ab08cfbff /heat/tests/test_stack_update.py
parenta024709f8c77a5bda808b355d5208ffaecc2d12f (diff)
parent2aebdf7f3f38a8505374fa15e6ce9e7586accf88 (diff)
downloadheat-fd1d005296098e109f15d12540275eab79c490c4.tar.gz
Merge "Fix stack-list after failed update"
Diffstat (limited to 'heat/tests/test_stack_update.py')
-rw-r--r--heat/tests/test_stack_update.py102
1 files changed, 102 insertions, 0 deletions
diff --git a/heat/tests/test_stack_update.py b/heat/tests/test_stack_update.py
index daff80e18..b6ede3f80 100644
--- a/heat/tests/test_stack_update.py
+++ b/heat/tests/test_stack_update.py
@@ -19,6 +19,7 @@ from heat.common import template_format
from heat.engine import environment
from heat.engine import resource
from heat.engine import scheduler
+from heat.engine import service
from heat.engine import stack
from heat.engine import template
from heat.rpc import api as rpc_api
@@ -1434,6 +1435,107 @@ class StackUpdateTest(common.HeatTestCase):
mock_delete_A.assert_called_once_with()
self.assertEqual(2, mock_create.call_count)
+ def test_update_failure_recovery_new_param_stack_list(self):
+ '''
+ assertion:
+ check that stack-list is not broken if update fails in between.
+ Also ensure that next update passes
+ '''
+
+ class ResourceTypeA(generic_rsrc.ResourceWithProps):
+ count = 0
+
+ def handle_create(self):
+ ResourceTypeA.count += 1
+ self.resource_id_set('%s%d' % (self.name, self.count))
+
+ def handle_delete(self):
+ return super(ResourceTypeA, self).handle_delete()
+
+ resource._register_class('ResourceTypeA', ResourceTypeA)
+
+ tmpl = {
+ 'HeatTemplateFormatVersion': '2012-12-12',
+ 'Parameters': {
+ 'abc-param': {'Type': 'String'}
+ },
+ 'Resources': {
+ 'AResource': {'Type': 'ResourceTypeA',
+ 'Properties': {'Foo': {'Ref': 'abc-param'}}},
+ 'BResource': {'Type': 'ResourceWithPropsType',
+ 'Properties': {'Foo': {'Ref': 'AResource'}}}
+ }
+ }
+ env1 = environment.Environment({'abc-param': 'abc'})
+ tmpl2 = {
+ 'HeatTemplateFormatVersion': '2012-12-12',
+ 'Parameters': {
+ 'smelly-param': {'Type': 'String'}
+ },
+ 'Resources': {
+ 'AResource': {'Type': 'ResourceTypeA',
+ 'Properties': {'Foo': {'Ref': 'smelly-param'}}},
+ 'BResource': {'Type': 'ResourceWithPropsType',
+ 'Properties': {'Foo': {'Ref': 'AResource'}}}
+ }
+ }
+ env2 = environment.Environment({'smelly-param': 'smelly'})
+
+ self.stack = stack.Stack(self.ctx, 'update_test_stack',
+ template.Template(tmpl, env=env1),
+ disable_rollback=True)
+
+ self.stack.store()
+ self.stack.create()
+
+ self.assertEqual((stack.Stack.CREATE, stack.Stack.COMPLETE),
+ self.stack.state)
+ self.assertEqual('abc', self.stack['AResource'].properties['Foo'])
+ self.assertEqual('AResource1',
+ self.stack['BResource'].properties['Foo'])
+
+ mock_create = self.patchobject(generic_rsrc.ResourceWithProps,
+ 'handle_create',
+ side_effect=[Exception, None])
+ mock_delete = self.patchobject(generic_rsrc.ResourceWithProps,
+ 'handle_delete')
+ mock_delete_A = self.patchobject(ResourceTypeA, 'handle_delete')
+
+ updated_stack = stack.Stack(self.ctx, 'updated_stack',
+ template.Template(tmpl2, env=env2),
+ disable_rollback=True)
+ self.stack.update(updated_stack)
+
+ # Ensure UPDATE FAILED
+ mock_create.assert_called_once_with()
+ self.assertEqual((stack.Stack.UPDATE, stack.Stack.FAILED),
+ self.stack.state)
+ self.assertEqual('smelly', self.stack['AResource'].properties['Foo'])
+
+ # check if heat stack-list works, wherein it tries to fetch template
+ # parameters value from env
+ self.eng = service.EngineService('a-host', 'a-topic')
+ self.eng.list_stacks(self.ctx)
+
+ # Check if next update works fine
+ self.stack = stack.Stack.load(self.ctx, self.stack.id)
+ updated_stack2 = stack.Stack(self.ctx, 'updated_stack',
+ template.Template(tmpl2, env=env2),
+ disable_rollback=True)
+
+ self.stack.update(updated_stack2)
+ self.assertEqual((stack.Stack.UPDATE, stack.Stack.COMPLETE),
+ self.stack.state)
+
+ self.stack = stack.Stack.load(self.ctx, self.stack.id)
+ self.assertEqual('smelly', self.stack['AResource'].properties['Foo'])
+ self.assertEqual('AResource2',
+ self.stack['BResource'].properties['Foo'])
+
+ self.assertEqual(2, mock_delete.call_count)
+ mock_delete_A.assert_called_once_with()
+ self.assertEqual(2, mock_create.call_count)
+
def test_update_replace_parameters(self):
'''
assertion: