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
This commit is contained in:
Monty Taylor 2018-01-18 16:53:26 -06:00
parent 34f1e046b4
commit e636890d59
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
47 changed files with 245 additions and 248 deletions

View File

@ -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(

View File

@ -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')

View File

@ -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:

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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(

View File

@ -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')

View File

@ -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(

View File

@ -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')

View File

@ -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')

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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')

View File

@ -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')

View File

@ -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)

View File

@ -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):

View File

@ -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):

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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()

View File

@ -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):

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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'})

View File

@ -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

View File

@ -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 = [{}]

View File

@ -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):

View File

@ -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()

View File

@ -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)

View File

@ -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):

View File

@ -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',

View File

@ -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)

View File

@ -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')

View File

@ -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

View File

@ -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')

View File

@ -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()

View File

@ -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."
):

View File

@ -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)

View File

@ -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'])