]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Use physical_resource_name() for Swift containers
authorZane Bitter <zbitter@redhat.com>
Mon, 17 Jun 2013 10:24:50 +0000 (12:24 +0200)
committerZane Bitter <zbitter@redhat.com>
Mon, 17 Jun 2013 10:26:20 +0000 (12:26 +0200)
This returns names which are of the same form, but which are based on the
resource id (and hence are stable).

Change-Id: Id091bdef74e07fc0df0e6e4914dae8af8b29384c

heat/engine/resources/s3.py
heat/engine/resources/swift.py
heat/tests/test_s3.py
heat/tests/test_swift.py

index ab7469989e916556296fcc7b9d843be0d166f52e..751f21fdc3130cef65a29f788634533880274117 100644 (file)
@@ -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))
index be16023b73df28cffa1be68bd4a2557b8fff7b6f..57b92f3edcbe715c25044b8e0d96e2afc660644e 100644 (file)
@@ -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():
index 3f08a9eb0dd9411dfb98b29652874e8167a1d02c..7657613448285ae921d42f39dc038327014ed082 100644 (file)
@@ -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),
index 1ad87ca3a9d02512e01e81788965cb1e16fedc00..6b9b2e81592dc5b94b99fb393677ce1a2c72c736 100644 (file)
@@ -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()