Fix KeyError when rename to a name is already in use

When a user attempts to rename a project via the PATCH
v3/projects/{project_id} API, and the new name is already in-use, rather
than return a nice error explaining that the name is in use, keystone
blows up and raises `KeyError: 'is_domain'` in
_generate_project_name_conflict_msg.

Change-Id: I56fcd8fe1258e2d1de3e541144649ef619f86a7b
Closes-bug: #1565108
This commit is contained in:
liyingjun 2016-03-31 08:13:49 +08:00
parent 6f9f390981
commit c1be6883f2
2 changed files with 23 additions and 0 deletions

View File

@ -405,6 +405,8 @@ class Manager(manager.Manager):
self._update_project_enabled_cascade(project_id, project_enabled)
try:
project['is_domain'] = (project.get('is_domain') or
original_project['is_domain'])
ret = self.driver.update_project(project_id, project)
except exception.Conflict:
raise exception.Conflict(

View File

@ -94,6 +94,27 @@ class TestResourceManagerNoFixtures(unit.SQLDriverOverrides, unit.TestCase):
self.assertRaises(exception.UnexpectedError,
self.resource_api.ensure_default_domain_exists)
def test_update_project_name_conflict(self):
name = uuid.uuid4().hex
description = uuid.uuid4().hex
domain_attrs = {
'id': CONF.identity.default_domain_id,
'name': name,
'description': description,
}
domain = self.resource_api.create_domain(
CONF.identity.default_domain_id, domain_attrs)
project1 = unit.new_project_ref(domain_id=domain['id'],
name=uuid.uuid4().hex)
self.resource_api.create_project(project1['id'], project1)
project2 = unit.new_project_ref(domain_id=domain['id'],
name=uuid.uuid4().hex)
project = self.resource_api.create_project(project2['id'], project2)
self.assertRaises(exception.Conflict,
self.resource_api.update_project,
project['id'], {'name': project1['name']})
class DomainConfigDriverTests(object):