Merge remote-tracking branch 'origin/master' into merge-r1

Change-Id: Ie19db186859a5a3d2cbefae5dcf4cf8199cd0169
This commit is contained in:
Artem Goncharov 2021-05-21 17:34:36 +02:00
commit c7c0c26a39
56 changed files with 2167 additions and 1360 deletions

View File

@ -262,6 +262,31 @@ establish new connection.
auth: true
MFA Support
-----------
MFA support requires a specially prepared configuration file. In this case a
combination of 2 different authorization plugins is used with their individual
requirements to the specified parameteres.
.. code-block:: yaml
clouds:
mfa:
auth_type: "v3multifactor"
auth_methods:
- v3password
- v3totp
auth:
auth_url: https://identity.cloud.com
username: user
user_id: uid
password: XXXXXXXXX
project_name: project
user_domain_name: udn
project_domain_name: pdn
IPv6
----

View File

@ -234,6 +234,15 @@ VPN Operations
:members: create_vpn_service, update_vpn_service, delete_vpn_service,
get_vpn_service, find_vpn_service, vpn_services
IPSecSiteConnection Operations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: openstack.network.v2._proxy.Proxy
:noindex:
:members: create_vpn_ipsec_site_connection, update_vpn_ipsec_site_connection,
delete_vpn_ipsec_site_connection, get_vpn_ipsec_site_connection,
find_vpn_ipsec_site_connection, vpn_ipsec_site_connections
Extension Operations
^^^^^^^^^^^^^^^^^^^^

View File

@ -10,6 +10,14 @@ The placement high-level interface is available through the ``placement``
member of a :class:`~openstack.connection.Connection` object.
The ``placement`` member will only be added if the service is detected.
Resource Classes
^^^^^^^^^^^^^^^^
.. autoclass:: openstack.placement.v1._proxy.Proxy
:noindex:
:members: create_resource_class, update_resource_class,
delete_resource_class, get_resource_class,
resource_classes
Resource Providers
^^^^^^^^^^^^^^^^^^
@ -18,4 +26,4 @@ Resource Providers
:noindex:
:members: create_resource_provider, update_resource_provider,
delete_resource_provider, get_resource_provider,
resource_providers
find_resource_provider, resource_providers

View File

@ -13,6 +13,7 @@ Network Resources
v2/flavor
v2/floating_ip
v2/health_monitor
v2/ipsec_site_connection
v2/listener
v2/load_balancer
v2/metering_label

View File

@ -0,0 +1,13 @@
openstack.network.v2.ipsec_site_connection
==========================================
.. automodule:: openstack.network.v2.ipsec_site_connection
The IPSecSiteConnection Class
-----------------------------
The ``IPSecSiteConnection`` class inherits from
:class:`~openstack.resource.Resource`.
.. autoclass:: openstack.network.v2.ipsec_site_connection.IPSecSiteConnection
:members:

View File

@ -4,4 +4,5 @@ Placement v1 Resources
.. toctree::
:maxdepth: 1
v1/resource_class
v1/resource_provider

View File

@ -0,0 +1,13 @@
openstack.placement.v1.resource_class
=====================================
.. automodule:: openstack.placement.v1.resource_class
The ResourceClass Class
-----------------------
The ``ResourceClass`` class inherits from
:class:`~openstack.resource.Resource`.
.. autoclass:: openstack.placement.v1.resource_class.ResourceClass
:members:

View File

@ -168,19 +168,20 @@ class Proxy(proxy.Proxy):
return self._delete(_chassis.Chassis, chassis,
ignore_missing=ignore_missing)
def drivers(self, details=False):
def drivers(self, details=False, **query):
"""Retrieve a generator of drivers.
:param bool details: A boolean indicating whether the detailed
information for every driver should be returned.
:param kwargs query: Optional query parameters to be sent to limit
the resources being returned.
:returns: A generator of driver instances.
"""
kwargs = {}
# NOTE(dtantsur): details are available starting with API microversion
# 1.30. Thus we do not send any value if not needed.
if details:
kwargs['details'] = True
return self._list(_driver.Driver, **kwargs)
query['details'] = True
return self._list(_driver.Driver, **query)
def get_driver(self, driver):
"""Get a specific driver.

View File

@ -201,12 +201,15 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
volume = self._get_resource(_volume.Volume, volume)
volume.extend(self, size)
def backend_pools(self):
def backend_pools(self, **query):
"""Returns a generator of cinder Back-end storage pools
:param kwargs query: Optional query parameters to be sent to limit
the resources being returned.
:returns A generator of cinder Back-end storage pools objects
"""
return self._list(_stats.Pools)
return self._list(_stats.Pools, **query)
def backups(self, details=True, **query):
"""Retrieve a generator of backups

View File

@ -14,6 +14,7 @@ from openstack.block_storage import _base_proxy
from openstack.block_storage.v3 import availability_zone
from openstack.block_storage.v3 import backup as _backup
from openstack.block_storage.v3 import capabilities as _capabilities
from openstack.block_storage.v3 import extension as _extension
from openstack.block_storage.v3 import group_type as _group_type
from openstack.block_storage.v3 import limits as _limits
from openstack.block_storage.v3 import resource_filter as _resource_filter
@ -416,12 +417,15 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
volume = self._get_resource(_volume.Volume, volume)
volume.retype(self, new_type, migration_policy)
def backend_pools(self):
def backend_pools(self, **query):
"""Returns a generator of cinder Back-end storage pools
:param kwargs query: Optional query parameters to be sent to limit
the resources being returned.
:returns A generator of cinder Back-end storage pools objects
"""
return self._list(_stats.Pools)
return self._list(_stats.Pools, **query)
def backups(self, details=True, **query):
"""Retrieve a generator of backups
@ -693,6 +697,15 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
"""
return self._list(_resource_filter.ResourceFilter, **query)
def extensions(self):
"""Return a generator of extensions
:returns: A generator of extension
:rtype: :class:`~openstack.block_storage.v3.extension.\
Extension`
"""
return self._list(_extension.Extension)
def _get_cleanup_dependencies(self):
return {
'block_storage': {

View File

@ -0,0 +1,31 @@
# 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.
from openstack import resource
class Extension(resource.Resource):
"""Extension"""
resources_key = "extensions"
base_path = "/extensions"
# Capabilities
allow_list = True
#: Properties
#: The alias for the extension.
alias = resource.Body('alias', type=str)
#: The extension description.
description = resource.Body('description', type=str)
#: The date and time when the resource was updated.
#: The date and time stamp format is ISO 8601.
updated = resource.Body('updated', type=str)

View File

@ -119,5 +119,15 @@ class Volume(resource.Resource):
body = {'os-update_readonly_flag': {'readonly': readonly}}
self._action(session, body)
def retype(self, session, new_type, migration_policy):
"""Retype volume considering the migration policy"""
body = {
'os-retype': {
'new_type': new_type,
'migration_policy': migration_policy
}
}
self._action(session, body)
VolumeDetail = Volume

View File

@ -420,12 +420,14 @@ class Proxy(proxy.Proxy):
obj = self._find(_cluster.Cluster, cluster, ignore_missing=False)
return obj.policy_update(self, policy, **params)
def collect_cluster_attrs(self, cluster, path):
def collect_cluster_attrs(self, cluster, path, **query):
"""Collect attribute values across a cluster.
:param cluster: The value can be either the ID of a cluster or a
:class:`~openstack.clustering.v1.cluster.Cluster` instance.
:param path: A Json path string specifying the attribute to collect.
:param query: Optional query parameters to be sent to limit the
resources being returned.
:returns: A dictionary containing the list of attribute values.
"""

View File

@ -708,7 +708,7 @@ class Proxy(proxy.Proxy):
:returns: encrypted password.
"""
server = self._get_resource(_server.Server, server)
return server.get_password(self._session)
return server.get_password(self)
def reset_server_state(self, server, state):
"""Reset the state of server
@ -1144,6 +1144,8 @@ class Proxy(proxy.Proxy):
return self._create(_server_interface.ServerInterface,
server_id=server_id, **attrs)
# TODO(stephenfin): Does this work? There's no 'value' parameter for the
# call to '_delete'
def delete_server_interface(self, server_interface, server=None,
ignore_missing=True):
"""Delete a server interface
@ -1169,7 +1171,7 @@ class Proxy(proxy.Proxy):
server_interface = resource.Resource._get_id(server_interface)
self._delete(_server_interface.ServerInterface,
port_id=server_interface,
server_interface,
server_id=server_id,
ignore_missing=ignore_missing)
@ -1197,18 +1199,20 @@ class Proxy(proxy.Proxy):
return self._get(_server_interface.ServerInterface,
server_id=server_id, port_id=server_interface)
def server_interfaces(self, server):
def server_interfaces(self, server, **query):
"""Return a generator of server interfaces
:param server: The server can be either the ID of a server or a
:class:`~openstack.compute.v2.server.Server`.
:class:`~openstack.compute.v2.server.Server`.
:param query: Optional query parameters to be sent to limit the
resources being returned.
:returns: A generator of ServerInterface objects
:rtype: :class:`~openstack.compute.v2.server_interface.ServerInterface`
"""
server_id = resource.Resource._get_id(server)
return self._list(_server_interface.ServerInterface,
server_id=server_id)
server_id=server_id, **query)
def server_ips(self, server, network_label=None):
"""Return a generator of server IPs

View File

@ -256,7 +256,12 @@ class Server(resource.Resource, metadata.MetadataMixin, resource.TagMixin):
def get_password(self, session):
"""Get the encrypted administrator password."""
url = utils.urljoin(Server.base_path, self.id, 'os-server-password')
return session.get(url)
response = session.get(url)
exceptions.raise_from_response(response)
data = response.json()
return data.get('password')
def reboot(self, session, reboot_type):
"""Reboot server where reboot_type might be 'SOFT' or 'HARD'."""

View File

@ -39,5 +39,7 @@ class VolumeAttachment(resource.Resource):
attachment_id = resource.Body('attachment_id', alternate_id=True)
#: Virtual device tags for the attachment.
tag = resource.Body('tag')
# tag introduced in 2.70
_max_microversion = '2.70'
#: Indicates whether to delete the volume when server is destroyed
delete_on_termination = resource.Body('delete_on_termination')
# delete_on_termination introduced in 2.79
_max_microversion = '2.79'

View File

@ -1042,6 +1042,12 @@ class OpenStackConfig:
or ('token' in config and config['token'])):
config.setdefault('token', config.pop('auth_token', None))
# Infer passcode if it was given separately
# This is generally absolutely impractical to require setting passcode
# in the clouds.yaml
if 'auth' in config and 'passcode' in config:
config['auth']['passcode'] = config.pop('passcode', None)
# These backwards compat values are only set via argparse. If it's
# there, it's because it was passed in explicitly, and should win
config = self._fix_backwards_api_timeout(config)

View File

@ -55,6 +55,9 @@ class Project(resource.Resource, resource.TagMixin):
is_enabled = resource.Body('enabled', type=bool)
#: Unique project name, within the owning domain. *Type: string*
name = resource.Body('name')
#: The resource options for the project. Available resource options are
#: immutable.
options = resource.Body('options', type=dict)
#: The ID of the parent of the project.
#: New in version 3.4
parent_id = resource.Body('parent_id')

View File

@ -251,7 +251,7 @@ class BaseImageProxy(proxy.Proxy, metaclass=abc.ABCMeta):
converted to int.
"""
if image is None:
if isinstance(image, str):
image = self._connection.get_image(image)
if not meta:

View File

@ -579,16 +579,18 @@ class Proxy(_base_proxy.BaseImageProxy):
image_id = resource.Resource._get_id(image)
return self._create(_member.Member, image_id=image_id, **attrs)
def remove_member(self, member, image, ignore_missing=True):
def remove_member(self, member, image=None, ignore_missing=True):
"""Delete a member
:param member: The value can be either the ID of a member or a
:class:`~openstack.image.v2.member.Member` instance.
:class:`~openstack.image.v2.member.Member` instance.
:param image: The value can be either the ID of an image or a
:class:`~openstack.image.v2.image.Image` instance that the member
is part of. This is required if ``member`` is an ID.
:param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.ResourceNotFound` will be
raised when the member does not exist.
When set to ``True``, no exception will be set when
attempting to delete a nonexistent member.
:class:`~openstack.exceptions.ResourceNotFound` will be raised when
the member does not exist. When set to ``True``, no exception will
be set when attempting to delete a nonexistent member.
:returns: ``None``
"""
@ -632,12 +634,14 @@ class Proxy(_base_proxy.BaseImageProxy):
return self._get(_member.Member, member_id=member_id,
image_id=image_id)
def members(self, image):
def members(self, image, **query):
"""Return a generator of members
:param image: This is the image that the member belongs to,
the value can be the ID of a image or a
:class:`~openstack.image.v2.image.Image` instance.
the value can be the ID of a image or a
:class:`~openstack.image.v2.image.Image` instance.
:param kwargs query: Optional query parameters to be sent to limit
the resources being returned.
:returns: A generator of member objects
:rtype: :class:`~openstack.image.v2.member.Member`

View File

@ -78,8 +78,6 @@ class Image(resource.Resource, resource.TagMixin, _download.DownloadMixin):
#: The algorithm used to compute a secure hash of the image data
#: for this image
hash_algo = resource.Body('os_hash_algo')
#: List of tags for this image.
tags = resource.Body('tags')
#: The hexdigest of the secure hash of the image data computed using
#: the algorithm whose name is the value of the os_hash_algo property.
hash_value = resource.Body('os_hash_value')

View File

@ -24,6 +24,8 @@ from openstack.network.v2 import firewall_rule as _firewall_rule
from openstack.network.v2 import flavor as _flavor
from openstack.network.v2 import floating_ip as _floating_ip
from openstack.network.v2 import health_monitor as _health_monitor
from openstack.network.v2 import ipsec_site_connection as \
_ipsec_site_connection
from openstack.network.v2 import l3_conntrack_helper as _l3_conntrack_helper
from openstack.network.v2 import listener as _listener
from openstack.network.v2 import load_balancer as _load_balancer
@ -951,6 +953,100 @@ class Proxy(proxy.Proxy):
return self._update(_health_monitor.HealthMonitor, health_monitor,
**attrs)
def create_vpn_ipsec_site_connection(self, **attrs):
"""Create a new ipsec site connection from attributes
:param dict attrs: Keyword arguments which will be used to create a
:class:`~openstack.network.v2.ipsec_site_connection.
IPSecSiteConnection`, comprised of the properties on the
IPSecSiteConnection class.
:returns: The results of ipsec site connection creation :rtype:
:class:`~openstack.network.v2.ipsec_site_connection.
IPSecSiteConnection`
"""
return self._create(_ipsec_site_connection.IPSecSiteConnection,
**attrs)
def find_vpn_ipsec_site_connection(self, name_or_id,
ignore_missing=True, **args):
"""Find a single ipsec site connection
:param name_or_id: The name or ID of an ipsec site connection.
:param bool ignore_missing: When set to ``False`` :class:`~openstack.
exceptions.ResourceNotFound` will be raised when the resource does
not exist.When set to ``True``, None will be returned when
attempting to find a nonexistent resource.
:param dict args: Any additional parameters to be passed into
underlying methods such as query filters.
:returns: One :class:`~openstack.network.v2.ipsec_site_connection.
IPSecSiteConnection` or None
"""
return self._find(_ipsec_site_connection.IPSecSiteConnection,
name_or_id, ignore_missing=ignore_missing, **args)
def get_vpn_ipsec_site_connection(self, ipsec_site_connection):
"""Get a single ipsec site connection
:param ipsec_site_connection: The value can be the ID of an ipsec site
connection or a :class:`~openstack.network.v2.
ipsec_site_connection.IPSecSiteConnection` instance.
:returns: One :class:`~openstack.network.v2.ipsec_site_connection.
IPSecSiteConnection`
:raises: :class:`~openstack.exceptions.ResourceNotFound`
when no resource can be found.
"""
return self._get(_ipsec_site_connection.IPSecSiteConnection,
ipsec_site_connection)
def vpn_ipsec_site_connections(self, **query):
"""Return a generator of ipsec site connections
:param dict query: Optional query parameters to be sent to limit the
resources being returned.
:returns: A generator of ipsec site connection objects
:rtype: :class:`~openstack.network.v2.ipsec_site_connection.
IPSecSiteConnection`
"""
return self._list(_ipsec_site_connection.IPSecSiteConnection, **query)
def update_vpn_ipsec_site_connection(self, ipsec_site_connection, **attrs):
"""Update a ipsec site connection
:ipsec_site_connection: Either the id of an ipsec site connection or
a :class:`~openstack.network.v2.ipsec_site_connection.
IPSecSiteConnection` instance.
:param dict attrs: The attributes to update on the ipsec site
connection represented by ``ipsec_site_connection``.
:returns: The updated ipsec site connection
:rtype: :class:`~openstack.network.v2.ipsec_site_connection.
IPSecSiteConnection`
"""
return self._update(_ipsec_site_connection.IPSecSiteConnection,
ipsec_site_connection, **attrs)
def delete_vpn_ipsec_site_connection(self, ipsec_site_connection,
ignore_missing=True):
"""Delete a ipsec site connection
:param ipsec_site_connection: The value can be either the ID of an
ipsec site connection, or a :class:`~openstack.network.v2.
ipsec_site_connection.IPSecSiteConnection` instance.
:param bool ignore_missing:
When set to ``False`` :class:`~openstack.exceptions.
ResourceNotFound` will be raised when the ipsec site connection
does not exist.
When set to ``True``, no exception will be set when attempting to
delete a nonexistent ipsec site connection.
:returns: ``None``
"""
self._delete(_ipsec_site_connection.IPSecSiteConnection,
ipsec_site_connection, ignore_missing=ignore_missing)
def create_listener(self, **attrs):
"""Create a new listener from attributes

View File

@ -0,0 +1,105 @@
# 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.
from openstack import resource
class IPSecSiteConnection(resource.Resource):
resource_key = 'ipsec_site_connection'
resources_key = 'ipsec_site_connections'
base_path = '/vpn/ipsec-site-connections'
# capabilities
allow_create = True
allow_fetch = True
allow_commit = True
allow_delete = True
allow_list = True
# Properties
#: The dead peer detection (DPD) action.
# A valid value is clear, hold, restart,
# disabled, or restart-by-peer. Default value is hold.
action = resource.Body('action')
#: The authentication mode. A valid value
# is psk, which is the default.
auth_mode = resource.Body('auth_mode')
#: A human-readable description for the resource.
# Default is an empty string.
description = resource.Body('description')
#: A dictionary with dead peer detection (DPD) protocol controls.
dpd = resource.Body('dpd', type=dict)
#: The administrative state of the resource,
# which is up (true) or down (false).
is_admin_state_up = resource.Body('admin_state_up', type=bool)
#: The ID of the IKE policy.
ikepolicy_id = resource.Body('ikepolicy_id')
#: Indicates whether this VPN can only respond
# to connections or both respond
# to and initiate connections. A valid value is
# response- only or bi-directional. Default is bi-directional.
initiator = resource.Body('initiator')
#: The ID of the IPsec policy.
ipsecpolicy_id = resource.Body('ipsecpolicy_id')
#: The dead peer detection (DPD) interval, in seconds.
# A valid value is a positive integer. Default is 30.
interval = resource.Body('interval', type=int)
#: The ID for the endpoint group that contains
# private subnets for the local side of the connection.
# Yo must specify this parameter with the
# peer_ep_group_id parameter unless in backward- compatible
# mode where peer_cidrs is provided with
# a subnet_id for the VPN service.
local_ep_group_id = resource.Body('local_ep_group_id')
#: The peer gateway public IPv4 or IPv6 address or FQDN.
peer_address = resource.Body('peer_address')
#: An ID to be used instead of the external IP address for
# a virtual router used in traffic between
# instances on different networks in east-west traffic.
# Most often, local ID would be domain
# name, email address, etc. If this is not configured
# then the external IP address will be used as the ID.
local_id = resource.Body('local_id')
#: The maximum transmission unit (MTU)
# value to address fragmentation. Minimum value
# is 68 for IPv4, and 1280 for IPv6.
mtu = resource.Body('mtu', type=int)
#: Human-readable name of the resource. Default is an empty string.
name = resource.Body('name')
#: The peer router identity for authentication.
# A valid value is an IPv4 address, IPv6 address, e-mail address,
# key ID, or FQDN. Typically, this value matches
# the peer_address value.
peer_id = resource.Body('peer_id')
#: (Deprecated) Unique list of valid peer private
# CIDRs in the form < net_address > / < prefix > .
peer_cidrs = resource.Body('peer_cidrs', type=list)
#: The ID of the project.
project_id = resource.Body('tenant_id')
#: The pre-shared key. A valid value is any string.
psk = resource.Body('psk')
#: The ID for the endpoint group that contains
# private CIDRs in the form < net_address > / < prefix >
# for the peer side of the connection. You must
# specify this parameter with the local_ep_group_id
# parameter unless in backward-compatible mode
# where peer_cidrs is provided with a subnet_id for the VPN service.
peer_ep_group_id = resource.Body('peer_ep_group_id')
#: The route mode. A valid value is static, which is the default.
route_mode = resource.Body('route_mode')
#: The dead peer detection (DPD) timeout
# in seconds. A valid value is a
# positive integer that is greater
# than the DPD interval value. Default is 120.
timeout = resource.Body('timeout', type=int)
#: The ID of the VPN service.
vpnservice_id = resource.Body('vpnservice_id')

View File

@ -10,12 +10,94 @@
# License for the specific language governing permissions and limitations
# under the License.
from openstack.placement.v1 import resource_class as _resource_class
from openstack.placement.v1 import resource_provider as _resource_provider
from openstack import proxy
class Proxy(proxy.Proxy):
# resource classes
def create_resource_class(self, **attrs):
"""Create a new resource class from attributes.
:param attrs: Keyword arguments which will be used to create a
:class:`~openstack.placement.v1.resource_provider.ResourceClass`,
comprised of the properties on the ResourceClass class.
:returns: The results of resource class creation
:rtype: :class:`~openstack.placement.v1.resource_class.ResourceClass`
"""
return self._create(_resource_class.ResourceClass, **attrs)
def delete_resource_class(self, resource_class, ignore_missing=True):
"""Delete a resource class
:param resource_class: The value can be either the ID of a resource
class or an
:class:`~openstack.placement.v1.resource_class.ResourceClass`,
instance.
:param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.ResourceNotFound` will be raised when
the resource class does not exist. When set to ``True``, no
exception will be set when attempting to delete a nonexistent
resource class.
:returns: ``None``
"""
self._delete(
_resource_class.ResourceClass,
resource_class,
ignore_missing=ignore_missing,
)
def update_resource_class(self, resource_class, **attrs):
"""Update a resource class
:param resource_class: The value can be either the ID of a resource
class or an
:class:`~openstack.placement.v1.resource_class.ResourceClass`,
instance.
:attrs kwargs: The attributes to update on the resource class
represented by ``resource_class``.
:returns: The updated resource class
:rtype: :class:`~openstack.placement.v1.resource_class.ResourceClass`
"""
return self._update(
_resource_class.ResourceClass, resource_class, **attrs,
)
def get_resource_class(self, resource_class):
"""Get a single resource_class.
:param resource_class: The value can be either the ID of a resource
class or an
:class:`~openstack.placement.v1.resource_class.ResourceClass`,
instance.
:returns: An instance of
:class:`~openstack.placement.v1.resource_class.ResourceClass`
:raises: :class:`~openstack.exceptions.ResourceNotFound` when no
resource class matching the criteria could be found.
"""
return self._get(
_resource_class.ResourceClass, resource_class,
)
def resource_classes(self, **query):
"""Retrieve a generator of resource classs.
:param kwargs query: Optional query parameters to be sent to
restrict the resource classs to be returned.
:returns: A generator of resource class instances.
"""
return self._list(_resource_class.ResourceClass, **query)
# resource providers
def create_resource_provider(self, **attrs):
"""Create a new resource provider from attributes.
@ -50,7 +132,7 @@ class Proxy(proxy.Proxy):
)
def update_resource_provider(self, resource_provider, **attrs):
"""Update a flavor
"""Update a resource provider
:param resource_provider: The value can be either the ID of a resource
provider or an

