From e636890d59c92345fe96f8dfdc6baa3401f8bef8 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Thu, 18 Jan 2018 16:53:26 -0600 Subject: [PATCH] Move openstack_cloud helper functions We don't want these where they look like supported interfaces just yet. Move them below openstack.cloud. Change-Id: I653e5aaba8084e8c226fd0e787dfff01050e7a6c --- README.rst | 4 +- doc/source/user/multi-cloud-demo.rst | 36 ++++---- doc/source/user/usage.rst | 4 +- examples/cloud/cleanup-servers.py | 2 +- examples/cloud/create-server-dict.py | 2 +- examples/cloud/create-server-name-or-id.py | 2 +- examples/cloud/debug-logging.py | 2 +- examples/cloud/find-an-image.py | 2 +- examples/cloud/http-debug-logging.py | 2 +- examples/cloud/munch-dict-object.py | 2 +- examples/cloud/normalization.py | 2 +- openstack/__init__.py | 92 +------------------ openstack/cloud/__init__.py | 79 ++++++++++++++++ openstack/cloud/cmd/inventory.py | 2 +- openstack/cloud/inventory.py | 10 +- openstack/cloud/openstackcloud.py | 4 +- openstack/connection.py | 7 ++ openstack/tests/functional/cloud/base.py | 4 +- .../tests/functional/cloud/test_domain.py | 2 +- .../tests/functional/cloud/test_groups.py | 2 +- .../tests/functional/cloud/test_identity.py | 2 +- .../tests/functional/cloud/test_users.py | 2 +- openstack/tests/unit/base.py | 10 +- openstack/tests/unit/cloud/test_caching.py | 11 ++- .../unit/cloud/test_cluster_templates.py | 2 +- .../tests/unit/cloud/test_create_server.py | 10 +- .../tests/unit/cloud/test_domain_params.py | 16 ++-- openstack/tests/unit/cloud/test_domains.py | 6 +- openstack/tests/unit/cloud/test_flavors.py | 4 +- .../unit/cloud/test_floating_ip_common.py | 2 +- .../tests/unit/cloud/test_floating_ip_pool.py | 2 +- .../tests/unit/cloud/test_identity_roles.py | 4 +- openstack/tests/unit/cloud/test_image.py | 36 ++++---- openstack/tests/unit/cloud/test_inventory.py | 14 +-- openstack/tests/unit/cloud/test_meta.py | 40 ++++---- openstack/tests/unit/cloud/test_network.py | 4 +- openstack/tests/unit/cloud/test_object.py | 8 +- openstack/tests/unit/cloud/test_operator.py | 4 +- .../tests/unit/cloud/test_operator_noauth.py | 6 +- openstack/tests/unit/cloud/test_project.py | 4 +- .../tests/unit/cloud/test_security_groups.py | 12 +-- openstack/tests/unit/cloud/test_services.py | 2 +- openstack/tests/unit/cloud/test_shade.py | 6 +- openstack/tests/unit/cloud/test_stack.py | 8 +- openstack/tests/unit/cloud/test_users.py | 2 +- openstack/tests/unit/cloud/test_volume.py | 12 +-- .../tests/unit/cloud/test_volume_access.py | 2 +- 47 files changed, 245 insertions(+), 248 deletions(-) diff --git a/README.rst b/README.rst index 7079da180..11f125950 100644 --- a/README.rst +++ b/README.rst @@ -138,14 +138,14 @@ Create a server using objects configured with the ``clouds.yaml`` file: .. code-block:: python - import openstack + import openstack.cloud # Initialize and turn on debug logging openstack.enable_logging(debug=True) # Initialize cloud # Cloud configs are read with openstack.config - cloud = openstack.openstack_cloud(cloud='mordred') + cloud = openstack.cloud.openstack_cloud(cloud='mordred') # Upload an image to the cloud image = cloud.create_image( diff --git a/doc/source/user/multi-cloud-demo.rst b/doc/source/user/multi-cloud-demo.rst index aafd3a164..757796096 100644 --- a/doc/source/user/multi-cloud-demo.rst +++ b/doc/source/user/multi-cloud-demo.rst @@ -62,7 +62,7 @@ Complete Example .. code:: python - import openstack + from openstack import cloud as openstack # Initialize and turn on debug logging openstack.enable_logging(debug=True) @@ -314,7 +314,7 @@ Complete Example Again .. code:: python - import openstack + from openstack import cloud as openstack # Initialize and turn on debug logging openstack.enable_logging(debug=True) @@ -346,7 +346,7 @@ Import the library .. code:: python - import openstack + from openstack import cloud as openstack Logging ======= @@ -373,7 +373,7 @@ Example with Debug Logging .. code:: python - import openstack + from openstack import cloud as openstack openstack.enable_logging(debug=True) cloud = openstack.openstack_cloud( @@ -387,7 +387,7 @@ Example with HTTP Debug Logging .. code:: python - import openstack + from openstack import cloud as openstack openstack.enable_logging(http_debug=True) cloud = openstack.openstack_cloud( @@ -484,7 +484,7 @@ Image and Flavor by Name or ID .. code:: python - import openstack + from openstack import cloud as openstack # Initialize and turn on debug logging openstack.enable_logging(debug=True) @@ -531,7 +531,7 @@ Image and Flavor by Dict .. code:: python - import openstack + from openstack import cloud as openstack # Initialize and turn on debug logging openstack.enable_logging(debug=True) @@ -562,7 +562,7 @@ Munch Objects .. code:: python - import openstack + from openstack import cloud as openstack openstack.enable_logging(debug=True) cloud = openstack.openstack_cloud(cloud='zetta', region_name='no-osl1') @@ -594,7 +594,7 @@ Cleanup Script .. code:: python - import openstack + from openstack import cloud as openstack # Initialize and turn on debug logging openstack.enable_logging(debug=True) @@ -616,7 +616,7 @@ Normalization .. code:: python - import openstack + from openstack import cloud as openstack openstack.enable_logging() cloud = openstack.openstack_cloud(cloud='fuga', region_name='cystack') @@ -632,7 +632,7 @@ Strict Normalized Results .. code:: python - import openstack + from openstack import cloud as openstack openstack.enable_logging() cloud = openstack.openstack_cloud( @@ -649,7 +649,7 @@ How Did I Find the Image Name for the Last Example? .. code:: python - import openstack + from openstack import cloud as openstack openstack.enable_logging() cloud = openstack.openstack_cloud(cloud='fuga', region_name='cystack') @@ -670,7 +670,7 @@ Added / Modified Information .. code:: python - import openstack + from openstack import cloud as openstack openstack.enable_logging(debug=True) cloud = openstack.openstack_cloud(cloud='my-citycloud', region_name='Buf1') @@ -712,7 +712,7 @@ User Agent Info .. code:: python - import openstack + from openstack import cloud as openstack openstack.enable_logging(http_debug=True) cloud = openstack.openstack_cloud( @@ -730,7 +730,7 @@ Uploading Large Objects .. code:: python - import openstack + from openstack import cloud as openstack openstack.enable_logging(debug=True) cloud = openstack.openstack_cloud(cloud='ovh', region_name='SBG1') @@ -751,7 +751,7 @@ Uploading Large Objects .. code:: python - import openstack + from openstack import cloud as openstack openstack.enable_logging(debug=True) cloud = openstack.openstack_cloud(cloud='ovh', region_name='SBG1') @@ -767,7 +767,7 @@ Service Conditionals .. code:: python - import openstack + from openstack import cloud as openstack openstack.enable_logging(debug=True) cloud = openstack.openstack_cloud(cloud='kiss', region_name='region1') @@ -781,7 +781,7 @@ Service Conditional Overrides .. code:: python - import openstack + from openstack import cloud as openstack openstack.enable_logging(debug=True) cloud = openstack.openstack_cloud(cloud='rax', region_name='DFW') diff --git a/doc/source/user/usage.rst b/doc/source/user/usage.rst index 7ef63d511..f707c7964 100644 --- a/doc/source/user/usage.rst +++ b/doc/source/user/usage.rst @@ -15,8 +15,8 @@ To use `openstack.cloud` in a project: objects can be accessed using either dictionary or object notation (e.g., ``server.id``, ``image.name`` and ``server['id']``, ``image['name']``) -.. autoclass:: openstack.OpenStackCloud +.. autoclass:: openstack.cloud.OpenStackCloud :members: -.. autoclass:: openstack.OperatorCloud +.. autoclass:: openstack.cloud.OperatorCloud :members: diff --git a/examples/cloud/cleanup-servers.py b/examples/cloud/cleanup-servers.py index 7620f4c0d..89b7c16e4 100644 --- a/examples/cloud/cleanup-servers.py +++ b/examples/cloud/cleanup-servers.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -import openstack +from openstack import cloud as openstack # Initialize and turn on debug logging openstack.enable_logging(debug=True) diff --git a/examples/cloud/create-server-dict.py b/examples/cloud/create-server-dict.py index 7b7505010..d8d31cc34 100644 --- a/examples/cloud/create-server-dict.py +++ b/examples/cloud/create-server-dict.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -import openstack +from openstack import cloud as openstack # Initialize and turn on debug logging openstack.enable_logging(debug=True) diff --git a/examples/cloud/create-server-name-or-id.py b/examples/cloud/create-server-name-or-id.py index 170904a9d..a1fc1b95c 100644 --- a/examples/cloud/create-server-name-or-id.py +++ b/examples/cloud/create-server-name-or-id.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -import openstack +from openstack import cloud as openstack # Initialize and turn on debug logging openstack.enable_logging(debug=True) diff --git a/examples/cloud/debug-logging.py b/examples/cloud/debug-logging.py index 0874e7b6c..4c9cad328 100644 --- a/examples/cloud/debug-logging.py +++ b/examples/cloud/debug-logging.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -import openstack +from openstack import cloud as openstack openstack.enable_logging(debug=True) cloud = openstack.openstack_cloud( diff --git a/examples/cloud/find-an-image.py b/examples/cloud/find-an-image.py index 9be76817e..f15787378 100644 --- a/examples/cloud/find-an-image.py +++ b/examples/cloud/find-an-image.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -import openstack +from openstack import cloud as openstack openstack.enable_logging() cloud = openstack.openstack_cloud(cloud='fuga', region_name='cystack') diff --git a/examples/cloud/http-debug-logging.py b/examples/cloud/http-debug-logging.py index 62b942532..5e67f4a38 100644 --- a/examples/cloud/http-debug-logging.py +++ b/examples/cloud/http-debug-logging.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -import openstack +from openstack import cloud as openstack openstack.enable_logging(http_debug=True) cloud = openstack.openstack_cloud( diff --git a/examples/cloud/munch-dict-object.py b/examples/cloud/munch-dict-object.py index 5ba6e63ea..65568c112 100644 --- a/examples/cloud/munch-dict-object.py +++ b/examples/cloud/munch-dict-object.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -import openstack +from openstack import cloud as openstack openstack.enable_logging(debug=True) cloud = openstack.openstack_cloud(cloud='ovh', region_name='SBG1') diff --git a/examples/cloud/normalization.py b/examples/cloud/normalization.py index 40a3748d3..914baef70 100644 --- a/examples/cloud/normalization.py +++ b/examples/cloud/normalization.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -import openstack +from openstack import cloud as openstack openstack.enable_logging() cloud = openstack.openstack_cloud(cloud='fuga', region_name='cystack') diff --git a/openstack/__init__.py b/openstack/__init__.py index 0a0be0faa..58ed37874 100644 --- a/openstack/__init__.py +++ b/openstack/__init__.py @@ -17,97 +17,7 @@ __all__ = [ 'enable_logging', ] -import warnings - -import keystoneauth1.exceptions -import requestsexceptions - from openstack._log import enable_logging # noqa -from openstack.cloud.exc import * # noqa -# TODO(shade) These two want to be removed before we make a release -from openstack.cloud.openstackcloud import OpenStackCloud -from openstack.cloud.operatorcloud import OperatorCloud import openstack.connection -if requestsexceptions.SubjectAltNameWarning: - warnings.filterwarnings( - 'ignore', category=requestsexceptions.SubjectAltNameWarning) - - -def _get_openstack_config(app_name=None, app_version=None): - import openstack.config - return openstack.config.OpenStackConfig( - app_name=app_name, app_version=app_version) - - -# TODO(shade) This wants to be remove before we make a release. -def openstack_clouds( - config=None, debug=False, cloud=None, strict=False, - app_name=None, app_version=None): - if not config: - config = _get_openstack_config(app_name, app_version) - try: - if cloud is None: - return [ - OpenStackCloud( - cloud=f.name, debug=debug, - cloud_config=cloud_region, - strict=strict) - for cloud_region in config.get_all() - ] - else: - return [ - OpenStackCloud( - cloud=f.name, debug=debug, - cloud_config=cloud_region, - strict=strict) - for cloud_region in config.get_all() - if cloud_region.name == cloud - ] - except keystoneauth1.exceptions.auth_plugins.NoMatchingPlugin as e: - raise OpenStackCloudException( - "Invalid cloud configuration: {exc}".format(exc=str(e))) - - -# TODO(shade) This wants to be removed before we make a release. -def openstack_cloud( - config=None, strict=False, app_name=None, app_version=None, **kwargs): - if not config: - config = _get_openstack_config(app_name, app_version) - try: - cloud_region = config.get_one(**kwargs) - except keystoneauth1.exceptions.auth_plugins.NoMatchingPlugin as e: - raise OpenStackCloudException( - "Invalid cloud configuration: {exc}".format(exc=str(e))) - return OpenStackCloud(cloud_config=cloud_region, strict=strict) - - -# TODO(shade) This wants to be removed before we make a release. -def operator_cloud( - config=None, strict=False, app_name=None, app_version=None, **kwargs): - if not config: - config = _get_openstack_config(app_name, app_version) - try: - cloud_region = config.get_one(**kwargs) - except keystoneauth1.exceptions.auth_plugins.NoMatchingPlugin as e: - raise OpenStackCloudException( - "Invalid cloud configuration: {exc}".format(exc=str(e))) - return OperatorCloud(cloud_config=cloud_region, strict=strict) - - -def connect(*args, **kwargs): - """Create a `openstack.connection.Connection`.""" - return openstack.connection.Connection(*args, **kwargs) - - -def connect_all(config=None, app_name=None, app_version=None): - if not config: - config = _get_openstack_config(app_name, app_version) - try: - return [ - openstack.connection.Connection(config=cloud_region) - for cloud_region in config.get_all() - ] - except keystoneauth1.exceptions.auth_plugins.NoMatchingPlugin as e: - raise OpenStackCloudException( - "Invalid cloud configuration: {exc}".format(exc=str(e))) +connect = openstack.connection.Connection diff --git a/openstack/cloud/__init__.py b/openstack/cloud/__init__.py index e69de29bb..a28fe467e 100644 --- a/openstack/cloud/__init__.py +++ b/openstack/cloud/__init__.py @@ -0,0 +1,79 @@ +# 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 keystoneauth1.exceptions + +from openstack._log import enable_logging # noqa +from openstack.cloud.exc import * # noqa +from openstack.cloud.openstackcloud import OpenStackCloud +from openstack.cloud.operatorcloud import OperatorCloud + + +def _get_openstack_config(app_name=None, app_version=None): + import openstack.config + return openstack.config.OpenStackConfig( + app_name=app_name, app_version=app_version) + + +# TODO(shade) This wants to be remove before we make a release. +def openstack_clouds( + config=None, debug=False, cloud=None, strict=False, + app_name=None, app_version=None): + if not config: + config = _get_openstack_config(app_name, app_version) + try: + if cloud is None: + return [ + OpenStackCloud( + cloud=f.name, debug=debug, + cloud_config=cloud_region, + strict=strict) + for cloud_region in config.get_all() + ] + else: + return [ + OpenStackCloud( + cloud=f.name, debug=debug, + cloud_config=cloud_region, + strict=strict) + for cloud_region in config.get_all() + if cloud_region.name == cloud + ] + except keystoneauth1.exceptions.auth_plugins.NoMatchingPlugin as e: + raise OpenStackCloudException( + "Invalid cloud configuration: {exc}".format(exc=str(e))) + + +def openstack_cloud( + config=None, strict=False, app_name=None, app_version=None, **kwargs): + if not config: + config = _get_openstack_config(app_name, app_version) + try: + cloud_region = config.get_one(**kwargs) + except keystoneauth1.exceptions.auth_plugins.NoMatchingPlugin as e: + raise OpenStackCloudException( + "Invalid cloud configuration: {exc}".format(exc=str(e))) + return OpenStackCloud(cloud_config=cloud_region, strict=strict) + + +def operator_cloud( + config=None, strict=False, app_name=None, app_version=None, **kwargs): + if not config: + config = _get_openstack_config(app_name, app_version) + try: + cloud_region = config.get_one(**kwargs) + except keystoneauth1.exceptions.auth_plugins.NoMatchingPlugin as e: + raise OpenStackCloudException( + "Invalid cloud configuration: {exc}".format(exc=str(e))) + return OperatorCloud(cloud_config=cloud_region, strict=strict) diff --git a/openstack/cloud/cmd/inventory.py b/openstack/cloud/cmd/inventory.py index c7bc09d97..c5bc8cf26 100755 --- a/openstack/cloud/cmd/inventory.py +++ b/openstack/cloud/cmd/inventory.py @@ -60,7 +60,7 @@ def main(): elif args.host: output = inventory.get_host(args.host) print(output_format_dict(output, args.yaml)) - except openstack.OpenStackCloudException as e: + except openstack.cloud.OpenStackCloudException as e: sys.stderr.write(e.message + '\n') sys.exit(1) sys.exit(0) diff --git a/openstack/cloud/inventory.py b/openstack/cloud/inventory.py index 865339f54..5c488c2f9 100644 --- a/openstack/cloud/inventory.py +++ b/openstack/cloud/inventory.py @@ -14,8 +14,8 @@ import functools -import openstack.cloud import openstack.config +import openstack.cloud from openstack.cloud import _utils @@ -37,17 +37,17 @@ class OpenStackInventory(object): if cloud is None: self.clouds = [ - openstack.OpenStackCloud(cloud_config=cloud_region) + openstack.cloud.OpenStackCloud(cloud_config=cloud_region) for cloud_region in config.get_all() ] else: try: self.clouds = [ - openstack.OpenStackCloud( + openstack.cloud.OpenStackCloud( cloud_config=config.get_one(cloud)) ] except openstack.config.exceptions.OpenStackConfigException as e: - raise openstack.OpenStackCloudException(e) + raise openstack.cloud.OpenStackCloudException(e) if private: for cloud in self.clouds: @@ -66,7 +66,7 @@ class OpenStackInventory(object): # Cycle on servers for server in cloud.list_servers(detailed=expand): hostvars.append(server) - except openstack.OpenStackCloudException: + except openstack.cloud.OpenStackCloudException: # Don't fail on one particular cloud as others may work if fail_on_cloud_config: raise diff --git a/openstack/cloud/openstackcloud.py b/openstack/cloud/openstackcloud.py index 60a70effd..9a59156b5 100644 --- a/openstack/cloud/openstackcloud.py +++ b/openstack/cloud/openstackcloud.py @@ -329,7 +329,7 @@ class OpenStackCloud(_normalize.Normalizer): .. code-block:: python - cloud = shade.openstack_cloud(cloud='example') + cloud = openstack.cloud.openstack_cloud(cloud='example') # Work normally servers = cloud.list_servers() cloud2 = cloud.connect_as(username='different-user', password='') @@ -408,7 +408,7 @@ class OpenStackCloud(_normalize.Normalizer): .. code-block:: python - cloud = shade.openstack_cloud(cloud='example') + cloud = openstack.cloud.openstack_cloud(cloud='example') # Work normally servers = cloud.list_servers() cloud2 = cloud.connect_as_project('different-project') diff --git a/openstack/connection.py b/openstack/connection.py index 300972894..1cc1a6f0c 100644 --- a/openstack/connection.py +++ b/openstack/connection.py @@ -74,8 +74,11 @@ try to find it and if that fails, you would create it:: network = conn.network.create_network({"name": "zuul"}) """ +import warnings + import keystoneauth1.exceptions import os_service_types +import requestsexceptions import six from six.moves import urllib @@ -86,6 +89,10 @@ from openstack import exceptions from openstack import service_description from openstack import task_manager +if requestsexceptions.SubjectAltNameWarning: + warnings.filterwarnings( + 'ignore', category=requestsexceptions.SubjectAltNameWarning) + _logger = _log.setup_logging('openstack') diff --git a/openstack/tests/functional/cloud/base.py b/openstack/tests/functional/cloud/base.py index ccaabc6cd..63f14f58c 100644 --- a/openstack/tests/functional/cloud/base.py +++ b/openstack/tests/functional/cloud/base.py @@ -38,14 +38,14 @@ class BaseFunctionalTestCase(base.TestCase): def _set_user_cloud(self, **kwargs): user_config = self.config.get_one( cloud=self._demo_name, **kwargs) - self.user_cloud = openstack.OpenStackCloud( + self.user_cloud = openstack.cloud.OpenStackCloud( cloud_config=user_config, log_inner_exceptions=True) def _set_operator_cloud(self, **kwargs): operator_config = self.config.get_one( cloud=self._op_name, **kwargs) - self.operator_cloud = openstack.OperatorCloud( + self.operator_cloud = openstack.cloud.OperatorCloud( cloud_config=operator_config, log_inner_exceptions=True) diff --git a/openstack/tests/functional/cloud/test_domain.py b/openstack/tests/functional/cloud/test_domain.py index 29f99b273..a2c22bf09 100644 --- a/openstack/tests/functional/cloud/test_domain.py +++ b/openstack/tests/functional/cloud/test_domain.py @@ -46,7 +46,7 @@ class TestDomain(base.BaseFunctionalTestCase): if exception_list: # Raise an error: we must make users aware that something went # wrong - raise openstack.OpenStackCloudException( + raise openstack.cloud.OpenStackCloudException( '\n'.join(exception_list)) def test_search_domains(self): diff --git a/openstack/tests/functional/cloud/test_groups.py b/openstack/tests/functional/cloud/test_groups.py index 8d8b050e9..b5e3a4f7d 100644 --- a/openstack/tests/functional/cloud/test_groups.py +++ b/openstack/tests/functional/cloud/test_groups.py @@ -46,7 +46,7 @@ class TestGroup(base.BaseFunctionalTestCase): if exception_list: # Raise an error: we must make users aware that something went # wrong - raise openstack.OpenStackCloudException( + raise openstack.cloud.OpenStackCloudException( '\n'.join(exception_list)) def test_create_group(self): diff --git a/openstack/tests/functional/cloud/test_identity.py b/openstack/tests/functional/cloud/test_identity.py index 2d9afe459..10f1be3c4 100644 --- a/openstack/tests/functional/cloud/test_identity.py +++ b/openstack/tests/functional/cloud/test_identity.py @@ -20,7 +20,7 @@ Functional tests for `shade` identity methods. import random import string -from openstack import OpenStackCloudException +from openstack.cloud.exc import OpenStackCloudException from openstack.tests.functional.cloud import base diff --git a/openstack/tests/functional/cloud/test_users.py b/openstack/tests/functional/cloud/test_users.py index df2195a1b..3b8f5a27e 100644 --- a/openstack/tests/functional/cloud/test_users.py +++ b/openstack/tests/functional/cloud/test_users.py @@ -17,7 +17,7 @@ test_users Functional tests for `shade` user methods. """ -from openstack import OpenStackCloudException +from openstack.cloud.exc import OpenStackCloudException from openstack.tests.functional.cloud import base diff --git a/openstack/tests/unit/base.py b/openstack/tests/unit/base.py index d2caed078..0463a1d4c 100644 --- a/openstack/tests/unit/base.py +++ b/openstack/tests/unit/base.py @@ -119,14 +119,14 @@ class BaseTestCase(base.TestCase): secure_files=['non-existant']) self.cloud_config = self.config.get_one( cloud=test_cloud, validate=False) - self.cloud = openstack.OpenStackCloud( + self.cloud = openstack.cloud.OpenStackCloud( cloud_config=self.cloud_config, log_inner_exceptions=True) - self.strict_cloud = openstack.OpenStackCloud( + self.strict_cloud = openstack.cloud.OpenStackCloud( cloud_config=self.cloud_config, log_inner_exceptions=True, strict=True) - self.op_cloud = openstack.OperatorCloud( + self.op_cloud = openstack.cloud.OperatorCloud( cloud_config=self.cloud_config, log_inner_exceptions=True) @@ -465,10 +465,10 @@ class RequestsMockTestCase(BaseTestCase): cloud=test_cloud, validate=True, **kwargs) self.conn = openstack.connection.Connection( config=self.cloud_config) - self.cloud = openstack.OpenStackCloud( + self.cloud = openstack.cloud.OpenStackCloud( cloud_config=self.cloud_config, log_inner_exceptions=True) - self.op_cloud = openstack.OperatorCloud( + self.op_cloud = openstack.cloud.OperatorCloud( cloud_config=self.cloud_config, log_inner_exceptions=True) diff --git a/openstack/tests/unit/cloud/test_caching.py b/openstack/tests/unit/cloud/test_caching.py index aa26f11eb..bcfc7cd63 100644 --- a/openstack/tests/unit/cloud/test_caching.py +++ b/openstack/tests/unit/cloud/test_caching.py @@ -17,6 +17,7 @@ import munch import testtools import openstack +import openstack.cloud from openstack.cloud import exc from openstack.cloud import meta from openstack.tests import fakes @@ -104,7 +105,7 @@ class TestMemoryCache(base.RequestsMockTestCase): return self.cloud._normalize_images([fake_image]) def test_openstack_cloud(self): - self.assertIsInstance(self.cloud, openstack.OpenStackCloud) + self.assertIsInstance(self.cloud, openstack.cloud.OpenStackCloud) def test_list_projects_v3(self): project_one = self._get_project_data() @@ -480,7 +481,7 @@ class TestMemoryCache(base.RequestsMockTestCase): self.assert_calls() - @mock.patch.object(openstack.OpenStackCloud, '_image_client') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_image_client') def test_list_images_ignores_unsteady_status(self, mock_image_client): steady_image = munch.Munch(id='68', name='Jagr', status='active') for status in ('queued', 'saving', 'pending_delete'): @@ -500,7 +501,7 @@ class TestMemoryCache(base.RequestsMockTestCase): self._image_dict(steady_image)], self.cloud.list_images()) - @mock.patch.object(openstack.OpenStackCloud, '_image_client') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_image_client') def test_list_images_caches_steady_status(self, mock_image_client): steady_image = munch.Munch(id='91', name='Federov', status='active') first_image = None @@ -523,7 +524,7 @@ class TestMemoryCache(base.RequestsMockTestCase): self._munch_images(first_image), self.cloud.list_images()) - @mock.patch.object(openstack.OpenStackCloud, '_image_client') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_image_client') def test_cache_no_cloud_name(self, mock_image_client): self.cloud.name = None @@ -557,5 +558,5 @@ class TestBogusAuth(base.TestCase): def test_get_auth_bogus(self): with testtools.ExpectedException(exc.OpenStackCloudException): - openstack.openstack_cloud( + openstack.cloud.openstack_cloud( cloud='_bogus_test_', config=self.config) diff --git a/openstack/tests/unit/cloud/test_cluster_templates.py b/openstack/tests/unit/cloud/test_cluster_templates.py index 8beff5dee..56b45c028 100644 --- a/openstack/tests/unit/cloud/test_cluster_templates.py +++ b/openstack/tests/unit/cloud/test_cluster_templates.py @@ -152,7 +152,7 @@ class TestClusterTemplates(base.RequestsMockTestCase): # match the more specific HTTPError, even though it's a subclass # of OpenStackCloudException. with testtools.ExpectedException( - openstack.OpenStackCloudHTTPError): + openstack.cloud.OpenStackCloudHTTPError): self.cloud.create_cluster_template('fake-cluster-template') self.assert_calls() diff --git a/openstack/tests/unit/cloud/test_create_server.py b/openstack/tests/unit/cloud/test_create_server.py index b37b14f3d..36050ed83 100644 --- a/openstack/tests/unit/cloud/test_create_server.py +++ b/openstack/tests/unit/cloud/test_create_server.py @@ -325,7 +325,7 @@ class TestCreateServer(base.RequestsMockTestCase): self.assert_calls() - @mock.patch.object(openstack.OpenStackCloud, "wait_for_server") + @mock.patch.object(openstack.cloud.OpenStackCloud, "wait_for_server") def test_create_server_with_admin_pass_wait(self, mock_wait): """ Test that a server with an admin_pass passed returns the password @@ -411,8 +411,8 @@ class TestCreateServer(base.RequestsMockTestCase): self.assert_calls() - @mock.patch.object(openstack.OpenStackCloud, "get_active_server") - @mock.patch.object(openstack.OpenStackCloud, "get_server") + @mock.patch.object(openstack.cloud.OpenStackCloud, "get_active_server") + @mock.patch.object(openstack.cloud.OpenStackCloud, "get_server") def test_wait_for_server(self, mock_get_server, mock_get_active_server): """ Test that waiting for a server returns the server instance when @@ -446,7 +446,7 @@ class TestCreateServer(base.RequestsMockTestCase): self.assertEqual('ACTIVE', server['status']) - @mock.patch.object(openstack.OpenStackCloud, 'wait_for_server') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'wait_for_server') def test_create_server_wait(self, mock_wait): """ Test that create_server with a wait actually does the wait. @@ -483,7 +483,7 @@ class TestCreateServer(base.RequestsMockTestCase): ) self.assert_calls() - @mock.patch.object(openstack.OpenStackCloud, 'add_ips_to_server') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'add_ips_to_server') @mock.patch('time.sleep') def test_create_server_no_addresses( self, mock_sleep, mock_add_ips_to_server): diff --git a/openstack/tests/unit/cloud/test_domain_params.py b/openstack/tests/unit/cloud/test_domain_params.py index e01dd88a0..1c5395c7e 100644 --- a/openstack/tests/unit/cloud/test_domain_params.py +++ b/openstack/tests/unit/cloud/test_domain_params.py @@ -21,8 +21,8 @@ from openstack.tests.unit import base class TestDomainParams(base.TestCase): - @mock.patch.object(openstack.OpenStackCloud, '_is_client_version') - @mock.patch.object(openstack.OpenStackCloud, 'get_project') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_is_client_version') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_project') def test_identity_params_v3(self, mock_get_project, mock_is_client_version): mock_get_project.return_value = munch.Munch(id=1234) @@ -34,8 +34,8 @@ class TestDomainParams(base.TestCase): self.assertIn('domain_id', ret) self.assertEqual(ret['domain_id'], '5678') - @mock.patch.object(openstack.OpenStackCloud, '_is_client_version') - @mock.patch.object(openstack.OpenStackCloud, 'get_project') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_is_client_version') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_project') def test_identity_params_v3_no_domain( self, mock_get_project, mock_is_client_version): mock_get_project.return_value = munch.Munch(id=1234) @@ -46,8 +46,8 @@ class TestDomainParams(base.TestCase): self.cloud._get_identity_params, domain_id=None, project='bar') - @mock.patch.object(openstack.OpenStackCloud, '_is_client_version') - @mock.patch.object(openstack.OpenStackCloud, 'get_project') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_is_client_version') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_project') def test_identity_params_v2(self, mock_get_project, mock_is_client_version): mock_get_project.return_value = munch.Munch(id=1234) @@ -58,8 +58,8 @@ class TestDomainParams(base.TestCase): self.assertEqual(ret['tenant_id'], 1234) self.assertNotIn('domain', ret) - @mock.patch.object(openstack.OpenStackCloud, '_is_client_version') - @mock.patch.object(openstack.OpenStackCloud, 'get_project') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_is_client_version') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_project') def test_identity_params_v2_no_domain(self, mock_get_project, mock_is_client_version): mock_get_project.return_value = munch.Munch(id=1234) diff --git a/openstack/tests/unit/cloud/test_domains.py b/openstack/tests/unit/cloud/test_domains.py index d531768b8..2bb69f8c6 100644 --- a/openstack/tests/unit/cloud/test_domains.py +++ b/openstack/tests/unit/cloud/test_domains.py @@ -94,7 +94,7 @@ class TestDomains(base.RequestsMockTestCase): domain_data = self._get_domain_data(domain_name='domain_name', enabled=True) with testtools.ExpectedException( - openstack.OpenStackCloudBadRequest, + openstack.cloud.OpenStackCloudBadRequest, "Failed to create domain domain_name" ): self.register_uris([ @@ -149,7 +149,7 @@ class TestDomains(base.RequestsMockTestCase): validate=dict(json={'domain': {'enabled': False}})), dict(method='DELETE', uri=domain_resource_uri, status_code=404)]) with testtools.ExpectedException( - openstack.OpenStackCloudURINotFound, + openstack.cloud.OpenStackCloudURINotFound, "Failed to delete domain %s" % domain_data.domain_id ): self.op_cloud.delete_domain(domain_data.domain_id) @@ -203,7 +203,7 @@ class TestDomains(base.RequestsMockTestCase): json=domain_data.json_response, validate=dict(json={'domain': {'enabled': False}}))]) with testtools.ExpectedException( - openstack.OpenStackCloudHTTPError, + openstack.cloud.OpenStackCloudHTTPError, "Error in updating domain %s" % domain_data.domain_id ): self.op_cloud.delete_domain(domain_data.domain_id) diff --git a/openstack/tests/unit/cloud/test_flavors.py b/openstack/tests/unit/cloud/test_flavors.py index f72641927..094068887 100644 --- a/openstack/tests/unit/cloud/test_flavors.py +++ b/openstack/tests/unit/cloud/test_flavors.py @@ -78,7 +78,7 @@ class TestFlavors(base.RequestsMockTestCase): endpoint=fakes.COMPUTE_ENDPOINT, id=fakes.FLAVOR_ID), status_code=503)]) - self.assertRaises(openstack.OpenStackCloudException, + self.assertRaises(openstack.cloud.OpenStackCloudException, self.op_cloud.delete_flavor, 'vanilla') def test_list_flavors(self): @@ -153,7 +153,7 @@ class TestFlavors(base.RequestsMockTestCase): endpoint=fakes.COMPUTE_ENDPOINT), json={'flavors': []})]) self.assertRaises( - openstack.OpenStackCloudException, + openstack.cloud.OpenStackCloudException, self.cloud.get_flavor_by_ram, ram=100) diff --git a/openstack/tests/unit/cloud/test_floating_ip_common.py b/openstack/tests/unit/cloud/test_floating_ip_common.py index f4c3a0fc3..e7c20f923 100644 --- a/openstack/tests/unit/cloud/test_floating_ip_common.py +++ b/openstack/tests/unit/cloud/test_floating_ip_common.py @@ -22,7 +22,7 @@ Tests floating IP resource methods for Neutron and Nova-network. from mock import patch from openstack.cloud import meta -from openstack import OpenStackCloud +from openstack.cloud import OpenStackCloud from openstack.tests import fakes from openstack.tests.unit import base diff --git a/openstack/tests/unit/cloud/test_floating_ip_pool.py b/openstack/tests/unit/cloud/test_floating_ip_pool.py index 4d3ee8369..37a27f812 100644 --- a/openstack/tests/unit/cloud/test_floating_ip_pool.py +++ b/openstack/tests/unit/cloud/test_floating_ip_pool.py @@ -19,7 +19,7 @@ test_floating_ip_pool Test floating IP pool resource (managed by nova) """ -from openstack import OpenStackCloudException +from openstack.cloud.exc import OpenStackCloudException from openstack.tests.unit import base from openstack.tests import fakes diff --git a/openstack/tests/unit/cloud/test_identity_roles.py b/openstack/tests/unit/cloud/test_identity_roles.py index 8872da0c6..51a4a8c2a 100644 --- a/openstack/tests/unit/cloud/test_identity_roles.py +++ b/openstack/tests/unit/cloud/test_identity_roles.py @@ -292,7 +292,7 @@ class TestIdentityRoles(base.RequestsMockTestCase): def test_list_role_assignments_exception_v2(self): self.use_keystone_v2() with testtools.ExpectedException( - openstack.OpenStackCloudException, + openstack.cloud.OpenStackCloudException, "Must provide project and user for keystone v2" ): self.op_cloud.list_role_assignments() @@ -301,7 +301,7 @@ class TestIdentityRoles(base.RequestsMockTestCase): def test_list_role_assignments_exception_v2_no_project(self): self.use_keystone_v2() with testtools.ExpectedException( - openstack.OpenStackCloudException, + openstack.cloud.OpenStackCloudException, "Must provide project and user for keystone v2" ): self.op_cloud.list_role_assignments(filters={'user': '12345'}) diff --git a/openstack/tests/unit/cloud/test_image.py b/openstack/tests/unit/cloud/test_image.py index 4fa06cd83..1511d9b9a 100644 --- a/openstack/tests/unit/cloud/test_image.py +++ b/openstack/tests/unit/cloud/test_image.py @@ -588,8 +588,8 @@ class TestImage(BaseTestImage): is_public=False, **kwargs) # TODO(shade) Migrate this to requests-mock - @mock.patch.object(openstack.OpenStackCloud, '_is_client_version') - @mock.patch.object(openstack.OpenStackCloud, '_image_client') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_is_client_version') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_image_client') def test_create_image_put_v1( self, mock_image_client, mock_is_client_version): mock_is_client_version.return_value = False @@ -626,8 +626,8 @@ class TestImage(BaseTestImage): self._munch_images(ret), self.cloud.list_images()) # TODO(shade) Migrate this to requests-mock - @mock.patch.object(openstack.OpenStackCloud, '_is_client_version') - @mock.patch.object(openstack.OpenStackCloud, '_image_client') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_is_client_version') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_image_client') def test_create_image_put_v1_bad_delete( self, mock_image_client, mock_is_client_version): mock_is_client_version.return_value = False @@ -665,8 +665,8 @@ class TestImage(BaseTestImage): mock_image_client.delete.assert_called_with('/images/42') # TODO(shade) Migrate this to requests-mock - @mock.patch.object(openstack.OpenStackCloud, '_is_client_version') - @mock.patch.object(openstack.OpenStackCloud, '_image_client') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_is_client_version') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_image_client') def test_update_image_no_patch( self, mock_image_client, mock_is_client_version): mock_is_client_version.return_value = True @@ -697,8 +697,8 @@ class TestImage(BaseTestImage): mock_image_client.patch.assert_not_called() # TODO(shade) Migrate this to requests-mock - @mock.patch.object(openstack.OpenStackCloud, '_is_client_version') - @mock.patch.object(openstack.OpenStackCloud, '_image_client') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_is_client_version') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_image_client') def test_create_image_put_v2_bad_delete( self, mock_image_client, mock_is_client_version): mock_is_client_version.return_value = True @@ -737,8 +737,8 @@ class TestImage(BaseTestImage): mock_image_client.delete.assert_called_with('/images/42') # TODO(shade) Migrate this to requests-mock - @mock.patch.object(openstack.OpenStackCloud, '_is_client_version') - @mock.patch.object(openstack.OpenStackCloud, '_image_client') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_is_client_version') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_image_client') def test_create_image_put_bad_int( self, mock_image_client, mock_is_client_version): mock_is_client_version.return_value = True @@ -750,8 +750,8 @@ class TestImage(BaseTestImage): mock_image_client.post.assert_not_called() # TODO(shade) Migrate this to requests-mock - @mock.patch.object(openstack.OpenStackCloud, '_is_client_version') - @mock.patch.object(openstack.OpenStackCloud, '_image_client') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_is_client_version') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_image_client') def test_create_image_put_user_int( self, mock_image_client, mock_is_client_version): mock_is_client_version.return_value = True @@ -786,8 +786,8 @@ class TestImage(BaseTestImage): self._munch_images(ret), self.cloud.list_images()) # TODO(shade) Migrate this to requests-mock - @mock.patch.object(openstack.OpenStackCloud, '_is_client_version') - @mock.patch.object(openstack.OpenStackCloud, '_image_client') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_is_client_version') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_image_client') def test_create_image_put_meta_int( self, mock_image_client, mock_is_client_version): mock_is_client_version.return_value = True @@ -816,8 +816,8 @@ class TestImage(BaseTestImage): self._munch_images(ret), self.cloud.list_images()) # TODO(shade) Migrate this to requests-mock - @mock.patch.object(openstack.OpenStackCloud, '_is_client_version') - @mock.patch.object(openstack.OpenStackCloud, '_image_client') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_is_client_version') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_image_client') def test_create_image_put_protected( self, mock_image_client, mock_is_client_version): mock_is_client_version.return_value = True @@ -855,8 +855,8 @@ class TestImage(BaseTestImage): self.assertEqual(self._munch_images(ret), self.cloud.list_images()) # TODO(shade) Migrate this to requests-mock - @mock.patch.object(openstack.OpenStackCloud, '_is_client_version') - @mock.patch.object(openstack.OpenStackCloud, '_image_client') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_is_client_version') + @mock.patch.object(openstack.cloud.OpenStackCloud, '_image_client') def test_create_image_put_user_prop( self, mock_image_client, mock_is_client_version): mock_is_client_version.return_value = True diff --git a/openstack/tests/unit/cloud/test_inventory.py b/openstack/tests/unit/cloud/test_inventory.py index b06be882f..4f4b04104 100644 --- a/openstack/tests/unit/cloud/test_inventory.py +++ b/openstack/tests/unit/cloud/test_inventory.py @@ -26,7 +26,7 @@ class TestInventory(base.TestCase): super(TestInventory, self).setUp() @mock.patch("openstack.config.loader.OpenStackConfig") - @mock.patch("openstack.OpenStackCloud") + @mock.patch("openstack.cloud.OpenStackCloud") def test__init(self, mock_cloud, mock_config): mock_config.return_value.get_all.return_value = [{}] @@ -40,7 +40,7 @@ class TestInventory(base.TestCase): self.assertTrue(mock_config.return_value.get_all.called) @mock.patch("openstack.config.loader.OpenStackConfig") - @mock.patch("openstack.OpenStackCloud") + @mock.patch("openstack.cloud.OpenStackCloud") def test__init_one_cloud(self, mock_cloud, mock_config): mock_config.return_value.get_one.return_value = [{}] @@ -56,7 +56,7 @@ class TestInventory(base.TestCase): 'supercloud') @mock.patch("openstack.config.loader.OpenStackConfig") - @mock.patch("openstack.OpenStackCloud") + @mock.patch("openstack.cloud.OpenStackCloud") def test__raise_exception_on_no_cloud(self, mock_cloud, mock_config): """ Test that when os-client-config can't find a named cloud, a @@ -72,7 +72,7 @@ class TestInventory(base.TestCase): 'supercloud') @mock.patch("openstack.config.loader.OpenStackConfig") - @mock.patch("openstack.OpenStackCloud") + @mock.patch("openstack.cloud.OpenStackCloud") def test_list_hosts(self, mock_cloud, mock_config): mock_config.return_value.get_all.return_value = [{}] @@ -91,7 +91,7 @@ class TestInventory(base.TestCase): self.assertEqual([server], ret) @mock.patch("openstack.config.loader.OpenStackConfig") - @mock.patch("openstack.OpenStackCloud") + @mock.patch("openstack.cloud.OpenStackCloud") def test_list_hosts_no_detail(self, mock_cloud, mock_config): mock_config.return_value.get_all.return_value = [{}] @@ -110,7 +110,7 @@ class TestInventory(base.TestCase): self.assertFalse(inv.clouds[0].get_openstack_vars.called) @mock.patch("openstack.config.loader.OpenStackConfig") - @mock.patch("openstack.OpenStackCloud") + @mock.patch("openstack.cloud.OpenStackCloud") def test_search_hosts(self, mock_cloud, mock_config): mock_config.return_value.get_all.return_value = [{}] @@ -126,7 +126,7 @@ class TestInventory(base.TestCase): self.assertEqual([server], ret) @mock.patch("openstack.config.loader.OpenStackConfig") - @mock.patch("openstack.OpenStackCloud") + @mock.patch("openstack.cloud.OpenStackCloud") def test_get_host(self, mock_cloud, mock_config): mock_config.return_value.get_all.return_value = [{}] diff --git a/openstack/tests/unit/cloud/test_meta.py b/openstack/tests/unit/cloud/test_meta.py index de3da10d6..29634f9db 100644 --- a/openstack/tests/unit/cloud/test_meta.py +++ b/openstack/tests/unit/cloud/test_meta.py @@ -333,10 +333,10 @@ class TestMeta(base.RequestsMockTestCase): '10.0.0.101', meta.get_server_private_ip(srv, self.cloud)) self.assert_calls() - @mock.patch.object(openstack.OpenStackCloud, 'has_service') - @mock.patch.object(openstack.OpenStackCloud, 'get_volumes') - @mock.patch.object(openstack.OpenStackCloud, 'get_image_name') - @mock.patch.object(openstack.OpenStackCloud, 'get_flavor_name') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'has_service') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_volumes') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_image_name') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_flavor_name') def test_get_server_private_ip_devstack( self, mock_get_flavor_name, mock_get_image_name, @@ -398,9 +398,9 @@ class TestMeta(base.RequestsMockTestCase): self.assertEqual(PRIVATE_V4, srv['private_v4']) self.assert_calls() - @mock.patch.object(openstack.OpenStackCloud, 'get_volumes') - @mock.patch.object(openstack.OpenStackCloud, 'get_image_name') - @mock.patch.object(openstack.OpenStackCloud, 'get_flavor_name') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_volumes') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_image_name') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_flavor_name') def test_get_server_private_ip_no_fip( self, mock_get_flavor_name, mock_get_image_name, @@ -448,9 +448,9 @@ class TestMeta(base.RequestsMockTestCase): self.assertEqual(PRIVATE_V4, srv['private_v4']) self.assert_calls() - @mock.patch.object(openstack.OpenStackCloud, 'get_volumes') - @mock.patch.object(openstack.OpenStackCloud, 'get_image_name') - @mock.patch.object(openstack.OpenStackCloud, 'get_flavor_name') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_volumes') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_image_name') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_flavor_name') def test_get_server_cloud_no_fips( self, mock_get_flavor_name, mock_get_image_name, @@ -496,10 +496,10 @@ class TestMeta(base.RequestsMockTestCase): self.assertEqual(PRIVATE_V4, srv['private_v4']) self.assert_calls() - @mock.patch.object(openstack.OpenStackCloud, 'has_service') - @mock.patch.object(openstack.OpenStackCloud, 'get_volumes') - @mock.patch.object(openstack.OpenStackCloud, 'get_image_name') - @mock.patch.object(openstack.OpenStackCloud, 'get_flavor_name') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'has_service') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_volumes') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_image_name') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_flavor_name') def test_get_server_cloud_missing_fips( self, mock_get_flavor_name, mock_get_image_name, @@ -565,9 +565,9 @@ class TestMeta(base.RequestsMockTestCase): self.assertEqual(PUBLIC_V4, srv['public_v4']) self.assert_calls() - @mock.patch.object(openstack.OpenStackCloud, 'get_volumes') - @mock.patch.object(openstack.OpenStackCloud, 'get_image_name') - @mock.patch.object(openstack.OpenStackCloud, 'get_flavor_name') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_volumes') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_image_name') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_flavor_name') def test_get_server_cloud_rackspace_v6( self, mock_get_flavor_name, mock_get_image_name, mock_get_volumes): @@ -615,9 +615,9 @@ class TestMeta(base.RequestsMockTestCase): "2001:4800:7819:103:be76:4eff:fe05:8525", srv['interface_ip']) self.assert_calls() - @mock.patch.object(openstack.OpenStackCloud, 'get_volumes') - @mock.patch.object(openstack.OpenStackCloud, 'get_image_name') - @mock.patch.object(openstack.OpenStackCloud, 'get_flavor_name') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_volumes') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_image_name') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'get_flavor_name') def test_get_server_cloud_osic_split( self, mock_get_flavor_name, mock_get_image_name, mock_get_volumes): diff --git a/openstack/tests/unit/cloud/test_network.py b/openstack/tests/unit/cloud/test_network.py index 52d0449dc..9a88501cb 100644 --- a/openstack/tests/unit/cloud/test_network.py +++ b/openstack/tests/unit/cloud/test_network.py @@ -183,7 +183,7 @@ class TestNetwork(base.RequestsMockTestCase): def test_create_network_provider_wrong_type(self): provider_opts = "invalid" with testtools.ExpectedException( - openstack.OpenStackCloudException, + openstack.cloud.OpenStackCloudException, "Parameter 'provider' must be a dict" ): self.cloud.create_network("netname", provider=provider_opts) @@ -231,7 +231,7 @@ class TestNetwork(base.RequestsMockTestCase): append=['v2.0', 'networks', "%s.json" % network_id]), status_code=503) ]) - self.assertRaises(openstack.OpenStackCloudException, + self.assertRaises(openstack.cloud.OpenStackCloudException, self.cloud.delete_network, network_name) self.assert_calls() diff --git a/openstack/tests/unit/cloud/test_object.py b/openstack/tests/unit/cloud/test_object.py index f63ddd6a4..bbb879ff4 100644 --- a/openstack/tests/unit/cloud/test_object.py +++ b/openstack/tests/unit/cloud/test_object.py @@ -144,7 +144,7 @@ class TestObject(BaseTestObject): dict(method='DELETE', uri=self.container_endpoint, status_code=409)]) self.assertRaises( - openstack.OpenStackCloudException, + openstack.cloud.OpenStackCloudException, self.cloud.delete_container, self.container) self.assert_calls() @@ -171,7 +171,7 @@ class TestObject(BaseTestObject): dict(method='POST', uri=self.container_endpoint, status_code=409)]) self.assertRaises( - openstack.OpenStackCloudException, + openstack.cloud.OpenStackCloudException, self.cloud.update_container, self.container, dict(foo='bar')) self.assert_calls() @@ -205,7 +205,7 @@ class TestObject(BaseTestObject): def test_set_container_access_invalid(self): self.assertRaises( - openstack.OpenStackCloudException, + openstack.cloud.OpenStackCloudException, self.cloud.set_container_access, self.container, 'invalid') def test_get_container_access(self): @@ -360,7 +360,7 @@ class TestObject(BaseTestObject): status_code=416)]) self.assertRaises( - openstack.OpenStackCloudException, + openstack.cloud.OpenStackCloudException, self.cloud.get_object, self.container, self.object) diff --git a/openstack/tests/unit/cloud/test_operator.py b/openstack/tests/unit/cloud/test_operator.py index a9a5d0e45..fb5702e6e 100644 --- a/openstack/tests/unit/cloud/test_operator.py +++ b/openstack/tests/unit/cloud/test_operator.py @@ -13,7 +13,7 @@ import mock import testtools -import openstack +import openstack.cloud from openstack.cloud import exc from openstack.config import cloud_region from openstack.tests import fakes @@ -23,7 +23,7 @@ from openstack.tests.unit import base class TestOperatorCloud(base.RequestsMockTestCase): def test_operator_cloud(self): - self.assertIsInstance(self.op_cloud, openstack.OperatorCloud) + self.assertIsInstance(self.op_cloud, openstack.cloud.OperatorCloud) @mock.patch.object(cloud_region.CloudRegion, 'get_endpoint') def test_get_session_endpoint_provided(self, fake_get_endpoint): diff --git a/openstack/tests/unit/cloud/test_operator_noauth.py b/openstack/tests/unit/cloud/test_operator_noauth.py index 5f4367b7d..14fdd9dad 100644 --- a/openstack/tests/unit/cloud/test_operator_noauth.py +++ b/openstack/tests/unit/cloud/test_operator_noauth.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import openstack +import openstack.cloud from openstack.tests.unit import base @@ -50,7 +50,7 @@ class TestOpenStackCloudOperatorNoAuth(base.RequestsMockTestCase): # with 'v1'. As such, since we are overriding the endpoint, # we must explicitly do the same as we move away from the # client library. - self.cloud_noauth = openstack.operator_cloud( + self.cloud_noauth = openstack.cloud.operator_cloud( auth_type='none', baremetal_endpoint_override="https://bare-metal.example.com/v1") @@ -63,7 +63,7 @@ class TestOpenStackCloudOperatorNoAuth(base.RequestsMockTestCase): The old way of doing this was to abuse admin_token. """ - self.cloud_noauth = openstack.operator_cloud( + self.cloud_noauth = openstack.cloud.operator_cloud( auth_type='admin_token', auth=dict( endpoint='https://bare-metal.example.com/v1', diff --git a/openstack/tests/unit/cloud/test_project.py b/openstack/tests/unit/cloud/test_project.py index 737967966..8001260c4 100644 --- a/openstack/tests/unit/cloud/test_project.py +++ b/openstack/tests/unit/cloud/test_project.py @@ -76,7 +76,7 @@ class TestProject(base.RequestsMockTestCase): def test_create_project_v3_no_domain(self): with testtools.ExpectedException( - openstack.OpenStackCloudException, + openstack.cloud.OpenStackCloudException, "User or project creation requires an explicit" " domain_id argument." ): @@ -126,7 +126,7 @@ class TestProject(base.RequestsMockTestCase): # shade will raise an attribute error instead of the proper # project not found exception. with testtools.ExpectedException( - openstack.OpenStackCloudException, + openstack.cloud.OpenStackCloudException, "Project %s not found." % project_data.project_id ): self.op_cloud.update_project(project_data.project_id) diff --git a/openstack/tests/unit/cloud/test_security_groups.py b/openstack/tests/unit/cloud/test_security_groups.py index e49a3424a..1960373b9 100644 --- a/openstack/tests/unit/cloud/test_security_groups.py +++ b/openstack/tests/unit/cloud/test_security_groups.py @@ -83,7 +83,7 @@ class TestSecurityGroups(base.RequestsMockTestCase): self.cloud.secgroup_source = None self.has_neutron = False - self.assertRaises(openstack.OpenStackCloudUnavailableFeature, + self.assertRaises(openstack.cloud.OpenStackCloudUnavailableFeature, self.cloud.list_security_groups) def test_delete_security_group_neutron(self): @@ -146,7 +146,7 @@ class TestSecurityGroups(base.RequestsMockTestCase): def test_delete_security_group_none(self): self.cloud.secgroup_source = None - self.assertRaises(openstack.OpenStackCloudUnavailableFeature, + self.assertRaises(openstack.cloud.OpenStackCloudUnavailableFeature, self.cloud.delete_security_group, 'doesNotExist') @@ -246,7 +246,7 @@ class TestSecurityGroups(base.RequestsMockTestCase): def test_create_security_group_none(self): self.cloud.secgroup_source = None self.has_neutron = False - self.assertRaises(openstack.OpenStackCloudUnavailableFeature, + self.assertRaises(openstack.cloud.OpenStackCloudUnavailableFeature, self.cloud.create_security_group, '', '') @@ -465,7 +465,7 @@ class TestSecurityGroups(base.RequestsMockTestCase): def test_create_security_group_rule_none(self): self.has_neutron = False self.cloud.secgroup_source = None - self.assertRaises(openstack.OpenStackCloudUnavailableFeature, + self.assertRaises(openstack.cloud.OpenStackCloudUnavailableFeature, self.cloud.create_security_group_rule, '') @@ -498,7 +498,7 @@ class TestSecurityGroups(base.RequestsMockTestCase): def test_delete_security_group_rule_none(self): self.has_neutron = False self.cloud.secgroup_source = None - self.assertRaises(openstack.OpenStackCloudUnavailableFeature, + self.assertRaises(openstack.cloud.OpenStackCloudUnavailableFeature, self.cloud.delete_security_group_rule, '') @@ -538,7 +538,7 @@ class TestSecurityGroups(base.RequestsMockTestCase): endpoint=fakes.COMPUTE_ENDPOINT), json={'security_groups': [nova_grp_dict]}), ]) - self.assertRaises(openstack.OpenStackCloudException, + self.assertRaises(openstack.cloud.OpenStackCloudException, self.cloud.create_security_group_rule, secgroup_name_or_id='nova-sec-group', direction='egress') diff --git a/openstack/tests/unit/cloud/test_services.py b/openstack/tests/unit/cloud/test_services.py index cfbb261d0..488eacdc8 100644 --- a/openstack/tests/unit/cloud/test_services.py +++ b/openstack/tests/unit/cloud/test_services.py @@ -19,7 +19,7 @@ test_cloud_services Tests Keystone services commands. """ -from openstack import OpenStackCloudException +from openstack.cloud.exc import OpenStackCloudException from openstack.cloud.exc import OpenStackCloudUnavailableFeature from openstack.tests.unit import base from testtools import matchers diff --git a/openstack/tests/unit/cloud/test_shade.py b/openstack/tests/unit/cloud/test_shade.py index 6b3be1387..d8ea062bf 100644 --- a/openstack/tests/unit/cloud/test_shade.py +++ b/openstack/tests/unit/cloud/test_shade.py @@ -52,9 +52,9 @@ class TestShade(base.RequestsMockTestCase): self.cloud.has_service = fake_has_service def test_openstack_cloud(self): - self.assertIsInstance(self.cloud, openstack.OpenStackCloud) + self.assertIsInstance(self.cloud, openstack.cloud.OpenStackCloud) - @mock.patch.object(openstack.OpenStackCloud, 'search_images') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'search_images') def test_get_images(self, mock_search): image1 = dict(id='123', name='mickey') mock_search.return_value = [image1] @@ -62,7 +62,7 @@ class TestShade(base.RequestsMockTestCase): self.assertIsNotNone(r) self.assertDictEqual(image1, r) - @mock.patch.object(openstack.OpenStackCloud, 'search_images') + @mock.patch.object(openstack.cloud.OpenStackCloud, 'search_images') def test_get_image_not_found(self, mock_search): mock_search.return_value = [] r = self.cloud.get_image('doesNotExist') diff --git a/openstack/tests/unit/cloud/test_stack.py b/openstack/tests/unit/cloud/test_stack.py index 4e99dbddd..448a09857 100644 --- a/openstack/tests/unit/cloud/test_stack.py +++ b/openstack/tests/unit/cloud/test_stack.py @@ -57,7 +57,7 @@ class TestStack(base.RequestsMockTestCase): status_code=404) ]) with testtools.ExpectedException( - openstack.OpenStackCloudURINotFound): + openstack.cloud.OpenStackCloudURINotFound): self.cloud.list_stacks() self.assert_calls() @@ -110,7 +110,7 @@ class TestStack(base.RequestsMockTestCase): status_code=404) ]) with testtools.ExpectedException( - openstack.OpenStackCloudURINotFound): + openstack.cloud.OpenStackCloudURINotFound): self.cloud.search_stacks() def test_delete_stack(self): @@ -171,7 +171,7 @@ class TestStack(base.RequestsMockTestCase): reason="ouch"), ]) with testtools.ExpectedException( - openstack.OpenStackCloudBadRequest): + openstack.cloud.OpenStackCloudBadRequest): self.cloud.delete_stack(self.stack_id) self.assert_calls() @@ -288,7 +288,7 @@ class TestStack(base.RequestsMockTestCase): ]) with testtools.ExpectedException( - openstack.OpenStackCloudException): + openstack.cloud.OpenStackCloudException): self.cloud.delete_stack(self.stack_id, wait=True) self.assert_calls() diff --git a/openstack/tests/unit/cloud/test_users.py b/openstack/tests/unit/cloud/test_users.py index a4c8a466f..a5c00a6c8 100644 --- a/openstack/tests/unit/cloud/test_users.py +++ b/openstack/tests/unit/cloud/test_users.py @@ -124,7 +124,7 @@ class TestUsers(base.RequestsMockTestCase): user_data = self._get_user_data(domain_id=uuid.uuid4().hex, email='test@example.com') with testtools.ExpectedException( - openstack.OpenStackCloudException, + openstack.cloud.OpenStackCloudException, "User or project creation requires an explicit" " domain_id argument." ): diff --git a/openstack/tests/unit/cloud/test_volume.py b/openstack/tests/unit/cloud/test_volume.py index 84bf9b334..9c1e2380e 100644 --- a/openstack/tests/unit/cloud/test_volume.py +++ b/openstack/tests/unit/cloud/test_volume.py @@ -60,7 +60,7 @@ class TestVolume(base.RequestsMockTestCase): 'volumeId': vol['id']}}) )]) with testtools.ExpectedException( - openstack.OpenStackCloudURINotFound, + openstack.cloud.OpenStackCloudURINotFound, "Error attaching volume %s to server %s" % ( volume['id'], server['id']) ): @@ -126,7 +126,7 @@ class TestVolume(base.RequestsMockTestCase): json={'volumes': [errored_volume]})]) with testtools.ExpectedException( - openstack.OpenStackCloudException, + openstack.cloud.OpenStackCloudException, "Error in attaching volume %s" % errored_volume['id'] ): self.cloud.attach_volume(server, volume) @@ -137,7 +137,7 @@ class TestVolume(base.RequestsMockTestCase): volume = dict(id='volume001', status='error', attachments=[]) with testtools.ExpectedException( - openstack.OpenStackCloudException, + openstack.cloud.OpenStackCloudException, "Volume %s is not available. Status is '%s'" % ( volume['id'], volume['status']) ): @@ -153,7 +153,7 @@ class TestVolume(base.RequestsMockTestCase): ]) with testtools.ExpectedException( - openstack.OpenStackCloudException, + openstack.cloud.OpenStackCloudException, "Volume %s already attached to server %s on device %s" % ( volume['id'], server['id'], device_id) ): @@ -189,7 +189,7 @@ class TestVolume(base.RequestsMockTestCase): 'os-volume_attachments', volume['id']]), status_code=404)]) with testtools.ExpectedException( - openstack.OpenStackCloudURINotFound, + openstack.cloud.OpenStackCloudURINotFound, "Error detaching volume %s from server %s" % ( volume['id'], server['id']) ): @@ -238,7 +238,7 @@ class TestVolume(base.RequestsMockTestCase): 'volumev2', 'public', append=['volumes', 'detail']), json={'volumes': [errored_volume]})]) with testtools.ExpectedException( - openstack.OpenStackCloudException, + openstack.cloud.OpenStackCloudException, "Error in detaching volume %s" % errored_volume['id'] ): self.cloud.detach_volume(server, volume) diff --git a/openstack/tests/unit/cloud/test_volume_access.py b/openstack/tests/unit/cloud/test_volume_access.py index 8124f3e59..79b1697ee 100644 --- a/openstack/tests/unit/cloud/test_volume_access.py +++ b/openstack/tests/unit/cloud/test_volume_access.py @@ -187,7 +187,7 @@ class TestVolumeAccess(base.RequestsMockTestCase): qs_elements=['is_public=None']), json={'volume_types': [volume_type]})]) with testtools.ExpectedException( - openstack.OpenStackCloudException, + openstack.cloud.OpenStackCloudException, "VolumeType not found: MISSING"): self.op_cloud.add_volume_type_access( "MISSING", project_001['project_id'])