]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Use a short_id for naming Swift 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:45 +0000 (10:51 +0100)
Change-Id: Id6ee6b92f05326e3feda3f2b770fff5864e38e19
Signed-off-by: Zane Bitter <zbitter@redhat.com>
heat/engine/resources/swift.py
heat/tests/test_swift.py

index e22b260693dcb836addc0209748588807660a445..cafeabc8a4213dc046f9760775dc1b54109cb739 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
 
@@ -47,10 +46,10 @@ class SwiftContainer(resource.Resource):
             return {'Error':
                     'SwiftContainer unavailable due to missing swiftclient.'}
 
-    @staticmethod
-    def _create_container_name(resource_name, name=None):
-        return name or 'heat-%s-%s' % (resource_name,
-                                       binascii.hexlify(os.urandom(10)))
+    def _create_container_name(self, name=None):
+        return name or '%s-%s-%s' % (self.stack.name,
+                                     self.name,
+                                     short_id.generate_id())
 
     @staticmethod
     def _build_meta_headers(meta_props):
@@ -65,8 +64,7 @@ class SwiftContainer(resource.Resource):
 
     def handle_create(self):
         """Create a container."""
-        container = SwiftContainer._create_container_name(
-            self.physical_resource_name(), self.properties['name'])
+        container = self._create_container_name(self.properties.get('name'))
         headers = SwiftContainer._build_meta_headers(
             self.properties['X-Container-Meta'])
         if 'X-Container-Read' in self.properties.keys():
index 8fb8a2db8fccf826b7848ee623ba984fb58dec47..fe3f28a87f201df32e80ae4a2c64c0173e1dd596 100644 (file)
@@ -43,7 +43,7 @@ class swiftTest(unittest.TestCase):
         self.m.StubOutWithMock(swiftclient.Connection, 'head_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()
@@ -78,15 +78,19 @@ class swiftTest(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 = swift.SwiftContainer(
+            'test_resource',
+            t['Resources']['SwiftContainer'],
+            stack)
+
         self.assertTrue(re.match(self.container_pattern,
-                        swift.SwiftContainer._create_container_name(
-                        'test_stack.test_resource')))
+                                 resource._create_container_name()))
         self.assertEqual(
             'the_name',
-            swift.SwiftContainer._create_container_name(
-                'test_stack.test_resource',
-                'the_name'))
+            resource._create_container_name('the_name'))
 
     @skip_if(swiftclient is None, 'unable to import swiftclient')
     def test_build_meta_headers(self):