View File

@ -0,0 +1,32 @@
# 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.
from openstack import resource
class ResourceClass(resource.Resource):
resource_key = None
resources_key = 'resource_classes'
base_path = '/resource_classes'
# Capabilities
allow_create = True
allow_fetch = True
allow_commit = True
allow_delete = True
allow_list = True
# Added in 1.2
_max_microversion = '1.2'
name = resource.Body('name', alternate_id=True)

View File

@ -310,14 +310,13 @@ class Proxy(adapter.Adapter):
"""Get a resource object to work on
:param resource_type: The type of resource to operate on. This should
be a subclass of
:class:`~openstack.resource.Resource` with a
``from_id`` method.
be a subclass of :class:`~openstack.resource.Resource` with a
``from_id`` method.
:param value: The ID of a resource or an object of ``resource_type``
class if using an existing instance, or ``munch.Munch``,
or None to create a new instance.
:param path_args: A dict containing arguments for forming the request
URL, if needed.
class if using an existing instance, or ``munch.Munch``,
or None to create a new instance.
:param attrs: A dict containing arguments for forming the request
URL, if needed.
"""
conn = self._get_connection()
if value is None:
@ -374,6 +373,7 @@ class Proxy(adapter.Adapter):
ignore_missing=ignore_missing,
**attrs)
# TODO(stephenfin): Update docstring for attrs since it's a lie
@_check_resource(strict=False)
def _delete(self, resource_type, value, ignore_missing=True, **attrs):
"""Delete a resource
@ -512,16 +512,13 @@ class Proxy(adapter.Adapter):
error_message="No {resource_type} found for {value}".format(
resource_type=resource_type.__name__, value=value))
def _list(self, resource_type, value=None,
def _list(self, resource_type,
paginated=True, base_path=None, **attrs):
"""List a resource
:param resource_type: The type of resource to list. This should
be a :class:`~openstack.resource.Resource`
subclass with a ``from_id`` method.
:param value: The resource to list. It can be the ID of a resource, or
a :class:`~openstack.resource.Resource` object. When set
to None, a new bare resource is created.
:param bool paginated: When set to ``False``, expect all of the data
to be returned in one response. When set to
``True``, the resource supports data being

View File

@ -0,0 +1,24 @@
# 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.
from openstack.tests.functional.block_storage.v3 import base
class Extensions(base.BaseBlockStorageTest):
def test_get(self):
extensions = list(self.conn.block_storage.extensions())
for extension in extensions:
self.assertIsInstance(extension.alias, str)
self.assertIsInstance(extension.description, str)
self.assertIsInstance(extension.updated, str)

View File

