diff --git a/doc/source/user/config/using.rst b/doc/source/user/config/using.rst index 1e81b4b4f..7792989cf 100644 --- a/doc/source/user/config/using.rst +++ b/doc/source/user/config/using.rst @@ -56,86 +56,3 @@ with - as well as a consumption argument. options = parser.parse_args() cloud_region = config.get_one(argparse=options) - -Constructing a Connection object --------------------------------- - -If what you want to do is get an `openstack.connection.Connection` and you -want it to do all the normal things related to clouds.yaml, `OS_` environment -variables, a helper function is provided. The following will get you a fully -configured `openstacksdk` instance. - -.. code-block:: python - - import openstack.config - - conn = openstack.config.make_connection() - -If you want to do the same thing but on a named cloud. - -.. code-block:: python - - import openstack.config - - conn = openstack.config.make_connection(cloud='mtvexx') - -If you want to do the same thing but also support command line parsing. - -.. code-block:: python - - import argparse - - import openstack.config - - conn = openstack.config.make_connection(options=argparse.ArgumentParser()) - -Constructing OpenStackCloud objects ------------------------------------ - -If what you want to do is get an -`opentack.cloud.openstackcloud.OpenStackCloud` object, a -helper function that honors clouds.yaml and `OS_` environment variables is -provided. The following will get you a fully configured `OpenStackCloud` -instance. - -.. code-block:: python - - import openstack.config - - cloud = openstack.config.make_cloud() - -If you want to do the same thing but on a named cloud. - -.. code-block:: python - - import openstack.config - - cloud = openstack.config.make_cloud(cloud='mtvexx') - -If you want to do the same thing but also support command line parsing. - -.. code-block:: python - - import argparse - - import openstack.config - - cloud = openstack.config.make_cloud(options=argparse.ArgumentParser()) - -Constructing REST API Clients ------------------------------ - -What if you want to make direct REST calls via a Session interface? You're -in luck. A similar interface is available as with `openstacksdk` and `shade`. -The main difference is that you need to specify which service you want to -talk to and `make_rest_client` will return you a keystoneauth Session object -that is mounted on the endpoint for the service you're looking for. - -.. code-block:: python - - import openstack.config - - session = openstack.config.make_rest_client('compute', cloud='vexxhost') - - response = session.get('/servers') - server_list = response.json()['servers'] diff --git a/openstack/cloud/meta.py b/openstack/cloud/meta.py index 957fea6a8..35bc242d2 100644 --- a/openstack/cloud/meta.py +++ b/openstack/cloud/meta.py @@ -542,21 +542,6 @@ def obj_list_to_munch(obj_list): obj_list_to_dict = obj_list_to_munch -def warlock_to_dict(obj): - # This function is unused in shade - but it is a public function, so - # removing it would be rude. We don't actually have to depend on warlock - # ourselves to keep this - so just leave it here. - # - # glanceclient v2 uses warlock to construct its objects. Warlock does - # deep black magic to attribute look up to support validation things that - # means we cannot use normal obj_to_munch - obj_dict = munch.Munch() - for (key, value) in obj.items(): - if isinstance(value, NON_CALLABLES) and not key.startswith('_'): - obj_dict[key] = value - return obj_dict - - def get_and_munchify(key, data): """Get the value associated to key and convert it. diff --git a/openstack/cloud/openstackcloud.py b/openstack/cloud/openstackcloud.py index 90fa03d56..9a3103f66 100644 --- a/openstack/cloud/openstackcloud.py +++ b/openstack/cloud/openstackcloud.py @@ -459,26 +459,6 @@ class OpenStackCloud(_normalize.Normalizer): else: return self._cache - def _get_client( - self, service_key, client_class=None, interface_key=None, - pass_version_arg=True, **kwargs): - try: - client = self.cloud_config.get_legacy_client( - service_key=service_key, client_class=client_class, - interface_key=interface_key, pass_version_arg=pass_version_arg, - **kwargs) - except Exception: - self.log.debug( - "Couldn't construct %(service)s object", - {'service': service_key}, exc_info=True) - raise - if client is None: - raise OpenStackCloudException( - "Failed to instantiate {service} client." - " This could mean that your credentials are wrong.".format( - service=service_key)) - return client - def _get_major_version_id(self, version): if isinstance(version, int): return version diff --git a/openstack/config/__init__.py b/openstack/config/__init__.py index e50e7f9db..4c4547c14 100644 --- a/openstack/config/__init__.py +++ b/openstack/config/__init__.py @@ -19,7 +19,7 @@ from openstack.config.loader import OpenStackConfig # noqa _config = None -def get_config( +def get_cloud_region( service_key=None, options=None, app_name=None, app_version=None, **kwargs): @@ -36,55 +36,3 @@ def get_config( parsed_options = None return _config.get_one(options=parsed_options, **kwargs) - - -def make_rest_client( - service_key, options=None, - app_name=None, app_version=None, version=None, - **kwargs): - """Simple wrapper function. It has almost no features. - - This will get you a raw requests Session Adapter that is mounted - on the given service from the keystone service catalog. If you leave - off cloud and region_name, it will assume that you've got env vars - set, but if you give them, it'll use clouds.yaml as you'd expect. - - This function is deliberately simple. It has no flexibility. If you - want flexibility, you can make a cloud config object and call - get_session_client on it. This function is to make it easy to poke - at OpenStack REST APIs with a properly configured keystone session. - """ - cloud_region = get_config( - service_key=service_key, options=options, - app_name=app_name, app_version=app_version, - **kwargs) - return cloud_region.get_session_client(service_key, version=version) -# Backwards compat - simple_client was a terrible name -simple_client = make_rest_client -# Backwards compat - session_client was a terrible name -session_client = make_rest_client - - -def make_connection(options=None, **kwargs): - """Simple wrapper for getting an OpenStack SDK Connection. - - For completeness, provide a mechanism that matches make_client and - make_rest_client. The heavy lifting here is done in openstacksdk. - - :rtype: :class:`~openstack.connection.Connection` - """ - from openstack import connection - cloud_region = get_config(options=options, **kwargs) - return connection.from_config(cloud_region=cloud_region, options=options) - - -def make_cloud(options=None, **kwargs): - """Simple wrapper for getting an OpenStackCloud object - - A mechanism that matches make_connection and make_rest_client. - - :rtype: :class:`~openstack.OpenStackCloud` - """ - import openstack.cloud - cloud_region = get_config(options=options, **kwargs) - return openstack.OpenStackCloud(cloud_config=cloud_region, **kwargs) diff --git a/openstack/config/cloud_region.py b/openstack/config/cloud_region.py index 8119fdf72..ffef7f60e 100644 --- a/openstack/config/cloud_region.py +++ b/openstack/config/cloud_region.py @@ -12,7 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import importlib import math import warnings @@ -24,44 +23,9 @@ from six.moves import urllib import openstack from openstack import _log -from openstack.config import constructors from openstack.config import exceptions -def _get_client(service_key): - class_mapping = constructors.get_constructor_mapping() - if service_key not in class_mapping: - raise exceptions.OpenStackConfigException( - "Service {service_key} is unkown. Please pass in a client" - " constructor or submit a patch to os-client-config".format( - service_key=service_key)) - mod_name, ctr_name = class_mapping[service_key].rsplit('.', 1) - lib_name = mod_name.split('.')[0] - try: - mod = importlib.import_module(mod_name) - except ImportError: - raise exceptions.OpenStackConfigException( - "Client for '{service_key}' was requested, but" - " {mod_name} was unable to be imported. Either import" - " the module yourself and pass the constructor in as an argument," - " or perhaps you do not have python-{lib_name} installed.".format( - service_key=service_key, - mod_name=mod_name, - lib_name=lib_name)) - try: - ctr = getattr(mod, ctr_name) - except AttributeError: - raise exceptions.OpenStackConfigException( - "Client for '{service_key}' was requested, but although" - " {mod_name} imported fine, the constructor at {fullname}" - " as not found. Please check your installation, we have no" - " clue what is wrong with your computer.".format( - service_key=service_key, - mod_name=mod_name, - fullname=class_mapping[service_key])) - return ctr - - def _make_key(key, service_type): if not service_type: return key @@ -371,148 +335,6 @@ class CloudRegion(object): kwargs['region_name']) return endpoint - def get_legacy_client( - self, service_key, client_class=None, interface_key=None, - pass_version_arg=True, version=None, min_version=None, - max_version=None, **kwargs): - """Return a legacy OpenStack client object for the given config. - - Most of the OpenStack python-*client libraries have the same - interface for their client constructors, but there are several - parameters one wants to pass given a :class:`CloudRegion` object. - - In the future, OpenStack API consumption should be done through - the OpenStack SDK, but that's not ready yet. This is for getting - Client objects from python-*client only. - - :param service_key: Generic key for service, such as 'compute' or - 'network' - :param client_class: Class of the client to be instantiated. This - should be the unversioned version if there - is one, such as novaclient.client.Client, or - the versioned one, such as - neutronclient.v2_0.client.Client if there isn't - :param interface_key: (optional) Some clients, such as glanceclient - only accept the parameter 'interface' instead - of 'endpoint_type' - this is a get-out-of-jail - parameter for those until they can be aligned. - os-client-config understands this to be the - case if service_key is image, so this is really - only for use with other unknown broken clients. - :param pass_version_arg: (optional) If a versioned Client constructor - was passed to client_class, set this to - False, which will tell get_client to not - pass a version parameter. os-client-config - already understand that this is the - case for network, so it can be omitted in - that case. - :param version: (optional) Version string to override the configured - version string. - :param min_version: (options) Minimum version acceptable. - :param max_version: (options) Maximum version acceptable. - :param kwargs: (optional) keyword args are passed through to the - Client constructor, so this is in case anything - additional needs to be passed in. - """ - if not client_class: - client_class = _get_client(service_key) - - interface = self.get_interface(service_key) - # trigger exception on lack of service - endpoint = self.get_session_endpoint( - service_key, min_version=min_version, max_version=max_version) - endpoint_override = self.get_endpoint(service_key) - - if service_key == 'object-store': - constructor_kwargs = dict( - session=self.get_session(), - os_options=dict( - service_type=self.get_service_type(service_key), - object_storage_url=endpoint_override, - region_name=self.region_name)) - else: - constructor_kwargs = dict( - session=self.get_session(), - service_name=self.get_service_name(service_key), - service_type=self.get_service_type(service_key), - endpoint_override=endpoint_override, - region_name=self.region_name) - - if service_key == 'image': - # os-client-config does not depend on glanceclient, but if - # the user passed in glanceclient.client.Client, which they - # would need to do if they were requesting 'image' - then - # they necessarily have glanceclient installed - from glanceclient.common import utils as glance_utils - endpoint, detected_version = glance_utils.strip_version(endpoint) - # If the user has passed in a version, that's explicit, use it - if not version: - version = detected_version - # If the user has passed in or configured an override, use it. - # Otherwise, ALWAYS pass in an endpoint_override becuase - # we've already done version stripping, so we don't want version - # reconstruction to happen twice - if not endpoint_override: - constructor_kwargs['endpoint_override'] = endpoint - constructor_kwargs.update(kwargs) - if pass_version_arg and service_key != 'object-store': - if not version: - version = self.get_api_version(service_key) - if not version and service_key == 'volume': - from cinderclient import client as cinder_client - version = cinder_client.get_volume_api_from_url(endpoint) - # Temporary workaround while we wait for python-openstackclient - # to be able to handle 2.0 which is what neutronclient expects - if service_key == 'network' and version == '2': - version = '2.0' - if service_key == 'identity': - # Workaround for bug#1513839 - if 'endpoint' not in constructor_kwargs: - endpoint = self.get_session_endpoint('identity') - constructor_kwargs['endpoint'] = endpoint - if service_key == 'network': - constructor_kwargs['api_version'] = version - elif service_key == 'baremetal': - if version != '1': - # Set Ironic Microversion - constructor_kwargs['os_ironic_api_version'] = version - # Version arg is the major version, not the full microstring - constructor_kwargs['version'] = version[0] - else: - constructor_kwargs['version'] = version - if min_version and min_version > float(version): - raise exceptions.OpenStackConfigVersionException( - "Minimum version {min_version} requested but {version}" - " found".format(min_version=min_version, version=version), - version=version) - if max_version and max_version < float(version): - raise exceptions.OpenStackConfigVersionException( - "Maximum version {max_version} requested but {version}" - " found".format(max_version=max_version, version=version), - version=version) - if service_key == 'database': - # TODO(mordred) Remove when https://review.openstack.org/314032 - # has landed and released. We're passing in a Session, but the - # trove Client object has username and password as required - # args - constructor_kwargs['username'] = None - constructor_kwargs['password'] = None - - if not interface_key: - if service_key in ('image', 'key-manager'): - interface_key = 'interface' - elif (service_key == 'identity' - and version and version.startswith('3')): - interface_key = 'interface' - else: - interface_key = 'endpoint_type' - if service_key == 'object-store': - constructor_kwargs['os_options'][interface_key] = interface - else: - constructor_kwargs[interface_key] = interface - - return client_class(**constructor_kwargs) - def get_cache_expiration_time(self): if self._openstack_config: return self._openstack_config.get_cache_expiration_time() diff --git a/openstack/config/constructors.json b/openstack/config/constructors.json deleted file mode 100644 index 9acb7cfb9..000000000 --- a/openstack/config/constructors.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "application-catalog": "muranoclient.client.Client", - "baremetal": "ironicclient.client.Client", - "compute": "novaclient.client.Client", - "container-infra": "magnumclient.client.Client", - "database": "troveclient.client.Client", - "dns": "designateclient.client.Client", - "identity": "keystoneclient.client.Client", - "image": "glanceclient.Client", - "key-manager": "barbicanclient.client.Client", - "metering": "ceilometerclient.client.Client", - "network": "neutronclient.neutron.client.Client", - "object-store": "swiftclient.client.Connection", - "orchestration": "heatclient.client.Client", - "volume": "cinderclient.client.Client" -} diff --git a/openstack/config/constructors.py b/openstack/config/constructors.py deleted file mode 100644 index 579bb2d5e..000000000 --- a/openstack/config/constructors.py +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (c) 2014 Hewlett-Packard Development Company, L.P. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import json -import os -import threading - -_json_path = os.path.join( - os.path.dirname(os.path.realpath(__file__)), 'constructors.json') -_class_mapping = None -_class_mapping_lock = threading.Lock() - - -def get_constructor_mapping(): - global _class_mapping - if _class_mapping is not None: - return _class_mapping.copy() - with _class_mapping_lock: - if _class_mapping is not None: - return _class_mapping.copy() - tmp_class_mapping = {} - with open(_json_path, 'r') as json_file: - tmp_class_mapping.update(json.load(json_file)) - _class_mapping = tmp_class_mapping - return tmp_class_mapping.copy() diff --git a/openstack/tests/functional/base.py b/openstack/tests/functional/base.py index 3614f34d2..c2b5e6308 100644 --- a/openstack/tests/functional/base.py +++ b/openstack/tests/functional/base.py @@ -23,7 +23,7 @@ from openstack.tests import base #: will determine where the functional tests will be run and what resource #: defaults will be used to run the functional tests. TEST_CLOUD_NAME = os.getenv('OS_CLOUD', 'devstack-admin') -TEST_CLOUD_REGION = openstack.config.get_config(cloud=TEST_CLOUD_NAME) +TEST_CLOUD_REGION = openstack.config.get_cloud_region(cloud=TEST_CLOUD_NAME) def _get_resource_value(resource_key, default): diff --git a/openstack/tests/unit/config/test_cloud_config.py b/openstack/tests/unit/config/test_cloud_config.py index 6ce77db5b..cf389acad 100644 --- a/openstack/tests/unit/config/test_cloud_config.py +++ b/openstack/tests/unit/config/test_cloud_config.py @@ -278,305 +278,3 @@ class TestCloudRegion(base.TestCase): cc = cloud_region.CloudRegion( "test1", "region-al", {}, auth_plugin=mock.Mock()) self.assertIsNone(cc.get_session_endpoint('notfound')) - - @mock.patch.object(cloud_region.CloudRegion, 'get_api_version') - @mock.patch.object(cloud_region.CloudRegion, 'get_auth_args') - @mock.patch.object(cloud_region.CloudRegion, 'get_session_endpoint') - def test_legacy_client_object_store_password( - self, - mock_get_session_endpoint, - mock_get_auth_args, - mock_get_api_version): - mock_client = mock.Mock() - mock_get_session_endpoint.return_value = 'http://swift.example.com' - mock_get_api_version.return_value = '3' - mock_get_auth_args.return_value = dict( - username='testuser', - password='testpassword', - project_name='testproject', - auth_url='http://example.com', - ) - config_dict = defaults.get_defaults() - config_dict.update(fake_services_dict) - cc = cloud_region.CloudRegion( - "test1", "region-al", config_dict, auth_plugin=mock.Mock()) - cc.get_legacy_client('object-store', mock_client) - mock_client.assert_called_with( - session=mock.ANY, - os_options={ - 'region_name': 'region-al', - 'service_type': 'object-store', - 'object_storage_url': None, - 'endpoint_type': 'public', - }) - - @mock.patch.object(cloud_region.CloudRegion, 'get_auth_args') - @mock.patch.object(cloud_region.CloudRegion, 'get_session_endpoint') - def test_legacy_client_object_store_password_v2( - self, mock_get_session_endpoint, mock_get_auth_args): - mock_client = mock.Mock() - mock_get_session_endpoint.return_value = 'http://swift.example.com' - mock_get_auth_args.return_value = dict( - username='testuser', - password='testpassword', - project_name='testproject', - auth_url='http://example.com', - ) - config_dict = defaults.get_defaults() - config_dict.update(fake_services_dict) - cc = cloud_region.CloudRegion( - "test1", "region-al", config_dict, auth_plugin=mock.Mock()) - cc.get_legacy_client('object-store', mock_client) - mock_client.assert_called_with( - session=mock.ANY, - os_options={ - 'region_name': 'region-al', - 'service_type': 'object-store', - 'object_storage_url': None, - 'endpoint_type': 'public', - }) - - @mock.patch.object(cloud_region.CloudRegion, 'get_auth_args') - @mock.patch.object(cloud_region.CloudRegion, 'get_session_endpoint') - def test_legacy_client_object_store( - self, mock_get_session_endpoint, mock_get_auth_args): - mock_client = mock.Mock() - mock_get_session_endpoint.return_value = 'http://example.com/v2' - mock_get_auth_args.return_value = {} - config_dict = defaults.get_defaults() - config_dict.update(fake_services_dict) - cc = cloud_region.CloudRegion( - "test1", "region-al", config_dict, auth_plugin=mock.Mock()) - cc.get_legacy_client('object-store', mock_client) - mock_client.assert_called_with( - session=mock.ANY, - os_options={ - 'region_name': 'region-al', - 'service_type': 'object-store', - 'object_storage_url': None, - 'endpoint_type': 'public', - }) - - @mock.patch.object(cloud_region.CloudRegion, 'get_auth_args') - @mock.patch.object(cloud_region.CloudRegion, 'get_session_endpoint') - def test_legacy_client_object_store_timeout( - self, mock_get_session_endpoint, mock_get_auth_args): - mock_client = mock.Mock() - mock_get_session_endpoint.return_value = 'http://example.com/v2' - mock_get_auth_args.return_value = {} - config_dict = defaults.get_defaults() - config_dict.update(fake_services_dict) - config_dict['api_timeout'] = 9 - cc = cloud_region.CloudRegion( - "test1", "region-al", config_dict, auth_plugin=mock.Mock()) - cc.get_legacy_client('object-store', mock_client) - mock_client.assert_called_with( - session=mock.ANY, - os_options={ - 'region_name': 'region-al', - 'service_type': 'object-store', - 'object_storage_url': None, - 'endpoint_type': 'public', - }) - - @mock.patch.object(cloud_region.CloudRegion, 'get_auth_args') - def test_legacy_client_object_store_endpoint( - self, mock_get_auth_args): - mock_client = mock.Mock() - mock_get_auth_args.return_value = {} - config_dict = defaults.get_defaults() - config_dict.update(fake_services_dict) - config_dict['object_store_endpoint'] = 'http://example.com/swift' - cc = cloud_region.CloudRegion( - "test1", "region-al", config_dict, auth_plugin=mock.Mock()) - cc.get_legacy_client('object-store', mock_client) - mock_client.assert_called_with( - session=mock.ANY, - os_options={ - 'region_name': 'region-al', - 'service_type': 'object-store', - 'object_storage_url': 'http://example.com/swift', - 'endpoint_type': 'public', - }) - - @mock.patch.object(cloud_region.CloudRegion, 'get_session_endpoint') - def test_legacy_client_image(self, mock_get_session_endpoint): - mock_client = mock.Mock() - mock_get_session_endpoint.return_value = 'http://example.com/v2' - config_dict = defaults.get_defaults() - config_dict.update(fake_services_dict) - cc = cloud_region.CloudRegion( - "test1", "region-al", config_dict, auth_plugin=mock.Mock()) - cc.get_legacy_client('image', mock_client) - mock_client.assert_called_with( - version=2.0, - service_name=None, - endpoint_override='http://example.com', - region_name='region-al', - interface='public', - session=mock.ANY, - # Not a typo - the config dict above overrides this - service_type='mage' - ) - - @mock.patch.object(cloud_region.CloudRegion, 'get_session_endpoint') - def test_legacy_client_image_override(self, mock_get_session_endpoint): - mock_client = mock.Mock() - mock_get_session_endpoint.return_value = 'http://example.com/v2' - config_dict = defaults.get_defaults() - config_dict.update(fake_services_dict) - config_dict['image_endpoint_override'] = 'http://example.com/override' - cc = cloud_region.CloudRegion( - "test1", "region-al", config_dict, auth_plugin=mock.Mock()) - cc.get_legacy_client('image', mock_client) - mock_client.assert_called_with( - version=2.0, - service_name=None, - endpoint_override='http://example.com/override', - region_name='region-al', - interface='public', - session=mock.ANY, - # Not a typo - the config dict above overrides this - service_type='mage' - ) - - @mock.patch.object(cloud_region.CloudRegion, 'get_session_endpoint') - def test_legacy_client_image_versioned(self, mock_get_session_endpoint): - mock_client = mock.Mock() - mock_get_session_endpoint.return_value = 'http://example.com/v2' - config_dict = defaults.get_defaults() - config_dict.update(fake_services_dict) - # v2 endpoint was passed, 1 requested in config, endpoint wins - config_dict['image_api_version'] = '1' - cc = cloud_region.CloudRegion( - "test1", "region-al", config_dict, auth_plugin=mock.Mock()) - cc.get_legacy_client('image', mock_client) - mock_client.assert_called_with( - version=2.0, - service_name=None, - endpoint_override='http://example.com', - region_name='region-al', - interface='public', - session=mock.ANY, - # Not a typo - the config dict above overrides this - service_type='mage' - ) - - @mock.patch.object(cloud_region.CloudRegion, 'get_session_endpoint') - def test_legacy_client_image_unversioned(self, mock_get_session_endpoint): - mock_client = mock.Mock() - mock_get_session_endpoint.return_value = 'http://example.com/' - config_dict = defaults.get_defaults() - config_dict.update(fake_services_dict) - # Versionless endpoint, config wins - config_dict['image_api_version'] = '1' - cc = cloud_region.CloudRegion( - "test1", "region-al", config_dict, auth_plugin=mock.Mock()) - cc.get_legacy_client('image', mock_client) - mock_client.assert_called_with( - version='1', - service_name=None, - endpoint_override='http://example.com', - region_name='region-al', - interface='public', - session=mock.ANY, - # Not a typo - the config dict above overrides this - service_type='mage' - ) - - @mock.patch.object(cloud_region.CloudRegion, 'get_session_endpoint') - def test_legacy_client_image_argument(self, mock_get_session_endpoint): - mock_client = mock.Mock() - mock_get_session_endpoint.return_value = 'http://example.com/v3' - config_dict = defaults.get_defaults() - config_dict.update(fake_services_dict) - # Versionless endpoint, config wins - config_dict['image_api_version'] = '6' - cc = cloud_region.CloudRegion( - "test1", "region-al", config_dict, auth_plugin=mock.Mock()) - cc.get_legacy_client('image', mock_client, version='beef') - mock_client.assert_called_with( - version='beef', - service_name=None, - endpoint_override='http://example.com', - region_name='region-al', - interface='public', - session=mock.ANY, - # Not a typo - the config dict above overrides this - service_type='mage' - ) - - @mock.patch.object(cloud_region.CloudRegion, 'get_session_endpoint') - def test_legacy_client_network(self, mock_get_session_endpoint): - mock_client = mock.Mock() - mock_get_session_endpoint.return_value = 'http://example.com/v2' - config_dict = defaults.get_defaults() - config_dict.update(fake_services_dict) - cc = cloud_region.CloudRegion( - "test1", "region-al", config_dict, auth_plugin=mock.Mock()) - cc.get_legacy_client('network', mock_client) - mock_client.assert_called_with( - api_version='2.0', - endpoint_type='public', - endpoint_override=None, - region_name='region-al', - service_type='network', - session=mock.ANY, - service_name=None) - - @mock.patch.object(cloud_region.CloudRegion, 'get_session_endpoint') - def test_legacy_client_compute(self, mock_get_session_endpoint): - mock_client = mock.Mock() - mock_get_session_endpoint.return_value = 'http://example.com/v2' - config_dict = defaults.get_defaults() - config_dict.update(fake_services_dict) - cc = cloud_region.CloudRegion( - "test1", "region-al", config_dict, auth_plugin=mock.Mock()) - cc.get_legacy_client('compute', mock_client) - mock_client.assert_called_with( - version='2', - endpoint_type='public', - endpoint_override='http://compute.example.com', - region_name='region-al', - service_type='compute', - session=mock.ANY, - service_name=None) - - @mock.patch.object(cloud_region.CloudRegion, 'get_session_endpoint') - def test_legacy_client_identity(self, mock_get_session_endpoint): - mock_client = mock.Mock() - mock_get_session_endpoint.return_value = 'http://example.com/v2' - config_dict = defaults.get_defaults() - config_dict.update(fake_services_dict) - cc = cloud_region.CloudRegion( - "test1", "region-al", config_dict, auth_plugin=mock.Mock()) - cc.get_legacy_client('identity', mock_client) - mock_client.assert_called_with( - version='2.0', - endpoint='http://example.com/v2', - endpoint_type='admin', - endpoint_override=None, - region_name='region-al', - service_type='identity', - session=mock.ANY, - service_name='locks') - - @mock.patch.object(cloud_region.CloudRegion, 'get_session_endpoint') - def test_legacy_client_identity_v3(self, mock_get_session_endpoint): - mock_client = mock.Mock() - mock_get_session_endpoint.return_value = 'http://example.com' - config_dict = defaults.get_defaults() - config_dict.update(fake_services_dict) - config_dict['identity_api_version'] = '3' - cc = cloud_region.CloudRegion( - "test1", "region-al", config_dict, auth_plugin=mock.Mock()) - cc.get_legacy_client('identity', mock_client) - mock_client.assert_called_with( - version='3', - endpoint='http://example.com', - interface='admin', - endpoint_override=None, - region_name='region-al', - service_type='identity', - session=mock.ANY, - service_name='locks') diff --git a/openstack/tests/unit/config/test_init.py b/openstack/tests/unit/config/test_init.py index 97171291a..62fb7ea45 100644 --- a/openstack/tests/unit/config/test_init.py +++ b/openstack/tests/unit/config/test_init.py @@ -17,16 +17,16 @@ from openstack.tests.unit.config import base class TestInit(base.TestCase): - def test_get_config_without_arg_parser(self): - cloud_region = openstack.config.get_config( + def test_get_cloud_region_without_arg_parser(self): + cloud_region = openstack.config.get_cloud_region( options=None, validate=False) self.assertIsInstance( cloud_region, openstack.config.cloud_region.CloudRegion ) - def test_get_config_with_arg_parser(self): - cloud_region = openstack.config.get_config( + def test_get_cloud_region_with_arg_parser(self): + cloud_region = openstack.config.get_cloud_region( options=argparse.ArgumentParser(), validate=False) self.assertIsInstance( diff --git a/test-requirements.txt b/test-requirements.txt index 943a8376e..4584371f0 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -16,5 +16,3 @@ stestr>=1.0.0 # Apache-2.0 testrepository>=0.0.18 # Apache-2.0/BSD testscenarios>=0.4 # Apache-2.0/BSD testtools>=2.2.0 # MIT -python-glanceclient>=2.8.0 # Apache-2.0 -python-ironicclient>=1.14.0 # Apache-2.0