Make the saving cfn-signaling more reliable

1) The metadata saved in manager.py was not always showing up
   in the db (from wait_condition.py)
2) Reuse a little method in parser.py to retrieve the parsed_template
   db entry (and store the parsed_template_id).

Change-Id: Ib5b5474b81c0b7439eb1fa4aec5a0f1f21bbde1c
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
This commit is contained in:
Angus Salkeld 2012-06-20 21:24:44 +10:00
parent cfd1232038
commit 1530a29cfd
3 changed files with 25 additions and 20 deletions

View File

@ -509,8 +509,7 @@ class EngineManager(manager.Manager):
# There's probably an idiomatic way I'm missing right now.
t = deepcopy(pt.template)
t['Resources'][resource_id]['Metadata'] = metadata
pt.template = t
pt.save()
pt.update_and_save({'template': t})
return [None, metadata]
@manager.periodic_task

View File

@ -147,19 +147,27 @@ class Stack(object):
response['ValidateTemplateResult']['Parameters'].append(res)
return response
def parsed_template_get(self):
stack = None
if self.parsed_template_id == 0:
if self.id == 0:
stack = db_api.stack_get(self.context, self.id)
else:
stack = db_api.stack_get_by_name(self.context, self.name)
if stack is None:
return None
self.parsed_template_id = stack.raw_template.parsed_template.id
return db_api.parsed_template_get(self.context,
self.parsed_template_id)
def update_parsed_template(self):
'''
Update the parsed template after each resource has been
created, so commands like describe will work.
'''
if self.parsed_template_id == 0:
stack = db_api.stack_get(self.context, self.id)
if stack:
self.parsed_template_id = stack.raw_template.parsed_template.id
else:
return
pt = db_api.parsed_template_get(self.context, self.parsed_template_id)
pt = self.parsed_template_get()
if pt:
template = self.t.copy()
template['Resources'] = dict((k, r.parsed_template())

View File

@ -78,16 +78,14 @@ class WaitCondition(Resource):
try:
while status == 'WAITING':
pt = None
if self.stack.parsed_template_id:
try:
pt = db_api.parsed_template_get(self.stack.context,
self.stack.parsed_template_id)
except Exception as ex:
if 'not found' in ex:
# it has been deleted
status = 'DELETED'
else:
pass
try:
pt = self.stack.parsed_template_get()
except Exception as ex:
if 'not found' in ex:
# it has been deleted
status = 'DELETED'
else:
pass
if pt:
res = pt.template['Resources'][self.resource_id]