@ -28,7 +28,7 @@ class TestImage(base.BaseFunctionalTest):
self.conn = connection.from_config(
cloud_name=base.TEST_CLOUD_NAME, options=opts)
self.img = self.conn.image.upload_image(
self.img = self.conn.image.create_image(
name=TEST_IMAGE_NAME,
disk_format='raw',
container_format='bare',
@ -37,7 +37,9 @@ class TestImage(base.BaseFunctionalTest):
# we need to just replace the image upload code with the stuff
# from shade. Figuring out mapping the crap-tastic arbitrary
# extra key-value pairs into Resource is going to be fun.
properties='{"description": "This is not an image"}',
properties=dict(
description="This is not an image"
),
data=open('CONTRIBUTING.rst', 'r')
)
self.addCleanup(self.conn.image.delete_image, self.img)
@ -65,3 +67,18 @@ class TestImage(base.BaseFunctionalTest):
def test_list_tasks(self):
tasks = self.conn.image.tasks()
self.assertIsNotNone(tasks)
def test_tags(self):
img = self.conn.image.get_image(self.img)
self.conn.image.add_tag(img, 't1')
self.conn.image.add_tag(img, 't2')
# Ensure list with array of tags return us our image
list_img = list(self.conn.image.images(tag=['t1', 't2']))[0]
self.assertEqual(img.id, list_img.id)
self.assertIn('t1', list_img.tags)
self.assertIn('t2', list_img.tags)
self.conn.image.remove_tag(img, 't1')
# Refetch img to verify tags
img = self.conn.image.get_image(self.img)
self.assertIn('t2', img.tags)
self.assertNotIn('t1', img.tags)

View File

@ -88,10 +88,11 @@ class TestVolumeProxy(test_proxy_base.TestProxyBase):
self.verify_delete(self.proxy.delete_volume, volume.Volume, True)
def test_volume_extend(self):
self._verify("openstack.block_storage.v2.volume.Volume.extend",
self.proxy.extend_volume,
method_args=["value", "new-size"],
expected_args=["new-size"])
self._verify(
"openstack.block_storage.v2.volume.Volume.extend",
self.proxy.extend_volume,
method_args=["value", "new-size"],
expected_args=[self.proxy, "new-size"])
def test_backend_pools(self):
self.verify_list(self.proxy.backend_pools, stats.Pools)
@ -141,7 +142,7 @@ class TestVolumeProxy(test_proxy_base.TestProxyBase):
# NOTE: mock has_service
self.proxy._connection = mock.Mock()
self.proxy._connection.has_service = mock.Mock(return_value=True)
self._verify2(
self._verify(
'openstack.block_storage.v2.backup.Backup.restore',
self.proxy.restore_backup,
method_args=['volume_id'],

View File

@ -0,0 +1,41 @@
# 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.
from openstack.block_storage.v3 import extension
from openstack.tests.unit import base
EXTENSION = {
"alias": "os-hosts",
"description": "Admin-only host administration.",
"links": [],
"name": "Hosts",
"updated": "2011-06-29T00:00:00+00:00",
}
class TestExtension(base.TestCase):
def test_basic(self):
extension_resource = extension.Extension()
self.assertEqual('extensions', extension_resource.resources_key)
self.assertEqual('/extensions', extension_resource.base_path)
self.assertFalse(extension_resource.allow_create)
self.assertFalse(extension_resource.allow_fetch)
self.assertFalse(extension_resource.allow_commit)
self.assertFalse(extension_resource.allow_delete)
self.assertTrue(extension_resource.allow_list)
def test_make_extension(self):
extension_resource = extension.Extension(**EXTENSION)
self.assertEqual(EXTENSION['alias'], extension_resource.alias)
self.assertEqual(EXTENSION['description'],
extension_resource.description)
self.assertEqual(EXTENSION['updated'], extension_resource.updated)

View File

@ -14,6 +14,7 @@ from unittest import mock
from openstack.block_storage.v3 import _proxy
from openstack.block_storage.v3 import backup
from openstack.block_storage.v3 import capabilities
from openstack.block_storage.v3 import extension
from openstack.block_storage.v3 import group_type
from openstack.block_storage.v3 import limits
from openstack.block_storage.v3 import resource_filter
@ -81,7 +82,7 @@ class TestVolumeProxy(test_proxy_base.TestProxyBase):
def test_type_extra_specs_update(self):
kwargs = {"a": "1", "b": "2"}
id = "an_id"
self._verify2(
self._verify(
"openstack.block_storage.v3.type.Type.set_extra_specs",
self.proxy.update_type_extra_specs,
method_args=[id],
@ -93,7 +94,7 @@ class TestVolumeProxy(test_proxy_base.TestProxyBase):
expected_result=kwargs)
def test_type_extra_specs_delete(self):
self._verify2(
self._verify(
"openstack.block_storage.v3.type.Type.delete_extra_specs",
self.proxy.delete_type_extra_specs,
expected_result=None,
@ -103,9 +104,9 @@ class TestVolumeProxy(test_proxy_base.TestProxyBase):
def test_type_encryption_get(self):
self.verify_get(self.proxy.get_type_encryption,
type.TypeEncryption,
expected_args=[type.TypeEncryption],
expected_args=[],
expected_kwargs={
'volume_type_id': 'value',
'volume_type_id': 'resource_id',
'requires_id': False
})
@ -155,22 +156,37 @@ class TestVolumeProxy(test_proxy_base.TestProxyBase):
self.verify_delete(self.proxy.delete_volume, volume.Volume, True)
def test_volume_extend(self):
self._verify("openstack.block_storage.v3.volume.Volume.extend",
self.proxy.extend_volume,
method_args=["value", "new-size"],
expected_args=["new-size"])
self._verify(
"openstack.block_storage.v3.volume.Volume.extend",
self.proxy.extend_volume,
method_args=["value", "new-size"],
expected_args=[self.proxy, "new-size"])
def test_volume_set_readonly_no_argument(self):
self._verify("openstack.block_storage.v3.volume.Volume.set_readonly",
self.proxy.set_volume_readonly,
method_args=["value"],
expected_args=[True])
self._verify(
"openstack.block_storage.v3.volume.Volume.set_readonly",
self.proxy.set_volume_readonly,
method_args=["value"],
expected_args=[self.proxy, True])
def test_volume_set_readonly_false(self):
self._verify("openstack.block_storage.v3.volume.Volume.set_readonly",
self.proxy.set_volume_readonly,
method_args=["value", False],
expected_args=[False])
self._verify(
"openstack.block_storage.v3.volume.Volume.set_readonly",
self.proxy.set_volume_readonly,
method_args=["value", False],
expected_args=[self.proxy, False])
def test_volume_retype_without_migration_policy(self):
self._verify("openstack.block_storage.v3.volume.Volume.retype",
self.proxy.retype_volume,
method_args=["value", "rbd"],
expected_args=[self.proxy, "rbd", "never"])
def test_volume_retype_with_migration_policy(self):
self._verify("openstack.block_storage.v3.volume.Volume.retype",
self.proxy.retype_volume,
method_args=["value", "rbd", "on-demand"],
expected_args=[self.proxy, "rbd", "on-demand"])
def test_backend_pools(self):
self.verify_list(self.proxy.backend_pools, stats.Pools)
@ -226,7 +242,7 @@ class TestVolumeProxy(test_proxy_base.TestProxyBase):
# NOTE: mock has_service
self.proxy._connection = mock.Mock()
self.proxy._connection.has_service = mock.Mock(return_value=True)
self._verify2(
self._verify(
'openstack.block_storage.v3.backup.Backup.restore',
self.proxy.restore_backup,
method_args=['volume_id'],
@ -237,7 +253,8 @@ class TestVolumeProxy(test_proxy_base.TestProxyBase):
def test_limits_get(self):
self.verify_get(
self.proxy.get_limits, limits.Limit, ignore_value=True,
self.proxy.get_limits, limits.Limit,
method_args=[],
expected_kwargs={'requires_id': False})
def test_capabilites_get(self):
@ -269,3 +286,6 @@ class TestVolumeProxy(test_proxy_base.TestProxyBase):
def test_group_type_update(self):
self.verify_update(self.proxy.update_group_type, group_type.GroupType)
def test_extensions(self):
self.verify_list(self.proxy.extensions, extension.Extension)

View File

@ -147,3 +147,18 @@ class TestVolume(base.TestCase):
body = {'os-update_readonly_flag': {'readonly': False}}
headers = {'Accept': ''}
self.sess.post.assert_called_with(url, json=body, headers=headers)
def test_retype(self):
sot = volume.Volume(**VOLUME)
self.assertIsNone(sot.retype(self.sess, 'rbd', 'on-demand'))
url = 'volumes/%s/action' % FAKE_ID
body = {
'os-retype': {
'new_type': 'rbd',
'migration_policy': 'on-demand'
}
}
headers = {'Accept': ''}
self.sess.post.assert_called_with(url, json=body, headers=headers)

View File

@ -37,7 +37,7 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
def test_build_info_get(self):
self.verify_get(self.proxy.get_build_info, build_info.BuildInfo,
ignore_value=True,
method_args=[],
expected_kwargs={'requires_id': False})
def test_profile_types(self):
@ -91,9 +91,11 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
self.verify_delete(self.proxy.delete_cluster, cluster.Cluster, True)
def test_cluster_force_delete(self):
self._verify("openstack.clustering.v1.cluster.Cluster.force_delete",
self.proxy.delete_cluster,
method_args=["value", False, True])
self._verify(
"openstack.clustering.v1.cluster.Cluster.force_delete",
self.proxy.delete_cluster,
method_args=["value", False, True],
expected_args=[self.proxy])
def test_cluster_find(self):
self.verify_find(self.proxy.find_cluster, cluster.Cluster)
@ -117,26 +119,31 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
def test_resize_cluster(self, mock_find):
mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER')
mock_find.return_value = mock_cluster
self._verify("openstack.clustering.v1.cluster.Cluster.resize",
self.proxy.resize_cluster,
method_args=["FAKE_CLUSTER"],
method_kwargs={'k1': 'v1', 'k2': 'v2'},
expected_kwargs={'k1': 'v1', 'k2': 'v2'})
self._verify(
"openstack.clustering.v1.cluster.Cluster.resize",
self.proxy.resize_cluster,
method_args=["FAKE_CLUSTER"],
method_kwargs={'k1': 'v1', 'k2': 'v2'},
expected_args=[self.proxy],
expected_kwargs={'k1': 'v1', 'k2': 'v2'})
mock_find.assert_called_once_with(cluster.Cluster, "FAKE_CLUSTER",
ignore_missing=False)
def test_resize_cluster_with_obj(self):
mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER')
self._verify("openstack.clustering.v1.cluster.Cluster.resize",
self.proxy.resize_cluster,
method_args=[mock_cluster],
method_kwargs={'k1': 'v1', 'k2': 'v2'},
expected_kwargs={'k1': 'v1', 'k2': 'v2'})
self._verify(
"openstack.clustering.v1.cluster.Cluster.resize",
self.proxy.resize_cluster,
method_args=[mock_cluster],
method_kwargs={'k1': 'v1', 'k2': 'v2'},
expected_args=[self.proxy],
expected_kwargs={'k1': 'v1', 'k2': 'v2'})
def test_collect_cluster_attrs(self):
self.verify_list(self.proxy.collect_cluster_attrs,
cluster_attr.ClusterAttr,
method_args=['FAKE_ID', 'path.to.attr'],
expected_args=[],
expected_kwargs={'cluster_id': 'FAKE_ID',
'path': 'path.to.attr'})
@ -144,18 +151,22 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
def test_cluster_check(self, mock_get):
mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER')
mock_get.return_value = mock_cluster
self._verify("openstack.clustering.v1.cluster.Cluster.check",
self.proxy.check_cluster,
method_args=["FAKE_CLUSTER"])
self._verify(
"openstack.clustering.v1.cluster.Cluster.check",
self.proxy.check_cluster,
method_args=["FAKE_CLUSTER"],
expected_args=[self.proxy])
mock_get.assert_called_once_with(cluster.Cluster, "FAKE_CLUSTER")
@mock.patch.object(proxy_base.Proxy, '_get_resource')
def test_cluster_recover(self, mock_get):
mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER')
mock_get.return_value = mock_cluster
self._verify("openstack.clustering.v1.cluster.Cluster.recover",
self.proxy.recover_cluster,
method_args=["FAKE_CLUSTER"])
self._verify(
"openstack.clustering.v1.cluster.Cluster.recover",
self.proxy.recover_cluster,
method_args=["FAKE_CLUSTER"],
expected_args=[self.proxy])
mock_get.assert_called_once_with(cluster.Cluster, "FAKE_CLUSTER")
def test_node_create(self):
@ -168,9 +179,11 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
self.verify_delete(self.proxy.delete_node, node.Node, True)
def test_node_force_delete(self):
self._verify("openstack.clustering.v1.node.Node.force_delete",
self.proxy.delete_node,
method_args=["value", False, True])
self._verify(
"openstack.clustering.v1.node.Node.force_delete",
self.proxy.delete_node,
method_args=["value", False, True],
expected_args=[self.proxy])
def test_node_find(self):
self.verify_find(self.proxy.find_node, node.Node)
@ -179,13 +192,13 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
self.verify_get(self.proxy.get_node, node.Node)
def test_node_get_with_details(self):
self._verify2('openstack.proxy.Proxy._get',
self.proxy.get_node,
method_args=['NODE_ID'],
method_kwargs={'details': True},
expected_args=[node.NodeDetail],
expected_kwargs={'node_id': 'NODE_ID',
'requires_id': False})
self._verify(
'openstack.proxy.Proxy._get',
self.proxy.get_node,
method_args=['NODE_ID'],
method_kwargs={'details': True},
expected_args=[node.NodeDetail],
expected_kwargs={'node_id': 'NODE_ID', 'requires_id': False})
def test_nodes(self):
self.verify_list(self.proxy.nodes, node.Node,
@ -199,28 +212,34 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
def test_node_check(self, mock_get):
mock_node = node.Node.new(id='FAKE_NODE')
mock_get.return_value = mock_node
self._verify("openstack.clustering.v1.node.Node.check",
self.proxy.check_node,
method_args=["FAKE_NODE"])
self._verify(
"openstack.clustering.v1.node.Node.check",
self.proxy.check_node,
method_args=["FAKE_NODE"],
expected_args=[self.proxy])
mock_get.assert_called_once_with(node.Node, "FAKE_NODE")
@mock.patch.object(proxy_base.Proxy, '_get_resource')
def test_node_recover(self, mock_get):
mock_node = node.Node.new(id='FAKE_NODE')
mock_get.return_value = mock_node
self._verify("openstack.clustering.v1.node.Node.recover",
self.proxy.recover_node,
method_args=["FAKE_NODE"])
self._verify(
"openstack.clustering.v1.node.Node.recover",
self.proxy.recover_node,
method_args=["FAKE_NODE"],
expected_args=[self.proxy])
mock_get.assert_called_once_with(node.Node, "FAKE_NODE")
@mock.patch.object(proxy_base.Proxy, '_get_resource')
def test_node_adopt(self, mock_get):
mock_node = node.Node.new()
mock_get.return_value = mock_node
self._verify("openstack.clustering.v1.node.Node.adopt",
self.proxy.adopt_node,
method_kwargs={"preview": False, "foo": "bar"},
expected_kwargs={"preview": False, "foo": "bar"})
self._verify(
"openstack.clustering.v1.node.Node.adopt",
self.proxy.adopt_node,
method_kwargs={"preview": False, "foo": "bar"},
expected_args=[self.proxy],
expected_kwargs={"preview": False, "foo": "bar"})
mock_get.assert_called_once_with(node.Node, None)
@ -228,10 +247,12 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
def test_node_adopt_preview(self, mock_get):
mock_node = node.Node.new()
mock_get.return_value = mock_node
self._verify("openstack.clustering.v1.node.Node.adopt",
self.proxy.adopt_node,
method_kwargs={"preview": True, "foo": "bar"},
expected_kwargs={"preview": True, "foo": "bar"})
self._verify(
"openstack.clustering.v1.node.Node.adopt",
self.proxy.adopt_node,
method_kwargs={"preview": True, "foo": "bar"},
expected_args=[self.proxy],
expected_kwargs={"preview": True, "foo": "bar"})
mock_get.assert_called_once_with(node.Node, None)
@ -265,6 +286,7 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
self.verify_list(self.proxy.cluster_policies,
cluster_policy.ClusterPolicy,
method_args=["FAKE_CLUSTER"],
expected_args=[],
expected_kwargs={"cluster_id": "FAKE_CLUSTER"})
def test_get_cluster_policy(self):
@ -272,29 +294,29 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
fake_cluster = cluster.Cluster.new(id='FAKE_CLUSTER')
# ClusterPolicy object as input
self._verify2('openstack.proxy.Proxy._get',
self.proxy.get_cluster_policy,
method_args=[fake_policy, "FAKE_CLUSTER"],
expected_args=[cluster_policy.ClusterPolicy,
fake_policy],
expected_kwargs={'cluster_id': 'FAKE_CLUSTER'},
expected_result=fake_policy)
self._verify(
'openstack.proxy.Proxy._get',
self.proxy.get_cluster_policy,
method_args=[fake_policy, "FAKE_CLUSTER"],
expected_args=[cluster_policy.ClusterPolicy, fake_policy],
expected_kwargs={'cluster_id': 'FAKE_CLUSTER'},
expected_result=fake_policy)
# Policy ID as input
self._verify2('openstack.proxy.Proxy._get',
self.proxy.get_cluster_policy,
method_args=["FAKE_POLICY", "FAKE_CLUSTER"],
expected_args=[cluster_policy.ClusterPolicy,
"FAKE_POLICY"],
expected_kwargs={"cluster_id": "FAKE_CLUSTER"})
self._verify(
'openstack.proxy.Proxy._get',
self.proxy.get_cluster_policy,
method_args=["FAKE_POLICY", "FAKE_CLUSTER"],
expected_args=[cluster_policy.ClusterPolicy, "FAKE_POLICY"],
expected_kwargs={"cluster_id": "FAKE_CLUSTER"})
# Cluster object as input
self._verify2('openstack.proxy.Proxy._get',
self.proxy.get_cluster_policy,
method_args=["FAKE_POLICY", fake_cluster],
expected_args=[cluster_policy.ClusterPolicy,
"FAKE_POLICY"],
expected_kwargs={"cluster_id": fake_cluster})
self._verify(
'openstack.proxy.Proxy._get',
self.proxy.get_cluster_policy,
method_args=["FAKE_POLICY", fake_cluster],
expected_args=[cluster_policy.ClusterPolicy, "FAKE_POLICY"],
expected_kwargs={"cluster_id": fake_cluster})
def test_receiver_create(self):
self.verify_create(self.proxy.create_receiver, receiver.Receiver)

View File

@ -56,7 +56,7 @@ class TestFlavor(TestComputeProxy):
self.verify_find(
self.proxy.find_flavor, flavor.Flavor,
method_kwargs={"a": "b"},
expected_kwargs={"a": "b", "ignore_missing": False}
expected_kwargs={"a": "b", "ignore_missing": True}
)
def test_flavor_find_fetch_extra(self):
@ -66,7 +66,7 @@ class TestFlavor(TestComputeProxy):
) as mocked:
res = flavor.Flavor()
mocked.return_value = res
self._verify2(
self._verify(
'openstack.proxy.Proxy._find',
self.proxy.find_flavor,
method_args=['res', True, True],
@ -83,7 +83,7 @@ class TestFlavor(TestComputeProxy):
) as mocked:
res = flavor.Flavor(extra_specs={'a': 'b'})
mocked.return_value = res
self._verify2(
self._verify(
'openstack.proxy.Proxy._find',
self.proxy.find_flavor,
method_args=['res', True],
@ -100,7 +100,7 @@ class TestFlavor(TestComputeProxy):
) as mocked:
res = flavor.Flavor()
mocked.return_value = res
self._verify2(
self._verify(
'openstack.proxy.Proxy._get',
self.proxy.get_flavor,
method_args=['res'],
@ -116,7 +116,7 @@ class TestFlavor(TestComputeProxy):
) as mocked:
res = flavor.Flavor()
mocked.return_value = res
self._verify2(
self._verify(
'openstack.proxy.Proxy._get',
self.proxy.get_flavor,
method_args=['res', True],
@ -132,7 +132,7 @@ class TestFlavor(TestComputeProxy):
) as mocked:
res = flavor.Flavor(extra_specs={'a': 'b'})
mocked.return_value = res
self._verify2(
self._verify(
'openstack.proxy.Proxy._get',
self.proxy.get_flavor,
method_args=['res', True],
@ -193,58 +193,61 @@ class TestFlavor(TestComputeProxy):
)
def test_flavor_get_access(self):
self._verify("openstack.compute.v2.flavor.Flavor.get_access",
self.proxy.get_flavor_access,
method_args=["value"],
expected_args=[])
self._verify(
"openstack.compute.v2.flavor.Flavor.get_access",
self.proxy.get_flavor_access,
method_args=["value"],
expected_args=[self.proxy])
def test_flavor_add_tenant_access(self):
self._verify("openstack.compute.v2.flavor.Flavor.add_tenant_access",
self.proxy.flavor_add_tenant_access,
method_args=["value", "fake-tenant"],
expected_args=["fake-tenant"])
self._verify(
"openstack.compute.v2.flavor.Flavor.add_tenant_access",
self.proxy.flavor_add_tenant_access,
method_args=["value", "fake-tenant"],
expected_args=[self.proxy, "fake-tenant"])
def test_flavor_remove_tenant_access(self):
self._verify("openstack.compute.v2.flavor.Flavor.remove_tenant_access",
self.proxy.flavor_remove_tenant_access,
method_args=["value", "fake-tenant"],
expected_args=["fake-tenant"])
self._verify(
"openstack.compute.v2.flavor.Flavor.remove_tenant_access",
self.proxy.flavor_remove_tenant_access,
method_args=["value", "fake-tenant"],
expected_args=[self.proxy, "fake-tenant"])
def test_flavor_fetch_extra_specs(self):
self._verify("openstack.compute.v2.flavor.Flavor.fetch_extra_specs",
self.proxy.fetch_flavor_extra_specs,
method_args=["value"],
expected_args=[])
self._verify(
"openstack.compute.v2.flavor.Flavor.fetch_extra_specs",
self.proxy.fetch_flavor_extra_specs,
method_args=["value"],
expected_args=[self.proxy])
def test_create_flavor_extra_specs(self):
specs = {
'a': 'b'
}
self._verify("openstack.compute.v2.flavor.Flavor.create_extra_specs",
self.proxy.create_flavor_extra_specs,
method_args=["value", specs],
expected_kwargs={"specs": specs})
self._verify(
"openstack.compute.v2.flavor.Flavor.create_extra_specs",
self.proxy.create_flavor_extra_specs,
method_args=["value", {'a': 'b'}],
expected_args=[self.proxy],
expected_kwargs={"specs": {'a': 'b'}})
def test_get_flavor_extra_specs_prop(self):
self._verify(
"openstack.compute.v2.flavor.Flavor.get_extra_specs_property",
self.proxy.get_flavor_extra_specs_property,
method_args=["value", "prop"],
expected_args=["prop"])
expected_args=[self.proxy, "prop"])
def test_update_flavor_extra_specs_prop(self):
self._verify(
"openstack.compute.v2.flavor.Flavor.update_extra_specs_property",
self.proxy.update_flavor_extra_specs_property,
method_args=["value", "prop", "val"],
expected_args=["prop", "val"])
expected_args=[self.proxy, "prop", "val"])
def test_delete_flavor_extra_specs_prop(self):
self._verify(
"openstack.compute.v2.flavor.Flavor.delete_extra_specs_property",
self.proxy.delete_flavor_extra_specs_property,
method_args=["value", "prop"],
expected_args=["prop"])
expected_args=[self.proxy, "prop"])
class TestKeyPair(TestComputeProxy):
@ -286,7 +289,7 @@ class TestKeyPair(TestComputeProxy):
)
def test_keypairs(self):
self.verify_list_no_kwargs(self.proxy.keypairs, keypair.Keypair)
self.verify_list(self.proxy.keypairs, keypair.Keypair)
def test_keypairs_user_id(self):
self.verify_list(
@ -312,7 +315,7 @@ class TestAggregate(TestComputeProxy):
self.verify_find(self.proxy.find_aggregate, aggregate.Aggregate)
def test_aggregates(self):
self.verify_list_no_kwargs(self.proxy.aggregates, aggregate.Aggregate)
self.verify_list(self.proxy.aggregates, aggregate.Aggregate)
def test_aggregate_get(self):
self.verify_get(self.proxy.get_aggregate, aggregate.Aggregate)
@ -321,47 +324,49 @@ class TestAggregate(TestComputeProxy):
self.verify_update(self.proxy.update_aggregate, aggregate.Aggregate)
def test_aggregate_add_host(self):
self._verify("openstack.compute.v2.aggregate.Aggregate.add_host",
self.proxy.add_host_to_aggregate,
method_args=["value", "host"],
expected_args=["host"])
self._verify(
"openstack.compute.v2.aggregate.Aggregate.add_host",
self.proxy.add_host_to_aggregate,
method_args=["value", "host"],
expected_args=[self.proxy, "host"])
def test_aggregate_remove_host(self):
self._verify("openstack.compute.v2.aggregate.Aggregate.remove_host",
self.proxy.remove_host_from_aggregate,
method_args=["value", "host"],
expected_args=["host"])
self._verify(
"openstack.compute.v2.aggregate.Aggregate.remove_host",
self.proxy.remove_host_from_aggregate,
method_args=["value", "host"],
expected_args=[self.proxy, "host"])
def test_aggregate_set_metadata(self):
self._verify("openstack.compute.v2.aggregate.Aggregate.set_metadata",
self.proxy.set_aggregate_metadata,
method_args=["value", {'a': 'b'}],
expected_args=[{'a': 'b'}])
self._verify(
"openstack.compute.v2.aggregate.Aggregate.set_metadata",
self.proxy.set_aggregate_metadata,
method_args=["value", {'a': 'b'}],
expected_args=[self.proxy, {'a': 'b'}])
def test_aggregate_precache_image(self):
self._verify(
"openstack.compute.v2.aggregate.Aggregate.precache_images",
self.proxy.aggregate_precache_images,
method_args=["value", '1'],
expected_args=[[{'id': '1'}]])
expected_args=[self.proxy, [{'id': '1'}]])
def test_aggregate_precache_images(self):
self._verify(
"openstack.compute.v2.aggregate.Aggregate.precache_images",
self.proxy.aggregate_precache_images,
method_args=["value", ['1', '2']],
expected_args=[[{'id': '1'}, {'id': '2'}]])
expected_args=[self.proxy, [{'id': '1'}, {'id': '2'}]])
class TestService(TestComputeProxy):
def test_services(self):
self.verify_list_no_kwargs(
self.proxy.services, service.Service)
self.verify_list(self.proxy.services, service.Service)
@mock.patch('openstack.utils.supports_microversion', autospec=True,
return_value=False)
def test_enable_service_252(self, mv_mock):
self._verify2(
self._verify(
'openstack.compute.v2.service.Service.enable',
self.proxy.enable_service,
method_args=["value", "host1", "nova-compute"],
@ -371,7 +376,7 @@ class TestService(TestComputeProxy):
@mock.patch('openstack.utils.supports_microversion', autospec=True,
return_value=True)
def test_enable_service_253(self, mv_mock):
self._verify2(
self._verify(
'openstack.proxy.Proxy._update',
self.proxy.enable_service,
method_args=["value"],
@ -383,7 +388,7 @@ class TestService(TestComputeProxy):
@mock.patch('openstack.utils.supports_microversion', autospec=True,
return_value=False)
def test_disable_service_252(self, mv_mock):
self._verify2(
self._verify(
'openstack.compute.v2.service.Service.disable',
self.proxy.disable_service,
method_args=["value", "host1", "nova-compute"],
@ -392,7 +397,7 @@ class TestService(TestComputeProxy):
@mock.patch('openstack.utils.supports_microversion', autospec=True,
return_value=True)
def test_disable_service_253(self, mv_mock):
self._verify2(
self._verify(
'openstack.proxy.Proxy._update',
self.proxy.disable_service,
method_args=["value"],
@ -407,7 +412,7 @@ class TestService(TestComputeProxy):
@mock.patch('openstack.utils.supports_microversion', autospec=True,
return_value=False)
def test_force_service_down_252(self, mv_mock):
self._verify2(
self._verify(
'openstack.compute.v2.service.Service.set_forced_down',
self.proxy.update_service_forced_down,
method_args=["value", "host1", "nova-compute"],
@ -425,7 +430,7 @@ class TestService(TestComputeProxy):
@mock.patch('openstack.utils.supports_microversion', autospec=True,
return_value=False)
def test_force_service_down_252_empty_vals_svc(self, mv_mock):
self._verify2(
self._verify(
'openstack.compute.v2.service.Service.set_forced_down',
self.proxy.update_service_forced_down,
method_args=[{'host': 'a', 'binary': 'b'}, None, None],
@ -450,11 +455,13 @@ class TestHypervisor(TestComputeProxy):
def test_hypervisors_not_detailed(self):
self.verify_list(self.proxy.hypervisors, hypervisor.Hypervisor,
method_kwargs={"details": False})
method_kwargs={"details": False},
expected_kwargs={})
def test_hypervisors_detailed(self):
self.verify_list(self.proxy.hypervisors, hypervisor.HypervisorDetail,
method_kwargs={"details": True})
method_kwargs={"details": True},
expected_kwargs={})
@mock.patch('openstack.utils.supports_microversion', autospec=True,
return_value=False)
@ -462,8 +469,9 @@ class TestHypervisor(TestComputeProxy):
self.verify_list(
self.proxy.hypervisors,
hypervisor.Hypervisor,
base_path='/os-hypervisors/detail',
method_kwargs={'details': True},
base_path='/os-hypervisors/detail'
expected_kwargs={},
)
@mock.patch('openstack.utils.supports_microversion', autospec=True,
@ -472,8 +480,9 @@ class TestHypervisor(TestComputeProxy):
self.verify_list(
self.proxy.hypervisors,
hypervisor.Hypervisor,
base_path='/os-hypervisors/substring/search',
method_kwargs={'hypervisor_hostname_pattern': 'substring'},
base_path='/os-hypervisors/substring/search'
expected_kwargs={},
)
@mock.patch('openstack.utils.supports_microversion', autospec=True,
@ -492,7 +501,7 @@ class TestHypervisor(TestComputeProxy):
hypervisor.Hypervisor,
expected_kwargs={
'list_base_path': '/os-hypervisors/detail',
'ignore_missing': False})
'ignore_missing': True})
def test_find_hypervisor_no_detail(self):
self.verify_find(self.proxy.find_hypervisor,
@ -500,7 +509,7 @@ class TestHypervisor(TestComputeProxy):
method_kwargs={'details': False},
expected_kwargs={
'list_base_path': None,
'ignore_missing': False})
'ignore_missing': True})
def test_get_hypervisor(self):
self.verify_get(self.proxy.get_hypervisor,
@ -511,7 +520,7 @@ class TestHypervisor(TestComputeProxy):
"openstack.compute.v2.hypervisor.Hypervisor.get_uptime",
self.proxy.get_hypervisor_uptime,
method_args=["value"],
expected_args=[])
expected_args=[self.proxy])
class TestCompute(TestComputeProxy):
@ -519,7 +528,7 @@ class TestCompute(TestComputeProxy):
self.verify_find(self.proxy.find_extension, extension.Extension)
def test_extensions(self):
self.verify_list_no_kwargs(self.proxy.extensions, extension.Extension)
self.verify_list(self.proxy.extensions, extension.Extension)
def test_image_delete(self):
self.verify_delete(self.proxy.delete_image, image.Image, False)
@ -544,7 +553,7 @@ class TestCompute(TestComputeProxy):
expected_kwargs={"query": 1})
def test_limits_get(self):
self.verify_get(self.proxy.get_limits, limits.Limits, value=[])
self.verify_get(self.proxy.get_limits, limits.Limits, method_args=[])
def test_server_interface_create(self):
self.verify_create(self.proxy.create_server_interface,
@ -561,33 +570,30 @@ class TestCompute(TestComputeProxy):
test_interface.server_id = server_id
# Case1: ServerInterface instance is provided as value
self._verify2("openstack.proxy.Proxy._delete",
self.proxy.delete_server_interface,
method_args=[test_interface],
method_kwargs={"server": server_id},
expected_args=[server_interface.ServerInterface],
expected_kwargs={"server_id": server_id,
"port_id": interface_id,
"ignore_missing": True})
self._verify(
"openstack.proxy.Proxy._delete",
self.proxy.delete_server_interface,
method_args=[test_interface],
method_kwargs={"server": server_id},
expected_args=[server_interface.ServerInterface, interface_id],
expected_kwargs={"server_id": server_id, "ignore_missing": True})
# Case2: ServerInterface ID is provided as value
self._verify2("openstack.proxy.Proxy._delete",
self.proxy.delete_server_interface,
method_args=[interface_id],
method_kwargs={"server": server_id},
expected_args=[server_interface.ServerInterface],
expected_kwargs={"server_id": server_id,
"port_id": interface_id,
"ignore_missing": True})
self._verify(
"openstack.proxy.Proxy._delete",
self.proxy.delete_server_interface,
method_args=[interface_id],
method_kwargs={"server": server_id},
expected_args=[server_interface.ServerInterface, interface_id],
expected_kwargs={"server_id": server_id, "ignore_missing": True})
def test_server_interface_delete_ignore(self):
self.proxy._get_uri_attribute = lambda *args: args[1]
self.verify_delete(self.proxy.delete_server_interface,
server_interface.ServerInterface, True,
method_kwargs={"server": "test_id"},
expected_args=[server_interface.ServerInterface],
expected_kwargs={"server_id": "test_id",
"port_id": "resource_or_id"})
expected_args=[],
expected_kwargs={"server_id": "test_id"})
def test_server_interface_get(self):
self.proxy._get_uri_attribute = lambda *args: args[1]
@ -598,39 +604,42 @@ class TestCompute(TestComputeProxy):
test_interface.server_id = server_id
# Case1: ServerInterface instance is provided as value
self._verify2('openstack.proxy.Proxy._get',
self.proxy.get_server_interface,
method_args=[test_interface],
method_kwargs={"server": server_id},
expected_args=[server_interface.ServerInterface],
expected_kwargs={"port_id": interface_id,
"server_id": server_id})
self._verify(
'openstack.proxy.Proxy._get',
self.proxy.get_server_interface,
method_args=[test_interface],
method_kwargs={"server": server_id},
expected_args=[server_interface.ServerInterface],
expected_kwargs={"port_id": interface_id, "server_id": server_id})
# Case2: ServerInterface ID is provided as value
self._verify2('openstack.proxy.Proxy._get',
self.proxy.get_server_interface,
method_args=[interface_id],
method_kwargs={"server": server_id},
expected_args=[server_interface.ServerInterface],
expected_kwargs={"port_id": interface_id,
"server_id": server_id})
self._verify(
'openstack.proxy.Proxy._get',
self.proxy.get_server_interface,
method_args=[interface_id],
method_kwargs={"server": server_id},
expected_args=[server_interface.ServerInterface],
expected_kwargs={"port_id": interface_id, "server_id": server_id})
def test_server_interfaces(self):
self.verify_list(self.proxy.server_interfaces,
server_interface.ServerInterface,
method_args=["test_id"],
expected_args=[],
expected_kwargs={"server_id": "test_id"})
def test_server_ips_with_network_label(self):
self.verify_list(self.proxy.server_ips, server_ip.ServerIP,
method_args=["test_id"],
method_kwargs={"network_label": "test_label"},
expected_args=[],
expected_kwargs={"server_id": "test_id",
"network_label": "test_label"})
def test_server_ips_without_network_label(self):
self.verify_list(self.proxy.server_ips, server_ip.ServerIP,
method_args=["test_id"],
expected_args=[],
expected_kwargs={"server_id": "test_id",
"network_label": None})
@ -644,9 +653,11 @@ class TestCompute(TestComputeProxy):
self.verify_delete(self.proxy.delete_server, server.Server, True)
def test_server_force_delete(self):
self._verify("openstack.compute.v2.server.Server.force_delete",
self.proxy.delete_server,
method_args=["value", False, True])
self._verify(
"openstack.compute.v2.server.Server.force_delete",
self.proxy.delete_server,
method_args=["value", False, True],
expected_args=[self.proxy])
def test_server_find(self):
self.verify_find(self.proxy.find_server, server.Server)
@ -675,23 +686,28 @@ class TestCompute(TestComputeProxy):
self.verify_wait_for_status(
self.proxy.wait_for_server,
method_args=[value],
expected_args=[value, 'ACTIVE', ['ERROR'], 2, 120])
expected_args=[self.proxy, value, 'ACTIVE', ['ERROR'], 2, 120])
def test_server_resize(self):
self._verify("openstack.compute.v2.server.Server.resize",
self.proxy.resize_server,
method_args=["value", "test-flavor"],
expected_args=["test-flavor"])
self._verify(
"openstack.compute.v2.server.Server.resize",
self.proxy.resize_server,
method_args=["value", "test-flavor"],
expected_args=[self.proxy, "test-flavor"])
def test_server_confirm_resize(self):
self._verify("openstack.compute.v2.server.Server.confirm_resize",
self.proxy.confirm_server_resize,
method_args=["value"])
self._verify(
"openstack.compute.v2.server.Server.confirm_resize",
self.proxy.confirm_server_resize,
method_args=["value"],
expected_args=[self.proxy])
def test_server_revert_resize(self):
self._verify("openstack.compute.v2.server.Server.revert_resize",
self.proxy.revert_server_resize,
method_args=["value"])
self._verify(
"openstack.compute.v2.server.Server.revert_resize",
self.proxy.revert_server_resize,
method_args=["value"],
expected_args=[self.proxy])
def test_server_rebuild(self):
id = 'test_image_id'
@ -700,194 +716,233 @@ class TestCompute(TestComputeProxy):
# Case1: image object is provided
# NOTE: Inside of Server.rebuild is where image_obj gets converted
# to an ID instead of object.
self._verify('openstack.compute.v2.server.Server.rebuild',
self.proxy.rebuild_server,
method_args=["value", "test_server", "test_pass"],
method_kwargs={"metadata": {"k1": "v1"},
"image": image_obj},
expected_args=["test_server", "test_pass"],
expected_kwargs={"metadata": {"k1": "v1"},
"image": image_obj})
self._verify(
'openstack.compute.v2.server.Server.rebuild',
self.proxy.rebuild_server,
method_args=["value", "test_server", "test_pass"],
method_kwargs={"metadata": {"k1": "v1"}, "image": image_obj},
expected_args=[self.proxy, "test_server", "test_pass"],
expected_kwargs={"metadata": {"k1": "v1"}, "image": image_obj})
# Case2: image name or id is provided
self._verify('openstack.compute.v2.server.Server.rebuild',
self.proxy.rebuild_server,
method_args=["value", "test_server", "test_pass"],
method_kwargs={"metadata": {"k1": "v1"},
"image": id},
expected_args=["test_server", "test_pass"],
expected_kwargs={"metadata": {"k1": "v1"},
"image": id})
self._verify(
'openstack.compute.v2.server.Server.rebuild',
self.proxy.rebuild_server,
method_args=["value", "test_server", "test_pass"],
method_kwargs={"metadata": {"k1": "v1"}, "image": id},
expected_args=[self.proxy, "test_server", "test_pass"],
expected_kwargs={"metadata": {"k1": "v1"}, "image": id})
def test_add_fixed_ip_to_server(self):
self._verify("openstack.compute.v2.server.Server.add_fixed_ip",
self.proxy.add_fixed_ip_to_server,
method_args=["value", "network-id"],
expected_args=["network-id"])
self._verify(
"openstack.compute.v2.server.Server.add_fixed_ip",
self.proxy.add_fixed_ip_to_server,
method_args=["value", "network-id"],
expected_args=[self.proxy, "network-id"])
def test_fixed_ip_from_server(self):
self._verify("openstack.compute.v2.server.Server.remove_fixed_ip",
self.proxy.remove_fixed_ip_from_server,
method_args=["value", "address"],
expected_args=["address"])
self._verify(
"openstack.compute.v2.server.Server.remove_fixed_ip",
self.proxy.remove_fixed_ip_from_server,
method_args=["value", "address"],
expected_args=[self.proxy, "address"])
def test_floating_ip_to_server(self):
self._verify("openstack.compute.v2.server.Server.add_floating_ip",
self.proxy.add_floating_ip_to_server,
method_args=["value", "floating-ip"],
expected_args=["floating-ip"],
expected_kwargs={'fixed_address': None})
self._verify(
"openstack.compute.v2.server.Server.add_floating_ip",
self.proxy.add_floating_ip_to_server,
method_args=["value", "floating-ip"],
expected_args=[self.proxy, "floating-ip"],
expected_kwargs={'fixed_address': None})
def test_add_floating_ip_to_server_with_fixed_addr(self):
self._verify("openstack.compute.v2.server.Server.add_floating_ip",
self.proxy.add_floating_ip_to_server,
method_args=["value", "floating-ip", 'fixed-addr'],
expected_args=["floating-ip"],
expected_kwargs={'fixed_address': 'fixed-addr'})
self._verify(
"openstack.compute.v2.server.Server.add_floating_ip",
self.proxy.add_floating_ip_to_server,
method_args=["value", "floating-ip", 'fixed-addr'],
expected_args=[self.proxy, "floating-ip"],
expected_kwargs={'fixed_address': 'fixed-addr'})
def test_remove_floating_ip_from_server(self):
self._verify("openstack.compute.v2.server.Server.remove_floating_ip",
self.proxy.remove_floating_ip_from_server,
method_args=["value", "address"],
expected_args=["address"])
self._verify(
"openstack.compute.v2.server.Server.remove_floating_ip",
self.proxy.remove_floating_ip_from_server,
method_args=["value", "address"],
expected_args=[self.proxy, "address"])
def test_server_backup(self):
self._verify("openstack.compute.v2.server.Server.backup",
self.proxy.backup_server,
method_args=["value", "name", "daily", 1],
expected_args=["name", "daily", 1])
self._verify(
"openstack.compute.v2.server.Server.backup",
self.proxy.backup_server,
method_args=["value", "name", "daily", 1],
expected_args=[self.proxy, "name", "daily", 1])
def test_server_pause(self):
self._verify("openstack.compute.v2.server.Server.pause",
self.proxy.pause_server,
method_args=["value"])
self._verify(
"openstack.compute.v2.server.Server.pause",
self.proxy.pause_server,
method_args=["value"],
expected_args=[self.proxy])
def test_server_unpause(self):
self._verify("openstack.compute.v2.server.Server.unpause",
self.proxy.unpause_server,
method_args=["value"])
self._verify(
"openstack.compute.v2.server.Server.unpause",
self.proxy.unpause_server,
method_args=["value"],
expected_args=[self.proxy])
def test_server_suspend(self):
self._verify("openstack.compute.v2.server.Server.suspend",
self.proxy.suspend_server,
method_args=["value"])
self._verify(
"openstack.compute.v2.server.Server.suspend",
self.proxy.suspend_server,
method_args=["value"],
expected_args=[self.proxy])
def test_server_resume(self):
self._verify("openstack.compute.v2.server.Server.resume",
self.proxy.resume_server,
method_args=["value"])
self._verify(
"openstack.compute.v2.server.Server.resume",
self.proxy.resume_server,
method_args=["value"],
expected_args=[self.proxy])
def test_server_lock(self):
self._verify("openstack.compute.v2.server.Server.lock",
self.proxy.lock_server,
method_args=["value"])
self._verify(
"openstack.compute.v2.server.Server.lock",
self.proxy.lock_server,
method_args=["value"],
expected_args=[self.proxy])
def test_server_unlock(self):
self._verify("openstack.compute.v2.server.Server.unlock",
self.proxy.unlock_server,
method_args=["value"])
self._verify(
"openstack.compute.v2.server.Server.unlock",
self.proxy.unlock_server,
method_args=["value"],
expected_args=[self.proxy])
def test_server_rescue(self):
self._verify("openstack.compute.v2.server.Server.rescue",
self.proxy.rescue_server,
method_args=["value"],
expected_kwargs={"admin_pass": None, "image_ref": None})
self._verify(
"openstack.compute.v2.server.Server.rescue",
self.proxy.rescue_server,
method_args=["value"],
expected_args=[self.proxy],
expected_kwargs={"admin_pass": None, "image_ref": None})
def test_server_rescue_with_options(self):
self._verify("openstack.compute.v2.server.Server.rescue",
self.proxy.rescue_server,
method_args=["value", 'PASS', 'IMG'],
expected_kwargs={"admin_pass": 'PASS',
"image_ref": 'IMG'})
self._verify(
"openstack.compute.v2.server.Server.rescue",
self.proxy.rescue_server,
method_args=["value", 'PASS', 'IMG'],
expected_args=[self.proxy],
expected_kwargs={"admin_pass": 'PASS', "image_ref": 'IMG'})
def test_server_unrescue(self):
self._verify("openstack.compute.v2.server.Server.unrescue",
self.proxy.unrescue_server,
method_args=["value"])
self._verify(
"openstack.compute.v2.server.Server.unrescue",
self.proxy.unrescue_server,
method_args=["value"],
expected_args=[self.proxy])
def test_server_evacuate(self):
self._verify("openstack.compute.v2.server.Server.evacuate",
self.proxy.evacuate_server,
method_args=["value"],
expected_kwargs={"host": None, "admin_pass": None,
"force": None})
self._verify(
"openstack.compute.v2.server.Server.evacuate",
self.proxy.evacuate_server,
method_args=["value"],
expected_args=[self.proxy],
expected_kwargs={"host": None, "admin_pass": None, "force": None})
def test_server_evacuate_with_options(self):
self._verify("openstack.compute.v2.server.Server.evacuate",
self.proxy.evacuate_server,
method_args=["value", 'HOST2', 'NEW_PASS', True],
expected_kwargs={"host": "HOST2",
"admin_pass": 'NEW_PASS',
"force": True})
self._verify(
"openstack.compute.v2.server.Server.evacuate",
self.proxy.evacuate_server,
method_args=["value", 'HOST2', 'NEW_PASS', True],
expected_args=[self.proxy],
expected_kwargs={
"host": "HOST2", "admin_pass": 'NEW_PASS', "force": True})
def test_server_start(self):
self._verify("openstack.compute.v2.server.Server.start",
self.proxy.start_server,
method_args=["value"])
self._verify(
"openstack.compute.v2.server.Server.start",
self.proxy.start_server,
method_args=["value"],
expected_args=[self.proxy])
def test_server_stop(self):
self._verify("openstack.compute.v2.server.Server.stop",
self.proxy.stop_server,
method_args=["value"])
self._verify(
"openstack.compute.v2.server.Server.stop",
self.proxy.stop_server,
method_args=["value"],
expected_args=[self.proxy])
def test_server_shelve(self):
self._verify("openstack.compute.v2.server.Server.shelve",
self.proxy.shelve_server,
method_args=["value"])
self._verify(
"openstack.compute.v2.server.Server.shelve",
self.proxy.shelve_server,
method_args=["value"],
expected_args=[self.proxy])
def test_server_unshelve(self):
self._verify("openstack.compute.v2.server.Server.unshelve",
self.proxy.unshelve_server,
method_args=["value"])
self._verify(
"openstack.compute.v2.server.Server.unshelve",
self.proxy.unshelve_server,
method_args=["value"],
expected_args=[self.proxy])
def test_get_server_output(self):
self._verify("openstack.compute.v2.server.Server.get_console_output",
self.proxy.get_server_console_output,
method_args=["value"],
expected_kwargs={"length": None})
self._verify(
"openstack.compute.v2.server.Server.get_console_output",
self.proxy.get_server_console_output,
method_args=["value"],
expected_args=[self.proxy],
expected_kwargs={"length": None})
self._verify("openstack.compute.v2.server.Server.get_console_output",
self.proxy.get_server_console_output,
method_args=["value", 1],
expected_kwargs={"length": 1})
self._verify(
"openstack.compute.v2.server.Server.get_console_output",
self.proxy.get_server_console_output,
method_args=["value", 1],
expected_args=[self.proxy],
expected_kwargs={"length": 1})
def test_availability_zones_not_detailed(self):
self.verify_list(self.proxy.availability_zones,
az.AvailabilityZone,
method_kwargs={"details": False})
method_kwargs={"details": False},
expected_kwargs={})
def test_availability_zones_detailed(self):
self.verify_list(self.proxy.availability_zones,
az.AvailabilityZoneDetail,
method_kwargs={"details": True})
method_kwargs={"details": True},
expected_kwargs={})
def test_get_all_server_metadata(self):
self._verify2("openstack.compute.v2.server.Server.get_metadata",
self.proxy.get_server_metadata,
method_args=["value"],
method_result=server.Server(id="value", metadata={}),
expected_args=[self.proxy],
expected_result={})
self._verify(
"openstack.compute.v2.server.Server.get_metadata",
self.proxy.get_server_metadata,
method_args=["value"],
method_result=server.Server(id="value", metadata={}),
expected_args=[self.proxy],
expected_result={})
def test_set_server_metadata(self):
kwargs = {"a": "1", "b": "2"}
id = "an_id"
self._verify2("openstack.compute.v2.server.Server.set_metadata",
self.proxy.set_server_metadata,
method_args=[id],
method_kwargs=kwargs,
method_result=server.Server.existing(id=id,
metadata=kwargs),
expected_args=[self.proxy],
expected_kwargs=kwargs,
expected_result=kwargs)
self._verify(
"openstack.compute.v2.server.Server.set_metadata",
self.proxy.set_server_metadata,
method_args=[id],
method_kwargs=kwargs,
method_result=server.Server.existing(id=id, metadata=kwargs),
expected_args=[self.proxy],
expected_kwargs=kwargs,
expected_result=kwargs)
def test_delete_server_metadata(self):
self._verify2("openstack.compute.v2.server.Server.delete_metadata",
self.proxy.delete_server_metadata,
expected_result=None,
method_args=["value", "key"],
expected_args=[self.proxy, "key"])
self._verify(
"openstack.compute.v2.server.Server.delete_metadata",
self.proxy.delete_server_metadata,
expected_result=None,
method_args=["value", "key"],
expected_args=[self.proxy, "key"])
def test_create_image(self):
metadata = {'k1': 'v1'}
@ -940,32 +995,33 @@ class TestCompute(TestComputeProxy):
self.verify_list(self.proxy.server_groups, server_group.ServerGroup)
def test_live_migrate_server(self):
self._verify('openstack.compute.v2.server.Server.live_migrate',
self.proxy.live_migrate_server,
method_args=["value", "host1", False],
expected_args=["host1"],
expected_kwargs={'force': False, 'block_migration': None})
self._verify(
'openstack.compute.v2.server.Server.live_migrate',
self.proxy.live_migrate_server,
method_args=["value", "host1", False],
expected_args=[self.proxy, "host1"],
expected_kwargs={'force': False, 'block_migration': None})
def test_fetch_security_groups(self):
self._verify(
'openstack.compute.v2.server.Server.fetch_security_groups',
self.proxy.fetch_server_security_groups,
method_args=["value"],
expected_args=[])
expected_args=[self.proxy])
def test_add_security_groups(self):
self._verify(
'openstack.compute.v2.server.Server.add_security_group',
self.proxy.add_security_group_to_server,
method_args=["value", {'id': 'id', 'name': 'sg'}],
expected_args=['sg'])
expected_args=[self.proxy, 'sg'])
def test_remove_security_groups(self):
self._verify(
'openstack.compute.v2.server.Server.remove_security_group',
self.proxy.remove_security_group_from_server,
method_args=["value", {'id': 'id', 'name': 'sg'}],
expected_args=['sg'])
expected_args=[self.proxy, 'sg'])
def test_create_server_remote_console(self):
self.verify_create(
@ -979,7 +1035,7 @@ class TestCompute(TestComputeProxy):
'openstack.compute.v2.server.Server.get_console_url',
self.proxy.get_server_console_url,
method_args=["value", "console_type"],
expected_args=["console_type"])
expected_args=[self.proxy, "console_type"])
@mock.patch('openstack.utils.supports_microversion', autospec=True)
@mock.patch('openstack.compute.v2._proxy.Proxy._create', autospec=True)

View File

@ -19,6 +19,7 @@ EXAMPLE = {
'id': '2',
'volume_id': '3',
'tag': '4',
'delete_on_termination': 'true',
}
@ -46,3 +47,5 @@ class TestServerInterface(base.TestCase):
self.assertEqual(EXAMPLE['id'], sot.id)
self.assertEqual(EXAMPLE['volume_id'], sot.volume_id)
self.assertEqual(EXAMPLE['tag'], sot.tag)
self.assertEqual(EXAMPLE['delete_on_termination'],
sot.delete_on_termination)

View File

@ -205,6 +205,29 @@ class TestConfig(base.TestCase):
self.assertNotIn('domain_id', cc.auth)
self.assertNotIn('domain_id', cc)
def test_get_one_infer_passcode(self):
single_conf = base._write_yaml({
'clouds': {
'mfa': {
'auth_type': 'v3multifactor',
'auth_methods': ['v3password', 'v3totp'],
'auth': {
'auth_url': 'fake_url',
'username': 'testuser',
'password': 'testpass',
'project_name': 'testproject',
'project_domain_name': 'projectdomain',
'user_domain_name': 'udn'
},
'region_name': 'test-region',
}
}
})
c = config.OpenStackConfig(config_files=[single_conf])
cc = c.get_one(cloud='mfa', passcode='123')
self.assertEqual('123', cc.auth['passcode'])
def test_get_one_with_hyphenated_project_id(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])

View File

@ -24,33 +24,38 @@ class TestDatabaseProxy(test_proxy_base.TestProxyBase):
self.proxy = _proxy.Proxy(self.session)
def test_database_create_attrs(self):
self.verify_create(self.proxy.create_database, database.Database,
self.verify_create(self.proxy.create_database,
database.Database,
method_kwargs={"instance": "id"},
expected_kwargs={"instance_id": "id"})
def test_database_delete(self):
self.verify_delete(self.proxy.delete_database,
database.Database, False,
input_path_args={"instance": "test_id"},
expected_path_args={"instance_id": "test_id"})
database.Database,
ignore_missing=False,
method_kwargs={"instance": "test_id"},
expected_kwargs={"instance_id": "test_id"})
def test_database_delete_ignore(self):
self.verify_delete(self.proxy.delete_database,
database.Database, True,
input_path_args={"instance": "test_id"},
expected_path_args={"instance_id": "test_id"})
database.Database,
ignore_missing=True,
method_kwargs={"instance": "test_id"},
expected_kwargs={"instance_id": "test_id"})
def test_database_find(self):
self._verify2('openstack.proxy.Proxy._find',
self.proxy.find_database,
method_args=["db", "instance"],
expected_args=[database.Database, "db"],
expected_kwargs={"instance_id": "instance",
"ignore_missing": True})
self._verify(
'openstack.proxy.Proxy._find',
self.proxy.find_database,
method_args=["db", "instance"],
expected_args=[database.Database, "db"],
expected_kwargs={
"instance_id": "instance", "ignore_missing": True})
def test_databases(self):
self.verify_list(self.proxy.databases, database.Database,
method_args=["id"],
expected_args=[],
expected_kwargs={"instance_id": "id"})
def test_database_get(self):
@ -95,25 +100,27 @@ class TestDatabaseProxy(test_proxy_base.TestProxyBase):
def test_user_delete(self):
self.verify_delete(self.proxy.delete_user, user.User, False,
input_path_args={"instance": "id"},
expected_path_args={"instance_id": "id"})
method_kwargs={"instance": "id"},
expected_kwargs={"instance_id": "id"})
def test_user_delete_ignore(self):
self.verify_delete(self.proxy.delete_user, user.User, True,
input_path_args={"instance": "id"},
expected_path_args={"instance_id": "id"})
method_kwargs={"instance": "id"},
expected_kwargs={"instance_id": "id"})
def test_user_find(self):
self._verify2('openstack.proxy.Proxy._find',
self.proxy.find_user,
method_args=["user", "instance"],
expected_args=[user.User, "user"],
expected_kwargs={"instance_id": "instance",
"ignore_missing": True})
self._verify(
'openstack.proxy.Proxy._find',
self.proxy.find_user,
method_args=["user", "instance"],
expected_args=[user.User, "user"],
expected_kwargs={
"instance_id": "instance", "ignore_missing": True})
def test_users(self):
self.verify_list(self.proxy.users, user.User,
method_args=["test_instance"],
expected_args=[],
expected_kwargs={"instance_id": "test_instance"})
def test_user_get(self):

View File

@ -50,16 +50,18 @@ class TestDnsZone(TestDnsProxy):
self.verify_update(self.proxy.update_zone, zone.Zone)
def test_zone_abandon(self):
self._verify2("openstack.dns.v2.zone.Zone.abandon",
self.proxy.abandon_zone,
method_args=[{'zone': 'id'}],
expected_args=[self.proxy])
self._verify(
"openstack.dns.v2.zone.Zone.abandon",
self.proxy.abandon_zone,
method_args=[{'zone': 'id'}],
expected_args=[self.proxy])
def test_zone_xfr(self):
self._verify2("openstack.dns.v2.zone.Zone.xfr",
self.proxy.xfr_zone,
method_args=[{'zone': 'id'}],
expected_args=[self.proxy])
self._verify(
"openstack.dns.v2.zone.Zone.xfr",
self.proxy.xfr_zone,
method_args=[{'zone': 'id'}],
expected_args=[self.proxy])
class TestDnsRecordset(TestDnsProxy):
@ -84,7 +86,7 @@ class TestDnsRecordset(TestDnsProxy):
def test_recordsets(self):
self.verify_list(self.proxy.recordsets, recordset.Recordset,
base_path='/recordsets')
expected_kwargs={'base_path': '/recordsets'})
def test_recordsets_zone(self):
self.verify_list(self.proxy.recordsets, recordset.Recordset,
@ -92,13 +94,13 @@ class TestDnsRecordset(TestDnsProxy):
expected_kwargs={'zone_id': 'zid'})
def test_recordset_find(self):
self._verify2("openstack.proxy.Proxy._find",
self.proxy.find_recordset,
method_args=['zone', 'rs'],
method_kwargs={},
expected_args=[recordset.Recordset, 'rs'],
expected_kwargs={'ignore_missing': True,
'zone_id': 'zone'})
self._verify(
"openstack.proxy.Proxy._find",
self.proxy.find_recordset,
method_args=['zone', 'rs'],
method_kwargs={},
expected_args=[recordset.Recordset, 'rs'],
expected_kwargs={'ignore_missing': True, 'zone_id': 'zone'})
class TestDnsFloatIP(TestDnsProxy):
@ -143,7 +145,7 @@ class TestDnsZoneExport(TestDnsProxy):
def test_zone_export_get_text(self):
self.verify_get(self.proxy.get_zone_export_text,
zone_export.ZoneExport,
value=[{'id': 'zone_export_id_value'}],
method_args=[{'id': 'zone_export_id_value'}],
expected_kwargs={
'base_path': '/zones/tasks/export/%(id)s/export'
})
@ -156,6 +158,7 @@ class TestDnsZoneExport(TestDnsProxy):
zone_export.ZoneExport,
method_args=[{'id': 'zone_id_value'}],
method_kwargs={'name': 'id'},
expected_args=[],
expected_kwargs={'name': 'id',
'zone_id': 'zone_id_value',
'prepend_key': False})
@ -179,6 +182,7 @@ class TestDnsZoneTransferRequest(TestDnsProxy):
zone_transfer.ZoneTransferRequest,
method_args=[{'id': 'zone_id_value'}],
method_kwargs={'name': 'id'},
expected_args=[],
expected_kwargs={'name': 'id',
'zone_id': 'zone_id_value',
'prepend_key': False})

