Make it clear that OpenStackCloud is a mixin

It's not clear that this is a mixin. Make it clear. There was also a
documentation page that referenced it like it was a separate thing.
Remove that, since it's covered in the Connection docs.

Change-Id: I13bbf5155f7ee2aabe78ec93eb22175ec2403cfb
This commit is contained in:
Monty Taylor 2018-10-05 12:28:25 -05:00
parent 877326aa73
commit 1370553e73
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
10 changed files with 64 additions and 120 deletions

View File

@ -28,7 +28,6 @@ approach, this is where you'll want to begin.
Configuration <config/index>
Connect to an OpenStack Cloud <guides/connect>
Connect to an OpenStack Cloud Using a Config File <guides/connect_from_config>
Using Cloud Abstration Layer <usage>
Logging <guides/logging>
Microversions <microversions>
Baremetal <guides/baremetal>

View File

@ -1,19 +0,0 @@
=====
Usage
=====
To use `openstack.cloud` in a project:
.. code-block:: python
import openstack.cloud
.. note::
API methods that return a description of an OpenStack resource (e.g.,
server instance, image, volume, etc.) do so using a `munch.Munch` object
from the `Munch library <https://github.com/Infinidat/munch>`_. `Munch`
objects can be accessed using either dictionary or object notation
(e.g., ``server.id``, ``image.name`` and ``server['id']``, ``image['name']``)
.. autoclass:: openstack.cloud.OpenStackCloud
:members:

View File

