Don't manipulate config for admin creds
Soon this will be global tempest config, so modifying it is not an
option.
Instead the client manager can now be replaced with one which uses admin
credentials when setup_clients_for_admin is called.
blueprint tempest-plugin-support
Change-Id: I9c1b80ec2048d227cc99c06808da90745fcf516e
diff --git a/common/clients.py b/common/clients.py
index 9f58678..96a34b7 100644
--- a/common/clients.py
+++ b/common/clients.py
@@ -67,8 +67,10 @@
NOVA_API_VERSION = '2.1'
CEILOMETER_VERSION = '2'
- def __init__(self, conf):
+ def __init__(self, conf, admin_credentials=False):
self.conf = conf
+ self.admin_credentials = admin_credentials
+
if self.conf.auth_url.find('/v'):
self.auth_version = self.conf.auth_url.split('/v')[1]
else:
@@ -85,6 +87,21 @@
self.object_client = self._get_object_client()
self.metering_client = self._get_metering_client()
+ def _username(self):
+ if self.admin_credentials:
+ return self.conf.admin_username
+ return self.conf.username
+
+ def _password(self):
+ if self.admin_credentials:
+ return self.conf.admin_password
+ return self.conf.password
+
+ def _tenant_name(self):
+ if self.admin_credentials:
+ return self.conf.admin_tenant_name
+ return self.conf.tenant_name
+
def _get_orchestration_client(self):
endpoint = os.environ.get('HEAT_URL')
if os.environ.get('OS_NO_CLIENT_AUTH') == 'True':
@@ -102,16 +119,16 @@
self.HEATCLIENT_VERSION,
endpoint,
token=token,
- username=self.conf.username,
- password=self.conf.password)
+ username=self._username(),
+ password=self._password())
def _get_identity_client(self):
user_domain_name = self.conf.user_domain_name
project_domain_name = self.conf.project_domain_name
kwargs = {
- 'username': self.conf.username,
- 'password': self.conf.password,
- 'tenant_name': self.conf.tenant_name,
+ 'username': self._username(),
+ 'password': self._password(),
+ 'tenant_name': self._tenant_name(),
'auth_url': self.conf.auth_url
}
# keystone v2 can't ignore domain details
@@ -166,8 +183,8 @@
# swiftclient does not support keystone sessions yet
args = {
'auth_version': self.auth_version,
- 'tenant_name': self.conf.tenant_name,
- 'user': self.conf.username,
+ 'tenant_name': self._tenant_name(),
+ 'user': self._username(),
'key': self.conf.password,
'authurl': self.conf.auth_url,
'os_options': {'endpoint_type': 'publicURL'},
diff --git a/common/test.py b/common/test.py
index 413e51f..2bf7771 100644
--- a/common/test.py
+++ b/common/test.py
@@ -89,8 +89,8 @@
else:
self.verify_cert = self.conf.ca_file or True
- def setup_clients(self, conf):
- self.manager = clients.ClientManager(conf)
+ def setup_clients(self, conf, admin_credentials=False):
+ self.manager = clients.ClientManager(conf, admin_credentials)
self.identity_client = self.manager.identity_client
self.orchestration_client = self.manager.orchestration_client
self.compute_client = self.manager.compute_client
@@ -102,15 +102,7 @@
self.client = self.orchestration_client
def setup_clients_for_admin(self):
- self.assertIsNotNone(self.conf.admin_username,
- 'No admin username configured')
- self.assertIsNotNone(self.conf.admin_password,
- 'No admin password configured')
- conf = config.init_conf().heat_plugin
- conf.username = self.conf.admin_username
- conf.password = self.conf.admin_password
- conf.tenant_name = self.conf.admin_tenant_name
- self.setup_clients(conf)
+ self.setup_clients(self.conf, True)
def get_remote_client(self, server_or_ip, username, private_key=None):
if isinstance(server_or_ip, six.string_types):