View File

@ -23,6 +23,9 @@ EXAMPLE = {
'is_domain': False,
'name': '5',
'parent_id': '6',
'options': {
'foo': 'bar'
}
}
@ -65,6 +68,7 @@ class TestProject(base.TestCase):
self.assertEqual(EXAMPLE['id'], sot.id)
self.assertEqual(EXAMPLE['name'], sot.name)
self.assertEqual(EXAMPLE['parent_id'], sot.parent_id)
self.assertDictEqual(EXAMPLE['options'], sot.options)
class TestUserProject(base.TestCase):

View File

@ -58,6 +58,7 @@ class TestImageProxy(test_proxy_base.TestProxyBase):
"openstack.image.v2.image.Image.import_image",
self.proxy.import_image,
method_args=[original_image, "method", "uri"],
expected_args=[self.proxy],
expected_kwargs={
"method": "method",
"store": None,
@ -218,17 +219,21 @@ class TestImageProxy(test_proxy_base.TestProxyBase):
def test_image_download(self):
original_image = image.Image(**EXAMPLE)
self._verify('openstack.image.v2.image.Image.download',
self.proxy.download_image,
method_args=[original_image],
method_kwargs={
'output': 'some_output',
'chunk_size': 1,
'stream': True
},
expected_kwargs={'output': 'some_output',
'chunk_size': 1,
'stream': True})
self._verify(
'openstack.image.v2.image.Image.download',
self.proxy.download_image,
method_args=[original_image],
method_kwargs={
'output': 'some_output',
'chunk_size': 1,
'stream': True
},
expected_args=[self.proxy],
expected_kwargs={
'output': 'some_output',
'chunk_size': 1,
'stream': True,
})
@mock.patch("openstack.image.v2.image.Image.fetch")
def test_image_stage(self, mock_fetch):
@ -289,26 +294,32 @@ class TestImageProxy(test_proxy_base.TestProxyBase):
self.verify_list(self.proxy.images, image.Image)
def test_add_tag(self):
self._verify("openstack.image.v2.image.Image.add_tag",
self.proxy.add_tag,
method_args=["image", "tag"],
expected_args=["tag"])
self._verify(
"openstack.image.v2.image.Image.add_tag",
self.proxy.add_tag,
method_args=["image", "tag"],
expected_args=[self.proxy, "tag"])
def test_remove_tag(self):
self._verify("openstack.image.v2.image.Image.remove_tag",
self.proxy.remove_tag,
method_args=["image", "tag"],
expected_args=["tag"])
self._verify(
"openstack.image.v2.image.Image.remove_tag",
self.proxy.remove_tag,
method_args=["image", "tag"],
expected_args=[self.proxy, "tag"])
def test_deactivate_image(self):
self._verify("openstack.image.v2.image.Image.deactivate",
self.proxy.deactivate_image,
method_args=["image"])
self._verify(
"openstack.image.v2.image.Image.deactivate",
self.proxy.deactivate_image,
method_args=["image"],
expected_args=[self.proxy])
def test_reactivate_image(self):
self._verify("openstack.image.v2.image.Image.reactivate",
self.proxy.reactivate_image,
method_args=["image"])
self._verify(
"openstack.image.v2.image.Image.reactivate",
self.proxy.reactivate_image,
method_args=["image"],
expected_args=[self.proxy])
def test_member_create(self):
self.verify_create(self.proxy.add_member, member.Member,
@ -316,84 +327,91 @@ class TestImageProxy(test_proxy_base.TestProxyBase):
expected_kwargs={"image_id": "test_id"})
def test_member_delete(self):
self._verify2("openstack.proxy.Proxy._delete",
self.proxy.remove_member,
method_args=["member_id"],
method_kwargs={"image": "image_id",
"ignore_missing": False},
expected_args=[member.Member],
expected_kwargs={"member_id": "member_id",
"image_id": "image_id",
"ignore_missing": False})
self._verify(
"openstack.proxy.Proxy._delete",
self.proxy.remove_member,
method_args=["member_id"],
method_kwargs={"image": "image_id", "ignore_missing": False},
expected_args=[member.Member],
expected_kwargs={
"member_id": "member_id",
"image_id": "image_id",
"ignore_missing": False})
def test_member_delete_ignore(self):
self._verify2("openstack.proxy.Proxy._delete",
self.proxy.remove_member,
method_args=["member_id"],
method_kwargs={"image": "image_id"},
expected_args=[member.Member],
expected_kwargs={"member_id": "member_id",
"image_id": "image_id",
"ignore_missing": True})
self._verify(
"openstack.proxy.Proxy._delete",
self.proxy.remove_member,
method_args=["member_id"],
method_kwargs={"image": "image_id"},
expected_args=[member.Member],
expected_kwargs={
"member_id": "member_id",
"image_id": "image_id",
"ignore_missing": True})
def test_member_update(self):
self._verify2("openstack.proxy.Proxy._update",
self.proxy.update_member,
method_args=['member_id', 'image_id'],
expected_args=[member.Member],
expected_kwargs={'member_id': 'member_id',
'image_id': 'image_id'})
self._verify(
"openstack.proxy.Proxy._update",
self.proxy.update_member,
method_args=['member_id', 'image_id'],
expected_args=[member.Member],
expected_kwargs={'member_id': 'member_id', 'image_id': 'image_id'})
def test_member_get(self):
self._verify2("openstack.proxy.Proxy._get",
self.proxy.get_member,
method_args=['member_id'],
method_kwargs={"image": "image_id"},
expected_args=[member.Member],
expected_kwargs={'member_id': 'member_id',
'image_id': 'image_id'})
self._verify(
"openstack.proxy.Proxy._get",
self.proxy.get_member,
method_args=['member_id'],
method_kwargs={"image": "image_id"},
expected_args=[member.Member],
expected_kwargs={'member_id': 'member_id', 'image_id': 'image_id'})
def test_member_find(self):
self._verify2("openstack.proxy.Proxy._find",
self.proxy.find_member,
method_args=['member_id'],
method_kwargs={"image": "image_id"},
expected_args=[member.Member, "member_id"],
expected_kwargs={'ignore_missing': True,
'image_id': 'image_id'})
self._verify(
"openstack.proxy.Proxy._find",
self.proxy.find_member,
method_args=['member_id'],
method_kwargs={"image": "image_id"},
expected_args=[member.Member, "member_id"],
expected_kwargs={'ignore_missing': True, 'image_id': 'image_id'})
def test_members(self):
self.verify_list(self.proxy.members, member.Member,
method_args=('image_1',),
method_kwargs={'image': 'image_1'},
expected_kwargs={'image_id': 'image_1'})
def test_images_schema_get(self):
self._verify2("openstack.proxy.Proxy._get",
self.proxy.get_images_schema,
expected_args=[schema.Schema],
expected_kwargs={'base_path': '/schemas/images',
'requires_id': False})
self._verify(
"openstack.proxy.Proxy._get",
self.proxy.get_images_schema,
expected_args=[schema.Schema],
expected_kwargs={
'base_path': '/schemas/images', 'requires_id': False})
def test_image_schema_get(self):
self._verify2("openstack.proxy.Proxy._get",
self.proxy.get_image_schema,
expected_args=[schema.Schema],
expected_kwargs={'base_path': '/schemas/image',
'requires_id': False})
self._verify(
"openstack.proxy.Proxy._get",
self.proxy.get_image_schema,
expected_args=[schema.Schema],
expected_kwargs={
'base_path': '/schemas/image', 'requires_id': False})
def test_members_schema_get(self):
self._verify2("openstack.proxy.Proxy._get",
self.proxy.get_members_schema,
expected_args=[schema.Schema],
expected_kwargs={'base_path': '/schemas/members',
'requires_id': False})
self._verify(
"openstack.proxy.Proxy._get",
self.proxy.get_members_schema,
expected_args=[schema.Schema],
expected_kwargs={
'base_path': '/schemas/members', 'requires_id': False})
def test_member_schema_get(self):
self._verify2("openstack.proxy.Proxy._get",
self.proxy.get_member_schema,
expected_args=[schema.Schema],
expected_kwargs={'base_path': '/schemas/member',
'requires_id': False})
self._verify(
"openstack.proxy.Proxy._get",
self.proxy.get_member_schema,
expected_args=[schema.Schema],
expected_kwargs={
'base_path': '/schemas/member', 'requires_id': False})
def test_task_get(self):
self.verify_get(self.proxy.get_task, task.Task)
@ -477,26 +495,29 @@ class TestImageProxy(test_proxy_base.TestProxyBase):
self.assertEqual('success', result.status)
def test_tasks_schema_get(self):
self._verify2("openstack.proxy.Proxy._get",
self.proxy.get_tasks_schema,
expected_args=[schema.Schema],
expected_kwargs={'base_path': '/schemas/tasks',
'requires_id': False})
self._verify(
"openstack.proxy.Proxy._get",
self.proxy.get_tasks_schema,
expected_args=[schema.Schema],
expected_kwargs={
'base_path': '/schemas/tasks', 'requires_id': False})
def test_task_schema_get(self):
self._verify2("openstack.proxy.Proxy._get",
self.proxy.get_task_schema,
expected_args=[schema.Schema],
expected_kwargs={'base_path': '/schemas/task',
'requires_id': False})
self._verify(
"openstack.proxy.Proxy._get",
self.proxy.get_task_schema,
expected_args=[schema.Schema],
expected_kwargs={
'base_path': '/schemas/task', 'requires_id': False})
def test_stores(self):
self.verify_list(self.proxy.stores, si.Store)
def test_import_info(self):
self._verify2("openstack.proxy.Proxy._get",
self.proxy.get_import_info,
method_args=[],
method_kwargs={},
expected_args=[si.Import],
expected_kwargs={'require_id': False})
self._verify(
"openstack.proxy.Proxy._get",
self.proxy.get_import_info,
method_args=[],
method_kwargs={},
expected_args=[si.Import],
expected_kwargs={'require_id': False})

View File

@ -31,12 +31,13 @@ class TestInstanceHaProxy(test_proxy_base.TestProxyBase):
self.verify_list(self.proxy.hosts,
host.Host,
method_args=[SEGMENT_ID],
expected_args=[],
expected_kwargs={"segment_id": SEGMENT_ID})
def test_host_get(self):
self.verify_get(self.proxy.get_host,
host.Host,
value=[HOST_ID],
method_args=[HOST_ID],
method_kwargs={"segment_id": SEGMENT_ID},
expected_kwargs={"segment_id": SEGMENT_ID})
@ -45,6 +46,7 @@ class TestInstanceHaProxy(test_proxy_base.TestProxyBase):
host.Host,
method_args=[SEGMENT_ID],
method_kwargs={},
expected_args=[],
expected_kwargs={"segment_id": SEGMENT_ID})
def test_host_update(self):

