Use keystone session with clients

Some of the remaining clients we use now have keystone
session support.

Change-Id: I92dd4c8abea00ea981d7d8e24e396af071c8b080
This commit is contained in:
rabi 2017-02-13 19:16:41 +05:30
parent e33070d846
commit 7fd82e1b78
3 changed files with 22 additions and 26 deletions

View File

@ -16,6 +16,8 @@ from heat.common.i18n import _
from heat.engine.clients import client_plugin
from heat.engine import constraints
from openstack import profile
from openstack import session
from senlinclient import client
from senlinclient.common import exc
@ -28,16 +30,15 @@ class SenlinClientPlugin(client_plugin.ClientPlugin):
VERSION = '1'
def _create(self):
con = self.context
args = {
'auth_url': con.auth_url,
'project_id': con.tenant_id,
'token': con.keystone_session.get_token(),
'user_id': con.user_id,
'auth_plugin': 'token',
}
return client.Client(self.VERSION, **args)
interface = self._get_client_option(CLIENT_NAME, 'endpoint_type')
prof = profile.Profile()
prof.set_interface(self.CLUSTERING, interface)
prof.set_region(self.CLUSTERING, self._get_region_name())
keystone_session = self.context.keystone_session
s = session.Session(session=keystone_session,
auth=keystone_session.auth,
profile=prof)
return client.Client(self.VERSION, session=s)
def generate_spec(self, spec_type, spec_props):
spec = {'properties': spec_props}

View File

@ -45,23 +45,13 @@ class SwiftClientPlugin(client_plugin.ClientPlugin):
service_types = [OBJECT_STORE] = ['object-store']
def _create(self):
con = self.context
endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type')
args = {
'auth_version': '2.0',
'tenant_name': con.project_name,
'user': con.username,
'key': None,
'authurl': None,
'preauthtoken': con.keystone_session.get_token(),
'preauthurl': self.url_for(service_type=self.OBJECT_STORE,
endpoint_type=endpoint_type),
'os_options': {'endpoint_type': endpoint_type},
'cacert': self._get_client_option(CLIENT_NAME, 'ca_file'),
'insecure': self._get_client_option(CLIENT_NAME, 'insecure')
}
return sc.Connection(**args)
os_options = {'endpoint_type': endpoint_type,
'service_type': self.OBJECT_STORE,
'region_name': self._get_region_name()}
return sc.Connection(auth_version=3,
session=self.context.keystone_session,
os_options=os_options)
def is_client_exception(self, ex):
return isinstance(ex, exceptions.ClientException)

View File

@ -137,6 +137,11 @@ class SwiftTest(common.HeatTestCase):
# Test
container = self._create_container(stack)
# call this to populate the url of swiftclient. This is actually
# set in head_container/put_container, but we're patching them in
# this test.
container.client().get_auth()
# Verify Attributes
self.assertEqual(container_name, container.FnGetRefId())
self.assertEqual('82', container.FnGetAtt('ObjectCount'))