Don't delete RawTemplate if it referenced by a stack
When creating a nested stack and pre-storing the raw template, we previously used a try/finally block to ensure that if the stack creation was never started (e.g. because the template failed validation at the other end) that we would delete the raw template again rather than leave it lying around in the DB. However, this catches too broad a range of exceptions. If an exception such as GreenletExit occurs inside this block, then we will attempt to delete the raw template, resulting in a DB IntegrityError either here (because the template id is already referenced by a stack) or when trying to store the stack (because the template is gone). Resolve this by only doing the cleanup on HeatExceptions, which indicates that the other engine has bailed out without storing the stack. Change-Id: Ie24a82b7ce16281c72d4eb66cca8683248628b46 Closes-Bug: #1626256
This commit is contained in:
parent
5ecb4026ae
commit
55c21c18e6
|
@ -283,14 +283,14 @@ class StackResource(resource.Resource):
|
|||
'parent_resource_name': self.name
|
||||
})
|
||||
with self.translate_remote_exceptions:
|
||||
result = None
|
||||
try:
|
||||
result = self.rpc_client()._create_stack(self.context,
|
||||
**kwargs)
|
||||
finally:
|
||||
if adopt_data is None and not result:
|
||||
raw_template.RawTemplate.delete(self.context,
|
||||
kwargs['template_id'])
|
||||
except exception.HeatException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
if adopt_data is None:
|
||||
raw_template.RawTemplate.delete(self.context,
|
||||
kwargs['template_id'])
|
||||
|
||||
self.resource_id_set(result['stack_id'])
|
||||
|
||||
|
@ -478,12 +478,10 @@ class StackResource(resource.Resource):
|
|||
'args': {rpc_api.PARAM_TIMEOUT: timeout_mins}
|
||||
})
|
||||
with self.translate_remote_exceptions:
|
||||
result = None
|
||||
try:
|
||||
result = self.rpc_client()._update_stack(self.context,
|
||||
**kwargs)
|
||||
finally:
|
||||
if not result:
|
||||
self.rpc_client()._update_stack(self.context, **kwargs)
|
||||
except exception.HeatException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
raw_template.RawTemplate.delete(self.context,
|
||||
kwargs['template_id'])
|
||||
return cookie
|
||||
|
|
Loading…
Reference in New Issue