View File

@ -56,8 +56,8 @@ class TestLoadBalancerProxy(test_proxy_base.TestProxyBase):
def test_load_balancer_stats_get(self):
self.verify_get(self.proxy.get_load_balancer_statistics,
lb.LoadBalancerStats,
value=[self.LB_ID],
expected_args=[lb.LoadBalancerStats],
method_args=[self.LB_ID],
expected_args=[],
expected_kwargs={'lb_id': self.LB_ID,
'requires_id': False})
@ -70,13 +70,12 @@ class TestLoadBalancerProxy(test_proxy_base.TestProxyBase):
fake_load_balancer = mock.Mock()
fake_load_balancer.id = "load_balancer_id"
mock_get_resource.return_value = fake_load_balancer
self._verify2("openstack.proxy.Proxy._delete",
self.proxy.delete_load_balancer,
method_args=["resource_or_id", True,
False],
expected_args=[lb.LoadBalancer,
fake_load_balancer],
expected_kwargs={"ignore_missing": True})
self._verify(
"openstack.proxy.Proxy._delete",
self.proxy.delete_load_balancer,
method_args=["resource_or_id", True, False],
expected_args=[lb.LoadBalancer, fake_load_balancer],
expected_kwargs={"ignore_missing": True})
self.assertFalse(fake_load_balancer.cascade)
mock_get_resource.assert_called_once_with(lb.LoadBalancer,
"resource_or_id")
@ -86,13 +85,12 @@ class TestLoadBalancerProxy(test_proxy_base.TestProxyBase):
fake_load_balancer = mock.Mock()
fake_load_balancer.id = "load_balancer_id"
mock_get_resource.return_value = fake_load_balancer
self._verify2("openstack.proxy.Proxy._delete",
self.proxy.delete_load_balancer,
method_args=["resource_or_id", True,
True],
expected_args=[lb.LoadBalancer,
fake_load_balancer],
expected_kwargs={"ignore_missing": True})
self._verify(
"openstack.proxy.Proxy._delete",
self.proxy.delete_load_balancer,
method_args=["resource_or_id", True, True],
expected_args=[lb.LoadBalancer, fake_load_balancer],
expected_kwargs={"ignore_missing": True})
self.assertTrue(fake_load_balancer.cascade)
mock_get_resource.assert_called_once_with(lb.LoadBalancer,
"resource_or_id")
@ -108,7 +106,7 @@ class TestLoadBalancerProxy(test_proxy_base.TestProxyBase):
def test_load_balancer_failover(self):
self.verify_update(self.proxy.failover_load_balancer,
lb.LoadBalancerFailover,
value=[self.LB_ID],
method_args=[self.LB_ID],
expected_args=[],
expected_kwargs={'lb_id': self.LB_ID})
@ -123,8 +121,8 @@ class TestLoadBalancerProxy(test_proxy_base.TestProxyBase):
def test_listener_stats_get(self):
self.verify_get(self.proxy.get_listener_statistics,
listener.ListenerStats,
value=[self.LISTENER_ID],
expected_args=[listener.ListenerStats],
method_args=[self.LISTENER_ID],
expected_args=[],
expected_kwargs={'listener_id': self.LISTENER_ID,
'requires_id': False})
@ -189,24 +187,27 @@ class TestLoadBalancerProxy(test_proxy_base.TestProxyBase):
def test_member_delete(self):
self.verify_delete(self.proxy.delete_member,
member.Member,
True,
ignore_missing=True,
method_kwargs={'pool': self.POOL_ID},
expected_kwargs={'pool_id': self.POOL_ID})
expected_kwargs={
'pool_id': self.POOL_ID,
'ignore_missing': True})
def test_member_find(self):
self._verify2('openstack.proxy.Proxy._find',
self.proxy.find_member,
method_args=["MEMBER", self.POOL_ID],
expected_args=[member.Member, "MEMBER"],
expected_kwargs={"pool_id": self.POOL_ID,
"ignore_missing": True})
self._verify(
'openstack.proxy.Proxy._find',
self.proxy.find_member,
method_args=["MEMBER", self.POOL_ID],
expected_args=[member.Member, "MEMBER"],
expected_kwargs={"pool_id": self.POOL_ID, "ignore_missing": True})
def test_member_update(self):
self._verify2('openstack.proxy.Proxy._update',
self.proxy.update_member,
method_args=["MEMBER", self.POOL_ID],
expected_args=[member.Member, "MEMBER"],
expected_kwargs={"pool_id": self.POOL_ID})
self._verify(
'openstack.proxy.Proxy._update',
self.proxy.update_member,
method_args=["MEMBER", self.POOL_ID],
expected_args=[member.Member, "MEMBER"],
expected_kwargs={"pool_id": self.POOL_ID})
def test_health_monitors(self):
self.verify_list(self.proxy.health_monitors,
@ -277,24 +278,26 @@ class TestLoadBalancerProxy(test_proxy_base.TestProxyBase):
def test_l7_rule_delete(self):
self.verify_delete(self.proxy.delete_l7_rule,
l7_rule.L7Rule,
True,
ignore_missing=True,
method_kwargs={'l7_policy': self.L7_POLICY_ID},
expected_kwargs={'l7policy_id': self.L7_POLICY_ID})
def test_l7_rule_find(self):
self._verify2('openstack.proxy.Proxy._find',
self.proxy.find_l7_rule,
method_args=["RULE", self.L7_POLICY_ID],
expected_args=[l7_rule.L7Rule, "RULE"],
expected_kwargs={"l7policy_id": self.L7_POLICY_ID,
"ignore_missing": True})
self._verify(
'openstack.proxy.Proxy._find',
self.proxy.find_l7_rule,
method_args=["RULE", self.L7_POLICY_ID],
expected_args=[l7_rule.L7Rule, "RULE"],
expected_kwargs={
"l7policy_id": self.L7_POLICY_ID, "ignore_missing": True})
def test_l7_rule_update(self):
self._verify2('openstack.proxy.Proxy._update',
self.proxy.update_l7_rule,
method_args=["RULE", self.L7_POLICY_ID],
expected_args=[l7_rule.L7Rule, "RULE"],
expected_kwargs={"l7policy_id": self.L7_POLICY_ID})
self._verify(
'openstack.proxy.Proxy._update',
self.proxy.update_l7_rule,
method_args=["RULE", self.L7_POLICY_ID],
expected_args=[l7_rule.L7Rule, "RULE"],
expected_kwargs={"l7policy_id": self.L7_POLICY_ID})
def test_quotas(self):
self.verify_list(self.proxy.quotas, quota.Quota)
@ -306,10 +309,11 @@ class TestLoadBalancerProxy(test_proxy_base.TestProxyBase):
self.verify_update(self.proxy.update_quota, quota.Quota)
def test_quota_default_get(self):
self._verify2("openstack.proxy.Proxy._get",
self.proxy.get_quota_default,
expected_args=[quota.QuotaDefault],
expected_kwargs={'requires_id': False})
self._verify(
"openstack.proxy.Proxy._get",
self.proxy.get_quota_default,
expected_args=[quota.QuotaDefault],
expected_kwargs={'requires_id': False})
def test_quota_delete(self):
self.verify_delete(self.proxy.delete_quota, quota.Quota, False)
@ -324,6 +328,7 @@ class TestLoadBalancerProxy(test_proxy_base.TestProxyBase):
self.verify_list(self.proxy.provider_flavor_capabilities,
provider.ProviderFlavorCapabilities,
method_args=[self.AMPHORA],
expected_args=[],
expected_kwargs={'provider': self.AMPHORA})
def test_flavor_profiles(self):
@ -380,14 +385,14 @@ class TestLoadBalancerProxy(test_proxy_base.TestProxyBase):
def test_amphora_configure(self):
self.verify_update(self.proxy.configure_amphora,
amphora.AmphoraConfig,
value=[self.AMPHORA_ID],
method_args=[self.AMPHORA_ID],
expected_args=[],
expected_kwargs={'amphora_id': self.AMPHORA_ID})
def test_amphora_failover(self):
self.verify_update(self.proxy.failover_amphora,
amphora.AmphoraFailover,
value=[self.AMPHORA_ID],
method_args=[self.AMPHORA_ID],
expected_args=[],
expected_kwargs={'amphora_id': self.AMPHORA_ID})

View File

@ -50,20 +50,22 @@ class TestMessageProxy(test_proxy_base.TestProxyBase):
def test_message_post(self, mock_get_resource):
message_obj = message.Message(queue_name="test_queue")
mock_get_resource.return_value = message_obj
self._verify("openstack.message.v2.message.Message.post",
self.proxy.post_message,
method_args=["test_queue", ["msg1", "msg2"]],
expected_args=[["msg1", "msg2"]])
self._verify(
"openstack.message.v2.message.Message.post",
self.proxy.post_message,
method_args=["test_queue", ["msg1", "msg2"]],
expected_args=[self.proxy, ["msg1", "msg2"]])
mock_get_resource.assert_called_once_with(message.Message, None,
queue_name="test_queue")
@mock.patch.object(proxy_base.Proxy, '_get_resource')
def test_message_get(self, mock_get_resource):
mock_get_resource.return_value = "resource_or_id"
self._verify2("openstack.proxy.Proxy._get",
self.proxy.get_message,
method_args=["test_queue", "resource_or_id"],
expected_args=[message.Message, "resource_or_id"])
self._verify(
"openstack.proxy.Proxy._get",
self.proxy.get_message,
method_args=["test_queue", "resource_or_id"],
expected_args=[message.Message, "resource_or_id"])
mock_get_resource.assert_called_once_with(message.Message,
"resource_or_id",
queue_name="test_queue")
@ -73,7 +75,7 @@ class TestMessageProxy(test_proxy_base.TestProxyBase):
def test_messages(self):
self.verify_list(self.proxy.messages, message.Message,
method_args=["test_queue"],
method_kwargs={"queue_name": "test_queue"},
expected_kwargs={"queue_name": "test_queue"})
@mock.patch.object(proxy_base.Proxy, '_get_resource')
@ -81,13 +83,12 @@ class TestMessageProxy(test_proxy_base.TestProxyBase):
fake_message = mock.Mock()
fake_message.id = "message_id"
mock_get_resource.return_value = fake_message
self._verify2("openstack.proxy.Proxy._delete",
self.proxy.delete_message,
method_args=["test_queue", "resource_or_id", None,
False],
expected_args=[message.Message,
fake_message],
expected_kwargs={"ignore_missing": False})
self._verify(
"openstack.proxy.Proxy._delete",
self.proxy.delete_message,
method_args=["test_queue", "resource_or_id", None, False],
expected_args=[message.Message, fake_message],
expected_kwargs={"ignore_missing": False})
self.assertIsNone(fake_message.claim_id)
mock_get_resource.assert_called_once_with(message.Message,
"resource_or_id",
@ -98,13 +99,12 @@ class TestMessageProxy(test_proxy_base.TestProxyBase):
fake_message = mock.Mock()
fake_message.id = "message_id"
mock_get_resource.return_value = fake_message
self._verify2("openstack.proxy.Proxy._delete",
self.proxy.delete_message,
method_args=["test_queue", "resource_or_id", "claim_id",
False],
expected_args=[message.Message,
fake_message],
expected_kwargs={"ignore_missing": False})
self._verify(
"openstack.proxy.Proxy._delete",
self.proxy.delete_message,
method_args=["test_queue", "resource_or_id", "claim_id", False],
expected_args=[message.Message, fake_message],
expected_kwargs={"ignore_missing": False})
self.assertEqual("claim_id", fake_message.claim_id)
mock_get_resource.assert_called_once_with(message.Message,
"resource_or_id",
@ -115,32 +115,33 @@ class TestMessageProxy(test_proxy_base.TestProxyBase):
fake_message = mock.Mock()
fake_message.id = "message_id"
mock_get_resource.return_value = fake_message
self._verify2("openstack.proxy.Proxy._delete",
self.proxy.delete_message,
method_args=["test_queue", "resource_or_id", None,
True],
expected_args=[message.Message,
fake_message],
expected_kwargs={"ignore_missing": True})
self._verify(
"openstack.proxy.Proxy._delete",
self.proxy.delete_message,
method_args=["test_queue", "resource_or_id", None, True],
expected_args=[message.Message, fake_message],
expected_kwargs={"ignore_missing": True})
self.assertIsNone(fake_message.claim_id)
mock_get_resource.assert_called_once_with(message.Message,
"resource_or_id",
queue_name="test_queue")
def test_subscription_create(self):
self._verify("openstack.message.v2.subscription.Subscription.create",
self.proxy.create_subscription,
method_args=["test_queue"],
expected_kwargs={"base_path": None})
self._verify(
"openstack.message.v2.subscription.Subscription.create",
self.proxy.create_subscription,
method_args=["test_queue"],
expected_args=[self.proxy],
expected_kwargs={"base_path": None})
@mock.patch.object(proxy_base.Proxy, '_get_resource')
def test_subscription_get(self, mock_get_resource):
mock_get_resource.return_value = "resource_or_id"
self._verify2("openstack.proxy.Proxy._get",
self.proxy.get_subscription,
method_args=["test_queue", "resource_or_id"],
expected_args=[subscription.Subscription,
"resource_or_id"])
self._verify(
"openstack.proxy.Proxy._get",
self.proxy.get_subscription,
method_args=["test_queue", "resource_or_id"],
expected_args=[subscription.Subscription, "resource_or_id"])
mock_get_resource.assert_called_once_with(
subscription.Subscription, "resource_or_id",
queue_name="test_queue")
@ -150,64 +151,78 @@ class TestMessageProxy(test_proxy_base.TestProxyBase):
def test_subscriptions(self):
self.verify_list(self.proxy.subscriptions, subscription.Subscription,
method_args=["test_queue"],
method_kwargs={"queue_name": "test_queue"},
expected_kwargs={"queue_name": "test_queue"})
@mock.patch.object(proxy_base.Proxy, '_get_resource')
def test_subscription_delete(self, mock_get_resource):
mock_get_resource.return_value = "resource_or_id"
mock_get_resource.return_value = "test_subscription"
self.verify_delete(self.proxy.delete_subscription,
subscription.Subscription, False,
["test_queue", "resource_or_id"])
subscription.Subscription,
ignore_missing=False,
method_args=["test_queue", "resource_or_id"],
expected_args=["test_subscription"])
mock_get_resource.assert_called_once_with(
subscription.Subscription, "resource_or_id",
queue_name="test_queue")
@mock.patch.object(proxy_base.Proxy, '_get_resource')
def test_subscription_delete_ignore(self, mock_get_resource):
mock_get_resource.return_value = "resource_or_id"
mock_get_resource.return_value = "test_subscription"
self.verify_delete(self.proxy.delete_subscription,
subscription.Subscription, True,
["test_queue", "resource_or_id"])
subscription.Subscription,
ignore_missing=True,
method_args=["test_queue", "resource_or_id"],
expected_args=["test_subscription"])
mock_get_resource.assert_called_once_with(
subscription.Subscription, "resource_or_id",
queue_name="test_queue")
def test_claim_create(self):
self._verify("openstack.message.v2.claim.Claim.create",
self.proxy.create_claim,
method_args=["test_queue"],
expected_kwargs={"base_path": None})
self._verify(
"openstack.message.v2.claim.Claim.create",
self.proxy.create_claim,
method_args=["test_queue"],
expected_args=[self.proxy],
expected_kwargs={"base_path": None})
def test_claim_get(self):
self._verify2("openstack.proxy.Proxy._get",
self.proxy.get_claim,
method_args=["test_queue", "resource_or_id"],
expected_args=[claim.Claim,
"resource_or_id"],
expected_kwargs={"queue_name": "test_queue"})
self._verify(
"openstack.proxy.Proxy._get",
self.proxy.get_claim,
method_args=["test_queue", "resource_or_id"],
expected_args=[claim.Claim, "resource_or_id"],
expected_kwargs={"queue_name": "test_queue"})
self.verify_get_overrided(
self.proxy, claim.Claim,
'openstack.message.v2.claim.Claim')
def test_claim_update(self):
self._verify2("openstack.proxy.Proxy._update",
self.proxy.update_claim,
method_args=["test_queue", "resource_or_id"],
method_kwargs={"k1": "v1"},
expected_args=[claim.Claim,
"resource_or_id"],
expected_kwargs={"queue_name": "test_queue",
"k1": "v1"})
self._verify(
"openstack.proxy.Proxy._update",
self.proxy.update_claim,
method_args=["test_queue", "resource_or_id"],
method_kwargs={"k1": "v1"},
expected_args=[claim.Claim, "resource_or_id"],
expected_kwargs={"queue_name": "test_queue", "k1": "v1"})
def test_claim_delete(self):
self.verify_delete(self.proxy.delete_claim,
claim.Claim, False,
["test_queue", "resource_or_id"],
expected_kwargs={"queue_name": "test_queue"})
claim.Claim,
ignore_missing=False,
method_args=["test_queue", "test_claim"],
expected_args=["test_claim"],
expected_kwargs={
"queue_name": "test_queue",
"ignore_missing": False})
def test_claim_delete_ignore(self):
self.verify_delete(self.proxy.delete_claim,
claim.Claim, True,
["test_queue", "resource_or_id"],
expected_kwargs={"queue_name": "test_queue"})
self.verify_delete(
self.proxy.delete_claim,
claim.Claim,
ignore_missing=True,
method_args=["test_queue", "test_claim"],
expected_args=["test_claim"],
expected_kwargs={
"queue_name": "test_queue", "ignore_missing": True,
})

View File