@ -12,44 +12,5 @@
# 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 import exc
from openstack.cloud.openstackcloud import OpenStackCloud
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=cloud_region.name, debug=debug,
cloud_config=cloud_region,
strict=strict)
for cloud_region in config.get_all()
]
else:
return [
OpenStackCloud(
cloud=cloud_region.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 exc.OpenStackCloudException(
"Invalid cloud configuration: {exc}".format(exc=str(e)))

View File

@ -98,7 +98,7 @@ def _no_pending_stacks(stacks):
return True
class OpenStackCloud(_normalize.Normalizer):
class _OpenStackCloudMixin(_normalize.Normalizer):
"""Represent a connection to an OpenStack Cloud.
OpenStackCloud is the entry point for all cloud operations, regardless

View File

@ -163,7 +163,7 @@ import six
from openstack import _log
from openstack._meta import connection as _meta
from openstack import cloud as _cloud
from openstack.cloud import openstackcloud as _cloud
from openstack import config as _config
from openstack.config import cloud_region
from openstack import exceptions
@ -212,7 +212,7 @@ def from_config(cloud=None, config=None, options=None, **kwargs):
class Connection(six.with_metaclass(_meta.ConnectionMeta,
_cloud.OpenStackCloud)):
_cloud._OpenStackCloudMixin)):
def __init__(self, cloud=None, config=None, session=None,
app_name=None, app_version=None,
@ -295,9 +295,9 @@ class Connection(six.with_metaclass(_meta.ConnectionMeta,
self._proxies = {}
self.use_direct_get = use_direct_get
self.strict_mode = strict
# Call the OpenStackCloud constructor while we work on integrating
# things better.
_cloud.OpenStackCloud.__init__(self)
# Call the _OpenStackCloudMixin constructor while we work on
# integrating things better.
_cloud._OpenStackCloudMixin.__init__(self)
@property
def session(self):

View File

@ -104,7 +104,7 @@ class TestMemoryCache(base.TestCase):
return self.cloud._normalize_images([fake_image])
def test_openstack_cloud(self):
self.assertIsInstance(self.cloud, openstack.cloud.OpenStackCloud)
self.assertIsInstance(self.cloud, openstack.connection.Connection)
def test_list_projects_v3(self):
project_one = self._get_project_data()

View File

@ -21,7 +21,7 @@ import uuid
import mock
import openstack.cloud
from openstack.cloud import openstackcloud
from openstack.cloud import exc
from openstack.cloud import meta
from openstack.tests import fakes
@ -325,7 +325,7 @@ class TestCreateServer(base.TestCase):
self.assert_calls()
@mock.patch.object(openstack.cloud.OpenStackCloud, "wait_for_server")
@mock.patch.object(openstackcloud._OpenStackCloudMixin, "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,9 @@ class TestCreateServer(base.TestCase):
self.assert_calls()
@mock.patch.object(openstack.cloud.OpenStackCloud, "get_active_server")
@mock.patch.object(openstack.cloud.OpenStackCloud, "get_server")
@mock.patch.object(
openstackcloud._OpenStackCloudMixin, "get_active_server")
@mock.patch.object(openstackcloud._OpenStackCloudMixin, "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 +447,7 @@ class TestCreateServer(base.TestCase):
self.assertEqual('ACTIVE', server['status'])
@mock.patch.object(openstack.cloud.OpenStackCloud, 'wait_for_server')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'wait_for_server')
def test_create_server_wait(self, mock_wait):
"""
Test that create_server with a wait actually does the wait.
@ -483,7 +484,8 @@ class TestCreateServer(base.TestCase):
)
self.assert_calls()
@mock.patch.object(openstack.cloud.OpenStackCloud, 'add_ips_to_server')
@mock.patch.object(
openstackcloud._OpenStackCloudMixin, 'add_ips_to_server')
def test_create_server_no_addresses(
self, mock_add_ips_to_server):
"""

View File

@ -22,16 +22,16 @@ Tests floating IP resource methods for Neutron and Nova-network.
from mock import patch
from openstack.cloud import meta
from openstack.cloud import OpenStackCloud
from openstack.cloud import openstackcloud
from openstack.tests import fakes
from openstack.tests.unit import base
class TestFloatingIP(base.TestCase):
@patch.object(OpenStackCloud, 'get_floating_ip')
@patch.object(OpenStackCloud, '_attach_ip_to_server')
@patch.object(OpenStackCloud, 'available_floating_ip')
@patch.object(openstackcloud._OpenStackCloudMixin, 'get_floating_ip')
@patch.object(openstackcloud._OpenStackCloudMixin, '_attach_ip_to_server')
@patch.object(openstackcloud._OpenStackCloudMixin, 'available_floating_ip')
def test_add_auto_ip(
self, mock_available_floating_ip, mock_attach_ip_to_server,
mock_get_floating_ip):
@ -57,7 +57,7 @@ class TestFloatingIP(base.TestCase):
timeout=60, wait=False, server=server_dict,
floating_ip=floating_ip_dict, skip_attach=False)
@patch.object(OpenStackCloud, '_add_ip_from_pool')
@patch.object(openstackcloud._OpenStackCloudMixin, '_add_ip_from_pool')
def test_add_ips_to_server_pool(self, mock_add_ip_from_pool):
server_dict = fakes.make_fake_server(
server_id='romeo', name='test-server', status="ACTIVE",
@ -70,9 +70,9 @@ class TestFloatingIP(base.TestCase):
server_dict, pool, reuse=True, wait=False, timeout=60,
fixed_address=None, nat_destination=None)
@patch.object(OpenStackCloud, 'has_service')
@patch.object(OpenStackCloud, 'get_floating_ip')
@patch.object(OpenStackCloud, '_add_auto_ip')
@patch.object(openstackcloud._OpenStackCloudMixin, 'has_service')
@patch.object(openstackcloud._OpenStackCloudMixin, 'get_floating_ip')
@patch.object(openstackcloud._OpenStackCloudMixin, '_add_auto_ip')
def test_add_ips_to_server_ipv6_only(
self, mock_add_auto_ip,
mock_get_floating_ip,
@ -109,9 +109,9 @@ class TestFloatingIP(base.TestCase):
self.assertEqual(
new_server['public_v6'], '2001:4800:7819:103:be76:4eff:fe05:8525')
@patch.object(OpenStackCloud, 'has_service')
@patch.object(OpenStackCloud, 'get_floating_ip')
@patch.object(OpenStackCloud, '_add_auto_ip')
@patch.object(openstackcloud._OpenStackCloudMixin, 'has_service')
@patch.object(openstackcloud._OpenStackCloudMixin, 'get_floating_ip')
@patch.object(openstackcloud._OpenStackCloudMixin, '_add_auto_ip')
def test_add_ips_to_server_rackspace(
self, mock_add_auto_ip,
mock_get_floating_ip,
@ -145,9 +145,9 @@ class TestFloatingIP(base.TestCase):
new_server['interface_ip'],
'2001:4800:7819:103:be76:4eff:fe05:8525')
@patch.object(OpenStackCloud, 'has_service')
@patch.object(OpenStackCloud, 'get_floating_ip')
@patch.object(OpenStackCloud, '_add_auto_ip')
@patch.object(openstackcloud._OpenStackCloudMixin, 'has_service')
@patch.object(openstackcloud._OpenStackCloudMixin, 'get_floating_ip')
@patch.object(openstackcloud._OpenStackCloudMixin, '_add_auto_ip')
def test_add_ips_to_server_rackspace_local_ipv4(
self, mock_add_auto_ip,
mock_get_floating_ip,
@ -179,7 +179,7 @@ class TestFloatingIP(base.TestCase):
mock_add_auto_ip.assert_not_called()
self.assertEqual(new_server['interface_ip'], '104.130.246.91')
@patch.object(OpenStackCloud, 'add_ip_list')
@patch.object(openstackcloud._OpenStackCloudMixin, 'add_ip_list')
def test_add_ips_to_server_ip_list(self, mock_add_ip_list):
server_dict = fakes.make_fake_server(
server_id='server-id', name='test-server', status="ACTIVE",
@ -191,8 +191,8 @@ class TestFloatingIP(base.TestCase):
mock_add_ip_list.assert_called_with(
server_dict, ips, wait=False, timeout=60, fixed_address=None)
@patch.object(OpenStackCloud, '_needs_floating_ip')
@patch.object(OpenStackCloud, '_add_auto_ip')
@patch.object(openstackcloud._OpenStackCloudMixin, '_needs_floating_ip')
@patch.object(openstackcloud._OpenStackCloudMixin, '_add_auto_ip')
def test_add_ips_to_server_auto_ip(
self, mock_add_auto_ip, mock_needs_floating_ip):
server_dict = fakes.make_fake_server(

View File

@ -14,7 +14,7 @@
import mock
import openstack.cloud
from openstack.cloud import openstackcloud
from openstack.cloud import meta
from openstack.tests import fakes
from openstack.tests.unit import base
@ -352,10 +352,10 @@ class TestMeta(base.TestCase):
'10.0.0.101', meta.get_server_private_ip(srv, self.cloud))
self.assert_calls()
@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')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'has_service')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_volumes')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_image_name')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_flavor_name')
def test_get_server_private_ip_devstack(
self,
mock_get_flavor_name, mock_get_image_name,
@ -417,9 +417,9 @@ class TestMeta(base.TestCase):
self.assertEqual(PRIVATE_V4, srv['private_v4'])
self.assert_calls()
@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')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_volumes')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_image_name')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_flavor_name')
def test_get_server_private_ip_no_fip(
self,
mock_get_flavor_name, mock_get_image_name,
@ -467,9 +467,9 @@ class TestMeta(base.TestCase):
self.assertEqual(PRIVATE_V4, srv['private_v4'])
self.assert_calls()
@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')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_volumes')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_image_name')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_flavor_name')
def test_get_server_cloud_no_fips(
self,
mock_get_flavor_name, mock_get_image_name,
@ -515,10 +515,10 @@ class TestMeta(base.TestCase):
self.assertEqual(PRIVATE_V4, srv['private_v4'])
self.assert_calls()
@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')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'has_service')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_volumes')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_image_name')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_flavor_name')
def test_get_server_cloud_missing_fips(
self,
mock_get_flavor_name, mock_get_image_name,
@ -584,9 +584,9 @@ class TestMeta(base.TestCase):
self.assertEqual(PUBLIC_V4, srv['public_v4'])
self.assert_calls()
@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')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_volumes')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_image_name')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_flavor_name')
def test_get_server_cloud_rackspace_v6(
self, mock_get_flavor_name, mock_get_image_name,
mock_get_volumes):
@ -634,9 +634,9 @@ class TestMeta(base.TestCase):
"2001:4800:7819:103:be76:4eff:fe05:8525", srv['interface_ip'])
self.assert_calls()
@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')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_volumes')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_image_name')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'get_flavor_name')
def test_get_server_cloud_osic_split(
self, mock_get_flavor_name, mock_get_image_name,
mock_get_volumes):
@ -918,8 +918,8 @@ class TestMeta(base.TestCase):
self.assertEqual('testgroup',
hostvars['security_groups'][0]['name'])
@mock.patch.object(openstack.cloud.meta, 'get_server_external_ipv6')
@mock.patch.object(openstack.cloud.meta, 'get_server_external_ipv4')
@mock.patch.object(meta, 'get_server_external_ipv6')
@mock.patch.object(meta, 'get_server_external_ipv4')
def test_basic_hostvars(
self, mock_get_server_external_ipv4,
mock_get_server_external_ipv6):
@ -952,8 +952,8 @@ class TestMeta(base.TestCase):
# test volume exception
self.assertEqual([], hostvars['volumes'])
@mock.patch.object(openstack.cloud.meta, 'get_server_external_ipv6')
@mock.patch.object(openstack.cloud.meta, 'get_server_external_ipv4')
@mock.patch.object(meta, 'get_server_external_ipv6')
@mock.patch.object(meta, 'get_server_external_ipv4')
def test_ipv4_hostvars(
self, mock_get_server_external_ipv4,
mock_get_server_external_ipv6):
@ -966,7 +966,7 @@ class TestMeta(base.TestCase):
fake_cloud, meta.obj_to_munch(standard_fake_server))
self.assertEqual(PUBLIC_V4, hostvars['interface_ip'])
@mock.patch.object(openstack.cloud.meta, 'get_server_external_ipv4')
@mock.patch.object(meta, 'get_server_external_ipv4')
def test_private_interface_ip(self, mock_get_server_external_ipv4):
mock_get_server_external_ipv4.return_value = PUBLIC_V4
@ -976,7 +976,7 @@ class TestMeta(base.TestCase):
cloud, meta.obj_to_munch(standard_fake_server))
self.assertEqual(PRIVATE_V4, hostvars['interface_ip'])
@mock.patch.object(openstack.cloud.meta, 'get_server_external_ipv4')
@mock.patch.object(meta, 'get_server_external_ipv4')
def test_image_string(self, mock_get_server_external_ipv4):
mock_get_server_external_ipv4.return_value = PUBLIC_V4

View File

@ -15,8 +15,9 @@ import uuid
import testtools
import openstack.cloud
from openstack.cloud import openstackcloud
from openstack.cloud import exc
from openstack import connection
from openstack.tests import fakes
from openstack.tests.unit import base
from openstack import utils
@ -52,7 +53,7 @@ class TestShade(base.TestCase):
self.cloud.has_service = fake_has_service
def test_openstack_cloud(self):
self.assertIsInstance(self.cloud, openstack.cloud.OpenStackCloud)
self.assertIsInstance(self.cloud, connection.Connection)
def test_connect_as(self):
# Do initial auth/catalog steps
@ -62,7 +63,7 @@ class TestShade(base.TestCase):
# keystoneauth1.loading.base.BaseLoader.load_from_options
self.cloud.connect_as(project_name='test_project')
@mock.patch.object(openstack.cloud.OpenStackCloud, 'search_images')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'search_images')
def test_get_images(self, mock_search):
image1 = dict(id='123', name='mickey')
mock_search.return_value = [image1]
@ -70,7 +71,7 @@ class TestShade(base.TestCase):
self.assertIsNotNone(r)
self.assertDictEqual(image1, r)
@mock.patch.object(openstack.cloud.OpenStackCloud, 'search_images')
@mock.patch.object(openstackcloud._OpenStackCloudMixin, 'search_images')
def test_get_image_not_found(self, mock_search):
mock_search.return_value = []
r = self.cloud.get_image('doesNotExist')