# 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
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):
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():
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()
@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):