From d4c226b9d3c65d8756bf7772c7ebe06ed21b43fd Mon Sep 17 00:00:00 2001 From: Oded Le'Sage Date: Tue, 11 Feb 2020 15:44:06 -0600 Subject: [PATCH] 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 --- shaker/engine/deploy.py | 14 +++++++++++--- shaker/openstack/clients/heat.py | 5 ++--- 2 files changed, 13 insertions(+), 6 deletions(-) mode change 100644 => 100755 shaker/engine/deploy.py mode change 100644 => 100755 shaker/openstack/clients/heat.py diff --git a/shaker/engine/deploy.py b/shaker/engine/deploy.py old mode 100644 new mode 100755 index c28b60e..dcc70e9 --- a/shaker/engine/deploy.py +++ b/shaker/engine/deploy.py @@ -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( diff --git a/shaker/openstack/clients/heat.py b/shaker/openstack/clients/heat.py old mode 100644 new mode 100755 index 6593419..cb09d43 --- a/shaker/openstack/clients/heat.py +++ b/shaker/openstack/clients/heat.py @@ -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