]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Use a short_id for naming S3 containers
authorZane Bitter <zbitter@redhat.com>
Fri, 22 Feb 2013 15:05:12 +0000 (16:05 +0100)
committerZane Bitter <zbitter@redhat.com>
Mon, 25 Feb 2013 09:51:47 +0000 (10:51 +0100)
Change-Id: Iba8ea4eb536d58e1332897cec2059aebbb41b28a
Signed-off-by: Zane Bitter <zbitter@redhat.com>
heat/engine/resources/s3.py
heat/tests/test_s3.py

index 119e43e871145c4c6a3f96dd0662e110f3a3d983..57668bff8cf6e7ebd190ac4c45fbb619de8b025c 100644 (file)
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import binascii
-import os
 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
 
@@ -54,15 +53,13 @@ class S3Bucket(resource.Resource):
             return {'Error':
                     'S3 services unavailable because of missing swiftclient.'}
 
-    @staticmethod
-    def _create_container_name(resource_name):
-        return 'heat-%s-%s' % (resource_name,
-                               binascii.hexlify(os.urandom(10)))
+    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 = S3Bucket._create_container_name(
-            self.physical_resource_name())
+        container = self._create_container_name()
         headers = {}
         logger.debug('S3Bucket create container %s with headers %s' %
                      (container, headers))
index 709b5a512a1bb4a603aa551256e7c527280c5f5a..e4f80e13e048cfd5f5769e1fa482efa5e8ee0f4d 100644 (file)
@@ -42,7 +42,7 @@ class s3Test(unittest.TestCase):
         self.m.StubOutWithMock(swiftclient.Connection, 'delete_container')
         self.m.StubOutWithMock(swiftclient.Connection, 'get_auth')
 
-        self.container_pattern = 'heat-test_stack.test_resource-[0-9a-f]+'
+        self.container_pattern = 'test_stack-test_resource-[0-9a-z]+'
 
     def tearDown(self):
         self.m.UnsetStubs()
@@ -76,10 +76,14 @@ class s3Test(unittest.TestCase):
 
     @skip_if(swiftclient is None, 'unable to import swiftclient')
     def test_create_container_name(self):
-        self.m.UnsetStubs()
+        self.m.ReplayAll()
+        t = self.load_template()
+        stack = self.parse_stack(t)
+        resource = s3.S3Bucket('test_resource',
+                               t['Resources']['S3Bucket'],
+                               stack)
         self.assertTrue(re.match(self.container_pattern,
-                        s3.S3Bucket._create_container_name(
-                        'test_stack.test_resource')))
+                                 resource._create_container_name()))
 
     @skip_if(swiftclient is None, 'unable to import swiftclient')
     def test_attributes(self):