Pass username/password to client

Currently when python clients are called, Rally authenticates
with keystone client then pass then token to the clients.
This behavior will break the test when the token gets expired.

When the token gets expired, the operations using the token
will receive a 401 error which instructs the clients to
re-new the token with the user crendentials. The python clients
will re-authenticate and try to re-send the operation request.

However, since the credentials are not passed by Rally,
the clients are unable to re-authenticate in which case
the operation will fail and break the test.

This patch is going to pass the credentials to the python clients
to allow the test go beyond the token expiration time.

This patch mainly focus on nova and neutron.
Please note that some clients do not support this
re-authentication mechanism.

Change-Id: I2732e9c7053005b265df3122181f99544d4b6100
This commit is contained in:
Zhongcheng Lao 2015-04-03 16:51:14 +08:00
parent ba108d3016
commit 42fcb22627
2 changed files with 67 additions and 22 deletions

View File

@ -132,6 +132,19 @@ class Clients(object):
url=self.endpoint.auth_url)
return client
def _get_auth_info(self, user_key="username",
password_key="password",
project_name_key="project_id"
):
kw = {
user_key: self.endpoint.username,
password_key: self.endpoint.password,
"auth_url": self.endpoint.auth_url
}
if project_name_key:
kw.update({project_name_key: self.endpoint.tenant_name})
return kw
@cached
def nova(self, version="2"):
"""Return nova client."""
@ -146,7 +159,8 @@ class Clients(object):
http_log_debug=logging.is_debug(),
timeout=CONF.openstack_client_http_timeout,
insecure=self.endpoint.insecure,
cacert=self.endpoint.cacert)
cacert=self.endpoint.cacert,
**self._get_auth_info(password_key="api_key"))
client.set_management_url(compute_api_url)
return client
@ -164,7 +178,10 @@ class Clients(object):
endpoint_url=network_api_url,
timeout=CONF.openstack_client_http_timeout,
insecure=self.endpoint.insecure,
ca_cert=self.endpoint.cacert)
ca_cert=self.endpoint.cacert,
**self._get_auth_info(
project_name_key="tenant_name")
)
return client
@cached
@ -198,18 +215,20 @@ class Clients(object):
token=kc.auth_token,
timeout=CONF.openstack_client_http_timeout,
insecure=self.endpoint.insecure,
cacert=self.endpoint.cacert)
cacert=self.endpoint.cacert,
**self._get_auth_info(project_name_key=None))
return client
@cached
def cinder(self, version="1"):
"""Return cinder client."""
from cinderclient import client as cinder
client = cinder.Client(version, None, None,
client = cinder.Client(version,
http_log_debug=logging.is_debug(),
timeout=CONF.openstack_client_http_timeout,
insecure=self.endpoint.insecure,
cacert=self.endpoint.cacert)
cacert=self.endpoint.cacert,
**self._get_auth_info(password_key="api_key"))
kc = self.keystone()
volume_api_url = kc.service_catalog.url_for(
service_type="volume",
@ -239,7 +258,8 @@ class Clients(object):
token=auth_token,
timeout=CONF.openstack_client_http_timeout,
insecure=self.endpoint.insecure,
cacert=self.endpoint.cacert)
cacert=self.endpoint.cacert,
**self._get_auth_info(project_name_key="tenant_name"))
return client
@cached
@ -264,10 +284,9 @@ class Clients(object):
"""Return Sahara client."""
from saharaclient import client as sahara
client = sahara.Client(version,
username=self.endpoint.username,
api_key=self.endpoint.password,
project_name=self.endpoint.tenant_name,
auth_url=self.endpoint.auth_url)
**self._get_auth_info(
password_key="api_key",
project_name_key="project_name"))
return client
@ -329,14 +348,12 @@ class Clients(object):
"""Returns trove client."""
from troveclient import client as trove
client = trove.Client(version,
username=self.endpoint.username,
api_key=self.endpoint.password,
project_id=self.endpoint.tenant_name,
auth_url=self.endpoint.auth_url,
region_name=self.endpoint.region_name,
timeout=CONF.openstack_client_http_timeout,
insecure=self.endpoint.insecure,
cacert=self.endpoint.cacert)
cacert=self.endpoint.cacert,
**self._get_auth_info(password_key="api_key")
)
return client
@cached
@ -368,7 +385,12 @@ class Clients(object):
preauthurl=object_api_url,
preauthtoken=kc.auth_token,
insecure=self.endpoint.insecure,
cacert=self.endpoint.cacert)
cacert=self.endpoint.cacert,
**self._get_auth_info(
user_key="user",
password_key="key",
project_name_key="tenant_name")
)
return client
@cached

