From: Zane Bitter Date: Mon, 17 Jun 2013 10:24:50 +0000 (+0200) Subject: Use physical_resource_name() for Swift containers X-Git-Tag: 2014.1~483 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=560804e42852eb8fb9dd2958243135545f6b4d0d;p=openstack-build%2Fheat-build.git Use physical_resource_name() for Swift containers This returns names which are of the same form, but which are based on the resource id (and hence are stable). Change-Id: Id091bdef74e07fc0df0e6e4914dae8af8b29384c --- diff --git a/heat/engine/resources/s3.py b/heat/engine/resources/s3.py index ab746998..751f21fd 100644 --- a/heat/engine/resources/s3.py +++ b/heat/engine/resources/s3.py @@ -17,7 +17,6 @@ from urlparse import urlparse from heat.common import exception from heat.engine import resource -from heat.common import short_id from heat.openstack.common import log as logging from heat.engine import clients @@ -47,13 +46,9 @@ class S3Bucket(resource.Resource): return {'Error': 'S3 services unavailable because of missing swiftclient.'} - def _create_container_name(self): - return '%s-%s-%s' % (self.stack.name, self.name, - short_id.generate_id()) - def handle_create(self): """Create a bucket.""" - container = self._create_container_name() + container = self.physical_resource_name() headers = {} logger.debug('S3Bucket create container %s with headers %s' % (container, headers)) diff --git a/heat/engine/resources/swift.py b/heat/engine/resources/swift.py index be16023b..57b92f3e 100644 --- a/heat/engine/resources/swift.py +++ b/heat/engine/resources/swift.py @@ -17,7 +17,6 @@ from urlparse import urlparse from heat.common import exception from heat.engine import resource -from heat.common import short_id from heat.openstack.common import log as logging from heat.engine import clients @@ -40,10 +39,12 @@ class SwiftContainer(resource.Resource): return {'Error': 'SwiftContainer unavailable due to missing swiftclient.'} - def _create_container_name(self, name=None): - return name or '%s-%s-%s' % (self.stack.name, - self.name, - short_id.generate_id()) + def physical_resource_name(self): + name = self.properties.get('name') + if name: + return name + + return super(SwiftContainer, self).physical_resource_name() @staticmethod def _build_meta_headers(meta_props): @@ -58,7 +59,7 @@ class SwiftContainer(resource.Resource): def handle_create(self): """Create a container.""" - container = self._create_container_name(self.properties.get('name')) + container = self.physical_resource_name() headers = SwiftContainer._build_meta_headers( self.properties['X-Container-Meta']) if 'X-Container-Read' in self.properties.keys(): diff --git a/heat/tests/test_s3.py b/heat/tests/test_s3.py index 3f08a9eb..76576134 100644 --- a/heat/tests/test_s3.py +++ b/heat/tests/test_s3.py @@ -77,16 +77,6 @@ class s3Test(HeatTestCase): self.assertEqual(s3.S3Bucket.CREATE_COMPLETE, rsrc.state) return rsrc - def test_create_container_name(self): - self.m.ReplayAll() - t = template_format.parse(swift_template) - stack = parse_stack(t) - rsrc = s3.S3Bucket('test_resource', - t['Resources']['S3Bucket'], - stack) - self.assertTrue(re.match(self.container_pattern, - rsrc._create_container_name())) - def test_attributes(self): swiftclient.Connection.put_container( mox.Regex(self.container_pattern), diff --git a/heat/tests/test_swift.py b/heat/tests/test_swift.py index 1ad87ca3..6b9b2e81 100644 --- a/heat/tests/test_swift.py +++ b/heat/tests/test_swift.py @@ -81,17 +81,14 @@ class swiftTest(HeatTestCase): def test_create_container_name(self): self.m.ReplayAll() t = template_format.parse(swift_template) + t['Resources']['SwiftContainer']['Properties']['name'] = 'the_name' stack = parse_stack(t) rsrc = swift.SwiftContainer( 'test_resource', t['Resources']['SwiftContainer'], stack) - self.assertTrue(re.match(self.container_pattern, - rsrc._create_container_name())) - self.assertEqual( - 'the_name', - rsrc._create_container_name('the_name')) + self.assertEqual('the_name', rsrc.physical_resource_name()) def test_build_meta_headers(self): self.m.UnsetStubs()