Skip to content

Commit ff10d55

Browse files
committed
Fixes LP 973338 - Add custom alt and admin manager
* Adds new AltManager, AdminManager derived manager classes * Allows Manager to be inited with custom credentials * Adds config.ComputeAdminConfig class and setup * Updates test_authorization to use AltManager class Change-Id: Iff5b20fbdfb8979a775f30f7e07d6e06b29e6c1c
1 parent 017e95c commit ff10d55

File tree

3 files changed

+75
-22
lines changed

3 files changed

+75
-22
lines changed

tempest/config.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,26 @@ def log_level(self):
170170
return self.get("log_level", 'ERROR')
171171

172172

173+
class ComputeAdminConfig(BaseConfig):
174+
175+
SECTION_NAME = "compute-admin"
176+
177+
@property
178+
def username(self):
179+
"""Administrative Username to use for Nova API requests."""
180+
return self.get("username", "admin")
181+
182+
@property
183+
def tenant_name(self):
184+
"""Administrative Tenant name to use for Nova API requests."""
185+
return self.get("tenant_name", "admin")
186+
187+
@property
188+
def password(self):
189+
"""API key to use when authenticating as admin."""
190+
return self.get("password", "pass")
191+
192+
173193
class ImagesConfig(BaseConfig):
174194

175195
"""
@@ -253,6 +273,7 @@ def __init__(self):
253273

254274
self._conf = self.load_config(path)
255275
self.compute = ComputeConfig(self._conf)
276+
self.compute_admin = ComputeAdminConfig(self._conf)
256277
self.identity = IdentityConfig(self._conf)
257278
self.images = ImagesConfig(self._conf)
258279

tempest/openstack.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,21 @@ class Manager(object):
4040
Top level manager for OpenStack Compute clients
4141
"""
4242

43-
def __init__(self):
43+
def __init__(self, username=None, password=None, tenant_name=None):
44+
"""
45+
We allow overriding of the credentials used within the various
46+
client classes managed by the Manager object. Left as None, the
47+
standard username/password/tenant_name is used.
48+
49+
:param username: Override of the username
50+
:param password: Override of the password
51+
:param tenant_name: Override of the tenant name
52+
"""
4453
self.config = tempest.config.TempestConfig()
4554

46-
username = self.config.compute.username
47-
password = self.config.compute.password
48-
tenant_name = self.config.compute.tenant_name
55+
username = username or self.config.compute.username
56+
password = password or self.config.compute.password
57+
tenant_name = tenant_name or self.config.compute.tenant_name
4958

5059
if None in (username, password, tenant_name):
5160
msg = ("Missing required credentials. "
@@ -72,6 +81,35 @@ def __init__(self):
7281
self.volumes_client = VolumesClient(*client_args)
7382

7483

84+
class AltManager(Manager):
85+
86+
"""
87+
Manager object that uses the alt_XXX credentials for its
88+
managed client objects
89+
"""
90+
91+
def __init__(self):
92+
conf = tempest.config.TempestConfig()
93+
super(AltManager, self).__init__(conf.compute.alt_username,
94+
conf.compute.alt_password,
95+
conf.compute.alt_tenant_name)
96+
97+
98+
class AdminManager(Manager):
99+
100+
"""
101+
Manager object that uses the alt_XXX credentials for its
102+
managed client objects
103+
"""
104+
105+
def __init__(self):
106+
conf = tempest.config.TempestConfig()
107+
super(AdminManager, self).__init__(conf.compute_admin.username,
108+
conf.compute_admin.password,
109+
conf.compute_admin.tenant_name)
110+
# TODO(jaypipes): Add Admin-Only client class construction below...
111+
112+
75113
class ServiceManager(object):
76114

77115
"""

tempest/tests/test_authorization.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,9 @@ def setUpClass(cls):
3636
and cls.user2_tenant_name != None):
3737

3838
try:
39-
# Setup a client instance for the second user
40-
auth_url = cls.config.identity.auth_url
41-
42-
if cls.config.identity.strategy == 'keystone':
43-
cls.client_args = (cls.config, cls.user2,
44-
cls.user2_password,
45-
auth_url, cls.user2_tenant_name)
46-
else:
47-
cls.client_args = (cls.config, cls.user2,
48-
cls.user2_password, auth_url)
49-
cls.other_client = ServersClient(*cls.client_args)
50-
cls.other_images_client = ImagesClient(*cls.client_args)
39+
cls.other_manager = openstack.AltManager()
40+
cls.other_client = cls.other_manager.servers_client
41+
cls.other_images_client = cls.other_manager.images_client
5142
except exceptions.AuthenticationFailure:
5243
# multi_user is already set to false, just fall through
5344
pass
@@ -162,12 +153,15 @@ def test_create_server_fails_when_tenant_incorrect(self):
162153
A create server request should fail if the tenant id does not match
163154
the current user
164155
"""
165-
other_servers_client = ServersClient(*self.client_args)
166-
167-
# Change the base URL to impersonate another user
168-
other_servers_client.client.base_url = self.client.client.base_url
169-
other_servers_client.create_server('test', self.image['id'],
170-
self.flavor_ref)
156+
try:
157+
saved_base_url = self.other_client.client.base_url
158+
# Change the base URL to impersonate another user
159+
self.other_client.client.base_url = self.client.client.base_url
160+
self.other_client.create_server('test', self.image['id'],
161+
self.flavor_ref)
162+
finally:
163+
# Reset the base_url...
164+
self.other_client.client.base_url = saved_base_url
171165

172166
@classmethod
173167
def _parse_image_id(self, image_ref):

0 commit comments

Comments
 (0)