From: Zane Bitter Date: Fri, 22 Feb 2013 15:05:12 +0000 (+0100) Subject: Use a short_id for naming Swift containers X-Git-Tag: 2014.1~861 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=6d52011ed248edf5a42991cc094a17ff1cf7d7de;p=openstack-build%2Fheat-build.git Use a short_id for naming Swift containers Change-Id: Id6ee6b92f05326e3feda3f2b770fff5864e38e19 Signed-off-by: Zane Bitter --- diff --git a/heat/engine/resources/swift.py b/heat/engine/resources/swift.py index e22b2606..cafeabc8 100644 --- a/heat/engine/resources/swift.py +++ b/heat/engine/resources/swift.py @@ -13,12 +13,11 @@ # 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(): diff --git a/heat/tests/test_swift.py b/heat/tests/test_swift.py index 8fb8a2db..fe3f28a8 100644 --- a/heat/tests/test_swift.py +++ b/heat/tests/test_swift.py @@ -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):