Use stack ID to create domain project name

If the project for a given stack didn't get deleted for any reason then
launching a stack with the same name will fail as project names
are enforced to be unique.

By using the stack ID instead this issue is avoided if the project delete
didn't occur.

The resulting project name is truncated to the limit of 64.

Change-Id: Iba09cf94bdaa6a92d9520ed1743805862dc1b14d
Closes-Bug: #1288514
This commit is contained in:
Steve Baker 2014-03-06 15:44:42 +13:00
parent 22fd357a5e
commit d44273bfcd
6 changed files with 8 additions and 10 deletions

View File

@ -370,7 +370,7 @@ class KeystoneClientV3(object):
def delete_stack_user(self, user_id):
self.client_v3.users.delete(user=user_id)
def create_stack_domain_project(self, stack_name):
def create_stack_domain_project(self, stack_id):
'''Creates a project in the heat stack-user domain.'''
if not self.stack_domain_id:
# FIXME(shardy): Legacy fallback for folks using old heat.conf
@ -380,7 +380,7 @@ class KeystoneClientV3(object):
return self.context.tenant_id
# Note we use the tenant ID not name to ensure uniqueness in a multi-
# domain environment (where the tenant name may not be globally unique)
project_name = '%s-%s' % (self.context.tenant_id, stack_name)
project_name = ('%s-%s' % (self.context.tenant_id, stack_id))[:64]
desc = "Heat stack user project"
domain_project = self.domain_admin_client.projects.create(
name=project_name,

View File

@ -41,7 +41,7 @@ class StackUser(resource.Resource):
# Check for stack user project, create if not yet set
if not self.stack.stack_user_project_id:
project_id = self.keystone().create_stack_domain_project(
stack_name=self.stack.name)
self.stack.id)
self.stack.set_stack_user_project_id(project_id)
# Create a keystone user in the stack domain project

View File

@ -143,7 +143,7 @@ class FakeKeystoneClient(object):
def delete_stack_domain_project(self, project_id):
pass
def create_stack_domain_project(self, stack_name):
def create_stack_domain_project(self, stack_id):
return 'aprojectid'
def create_stack_domain_user(self, username, project_id, password=None):

View File

@ -1134,8 +1134,7 @@ class KeystoneClientTest(HeatTestCase):
heat_ks_client = heat_keystoneclient.KeystoneClient(ctx)
self.assertEqual('aproject123',
heat_ks_client.create_stack_domain_project(
stack_name='astack'))
heat_ks_client.create_stack_domain_project('astack'))
def test_create_stack_domain_project_legacy_fallback(self):
"""Test the create_stack_domain_project function, fallback path."""
@ -1146,8 +1145,7 @@ class KeystoneClientTest(HeatTestCase):
heat_ks_client = heat_keystoneclient.KeystoneClient(ctx)
self.assertEqual(ctx.tenant_id,
heat_ks_client.create_stack_domain_project(
stack_name='astack'))
heat_ks_client.create_stack_domain_project('astack'))
def test_delete_stack_domain_project(self):

View File

@ -65,7 +65,7 @@ class StackUserTest(HeatTestCase):
self.m.StubOutWithMock(fakes.FakeKeystoneClient,
'create_stack_domain_project')
fakes.FakeKeystoneClient.create_stack_domain_project(
stack_name=stack_name).AndReturn(project_id)
stack.id).AndReturn(project_id)
else:
stack.set_stack_user_project_id(project_id)

View File

@ -121,7 +121,7 @@ class UserTest(HeatTestCase):
self.m.StubOutWithMock(fakes.FakeKeystoneClient,
'create_stack_domain_project')
fakes.FakeKeystoneClient.create_stack_domain_project(
stack_name=stack.name).AndReturn(project_id)
stack.id).AndReturn(project_id)
self.m.StubOutWithMock(short_id, 'get_id')
short_id.get_id(self.resource_id).MultipleTimes().AndReturn('aabbcc')