@ -0,0 +1,80 @@
# 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.
from openstack.network.v2 import ipsec_site_connection
from openstack.tests.unit import base
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {
"admin_state_up": True,
"auth_mode": "1",
"ikepolicy_id": "2",
"vpnservice_id": "3",
"local_ep_group_id": "4",
"peer_address": "5",
"route_mode": "6",
"ipsecpolicy_id": "7",
"peer_id": "8",
"psk": "9",
"description": "10",
"initiator": "11",
"peer_cidrs": ['1', '2'],
"name": "12",
"tenant_id": "13",
"interval": 5,
"mtu": 5,
"peer_ep_group_id": "14",
"dpd": {'a': 5},
"timeout": 16,
"action": "17",
"local_id": "18"
}
class TestIPSecSiteConnection(base.TestCase):
def test_basic(self):
sot = ipsec_site_connection.IPSecSiteConnection()
self.assertEqual('ipsec_site_connection', sot.resource_key)
self.assertEqual('ipsec_site_connections', sot.resources_key)
self.assertEqual('/vpn/ipsec-site-connections', sot.base_path)
self.assertTrue(sot.allow_create)
self.assertTrue(sot.allow_fetch)
self.assertTrue(sot.allow_commit)
self.assertTrue(sot.allow_delete)
self.assertTrue(sot.allow_list)
def test_make_it(self):
sot = ipsec_site_connection.IPSecSiteConnection(**EXAMPLE)
self.assertTrue(sot.is_admin_state_up)
self.assertEqual(EXAMPLE['auth_mode'], sot.auth_mode)
self.assertEqual(EXAMPLE['ikepolicy_id'], sot.ikepolicy_id)
self.assertEqual(EXAMPLE['vpnservice_id'], sot.vpnservice_id)
self.assertEqual(EXAMPLE['local_ep_group_id'], sot.local_ep_group_id)
self.assertEqual(EXAMPLE['peer_address'], sot.peer_address)
self.assertEqual(EXAMPLE['route_mode'], sot.route_mode)
self.assertEqual(EXAMPLE['ipsecpolicy_id'], sot.ipsecpolicy_id)
self.assertEqual(EXAMPLE['peer_id'], sot.peer_id)
self.assertEqual(EXAMPLE['psk'], sot.psk)
self.assertEqual(EXAMPLE['description'], sot.description)
self.assertEqual(EXAMPLE['initiator'], sot.initiator)
self.assertEqual(EXAMPLE['peer_cidrs'], sot.peer_cidrs)
self.assertEqual(EXAMPLE['name'], sot.name)
self.assertEqual(EXAMPLE['tenant_id'], sot.project_id)
self.assertEqual(EXAMPLE['interval'], sot.interval)
self.assertEqual(EXAMPLE['mtu'], sot.mtu)
self.assertEqual(EXAMPLE['peer_ep_group_id'], sot.peer_ep_group_id)
self.assertEqual(EXAMPLE['dpd'], sot.dpd)
self.assertEqual(EXAMPLE['timeout'], sot.timeout)
self.assertEqual(EXAMPLE['action'], sot.action)
self.assertEqual(EXAMPLE['local_id'], sot.local_id)

View File

@ -26,6 +26,7 @@ from openstack.network.v2 import firewall_rule
from openstack.network.v2 import flavor
from openstack.network.v2 import floating_ip
from openstack.network.v2 import health_monitor
from openstack.network.v2 import ipsec_site_connection
from openstack.network.v2 import l3_conntrack_helper
from openstack.network.v2 import listener
from openstack.network.v2 import load_balancer
@ -72,23 +73,37 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
super(TestNetworkProxy, self).setUp()
self.proxy = _proxy.Proxy(self.session)
def verify_update(self, test_method, resource_type, value=None,
mock_method="openstack.network.v2._proxy.Proxy._update",
expected_result="result", path_args=None, **kwargs):
super(TestNetworkProxy, self).verify_update(
test_method, resource_type, value=value, mock_method=mock_method,
expected_result=expected_result, path_args=path_args, **kwargs)
def verify_update(
self, test_method, resource_type, base_path=None, *,
method_args=None, method_kwargs=None,
expected_args=None, expected_kwargs=None, expected_result="result",
mock_method="openstack.network.v2._proxy.Proxy._update",
):
super().verify_update(
test_method,
resource_type,
base_path=base_path,
method_args=method_args,
method_kwargs=method_kwargs,
expected_args=expected_args,
expected_kwargs=expected_kwargs,
expected_result=expected_result,
mock_method=mock_method)
def verify_delete(self, test_method, resource_type, ignore,
input_path_args=None, expected_path_args=None,
method_kwargs=None, expected_args=None,
expected_kwargs=None,
mock_method="openstack.network.v2._proxy.Proxy._delete"):
super(TestNetworkProxy, self).verify_delete(
test_method, resource_type, ignore,
input_path_args=input_path_args,
expected_path_args=expected_path_args, method_kwargs=method_kwargs,
expected_args=expected_args, expected_kwargs=expected_kwargs,
def verify_delete(
self, test_method, resource_type, ignore_missing=True, *,
method_args=None, method_kwargs=None,
expected_args=None, expected_kwargs=None,
mock_method="openstack.network.v2._proxy.Proxy._delete",
):
super().verify_delete(
test_method,
resource_type,
ignore_missing=ignore_missing,
method_args=method_args,
method_kwargs=method_kwargs,
expected_args=expected_args,
expected_kwargs=expected_kwargs,
mock_method=mock_method)
def test_address_scope_create_attrs(self):
@ -134,8 +149,9 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
self.verify_update(self.proxy.update_agent, agent.Agent)
def test_availability_zones(self):
self.verify_list_no_kwargs(self.proxy.availability_zones,
availability_zone.AvailabilityZone)
self.verify_list(
self.proxy.availability_zones,
availability_zone.AvailabilityZone)
def test_dhcp_agent_hosting_networks(self):
self.verify_list(
@ -224,6 +240,34 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
self.verify_update(self.proxy.update_health_monitor,
health_monitor.HealthMonitor)
def test_ipsec_site_connection_create_attrs(self):
self.verify_create(self.proxy.create_vpn_ipsec_site_connection,
ipsec_site_connection.IPSecSiteConnection)
def test_ipsec_site_connection_delete(self):
self.verify_delete(self.proxy.delete_vpn_ipsec_site_connection,
ipsec_site_connection.IPSecSiteConnection, False)
def test_ipsec_site_connection_delete_ignore(self):
self.verify_delete(self.proxy.delete_vpn_ipsec_site_connection,
ipsec_site_connection.IPSecSiteConnection, True)
def test_ipsec_site_connection_find(self):
self.verify_find(self.proxy.find_vpn_ipsec_site_connection,
ipsec_site_connection.IPSecSiteConnection)
def test_ipsec_site_connection_get(self):
self.verify_get(self.proxy.get_vpn_ipsec_site_connection,
ipsec_site_connection.IPSecSiteConnection)
def test_ipsec_site_connections(self):
self.verify_list(self.proxy.vpn_ipsec_site_connections,
ipsec_site_connection.IPSecSiteConnection)
def test_ipsec_site_connection_update(self):
self.verify_update(self.proxy.update_vpn_ipsec_site_connection,
ipsec_site_connection.IPSecSiteConnection)
def test_listener_create_attrs(self):
self.verify_create(self.proxy.create_listener, listener.Listener)
@ -351,13 +395,13 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
self.verify_find(self.proxy.find_network, network.Network)
def test_network_find_with_filter(self):
self._verify2('openstack.proxy.Proxy._find',
self.proxy.find_network,
method_args=["net1"],
method_kwargs={"project_id": "1"},
expected_args=[network.Network, "net1"],
expected_kwargs={"project_id": "1",
"ignore_missing": True})
self._verify(
'openstack.proxy.Proxy._find',
self.proxy.find_network,
method_args=["net1"],
method_kwargs={"project_id": "1"},
expected_args=[network.Network, "net1"],
expected_kwargs={"project_id": "1", "ignore_missing": True})
def test_network_get(self):
self.verify_get(self.proxy.get_network, network.Network)
@ -438,41 +482,51 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
expected_kwargs={"pool_id": "test_id"})
def test_pool_member_delete(self):
self.verify_delete(self.proxy.delete_pool_member,
pool_member.PoolMember, False,
{"pool": "test_id"}, {"pool_id": "test_id"})
self.verify_delete(
self.proxy.delete_pool_member,
pool_member.PoolMember,
ignore_missing=False,
method_kwargs={"pool": "test_id"},
expected_kwargs={"pool_id": "test_id"})
def test_pool_member_delete_ignore(self):
self.verify_delete(self.proxy.delete_pool_member,
pool_member.PoolMember, True,
{"pool": "test_id"}, {"pool_id": "test_id"})
self.verify_delete(
self.proxy.delete_pool_member,
pool_member.PoolMember,
ignore_missing=True,
method_kwargs={"pool": "test_id"},
expected_kwargs={"pool_id": "test_id"})
def test_pool_member_find(self):
self._verify2('openstack.proxy.Proxy._find',
self.proxy.find_pool_member,
method_args=["MEMBER", "POOL"],
expected_args=[pool_member.PoolMember, "MEMBER"],
expected_kwargs={"pool_id": "POOL",
"ignore_missing": True})
self._verify(
'openstack.proxy.Proxy._find',
self.proxy.find_pool_member,
method_args=["MEMBER", "POOL"],
expected_args=[pool_member.PoolMember, "MEMBER"],
expected_kwargs={"pool_id": "POOL", "ignore_missing": True})
def test_pool_member_get(self):
self._verify2('openstack.proxy.Proxy._get',
self.proxy.get_pool_member,
method_args=["MEMBER", "POOL"],
expected_args=[pool_member.PoolMember, "MEMBER"],
expected_kwargs={"pool_id": "POOL"})
self._verify(
'openstack.proxy.Proxy._get',
self.proxy.get_pool_member,
method_args=["MEMBER", "POOL"],
expected_args=[pool_member.PoolMember, "MEMBER"],
expected_kwargs={"pool_id": "POOL"})
def test_pool_members(self):
self.verify_list(self.proxy.pool_members, pool_member.PoolMember,
method_args=["test_id"],
expected_kwargs={"pool_id": "test_id"})
self.verify_list(
self.proxy.pool_members, pool_member.PoolMember,
method_args=["test_id"],
expected_args=[],
expected_kwargs={"pool_id": "test_id"})
def test_pool_member_update(self):
self._verify2("openstack.network.v2._proxy.Proxy._update",
self.proxy.update_pool_member,
method_args=["MEMBER", "POOL"],
expected_args=[pool_member.PoolMember, "MEMBER"],
expected_kwargs={"pool_id": "POOL"})
self._verify(
"openstack.network.v2._proxy.Proxy._update",
self.proxy.update_pool_member,
method_args=["MEMBER", "POOL"],
expected_args=[pool_member.PoolMember, "MEMBER"],
expected_kwargs={"pool_id": "POOL"})
def test_pool_create_attrs(self):
self.verify_create(self.proxy.create_pool, pool.Pool)
@ -551,26 +605,31 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
self.verify_delete(
self.proxy.delete_qos_bandwidth_limit_rule,
qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
False, input_path_args=["resource_or_id", QOS_POLICY_ID],
ignore_missing=False,
method_args=["resource_or_id", QOS_POLICY_ID],
expected_args=["resource_or_id"],
expected_kwargs={'qos_policy_id': QOS_POLICY_ID})
def test_qos_bandwidth_limit_rule_delete_ignore(self):
self.verify_delete(
self.proxy.delete_qos_bandwidth_limit_rule,
qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
True, input_path_args=["resource_or_id", QOS_POLICY_ID],
ignore_missing=True,
method_args=["resource_or_id", QOS_POLICY_ID],
expected_args=["resource_or_id"],
expected_kwargs={'qos_policy_id': QOS_POLICY_ID})
def test_qos_bandwidth_limit_rule_find(self):
policy = qos_policy.QoSPolicy.new(id=QOS_POLICY_ID)
self._verify2('openstack.proxy.Proxy._find',
self.proxy.find_qos_bandwidth_limit_rule,
method_args=['rule_id', policy],
expected_args=[
qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
'rule_id'],
expected_kwargs={'ignore_missing': True,
'qos_policy_id': QOS_POLICY_ID})
self._verify(
'openstack.proxy.Proxy._find',
self.proxy.find_qos_bandwidth_limit_rule,
method_args=['rule_id', policy],
expected_args=[
qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
'rule_id'],
expected_kwargs={
'ignore_missing': True, 'qos_policy_id': QOS_POLICY_ID})
def test_qos_bandwidth_limit_rule_get(self):
self.verify_get(
@ -588,15 +647,15 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
def test_qos_bandwidth_limit_rule_update(self):
policy = qos_policy.QoSPolicy.new(id=QOS_POLICY_ID)
self._verify2('openstack.network.v2._proxy.Proxy._update',
self.proxy.update_qos_bandwidth_limit_rule,
method_args=['rule_id', policy],
method_kwargs={'foo': 'bar'},
expected_args=[
qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
'rule_id'],
expected_kwargs={'qos_policy_id': QOS_POLICY_ID,
'foo': 'bar'})
self._verify(
'openstack.network.v2._proxy.Proxy._update',
self.proxy.update_qos_bandwidth_limit_rule,
method_args=['rule_id', policy],
method_kwargs={'foo': 'bar'},
expected_args=[
qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
'rule_id'],
expected_kwargs={'qos_policy_id': QOS_POLICY_ID, 'foo': 'bar'})
def test_qos_dscp_marking_rule_create_attrs(self):
self.verify_create(
@ -609,25 +668,30 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
self.verify_delete(
self.proxy.delete_qos_dscp_marking_rule,
qos_dscp_marking_rule.QoSDSCPMarkingRule,
False, input_path_args=["resource_or_id", QOS_POLICY_ID],
expected_path_args={'qos_policy_id': QOS_POLICY_ID},)
ignore_missing=False,
method_args=["resource_or_id", QOS_POLICY_ID],
expected_args=["resource_or_id"],
expected_kwargs={'qos_policy_id': QOS_POLICY_ID})
def test_qos_dscp_marking_rule_delete_ignore(self):
self.verify_delete(
self.proxy.delete_qos_dscp_marking_rule,
qos_dscp_marking_rule.QoSDSCPMarkingRule,
True, input_path_args=["resource_or_id", QOS_POLICY_ID],
expected_path_args={'qos_policy_id': QOS_POLICY_ID}, )
ignore_missing=True,
method_args=["resource_or_id", QOS_POLICY_ID],
expected_args=["resource_or_id"],
expected_kwargs={'qos_policy_id': QOS_POLICY_ID}, )
def test_qos_dscp_marking_rule_find(self):
policy = qos_policy.QoSPolicy.new(id=QOS_POLICY_ID)
self._verify2('openstack.proxy.Proxy._find',
self.proxy.find_qos_dscp_marking_rule,
method_args=['rule_id', policy],
expected_args=[qos_dscp_marking_rule.QoSDSCPMarkingRule,
'rule_id'],
expected_kwargs={'ignore_missing': True,
'qos_policy_id': QOS_POLICY_ID})
self._verify(
'openstack.proxy.Proxy._find',
self.proxy.find_qos_dscp_marking_rule,
method_args=['rule_id', policy],
expected_args=[
qos_dscp_marking_rule.QoSDSCPMarkingRule, 'rule_id'],
expected_kwargs={
'ignore_missing': True, 'qos_policy_id': QOS_POLICY_ID})
def test_qos_dscp_marking_rule_get(self):
self.verify_get(
@ -645,15 +709,15 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
def test_qos_dscp_marking_rule_update(self):
policy = qos_policy.QoSPolicy.new(id=QOS_POLICY_ID)
self._verify2('openstack.network.v2._proxy.Proxy._update',
self.proxy.update_qos_dscp_marking_rule,
method_args=['rule_id', policy],
method_kwargs={'foo': 'bar'},
expected_args=[
qos_dscp_marking_rule.QoSDSCPMarkingRule,
'rule_id'],
expected_kwargs={'qos_policy_id': QOS_POLICY_ID,
'foo': 'bar'})
self._verify(
'openstack.network.v2._proxy.Proxy._update',
self.proxy.update_qos_dscp_marking_rule,
method_args=['rule_id', policy],
method_kwargs={'foo': 'bar'},
expected_args=[
qos_dscp_marking_rule.QoSDSCPMarkingRule,
'rule_id'],
expected_kwargs={'qos_policy_id': QOS_POLICY_ID, 'foo': 'bar'})
def test_qos_minimum_bandwidth_rule_create_attrs(self):
self.verify_create(
@ -666,26 +730,31 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
self.verify_delete(
self.proxy.delete_qos_minimum_bandwidth_rule,
qos_minimum_bandwidth_rule.QoSMinimumBandwidthRule,
False, input_path_args=["resource_or_id", QOS_POLICY_ID],
expected_path_args={'qos_policy_id': QOS_POLICY_ID},)
ignore_missing=False,
method_args=["resource_or_id", QOS_POLICY_ID],
expected_args=["resource_or_id"],
expected_kwargs={'qos_policy_id': QOS_POLICY_ID})
def test_qos_minimum_bandwidth_rule_delete_ignore(self):
self.verify_delete(
self.proxy.delete_qos_minimum_bandwidth_rule,
qos_minimum_bandwidth_rule.QoSMinimumBandwidthRule,
True, input_path_args=["resource_or_id", QOS_POLICY_ID],
expected_path_args={'qos_policy_id': QOS_POLICY_ID}, )
ignore_missing=True,
method_args=["resource_or_id", QOS_POLICY_ID],
expected_args=["resource_or_id"],
expected_kwargs={'qos_policy_id': QOS_POLICY_ID})
def test_qos_minimum_bandwidth_rule_find(self):
policy = qos_policy.QoSPolicy.new(id=QOS_POLICY_ID)
self._verify2('openstack.proxy.Proxy._find',
self.proxy.find_qos_minimum_bandwidth_rule,
method_args=['rule_id', policy],
expected_args=[
qos_minimum_bandwidth_rule.QoSMinimumBandwidthRule,
'rule_id'],
expected_kwargs={'ignore_missing': True,
'qos_policy_id': QOS_POLICY_ID})
self._verify(
'openstack.proxy.Proxy._find',
self.proxy.find_qos_minimum_bandwidth_rule,
method_args=['rule_id', policy],
expected_args=[
qos_minimum_bandwidth_rule.QoSMinimumBandwidthRule,
'rule_id'],
expected_kwargs={
'ignore_missing': True, 'qos_policy_id': QOS_POLICY_ID})
def test_qos_minimum_bandwidth_rule_get(self):
self.verify_get(
@ -703,15 +772,16 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
def test_qos_minimum_bandwidth_rule_update(self):
policy = qos_policy.QoSPolicy.new(id=QOS_POLICY_ID)
self._verify2('openstack.network.v2._proxy.Proxy._update',
self.proxy.update_qos_minimum_bandwidth_rule,
method_args=['rule_id', policy],
method_kwargs={'foo': 'bar'},
expected_args=[
qos_minimum_bandwidth_rule.QoSMinimumBandwidthRule,
'rule_id'],
expected_kwargs={'qos_policy_id': QOS_POLICY_ID,
'foo': 'bar'})
self._verify(
'openstack.network.v2._proxy.Proxy._update',
self.proxy.update_qos_minimum_bandwidth_rule,
method_args=['rule_id', policy],
method_kwargs={'foo': 'bar'},
expected_args=[
qos_minimum_bandwidth_rule.QoSMinimumBandwidthRule,
'rule_id'],
expected_kwargs={
'qos_policy_id': QOS_POLICY_ID, 'foo': 'bar'})
def test_qos_policy_create_attrs(self):
self.verify_create(self.proxy.create_qos_policy, qos_policy.QoSPolicy)
@ -760,25 +830,27 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
def test_quota_get_details(self, mock_get):
fake_quota = mock.Mock(project_id='PROJECT')
mock_get.return_value = fake_quota
self._verify2("openstack.proxy.Proxy._get",
self.proxy.get_quota,
method_args=['QUOTA_ID'],
method_kwargs={'details': True},
expected_args=[quota.QuotaDetails],
expected_kwargs={'project': fake_quota.id,
'requires_id': False})
self._verify(
"openstack.proxy.Proxy._get",
self.proxy.get_quota,
method_args=['QUOTA_ID'],
method_kwargs={'details': True},
expected_args=[quota.QuotaDetails],
expected_kwargs={
'project': fake_quota.id, 'requires_id': False})
mock_get.assert_called_once_with(quota.Quota, 'QUOTA_ID')
@mock.patch.object(proxy_base.Proxy, "_get_resource")
def test_quota_default_get(self, mock_get):
fake_quota = mock.Mock(project_id='PROJECT')
mock_get.return_value = fake_quota
self._verify2("openstack.proxy.Proxy._get",
self.proxy.get_quota_default,
method_args=['QUOTA_ID'],
expected_args=[quota.QuotaDefault],
expected_kwargs={'project': fake_quota.id,
'requires_id': False})
self._verify(
"openstack.proxy.Proxy._get",
self.proxy.get_quota_default,
method_args=['QUOTA_ID'],
expected_args=[quota.QuotaDefault],
expected_kwargs={
'project': fake_quota.id, 'requires_id': False})
mock_get.assert_called_once_with(quota.Quota, 'QUOTA_ID')
def test_quotas(self):
@ -856,11 +928,13 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
x_router = router.Router.new(id="ROUTER_ID")
mock_get.return_value = x_router
self._verify("openstack.network.v2.router.Router.add_interface",
self.proxy.add_interface_to_router,
method_args=["FAKE_ROUTER"],
method_kwargs={"port_id": "PORT"},
expected_kwargs={"port_id": "PORT"})
self._verify(
"openstack.network.v2.router.Router.add_interface",
self.proxy.add_interface_to_router,
method_args=["FAKE_ROUTER"],
method_kwargs={"port_id": "PORT"},
expected_args=[self.proxy],
expected_kwargs={"port_id": "PORT"})
mock_get.assert_called_once_with(router.Router, "FAKE_ROUTER")
@mock.patch.object(proxy_base.Proxy, '_get_resource')
@ -870,11 +944,13 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
x_router = router.Router.new(id="ROUTER_ID")
mock_get.return_value = x_router
self._verify("openstack.network.v2.router.Router.add_interface",
self.proxy.add_interface_to_router,
method_args=["FAKE_ROUTER"],
method_kwargs={"subnet_id": "SUBNET"},
expected_kwargs={"subnet_id": "SUBNET"})
self._verify(
"openstack.network.v2.router.Router.add_interface",
self.proxy.add_interface_to_router,
method_args=["FAKE_ROUTER"],
method_kwargs={"subnet_id": "SUBNET"},
expected_args=[self.proxy],
expected_kwargs={"subnet_id": "SUBNET"})
mock_get.assert_called_once_with(router.Router, "FAKE_ROUTER")
@mock.patch.object(proxy_base.Proxy, '_get_resource')
@ -884,11 +960,13 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
x_router = router.Router.new(id="ROUTER_ID")
mock_get.return_value = x_router
self._verify("openstack.network.v2.router.Router.remove_interface",
self.proxy.remove_interface_from_router,
method_args=["FAKE_ROUTER"],
method_kwargs={"port_id": "PORT"},
expected_kwargs={"port_id": "PORT"})
self._verify(
"openstack.network.v2.router.Router.remove_interface",
self.proxy.remove_interface_from_router,
method_args=["FAKE_ROUTER"],
method_kwargs={"port_id": "PORT"},
expected_args=[self.proxy],
expected_kwargs={"port_id": "PORT"})
mock_get.assert_called_once_with(router.Router, "FAKE_ROUTER")
@mock.patch.object(proxy_base.Proxy, '_get_resource')
@ -898,11 +976,13 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
x_router = router.Router.new(id="ROUTER_ID")
mock_get.return_value = x_router
self._verify("openstack.network.v2.router.Router.remove_interface",
self.proxy.remove_interface_from_router,
method_args=["FAKE_ROUTER"],
method_kwargs={"subnet_id": "SUBNET"},
expected_kwargs={"subnet_id": "SUBNET"})
self._verify(
"openstack.network.v2.router.Router.remove_interface",
self.proxy.remove_interface_from_router,
method_args=["FAKE_ROUTER"],
method_kwargs={"subnet_id": "SUBNET"},
expected_args=[self.proxy],
expected_kwargs={"subnet_id": "SUBNET"})
mock_get.assert_called_once_with(router.Router, "FAKE_ROUTER")
@mock.patch.object(proxy_base.Proxy, '_get_resource')
@ -912,11 +992,13 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
x_router = router.Router.new(id="ROUTER_ID")
mock_get.return_value = x_router
self._verify("openstack.network.v2.router.Router.add_extra_routes",
self.proxy.add_extra_routes_to_router,
method_args=["FAKE_ROUTER"],
method_kwargs={"body": {"router": {"routes": []}}},
expected_kwargs={"body": {"router": {"routes": []}}})
self._verify(
"openstack.network.v2.router.Router.add_extra_routes",
self.proxy.add_extra_routes_to_router,
method_args=["FAKE_ROUTER"],
method_kwargs={"body": {"router": {"routes": []}}},
expected_args=[self.proxy],
expected_kwargs={"body": {"router": {"routes": []}}})
mock_get.assert_called_once_with(router.Router, "FAKE_ROUTER")
@mock.patch.object(proxy_base.Proxy, '_get_resource')
@ -926,11 +1008,13 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
x_router = router.Router.new(id="ROUTER_ID")
mock_get.return_value = x_router
self._verify("openstack.network.v2.router.Router.remove_extra_routes",
self.proxy.remove_extra_routes_from_router,
method_args=["FAKE_ROUTER"],
method_kwargs={"body": {"router": {"routes": []}}},
expected_kwargs={"body": {"router": {"routes": []}}})
self._verify(
"openstack.network.v2.router.Router.remove_extra_routes",
self.proxy.remove_extra_routes_from_router,
method_args=["FAKE_ROUTER"],
method_kwargs={"body": {"router": {"routes": []}}},
expected_args=[self.proxy],
expected_kwargs={"body": {"router": {"routes": []}}})
mock_get.assert_called_once_with(router.Router, "FAKE_ROUTER")
@mock.patch.object(proxy_base.Proxy, '_get_resource')
@ -939,11 +1023,13 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
x_router = router.Router.new(id="ROUTER_ID")
mock_get.return_value = x_router
self._verify("openstack.network.v2.router.Router.add_gateway",
self.proxy.add_gateway_to_router,
method_args=["FAKE_ROUTER"],
method_kwargs={"foo": "bar"},
expected_kwargs={"foo": "bar"})
self._verify(
"openstack.network.v2.router.Router.add_gateway",
self.proxy.add_gateway_to_router,
method_args=["FAKE_ROUTER"],
method_kwargs={"foo": "bar"},
expected_args=[self.proxy],
expected_kwargs={"foo": "bar"})
mock_get.assert_called_once_with(router.Router, "FAKE_ROUTER")
@mock.patch.object(proxy_base.Proxy, '_get_resource')
@ -952,11 +1038,13 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
x_router = router.Router.new(id="ROUTER_ID")
mock_get.return_value = x_router
self._verify("openstack.network.v2.router.Router.remove_gateway",
self.proxy.remove_gateway_from_router,
method_args=["FAKE_ROUTER"],
method_kwargs={"foo": "bar"},
expected_kwargs={"foo": "bar"})
self._verify(
"openstack.network.v2.router.Router.remove_gateway",
self.proxy.remove_gateway_from_router,
method_args=["FAKE_ROUTER"],
method_kwargs={"foo": "bar"},
expected_args=[self.proxy],
expected_kwargs={"foo": "bar"})
mock_get.assert_called_once_with(router.Router, "FAKE_ROUTER")
def test_router_hosting_l3_agents_list(self):
@ -1299,19 +1387,19 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
def test_validate_topology(self):
self.verify_get(self.proxy.validate_auto_allocated_topology,
auto_allocated_topology.ValidateTopology,
value=[mock.sentinel.project_id],
expected_args=[
auto_allocated_topology.ValidateTopology],
method_args=[mock.sentinel.project_id],
expected_args=[],
expected_kwargs={"project": mock.sentinel.project_id,
"requires_id": False})
def test_set_tags(self):
x_network = network.Network.new(id='NETWORK_ID')
self._verify('openstack.network.v2.network.Network.set_tags',
self.proxy.set_tags,
method_args=[x_network, ['TAG1', 'TAG2']],
expected_args=[['TAG1', 'TAG2']],
expected_result=mock.sentinel.result_set_tags)
self._verify(
'openstack.network.v2.network.Network.set_tags',
self.proxy.set_tags,
method_args=[x_network, ['TAG1', 'TAG2']],
expected_args=[self.proxy, ['TAG1', 'TAG2']],
expected_result=mock.sentinel.result_set_tags)
@mock.patch('openstack.network.v2.network.Network.set_tags')
def test_set_tags_resource_without_tag_suport(self, mock_set_tags):
@ -1331,36 +1419,42 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
self.verify_delete(
self.proxy.delete_floating_ip_port_forwarding,
port_forwarding.PortForwarding,
False, input_path_args=[FIP_ID, "resource_or_id"],
expected_path_args={'floatingip_id': FIP_ID},)
ignore_missing=False,
method_args=[FIP_ID, "resource_or_id"],
expected_args=["resource_or_id"],
expected_kwargs={'floatingip_id': FIP_ID})
def test_delete_floating_ip_port_forwarding_ignore(self):
self.verify_delete(
self.proxy.delete_floating_ip_port_forwarding,
port_forwarding.PortForwarding,
True, input_path_args=[FIP_ID, "resource_or_id"],
expected_path_args={'floatingip_id': FIP_ID}, )
ignore_missing=True,
method_args=[FIP_ID, "resource_or_id"],
expected_args=["resource_or_id"],
expected_kwargs={'floatingip_id': FIP_ID})
def test_find_floating_ip_port_forwarding(self):
fip = floating_ip.FloatingIP.new(id=FIP_ID)
self._verify2('openstack.proxy.Proxy._find',
self.proxy.find_floating_ip_port_forwarding,
method_args=[fip, 'port_forwarding_id'],
expected_args=[
port_forwarding.PortForwarding,
'port_forwarding_id'],
expected_kwargs={'ignore_missing': True,
'floatingip_id': FIP_ID})
self._verify(
'openstack.proxy.Proxy._find',
self.proxy.find_floating_ip_port_forwarding,
method_args=[fip, 'port_forwarding_id'],
expected_args=[
port_forwarding.PortForwarding,
'port_forwarding_id'],
expected_kwargs={
'ignore_missing': True, 'floatingip_id': FIP_ID})
def test_get_floating_ip_port_forwarding(self):
fip = floating_ip.FloatingIP.new(id=FIP_ID)
self._verify2('openstack.proxy.Proxy._get',
self.proxy.get_floating_ip_port_forwarding,
method_args=[fip, 'port_forwarding_id'],
expected_args=[
port_forwarding.PortForwarding,
'port_forwarding_id'],
expected_kwargs={'floatingip_id': FIP_ID})
self._verify(
'openstack.proxy.Proxy._get',
self.proxy.get_floating_ip_port_forwarding,
method_args=[fip, 'port_forwarding_id'],
expected_args=[
port_forwarding.PortForwarding,
'port_forwarding_id'],
expected_kwargs={'floatingip_id': FIP_ID})
def test_floating_ip_port_forwardings(self):
self.verify_list(self.proxy.floating_ip_port_forwardings,
@ -1370,15 +1464,15 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
def test_update_floating_ip_port_forwarding(self):
fip = floating_ip.FloatingIP.new(id=FIP_ID)
self._verify2('openstack.network.v2._proxy.Proxy._update',
self.proxy.update_floating_ip_port_forwarding,
method_args=[fip, 'port_forwarding_id'],
method_kwargs={'foo': 'bar'},
expected_args=[
port_forwarding.PortForwarding,
'port_forwarding_id'],
expected_kwargs={'floatingip_id': FIP_ID,
'foo': 'bar'})
self._verify(
'openstack.network.v2._proxy.Proxy._update',
self.proxy.update_floating_ip_port_forwarding,
method_args=[fip, 'port_forwarding_id'],
method_kwargs={'foo': 'bar'},
expected_args=[
port_forwarding.PortForwarding,
'port_forwarding_id'],
expected_kwargs={'floatingip_id': FIP_ID, 'foo': 'bar'})
def test_create_l3_conntrack_helper(self):
self.verify_create(self.proxy.create_conntrack_helper,
@ -1391,41 +1485,47 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
self.verify_delete(
self.proxy.delete_conntrack_helper,
l3_conntrack_helper.ConntrackHelper,
False, input_path_args=['resource_or_id', r],
expected_path_args={'router_id': ROUTER_ID},)
ignore_missing=False,
method_args=['resource_or_id', r],
expected_args=['resource_or_id'],
expected_kwargs={'router_id': ROUTER_ID},)
def test_delete_l3_conntrack_helper_ignore(self):
r = router.Router.new(id=ROUTER_ID)
self.verify_delete(
self.proxy.delete_conntrack_helper,
l3_conntrack_helper.ConntrackHelper,
True, input_path_args=['resource_or_id', r],
expected_path_args={'router_id': ROUTER_ID}, )
ignore_missing=True,
method_args=['resource_or_id', r],
expected_args=['resource_or_id'],
expected_kwargs={'router_id': ROUTER_ID},)
def test_get_l3_conntrack_helper(self):
r = router.Router.new(id=ROUTER_ID)
self._verify2('openstack.proxy.Proxy._get',
self.proxy.get_conntrack_helper,
method_args=['conntrack_helper_id', r],
expected_args=[
l3_conntrack_helper.ConntrackHelper,
'conntrack_helper_id'],
expected_kwargs={'router_id': ROUTER_ID})
self._verify(
'openstack.proxy.Proxy._get',
self.proxy.get_conntrack_helper,
method_args=['conntrack_helper_id', r],
expected_args=[
l3_conntrack_helper.ConntrackHelper,
'conntrack_helper_id'],
expected_kwargs={'router_id': ROUTER_ID})
def test_l3_conntrack_helpers(self):
self.verify_list(self.proxy.conntrack_helpers,
l3_conntrack_helper.ConntrackHelper,
method_args=[ROUTER_ID],
expected_args=[],
expected_kwargs={'router_id': ROUTER_ID})
def test_update_l3_conntrack_helper(self):
r = router.Router.new(id=ROUTER_ID)
self._verify2('openstack.network.v2._proxy.Proxy._update',
self.proxy.update_conntrack_helper,
method_args=['conntrack_helper_id', r],
method_kwargs={'foo': 'bar'},
expected_args=[
l3_conntrack_helper.ConntrackHelper,
'conntrack_helper_id'],
expected_kwargs={'router_id': ROUTER_ID,
'foo': 'bar'})
self._verify(
'openstack.network.v2._proxy.Proxy._update',
self.proxy.update_conntrack_helper,
method_args=['conntrack_helper_id', r],
method_kwargs={'foo': 'bar'},
expected_args=[
l3_conntrack_helper.ConntrackHelper,
'conntrack_helper_id'],
expected_kwargs={'router_id': ROUTER_ID, 'foo': 'bar'})

