cleanup per cfg when heat stack creation fails

If a heat stack fails creation (over quota, no more ips, resource
issue, etc) it does not get deleted even when cleanup_on_exit = true

Heat stacks should be deleted per the cleanup_on_exit cfg setting

Failure to cleanup is occuring because the stack_id is curently
empty when the exception is raised.

Change-Id: I1be7b82a4178d20ab267ccc1ec96051a6e8c7120
This commit is contained in:
Oded Le'Sage 2020-02-11 15:44:06 -06:00
parent 539e376978
commit d4c226b9d3
2 changed files with 13 additions and 6 deletions

14
shaker/engine/deploy.py Normal file → Executable file
View File

@ -342,9 +342,13 @@ class Deployment(object):
self._deploy_support_stacks(support_templates, base_dir)
if cfg.CONF.reuse_stack_name is None:
self.stack_id = heat.create_stack(
self.openstack_client.heat, self.stack_name, rendered_template,
merged_parameters, env_file)
try:
self.stack_id = heat.create_stack(
self.openstack_client.heat, self.stack_name,
rendered_template, merged_parameters, env_file)
except heat.exc.StackFailure as err:
self.stack_id = err.args[0]
raise
else:
self.stack_id = heat.get_id_with_name(self.openstack_client.heat,
self.stack_name)
@ -402,6 +406,10 @@ class Deployment(object):
if sys.version_info < (3, 0):
sys.exc_clear()
except heat.exc.StackFailure as err:
self.stackid = err.args[0]
raise
def _get_override(self, override_spec):
def override_ip(agent, ip_type):
return dict(ip=nova.get_server_ip(

5
shaker/openstack/clients/heat.py Normal file → Executable file
View File

@ -84,9 +84,8 @@ def wait_stack_completion(heat_client, stack_id):
dict(res=res.logical_resource_id,
type=res.resource_type,
reason=res.resource_status_reason))
raise Exception('Failed to deploy Heat stack %(id)s. Expected status '
'COMPLETE, but got %(status)s. Reason: %(reason)s' %
dict(id=stack_id, status=status, reason=reason))
raise exc.StackFailure(stack_id, status, reason)
# set the timeout for this method so we don't get stuck polling indefinitely