From cd125f328e3e4e9f517278b04347515eba380d5a Mon Sep 17 00:00:00 2001 From: rabi Date: Tue, 31 May 2016 15:43:07 +0530 Subject: [PATCH] Use keystone session from context in client plugin Now that we store the keystone session in the context, we can use them to create the client plugins. Change-Id: I9c870691ad5f6b1099dba51b5ef4c54360b65122 --- heat/engine/clients/client_plugin.py | 12 +----- heat/engine/clients/os/barbican.py | 9 ++-- heat/engine/clients/os/ceilometer.py | 19 ++------ heat/engine/clients/os/cinder.py | 21 +++------ heat/engine/clients/os/designate.py | 13 ++---- heat/engine/clients/os/glance.py | 19 ++------ heat/engine/clients/os/heat_plugin.py | 17 ++------ .../os/keystone/heat_keystoneclient.py | 8 ++-- heat/engine/clients/os/magnum.py | 10 ++--- heat/engine/clients/os/manila.py | 9 ++-- heat/engine/clients/os/mistral.py | 3 +- heat/engine/clients/os/neutron/__init__.py | 14 ++---- heat/engine/clients/os/nova.py | 19 ++------ heat/engine/clients/os/sahara.py | 10 +---- heat/engine/clients/os/senlin.py | 3 +- heat/engine/clients/os/swift.py | 2 +- heat/engine/clients/os/trove.py | 14 +----- heat/engine/clients/os/zaqar.py | 4 +- heat/engine/resources/volume_base.py | 4 +- heat/tests/clients/test_ceilometer_client.py | 6 +-- heat/tests/clients/test_clients.py | 5 ++- heat/tests/clients/test_designate_client.py | 41 ++++-------------- heat/tests/clients/test_heat_client.py | 43 +++++++++++++++---- heat/tests/clients/test_magnum_client.py | 2 +- 24 files changed, 106 insertions(+), 201 deletions(-) diff --git a/heat/engine/clients/client_plugin.py b/heat/engine/clients/client_plugin.py index ef7e485c88..0a08eb327c 100644 --- a/heat/engine/clients/client_plugin.py +++ b/heat/engine/clients/client_plugin.py @@ -92,14 +92,6 @@ class ClientPlugin(object): """Return a newly created client.""" pass - @property - def auth_token(self): - # Always use the auth_token from the keystone_session, as - # this may be refreshed if the context contains credentials - # which allow reissuing of a new token before the context - # auth_token expiry (e.g trust_id or username/password) - return self.context.keystone_session.get_token() - def url_for(self, **kwargs): keystone_session = self.context.keystone_session @@ -181,7 +173,7 @@ class ClientPlugin(object): 'auth_url': self.context.auth_url, 'service_type': service_type, 'project_id': self.context.tenant_id, - 'token': lambda: self.auth_token, + 'token': self.context.keystone_session.get_token(), 'endpoint_type': endpoint_type, 'os_endpoint': endpoint, 'cacert': self._get_client_option(service_name, 'ca_file'), @@ -191,8 +183,6 @@ class ClientPlugin(object): } return args - # FIXME(kanagaraj-manickam) Update other client plugins to leverage - # this method (bug 1461041) def does_endpoint_exist(self, service_type, diff --git a/heat/engine/clients/os/barbican.py b/heat/engine/clients/os/barbican.py index c5183413b4..5cb1b26506 100644 --- a/heat/engine/clients/os/barbican.py +++ b/heat/engine/clients/os/barbican.py @@ -26,12 +26,11 @@ class BarbicanClientPlugin(client_plugin.ClientPlugin): service_types = [KEY_MANAGER] = ['key-manager'] def _create(self): - endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') - endpoint = self.url_for(service_type=self.KEY_MANAGER, - endpoint_type=endpoint_type) + interface = self._get_client_option(CLIENT_NAME, 'endpoint_type') client = barbican_client.Client( - session=self.context.keystone_session, endpoint=endpoint) - + session=self.context.keystone_session, + service_type=self.KEY_MANAGER, + interface=interface) return client def is_not_found(self, ex): diff --git a/heat/engine/clients/os/ceilometer.py b/heat/engine/clients/os/ceilometer.py index d74cc1e5dc..5080a071a9 100644 --- a/heat/engine/clients/os/ceilometer.py +++ b/heat/engine/clients/os/ceilometer.py @@ -29,24 +29,13 @@ class CeilometerClientPlugin(client_plugin.ClientPlugin): def _create(self): con = self.context - endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') - endpoint = self.url_for(service_type=self.METERING, - endpoint_type=endpoint_type) + interface = self._get_client_option(CLIENT_NAME, 'endpoint_type') aodh_endpoint = self.url_for(service_type=self.ALARMING, - endpoint_type=endpoint_type) + endpoint_type=interface) args = { - 'auth_url': con.auth_url, + 'session': con.keystone_session, + 'interface': interface, 'service_type': self.METERING, - 'project_name': con.project_name, - 'token': lambda: self.auth_token, - 'user_domain_id': con.user_domain, - 'project_domain_id': con.project_domain, - 'endpoint_type': endpoint_type, - 'os_endpoint': endpoint, - 'cacert': self._get_client_option(CLIENT_NAME, 'ca_file'), - 'cert_file': self._get_client_option(CLIENT_NAME, 'cert_file'), - 'key_file': self._get_client_option(CLIENT_NAME, 'key_file'), - 'insecure': self._get_client_option(CLIENT_NAME, 'insecure'), 'aodh_endpoint': aodh_endpoint } diff --git a/heat/engine/clients/os/cinder.py b/heat/engine/clients/os/cinder.py index 31f177cda5..a799e0deb9 100644 --- a/heat/engine/clients/os/cinder.py +++ b/heat/engine/clients/os/cinder.py @@ -67,30 +67,19 @@ class CinderClientPlugin(client_plugin.ClientPlugin): LOG.info(_LI('Creating Cinder client with volume API version %d.'), volume_api_version) - endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') + interface = self._get_client_option(CLIENT_NAME, 'endpoint_type') extensions = cc.discover_extensions(client_version) args = { + 'session': con.keystone_session, + 'extensions': extensions, + 'interface': interface, 'service_type': service_type, - 'auth_url': con.auth_url or '', - 'project_id': con.tenant_id, - 'username': None, - 'api_key': None, - 'endpoint_type': endpoint_type, 'http_log_debug': self._get_client_option(CLIENT_NAME, - 'http_log_debug'), - 'cacert': self._get_client_option(CLIENT_NAME, 'ca_file'), - 'insecure': self._get_client_option(CLIENT_NAME, 'insecure'), - 'extensions': extensions + 'http_log_debug') } client = cc.Client(client_version, **args) - management_url = self.url_for(service_type=service_type, - endpoint_type=endpoint_type) - client.client.auth_token = self.auth_token - client.client.management_url = management_url - client.volume_api_version = volume_api_version - return client @os_client.MEMOIZE_EXTENSIONS diff --git a/heat/engine/clients/os/designate.py b/heat/engine/clients/os/designate.py index 67e4eea5ad..88d0bbe5e2 100644 --- a/heat/engine/clients/os/designate.py +++ b/heat/engine/clients/os/designate.py @@ -30,15 +30,10 @@ class DesignateClientPlugin(client_plugin.ClientPlugin): service_types = [DNS] = ['dns'] def _create(self): - args = self._get_client_args(service_name=CLIENT_NAME, - service_type=self.DNS) - - return client.Client(auth_url=args['auth_url'], - project_id=args['project_id'], - token=args['token'](), - endpoint=args['os_endpoint'], - cacert=args['cacert'], - insecure=args['insecure']) + endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') + return client.Client(session=self.context.keystone_session, + endpoint_type=endpoint_type, + service_type=self.DNS) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) diff --git a/heat/engine/clients/os/glance.py b/heat/engine/clients/os/glance.py index 0c2d31bc2c..6748d82e9a 100644 --- a/heat/engine/clients/os/glance.py +++ b/heat/engine/clients/os/glance.py @@ -35,22 +35,11 @@ class GlanceClientPlugin(client_plugin.ClientPlugin): def _create(self, version=None): con = self.context - endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') - endpoint = self.url_for(service_type=self.IMAGE, - endpoint_type=endpoint_type) - args = { - 'auth_url': con.auth_url, - 'service_type': self.IMAGE, - 'project_id': con.tenant_id, - 'token': self.auth_token, - 'endpoint_type': endpoint_type, - 'cacert': self._get_client_option(CLIENT_NAME, 'ca_file'), - 'cert_file': self._get_client_option(CLIENT_NAME, 'cert_file'), - 'key_file': self._get_client_option(CLIENT_NAME, 'key_file'), - 'insecure': self._get_client_option(CLIENT_NAME, 'insecure') - } + interface = self._get_client_option(CLIENT_NAME, 'endpoint_type') - return gc.Client(version, endpoint, **args) + return gc.Client(version, session=con.keystone_session, + interface=interface, + service_type=self.IMAGE) def _find_with_attr(self, entity, **kwargs): """Find a item for entity with attributes matching ``**kwargs``.""" diff --git a/heat/engine/clients/os/heat_plugin.py b/heat/engine/clients/os/heat_plugin.py index f1a759c0ca..a43e6a618d 100644 --- a/heat/engine/clients/os/heat_plugin.py +++ b/heat/engine/clients/os/heat_plugin.py @@ -30,27 +30,18 @@ class HeatClientPlugin(client_plugin.ClientPlugin): CLOUDFORMATION] = ['orchestration', 'cloudformation'] def _create(self): - args = { - 'auth_url': self.context.auth_url, - 'token': self.auth_token, - 'username': None, - 'password': None, - 'ca_file': self._get_client_option(CLIENT_NAME, 'ca_file'), - 'cert_file': self._get_client_option(CLIENT_NAME, 'cert_file'), - 'key_file': self._get_client_option(CLIENT_NAME, 'key_file'), - 'insecure': self._get_client_option(CLIENT_NAME, 'insecure') - } - endpoint = self.get_heat_url() + args = {} if self._get_client_option(CLIENT_NAME, 'url'): # assume that the heat API URL is manually configured because # it is not in the keystone catalog, so include the credentials # for the standalone auth_password middleware args['username'] = self.context.username args['password'] = self.context.password - del(args['token']) - return hc.Client('1', endpoint, **args) + return hc.Client('1', endpoint, + session=self.context.keystone_session, + **args) def is_not_found(self, ex): return isinstance(ex, exc.HTTPNotFound) diff --git a/heat/engine/clients/os/keystone/heat_keystoneclient.py b/heat/engine/clients/os/keystone/heat_keystoneclient.py index 196d474a49..7c77d0eca2 100644 --- a/heat/engine/clients/os/keystone/heat_keystoneclient.py +++ b/heat/engine/clients/os/keystone/heat_keystoneclient.py @@ -19,14 +19,13 @@ import weakref from keystoneauth1 import exceptions as ks_exception from keystoneauth1.identity import generic as ks_auth -from keystoneauth1 import session + from keystoneclient.v3 import client as kc_v3 from oslo_config import cfg from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import importutils -from heat.common import config from heat.common import context from heat.common import exception from heat.common.i18n import _ @@ -77,7 +76,7 @@ class KsClientWrapper(object): self._domain_admin_auth = None self._domain_admin_client = None - self.session = session.Session(**config.get_ssl_options('keystone')) + self.session = self.context.keystone_session self.v3_endpoint = self.context.keystone_v3_endpoint if self.context.trust_id: @@ -153,8 +152,7 @@ class KsClientWrapper(object): return self._domain_admin_client def _v3_client_init(self): - client = kc_v3.Client(session=self.session, - auth=self.context.auth_plugin) + client = kc_v3.Client(session=self.session) if hasattr(self.context.auth_plugin, 'get_access'): # NOTE(jamielennox): get_access returns the current token without diff --git a/heat/engine/clients/os/magnum.py b/heat/engine/clients/os/magnum.py index d67e141256..fe89ad69f1 100644 --- a/heat/engine/clients/os/magnum.py +++ b/heat/engine/clients/os/magnum.py @@ -26,13 +26,11 @@ class MagnumClientPlugin(client_plugin.ClientPlugin): service_types = [CONTAINER] = ['container-infra'] def _create(self): - endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') - endpoint = self.url_for(service_type=self.CONTAINER, - endpoint_type=endpoint_type) - + interface = self._get_client_option(CLIENT_NAME, 'endpoint_type') args = { - 'magnum_url': endpoint, - 'input_auth_token': self.auth_token + 'interface': interface, + 'service_type': self.CONTAINER, + 'session': self.context.keystone_session } client = magnum_client.Client(**args) return client diff --git a/heat/engine/clients/os/manila.py b/heat/engine/clients/os/manila.py index 085e0afe10..d72939549f 100644 --- a/heat/engine/clients/os/manila.py +++ b/heat/engine/clients/os/manila.py @@ -29,14 +29,11 @@ class ManilaClientPlugin(client_plugin.ClientPlugin): def _create(self): endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') - endpoint = self.url_for(service_type=self.SHARE, - endpoint_type=endpoint_type) - args = { - 'service_catalog_url': endpoint, - 'input_auth_token': self.auth_token + 'endpoint_type': endpoint_type, + 'service_type': self.SHARE, + 'session': self.context.keystone_session } - client = manila_client.Client(MANILACLIENT_VERSION, **args) return client diff --git a/heat/engine/clients/os/mistral.py b/heat/engine/clients/os/mistral.py index 50c9132ca7..106bade4d7 100644 --- a/heat/engine/clients/os/mistral.py +++ b/heat/engine/clients/os/mistral.py @@ -29,10 +29,9 @@ class MistralClientPlugin(client_plugin.ClientPlugin): endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') endpoint = self.url_for(service_type=self.WORKFLOW_V2, endpoint_type=endpoint_type) - args = { 'mistral_url': endpoint, - 'auth_token': self.auth_token + 'auth_token': self.context.keystone_session.get_token() } client = mistral_client.client(**args) diff --git a/heat/engine/clients/os/neutron/__init__.py b/heat/engine/clients/os/neutron/__init__.py index 1a84441778..93226891b2 100644 --- a/heat/engine/clients/os/neutron/__init__.py +++ b/heat/engine/clients/os/neutron/__init__.py @@ -30,19 +30,11 @@ class NeutronClientPlugin(client_plugin.ClientPlugin): def _create(self): con = self.context - - endpoint_type = self._get_client_option('neutron', 'endpoint_type') - endpoint = self.url_for(service_type=self.NETWORK, - endpoint_type=endpoint_type) - + interface = self._get_client_option('neutron', 'endpoint_type') args = { - 'auth_url': con.auth_url, + 'session': con.keystone_session, 'service_type': self.NETWORK, - 'token': self.auth_token, - 'endpoint_url': endpoint, - 'endpoint_type': endpoint_type, - 'ca_cert': self._get_client_option('neutron', 'ca_file'), - 'insecure': self._get_client_option('neutron', 'insecure') + 'interface': interface } return nc.Client(**args) diff --git a/heat/engine/clients/os/nova.py b/heat/engine/clients/os/nova.py index d3b7c4170a..62082b085e 100644 --- a/heat/engine/clients/os/nova.py +++ b/heat/engine/clients/os/nova.py @@ -63,29 +63,18 @@ class NovaClientPlugin(client_plugin.ClientPlugin): def _create(self): endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') - management_url = self.url_for(service_type=self.COMPUTE, - endpoint_type=endpoint_type) extensions = nc.discover_extensions(NOVA_API_VERSION) args = { - 'project_id': self.context.tenant_id, - 'auth_url': self.context.auth_url, - 'auth_token': self.auth_token, - 'service_type': self.COMPUTE, - 'username': None, - 'api_key': None, + 'session': self.context.keystone_session, 'extensions': extensions, - 'endpoint_type': endpoint_type, + 'interface': endpoint_type, + 'service_type': self.COMPUTE, 'http_log_debug': self._get_client_option(CLIENT_NAME, - 'http_log_debug'), - 'cacert': self._get_client_option(CLIENT_NAME, 'ca_file'), - 'insecure': self._get_client_option(CLIENT_NAME, 'insecure') + 'http_log_debug') } client = nc.Client(NOVA_API_VERSION, **args) - - client.client.set_management_url(management_url) - return client def is_not_found(self, ex): diff --git a/heat/engine/clients/os/sahara.py b/heat/engine/clients/os/sahara.py index a02bfe7cf2..253ebe2f31 100644 --- a/heat/engine/clients/os/sahara.py +++ b/heat/engine/clients/os/sahara.py @@ -35,16 +35,10 @@ class SaharaClientPlugin(client_plugin.ClientPlugin): def _create(self): con = self.context endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') - endpoint = self.url_for(service_type=self.DATA_PROCESSING, - endpoint_type=endpoint_type) args = { + 'endpoint_type': endpoint_type, 'service_type': self.DATA_PROCESSING, - 'input_auth_token': self.auth_token, - 'auth_url': con.auth_url, - 'project_name': con.tenant, - 'sahara_url': endpoint, - 'insecure': self._get_client_option(CLIENT_NAME, 'insecure'), - 'cacert': self._get_client_option(CLIENT_NAME, 'ca_file') + 'session': con.keystone_session } client = sahara_client.Client('1.1', **args) return client diff --git a/heat/engine/clients/os/senlin.py b/heat/engine/clients/os/senlin.py index df5b5fe858..dfab28649f 100644 --- a/heat/engine/clients/os/senlin.py +++ b/heat/engine/clients/os/senlin.py @@ -32,9 +32,10 @@ class SenlinClientPlugin(client_plugin.ClientPlugin): args = { 'auth_url': con.auth_url, 'project_id': con.tenant_id, - 'token': self.auth_token, + 'token': con.keystone_session.get_token(), 'user_id': con.user_id, 'auth_plugin': 'token', + } return client.Client(self.VERSION, **args) diff --git a/heat/engine/clients/os/swift.py b/heat/engine/clients/os/swift.py index e5e550c292..5a7f88d448 100644 --- a/heat/engine/clients/os/swift.py +++ b/heat/engine/clients/os/swift.py @@ -48,7 +48,7 @@ class SwiftClientPlugin(client_plugin.ClientPlugin): 'user': con.username, 'key': None, 'authurl': None, - 'preauthtoken': self.auth_token, + '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}, diff --git a/heat/engine/clients/os/trove.py b/heat/engine/clients/os/trove.py index d260ee0fcf..362b05aa89 100644 --- a/heat/engine/clients/os/trove.py +++ b/heat/engine/clients/os/trove.py @@ -33,22 +33,12 @@ class TroveClientPlugin(client_plugin.ClientPlugin): con = self.context endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') args = { + 'endpoint_type': endpoint_type, 'service_type': self.DATABASE, - 'auth_url': con.auth_url or '', - 'proxy_token': con.auth_token, - 'username': None, - 'password': None, - 'cacert': self._get_client_option(CLIENT_NAME, 'ca_file'), - 'insecure': self._get_client_option(CLIENT_NAME, 'insecure'), - 'endpoint_type': endpoint_type + 'session': con.keystone_session } client = tc.Client('1.0', **args) - management_url = self.url_for(service_type=self.DATABASE, - endpoint_type=endpoint_type) - client.client.auth_token = self.auth_token - client.client.management_url = management_url - return client def validate_datastore(self, datastore_type, datastore_version, diff --git a/heat/engine/clients/os/zaqar.py b/heat/engine/clients/os/zaqar.py index 32151ccc2e..e02432e06c 100644 --- a/heat/engine/clients/os/zaqar.py +++ b/heat/engine/clients/os/zaqar.py @@ -34,7 +34,9 @@ class ZaqarClientPlugin(client_plugin.ClientPlugin): DEFAULT_TTL = 3600 def _create(self): - return self.create_for_tenant(self.context.tenant_id, self.auth_token) + return self.create_for_tenant( + self.context.tenant_id, + self.context.keystone_session.get_token()) def create_for_tenant(self, tenant_id, token): con = self.context diff --git a/heat/engine/resources/volume_base.py b/heat/engine/resources/volume_base.py index 5334a0a61d..8cf0c04226 100644 --- a/heat/engine/resources/volume_base.py +++ b/heat/engine/resources/volume_base.py @@ -30,12 +30,12 @@ class BaseVolume(resource.Resource): vol = cinder.volumes.get(vol_id) kwargs = self._fetch_name_and_description( - cinder.volume_api_version) + cinder.version) cinder.volumes.update(vol_id, **kwargs) else: kwargs = self._create_arguments() kwargs.update(self._fetch_name_and_description( - cinder.volume_api_version)) + cinder.version)) vol = cinder.volumes.create(**kwargs) self.resource_id_set(vol.id) diff --git a/heat/tests/clients/test_ceilometer_client.py b/heat/tests/clients/test_ceilometer_client.py index 4ab98d99ca..996176f715 100644 --- a/heat/tests/clients/test_ceilometer_client.py +++ b/heat/tests/clients/test_ceilometer_client.py @@ -11,7 +11,7 @@ # License for the specific language governing permissions and limitations # under the License. -from ceilometerclient.openstack.common.apiclient import client as cc +from ceilometerclient.v2 import client as cc from heat.tests import common from heat.tests import utils @@ -20,10 +20,8 @@ from heat.tests import utils class CeilometerClientPluginTest(common.HeatTestCase): def test_create(self): - self.patchobject(cc.HTTPClient, 'client_request') + self.patchobject(cc.Client, '_get_alarm_client') context = utils.dummy_context() plugin = context.clients.client_plugin('ceilometer') client = plugin.client() self.assertIsNotNone(client.alarms) - self.assertEqual('http://server.test:5000/v2.0', - client.auth_plugin.opts['auth_url']) diff --git a/heat/tests/clients/test_clients.py b/heat/tests/clients/test_clients.py index bc1306bd1d..90013e538d 100644 --- a/heat/tests/clients/test_clients.py +++ b/heat/tests/clients/test_clients.py @@ -205,7 +205,8 @@ class ClientPluginTest(common.HeatTestCase): def test_get_client_args(self): ctxt = mock.Mock() plugin = FooClientsPlugin(ctxt) - + self.patchobject(ctxt.keystone_session, 'get_token', + return_value='5678') plugin.url_for = mock.Mock(return_value='sample_endpoint_url') plugin.context.auth_url = 'sample_auth_url' plugin.context.tenant_id = 'sample_project_id' @@ -239,7 +240,7 @@ class ClientPluginTest(common.HeatTestCase): 'invalid project_id') self.assertEqual('5678', - args['token'](), + args['token'], 'invalid auth_token') self.assertEqual('sample_endpoint_url', diff --git a/heat/tests/clients/test_designate_client.py b/heat/tests/clients/test_designate_client.py index 1620fe81aa..60f92d958e 100644 --- a/heat/tests/clients/test_designate_client.py +++ b/heat/tests/clients/test_designate_client.py @@ -11,11 +11,10 @@ # License for the specific language governing permissions and limitations # under the License. -import mock -import six - from designateclient import exceptions as designate_exceptions from designateclient import v1 as designate_client +import mock +import six from heat.common import exception as heat_exception from heat.engine.clients.os import designate as client @@ -43,40 +42,18 @@ class DesignateDomainConstraintTest(common.HeatTestCase): class DesignateClientPluginTest(common.HeatTestCase): + @mock.patch.object(designate_client, 'Client') - @mock.patch.object(client.DesignateClientPlugin, '_get_client_args') - def test_client(self, - get_client_args, - client_designate): - args = dict( - auth_url='auth_url', - project_id='project_id', - token=lambda: '', - os_endpoint='os_endpoint', - cacert='cacert', - insecure='insecure' - ) - get_client_args.return_value = args - - client_plugin = client.DesignateClientPlugin( - context=mock.MagicMock() - ) + def test_client(self, client_designate): + context = mock.Mock() + session = mock.Mock() + context.keystone_session = session + client_plugin = client.DesignateClientPlugin(context) client_plugin.client() - # Make sure the right args are created - get_client_args.assert_called_once_with( - service_name='designate', - service_type='dns' - ) - # Make sure proper client is created with expected args client_designate.assert_called_once_with( - auth_url='auth_url', - project_id='project_id', - token='', - endpoint='os_endpoint', - cacert='cacert', - insecure='insecure' + endpoint_type='publicURL', service_type='dns', session=session ) diff --git a/heat/tests/clients/test_heat_client.py b/heat/tests/clients/test_heat_client.py index 6c391e137d..58dc95a1ac 100644 --- a/heat/tests/clients/test_heat_client.py +++ b/heat/tests/clients/test_heat_client.py @@ -106,6 +106,7 @@ class KeystoneClientTest(common.HeatTestCase): mock_auth_ref = self.m.CreateMockAnything() mock_ks_auth = self.m.CreateMockAnything() + self.patchobject(mock_ks_auth, 'get_auth_ref') if method == 'token': p = ks_token_endpoint.Token(token='abcd1234', endpoint='http://server.test:5000/v3') @@ -138,8 +139,7 @@ class KeystoneClientTest(common.HeatTestCase): p.AndReturn(mock_ks_auth) if client: - c = kc_v3.Client(session=mox.IsA(ks_session.Session), - auth=mock_ks_auth) + c = kc_v3.Client(session=mox.IsA(ks_session.Session)) c.AndReturn(self.mock_ks_v3_client) if stub_trust_context: @@ -220,6 +220,7 @@ class KeystoneClientTest(common.HeatTestCase): """Test creating a stack domain user.""" ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None # mock keystone client functions @@ -277,6 +278,7 @@ class KeystoneClientTest(common.HeatTestCase): def test_create_stack_domain_user_error_norole(self): """Test creating a stack domain user, no role error path.""" ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None self._stub_domain_admin_client(domain_id=None) @@ -296,6 +298,7 @@ class KeystoneClientTest(common.HeatTestCase): """Test deleting a stack domain user.""" ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None # mock keystone client functions @@ -340,6 +343,7 @@ class KeystoneClientTest(common.HeatTestCase): """Test deleting a stack domain user, wrong domain.""" ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None # mock keystone client functions @@ -362,6 +366,7 @@ class KeystoneClientTest(common.HeatTestCase): """Test deleting a stack domain user, wrong project.""" ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None # mock keystone client functions @@ -484,9 +489,8 @@ class KeystoneClientTest(common.HeatTestCase): ctx.trust_id = None ctx.username = None ctx.password = None - heat_ks_client = heat_keystoneclient.KeystoneClient(ctx) self.assertRaises(exception.AuthorizationFailure, - heat_ks_client._v3_client_init) + heat_keystoneclient.KeystoneClient, ctx) def test_create_trust_context_trust_id(self): @@ -596,6 +600,7 @@ class KeystoneClientTest(common.HeatTestCase): cfg.CONF.clear_override('stack_domain_admin_password') ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.username = None ctx.password = None ctx.trust_id = None @@ -778,6 +783,7 @@ class KeystoneClientTest(common.HeatTestCase): """Test enabling a stack domain user.""" ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None # mock keystone client functions @@ -813,6 +819,7 @@ class KeystoneClientTest(common.HeatTestCase): """Test enabling a stack domain user, wrong project.""" ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None # mock keystone client functions @@ -828,6 +835,7 @@ class KeystoneClientTest(common.HeatTestCase): """Test enabling a stack domain user, wrong domain.""" ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None # mock keystone client functions @@ -843,6 +851,7 @@ class KeystoneClientTest(common.HeatTestCase): """Test disabling a stack domain user.""" ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None # mock keystone client functions @@ -878,6 +887,7 @@ class KeystoneClientTest(common.HeatTestCase): """Test disabling a stack domain user, wrong project.""" ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None # mock keystone client functions @@ -893,6 +903,7 @@ class KeystoneClientTest(common.HeatTestCase): """Test disabling a stack domain user, wrong domain.""" ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None # mock keystone client functions @@ -906,6 +917,7 @@ class KeystoneClientTest(common.HeatTestCase): def test_delete_stack_domain_user_keypair(self): ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None # mock keystone client functions @@ -949,6 +961,7 @@ class KeystoneClientTest(common.HeatTestCase): def test_delete_stack_domain_user_keypair_error_project(self): ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None # mock keystone client functions @@ -964,6 +977,7 @@ class KeystoneClientTest(common.HeatTestCase): def test_delete_stack_domain_user_keypair_error_domain(self): ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None # mock keystone client functions @@ -1028,6 +1042,7 @@ class KeystoneClientTest(common.HeatTestCase): self._stub_domain_admin_client(domain_id=None) ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None ex_data = {'access': 'dummy_access2', @@ -1167,6 +1182,7 @@ class KeystoneClientTest(common.HeatTestCase): """Test getting ec2 credential error path.""" ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None heat_ks_client = heat_keystoneclient.KeystoneClient(ctx) @@ -1223,6 +1239,7 @@ class KeystoneClientTest(common.HeatTestCase): """Test deleting ec2 credential error path.""" ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None self.m.ReplayAll() @@ -1234,6 +1251,7 @@ class KeystoneClientTest(common.HeatTestCase): """Test the create_stack_domain_project function.""" ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None expected_name = '%s-astack' % ctx.tenant_id @@ -1257,7 +1275,7 @@ class KeystoneClientTest(common.HeatTestCase): ctx = utils.dummy_context() ctx.trust_id = None - + self.patchobject(ctx, '_create_auth_plugin') heat_ks_client = heat_keystoneclient.KeystoneClient(ctx) self.assertEqual(ctx.tenant_id, heat_ks_client.create_stack_domain_project('astack')) @@ -1277,6 +1295,7 @@ class KeystoneClientTest(common.HeatTestCase): self.m.ReplayAll() ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None heat_ks_client = heat_keystoneclient.KeystoneClient(ctx) heat_ks_client.delete_stack_domain_project(project_id='aprojectid') @@ -1292,6 +1311,7 @@ class KeystoneClientTest(common.HeatTestCase): self.m.ReplayAll() ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None heat_ks_client = heat_keystoneclient.KeystoneClient(ctx) heat_ks_client.delete_stack_domain_project(project_id='aprojectid') @@ -1307,6 +1327,7 @@ class KeystoneClientTest(common.HeatTestCase): self.m.ReplayAll() ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None heat_ks_client = heat_keystoneclient.KeystoneClient(ctx) heat_ks_client.delete_stack_domain_project(project_id='aprojectid') @@ -1325,6 +1346,7 @@ class KeystoneClientTest(common.HeatTestCase): self.m.ReplayAll() ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None heat_ks_client = heat_keystoneclient.KeystoneClient(ctx) heat_ks_client.delete_stack_domain_project(project_id='aprojectid') @@ -1336,6 +1358,7 @@ class KeystoneClientTest(common.HeatTestCase): self._clear_domain_override() ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None heat_ks_client = heat_keystoneclient.KeystoneClient(ctx) heat_ks_client.delete_stack_domain_project(project_id='aprojectid') @@ -1350,9 +1373,10 @@ class KeystoneClientTest(common.HeatTestCase): def test_stack_domain_user_token(self): """Test stack_domain_user_token function.""" dum_tok = 'dummytoken' + ctx = utils.dummy_context() mock_ks_auth = self.m.CreateMockAnything() mock_ks_auth.get_token(mox.IsA(ks_session.Session)).AndReturn(dum_tok) - + self.patchobject(ctx, '_create_auth_plugin') m = ks_auth.Password(auth_url='http://server.test:5000/v3', password='apassw', project_id='aproject', @@ -1361,7 +1385,6 @@ class KeystoneClientTest(common.HeatTestCase): self.m.ReplayAll() - ctx = utils.dummy_context() ctx.trust_id = None heat_ks_client = heat_keystoneclient.KeystoneClient(ctx) token = heat_ks_client.stack_domain_user_token(user_id='duser', @@ -1373,6 +1396,8 @@ class KeystoneClientTest(common.HeatTestCase): """Test stack_domain_user_token error path.""" self._clear_domain_override() ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') + ctx.trust_id = None heat_ks_client = heat_keystoneclient.KeystoneClient(ctx) self.assertRaises(exception.Error, @@ -1386,6 +1411,7 @@ class KeystoneClientTest(common.HeatTestCase): self._clear_domain_override() ctx = utils.dummy_context() + self.patchobject(ctx, '_create_auth_plugin') ctx.trust_id = None heat_ks_client = heat_keystoneclient.KeystoneClient(ctx) self.assertIsNone(heat_ks_client.delete_stack_domain_project( @@ -1492,7 +1518,8 @@ class KeystoneClientTestDomainName(KeystoneClientTest): if domain_id: a = self.m.CreateMockAnything() a.domain_id = domain_id - mock_ks_auth.get_access(mox.IsA(ks_session.Session)).AndReturn(a) + mock_ks_auth.get_access( + mox.IsA(ks_session.Session)).AndReturn(a) m = ks_auth.Password(auth_url='http://server.test:5000/v3', password='adminsecret', diff --git a/heat/tests/clients/test_magnum_client.py b/heat/tests/clients/test_magnum_client.py index 7a58dc1dc7..b045e397b5 100644 --- a/heat/tests/clients/test_magnum_client.py +++ b/heat/tests/clients/test_magnum_client.py @@ -22,4 +22,4 @@ class MagnumClientPluginTest(common.HeatTestCase): plugin = context.clients.client_plugin('magnum') client = plugin.client() self.assertEqual('http://server.test:5000/v3', - client.baymodels.api.endpoint_override) + client.baymodels.api.session.auth.endpoint)