Pass keystone session to clients

Pass keystone session while initializing clients
for integration tests. Swift client does not support
session yet and using keystone session for heat client
results in failure with reload of heat-api in
test_reload_on_sighup functional test.

Change-Id: I9c1e455268bf8c796c9052e428ab02bc67699a0f
This commit is contained in:
Rabi Mishra 2016-05-03 11:19:41 +05:30 committed by rabi
parent e1a6c072a1
commit 59713c5265

View File

@ -70,14 +70,13 @@ class ClientManager(object):
def __init__(self, conf): def __init__(self, conf):
self.conf = conf self.conf = conf
if self.conf.auth_url.find('/v'): if self.conf.auth_url.find('/v'):
self.v2_auth_url = self.conf.auth_url.replace('/v3', '/v2.0')
self.auth_version = self.conf.auth_url.split('/v')[1] self.auth_version = self.conf.auth_url.split('/v')[1]
else: else:
raise ValueError(_('Incorrectly specified auth_url config: no ' raise ValueError(_('Incorrectly specified auth_url config: no '
'version found.')) 'version found.'))
self.insecure = self.conf.disable_ssl_certificate_validation self.insecure = self.conf.disable_ssl_certificate_validation
self.ca_file = self.conf.ca_file self.ca_file = self.conf.ca_file
self.identity_client = self._get_identity_client() self.identity_client = self._get_identity_client()
self.orchestration_client = self._get_orchestration_client() self.orchestration_client = self._get_orchestration_client()
self.compute_client = self._get_compute_client() self.compute_client = self._get_compute_client()
@ -131,19 +130,10 @@ class ClientManager(object):
def _get_compute_client(self): def _get_compute_client(self):
region = self.conf.region region = self.conf.region
client_args = (
self.conf.username,
self.conf.password,
self.conf.tenant_name,
# novaclient can not use v3 url
self.v2_auth_url
)
# Create our default Nova client to use in testing # Create our default Nova client to use in testing
return nova_client.Client( return nova_client.Client(
self.NOVA_API_VERSION, self.NOVA_API_VERSION,
*client_args, session=self.identity_client.session,
service_type='compute', service_type='compute',
endpoint_type='publicURL', endpoint_type='publicURL',
region_name=region, region_name=region,
@ -155,12 +145,8 @@ class ClientManager(object):
def _get_network_client(self): def _get_network_client(self):
return neutron_client.Client( return neutron_client.Client(
username=self.conf.username, session=self.identity_client.session,
password=self.conf.password,
tenant_name=self.conf.tenant_name,
endpoint_type='publicURL', endpoint_type='publicURL',
# neutronclient can not use v3 url
auth_url=self.v2_auth_url,
insecure=self.insecure, insecure=self.insecure,
ca_cert=self.ca_file) ca_cert=self.ca_file)
@ -169,11 +155,7 @@ class ClientManager(object):
endpoint_type = 'publicURL' endpoint_type = 'publicURL'
return cinder_client.Client( return cinder_client.Client(
self.CINDERCLIENT_VERSION, self.CINDERCLIENT_VERSION,
self.conf.username, session=self.identity_client.session,
self.conf.password,
self.conf.tenant_name,
# cinderclient can not use v3 url
self.v2_auth_url,
region_name=region, region_name=region,
endpoint_type=endpoint_type, endpoint_type=endpoint_type,
insecure=self.insecure, insecure=self.insecure,
@ -181,6 +163,7 @@ class ClientManager(object):
http_log_debug=True) http_log_debug=True)
def _get_object_client(self): def _get_object_client(self):
# swiftclient does not support keystone sessions yet
args = { args = {
'auth_version': self.auth_version, 'auth_version': self.auth_version,
'tenant_name': self.conf.tenant_name, 'tenant_name': self.conf.tenant_name,
@ -194,8 +177,6 @@ class ClientManager(object):
return swift_client.Connection(**args) return swift_client.Connection(**args)
def _get_metering_client(self): def _get_metering_client(self):
user_domain_name = self.conf.user_domain_name
project_domain_name = self.conf.project_domain_name
try: try:
endpoint = self.identity_client.get_endpoint_url('metering', endpoint = self.identity_client.get_endpoint_url('metering',
self.conf.region) self.conf.region)
@ -203,22 +184,12 @@ class ClientManager(object):
return None return None
else: else:
args = { args = {
'username': self.conf.username, 'session': self.identity_client.session,
'password': self.conf.password,
'tenant_name': self.conf.tenant_name,
'auth_url': self.conf.auth_url,
'insecure': self.insecure, 'insecure': self.insecure,
'cacert': self.ca_file, 'cacert': self.ca_file,
'region_name': self.conf.region, 'region_name': self.conf.region,
'endpoint_type': 'publicURL', 'endpoint_type': 'publicURL',
'service_type': 'metering', 'service_type': 'metering',
} }
# ceilometerclient can't ignore domain details for
# v2 auth_url
if self.auth_version == '3':
args.update(
{'user_domain_name': user_domain_name,
'project_domain_name': project_domain_name})
return ceilometer_client.Client(self.CEILOMETER_VERSION, return ceilometer_client.Client(self.CEILOMETER_VERSION,
endpoint, **args) endpoint, **args)