Merge pull request #137 from cloudbuilders/keystone-roles-errors

fixing error which would cause setting of user role to fail
This commit is contained in:
Joseph Heck 2011-09-28 13:51:13 -07:00
commit 703801598f
3 changed files with 39 additions and 4 deletions

View File

@ -236,6 +236,11 @@ class User(APIResourceWrapper):
_attrs = ['email', 'enabled', 'id', 'tenantId', 'name']
class Role(APIResourceWrapper):
"""Wrapper around user role"""
_attrs = ['id', 'name', 'description', 'service_id']
class SecurityGroup(APIResourceWrapper):
"""Simple wrapper around openstackx.extras.security_groups.SecurityGroup"""
_attrs = ['id', 'name', 'description', 'tenant_id', 'rules']

View File

@ -198,13 +198,19 @@ def create(request):
user['password'],
user['tenant_id'],
True)
api.account_api(request).role_refs.add_for_tenant_user(
user['tenant_id'], user['id'],
settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE)
messages.success(request,
'%s was successfully created.'
% user['id'])
try:
api.role_add_for_tenant_user(
request, user['tenant_id'], user['id'],
settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE)
except api_exceptions.ApiException, e:
LOG.exception('ApiException while assigning\
role to new user: %s' % user['id'])
messages.error(request, 'Error assigning role to user: %s'
% e.message)
return redirect('syspanel_users')
except api_exceptions.ApiException, e:

View File

@ -543,6 +543,30 @@ class AccountApiTests(test.TestCase):
self.mox.VerifyAll()
def test_role_add_for_tenant_user(self):
account_api = self.stub_account_api()
role = api.Role(APIResource.get_instance())
role.id = TEST_RETURN
role.name = TEST_RETURN
account_api.role_refs = self.mox.CreateMockAnything()
account_api.role_refs.add_for_tenant_user(TEST_TENANT_ID,
TEST_USERNAME,
TEST_RETURN).AndReturn(role)
api._get_role = self.mox.CreateMockAnything()
api._get_role(IsA(http.HttpRequest), IsA(str)).AndReturn(role)
self.mox.ReplayAll()
ret_val = api.role_add_for_tenant_user(self.request,
TEST_TENANT_ID,
TEST_USERNAME,
TEST_RETURN)
self.assertEqual(ret_val, None)
self.mox.VerifyAll()
class AdminApiTests(test.TestCase):
def stub_admin_api(self, count=1):
self.mox.StubOutWithMock(api, 'admin_api')