From 4f953f4e8815f00bb3d0ebbfd68338bd668be133 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Wed, 27 Mar 2013 10:02:31 +1300 Subject: [PATCH] Make swift FnGetAtt fault tolerant and block less head_container is now only called for required attributes and will tolerate failure if there is an issue with the underlying container. This was preventing deleting of stacks with swift resources. Possibly this is eligible for backporting to milestone-proposed. Change-Id: I2f489126957f11924943955a7f63a2ebc45f1911 Fixes: bug #1160584 --- heat/engine/resources/swift.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/heat/engine/resources/swift.py b/heat/engine/resources/swift.py index cafeabc8..6d4866df 100644 --- a/heat/engine/resources/swift.py +++ b/heat/engine/resources/swift.py @@ -96,8 +96,6 @@ class SwiftContainer(resource.Resource): def FnGetAtt(self, key): url, token_id = self.swift().get_auth() - if self.resource_id: - headers = self.swift().head_container(self.resource_id) parsed = list(urlparse(url)) if key == 'DomainName': return parsed[1].split(':')[0] @@ -106,12 +104,20 @@ class SwiftContainer(resource.Resource): self.resource_id) elif key == 'RootURL': return '%s://%s%s' % (parsed[0], parsed[1], parsed[2]) - elif key == 'ObjectCount': - return headers['x-container-object-count'] - elif key == 'BytesUsed': - return headers['x-container-bytes-used'] - elif key == 'HeadContainer': - return headers + elif self.resource_id and key in ( + 'ObjectCount', 'BytesUsed', 'HeadContainer'): + try: + headers = self.swift().head_container(self.resource_id) + except clients.swiftclient.ClientException as ex: + logger.warn("Head container failed: %s" % str(ex)) + return None + else: + if key == 'ObjectCount': + return headers['x-container-object-count'] + elif key == 'BytesUsed': + return headers['x-container-bytes-used'] + elif key == 'HeadContainer': + return headers else: raise exception.InvalidTemplateAttribute(resource=self.name, key=key) -- 2.45.2