From 2ff3ddd356d599677bfc2a1ad08009b2226357eb Mon Sep 17 00:00:00 2001 From: Dolph Mathews Date: Mon, 3 Jun 2013 15:30:10 -0500 Subject: Ignore conflict on v2 auto role assignment (bug 1161963) Change-Id: I10581a39325b4fcdb997ad704c3ee0de494b32e0 --- keystone/identity/controllers.py | 13 +++++++++---- tests/test_keystoneclient.py | 13 +++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/keystone/identity/controllers.py b/keystone/identity/controllers.py index 3e60272d..003ccbe4 100644 --- a/keystone/identity/controllers.py +++ b/keystone/identity/controllers.py @@ -242,10 +242,15 @@ class User(controller.V2Controller): def update_user_project(self, context, user_id, user): """Update the default tenant.""" self.assert_admin(context) - # ensure that we're a member of that tenant - default_tenant_id = user.get('tenantId') - self.identity_api.add_user_to_project(context, - default_tenant_id, user_id) + + try: + # ensure that we're a member of that tenant + self.identity_api.add_user_to_project( + context, user.get('tenantId'), user_id) + except exception.Conflict: + # we're already a member of that tenant + pass + return self.update_user(context, user_id, user) diff --git a/tests/test_keystoneclient.py b/tests/test_keystoneclient.py index 49e3bfc9..bd538700 100644 --- a/tests/test_keystoneclient.py +++ b/tests/test_keystoneclient.py @@ -482,6 +482,19 @@ class KeystoneClientTests(object): tenant_id='bar') self.assertEquals(user2.name, test_username) + def test_update_default_tenant_to_existing_value(self): + client = self.get_client(admin=True) + + user = client.users.create( + name=uuid.uuid4().hex, + password=uuid.uuid4().hex, + email=uuid.uuid4().hex, + tenant_id=self.tenant_bar['id']) + + # attempting to update the tenant with the existing value should work + user = client.users.update_tenant( + user=user, tenant=self.tenant_bar['id']) + def test_user_create_no_name(self): from keystoneclient import exceptions as client_exceptions client = self.get_client(admin=True) -- cgit