View File

@ -162,7 +162,11 @@ class OSClientsTestCase(test.TestCase):
auth_token=self.fake_keystone.auth_token,
http_log_debug=False,
timeout=cfg.CONF.openstack_client_http_timeout,
insecure=False, cacert=None)
insecure=False, cacert=None,
username=self.endpoint.username,
api_key=self.endpoint.password,
project_id=self.endpoint.tenant_name,
auth_url=self.endpoint.auth_url)
client.set_management_url.assert_called_once_with(
self.service_catalog.url_for.return_value)
self.assertEqual(fake_nova, self.clients.cache["nova"])
@ -181,7 +185,11 @@ class OSClientsTestCase(test.TestCase):
"endpoint_url": self.service_catalog.url_for.return_value,
"timeout": cfg.CONF.openstack_client_http_timeout,
"insecure": self.endpoint.insecure,
"ca_cert": self.endpoint.cacert
"ca_cert": self.endpoint.cacert,
"username": self.endpoint.username,
"password": self.endpoint.password,
"tenant_name": self.endpoint.tenant_name,
"auth_url": self.endpoint.auth_url
}
self.service_catalog.url_for.assert_called_once_with(
service_type="network",
@ -222,9 +230,14 @@ class OSClientsTestCase(test.TestCase):
endpoint_type=consts.EndpointType.PUBLIC,
region_name=self.endpoint.region_name)
mock_cinder.client.Client.assert_called_once_with(
"1", None, None, http_log_debug=False,
"1",
http_log_debug=False,
timeout=cfg.CONF.openstack_client_http_timeout,
insecure=False, cacert=None)
insecure=False, cacert=None,
username=self.endpoint.username,
api_key=self.endpoint.password,
project_id=self.endpoint.tenant_name,
auth_url=self.endpoint.auth_url)
self.assertEqual(fake_cinder.client.management_url,
self.service_catalog.url_for.return_value)
self.assertEqual(fake_cinder.client.auth_token,
@ -248,7 +261,12 @@ class OSClientsTestCase(test.TestCase):
kw = {"os_endpoint": self.service_catalog.url_for.return_value,
"token": self.fake_keystone.auth_token,
"timeout": cfg.CONF.openstack_client_http_timeout,
"insecure": False, "cacert": None}
"insecure": False, "cacert": None,
"username": self.endpoint.username,
"password": self.endpoint.password,
"tenant_name": self.endpoint.tenant_name,
"auth_url": self.endpoint.auth_url
}
mock_ceilometer.client.get_client.assert_called_once_with("2",
**kw)
self.assertEqual(fake_ceilometer,
@ -381,7 +399,12 @@ class OSClientsTestCase(test.TestCase):
"preauthurl": self.service_catalog.url_for.return_value,
"preauthtoken": self.fake_keystone.auth_token,
"insecure": False,
"cacert": None}
"cacert": None,
"user": self.endpoint.username,
"key": self.endpoint.password,
"tenant_name": self.endpoint.tenant_name,
"auth_url": self.endpoint.auth_url
}
mock_swift.client.Connection.assert_called_once_with(**kw)
self.assertEqual(self.clients.cache["swift"], fake_swift)