View File

@ -39,11 +39,13 @@ class TestObjectStoreProxy(test_proxy_base.TestProxyBase):
endpoint=self.endpoint, container=self.container)
def test_account_metadata_get(self):
self.verify_head(self.proxy.get_account_metadata, account.Account)
self.verify_head(
self.proxy.get_account_metadata, account.Account,
method_args=[])
def test_container_metadata_get(self):
self.verify_head(self.proxy.get_container_metadata,
container.Container, value="container")
container.Container, method_args=["container"])
def test_container_delete(self):
self.verify_delete(self.proxy.delete_container,
@ -58,15 +60,17 @@ class TestObjectStoreProxy(test_proxy_base.TestProxyBase):
self.proxy.create_container,
container.Container,
method_args=['container_name'],
expected_args=[],
expected_kwargs={'name': 'container_name', "x": 1, "y": 2, "z": 3})
def test_object_metadata_get(self):
self._verify2("openstack.proxy.Proxy._head",
self.proxy.get_object_metadata,
method_args=['object'],
method_kwargs={'container': 'container'},
expected_args=[obj.Object, 'object'],
expected_kwargs={'container': 'container'})
self._verify(
"openstack.proxy.Proxy._head",
self.proxy.get_object_metadata,
method_args=['object'],
method_kwargs={'container': 'container'},
expected_args=[obj.Object, 'object'],
expected_kwargs={'container': 'container'})
def _test_object_delete(self, ignore):
expected_kwargs = {
@ -74,12 +78,13 @@ class TestObjectStoreProxy(test_proxy_base.TestProxyBase):
"container": "name",
}
self._verify2("openstack.proxy.Proxy._delete",
self.proxy.delete_object,
method_args=["resource"],
method_kwargs=expected_kwargs,
expected_args=[obj.Object, "resource"],
expected_kwargs=expected_kwargs)
self._verify(
"openstack.proxy.Proxy._delete",
self.proxy.delete_object,
method_args=["resource"],
method_kwargs=expected_kwargs,
expected_args=[obj.Object, "resource"],
expected_kwargs=expected_kwargs)
def test_object_delete(self):
self._test_object_delete(False)
@ -90,11 +95,12 @@ class TestObjectStoreProxy(test_proxy_base.TestProxyBase):
def test_object_create_attrs(self):
kwargs = {"name": "test", "data": "data", "container": "name"}
self._verify2("openstack.proxy.Proxy._create",
self.proxy.upload_object,
method_kwargs=kwargs,
expected_args=[obj.Object],
expected_kwargs=kwargs)
self._verify(
"openstack.proxy.Proxy._create",
self.proxy.upload_object,
method_kwargs=kwargs,
expected_args=[obj.Object],
expected_kwargs=kwargs)
def test_object_create_no_container(self):
self.assertRaises(TypeError, self.proxy.upload_object)
@ -103,7 +109,7 @@ class TestObjectStoreProxy(test_proxy_base.TestProxyBase):
kwargs = dict(container="container")
self.verify_get(
self.proxy.get_object, obj.Object,
value=["object"],
method_args=["object"],
method_kwargs=kwargs,
expected_kwargs=kwargs)

View File

@ -35,9 +35,11 @@ class TestOrchestrationProxy(test_proxy_base.TestProxyBase):
self.verify_create(self.proxy.create_stack, stack.Stack)
def test_create_stack_preview(self):
method_kwargs = {"preview": True, "x": 1, "y": 2, "z": 3}
self.verify_create(self.proxy.create_stack, stack.Stack,
method_kwargs=method_kwargs)
self.verify_create(
self.proxy.create_stack,
stack.Stack,
method_kwargs={"preview": True, "x": 1, "y": 2, "z": 3},
expected_kwargs={"x": 1, "y": 2, "z": 3})
def test_find_stack(self):
self.verify_find(self.proxy.find_stack, stack.Stack,
@ -49,23 +51,25 @@ class TestOrchestrationProxy(test_proxy_base.TestProxyBase):
# 'ignore_missing': False
# }
# method_args=["name_or_id"]
# self._verify2(mock_method, test_method,
# method_args=method_args,
# method_kwargs=method_kwargs,
# expected_args=[stack.Stack, "name_or_id"],
# expected_kwargs=method_kwargs,
# expected_result="result")
# self._verify(
# mock_method, test_method,
# method_args=method_args,
# method_kwargs=method_kwargs,
# expected_args=[stack.Stack, "name_or_id"],
# expected_kwargs=method_kwargs,
# expected_result="result")
#
# method_kwargs = {
# 'resolve_outputs': True,
# 'ignore_missing': True
# }
# self._verify2(mock_method, test_method,
# method_args=method_args,
# method_kwargs=method_kwargs,
# expected_args=[stack.Stack, "name_or_id"],
# expected_kwargs=method_kwargs,
# expected_result="result")
# self._verify(
# mock_method, test_method,
# method_args=method_args,
# method_kwargs=method_kwargs,
# expected_args=[stack.Stack, "name_or_id"],
# expected_kwargs=method_kwargs,
# expected_result="result")
def test_stacks(self):
self.verify_list(self.proxy.stacks, stack.Stack)
@ -79,27 +83,30 @@ class TestOrchestrationProxy(test_proxy_base.TestProxyBase):
'openstack.orchestration.v1.stack.Stack')
def test_update_stack(self):
self._verify2('openstack.orchestration.v1.stack.Stack.update',
self.proxy.update_stack,
expected_result='result',
method_args=['stack'],
method_kwargs={'preview': False},
expected_args=[self.proxy, False])
self._verify(
'openstack.orchestration.v1.stack.Stack.update',
self.proxy.update_stack,
expected_result='result',
method_args=['stack'],
method_kwargs={'preview': False},
expected_args=[self.proxy, False])
def test_update_stack_preview(self):
self._verify2('openstack.orchestration.v1.stack.Stack.update',
self.proxy.update_stack,
expected_result='result',
method_args=['stack'],
method_kwargs={'preview': True},
expected_args=[self.proxy, True])
self._verify(
'openstack.orchestration.v1.stack.Stack.update',
self.proxy.update_stack,
expected_result='result',
method_args=['stack'],
method_kwargs={'preview': True},
expected_args=[self.proxy, True])
def test_abandon_stack(self):
self._verify2('openstack.orchestration.v1.stack.Stack.abandon',
self.proxy.abandon_stack,
expected_result='result',
method_args=['stack'],
expected_args=[self.proxy])
self._verify(
'openstack.orchestration.v1.stack.Stack.abandon',
self.proxy.abandon_stack,
expected_result='result',
method_args=['stack'],
expected_args=[self.proxy])
def test_delete_stack(self):
self.verify_delete(self.proxy.delete_stack, stack.Stack, False)
@ -134,13 +141,15 @@ class TestOrchestrationProxy(test_proxy_base.TestProxyBase):
stk = stack.Stack(id=stack_id, name=stack_name)
mock_find.return_value = stk
self._verify2('openstack.proxy.Proxy._get',
self.proxy.get_stack_environment,
method_args=['IDENTITY'],
expected_args=[stack_environment.StackEnvironment],
expected_kwargs={'requires_id': False,
'stack_name': stack_name,
'stack_id': stack_id})
self._verify(
'openstack.proxy.Proxy._get',
self.proxy.get_stack_environment,
method_args=['IDENTITY'],
expected_args=[stack_environment.StackEnvironment],
expected_kwargs={
'requires_id': False,
'stack_name': stack_name,
'stack_id': stack_id})
mock_find.assert_called_once_with(mock.ANY, 'IDENTITY',
ignore_missing=False)
@ -149,13 +158,15 @@ class TestOrchestrationProxy(test_proxy_base.TestProxyBase):
stack_name = 'test_stack'
stk = stack.Stack(id=stack_id, name=stack_name)
self._verify2('openstack.proxy.Proxy._get',
self.proxy.get_stack_environment,
method_args=[stk],
expected_args=[stack_environment.StackEnvironment],
expected_kwargs={'requires_id': False,
'stack_name': stack_name,
'stack_id': stack_id})
self._verify(
'openstack.proxy.Proxy._get',
self.proxy.get_stack_environment,
method_args=[stk],
expected_args=[stack_environment.StackEnvironment],
expected_kwargs={
'requires_id': False,
'stack_name': stack_name,
'stack_id': stack_id})
@mock.patch.object(stack_files.StackFiles, 'fetch')
@mock.patch.object(stack.Stack, 'find')
@ -192,13 +203,15 @@ class TestOrchestrationProxy(test_proxy_base.TestProxyBase):
stk = stack.Stack(id=stack_id, name=stack_name)
mock_find.return_value = stk
self._verify2('openstack.proxy.Proxy._get',
self.proxy.get_stack_template,
method_args=['IDENTITY'],
expected_args=[stack_template.StackTemplate],
expected_kwargs={'requires_id': False,
'stack_name': stack_name,
'stack_id': stack_id})
self._verify(
'openstack.proxy.Proxy._get',
self.proxy.get_stack_template,
method_args=['IDENTITY'],
expected_args=[stack_template.StackTemplate],
expected_kwargs={
'requires_id': False,
'stack_name': stack_name,
'stack_id': stack_id})
mock_find.assert_called_once_with(mock.ANY, 'IDENTITY',
ignore_missing=False)
@ -207,13 +220,15 @@ class TestOrchestrationProxy(test_proxy_base.TestProxyBase):
stack_name = 'test_stack'
stk = stack.Stack(id=stack_id, name=stack_name)
self._verify2('openstack.proxy.Proxy._get',
self.proxy.get_stack_template,
method_args=[stk],
expected_args=[stack_template.StackTemplate],
expected_kwargs={'requires_id': False,
'stack_name': stack_name,
'stack_id': stack_id})
self._verify(
'openstack.proxy.Proxy._get',
self.proxy.get_stack_template,
method_args=[stk],
expected_args=[stack_template.StackTemplate],
expected_kwargs={
'requires_id': False,
'stack_name': stack_name,
'stack_id': stack_id})
@mock.patch.object(stack.Stack, 'find')
def test_resources_with_stack_object(self, mock_find):
@ -223,6 +238,7 @@ class TestOrchestrationProxy(test_proxy_base.TestProxyBase):
self.verify_list(self.proxy.resources, resource.Resource,
method_args=[stk],
expected_args=[],
expected_kwargs={'stack_name': stack_name,
'stack_id': stack_id})
@ -237,6 +253,7 @@ class TestOrchestrationProxy(test_proxy_base.TestProxyBase):
self.verify_list(self.proxy.resources, resource.Resource,
method_args=[stack_id],
expected_args=[],
expected_kwargs={'stack_name': stack_name,
'stack_id': stack_id})

View File

