Skip to content

Commit

Permalink
Pass the context when updating raw_templates
Browse files Browse the repository at this point in the history
Without a context, the raw_template was being stored using a different DB
session, with the result that changes did not end up in the database.

Also, don't use the same raw_template DB entry for the backup stack, since
that causes competing modifications to the DB that break rollback.

Change-Id: I6c71c19acac0b87943f36c57c2300cf2b0478aa3
Closes-Bug: #1331872
Related-Bug: #1291905
Related-Bug: #1206702
Related-Bug: #1328342
  • Loading branch information
zaneb committed Jun 27, 2014
1 parent 089f7f0 commit 3ff80e6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
10 changes: 4 additions & 6 deletions heat/engine/parser.py
Expand Up @@ -325,14 +325,14 @@ def add_resource(self, resource):
self.resources[resource.name] = resource
self.t.add_resource(definition)
if self.t.id is not None:
self.t.store()
self.t.store(self.context)

def remove_resource(self, resource_name):
'''Remove the resource with the specified name.'''
del self.resources[resource_name]
self.t.remove_resource(resource_name)
if self.t.id is not None:
self.t.store()
self.t.store(self.context)

def __contains__(self, key):
'''Determine whether the stack contains the specified resource.'''
Expand Down Expand Up @@ -564,10 +564,8 @@ def _backup_stack(self, create_if_missing=True):
LOG.debug('Loaded existing backup stack')
return self.load(self.context, stack=s)
elif create_if_missing:
templ = Template.load(self.context, self.t.id)
templ.files = copy.deepcopy(self.t.files)
prev = type(self)(self.context, self.name, templ, self.env,
owner_id=self.id)
prev = type(self)(self.context, self.name, copy.deepcopy(self.t),
self.env, owner_id=self.id)
prev.store(backup=True)
LOG.debug('Created new backup stack')
return prev
Expand Down
37 changes: 36 additions & 1 deletion heat/tests/test_parser.py
Expand Up @@ -2145,6 +2145,41 @@ def test_update_modify_replace_failed_create_and_delete_2(self):
self.stack.state)
self.m.VerifyAll()

def test_update_add_signal(self):
tmpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources': {'AResource': {'Type': 'GenericResourceType'}}}

self.stack = parser.Stack(self.ctx, 'update_test_stack',
template.Template(tmpl))
self.stack.store()
self.stack.create()
self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE),
self.stack.state)

tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources': {
'AResource': {'Type': 'GenericResourceType'},
'BResource': {'Type': 'GenericResourceType'}}}
updated_stack = parser.Stack(self.ctx, 'updated_stack',
template.Template(tmpl2))

updater = scheduler.TaskRunner(self.stack.update_task, updated_stack)
updater.start()
while 'BResource' not in self.stack:
self.assertFalse(updater.step())
self.assertEqual((parser.Stack.UPDATE, parser.Stack.IN_PROGRESS),
self.stack.state)

# Reload the stack from the DB and prove that it contains the new
# resource already
re_stack = parser.Stack.load(utils.dummy_context(), self.stack.id)
self.assertIn('BResource', re_stack)

updater.run_to_completion()
self.assertEqual((parser.Stack.UPDATE, parser.Stack.COMPLETE),
self.stack.state)
self.assertIn('BResource', self.stack)

def test_update_add_failed_create(self):
tmpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources': {'AResource': {'Type': 'GenericResourceType'}}}
Expand Down Expand Up @@ -2175,7 +2210,7 @@ def test_update_add_failed_create(self):

# Reload the stack from the DB and prove that it contains the failed
# resource (to ensure it will be deleted on stack delete)
re_stack = parser.Stack.load(self.ctx, stack_id=self.stack.id)
re_stack = parser.Stack.load(utils.dummy_context(), self.stack.id)
self.assertIn('BResource', re_stack)
self.m.VerifyAll()

Expand Down

0 comments on commit 3ff80e6

Please sign in to comment.