Skip to content

Commit 44c97cc

Browse files
Dean Troyeropenstack-gerrit
authored andcommitted
Add Identity v2 role and service tests
* Add current auth info (auth_ref) to ClientManager * Fix identity.v2_0.role.ListUserRole to get default user/project from ClientManager.auth_ref * Fix identity.v2_0.role.AddRole call to roles.add_user_role() Change-Id: Ie8bf41c491d97b0292a2b86bdc9b7580989a7f97
1 parent eb405a8 commit 44c97cc

6 files changed

Lines changed: 724 additions & 24 deletions

File tree

‎openstackclient/common/clientmanager.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2012-2013 OpenStack, LLC.
1+
# Copyright 2012-2013 OpenStack Foundation
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License"); you may
44
# not use this file except in compliance with the License. You may obtain
@@ -62,8 +62,11 @@ def __init__(self, token=None, url=None, auth_url=None, project_name=None,
6262
self._api_version = api_version
6363
self._service_catalog = None
6464

65+
self.auth_ref = None
66+
6567
if not self._url:
6668
# Populate other password flow attributes
69+
self.auth_ref = self.identity.auth_ref
6770
self._token = self.identity.auth_token
6871
self._service_catalog = self.identity.service_catalog
6972

‎openstackclient/identity/client.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2012-2013 OpenStack, LLC.
1+
# Copyright 2012-2013 OpenStack Foundation
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License"); you may
44
# not use this file except in compliance with the License. You may obtain
@@ -48,6 +48,7 @@ def make_client(instance):
4848
tenant_id=instance._project_id,
4949
auth_url=instance._auth_url,
5050
region_name=instance._region_name)
51+
instance.auth_ref = client.auth_ref
5152
return client
5253

5354

‎openstackclient/identity/v2_0/role.py‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from cliff import lister
2323
from cliff import show
2424

25+
from openstackclient.common import exceptions
2526
from openstackclient.common import utils
2627

2728

@@ -59,9 +60,10 @@ def take_action(self, parsed_args):
5960
)
6061
user = utils.find_resource(identity_client.users, parsed_args.user)
6162
role = identity_client.roles.add_user_role(
62-
user,
63-
role,
64-
project)
63+
user.id,
64+
role.id,
65+
project.id,
66+
)
6567

6668
info = {}
6769
info.update(role._info)
@@ -150,14 +152,23 @@ def get_parser(self, prog_name):
150152
def take_action(self, parsed_args):
151153
self.log.debug('take_action(%s)' % parsed_args)
152154
identity_client = self.app.client_manager.identity
155+
auth_ref = self.app.client_manager.auth_ref
153156

154-
# user-only roles are not supported in KSL so we are
155-
# required to have a user and project; default to the
156-
# values used for authentication if not specified
157+
# Project and user are required, if not included in command args
158+
# default to the values used for authentication. For token-flow
159+
# authentication they must be included on the command line.
157160
if not parsed_args.project:
158-
parsed_args.project = identity_client.auth_tenant_id
161+
if self.app.client_manager.auth_ref:
162+
parsed_args.project = auth_ref.project_id
163+
else:
164+
msg = "Project must be specified"
165+
raise exceptions.CommandError(msg)
159166
if not parsed_args.user:
160-
parsed_args.user = identity_client.auth_user_id
167+
if self.app.client_manager.auth_ref:
168+
parsed_args.user = auth_ref.user_id
169+
else:
170+
msg = "User must be specified"
171+
raise exceptions.CommandError(msg)
161172

162173
project = utils.find_resource(
163174
identity_client.tenants,

‎openstackclient/tests/identity/fakes.py‎

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,10 @@
1717

1818
from openstackclient.tests import fakes
1919

20-
21-
user_id = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
22-
user_name = 'paul'
23-
user_description = 'Sir Paul'
24-
user_email = 'paul@applecorps.com'
25-
2620
project_id = '8-9-64'
2721
project_name = 'beatles'
2822
project_description = 'Fab Four'
2923

30-
USER = {
31-
'id': user_id,
32-
'name': user_name,
33-
'tenantId': project_id,
34-
'email': user_email,
35-
'enabled': True,
36-
}
37-
3824
PROJECT = {
3925
'id': project_id,
4026
'name': project_name,
@@ -49,9 +35,46 @@
4935
'enabled': True,
5036
}
5137

38+
role_id = '1'
39+
role_name = 'boss'
40+
41+
ROLE = {
42+
'id': role_id,
43+
'name': role_name,
44+
}
45+
46+
service_id = '1925-10-11'
47+
service_name = 'elmore'
48+
service_description = 'Leonard, Elmore, rip'
49+
service_type = 'author'
50+
51+
SERVICE = {
52+
'id': service_id,
53+
'name': service_name,
54+
'description': service_description,
55+
'type': service_type,
56+
}
57+
58+
user_id = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
59+
user_name = 'paul'
60+
user_description = 'Sir Paul'
61+
user_email = 'paul@applecorps.com'
62+
63+
USER = {
64+
'id': user_id,
65+
'name': user_name,
66+
'tenantId': project_id,
67+
'email': user_email,
68+
'enabled': True,
69+
}
70+
5271

5372
class FakeIdentityv2Client(object):
5473
def __init__(self, **kwargs):
74+
self.roles = mock.Mock()
75+
self.roles.resource_class = fakes.FakeResource(None, {})
76+
self.services = mock.Mock()
77+
self.services.resource_class = fakes.FakeResource(None, {})
5578
self.tenants = mock.Mock()
5679
self.tenants.resource_class = fakes.FakeResource(None, {})
5780
self.users = mock.Mock()

0 commit comments

Comments
 (0)