@ -11,6 +11,7 @@
# under the License.
from openstack.placement.v1 import _proxy
from openstack.placement.v1 import resource_class
from openstack.placement.v1 import resource_provider
from openstack.tests.unit import test_proxy_base as test_proxy_base
@ -21,6 +22,42 @@ class TestPlacementProxy(test_proxy_base.TestProxyBase):
super().setUp()
self.proxy = _proxy.Proxy(self.session)
# resource classes
def test_resource_class_create(self):
self.verify_create(
self.proxy.create_resource_class,
resource_class.ResourceClass,
)
def test_resource_class_delete(self):
self.verify_delete(
self.proxy.delete_resource_class,
resource_class.ResourceClass,
False,
)
def test_resource_class_update(self):
self.verify_update(
self.proxy.update_resource_class,
resource_class.ResourceClass,
False,
)
def test_resource_class_get(self):
self.verify_get(
self.proxy.get_resource_class,
resource_class.ResourceClass,
)
def test_resource_classes(self):
self.verify_list(
self.proxy.resource_classes,
resource_class.ResourceClass,
)
# resource providers
def test_resource_provider_create(self):
self.verify_create(
self.proxy.create_resource_provider,
@ -48,7 +85,7 @@ class TestPlacementProxy(test_proxy_base.TestProxyBase):
)
def test_resource_providers(self):
self.verify_list_no_kwargs(
self.verify_list(
self.proxy.resource_providers,
resource_provider.ResourceProvider,
)

View File

@ -0,0 +1,42 @@
# 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.
from openstack.placement.v1 import resource_class as rc
from openstack.tests.unit import base
FAKE = {
'name': 'CUSTOM_FPGA',
}
class TestResourceClass(base.TestCase):
def test_basic(self):
sot = rc.ResourceClass()
self.assertEqual(None, sot.resource_key)
self.assertEqual('resource_classes', sot.resources_key)
self.assertEqual('/resource_classes', sot.base_path)
self.assertTrue(sot.allow_create)
self.assertTrue(sot.allow_fetch)
self.assertTrue(sot.allow_commit)
self.assertTrue(sot.allow_delete)
self.assertTrue(sot.allow_list)
self.assertFalse(sot.allow_patch)
self.assertDictEqual(
{'limit': 'limit', 'marker': 'marker'},
sot._query_mapping._mapping)
def test_make_it(self):
sot = rc.ResourceClass(**FAKE)
self.assertEqual(FAKE['name'], sot.id)
self.assertEqual(FAKE['name'], sot.name)

View File

@ -20,138 +20,132 @@ class TestProxyBase(base.TestCase):
super(TestProxyBase, self).setUp()
self.session = mock.Mock()
def _add_path_args_for_verify(self, path_args, method_args,
expected_kwargs, value=None):
if path_args is not None:
if value is None:
for key in path_args:
method_args.append(path_args[key])
expected_kwargs['path_args'] = path_args
def _verify(self, mock_method, test_method,
method_args=None, method_kwargs=None,
expected_args=None, expected_kwargs=None,
expected_result=None):
def _verify(
self, mock_method, test_method, *,
method_args=None, method_kwargs=None, method_result=None,
expected_args=None, expected_kwargs=None, expected_result=None,
):
with mock.patch(mock_method) as mocked:
mocked.return_value = expected_result
if any([method_args, method_kwargs,
expected_args, expected_kwargs]):
method_args = method_args or ()
method_kwargs = method_kwargs or {}
expected_args = expected_args or ()
expected_kwargs = expected_kwargs or {}
self.assertEqual(expected_result, test_method(*method_args,
**method_kwargs))
mocked.assert_called_with(test_method.__self__,
*expected_args, **expected_kwargs)
else:
self.assertEqual(expected_result, test_method())
mocked.assert_called_with(test_method.__self__)
# NOTE(briancurtin): This is a duplicate version of _verify that is
# temporarily here while we shift APIs. The difference is that
# calls from the Proxy classes aren't going to be going directly into
# the Resource layer anymore, so they don't pass in the session which
# was tested in assert_called_with.
# This is being done in lieu of adding logic and complicating
# the _verify method. It will be removed once there is one API to
# be verifying.
def _verify2(self, mock_method, test_method,
method_args=None, method_kwargs=None, method_result=None,
expected_args=None, expected_kwargs=None,
expected_result=None):
with mock.patch(mock_method) as mocked:
mocked.return_value = expected_result
if any([method_args, method_kwargs,
expected_args, expected_kwargs]):
if any([
method_args,
method_kwargs,
expected_args,
expected_kwargs,
]):
method_args = method_args or ()
method_kwargs = method_kwargs or {}
expected_args = expected_args or ()
expected_kwargs = expected_kwargs or {}
if method_result:
self.assertEqual(method_result, test_method(*method_args,
**method_kwargs))
self.assertEqual(
method_result,
test_method(*method_args, **method_kwargs),
)
else:
self.assertEqual(expected_result, test_method(*method_args,
**method_kwargs))
self.assertEqual(
expected_result,
test_method(*method_args, **method_kwargs),
)
# Check how the mock was called in detail
(called_args, called_kwargs) = mocked.call_args
self.assertEqual(list(called_args), expected_args)
base_path = expected_kwargs.get('base_path', None)
called_args, called_kwargs = mocked.call_args
self.assertEqual(expected_args, list(called_args))
# NOTE(gtema): if base_path is not in expected_kwargs or empty
# exclude it from the comparison, since some methods might
# still invoke method with None value
if not base_path:
base_path = expected_kwargs.get('base_path', None)
if base_path is None:
expected_kwargs.pop('base_path', None)
called_kwargs.pop('base_path', None)
self.assertDictEqual(called_kwargs, expected_kwargs)
# ditto for paginated
paginated = expected_kwargs.get('paginated', None)
if paginated is None:
expected_kwargs.pop('paginated', None)
called_kwargs.pop('paginated', None)
# and ignore_missing
ignore_missing = expected_kwargs.get('ignore_missing', None)
if ignore_missing is None:
expected_kwargs.pop('ignore_missing', None)
called_kwargs.pop('ignore_missing', None)
self.assertDictEqual(expected_kwargs, called_kwargs)
else:
self.assertEqual(expected_result, test_method())
mocked.assert_called_with(test_method.__self__)
def verify_create(self, test_method, resource_type,
mock_method="openstack.proxy.Proxy._create",
expected_result="result", **kwargs):
the_kwargs = {"x": 1, "y": 2, "z": 3}
method_kwargs = kwargs.pop("method_kwargs", the_kwargs)
expected_args = kwargs.pop('expected_args', [resource_type])
# Default the_kwargs should be copied, since we might need to extend it
expected_kwargs = kwargs.pop("expected_kwargs", the_kwargs.copy())
expected_kwargs["base_path"] = kwargs.pop("base_path", None)
def verify_create(
self, test_method, resource_type, base_path=None, *,
method_args=None, method_kwargs=None,
expected_args=None, expected_kwargs=None, expected_result="result",
mock_method="openstack.proxy.Proxy._create",
):
if method_args is None:
method_args = []
if method_kwargs is None:
method_kwargs = {"x": 1, "y": 2, "z": 3}
if expected_args is None:
expected_args = method_args.copy()
if expected_kwargs is None:
expected_kwargs = method_kwargs.copy()
expected_kwargs["base_path"] = base_path
self._verify2(mock_method, test_method,
expected_result=expected_result,
method_kwargs=method_kwargs,
expected_args=expected_args,
expected_kwargs=expected_kwargs,
**kwargs)
self._verify(
mock_method,
test_method,
method_args=method_args,
method_kwargs=method_kwargs,
expected_args=[resource_type] + expected_args,
expected_kwargs=expected_kwargs,
expected_result=expected_result,
)
def verify_delete(self, test_method, resource_type, ignore,
input_path_args=None, expected_path_args=None,
method_kwargs=None, expected_args=None,
expected_kwargs=None,
mock_method="openstack.proxy.Proxy._delete"):
method_args = ["resource_or_id"]
def verify_delete(
self, test_method, resource_type, ignore_missing=True, *,
method_args=None, method_kwargs=None,
expected_args=None, expected_kwargs=None,
mock_method="openstack.proxy.Proxy._delete",
):
method_args = method_args or ['resource_id']
method_kwargs = method_kwargs or {}
method_kwargs["ignore_missing"] = ignore
if isinstance(input_path_args, dict):
for key in input_path_args:
method_kwargs[key] = input_path_args[key]
elif isinstance(input_path_args, list):
method_args = input_path_args
expected_kwargs = expected_kwargs or {}
expected_kwargs["ignore_missing"] = ignore
if expected_path_args:
expected_kwargs.update(expected_path_args)
expected_args = expected_args or [resource_type, "resource_or_id"]
self._verify2(mock_method, test_method,
method_args=method_args,
method_kwargs=method_kwargs,
expected_args=expected_args,
expected_kwargs=expected_kwargs)
method_kwargs["ignore_missing"] = ignore_missing
expected_args = expected_args or method_args.copy()
expected_kwargs = expected_kwargs or method_kwargs.copy()
def verify_get(self, test_method, resource_type, value=None, args=None,
mock_method="openstack.proxy.Proxy._get",
ignore_value=False, **kwargs):
the_value = value
if value is None:
the_value = [] if ignore_value else ["value"]
expected_args = kwargs.pop("expected_args", [])
expected_kwargs = kwargs.pop("expected_kwargs", {})
method_kwargs = kwargs.pop("method_kwargs", kwargs)
if args:
expected_kwargs["args"] = args
if kwargs:
expected_kwargs["path_args"] = kwargs
if not expected_args:
expected_args = [resource_type] + the_value
self._verify2(mock_method, test_method,
method_args=the_value,
method_kwargs=method_kwargs or {},
expected_args=expected_args,
expected_kwargs=expected_kwargs)
self._verify(
mock_method,
test_method,
method_args=method_args,
method_kwargs=method_kwargs,
expected_args=[resource_type] + expected_args,
expected_kwargs=expected_kwargs,
)
def verify_get(
self, test_method, resource_type, requires_id=False, base_path=None, *,
method_args=None, method_kwargs=None,
expected_args=None, expected_kwargs=None,
mock_method="openstack.proxy.Proxy._get",
):
if method_args is None:
method_args = ['resource_id']
if method_kwargs is None:
method_kwargs = {}
if expected_args is None:
expected_args = method_args.copy()
if expected_kwargs is None:
expected_kwargs = method_kwargs.copy()
self._verify(
mock_method,
test_method,
method_args=method_args,
method_kwargs=method_kwargs,
expected_args=[resource_type] + expected_args,
expected_kwargs=expected_kwargs,
)
def verify_get_overrided(self, proxy, resource_type, patch_target):
with mock.patch(patch_target, autospec=True) as res:
@ -162,89 +156,106 @@ class TestProxyBase(base.TestCase):
base_path=None,
error_message=mock.ANY)
def verify_head(self, test_method, resource_type,
mock_method="openstack.proxy.Proxy._head",
value=None, **kwargs):
the_value = [value] if value is not None else []
expected_kwargs = {"path_args": kwargs} if kwargs else {}
self._verify2(mock_method, test_method,
method_args=the_value,
method_kwargs=kwargs,
expected_args=[resource_type] + the_value,
expected_kwargs=expected_kwargs)
def verify_head(
self, test_method, resource_type, base_path=None, *,
method_args=None, method_kwargs=None,
expected_args=None, expected_kwargs=None,
mock_method="openstack.proxy.Proxy._head",
):
if method_args is None:
method_args = ['resource_id']
if method_kwargs is None:
method_kwargs = {}
expected_args = expected_args or method_args.copy()
expected_kwargs = expected_kwargs or method_kwargs.copy()
def verify_find(self, test_method, resource_type, value=None,
mock_method="openstack.proxy.Proxy._find",
path_args=None, **kwargs):
method_args = value or ["name_or_id"]
expected_kwargs = kwargs.pop('expected_kwargs', {})
self._verify(
mock_method,
test_method,
method_args=method_args,
method_kwargs=method_kwargs,
expected_args=[resource_type] + expected_args,
expected_kwargs=expected_kwargs,
)
self._add_path_args_for_verify(path_args, method_args, expected_kwargs,
value=value)
def verify_find(
self, test_method, resource_type, name_or_id='resource_name',
ignore_missing=True, *,
method_args=None, method_kwargs=None,
expected_args=None, expected_kwargs=None,
mock_method="openstack.proxy.Proxy._find",
):
method_args = [name_or_id] + (method_args or [])
method_kwargs = method_kwargs or {}
method_kwargs["ignore_missing"] = ignore_missing
expected_args = expected_args or method_args.copy()
expected_kwargs = expected_kwargs or method_kwargs.copy()
# TODO(briancurtin): if sub-tests worked in this mess of
# test dependencies, the following would be a lot easier to work with.
expected_kwargs["ignore_missing"] = False
self._verify2(mock_method, test_method,
method_args=method_args + [False],
expected_args=[resource_type, "name_or_id"],
expected_kwargs=expected_kwargs,
expected_result="result",
**kwargs)
self._verify(
mock_method,
test_method,
method_args=method_args,
method_kwargs=method_kwargs,
expected_args=[resource_type] + expected_args,
expected_kwargs=expected_kwargs,
)
expected_kwargs["ignore_missing"] = True
self._verify2(mock_method, test_method,
method_args=method_args + [True],
expected_args=[resource_type, "name_or_id"],
expected_kwargs=expected_kwargs,
expected_result="result",
**kwargs)
def verify_list(
self, test_method, resource_type, paginated=None, base_path=None, *,
method_args=None, method_kwargs=None,
expected_args=None, expected_kwargs=None,
mock_method="openstack.proxy.Proxy._list",
):
if method_args is None:
method_args = []
if method_kwargs is None:
method_kwargs = {}
if paginated is not None:
method_kwargs["paginated"] = paginated
if expected_args is None:
expected_args = method_args.copy()
if expected_kwargs is None:
expected_kwargs = method_kwargs.copy()
if base_path is not None:
expected_kwargs["base_path"] = base_path
def verify_list(self, test_method, resource_type,
mock_method="openstack.proxy.Proxy._list",
**kwargs):
expected_kwargs = kwargs.pop("expected_kwargs", {})
if 'paginated' in kwargs:
expected_kwargs.update({"paginated": kwargs.pop('paginated')})
method_kwargs = kwargs.pop("method_kwargs", {})
expected_kwargs["base_path"] = kwargs.pop("base_path", None)
self._verify2(mock_method, test_method,
method_kwargs=method_kwargs,
expected_args=[resource_type],
expected_kwargs=expected_kwargs,
expected_result=["result"],
**kwargs)
self._verify(
mock_method,
test_method,
method_args=method_args,
method_kwargs=method_kwargs,
expected_args=[resource_type] + expected_args,
expected_kwargs=expected_kwargs,
)
def verify_list_no_kwargs(self, test_method, resource_type,
mock_method="openstack.proxy.Proxy._list"):
self._verify2(mock_method, test_method,
method_kwargs={},
expected_args=[resource_type],
expected_kwargs={},
expected_result=["result"])
def verify_update(
self, test_method, resource_type, base_path=None, *,
method_args=None, method_kwargs=None,
expected_args=None, expected_kwargs=None, expected_result="result",
mock_method="openstack.proxy.Proxy._update",
):
if method_args is None:
method_args = ['resource_id']
if method_kwargs is None:
method_kwargs = {"x": 1, "y": 2, "z": 3}
method_kwargs["base_path"] = base_path
if expected_args is None:
expected_args = method_args.copy()
if expected_kwargs is None:
expected_kwargs = method_kwargs.copy()
def verify_update(self, test_method, resource_type, value=None,
mock_method="openstack.proxy.Proxy._update",
expected_result="result", path_args=None, **kwargs):
method_args = value or ["resource_or_id"]
method_kwargs = kwargs.pop("method_kwargs", {})
method_kwargs.update({"x": 1, "y": 2, "z": 3})
expected_args = kwargs.pop("expected_args", ["resource_or_id"])
expected_kwargs = kwargs.pop("expected_kwargs", method_kwargs.copy())
expected_kwargs["base_path"] = kwargs.pop("base_path", None)
self._add_path_args_for_verify(path_args, method_args, expected_kwargs,
value=value)
self._verify2(mock_method, test_method,
expected_result=expected_result,
method_args=method_args,
method_kwargs=method_kwargs,
expected_args=[resource_type] + expected_args,
expected_kwargs=expected_kwargs,
**kwargs)
self._verify(
mock_method,
test_method,
method_args=method_args,
method_kwargs=method_kwargs,
expected_args=[resource_type] + expected_args,
expected_kwargs=expected_kwargs,
)
def verify_wait_for_status(
self, test_method,
mock_method="openstack.resource.wait_for_status", **kwargs):
self, test_method,
mock_method="openstack.resource.wait_for_status",
**kwargs,
):
self._verify(mock_method, test_method, **kwargs)

View File

@ -1,234 +0,0 @@
# 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.
from unittest import mock
from openstack.tests.unit import base
class TestProxyBase(base.TestCase):
# object_store makes calls with container= rather than
# path_args=dict(container= because container needs to wind up
# in the uri components.
kwargs_to_path_args = True
def setUp(self):
super(TestProxyBase, self).setUp()
self.session = mock.Mock()
def _add_path_args_for_verify(self, path_args, method_args,
expected_kwargs, value=None):
if path_args is not None:
if value is None:
for key in path_args:
method_args.append(path_args[key])
expected_kwargs['path_args'] = path_args
def _verify(self, mock_method, test_method,
method_args=None, method_kwargs=None,
expected_args=None, expected_kwargs=None,
expected_result=None):
with mock.patch(mock_method) as mocked:
mocked.return_value = expected_result
if any([method_args, method_kwargs,
expected_args, expected_kwargs]):
method_args = method_args or ()
method_kwargs = method_kwargs or {}
expected_args = expected_args or ()
expected_kwargs = expected_kwargs or {}
self.assertEqual(expected_result, test_method(*method_args,
**method_kwargs))
mocked.assert_called_with(test_method.__self__,
*expected_args, **expected_kwargs)
else:
self.assertEqual(expected_result, test_method())
mocked.assert_called_with(test_method.__self__)
# NOTE(briancurtin): This is a duplicate version of _verify that is
# temporarily here while we shift APIs. The difference is that
# calls from the Proxy classes aren't going to be going directly into
# the Resource layer anymore, so they don't pass in the session which
# was tested in assert_called_with.
# This is being done in lieu of adding logic and complicating
# the _verify method. It will be removed once there is one API to
# be verifying.
def _verify2(self, mock_method, test_method,
method_args=None, method_kwargs=None, method_result=None,
expected_args=None, expected_kwargs=None,
expected_result=None):
with mock.patch(mock_method) as mocked:
mocked.return_value = expected_result
if any([method_args, method_kwargs,
expected_args, expected_kwargs]):
method_args = method_args or ()
method_kwargs = method_kwargs or {}
expected_args = expected_args or ()
expected_kwargs = expected_kwargs or {}
if method_result:
self.assertEqual(method_result, test_method(*method_args,
**method_kwargs))
else:
self.assertEqual(expected_result, test_method(*method_args,
**method_kwargs))
mocked.assert_called_with(*expected_args, **expected_kwargs)
else:
self.assertEqual(expected_result, test_method())
mocked.assert_called_with(test_method.__self__)
def verify_create(self, test_method, resource_type,
mock_method="openstack.proxy.Proxy._create",
expected_result="result", **kwargs):
the_kwargs = {"x": 1, "y": 2, "z": 3}
method_kwargs = kwargs.pop("method_kwargs", the_kwargs)
expected_args = [resource_type]
expected_kwargs = kwargs.pop("expected_kwargs", the_kwargs)
self._verify2(mock_method, test_method,
expected_result=expected_result,
method_kwargs=method_kwargs,
expected_args=expected_args,
expected_kwargs=expected_kwargs,
**kwargs)
def verify_delete(self, test_method, resource_type, ignore,
input_path_args=None, expected_path_args=None,
method_kwargs=None, expected_args=None,
expected_kwargs=None,
mock_method="openstack.proxy.Proxy._delete"):
method_args = ["resource_or_id"]
method_kwargs = method_kwargs or {}
method_kwargs["ignore_missing"] = ignore
if isinstance(input_path_args, dict):
for key in input_path_args:
method_kwargs[key] = input_path_args[key]
elif isinstance(input_path_args, list):
method_args = input_path_args
expected_kwargs = expected_kwargs or {}
expected_kwargs["ignore_missing"] = ignore
if expected_path_args:
expected_kwargs.update(expected_path_args)
expected_args = expected_args or [resource_type, "resource_or_id"]
self._verify2(mock_method, test_method,
method_args=method_args,
method_kwargs=method_kwargs,
expected_args=expected_args,
expected_kwargs=expected_kwargs)
def verify_get(self, test_method, resource_type, value=None, args=None,
mock_method="openstack.proxy.Proxy._get",
ignore_value=False, **kwargs):
the_value = value
if value is None:
the_value = [] if ignore_value else ["value"]
expected_args = kwargs.pop("expected_args", [])
expected_kwargs = kwargs.pop("expected_kwargs", {})
method_kwargs = kwargs.pop("method_kwargs", kwargs)
if args:
expected_kwargs["args"] = args
if kwargs and self.kwargs_to_path_args:
expected_kwargs["path_args"] = kwargs
if not expected_args:
expected_args = [resource_type] + the_value
self._verify2(mock_method, test_method,
method_args=the_value,
method_kwargs=method_kwargs or {},
expected_args=expected_args,
expected_kwargs=expected_kwargs)
def verify_head(self, test_method, resource_type,
mock_method="openstack.proxy.Proxy._head",
value=None, **kwargs):
the_value = [value] if value is not None else []
if self.kwargs_to_path_args:
expected_kwargs = {"path_args": kwargs} if kwargs else {}
else:
expected_kwargs = kwargs or {}
self._verify2(mock_method, test_method,
method_args=the_value,
method_kwargs=kwargs,
expected_args=[resource_type] + the_value,
expected_kwargs=expected_kwargs)
def verify_find(self, test_method, resource_type, value=None,
mock_method="openstack.proxy.Proxy._find",
path_args=None, **kwargs):
method_args = value or ["name_or_id"]
expected_kwargs = {}
self._add_path_args_for_verify(path_args, method_args, expected_kwargs,
value=value)
# TODO(briancurtin): if sub-tests worked in this mess of
# test dependencies, the following would be a lot easier to work with.
expected_kwargs["ignore_missing"] = False
self._verify2(mock_method, test_method,
method_args=method_args + [False],
expected_args=[resource_type, "name_or_id"],
expected_kwargs=expected_kwargs,
expected_result="result",
**kwargs)
expected_kwargs["ignore_missing"] = True
self._verify2(mock_method, test_method,
method_args=method_args + [True],
expected_args=[resource_type, "name_or_id"],
expected_kwargs=expected_kwargs,
expected_result="result",
**kwargs)
def verify_list(self, test_method, resource_type, paginated=False,
mock_method="openstack.proxy.Proxy._list",
**kwargs):
expected_kwargs = kwargs.pop("expected_kwargs", {})
expected_kwargs.update({"paginated": paginated})
method_kwargs = kwargs.pop("method_kwargs", {})
self._verify2(mock_method, test_method,
method_kwargs=method_kwargs,
expected_args=[resource_type],
expected_kwargs=expected_kwargs,
expected_result=["result"],
**kwargs)
def verify_list_no_kwargs(self, test_method, resource_type,
paginated=False,
mock_method="openstack.proxy.Proxy._list"):
self._verify2(mock_method, test_method,
method_kwargs={},
expected_args=[resource_type],
expected_kwargs={"paginated": paginated},
expected_result=["result"])
def verify_update(self, test_method, resource_type, value=None,
mock_method="openstack.proxy.Proxy._update",
expected_result="result", path_args=None, **kwargs):
method_args = value or ["resource_or_id"]
method_kwargs = {"x": 1, "y": 2, "z": 3}
expected_args = kwargs.pop("expected_args", ["resource_or_id"])
expected_kwargs = method_kwargs.copy()
self._add_path_args_for_verify(path_args, method_args, expected_kwargs,
value=value)
self._verify2(mock_method, test_method,
expected_result=expected_result,
method_args=method_args,
method_kwargs=method_kwargs,
expected_args=[resource_type] + expected_args,
expected_kwargs=expected_kwargs,
**kwargs)
def verify_wait_for_status(
self, test_method,
mock_method="openstack.resource.wait_for_status", **kwargs):
self._verify(mock_method, test_method, **kwargs)

View File

@ -0,0 +1,4 @@
---
features:
- |
Added support for the ``ResourceClass`` Placement resource.

View File

@ -1,11 +1,11 @@
[metadata]
name = openstacksdk
summary = An SDK for building applications to work with OpenStack
description-file =
description_file =
README.rst
author = OpenStack
author-email = openstack-discuss@lists.openstack.org
home-page = https://docs.openstack.org/openstacksdk/
author_email = openstack-discuss@lists.openstack.org
home_page = https://docs.openstack.org/openstacksdk/
classifier =
Environment :: OpenStack
Intended Audience :: Information Technology
@ -17,7 +17,7 @@ classifier =
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
python-requires = >=3.6
python_requires = >=3.6
[files]
packages =