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
This commit is contained in:
parent
017e95c01e
commit
ff10d5577d
@ -170,6 +170,26 @@ class ComputeConfig(BaseConfig):
|
|||||||
return self.get("log_level", 'ERROR')
|
return self.get("log_level", 'ERROR')
|
||||||
|
|
||||||
|
|
||||||
|
class ComputeAdminConfig(BaseConfig):
|
||||||
|
|
||||||
|
SECTION_NAME = "compute-admin"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def username(self):
|
||||||
|
"""Administrative Username to use for Nova API requests."""
|
||||||
|
return self.get("username", "admin")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tenant_name(self):
|
||||||
|
"""Administrative Tenant name to use for Nova API requests."""
|
||||||
|
return self.get("tenant_name", "admin")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def password(self):
|
||||||
|
"""API key to use when authenticating as admin."""
|
||||||
|
return self.get("password", "pass")
|
||||||
|
|
||||||
|
|
||||||
class ImagesConfig(BaseConfig):
|
class ImagesConfig(BaseConfig):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -253,6 +273,7 @@ class TempestConfig:
|
|||||||
|
|
||||||
self._conf = self.load_config(path)
|
self._conf = self.load_config(path)
|
||||||
self.compute = ComputeConfig(self._conf)
|
self.compute = ComputeConfig(self._conf)
|
||||||
|
self.compute_admin = ComputeAdminConfig(self._conf)
|
||||||
self.identity = IdentityConfig(self._conf)
|
self.identity = IdentityConfig(self._conf)
|
||||||
self.images = ImagesConfig(self._conf)
|
self.images = ImagesConfig(self._conf)
|
||||||
|
|
||||||
|
@ -40,12 +40,21 @@ class Manager(object):
|
|||||||
Top level manager for OpenStack Compute clients
|
Top level manager for OpenStack Compute clients
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, username=None, password=None, tenant_name=None):
|
||||||
|
"""
|
||||||
|
We allow overriding of the credentials used within the various
|
||||||
|
client classes managed by the Manager object. Left as None, the
|
||||||
|
standard username/password/tenant_name is used.
|
||||||
|
|
||||||
|
:param username: Override of the username
|
||||||
|
:param password: Override of the password
|
||||||
|
:param tenant_name: Override of the tenant name
|
||||||
|
"""
|
||||||
self.config = tempest.config.TempestConfig()
|
self.config = tempest.config.TempestConfig()
|
||||||
|
|
||||||
username = self.config.compute.username
|
username = username or self.config.compute.username
|
||||||
password = self.config.compute.password
|
password = password or self.config.compute.password
|
||||||
tenant_name = self.config.compute.tenant_name
|
tenant_name = tenant_name or self.config.compute.tenant_name
|
||||||
|
|
||||||
if None in (username, password, tenant_name):
|
if None in (username, password, tenant_name):
|
||||||
msg = ("Missing required credentials. "
|
msg = ("Missing required credentials. "
|
||||||
@ -72,6 +81,35 @@ class Manager(object):
|
|||||||
self.volumes_client = VolumesClient(*client_args)
|
self.volumes_client = VolumesClient(*client_args)
|
||||||
|
|
||||||
|
|
||||||
|
class AltManager(Manager):
|
||||||
|
|
||||||
|
"""
|
||||||
|
Manager object that uses the alt_XXX credentials for its
|
||||||
|
managed client objects
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
conf = tempest.config.TempestConfig()
|
||||||
|
super(AltManager, self).__init__(conf.compute.alt_username,
|
||||||
|
conf.compute.alt_password,
|
||||||
|
conf.compute.alt_tenant_name)
|
||||||
|
|
||||||
|
|
||||||
|
class AdminManager(Manager):
|
||||||
|
|
||||||
|
"""
|
||||||
|
Manager object that uses the alt_XXX credentials for its
|
||||||
|
managed client objects
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
conf = tempest.config.TempestConfig()
|
||||||
|
super(AdminManager, self).__init__(conf.compute_admin.username,
|
||||||
|
conf.compute_admin.password,
|
||||||
|
conf.compute_admin.tenant_name)
|
||||||
|
# TODO(jaypipes): Add Admin-Only client class construction below...
|
||||||
|
|
||||||
|
|
||||||
class ServiceManager(object):
|
class ServiceManager(object):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -36,18 +36,9 @@ class AuthorizationTest(unittest.TestCase):
|
|||||||
and cls.user2_tenant_name != None):
|
and cls.user2_tenant_name != None):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Setup a client instance for the second user
|
cls.other_manager = openstack.AltManager()
|
||||||
auth_url = cls.config.identity.auth_url
|
cls.other_client = cls.other_manager.servers_client
|
||||||
|
cls.other_images_client = cls.other_manager.images_client
|
||||||
if cls.config.identity.strategy == 'keystone':
|
|
||||||
cls.client_args = (cls.config, cls.user2,
|
|
||||||
cls.user2_password,
|
|
||||||
auth_url, cls.user2_tenant_name)
|
|
||||||
else:
|
|
||||||
cls.client_args = (cls.config, cls.user2,
|
|
||||||
cls.user2_password, auth_url)
|
|
||||||
cls.other_client = ServersClient(*cls.client_args)
|
|
||||||
cls.other_images_client = ImagesClient(*cls.client_args)
|
|
||||||
except exceptions.AuthenticationFailure:
|
except exceptions.AuthenticationFailure:
|
||||||
# multi_user is already set to false, just fall through
|
# multi_user is already set to false, just fall through
|
||||||
pass
|
pass
|
||||||
@ -162,12 +153,15 @@ class AuthorizationTest(unittest.TestCase):
|
|||||||
A create server request should fail if the tenant id does not match
|
A create server request should fail if the tenant id does not match
|
||||||
the current user
|
the current user
|
||||||
"""
|
"""
|
||||||
other_servers_client = ServersClient(*self.client_args)
|
try:
|
||||||
|
saved_base_url = self.other_client.client.base_url
|
||||||
# Change the base URL to impersonate another user
|
# Change the base URL to impersonate another user
|
||||||
other_servers_client.client.base_url = self.client.client.base_url
|
self.other_client.client.base_url = self.client.client.base_url
|
||||||
other_servers_client.create_server('test', self.image['id'],
|
self.other_client.create_server('test', self.image['id'],
|
||||||
self.flavor_ref)
|
self.flavor_ref)
|
||||||
|
finally:
|
||||||
|
# Reset the base_url...
|
||||||
|
self.other_client.client.base_url = saved_base_url
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _parse_image_id(self, image_ref):
|
def _parse_image_id(self, image_ref):
|
||||||
|
Loading…
Reference in New Issue
Block a user