nova-net: Remove layer of indirection in 'nova.network'
At some point in the past, there was only nova-network and its code could be found in 'nova.network'. Neutron was added and eventually found itself (mostly!) in the 'nova.network.neutronv2' submodule. With nova-network now gone, we can remove one layer of indirection and move the code from 'nova.network.neutronv2' back up to 'nova.network', mirroring what we did with the old nova-volume code way back in 2012 [1]. To ensure people don't get nova-network and 'nova.network' confused, 'neutron' is retained in filenames. [1] https://review.opendev.org/#/c/14731/ Change-Id: I329f0fd589a4b2e0426485f09f6782f94275cc07 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
parent
bf7ea80c4d
commit
fadeedcdea
|
@ -32,7 +32,7 @@ from nova import block_device
|
|||
import nova.conf
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova import network
|
||||
from nova.network import neutron
|
||||
from nova.network.security_group import openstack_driver
|
||||
from nova import objects
|
||||
from nova.objects import virt_device_metadata as metadata_obj
|
||||
|
@ -645,7 +645,7 @@ class RouteConfiguration(object):
|
|||
|
||||
def get_metadata_by_address(address):
|
||||
ctxt = context.get_admin_context()
|
||||
fixed_ip = network.API().get_fixed_ip_by_address(ctxt, address)
|
||||
fixed_ip = neutron.API().get_fixed_ip_by_address(ctxt, address)
|
||||
LOG.info('Fixed IP %(ip)s translates to instance UUID %(uuid)s',
|
||||
{'ip': address, 'uuid': fixed_ip['instance_uuid']})
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ import nova.conf
|
|||
from nova import context as nova_context
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova.network.neutronv2 import api as neutronapi
|
||||
from nova.network import neutron as neutronapi
|
||||
|
||||
CONF = nova.conf.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
|
|
@ -31,7 +31,7 @@ import nova.conf
|
|||
from nova import context as nova_context
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova.network.neutronv2 import constants
|
||||
from nova.network import constants
|
||||
from nova import objects
|
||||
from nova import quota
|
||||
from nova import utils
|
||||
|
|
|
@ -26,7 +26,7 @@ from nova.api import validation
|
|||
from nova.compute import api as compute
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova import network
|
||||
from nova.network import neutron
|
||||
from nova import objects
|
||||
from nova.policies import attach_interfaces as ai_policies
|
||||
|
||||
|
@ -61,7 +61,7 @@ class InterfaceAttachmentController(wsgi.Controller):
|
|||
def __init__(self):
|
||||
super(InterfaceAttachmentController, self).__init__()
|
||||
self.compute_api = compute.API()
|
||||
self.network_api = network.API()
|
||||
self.network_api = neutron.API()
|
||||
|
||||
@wsgi.expected_errors((404, 501))
|
||||
def index(self, req, server_id):
|
||||
|
|
|
@ -25,7 +25,7 @@ from nova.compute import api as compute
|
|||
import nova.conf
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova import network
|
||||
from nova.network import neutron
|
||||
from nova.policies import evacuate as evac_policies
|
||||
from nova import utils
|
||||
|
||||
|
@ -37,7 +37,7 @@ class EvacuateController(wsgi.Controller):
|
|||
super(EvacuateController, self).__init__()
|
||||
self.compute_api = compute.API()
|
||||
self.host_api = compute.HostAPI()
|
||||
self.network_api = network.API()
|
||||
self.network_api = neutron.API()
|
||||
|
||||
def _get_on_shared_storage(self, req, evacuate_body):
|
||||
if api_version_request.is_supported(req, min_version='2.14'):
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
from nova.api.openstack.api_version_request \
|
||||
import MAX_PROXY_API_SUPPORT_VERSION
|
||||
from nova.api.openstack import wsgi
|
||||
from nova import network
|
||||
from nova.network import neutron
|
||||
from nova.policies import floating_ip_pools as fip_policies
|
||||
|
||||
|
||||
|
@ -37,7 +37,7 @@ class FloatingIPPoolsController(wsgi.Controller):
|
|||
|
||||
def __init__(self):
|
||||
super(FloatingIPPoolsController, self).__init__()
|
||||
self.network_api = network.API()
|
||||
self.network_api = neutron.API()
|
||||
|
||||
@wsgi.Controller.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
|
||||
@wsgi.expected_errors(())
|
||||
|
|
|
@ -29,7 +29,7 @@ from nova.api import validation
|
|||
from nova.compute import api as compute
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova import network
|
||||
from nova.network import neutron
|
||||
from nova.policies import floating_ips as fi_policies
|
||||
|
||||
|
||||
|
@ -108,7 +108,7 @@ class FloatingIPController(wsgi.Controller):
|
|||
def __init__(self):
|
||||
super(FloatingIPController, self).__init__()
|
||||
self.compute_api = compute.API()
|
||||
self.network_api = network.API()
|
||||
self.network_api = neutron.API()
|
||||
|
||||
@wsgi.Controller.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
|
||||
@wsgi.expected_errors((400, 404))
|
||||
|
@ -207,7 +207,7 @@ class FloatingIPActionController(wsgi.Controller):
|
|||
def __init__(self):
|
||||
super(FloatingIPActionController, self).__init__()
|
||||
self.compute_api = compute.API()
|
||||
self.network_api = network.API()
|
||||
self.network_api = neutron.API()
|
||||
|
||||
@wsgi.Controller.api_version("2.1", "2.43")
|
||||
@wsgi.expected_errors((400, 403, 404))
|
||||
|
|
|
@ -26,7 +26,7 @@ from nova.api import validation
|
|||
from nova.compute import api as compute
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova import network
|
||||
from nova.network import neutron
|
||||
from nova import objects
|
||||
from nova.policies import migrate_server as ms_policies
|
||||
|
||||
|
@ -39,7 +39,7 @@ class MigrateServerController(wsgi.Controller):
|
|||
def __init__(self):
|
||||
super(MigrateServerController, self).__init__()
|
||||
self.compute_api = compute.API()
|
||||
self.network_api = network.API()
|
||||
self.network_api = neutron.API()
|
||||
|
||||
@wsgi.response(202)
|
||||
@wsgi.expected_errors((400, 403, 404, 409))
|
||||
|
|
|
@ -21,7 +21,7 @@ from nova.api.openstack.api_version_request \
|
|||
from nova.api.openstack import wsgi
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova import network
|
||||
from nova.network import neutron
|
||||
from nova.objects import base as base_obj
|
||||
from nova.objects import fields as obj_fields
|
||||
from nova.policies import networks as net_policies
|
||||
|
@ -77,7 +77,7 @@ class NetworkController(wsgi.Controller):
|
|||
def __init__(self, network_api=None):
|
||||
super(NetworkController, self).__init__()
|
||||
# TODO(stephenfin): 'network_api' is only being passed for use by tests
|
||||
self.network_api = network_api or network.API()
|
||||
self.network_api = network_api or neutron.API()
|
||||
|
||||
@wsgi.Controller.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
|
||||
@wsgi.expected_errors(())
|
||||
|
|
|
@ -201,7 +201,7 @@ base_create = {
|
|||
'type': 'object',
|
||||
'properties': {
|
||||
# NOTE(oomichi): allocate_for_instance() of
|
||||
# neutronv2/api.py gets security_group names
|
||||
# network/neutron.py gets security_group names
|
||||
# or UUIDs from this parameter.
|
||||
# parameter_types.name allows both format.
|
||||
'name': parameter_types.name,
|
||||
|
|
|
@ -41,7 +41,7 @@ from nova import context as nova_context
|
|||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova.image import api as image_api
|
||||
from nova import network as network_api
|
||||
from nova.network import neutron
|
||||
from nova import objects
|
||||
from nova.policies import servers as server_policies
|
||||
from nova import utils
|
||||
|
@ -111,7 +111,7 @@ class ServersController(wsgi.Controller):
|
|||
def __init__(self):
|
||||
super(ServersController, self).__init__()
|
||||
self.compute_api = compute.API()
|
||||
self.network_api = network_api.API()
|
||||
self.network_api = neutron.API()
|
||||
|
||||
@wsgi.expected_errors((400, 403))
|
||||
@validation.query_schema(schema_servers.query_params_v275, '2.75')
|
||||
|
|
|
@ -25,7 +25,7 @@ from nova.compute import api as compute
|
|||
from nova.compute import vm_states
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova import network
|
||||
from nova.network import neutron
|
||||
from nova.policies import shelve as shelve_policies
|
||||
|
||||
|
||||
|
@ -33,7 +33,7 @@ class ShelveController(wsgi.Controller):
|
|||
def __init__(self):
|
||||
super(ShelveController, self).__init__()
|
||||
self.compute_api = compute.API()
|
||||
self.network_api = network.API()
|
||||
self.network_api = neutron.API()
|
||||
|
||||
@wsgi.response(202)
|
||||
@wsgi.expected_errors((404, 409))
|
||||
|
|
|
@ -23,7 +23,7 @@ import nova.conf
|
|||
from nova import context as nova_context
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
import nova.network
|
||||
from nova.network import neutron
|
||||
from nova.policies import tenant_networks as tn_policies
|
||||
from nova import quota
|
||||
|
||||
|
@ -46,7 +46,7 @@ def network_dict(network):
|
|||
class TenantNetworkController(wsgi.Controller):
|
||||
def __init__(self):
|
||||
super(TenantNetworkController, self).__init__()
|
||||
self.network_api = nova.network.API()
|
||||
self.network_api = neutron.API()
|
||||
self._default_networks = []
|
||||
|
||||
def _refresh_default_networks(self):
|
||||
|
|
|
@ -54,8 +54,8 @@ from nova.db import migration
|
|||
from nova.db.sqlalchemy import api as sa_db
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova.network.neutronv2 import api as neutron_api
|
||||
from nova.network.neutronv2 import constants
|
||||
from nova.network import constants
|
||||
from nova.network import neutron as neutron_api
|
||||
from nova import objects
|
||||
from nova.objects import block_device as block_device_obj
|
||||
from nova.objects import compute_node as compute_node_obj
|
||||
|
@ -1493,7 +1493,7 @@ class PlacementCommands(object):
|
|||
|
||||
:param ctxt: nova.context.RequestContext
|
||||
:param instance: the instance to return the ports for
|
||||
:param neutron: nova.network.neutronv2.api.ClientWrapper to
|
||||
:param neutron: nova.network.neutron.ClientWrapper to
|
||||
communicate with Neutron
|
||||
:return: a list of neutron port dict objects
|
||||
:raise UnableToQueryPorts: If the neutron list ports query fails.
|
||||
|
@ -1648,7 +1648,7 @@ class PlacementCommands(object):
|
|||
values; this cache is updated if a new node is processed.
|
||||
:param placement: nova.scheduler.client.report.SchedulerReportClient
|
||||
to communicate with the Placement service API.
|
||||
:param neutron: nova.network.neutronv2.api.ClientWrapper to
|
||||
:param neutron: nova.network.neutron.ClientWrapper to
|
||||
communicate with Neutron
|
||||
:param output: function that takes a single message for verbose output
|
||||
:raise UnableToQueryPorts: If the neutron list ports query fails.
|
||||
|
@ -1815,7 +1815,7 @@ class PlacementCommands(object):
|
|||
any changes.
|
||||
:param heal_port_allocations: True if healing port allocation is
|
||||
requested, False otherwise.
|
||||
:param neutron: nova.network.neutronv2.api.ClientWrapper to
|
||||
:param neutron: nova.network.neutron.ClientWrapper to
|
||||
communicate with Neutron
|
||||
:return: True if allocations were created or updated for the instance,
|
||||
None if nothing needed to be done
|
||||
|
@ -1965,7 +1965,7 @@ class PlacementCommands(object):
|
|||
:param instance_uuid: UUID of a specific instance to process.
|
||||
:param heal_port_allocations: True if healing port allocation is
|
||||
requested, False otherwise.
|
||||
:param neutron: nova.network.neutronv2.api.ClientWrapper to
|
||||
:param neutron: nova.network.neutron.ClientWrapper to
|
||||
communicate with Neutron
|
||||
:return: Number of instances that had allocations created.
|
||||
:raises: nova.exception.ComputeHostNotFound if a compute node for a
|
||||
|
|
|
@ -59,9 +59,9 @@ from nova import exception_wrapper
|
|||
from nova import hooks
|
||||
from nova.i18n import _
|
||||
from nova import image
|
||||
from nova import network
|
||||
from nova.network import constants
|
||||
from nova.network import model as network_model
|
||||
from nova.network.neutronv2 import constants
|
||||
from nova.network import neutron
|
||||
from nova.network.security_group import openstack_driver
|
||||
from nova import objects
|
||||
from nova.objects import base as obj_base
|
||||
|
@ -289,7 +289,7 @@ class API(base.Base):
|
|||
def __init__(self, image_api=None, network_api=None, volume_api=None,
|
||||
security_group_api=None, **kwargs):
|
||||
self.image_api = image_api or image.API()
|
||||
self.network_api = network_api or network.API()
|
||||
self.network_api = network_api or neutron.API()
|
||||
self.volume_api = volume_api or cinder.API()
|
||||
self._placementclient = None # Lazy-load on first access.
|
||||
self.security_group_api = (security_group_api or
|
||||
|
|
|
@ -76,9 +76,8 @@ from nova import hooks
|
|||
from nova.i18n import _
|
||||
from nova import image
|
||||
from nova import manager
|
||||
from nova import network
|
||||
from nova.network import base_api as base_net_api
|
||||
from nova.network import model as network_model
|
||||
from nova.network import neutron
|
||||
from nova import objects
|
||||
from nova.objects import base as obj_base
|
||||
from nova.objects import external_event as external_event_obj
|
||||
|
@ -568,7 +567,7 @@ class ComputeManager(manager.Manager):
|
|||
# ProviderTree cache for this compute service.
|
||||
self.reportclient = report.SchedulerReportClient()
|
||||
self.virtapi = ComputeVirtAPI(self)
|
||||
self.network_api = network.API()
|
||||
self.network_api = neutron.API()
|
||||
self.volume_api = cinder.API()
|
||||
self.image_api = image.API()
|
||||
self._last_bw_usage_poll = 0
|
||||
|
@ -3479,8 +3478,8 @@ class ComputeManager(manager.Manager):
|
|||
context, instance, self.host, migration,
|
||||
provider_mappings=request_group_resource_providers_mapping)
|
||||
# TODO(mriedem): Consider decorating setup_instance_network_on_host
|
||||
# with @base_api.refresh_cache and then we wouldn't need this
|
||||
# explicit call to get_instance_nw_info.
|
||||
# with @api.refresh_cache and then we wouldn't need this explicit
|
||||
# call to get_instance_nw_info.
|
||||
network_info = self.network_api.get_instance_nw_info(context,
|
||||
instance)
|
||||
else:
|
||||
|
@ -9864,10 +9863,8 @@ class ComputeManager(manager.Manager):
|
|||
'server_uuid': instance.uuid})
|
||||
|
||||
del network_info[index]
|
||||
base_net_api.update_instance_cache_with_nw_info(
|
||||
self.network_api, context,
|
||||
instance,
|
||||
nw_info=network_info)
|
||||
neutron.update_instance_cache_with_nw_info(
|
||||
self.network_api, context, instance, nw_info=network_info)
|
||||
try:
|
||||
self.driver.detach_interface(context, instance, vif)
|
||||
except NotImplementedError:
|
||||
|
|
|
@ -47,7 +47,7 @@ from nova import exception
|
|||
from nova.i18n import _
|
||||
from nova import image
|
||||
from nova import manager
|
||||
from nova import network
|
||||
from nova.network import neutron
|
||||
from nova import notifications
|
||||
from nova import objects
|
||||
from nova.objects import base as nova_object
|
||||
|
@ -240,7 +240,7 @@ class ComputeTaskManager(base.Base):
|
|||
self.compute_rpcapi = compute_rpcapi.ComputeAPI()
|
||||
self.volume_api = cinder.API()
|
||||
self.image_api = image.API()
|
||||
self.network_api = network.API()
|
||||
self.network_api = neutron.API()
|
||||
self.servicegroup_api = servicegroup.API()
|
||||
self.query_client = query.SchedulerQueryClient()
|
||||
self.report_client = report.SchedulerReportClient()
|
||||
|
|
|
@ -29,8 +29,8 @@ from nova import context as nova_context
|
|||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova import image as nova_image
|
||||
from nova import network
|
||||
from nova.network.neutronv2 import constants as neutron_constants
|
||||
from nova.network import constants as neutron_constants
|
||||
from nova.network import neutron
|
||||
from nova import objects
|
||||
from nova.objects import fields
|
||||
from nova.scheduler import utils as scheduler_utils
|
||||
|
@ -634,7 +634,7 @@ class CrossCellMigrationTask(base.TaskBase):
|
|||
self._target_cell_instance = None
|
||||
self._target_cell_context = None
|
||||
|
||||
self.network_api = network.API()
|
||||
self.network_api = neutron.API()
|
||||
self.volume_api = cinder.API()
|
||||
self.image_api = nova_image.API()
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ from nova.conductor.tasks import migrate
|
|||
import nova.conf
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova import network
|
||||
from nova.network import neutron
|
||||
from nova import objects
|
||||
from nova.objects import fields as obj_fields
|
||||
from nova.objects import migrate_data as migrate_data_obj
|
||||
|
@ -67,7 +67,7 @@ class LiveMigrationTask(base.TaskBase):
|
|||
self.request_spec = request_spec
|
||||
self._source_cn = None
|
||||
self._held_allocations = None
|
||||
self.network_api = network.API()
|
||||
self.network_api = neutron.API()
|
||||
self.instance_pci_request = None
|
||||
|
||||
def _execute(self):
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
# Copyright 2010 United States Government as represented by the
|
||||
# Administrator of the National Aeronautics and Space Administration.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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 oslo_utils import importutils
|
||||
|
||||
|
||||
# TODO(stephenfin): Remove this layer of indirection
|
||||
def API():
|
||||
cls = importutils.import_class('nova.network.neutronv2.api.API')
|
||||
return cls()
|
|
@ -1,382 +0,0 @@
|
|||
# Copyright 2014 OpenStack Foundation
|
||||
# All Rights Reserved
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import functools
|
||||
|
||||
from oslo_concurrency import lockutils
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import excutils
|
||||
|
||||
from nova.db import base
|
||||
from nova import hooks
|
||||
from nova.i18n import _
|
||||
from nova.network import model as network_model
|
||||
from nova import objects
|
||||
from nova import utils
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@hooks.add_hook('instance_network_info')
|
||||
def update_instance_cache_with_nw_info(impl, context, instance, nw_info=None):
|
||||
if instance.deleted:
|
||||
LOG.debug('Instance is deleted, no further info cache update',
|
||||
instance=instance)
|
||||
return
|
||||
|
||||
try:
|
||||
if not isinstance(nw_info, network_model.NetworkInfo):
|
||||
nw_info = None
|
||||
if nw_info is None:
|
||||
nw_info = impl._get_instance_nw_info(context, instance)
|
||||
|
||||
LOG.debug('Updating instance_info_cache with network_info: %s',
|
||||
nw_info, instance=instance)
|
||||
|
||||
# NOTE(comstud): The save() method actually handles updating or
|
||||
# creating the instance. We don't need to retrieve the object
|
||||
# from the DB first.
|
||||
ic = objects.InstanceInfoCache.new(context, instance.uuid)
|
||||
ic.network_info = nw_info
|
||||
ic.save()
|
||||
instance.info_cache = ic
|
||||
except Exception:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.exception('Failed storing info cache', instance=instance)
|
||||
|
||||
|
||||
def refresh_cache(f):
|
||||
"""Decorator to update the instance_info_cache
|
||||
|
||||
Requires context and instance as function args
|
||||
"""
|
||||
argspec = utils.getargspec(f)
|
||||
|
||||
@functools.wraps(f)
|
||||
def wrapper(self, context, *args, **kwargs):
|
||||
try:
|
||||
# get the instance from arguments (or raise ValueError)
|
||||
instance = kwargs.get('instance')
|
||||
if not instance:
|
||||
instance = args[argspec.args.index('instance') - 2]
|
||||
except ValueError:
|
||||
msg = _('instance is a required argument to use @refresh_cache')
|
||||
raise Exception(msg)
|
||||
|
||||
with lockutils.lock('refresh_cache-%s' % instance.uuid):
|
||||
# We need to call the wrapped function with the lock held to ensure
|
||||
# that it can call _get_instance_nw_info safely.
|
||||
res = f(self, context, *args, **kwargs)
|
||||
update_instance_cache_with_nw_info(self, context, instance,
|
||||
nw_info=res)
|
||||
# return the original function's return value
|
||||
return res
|
||||
return wrapper
|
||||
|
||||
|
||||
SENTINEL = object()
|
||||
|
||||
|
||||
class NetworkAPI(base.Base):
|
||||
"""Base Network API for doing networking operations.
|
||||
New operations available on specific clients must be added here as well.
|
||||
"""
|
||||
def get_all(self, context):
|
||||
"""Get all the networks for client."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def get(self, context, network_uuid):
|
||||
"""Get specific network for client."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_fixed_ip_by_address(self, context, address):
|
||||
"""Get fixed IP by address."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_floating_ip(self, context, id):
|
||||
"""Get floating IP by id."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_floating_ip_pools(self, context):
|
||||
"""Get floating IP pools."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_floating_ip_by_address(self, context, address):
|
||||
"""Get floating IP by address."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_floating_ips_by_project(self, context):
|
||||
"""Get floating IPs by project."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_instance_id_by_floating_address(self, context, address):
|
||||
"""Get instance id by floating address."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_vifs_by_instance(self, context, instance):
|
||||
"""Get vifs by instance.
|
||||
|
||||
:param context: nova.context.RequestContext
|
||||
:param instance: nova.objects.instance.Instance
|
||||
:returns: nova.objects.virtual_interface.VirtualInterfaceList; the
|
||||
fields address, uuid and net_uuid should be set for each VIF object
|
||||
in the returned list.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def allocate_floating_ip(self, context, pool=None):
|
||||
"""Adds (allocate) floating IP to a project from a pool."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def release_floating_ip(self, context, address,
|
||||
affect_auto_assigned=False):
|
||||
"""Removes (deallocates) a floating IP with address from a project."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def disassociate_and_release_floating_ip(self, context, instance,
|
||||
floating_ip):
|
||||
"""Removes (deallocates) and deletes the floating IP."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def associate_floating_ip(self, context, instance,
|
||||
floating_address, fixed_address,
|
||||
affect_auto_assigned=False):
|
||||
"""Associates a floating IP with a fixed IP."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def disassociate_floating_ip(self, context, instance, address,
|
||||
affect_auto_assigned=False):
|
||||
"""Disassociates a floating IP from fixed IP it is associated with."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def allocate_for_instance(self, context, instance, vpn,
|
||||
requested_networks,
|
||||
security_groups=None, bind_host_id=None,
|
||||
attach=False, resource_provider_mapping=None):
|
||||
"""Allocates all network structures for an instance.
|
||||
|
||||
:param context: The request context.
|
||||
:param instance: nova.objects.instance.Instance object.
|
||||
:param vpn: A boolean, if True, indicate a vpn to access the instance.
|
||||
:param requested_networks: A list of requested_networks,
|
||||
Optional value containing network_id, fixed_ip, and port_id.
|
||||
:param security_groups: None or security groups to allocate for
|
||||
instance.
|
||||
:param bind_host_id: the host ID to attach to the ports being created.
|
||||
:param attach: Boolean indicating if a port is being attached to an
|
||||
existing running instance. Should be False during server create.
|
||||
:param resource_provider_mapping: a dict keyed by ids of the entities
|
||||
(for example Neutron port) requesting resources for this instance
|
||||
mapped to a list of resource provider UUIDs that are fulfilling
|
||||
such a resource request.
|
||||
:returns: network info as from get_instance_nw_info() below
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def deallocate_for_instance(self, context, instance,
|
||||
requested_networks=None):
|
||||
"""Deallocates all network structures related to instance."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def allocate_port_for_instance(self, context, instance, port_id,
|
||||
network_id=None, requested_ip=None,
|
||||
bind_host_id=None, tag=None):
|
||||
"""Allocate port for instance."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def deallocate_port_for_instance(self, context, instance, port_id):
|
||||
"""Deallocate port for instance."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def list_ports(self, *args, **kwargs):
|
||||
"""List ports."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def show_port(self, *args, **kwargs):
|
||||
"""Show specific port."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def add_fixed_ip_to_instance(self, context, instance, network_id):
|
||||
"""Adds a fixed IP to instance from specified network."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def remove_fixed_ip_from_instance(self, context, instance, address):
|
||||
"""Removes a fixed IP from instance from specified network."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_instance_nw_info(self, context, instance, **kwargs):
|
||||
"""Returns all network info related to an instance."""
|
||||
with lockutils.lock('refresh_cache-%s' % instance.uuid):
|
||||
result = self._get_instance_nw_info(context, instance, **kwargs)
|
||||
update_instance_cache_with_nw_info(self, context, instance,
|
||||
nw_info=result)
|
||||
return result
|
||||
|
||||
def _get_instance_nw_info(self, context, instance, **kwargs):
|
||||
"""Template method, so a subclass can implement for neutron/network."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_requested_resource_for_instance(self, context, instance_uuid):
|
||||
"""Collect resource requests from the ports associated to the instance
|
||||
|
||||
:param context: nova request context
|
||||
:param instance_uuid: The UUID of the instance
|
||||
:return: A list of RequestGroup objects
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def validate_networks(self, context, requested_networks, num_instances):
|
||||
"""validate the networks passed at the time of creating
|
||||
the server.
|
||||
|
||||
Return the number of instances that can be successfully allocated
|
||||
with the requested network configuration.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def create_resource_requests(self, context, requested_networks,
|
||||
pci_requests=None):
|
||||
"""Retrieve all information for the networks passed at the time of
|
||||
creating the server.
|
||||
|
||||
:param context: The request context.
|
||||
:param requested_networks: The networks requested for the server.
|
||||
:type requested_networks: nova.objects.NetworkRequestList
|
||||
:param pci_requests: The list of PCI requests to which additional PCI
|
||||
requests created here will be added.
|
||||
:type pci_requests: nova.objects.InstancePCIRequests
|
||||
|
||||
:returns: A tuple with an instance of ``objects.NetworkMetadata`` for
|
||||
use by the scheduler or None and a list of RequestGroup
|
||||
objects representing the resource needs of each request ports
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def setup_networks_on_host(self, context, instance, host=None,
|
||||
teardown=False):
|
||||
"""Setup or teardown the network structures on hosts related to
|
||||
instance.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def migrate_instance_start(self, context, instance, migration):
|
||||
"""Start to migrate the network of an instance."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def migrate_instance_finish(
|
||||
self, context, instance, migration, provider_mappings):
|
||||
"""Finish migrating the network of an instance.
|
||||
|
||||
:param context: The request context.
|
||||
:param instance: nova.objects.instance.Instance object.
|
||||
:param migration: nova.objects.migration.Migration object.
|
||||
:param provider_mappings: a dict of list of resource provider uuids
|
||||
keyed by port uuid
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def setup_instance_network_on_host(
|
||||
self, context, instance, host, migration=None,
|
||||
provider_mappings=None):
|
||||
"""Setup network for specified instance on host.
|
||||
|
||||
:param context: The request context.
|
||||
:param instance: nova.objects.instance.Instance object.
|
||||
:param host: The host which network should be setup for instance.
|
||||
:param migration: The migration object if the instance is being
|
||||
tracked with a migration.
|
||||
:param provider_mappings: a dict of lists of resource provider uuids
|
||||
keyed by port uuid
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def cleanup_instance_network_on_host(self, context, instance, host):
|
||||
"""Cleanup network for specified instance on host.
|
||||
|
||||
:param context: The request context.
|
||||
:param instance: nova.objects.instance.Instance object.
|
||||
:param host: The host which network should be cleanup for instance.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def update_instance_vnic_index(self, context, instance, vif, index):
|
||||
"""Update instance vnic index.
|
||||
|
||||
When the 'VNIC index' extension is supported this method will update
|
||||
the vnic index of the instance on the port. An instance may have more
|
||||
than one vnic.
|
||||
|
||||
:param context: The request context.
|
||||
:param instance: nova.objects.instance.Instance object.
|
||||
:param vif: The VIF in question.
|
||||
:param index: The index on the instance for the VIF.
|
||||
"""
|
||||
pass
|
||||
|
||||
def has_substr_port_filtering_extension(self, context):
|
||||
return False
|
||||
|
||||
def supports_port_binding_extension(self, context):
|
||||
"""Checks to see if the networking API supports the binding-extended
|
||||
ports API extension.
|
||||
|
||||
Defaults to False since this is only implemented by the neutron API.
|
||||
|
||||
:param context: the user request context
|
||||
:returns: True if the binding-extended API extension is available,
|
||||
False otherwise
|
||||
"""
|
||||
return False
|
||||
|
||||
def bind_ports_to_host(self, context, instance, host,
|
||||
vnic_types=None, port_profiles=None):
|
||||
"""Attempts to bind the ports from the instance on the given host
|
||||
|
||||
If the ports are already actively bound to another host, like the
|
||||
source host during live migration, then the new port bindings will
|
||||
be inactive, assuming $host is the destination host for the live
|
||||
migration.
|
||||
|
||||
In the event of an error, any ports which were successfully bound to
|
||||
the host should have those host bindings removed from the ports.
|
||||
|
||||
This method should not be used if "supports_port_binding_extension"
|
||||
returns False.
|
||||
|
||||
:param context: the user request context
|
||||
:type context: nova.context.RequestContext
|
||||
:param instance: the instance with a set of ports
|
||||
:type instance: nova.objects.Instance
|
||||
:param host: the host on which to bind the ports which
|
||||
are attached to the instance
|
||||
:type host: str
|
||||
:param vnic_types: optional dict for the host port binding
|
||||
:type vnic_types: dict of <port_id> : <vnic_type>
|
||||
:param port_profiles: optional dict per port ID for the host port
|
||||
binding profile.
|
||||
note that the port binding profile is mutable
|
||||
via the networking "Port Binding" API so callers that
|
||||
pass in a profile should ensure they have the latest
|
||||
version from neutron with their changes merged,
|
||||
which can be determined using the "revision_number"
|
||||
attribute of the port.
|
||||
:type port_profiles: dict of <port_id> : <port_profile>
|
||||
:raises: PortBindingFailed if any of the ports failed to be bound to
|
||||
the destination host
|
||||
:returns: dict, keyed by port ID, of a new host port
|
||||
binding dict per port that was bound
|
||||
"""
|
||||
raise NotImplementedError()
|
|
@ -13,14 +13,19 @@
|
|||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
"""
|
||||
API and utilities for nova-network interactions.
|
||||
"""
|
||||
|
||||
import copy
|
||||
import functools
|
||||
import time
|
||||
|
||||
from keystoneauth1 import loading as ks_loading
|
||||
from neutronclient.common import exceptions as neutron_client_exc
|
||||
from neutronclient.v2_0 import client as clientv20
|
||||
from oslo_concurrency import lockutils
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import strutils
|
||||
|
@ -30,11 +35,12 @@ import six
|
|||
from nova.compute import utils as compute_utils
|
||||
import nova.conf
|
||||
from nova import context as nova_context
|
||||
from nova.db import base
|
||||
from nova import exception
|
||||
from nova import hooks
|
||||
from nova.i18n import _
|
||||
from nova.network import base_api
|
||||
from nova.network import constants
|
||||
from nova.network import model as network_model
|
||||
from nova.network.neutronv2 import constants
|
||||
from nova import objects
|
||||
from nova.objects import fields as obj_fields
|
||||
from nova.pci import manager as pci_manager
|
||||
|
@ -96,6 +102,63 @@ def get_binding_profile(port):
|
|||
return port.get(constants.BINDING_PROFILE, {}) or {}
|
||||
|
||||
|
||||
@hooks.add_hook('instance_network_info')
|
||||
def update_instance_cache_with_nw_info(impl, context, instance, nw_info=None):
|
||||
if instance.deleted:
|
||||
LOG.debug('Instance is deleted, no further info cache update',
|
||||
instance=instance)
|
||||
return
|
||||
|
||||
try:
|
||||
if not isinstance(nw_info, network_model.NetworkInfo):
|
||||
nw_info = None
|
||||
if nw_info is None:
|
||||
nw_info = impl._get_instance_nw_info(context, instance)
|
||||
|
||||
LOG.debug('Updating instance_info_cache with network_info: %s',
|
||||
nw_info, instance=instance)
|
||||
|
||||
# NOTE(comstud): The save() method actually handles updating or
|
||||
# creating the instance. We don't need to retrieve the object
|
||||
# from the DB first.
|
||||
ic = objects.InstanceInfoCache.new(context, instance.uuid)
|
||||
ic.network_info = nw_info
|
||||
ic.save()
|
||||
instance.info_cache = ic
|
||||
except Exception:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.exception('Failed storing info cache', instance=instance)
|
||||
|
||||
|
||||
def refresh_cache(f):
|
||||
"""Decorator to update the instance_info_cache
|
||||
|
||||
Requires context and instance as function args
|
||||
"""
|
||||
argspec = utils.getargspec(f)
|
||||
|
||||
@functools.wraps(f)
|
||||
def wrapper(self, context, *args, **kwargs):
|
||||
try:
|
||||
# get the instance from arguments (or raise ValueError)
|
||||
instance = kwargs.get('instance')
|
||||
if not instance:
|
||||
instance = args[argspec.args.index('instance') - 2]
|
||||
except ValueError:
|
||||
msg = _('instance is a required argument to use @refresh_cache')
|
||||
raise Exception(msg)
|
||||
|
||||
with lockutils.lock('refresh_cache-%s' % instance.uuid):
|
||||
# We need to call the wrapped function with the lock held to ensure
|
||||
# that it can call _get_instance_nw_info safely.
|
||||
res = f(self, context, *args, **kwargs)
|
||||
update_instance_cache_with_nw_info(self, context, instance,
|
||||
nw_info=res)
|
||||
# return the original function's return value
|
||||
return res
|
||||
return wrapper
|
||||
|
||||
|
||||
@profiler.trace_cls("neutron_api")
|
||||
class ClientWrapper(clientv20.Client):
|
||||
"""A Neutron client wrapper class.
|
||||
|
@ -235,7 +298,7 @@ def _ensure_no_port_binding_failure(port):
|
|||
raise exception.PortBindingFailed(port_id=port['id'])
|
||||
|
||||
|
||||
class API(base_api.NetworkAPI):
|
||||
class API(base.Base):
|
||||
"""API for interacting with the neutron 2.x API."""
|
||||
|
||||
def __init__(self):
|
||||
|
@ -1629,8 +1692,8 @@ class API(base_api.NetworkAPI):
|
|||
# hasn't already been deleted. This is needed when an instance fails to
|
||||
# launch and is rescheduled onto another compute node. If the instance
|
||||
# has already been deleted this call does nothing.
|
||||
base_api.update_instance_cache_with_nw_info(self, context, instance,
|
||||
network_model.NetworkInfo([]))
|
||||
update_instance_cache_with_nw_info(self, context, instance,
|
||||
network_model.NetworkInfo([]))
|
||||
|
||||
def allocate_port_for_instance(self, context, instance, port_id,
|
||||
network_id=None, requested_ip=None,
|
||||
|
@ -1772,6 +1835,14 @@ class API(base_api.NetworkAPI):
|
|||
{'port_id': port_id, 'reason': exc})
|
||||
raise exception.NovaException(message=msg)
|
||||
|
||||
def get_instance_nw_info(self, context, instance, **kwargs):
|
||||
"""Returns all network info related to an instance."""
|
||||
with lockutils.lock('refresh_cache-%s' % instance.uuid):
|
||||
result = self._get_instance_nw_info(context, instance, **kwargs)
|
||||
update_instance_cache_with_nw_info(self, context, instance,
|
||||
nw_info=result)
|
||||
return result
|
||||
|
||||
def _get_instance_nw_info(self, context, instance, networks=None,
|
||||
port_ids=None, admin_client=None,
|
||||
preexisting_port_ids=None,
|
||||
|
@ -1856,7 +1927,7 @@ class API(base_api.NetworkAPI):
|
|||
|
||||
return networks, port_ids
|
||||
|
||||
@base_api.refresh_cache
|
||||
@refresh_cache
|
||||
def add_fixed_ip_to_instance(self, context, instance, network_id):
|
||||
"""Add a fixed IP to the instance from specified network."""
|
||||
neutron = get_client(context)
|
||||
|
@ -1891,7 +1962,7 @@ class API(base_api.NetworkAPI):
|
|||
raise exception.NetworkNotFoundForInstance(
|
||||
instance_id=instance.uuid)
|
||||
|
||||
@base_api.refresh_cache
|
||||
@refresh_cache
|
||||
def remove_fixed_ip_from_instance(self, context, instance, address):
|
||||
"""Remove a fixed IP from the instance."""
|
||||
neutron = get_client(context)
|
||||
|
@ -2360,7 +2431,7 @@ class API(base_api.NetworkAPI):
|
|||
raise exception.FixedIpNotFoundForAddress(address=address)
|
||||
return port_id
|
||||
|
||||
@base_api.refresh_cache
|
||||
@refresh_cache
|
||||
def associate_floating_ip(self, context, instance,
|
||||
floating_address, fixed_address,
|
||||
affect_auto_assigned=False):
|
||||
|
@ -2421,7 +2492,7 @@ class API(base_api.NetworkAPI):
|
|||
if orig_instance:
|
||||
# purge cached nw info for the original instance; pass the
|
||||
# context from the instance in case we found it in another cell
|
||||
base_api.update_instance_cache_with_nw_info(
|
||||
update_instance_cache_with_nw_info(
|
||||
self, orig_instance._context, orig_instance)
|
||||
else:
|
||||
# Leave a breadcrumb about not being able to refresh the
|
||||
|
@ -2723,7 +2794,7 @@ class API(base_api.NetworkAPI):
|
|||
if using neutron.
|
||||
"""
|
||||
|
||||
@base_api.refresh_cache
|
||||
@refresh_cache
|
||||
def _release_floating_ip_and_refresh_cache(self, context, instance,
|
||||
floating_ip):
|
||||
self._release_floating_ip(context, floating_ip['address'],
|
||||
|
@ -2749,7 +2820,7 @@ class API(base_api.NetworkAPI):
|
|||
address=address
|
||||
)
|
||||
|
||||
@base_api.refresh_cache
|
||||
@refresh_cache
|
||||
def disassociate_floating_ip(self, context, instance, address,
|
||||
affect_auto_assigned=False):
|
||||
"""Disassociate a floating IP from the instance."""
|
||||
|
@ -3250,7 +3321,16 @@ class API(base_api.NetworkAPI):
|
|||
def setup_instance_network_on_host(
|
||||
self, context, instance, host, migration=None,
|
||||
provider_mappings=None):
|
||||
"""Setup network for specified instance on host."""
|
||||
"""Setup network for specified instance on host.
|
||||
|
||||
:param context: The request context.
|
||||
:param instance: nova.objects.instance.Instance object.
|
||||
:param host: The host which network should be setup for instance.
|
||||
:param migration: The migration object if the instance is being
|
||||
tracked with a migration.
|
||||
:param provider_mappings: a dict of lists of resource provider uuids
|
||||
keyed by port uuid
|
||||
"""
|
||||
self._update_port_binding_for_instance(
|
||||
context, instance, host, migration, provider_mappings)
|
||||
|
||||
|
@ -3409,7 +3489,13 @@ class API(base_api.NetworkAPI):
|
|||
"""Update instance vnic index.
|
||||
|
||||
When the 'VNIC index' extension is supported this method will update
|
||||
the vnic index of the instance on the port.
|
||||
the vnic index of the instance on the port. An instance may have more
|
||||
than one vnic.
|
||||
|
||||
:param context: The request context.
|
||||
:param instance: nova.objects.instance.Instance object.
|
||||
:param vif: The VIF in question.
|
||||
:param index: The index on the instance for the VIF.
|
||||
"""
|
||||
self._refresh_neutron_extensions_cache(context)
|
||||
if constants.VNIC_INDEX_EXT in self.extensions:
|
|
@ -26,7 +26,7 @@ from webob import exc
|
|||
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova.network.neutronv2 import api as neutronapi
|
||||
from nova.network import neutron as neutronapi
|
||||
from nova.network.security_group import security_group_base
|
||||
from nova import utils
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ import nova.conf
|
|||
import nova.context
|
||||
from nova import exception
|
||||
from nova import image as image_api
|
||||
from nova import network
|
||||
from nova.network import model as network_model
|
||||
from nova.network import neutron
|
||||
from nova.notifications.objects import base as notification_base
|
||||
from nova.notifications.objects import instance as instance_notification
|
||||
from nova import objects
|
||||
|
@ -287,7 +287,7 @@ def bandwidth_usage(context, instance_ref, audit_start,
|
|||
return cached_info
|
||||
return network_model.NetworkInfo.hydrate(cached_info)
|
||||
try:
|
||||
return network.API().get_instance_nw_info(admin_context,
|
||||
return neutron.API().get_instance_nw_info(admin_context,
|
||||
instance_ref)
|
||||
except Exception:
|
||||
try:
|
||||
|
|
|
@ -54,8 +54,8 @@ from nova import context
|
|||
from nova.db import migration
|
||||
from nova.db.sqlalchemy import api as session
|
||||
from nova import exception
|
||||
from nova.network import constants as neutron_constants
|
||||
from nova.network import model as network_model
|
||||
from nova.network.neutronv2 import constants as neutron_constants
|
||||
from nova import objects
|
||||
from nova.objects import base as obj_base
|
||||
from nova.objects import service as service_obj
|
||||
|
@ -1645,38 +1645,38 @@ class NeutronFixture(fixtures.Fixture):
|
|||
self.test.flags(vif_plugging_timeout=0)
|
||||
|
||||
self.test.stub_out(
|
||||
'nova.network.neutronv2.api.API.add_fixed_ip_to_instance',
|
||||
'nova.network.neutron.API.add_fixed_ip_to_instance',
|
||||
lambda *args, **kwargs: network_model.NetworkInfo.hydrate(
|
||||
self.nw_info))
|
||||
self.test.stub_out(
|
||||
'nova.network.neutronv2.api.API.remove_fixed_ip_from_instance',
|
||||
'nova.network.neutron.API.remove_fixed_ip_from_instance',
|
||||
lambda *args, **kwargs: network_model.NetworkInfo.hydrate(
|
||||
self.nw_info))
|
||||
|
||||
# Stub out port binding APIs which go through a KSA client Adapter
|
||||
# rather than python-neutronclient.
|
||||
self.test.stub_out(
|
||||
'nova.network.neutronv2.api._get_ksa_client',
|
||||
'nova.network.neutron._get_ksa_client',
|
||||
lambda *args, **kwargs: mock.Mock(
|
||||
spec=ksa_adap.Adapter))
|
||||
self.test.stub_out(
|
||||
'nova.network.neutronv2.api.API._create_port_binding',
|
||||
'nova.network.neutron.API._create_port_binding',
|
||||
self.create_port_binding)
|
||||
self.test.stub_out(
|
||||
'nova.network.neutronv2.api.API._delete_port_binding',
|
||||
'nova.network.neutron.API._delete_port_binding',
|
||||
self.delete_port_binding)
|
||||
self.test.stub_out(
|
||||
'nova.network.neutronv2.api.API._activate_port_binding',
|
||||
'nova.network.neutron.API._activate_port_binding',
|
||||
self.activate_port_binding)
|
||||
self.test.stub_out(
|
||||
'nova.network.neutronv2.api.API._get_port_binding',
|
||||
'nova.network.neutron.API._get_port_binding',
|
||||
self.get_port_binding)
|
||||
|
||||
self.test.stub_out('nova.network.neutronv2.api.get_client',
|
||||
self.test.stub_out('nova.network.neutron.get_client',
|
||||
self._get_client)
|
||||
|
||||
def _get_client(self, context, admin=False):
|
||||
# This logic is copied from nova.network.neutronv2.api._get_auth_plugin
|
||||
# This logic is copied from nova.network.neutron._get_auth_plugin
|
||||
admin = admin or context.is_admin and not context.auth_token
|
||||
return _FakeNeutronClient(self, admin)
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ class AttachInterfacesSampleJsonTest(test_servers.ServersSampleBase):
|
|||
def fake_detach_interface(self, context, instance, port_id):
|
||||
pass
|
||||
|
||||
self.stub_out('nova.network.neutronv2.api.API.list_ports',
|
||||
self.stub_out('nova.network.neutron.API.list_ports',
|
||||
fake_list_ports)
|
||||
self.stub_out('nova.compute.api.API.attach_interface',
|
||||
fake_attach_interface)
|
||||
|
@ -101,7 +101,7 @@ class AttachInterfacesSampleJsonTest(test_servers.ServersSampleBase):
|
|||
def _stub_show_for_instance(self, instance_uuid, port_id):
|
||||
show_port = self.neutron.show_port(port_id)
|
||||
show_port['port']['device_id'] = instance_uuid
|
||||
self.stub_out('nova.network.neutronv2.api.API.show_port',
|
||||
self.stub_out('nova.network.neutron.API.show_port',
|
||||
lambda *a, **k: show_port)
|
||||
|
||||
def test_show_interfaces(self):
|
||||
|
@ -176,7 +176,7 @@ class AttachInterfacesSampleV249JsonTest(test_servers.ServersSampleBase):
|
|||
def _stub_show_for_instance(self, instance_uuid, port_id):
|
||||
show_port = self.neutron.show_port(port_id)
|
||||
show_port['port']['device_id'] = instance_uuid
|
||||
self.stub_out('nova.network.neutronv2.api.API.show_port',
|
||||
self.stub_out('nova.network.neutron.API.show_port',
|
||||
lambda *a, **k: show_port)
|
||||
|
||||
def test_create_interfaces(self, instance_uuid=None):
|
||||
|
|
|
@ -24,7 +24,7 @@ class FloatingIPPoolsSampleTests(api_sample_base.ApiSampleTestBaseV21):
|
|||
def fake_get_floating_ip_pools(self, context):
|
||||
return pool_list
|
||||
|
||||
self.stub_out('nova.network.neutronv2.api.API.get_floating_ip_pools',
|
||||
self.stub_out('nova.network.neutron.API.get_floating_ip_pools',
|
||||
fake_get_floating_ip_pools)
|
||||
response = self._do_get('os-floating-ip-pools')
|
||||
subs = {
|
||||
|
|
|
@ -33,7 +33,7 @@ class NetworksJsonTests(api_sample_base.ApiSampleTestBaseV21):
|
|||
response = self._do_get('os-networks/%s' % uuid)
|
||||
self._verify_response('network-show-resp', {}, response, 200)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API.get',
|
||||
@mock.patch('nova.network.neutron.API.get',
|
||||
side_effect=exception.Unauthorized)
|
||||
def test_network_show_token_expired(self, mock_get):
|
||||
uuid = nova_fixtures.NeutronFixture.network_1['id']
|
||||
|
|
|
@ -769,7 +769,7 @@ class ServersActionsJsonTest(ServersSampleBase, _ServersActionsJsonTestMixin):
|
|||
# This is gross, but we need to stub out the associate_floating_ip
|
||||
# call in the FloatingIPActionController since we don't have a real
|
||||
# networking service backing this up, just the fake neutron stubs.
|
||||
self.stub_out('nova.network.neutronv2.api.API.associate_floating_ip',
|
||||
self.stub_out('nova.network.neutron.API.associate_floating_ip',
|
||||
lambda *a, **k: None)
|
||||
self._test_server_action(uuid, 'addFloatingIp',
|
||||
'server-action-addfloatingip-req', subs)
|
||||
|
@ -783,15 +783,15 @@ class ServersActionsJsonTest(ServersSampleBase, _ServersActionsJsonTestMixin):
|
|||
}
|
||||
|
||||
self.stub_out(
|
||||
'nova.network.neutronv2.api.API.get_floating_ip_by_address',
|
||||
'nova.network.neutron.API.get_floating_ip_by_address',
|
||||
lambda *a, **k: {
|
||||
'fixed_ip_id': 'a0c566f0-faab-406f-b77f-2b286dc6dd7e'})
|
||||
self.stub_out(
|
||||
'nova.network.neutronv2.api.API.'
|
||||
'nova.network.neutron.API.'
|
||||
'get_instance_id_by_floating_address',
|
||||
lambda *a, **k: server_uuid)
|
||||
self.stub_out(
|
||||
'nova.network.neutronv2.api.API.disassociate_floating_ip',
|
||||
'nova.network.neutron.API.disassociate_floating_ip',
|
||||
lambda *a, **k: None)
|
||||
|
||||
self._test_server_action(server_uuid, 'removeFloatingIp',
|
||||
|
|
|
@ -71,7 +71,7 @@ class MetadataTest(test.TestCase):
|
|||
|
||||
self.useFixture(
|
||||
fixtures.MonkeyPatch(
|
||||
'nova.network.neutronv2.api.API.get_fixed_ip_by_address',
|
||||
'nova.network.neutron.API.get_fixed_ip_by_address',
|
||||
fake_get_fixed_ip_by_address))
|
||||
|
||||
def fake_get_ec2_ip_info(nw_info):
|
||||
|
|
|
@ -24,7 +24,7 @@ from nova.cmd import manage
|
|||
from nova import config
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova.network.neutronv2 import constants
|
||||
from nova.network import constants
|
||||
from nova import objects
|
||||
from nova import test
|
||||
from nova.tests import fixtures as nova_fixtures
|
||||
|
|
|
@ -37,8 +37,8 @@ from nova.compute import instance_actions
|
|||
from nova.compute import manager as compute_manager
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova.network.neutronv2 import api as neutronapi
|
||||
from nova.network.neutronv2 import constants
|
||||
from nova.network import constants
|
||||
from nova.network import neutron as neutronapi
|
||||
from nova import objects
|
||||
from nova.objects import block_device as block_device_obj
|
||||
from nova.scheduler import utils
|
||||
|
|
|
@ -69,8 +69,7 @@ class EvacuateTestV21(test.NoDBTestCase):
|
|||
self.stub_out('nova.compute.api.HostAPI.service_get_by_compute_host',
|
||||
fake_service_get_by_compute_host)
|
||||
self.mock_list_port = self.useFixture(
|
||||
fixtures.MockPatch(
|
||||
'nova.network.neutronv2.api.API.list_ports')).mock
|
||||
fixtures.MockPatch('nova.network.neutron.API.list_ports')).mock
|
||||
self.mock_list_port.return_value = {'ports': []}
|
||||
self.UUID = uuids.fake
|
||||
for _method in self._methods:
|
||||
|
@ -263,8 +262,7 @@ class EvacuatePolicyEnforcementv21(test.NoDBTestCase):
|
|||
self.stub_out(
|
||||
'nova.api.openstack.common.get_instance', fake_get_instance)
|
||||
self.mock_list_port = self.useFixture(
|
||||
fixtures.MockPatch(
|
||||
'nova.network.neutronv2.api.API.list_ports')).mock
|
||||
fixtures.MockPatch('nova.network.neutron.API.list_ports')).mock
|
||||
self.mock_list_port.return_value = {'ports': []}
|
||||
|
||||
def test_evacuate_policy_failed_with_other_project(self):
|
||||
|
|
|
@ -48,8 +48,7 @@ class MigrateServerTestsV21(admin_only_action_common.CommonTests):
|
|||
'MigrateServerController',
|
||||
lambda *a, **kw: self.controller)
|
||||
self.mock_list_port = self.useFixture(
|
||||
fixtures.MockPatch(
|
||||
'nova.network.neutronv2.api.API.list_ports')).mock
|
||||
fixtures.MockPatch('nova.network.neutron.API.list_ports')).mock
|
||||
self.mock_list_port.return_value = {'ports': []}
|
||||
|
||||
def _get_migration_body(self, **kwargs):
|
||||
|
|
|
@ -25,7 +25,7 @@ import webob
|
|||
from nova.api.openstack.compute import networks as networks_v21
|
||||
import nova.context
|
||||
from nova import exception
|
||||
from nova.network.neutronv2 import api as neutron
|
||||
from nova.network import neutron
|
||||
from nova import objects
|
||||
from nova import test
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
|
|
|
@ -28,7 +28,7 @@ from nova import context as context_maker
|
|||
import nova.db.api
|
||||
from nova import exception
|
||||
from nova.network import model
|
||||
from nova.network.neutronv2 import api as neutron_api
|
||||
from nova.network import neutron as neutron_api
|
||||
from nova import objects
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova import test
|
||||
|
@ -279,7 +279,7 @@ class MockClient(object):
|
|||
return {'security_groups': ret}
|
||||
|
||||
def list_networks(self, **_params):
|
||||
# neutronv2/api.py _get_available_networks calls this assuming
|
||||
# network/api.py _get_available_networks calls this assuming
|
||||
# search_opts filter "shared" is implemented and not ignored
|
||||
shared = _params.get("shared", None)
|
||||
if shared:
|
||||
|
|
|
@ -100,8 +100,7 @@ class ServerActionsControllerTestV21(test.TestCase):
|
|||
self.addCleanup(mock_conductor.stop)
|
||||
# Assume that none of the tests are using ports with resource requests.
|
||||
self.mock_list_port = self.useFixture(
|
||||
fixtures.MockPatch(
|
||||
'nova.network.neutronv2.api.API.list_ports')).mock
|
||||
fixtures.MockPatch('nova.network.neutron.API.list_ports')).mock
|
||||
self.mock_list_port.return_value = {'ports': []}
|
||||
|
||||
def _get_controller(self):
|
||||
|
|
|
@ -205,7 +205,7 @@ def stub_out_nw_api(test, cls=None, private=None, publics=None):
|
|||
if cls is None:
|
||||
cls = Fake
|
||||
|
||||
test.stub_out('nova.network.neutronv2.api.API', cls)
|
||||
test.stub_out('nova.network.neutron.API', cls)
|
||||
|
||||
|
||||
def stub_out_secgroup_api(test, security_groups=None):
|
||||
|
|
|
@ -29,7 +29,7 @@ from nova.compute import task_states
|
|||
from nova.compute import vm_states
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova import network
|
||||
from nova.network import neutron as network
|
||||
from nova import test
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
|
||||
|
|
|
@ -2335,8 +2335,7 @@ class TestNovaManagePlacement(test.NoDBTestCase):
|
|||
self.output = StringIO()
|
||||
self.useFixture(fixtures.MonkeyPatch('sys.stdout', self.output))
|
||||
self.cli = manage.PlacementCommands()
|
||||
self.useFixture(
|
||||
fixtures.MockPatch('nova.network.neutronv2.api.get_client'))
|
||||
self.useFixture(fixtures.MockPatch('nova.network.neutron.get_client'))
|
||||
|
||||
@ddt.data(-1, 0, "one")
|
||||
def test_heal_allocations_invalid_max_count(self, max_count):
|
||||
|
|
|
@ -239,12 +239,10 @@ class BaseTestCase(test.TestCase):
|
|||
def fake_get_nw_info(cls, ctxt, instance, *args, **kwargs):
|
||||
return network_model.NetworkInfo()
|
||||
|
||||
self.stub_out(
|
||||
'nova.network.neutronv2.api.API.get_instance_nw_info',
|
||||
fake_get_nw_info)
|
||||
self.stub_out(
|
||||
'nova.network.neutronv2.api.API.migrate_instance_start',
|
||||
lambda *args, **kwargs: None)
|
||||
self.stub_out('nova.network.neutron.API.get_instance_nw_info',
|
||||
fake_get_nw_info)
|
||||
self.stub_out('nova.network.neutron.API.migrate_instance_start',
|
||||
lambda *args, **kwargs: None)
|
||||
self.useFixture(fixtures.NeutronFixture(self))
|
||||
|
||||
self.compute_api = compute.API()
|
||||
|
@ -6079,8 +6077,7 @@ class ComputeTestCase(BaseTestCase,
|
|||
def stupid(*args, **kwargs):
|
||||
return fake_network.fake_get_instance_nw_info(self)
|
||||
|
||||
self.stub_out(
|
||||
'nova.network.neutronv2.api.API.get_instance_nw_info', stupid)
|
||||
self.stub_out('nova.network.neutron.API.get_instance_nw_info', stupid)
|
||||
|
||||
# creating instance testdata
|
||||
instance = self._create_fake_instance_obj({'host': 'dummy'})
|
||||
|
@ -7075,7 +7072,7 @@ class ComputeTestCase(BaseTestCase,
|
|||
mock_is_older.assert_called_once_with(now,
|
||||
CONF.running_deleted_instance_timeout)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API.list_ports')
|
||||
@mock.patch('nova.network.neutron.API.list_ports')
|
||||
def test_require_nw_info_update_host_match(self, mock_list_ports):
|
||||
ctxt = context.get_admin_context()
|
||||
instance = self._create_fake_instance_obj()
|
||||
|
@ -7092,7 +7089,7 @@ class ComputeTestCase(BaseTestCase,
|
|||
self.assertFalse(val)
|
||||
mock_list_ports.assert_called_once_with(ctxt, **search_opts)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API.list_ports')
|
||||
@mock.patch('nova.network.neutron.API.list_ports')
|
||||
def test_require_nw_info_update_host_mismatch(self, mock_list_ports):
|
||||
ctxt = context.get_admin_context()
|
||||
instance = self._create_fake_instance_obj()
|
||||
|
@ -7105,7 +7102,7 @@ class ComputeTestCase(BaseTestCase,
|
|||
self.assertTrue(val)
|
||||
mock_list_ports.assert_called_once_with(ctxt, **search_opts)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API.list_ports')
|
||||
@mock.patch('nova.network.neutron.API.list_ports')
|
||||
def test_require_nw_info_update_failed_vif_types(self, mock_list_ports):
|
||||
ctxt = context.get_admin_context()
|
||||
instance = self._create_fake_instance_obj()
|
||||
|
@ -7218,10 +7215,10 @@ class ComputeTestCase(BaseTestCase,
|
|||
fake_require_nw_info_update)
|
||||
|
||||
self.stub_out(
|
||||
'nova.network.neutronv2.api.API.get_instance_nw_info',
|
||||
'nova.network.neutron.API.get_instance_nw_info',
|
||||
fake_get_instance_nw_info)
|
||||
self.stub_out(
|
||||
'nova.network.neutronv2.api.API.setup_instance_network_on_host',
|
||||
'nova.network.neutron.API.setup_instance_network_on_host',
|
||||
fake_setup_instance_network_on_host)
|
||||
|
||||
expected_require_nw_info = 0
|
||||
|
@ -11405,8 +11402,8 @@ class ComputeAPIIpFilterTestCase(test.NoDBTestCase):
|
|||
@mock.patch.object(objects.BuildRequestList, 'get_by_filters')
|
||||
@mock.patch.object(objects.CellMapping, 'get_by_uuid',
|
||||
side_effect=exception.CellMappingNotFound(uuid=uuids.volume))
|
||||
@mock.patch('nova.network.neutronv2.api.API.'
|
||||
'has_substr_port_filtering_extension', return_value=False)
|
||||
@mock.patch('nova.network.neutron.API.has_substr_port_filtering_extension',
|
||||
return_value=False)
|
||||
def test_ip_filtering_no_limit_to_db(self, mock_has_port_filter_ext,
|
||||
_mock_cell_map_get,
|
||||
mock_buildreq_get):
|
||||
|
|
|
@ -42,9 +42,9 @@ from nova import context
|
|||
from nova.db import api as db
|
||||
from nova import exception
|
||||
from nova.image import api as image_api
|
||||
from nova.network import constants
|
||||
from nova.network import model
|
||||
from nova.network.neutronv2 import api as neutron_api
|
||||
from nova.network.neutronv2 import constants
|
||||
from nova.network import neutron as neutron_api
|
||||
from nova import objects
|
||||
from nova.objects import base as obj_base
|
||||
from nova.objects import block_device as block_device_obj
|
||||
|
@ -314,7 +314,7 @@ class _ComputeAPIUnitTestMixIn(object):
|
|||
max_count = 3
|
||||
self._test_create_max_net_count(max_net_count, min_count, max_count)
|
||||
|
||||
def test_specified_port_and_multiple_instances_neutronv2(self):
|
||||
def test_specified_port_and_multiple_instances(self):
|
||||
# Tests that if port is specified there is only one instance booting
|
||||
# (i.e max_count == 1) as we can't share the same port across multiple
|
||||
# instances.
|
||||
|
@ -351,15 +351,6 @@ class _ComputeAPIUnitTestMixIn(object):
|
|||
self._test_specified_ip_and_multiple_instances_helper(
|
||||
requested_networks)
|
||||
|
||||
def test_specified_ip_and_multiple_instances_neutronv2(self):
|
||||
network = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
|
||||
address = '10.0.0.1'
|
||||
requested_networks = objects.NetworkRequestList(
|
||||
objects=[objects.NetworkRequest(network_id=network,
|
||||
address=address)])
|
||||
self._test_specified_ip_and_multiple_instances_helper(
|
||||
requested_networks)
|
||||
|
||||
@mock.patch('nova.objects.BlockDeviceMapping.save')
|
||||
@mock.patch.object(compute_rpcapi.ComputeAPI, 'reserve_block_device_name')
|
||||
def test_create_volume_bdm_call_reserve_dev_name(self, mock_reserve,
|
||||
|
@ -1648,8 +1639,7 @@ class _ComputeAPIUnitTestMixIn(object):
|
|||
def test_confirm_resize_with_migration_ref(self):
|
||||
self._test_confirm_resize(mig_ref_passed=True)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API.'
|
||||
'get_requested_resource_for_instance',
|
||||
@mock.patch('nova.network.neutron.API.get_requested_resource_for_instance',
|
||||
return_value=mock.sentinel.res_req)
|
||||
@mock.patch('nova.availability_zones.get_host_availability_zone',
|
||||
return_value='nova')
|
||||
|
@ -1710,8 +1700,7 @@ class _ComputeAPIUnitTestMixIn(object):
|
|||
def test_revert_resize(self):
|
||||
self._test_revert_resize()
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API.'
|
||||
'get_requested_resource_for_instance')
|
||||
@mock.patch('nova.network.neutron.API.get_requested_resource_for_instance')
|
||||
@mock.patch('nova.availability_zones.get_host_availability_zone',
|
||||
return_value='nova')
|
||||
@mock.patch('nova.objects.Quotas.check_deltas')
|
||||
|
|
|
@ -49,7 +49,7 @@ from nova import context
|
|||
from nova.db import api as db
|
||||
from nova import exception
|
||||
from nova.network import model as network_model
|
||||
from nova.network.neutronv2 import api as neutronv2_api
|
||||
from nova.network import neutron as neutronv2_api
|
||||
from nova import objects
|
||||
from nova.objects import base as base_obj
|
||||
from nova.objects import block_device as block_device_obj
|
||||
|
@ -3441,7 +3441,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
|
|||
inst_obj = objects.Instance(id=3, uuid=uuids.instance,
|
||||
info_cache=info_cache)
|
||||
|
||||
@mock.patch.object(manager.base_net_api,
|
||||
@mock.patch.object(manager.neutron,
|
||||
'update_instance_cache_with_nw_info')
|
||||
@mock.patch.object(self.compute.driver, 'detach_interface')
|
||||
def do_test(detach_interface, update_instance_cache_with_nw_info):
|
||||
|
@ -3468,7 +3468,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
|
|||
inst_obj = objects.Instance(id=3, uuid=uuids.instance,
|
||||
info_cache=info_cache)
|
||||
|
||||
@mock.patch.object(manager.base_net_api,
|
||||
@mock.patch.object(manager.neutron,
|
||||
'update_instance_cache_with_nw_info')
|
||||
@mock.patch.object(self.compute.driver, 'detach_interface',
|
||||
side_effect=NotImplementedError)
|
||||
|
@ -3496,7 +3496,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
|
|||
inst_obj = objects.Instance(id=3, uuid=uuids.instance,
|
||||
info_cache=info_cache)
|
||||
|
||||
@mock.patch.object(manager.base_net_api,
|
||||
@mock.patch.object(manager.neutron,
|
||||
'update_instance_cache_with_nw_info')
|
||||
@mock.patch.object(self.compute.driver, 'detach_interface',
|
||||
side_effect=exception.InstanceNotFound(
|
||||
|
@ -3818,7 +3818,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
|
|||
@mock.patch.object(instances[3], 'obj_load_attr',
|
||||
side_effect=exception.InstanceNotFound(
|
||||
instance_id=uuids.instance_4))
|
||||
@mock.patch.object(manager.base_net_api,
|
||||
@mock.patch.object(manager.neutron,
|
||||
'update_instance_cache_with_nw_info')
|
||||
@mock.patch.object(self.compute.driver, 'detach_interface',
|
||||
side_effect=exception.NovaException)
|
||||
|
@ -5046,9 +5046,8 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
|
|||
@mock.patch('nova.objects.instance.Instance.apply_migration_context')
|
||||
@mock.patch('nova.objects.instance.Instance.mutated_migration_context')
|
||||
@mock.patch('nova.objects.BlockDeviceMappingList.get_by_instance_uuid')
|
||||
@mock.patch('nova.network.neutronv2.api.API.'
|
||||
'setup_instance_network_on_host')
|
||||
@mock.patch('nova.network.neutronv2.api.API.setup_networks_on_host')
|
||||
@mock.patch('nova.network.neutron.API.setup_instance_network_on_host')
|
||||
@mock.patch('nova.network.neutron.API.setup_networks_on_host')
|
||||
@mock.patch('nova.objects.instance.Instance.save')
|
||||
@mock.patch('nova.compute.utils.notify_about_instance_rebuild')
|
||||
@mock.patch('nova.compute.utils.notify_about_instance_usage')
|
||||
|
|
|
@ -25,7 +25,7 @@ from nova.compute import vm_states
|
|||
import nova.conf
|
||||
from nova.db import api as db
|
||||
from nova import exception
|
||||
from nova.network.neutronv2 import api as neutron_api
|
||||
from nova.network import neutron as neutron_api
|
||||
from nova import objects
|
||||
from nova import test
|
||||
from nova.tests.unit.compute import test_compute
|
||||
|
|
|
@ -77,7 +77,7 @@ class LiveMigrationTaskTestCase(test.NoDBTestCase):
|
|||
self.addCleanup(_p.stop)
|
||||
|
||||
_p = mock.patch(
|
||||
'nova.network.neutronv2.api.API.'
|
||||
'nova.network.neutron.API.'
|
||||
'get_requested_resource_for_instance',
|
||||
return_value=[])
|
||||
self.mock_get_res_req = _p.start()
|
||||
|
@ -662,7 +662,7 @@ class LiveMigrationTaskTestCase(test.NoDBTestCase):
|
|||
|
||||
_test()
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API.bind_ports_to_host')
|
||||
@mock.patch('nova.network.neutron.API.bind_ports_to_host')
|
||||
def test_bind_ports_on_destination_merges_profiles(self, mock_bind_ports):
|
||||
"""Assert that if both the migration_data and the provider mapping
|
||||
contains binding profile related information then such information is
|
||||
|
@ -686,7 +686,7 @@ class LiveMigrationTaskTestCase(test.NoDBTestCase):
|
|||
port_profiles={uuids.port1: {'allocation': uuids.dest_bw_rp,
|
||||
'some-key': 'value'}})
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API.bind_ports_to_host')
|
||||
@mock.patch('nova.network.neutron.API.bind_ports_to_host')
|
||||
def test_bind_ports_on_destination_migration_data(self, mock_bind_ports):
|
||||
"""Assert that if only the migration_data contains binding profile
|
||||
related information then that is sent to neutron.
|
||||
|
@ -708,7 +708,7 @@ class LiveMigrationTaskTestCase(test.NoDBTestCase):
|
|||
vnic_types=None,
|
||||
port_profiles={uuids.port1: {'some-key': 'value'}})
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API.bind_ports_to_host')
|
||||
@mock.patch('nova.network.neutron.API.bind_ports_to_host')
|
||||
def test_bind_ports_on_destination_provider_mapping(self, mock_bind_ports):
|
||||
"""Assert that if only the provider mapping contains binding
|
||||
profile related information then that is sent to neutron.
|
||||
|
|
|
@ -1517,7 +1517,7 @@ class _BaseTaskTestCase(object):
|
|||
'select_destinations'),
|
||||
mock.patch('nova.scheduler.utils.fill_provider_mapping',
|
||||
new_callable=mock.NonCallableMock),
|
||||
mock.patch('nova.network.neutronv2.api.API.'
|
||||
mock.patch('nova.network.neutron.API.'
|
||||
'get_requested_resource_for_instance',
|
||||
new_callable=mock.NonCallableMock)
|
||||
) as (rebuild_mock, select_dest_mock, fill_provider_mock,
|
||||
|
@ -1736,10 +1736,9 @@ class _BaseTaskTestCase(object):
|
|||
return_value=[[fake_selection]]),
|
||||
mock.patch.object(fake_spec, 'reset_forced_destinations'),
|
||||
mock.patch('nova.scheduler.utils.fill_provider_mapping'),
|
||||
mock.patch(
|
||||
'nova.network.neutronv2.api.API.'
|
||||
'get_requested_resource_for_instance',
|
||||
return_value=[])
|
||||
mock.patch('nova.network.neutron.API.'
|
||||
'get_requested_resource_for_instance',
|
||||
return_value=[])
|
||||
) as (rebuild_mock, sig_mock, select_dest_mock, reset_fd,
|
||||
fill_rp_mapping_mock, get_req_res_mock):
|
||||
self.conductor_manager.rebuild_instance(context=self.context,
|
||||
|
|
|
@ -35,7 +35,7 @@ class TestNeutronDriver(test.NoDBTestCase):
|
|||
'auth_token',
|
||||
'bff4a5a6b9eb4ea2a6efec6eefb77936')
|
||||
self.mocked_client = mock.Mock(spec=client.Client)
|
||||
self.stub_out('nova.network.neutronv2.api.get_client',
|
||||
self.stub_out('nova.network.neutron.get_client',
|
||||
lambda context: self.mocked_client)
|
||||
|
||||
def test_list_with_project(self):
|
||||
|
|
|
@ -38,9 +38,9 @@ from six.moves import range
|
|||
from nova import context
|
||||
from nova.db.sqlalchemy import api as db_api
|
||||
from nova import exception
|
||||
from nova.network import constants
|
||||
from nova.network import model
|
||||
from nova.network.neutronv2 import api as neutronapi
|
||||
from nova.network.neutronv2 import constants
|
||||
from nova.network import neutron as neutronapi
|
||||
from nova import objects
|
||||
from nova.objects import network_request as net_req_obj
|
||||
from nova.objects import virtual_interface as obj_vif
|
||||
|
@ -203,7 +203,7 @@ class TestNeutronClient(test.NoDBTestCase):
|
|||
neutronapi.get_client,
|
||||
my_context)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._ADMIN_AUTH')
|
||||
@mock.patch('nova.network.neutron._ADMIN_AUTH')
|
||||
@mock.patch.object(client.Client, "list_networks", new=mock.Mock())
|
||||
def test_reuse_admin_token(self, m):
|
||||
self.flags(endpoint_override='http://anyhost/', group='neutron')
|
||||
|
@ -225,7 +225,7 @@ class TestNeutronClient(test.NoDBTestCase):
|
|||
client1.list_networks(retrieve_all=False)
|
||||
self.assertEqual('new_token2', client1.httpclient.auth.get_token(None))
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.LOG.error')
|
||||
@mock.patch('nova.network.neutron.LOG.error')
|
||||
@mock.patch.object(ks_loading, 'load_auth_from_conf_options')
|
||||
def test_load_auth_plugin_failed(self, mock_load_from_conf, mock_log_err):
|
||||
mock_load_from_conf.return_value = None
|
||||
|
@ -247,10 +247,10 @@ class TestNeutronClient(test.NoDBTestCase):
|
|||
client.list_networks)
|
||||
|
||||
|
||||
class TestNeutronv2Base(test.TestCase):
|
||||
class TestAPIBase(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestNeutronv2Base, self).setUp()
|
||||
super(TestAPIBase, self).setUp()
|
||||
self.api = neutronapi.API()
|
||||
self.context = context.RequestContext(
|
||||
'userid', uuids.my_tenant,
|
||||
|
@ -762,8 +762,8 @@ class TestNeutronv2Base(test.TestCase):
|
|||
return expected_create_port_calls
|
||||
|
||||
|
||||
class TestNeutronv2(TestNeutronv2Base):
|
||||
"""Used to test Neutron V2 API with mock."""
|
||||
class TestAPI(TestAPIBase):
|
||||
"""Used to test Neutron V2 API."""
|
||||
|
||||
@mock.patch.object(db_api, 'instance_info_cache_get')
|
||||
@mock.patch.object(db_api, 'instance_info_cache_update',
|
||||
|
@ -1280,10 +1280,9 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.assertEqual(2, mocked_client.list_networks.call_count)
|
||||
|
||||
@mock.patch.object(neutronapi, 'get_client')
|
||||
@mock.patch(
|
||||
'nova.network.neutronv2.api.API._populate_neutron_extension_values')
|
||||
@mock.patch('nova.network.neutronv2.api.API._create_ports_for_instance')
|
||||
@mock.patch('nova.network.neutronv2.api.API._unbind_ports')
|
||||
@mock.patch('nova.network.neutron.API._populate_neutron_extension_values')
|
||||
@mock.patch('nova.network.neutron.API._create_ports_for_instance')
|
||||
@mock.patch('nova.network.neutron.API._unbind_ports')
|
||||
def test_allocate_for_instance_ex1(self, mock_unbind, mock_create_ports,
|
||||
mock_populate, mock_get_client):
|
||||
"""Verify we will delete created ports if we fail to allocate all net
|
||||
|
@ -1596,7 +1595,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
mock_cache_update.assert_called_once_with(
|
||||
self.context, self.instance.uuid, {'network_info': '[]'})
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._get_preexisting_port_ids')
|
||||
@mock.patch('nova.network.neutron.API._get_preexisting_port_ids')
|
||||
def test_deallocate_for_instance_1_with_requested(self, mock_preexisting):
|
||||
mock_preexisting.return_value = []
|
||||
requested = objects.NetworkRequestList(
|
||||
|
@ -1607,7 +1606,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self._test_deallocate_for_instance(1, requested_networks=requested)
|
||||
mock_preexisting.assert_called_once_with(self.instance)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._get_preexisting_port_ids')
|
||||
@mock.patch('nova.network.neutron.API._get_preexisting_port_ids')
|
||||
def test_deallocate_for_instance_2_with_requested(self, mock_preexisting):
|
||||
mock_preexisting.return_value = []
|
||||
requested = objects.NetworkRequestList(
|
||||
|
@ -1618,14 +1617,14 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self._test_deallocate_for_instance(2, requested_networks=requested)
|
||||
mock_preexisting.assert_called_once_with(self.instance)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._get_preexisting_port_ids')
|
||||
@mock.patch('nova.network.neutron.API._get_preexisting_port_ids')
|
||||
def test_deallocate_for_instance_1(self, mock_preexisting):
|
||||
mock_preexisting.return_value = []
|
||||
# Test to deallocate in one port env.
|
||||
self._test_deallocate_for_instance(1)
|
||||
mock_preexisting.assert_called_once_with(self.instance)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._get_preexisting_port_ids')
|
||||
@mock.patch('nova.network.neutron.API._get_preexisting_port_ids')
|
||||
def test_deallocate_for_instance_2(self, mock_preexisting):
|
||||
mock_preexisting.return_value = []
|
||||
# Test to deallocate in two ports env.
|
||||
|
@ -1633,7 +1632,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
mock_preexisting.assert_called_once_with(self.instance)
|
||||
|
||||
@mock.patch.object(neutronapi, 'get_client')
|
||||
@mock.patch('nova.network.neutronv2.api.API._get_preexisting_port_ids')
|
||||
@mock.patch('nova.network.neutron.API._get_preexisting_port_ids')
|
||||
def test_deallocate_for_instance_port_not_found(self,
|
||||
mock_preexisting,
|
||||
mock_get_client):
|
||||
|
@ -3280,11 +3279,11 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
mock.call(self.context, mocked_client, 'net-id')] * 6)
|
||||
|
||||
@mock.patch.object(neutronapi, 'get_client')
|
||||
@mock.patch('nova.network.neutronv2.api.API._nw_info_get_subnets')
|
||||
@mock.patch('nova.network.neutronv2.api.API._nw_info_get_ips')
|
||||
@mock.patch('nova.network.neutronv2.api.API._nw_info_build_network')
|
||||
@mock.patch('nova.network.neutronv2.api.API._get_preexisting_port_ids')
|
||||
@mock.patch('nova.network.neutronv2.api.API._gather_port_ids_and_networks')
|
||||
@mock.patch('nova.network.neutron.API._nw_info_get_subnets')
|
||||
@mock.patch('nova.network.neutron.API._nw_info_get_ips')
|
||||
@mock.patch('nova.network.neutron.API._nw_info_build_network')
|
||||
@mock.patch('nova.network.neutron.API._get_preexisting_port_ids')
|
||||
@mock.patch('nova.network.neutron.API._gather_port_ids_and_networks')
|
||||
def test_build_network_info_model_empty(
|
||||
self, mock_gather_port_ids_and_networks,
|
||||
mock_get_preexisting_port_ids,
|
||||
|
@ -3606,7 +3605,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.assertTrue(trusted)
|
||||
self.assertIsNone(resource_requests)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._show_port')
|
||||
@mock.patch('nova.network.neutron.API._show_port')
|
||||
def test_deferred_ip_port_immediate_allocation(self, mock_show):
|
||||
port = {'network_id': 'my_netid1',
|
||||
'device_id': None,
|
||||
|
@ -3622,7 +3621,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.api.validate_networks,
|
||||
self.context, requested_networks, 1)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._show_port')
|
||||
@mock.patch('nova.network.neutron.API._show_port')
|
||||
def test_deferred_ip_port_deferred_allocation(self, mock_show):
|
||||
port = {'network_id': 'my_netid1',
|
||||
'device_id': None,
|
||||
|
@ -3646,7 +3645,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
api.get_instance_nw_info, 'context', instance)
|
||||
mock_lock.assert_called_once_with('refresh_cache-%s' % instance.uuid)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.LOG')
|
||||
@mock.patch('nova.network.neutron.LOG')
|
||||
def test_get_instance_nw_info_verify_duplicates_ignored(self, mock_log):
|
||||
"""test that the returned networks & port_ids from
|
||||
_gather_port_ids_and_networks doesn't contain any duplicates
|
||||
|
@ -3700,7 +3699,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
|
||||
@mock.patch('oslo_concurrency.lockutils.lock')
|
||||
@mock.patch.object(neutronapi.API, '_get_instance_nw_info')
|
||||
@mock.patch('nova.network.base_api.update_instance_cache_with_nw_info')
|
||||
@mock.patch('nova.network.neutron.update_instance_cache_with_nw_info')
|
||||
def test_get_instance_nw_info(self, mock_update, mock_get, mock_lock):
|
||||
fake_result = mock.sentinel.get_nw_info_result
|
||||
mock_get.return_value = fake_result
|
||||
|
@ -3881,8 +3880,8 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
api.allocate_floating_ip, self.context,
|
||||
'ext_net')
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutronv2.api.API._get_floating_ip_by_address',
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
@mock.patch('nova.network.neutron.API._get_floating_ip_by_address',
|
||||
return_value={'port_id': None, 'id': 'abc'})
|
||||
def test_release_floating_ip(self, mock_get_ip, mock_ntrn):
|
||||
"""Validate default behavior."""
|
||||
|
@ -3896,8 +3895,8 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
mock_get_ip.assert_called_once_with(mock_nc, address)
|
||||
mock_nc.delete_floatingip.assert_called_once_with('abc')
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutronv2.api.API._get_floating_ip_by_address',
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
@mock.patch('nova.network.neutron.API._get_floating_ip_by_address',
|
||||
return_value={'port_id': 'abc', 'id': 'abc'})
|
||||
def test_release_floating_ip_associated(self, mock_get_ip, mock_ntrn):
|
||||
"""Ensure release fails if a port is still associated with it.
|
||||
|
@ -3913,8 +3912,8 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.api.release_floating_ip,
|
||||
self.context, address)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutronv2.api.API._get_floating_ip_by_address',
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
@mock.patch('nova.network.neutron.API._get_floating_ip_by_address',
|
||||
return_value={'port_id': None, 'id': 'abc'})
|
||||
def test_release_floating_ip_not_found(self, mock_get_ip, mock_ntrn):
|
||||
"""Ensure neutron's NotFound exception is correctly handled.
|
||||
|
@ -4060,7 +4059,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.assertEqual(expected_exception_msg, six.text_type(exc))
|
||||
mock_client.delete_port.assert_called_once_with(uuids.port_id)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.LOG')
|
||||
@mock.patch('nova.network.neutron.LOG')
|
||||
def test_create_port_minimal_raise_qos_not_supported_cleanup_fails(
|
||||
self, mock_log):
|
||||
instance = fake_instance.fake_instance_obj(self.context)
|
||||
|
@ -4098,8 +4097,8 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
network_uuid)
|
||||
fake_show_network.assert_called_once_with(network_uuid)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._get_preexisting_port_ids')
|
||||
@mock.patch('nova.network.neutronv2.api.API.'
|
||||
@mock.patch('nova.network.neutron.API._get_preexisting_port_ids')
|
||||
@mock.patch('nova.network.neutron.API.'
|
||||
'_refresh_neutron_extensions_cache')
|
||||
def test_deallocate_for_instance_uses_delete_helper(self,
|
||||
mock_refresh,
|
||||
|
@ -4152,7 +4151,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
raise_if_fail=True)
|
||||
mock_client.delete_port.assert_called_once_with('port1')
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._get_preexisting_port_ids')
|
||||
@mock.patch('nova.network.neutron.API._get_preexisting_port_ids')
|
||||
def test_deallocate_port_for_instance_fails(self, mock_preexisting):
|
||||
mock_preexisting.return_value = []
|
||||
mock_client = mock.Mock()
|
||||
|
@ -4956,16 +4955,16 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.assertEqual(1, mock_neutron.call_count)
|
||||
mock_neutron.assert_has_calls(get_client_calls, True)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_unbind_ports_get_client_binding_extension(self,
|
||||
mock_neutron):
|
||||
self._test_unbind_ports_get_client(mock_neutron)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_unbind_ports_get_client(self, mock_neutron):
|
||||
self._test_unbind_ports_get_client(mock_neutron)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._show_port')
|
||||
@mock.patch('nova.network.neutron.API._show_port')
|
||||
def _test_unbind_ports(self, mock_neutron, mock_show):
|
||||
mock_client = mock.Mock()
|
||||
mock_update_port = mock.Mock()
|
||||
|
@ -4986,11 +4985,11 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.assertEqual(3, mock_update_port.call_count)
|
||||
mock_update_port.assert_has_calls(update_port_calls)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_unbind_ports_binding_ext(self, mock_neutron):
|
||||
self._test_unbind_ports(mock_neutron)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_unbind_ports(self, mock_neutron):
|
||||
self._test_unbind_ports(mock_neutron)
|
||||
|
||||
|
@ -5005,17 +5004,15 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
api._unbind_ports(mock_ctx, [None], mock_client, mock_client)
|
||||
self.assertFalse(mock_update_port.called)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API.get_instance_nw_info')
|
||||
@mock.patch('nova.network.neutronv2.api.excutils')
|
||||
@mock.patch('nova.network.neutronv2.api.API._delete_ports')
|
||||
@mock.patch('nova.network.neutronv2.api.API.'
|
||||
'_check_external_network_attach')
|
||||
@mock.patch('nova.network.neutronv2.api.LOG')
|
||||
@mock.patch('nova.network.neutronv2.api.API._unbind_ports')
|
||||
@mock.patch('nova.network.neutronv2.api.API.'
|
||||
'_populate_neutron_extension_values')
|
||||
@mock.patch('nova.network.neutronv2.api.API._get_available_networks')
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.API.get_instance_nw_info')
|
||||
@mock.patch('nova.network.neutron.excutils')
|
||||
@mock.patch('nova.network.neutron.API._delete_ports')
|
||||
@mock.patch('nova.network.neutron.API._check_external_network_attach')
|
||||
@mock.patch('nova.network.neutron.LOG')
|
||||
@mock.patch('nova.network.neutron.API._unbind_ports')
|
||||
@mock.patch('nova.network.neutron.API._populate_neutron_extension_values')
|
||||
@mock.patch('nova.network.neutron.API._get_available_networks')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
@mock.patch('nova.objects.VirtualInterface')
|
||||
def test_allocate_for_instance_unbind(self, mock_vif,
|
||||
mock_ntrn,
|
||||
|
@ -5062,9 +5059,9 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
mock.ANY,
|
||||
mock.ANY)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._validate_requested_port_ids')
|
||||
@mock.patch('nova.network.neutronv2.api.API._get_available_networks')
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.API._validate_requested_port_ids')
|
||||
@mock.patch('nova.network.neutron.API._get_available_networks')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_allocate_port_for_instance_no_networks(self,
|
||||
mock_getclient,
|
||||
mock_avail_nets,
|
||||
|
@ -5094,19 +5091,17 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
req_nets_in_call = mock_allocate.call_args[1]['requested_networks']
|
||||
self.assertEqual('foo', req_nets_in_call.objects[0].tag)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.LOG')
|
||||
@mock.patch('nova.network.neutronv2.api.base_api')
|
||||
@mock.patch('nova.network.neutronv2.api.API._delete_ports')
|
||||
@mock.patch('nova.network.neutronv2.api.API._unbind_ports')
|
||||
@mock.patch('nova.network.neutronv2.api.API._get_preexisting_port_ids')
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.LOG')
|
||||
@mock.patch('nova.network.neutron.API._delete_ports')
|
||||
@mock.patch('nova.network.neutron.API._unbind_ports')
|
||||
@mock.patch('nova.network.neutron.API._get_preexisting_port_ids')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
@mock.patch.object(objects.VirtualInterface, 'delete_by_instance_uuid')
|
||||
def test_preexisting_deallocate_for_instance(self, mock_delete_vifs,
|
||||
mock_ntrn,
|
||||
mock_gppids,
|
||||
mock_unbind,
|
||||
mock_deletep,
|
||||
mock_baseapi,
|
||||
mock_log):
|
||||
mock_inst = mock.Mock(project_id="proj-1",
|
||||
availability_zone='zone-1',
|
||||
|
@ -5137,11 +5132,11 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
raise_if_fail=True)
|
||||
mock_delete_vifs.assert_called_once_with(mock.sentinel.ctx, 'inst-1')
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._delete_nic_metadata')
|
||||
@mock.patch('nova.network.neutronv2.api.API.get_instance_nw_info')
|
||||
@mock.patch('nova.network.neutronv2.api.API._unbind_ports')
|
||||
@mock.patch('nova.network.neutron.API._delete_nic_metadata')
|
||||
@mock.patch('nova.network.neutron.API.get_instance_nw_info')
|
||||
@mock.patch('nova.network.neutron.API._unbind_ports')
|
||||
@mock.patch('nova.objects.Instance.get_network_info')
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
@mock.patch.object(objects.VirtualInterface, 'get_by_uuid')
|
||||
def test_preexisting_deallocate_port_for_instance(self,
|
||||
mock_get_vif_by_uuid,
|
||||
|
@ -5173,10 +5168,10 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
vif.destroy.assert_called_once_with()
|
||||
self.assertEqual({}, port_allocation)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API.get_instance_nw_info')
|
||||
@mock.patch('nova.network.neutronv2.api.API._delete_nic_metadata')
|
||||
@mock.patch('nova.network.neutron.API.get_instance_nw_info')
|
||||
@mock.patch('nova.network.neutron.API._delete_nic_metadata')
|
||||
@mock.patch.object(objects.VirtualInterface, 'get_by_uuid')
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_deallocate_port_for_instance_port_with_allocation(
|
||||
self, mock_get_client, mock_get_vif_by_uuid, mock_del_nic_meta,
|
||||
mock_netinfo):
|
||||
|
@ -5217,10 +5212,10 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
},
|
||||
port_allocation)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API.get_instance_nw_info')
|
||||
@mock.patch('nova.network.neutronv2.api.API._delete_nic_metadata')
|
||||
@mock.patch('nova.network.neutron.API.get_instance_nw_info')
|
||||
@mock.patch('nova.network.neutron.API._delete_nic_metadata')
|
||||
@mock.patch.object(objects.VirtualInterface, 'get_by_uuid')
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_deallocate_port_for_instance_port_already_deleted(
|
||||
self, mock_get_client, mock_get_vif_by_uuid, mock_del_nic_meta,
|
||||
mock_netinfo):
|
||||
|
@ -5262,12 +5257,10 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.assertEqual(0, len(instance.device_metadata.devices))
|
||||
instance.save.assert_called_once_with()
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API.'
|
||||
'_check_external_network_attach')
|
||||
@mock.patch('nova.network.neutronv2.api.API.'
|
||||
'_populate_neutron_extension_values')
|
||||
@mock.patch('nova.network.neutronv2.api.API._get_available_networks')
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.API._check_external_network_attach')
|
||||
@mock.patch('nova.network.neutron.API._populate_neutron_extension_values')
|
||||
@mock.patch('nova.network.neutron.API._get_available_networks')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_port_binding_failed_created_port(self, mock_ntrn,
|
||||
mock_avail_nets,
|
||||
mock_ext_vals,
|
||||
|
@ -5291,8 +5284,8 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
mock_inst, False, None)
|
||||
mock_nc.delete_port.assert_called_once_with(uuids.portid_1)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._show_port')
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.API._show_port')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_port_binding_failed_with_request(self, mock_ntrn,
|
||||
mock_show_port):
|
||||
mock_nc = mock.Mock()
|
||||
|
@ -5313,11 +5306,10 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
requested_networks=nw_req)
|
||||
|
||||
@mock.patch('nova.objects.virtual_interface.VirtualInterface.create')
|
||||
@mock.patch('nova.network.neutronv2.api.API.'
|
||||
'_check_external_network_attach')
|
||||
@mock.patch('nova.network.neutronv2.api.API._show_port')
|
||||
@mock.patch('nova.network.neutronv2.api.API._update_port')
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.API._check_external_network_attach')
|
||||
@mock.patch('nova.network.neutron.API._show_port')
|
||||
@mock.patch('nova.network.neutron.API._update_port')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_port_with_resource_request_has_allocation_in_binding(
|
||||
self, mock_get_client, mock_update_port, mock_show_port,
|
||||
mock_check_external, mock_vif_create):
|
||||
|
@ -5361,7 +5353,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
mock.sentinel.ctx, uuids.portid_1,
|
||||
neutron_client=mock_get_client.return_value)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_get_floating_ip_by_address_not_found_neutron_not_found(self,
|
||||
mock_ntrn):
|
||||
mock_nc = mock.Mock()
|
||||
|
@ -5372,7 +5364,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.api.get_floating_ip_by_address,
|
||||
self.context, address)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_get_floating_ip_by_address_not_found_neutron_raises_non404(self,
|
||||
mock_ntrn):
|
||||
mock_nc = mock.Mock()
|
||||
|
@ -5383,7 +5375,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.api.get_floating_ip_by_address,
|
||||
self.context, address)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_get_floating_ips_by_project_not_found(self, mock_ntrn):
|
||||
mock_nc = mock.Mock()
|
||||
mock_ntrn.return_value = mock_nc
|
||||
|
@ -5391,7 +5383,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
fips = self.api.get_floating_ips_by_project(self.context)
|
||||
self.assertEqual([], fips)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_get_floating_ips_by_project_not_found_legacy(self, mock_ntrn):
|
||||
# FIXME(danms): Remove this test along with the code path it tests
|
||||
# when bug 1513879 is fixed.
|
||||
|
@ -5404,7 +5396,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
fips = self.api.get_floating_ips_by_project(self.context)
|
||||
self.assertEqual([], fips)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_get_floating_ips_by_project_raises_non404(self, mock_ntrn):
|
||||
mock_nc = mock.Mock()
|
||||
mock_ntrn.return_value = mock_nc
|
||||
|
@ -5413,7 +5405,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.api.get_floating_ips_by_project,
|
||||
self.context)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._show_port')
|
||||
@mock.patch('nova.network.neutron.API._show_port')
|
||||
def test_unbind_ports_reset_dns_name_by_admin(self, mock_show):
|
||||
neutron = mock.Mock()
|
||||
neutron.show_network.return_value = {
|
||||
|
@ -5436,7 +5428,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
uuids.port_id, port_req_body)
|
||||
neutron.update_port.assert_not_called()
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._show_port')
|
||||
@mock.patch('nova.network.neutron.API._show_port')
|
||||
def test_unbind_ports_reset_dns_name_by_non_admin(self, mock_show):
|
||||
neutron = mock.Mock()
|
||||
neutron.show_network.return_value = {
|
||||
|
@ -5460,7 +5452,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
neutron.update_port.assert_called_once_with(
|
||||
uuids.port_id, non_admin_port_req_body)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._show_port')
|
||||
@mock.patch('nova.network.neutron.API._show_port')
|
||||
def test_unbind_ports_reset_allocation_in_port_binding(self, mock_show):
|
||||
neutron = mock.Mock()
|
||||
port_client = mock.Mock()
|
||||
|
@ -5475,7 +5467,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
port_client.update_port.assert_called_once_with(
|
||||
uuids.port_id, port_req_body)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._show_port')
|
||||
@mock.patch('nova.network.neutron.API._show_port')
|
||||
def test_unbind_ports_reset_binding_profile(self, mock_show):
|
||||
neutron = mock.Mock()
|
||||
port_client = mock.Mock()
|
||||
|
@ -5562,17 +5554,16 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.assertEqual(expected_floating.obj_to_primitive(),
|
||||
actual_obj.obj_to_primitive())
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API.'
|
||||
'_populate_neutron_extension_values')
|
||||
@mock.patch('nova.network.neutronv2.api.API._update_port',
|
||||
@mock.patch('nova.network.neutron.API._populate_neutron_extension_values')
|
||||
@mock.patch('nova.network.neutron.API._update_port',
|
||||
# called twice, fails on the 2nd call and triggers the cleanup
|
||||
side_effect=(mock.MagicMock(),
|
||||
exception.PortInUse(
|
||||
port_id=uuids.created_port_id)))
|
||||
@mock.patch.object(objects.VirtualInterface, 'create')
|
||||
@mock.patch.object(objects.VirtualInterface, 'destroy')
|
||||
@mock.patch('nova.network.neutronv2.api.API._unbind_ports')
|
||||
@mock.patch('nova.network.neutronv2.api.API._delete_ports')
|
||||
@mock.patch('nova.network.neutron.API._unbind_ports')
|
||||
@mock.patch('nova.network.neutron.API._delete_ports')
|
||||
def test_update_ports_for_instance_fails_rollback_ports_and_vifs(self,
|
||||
mock_delete_ports,
|
||||
mock_unbind_ports,
|
||||
|
@ -5616,9 +5607,9 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
mock_delete_ports.assert_called_once_with(
|
||||
ntrn, instance, [uuids.created_port_id])
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._get_floating_ip_by_address',
|
||||
@mock.patch('nova.network.neutron.API._get_floating_ip_by_address',
|
||||
return_value={"port_id": "1"})
|
||||
@mock.patch('nova.network.neutronv2.api.API._show_port',
|
||||
@mock.patch('nova.network.neutron.API._show_port',
|
||||
side_effect=exception.PortNotFound(port_id='1'))
|
||||
def test_get_instance_id_by_floating_address_port_not_found(self,
|
||||
mock_show,
|
||||
|
@ -5628,7 +5619,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
'172.24.4.227')
|
||||
self.assertIsNone(fip)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._show_port',
|
||||
@mock.patch('nova.network.neutron.API._show_port',
|
||||
side_effect=exception.PortNotFound(port_id=uuids.port))
|
||||
@mock.patch.object(neutronapi.LOG, 'exception')
|
||||
def test_unbind_ports_port_show_portnotfound(self, mock_log, mock_show):
|
||||
|
@ -5643,7 +5634,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
neutron_client=mock.ANY)
|
||||
mock_log.assert_not_called()
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._show_port',
|
||||
@mock.patch('nova.network.neutron.API._show_port',
|
||||
side_effect=Exception)
|
||||
@mock.patch.object(neutronapi.LOG, 'exception')
|
||||
def test_unbind_ports_port_show_unexpected_error(self,
|
||||
|
@ -5660,7 +5651,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
'binding:profile': {}, 'binding:host_id': None}})
|
||||
self.assertTrue(mock_log.called)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._show_port')
|
||||
@mock.patch('nova.network.neutron.API._show_port')
|
||||
@mock.patch.object(neutronapi.LOG, 'exception')
|
||||
def test_unbind_ports_portnotfound(self, mock_log, mock_show):
|
||||
api = neutronapi.API()
|
||||
|
@ -5676,7 +5667,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
'binding:profile': {}, 'binding:host_id': None}})
|
||||
mock_log.assert_not_called()
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._show_port')
|
||||
@mock.patch('nova.network.neutron.API._show_port')
|
||||
@mock.patch.object(neutronapi.LOG, 'exception')
|
||||
def test_unbind_ports_unexpected_error(self, mock_log, mock_show):
|
||||
api = neutronapi.API()
|
||||
|
@ -5852,9 +5843,9 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.context, instance,
|
||||
'172.24.5.15', '10.1.0.9')
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutronv2.api.LOG.warning')
|
||||
@mock.patch('nova.network.base_api.update_instance_cache_with_nw_info')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
@mock.patch('nova.network.neutron.LOG.warning')
|
||||
@mock.patch('nova.network.neutron.update_instance_cache_with_nw_info')
|
||||
def test_associate_floating_ip_refresh_error_trap(self, mock_update_cache,
|
||||
mock_log_warning,
|
||||
mock_get_client):
|
||||
|
@ -5903,7 +5894,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
mock_update_cache.assert_called_once_with( # from @refresh_cache
|
||||
self.api, ctxt, instance, nw_info=None)
|
||||
|
||||
@mock.patch('nova.network.base_api.update_instance_cache_with_nw_info')
|
||||
@mock.patch('nova.network.neutron.update_instance_cache_with_nw_info')
|
||||
def test_update_inst_info_cache_for_disassociated_fip_other_cell(
|
||||
self, mock_update_cache):
|
||||
"""Tests a scenario where a floating IP is associated to an instance
|
||||
|
@ -5939,8 +5930,8 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
mock_update_cache.assert_called_once_with(
|
||||
self.api, cctxt, old_instance)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.LOG.info')
|
||||
@mock.patch('nova.network.base_api.update_instance_cache_with_nw_info')
|
||||
@mock.patch('nova.network.neutron.LOG.info')
|
||||
@mock.patch('nova.network.neutron.update_instance_cache_with_nw_info')
|
||||
def test_update_inst_info_cache_for_disassociated_fip_inst_not_found(
|
||||
self, mock_update_cache, mock_log_info):
|
||||
"""Tests the case that a floating IP is re-associated to an instance
|
||||
|
@ -6071,7 +6062,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
mock_get_inst.assert_called_once_with(ctxt, instance.uuid)
|
||||
mock_get_map.assert_called_once_with(ctxt, instance.uuid)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._get_ksa_client',
|
||||
@mock.patch('nova.network.neutron._get_ksa_client',
|
||||
new_callable=mock.NonCallableMock) # asserts not called
|
||||
def test_migrate_instance_start_no_binding_ext(self, get_client_mock):
|
||||
"""Tests that migrate_instance_start exits early if neutron doesn't
|
||||
|
@ -6082,7 +6073,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.api.migrate_instance_start(
|
||||
self.context, mock.sentinel.instance, {})
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
|
||||
@mock.patch('nova.network.neutron._get_ksa_client')
|
||||
def test_migrate_instance_start_activate(self, get_client_mock):
|
||||
"""Tests the happy path for migrate_instance_start where the binding
|
||||
for the port(s) attached to the instance are activated on the
|
||||
|
@ -6105,7 +6096,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
'/v2.0/ports/%s/bindings/dest' % uuids.port_id, raise_exc=False,
|
||||
global_request_id=self.context.global_id)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
|
||||
@mock.patch('nova.network.neutron._get_ksa_client')
|
||||
def test_migrate_instance_start_already_active(self, get_client_mock):
|
||||
"""Tests the case that the destination host port binding is already
|
||||
ACTIVE when migrate_instance_start is called so we don't try to
|
||||
|
@ -6128,7 +6119,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
'/v2.0/ports/%s/bindings/dest' % uuids.port_id, raise_exc=False,
|
||||
global_request_id=self.context.global_id)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
|
||||
@mock.patch('nova.network.neutron._get_ksa_client')
|
||||
def test_migrate_instance_start_no_bindings(self, get_client_mock):
|
||||
"""Tests the case that migrate_instance_start is running against new
|
||||
enough neutron for the binding-extended API but the ports don't have
|
||||
|
@ -6153,7 +6144,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
'/v2.0/ports/%s/bindings/dest' % uuids.port1, raise_exc=False,
|
||||
global_request_id=self.context.global_id)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
|
||||
@mock.patch('nova.network.neutron._get_ksa_client')
|
||||
def test_migrate_instance_start_get_error(self, get_client_mock):
|
||||
"""Tests the case that migrate_instance_start is running against new
|
||||
enough neutron for the binding-extended API but getting the port
|
||||
|
@ -6182,7 +6173,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
raise_exc=False,
|
||||
global_request_id=self.context.global_id)])
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_get_requested_resource_for_instance_no_resource_request(
|
||||
self, mock_get_client):
|
||||
mock_client = mock_get_client.return_value
|
||||
|
@ -6202,7 +6193,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
device_id=uuids.inst1, fields=['id', 'resource_request'])
|
||||
self.assertEqual([], request_groups)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_get_requested_resource_for_instance_no_ports(
|
||||
self, mock_get_client):
|
||||
mock_client = mock_get_client.return_value
|
||||
|
@ -6217,7 +6208,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
device_id=uuids.inst1, fields=['id', 'resource_request'])
|
||||
self.assertEqual([], request_groups)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch('nova.network.neutron.get_client')
|
||||
def test_get_requested_resource_for_instance_with_multiple_ports(
|
||||
self, mock_get_client):
|
||||
mock_client = mock_get_client.return_value
|
||||
|
@ -6253,7 +6244,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
mock_get_client.assert_called_once_with(self.context, admin=True)
|
||||
|
||||
|
||||
class TestNeutronv2ModuleMethods(test.NoDBTestCase):
|
||||
class TestAPIModuleMethods(test.NoDBTestCase):
|
||||
|
||||
def test_gather_port_ids_and_networks_wrong_params(self):
|
||||
api = neutronapi.API()
|
||||
|
@ -6299,7 +6290,7 @@ class TestNeutronv2ModuleMethods(test.NoDBTestCase):
|
|||
self.assertEqual(networks, [{'id': 1}, {'id': 2}, {'id': 3}])
|
||||
|
||||
|
||||
class TestNeutronv2Portbinding(TestNeutronv2Base):
|
||||
class TestAPIPortbinding(TestAPIBase):
|
||||
|
||||
def test_allocate_for_instance_portbinding(self):
|
||||
self._test_allocate_for_instance_with_virtual_interface(
|
||||
|
@ -6513,7 +6504,7 @@ class TestNeutronv2Portbinding(TestNeutronv2Base):
|
|||
self.assertEqual(port_req_body, req)
|
||||
|
||||
@mock.patch.object(pci_manager, 'get_instance_pci_devs')
|
||||
@mock.patch('nova.network.neutronv2.api.LOG.error')
|
||||
@mock.patch('nova.network.neutron.LOG.error')
|
||||
def test_populate_pci_mac_address_no_device(self, mock_log_error,
|
||||
mock_get_instance_pci_devs):
|
||||
instance, pf, vf = self._populate_pci_mac_address_fakes()
|
||||
|
@ -6610,7 +6601,7 @@ class TestNeutronv2Portbinding(TestNeutronv2Base):
|
|||
'fake_host', 'setup_instance_network_on_host',
|
||||
self.context, instance, 'fake_host')
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._get_ksa_client',
|
||||
@mock.patch('nova.network.neutron._get_ksa_client',
|
||||
new_callable=mock.NonCallableMock)
|
||||
def test_bind_ports_to_host_no_ports(self, mock_client):
|
||||
self.assertDictEqual({},
|
||||
|
@ -6619,7 +6610,7 @@ class TestNeutronv2Portbinding(TestNeutronv2Base):
|
|||
objects.Instance(info_cache=None),
|
||||
'fake-host'))
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
|
||||
@mock.patch('nova.network.neutron._get_ksa_client')
|
||||
def test_bind_ports_to_host(self, mock_client):
|
||||
"""Tests a single port happy path where everything is successful."""
|
||||
def post_side_effect(*args, **kwargs):
|
||||
|
@ -6643,7 +6634,7 @@ class TestNeutronv2Portbinding(TestNeutronv2Base):
|
|||
self.assertEqual(1, mock_client.return_value.post.call_count)
|
||||
self.assertDictEqual({uuids.port: binding['binding']}, result)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
|
||||
@mock.patch('nova.network.neutron._get_ksa_client')
|
||||
def test_bind_ports_to_host_with_vif_profile_and_vnic(self, mock_client):
|
||||
"""Tests bind_ports_to_host with default/non-default parameters."""
|
||||
def post_side_effect(*args, **kwargs):
|
||||
|
@ -6687,7 +6678,7 @@ class TestNeutronv2Portbinding(TestNeutronv2Base):
|
|||
self.assertEqual(2, mock_client.return_value.post.call_count)
|
||||
self.assertDictEqual({uuids.port: binding['binding']}, result)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
|
||||
@mock.patch('nova.network.neutron._get_ksa_client')
|
||||
def test_bind_ports_to_host_rollback(self, mock_client):
|
||||
"""Tests a scenario where an instance has two ports, and binding the
|
||||
first is successful but binding the second fails, so the code will
|
||||
|
@ -6720,7 +6711,7 @@ class TestNeutronv2Portbinding(TestNeutronv2Base):
|
|||
mock_delete.assert_called_once_with(self.context, uuids.ok,
|
||||
'fake-host')
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
|
||||
@mock.patch('nova.network.neutron._get_ksa_client')
|
||||
def test_delete_port_binding(self, mock_client):
|
||||
# Create three ports where:
|
||||
# - one is successfully unbound
|
||||
|
@ -6743,7 +6734,7 @@ class TestNeutronv2Portbinding(TestNeutronv2Base):
|
|||
self.api.delete_port_binding(self.context, port_id,
|
||||
'fake-host')
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
|
||||
@mock.patch('nova.network.neutron._get_ksa_client')
|
||||
def test_activate_port_binding(self, mock_client):
|
||||
"""Tests the happy path of activating an inactive port binding."""
|
||||
resp = fake_req.FakeResponse(200)
|
||||
|
@ -6755,8 +6746,8 @@ class TestNeutronv2Portbinding(TestNeutronv2Base):
|
|||
raise_exc=False,
|
||||
global_request_id=self.context.global_id)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
|
||||
@mock.patch('nova.network.neutronv2.api.LOG.warning')
|
||||
@mock.patch('nova.network.neutron._get_ksa_client')
|
||||
@mock.patch('nova.network.neutron.LOG.warning')
|
||||
def test_activate_port_binding_already_active(
|
||||
self, mock_log_warning, mock_client):
|
||||
"""Tests the 409 case of activating an already active port binding."""
|
||||
|
@ -6770,7 +6761,7 @@ class TestNeutronv2Portbinding(TestNeutronv2Base):
|
|||
self.assertEqual(1, mock_log_warning.call_count)
|
||||
self.assertIn('is already active', mock_log_warning.call_args[0][0])
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
|
||||
@mock.patch('nova.network.neutron._get_ksa_client')
|
||||
def test_activate_port_binding_fails(self, mock_client):
|
||||
"""Tests the unknown error case of binding activation."""
|
||||
mock_client.return_value.put.return_value = fake_req.FakeResponse(500)
|
||||
|
@ -7166,7 +7157,7 @@ class TestAllocateForInstance(test.NoDBTestCase):
|
|||
'device_id': self.instance.uuid}})
|
||||
|
||||
|
||||
class TestNeutronv2NeutronHostnameDNS(TestNeutronv2Base):
|
||||
class TestAPINeutronHostnameDNS(TestAPIBase):
|
||||
|
||||
def test_allocate_for_instance_create_port(self):
|
||||
# The port's dns_name attribute should be set by the port create
|
||||
|
@ -7207,7 +7198,7 @@ class TestNeutronv2NeutronHostnameDNS(TestNeutronv2Base):
|
|||
_dns_name='my-instance')
|
||||
|
||||
|
||||
class TestNeutronv2NeutronHostnameDNSPortbinding(TestNeutronv2Base):
|
||||
class TestAPINeutronHostnameDNSPortbinding(TestAPIBase):
|
||||
|
||||
def test_allocate_for_instance_create_port(self):
|
||||
# The port's dns_name attribute should be set by the port create
|
||||
|
@ -7546,11 +7537,11 @@ class TestNeutronPortSecurity(test.NoDBTestCase):
|
|||
instance, mock.ANY, ['default', 'secgrp1', 'secgrp2'])
|
||||
|
||||
|
||||
class TestNeutronv2AutoAllocateNetwork(test.NoDBTestCase):
|
||||
class TestAPIAutoAllocateNetwork(test.NoDBTestCase):
|
||||
"""Tests auto-allocation scenarios"""
|
||||
|
||||
def setUp(self):
|
||||
super(TestNeutronv2AutoAllocateNetwork, self).setUp()
|
||||
super(TestAPIAutoAllocateNetwork, self).setUp()
|
||||
self.api = neutronapi.API()
|
||||
self.context = context.RequestContext(uuids.user_id, uuids.project_id)
|
||||
|
||||
|
@ -7704,7 +7695,7 @@ class TestNeutronv2AutoAllocateNetwork(test.NoDBTestCase):
|
|||
# return a fake vif
|
||||
return [model.VIF(id=uuids.port_id)]
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.get_client', return_value=ntrn)
|
||||
@mock.patch('nova.network.neutron.get_client', return_value=ntrn)
|
||||
@mock.patch.object(self.api, '_auto_allocate_network',
|
||||
return_value=fake_network)
|
||||
@mock.patch.object(self.api, '_check_external_network_attach')
|
||||
|
@ -7763,7 +7754,7 @@ class TestGetInstanceNetworkInfo(test.NoDBTestCase):
|
|||
self.api = neutronapi.API()
|
||||
self.context = context.RequestContext(uuids.user_id, uuids.project_id)
|
||||
self.instance = fake_instance.fake_instance_obj(self.context)
|
||||
client_mock = mock.patch('nova.network.neutronv2.api.get_client')
|
||||
client_mock = mock.patch('nova.network.neutron.get_client')
|
||||
self.client = client_mock.start().return_value
|
||||
self.addCleanup(client_mock.stop)
|
||||
# This is a no-db set of tests and we don't care about refreshing the
|
|
@ -136,7 +136,7 @@ class TestSendInstanceUpdateNotification(test.NoDBTestCase):
|
|||
|
||||
class TestBandwidthUsage(test.NoDBTestCase):
|
||||
@mock.patch('nova.context.RequestContext.elevated')
|
||||
@mock.patch('nova.network.API')
|
||||
@mock.patch('nova.network.neutron.API')
|
||||
@mock.patch('nova.objects.BandwidthUsageList.get_by_uuids')
|
||||
def test_context_elevated(self, mock_get_bw_usage, mock_nw_api,
|
||||
mock_elevated):
|
||||
|
|
|
@ -34,7 +34,7 @@ from nova import conductor
|
|||
from nova import context
|
||||
from nova.db.sqlalchemy import api as session
|
||||
from nova import exception
|
||||
from nova.network.neutronv2 import api as neutron_api
|
||||
from nova.network import neutron as neutron_api
|
||||
from nova import objects
|
||||
from nova.objects import base as obj_base
|
||||
from nova.objects import service as service_obj
|
||||
|
|
|
@ -47,7 +47,7 @@ from nova import block_device
|
|||
from nova import context
|
||||
from nova import exception
|
||||
from nova.network import model as network_model
|
||||
from nova.network.neutronv2 import api as neutronapi
|
||||
from nova.network import neutron as neutronapi
|
||||
from nova import objects
|
||||
from nova.objects import virt_device_metadata as metadata_obj
|
||||
from nova import test
|
||||
|
@ -1098,7 +1098,7 @@ class MetadataHandlerTestCase(test.TestCase):
|
|||
response_ctype = response.headers['Content-Type']
|
||||
self.assertTrue(response_ctype.startswith("application/json"))
|
||||
|
||||
@mock.patch('nova.network.API')
|
||||
@mock.patch('nova.network.neutron.API')
|
||||
def test_user_data_non_existing_fixed_address(self, mock_network_api):
|
||||
mock_network_api.return_value.get_fixed_ip_by_address.side_effect = (
|
||||
exception.NotFound())
|
||||
|
@ -1580,7 +1580,7 @@ class MetadataHandlerTestCase(test.TestCase):
|
|||
self.assertEqual(403, response.status_int)
|
||||
|
||||
@mock.patch.object(context, 'get_admin_context')
|
||||
@mock.patch('nova.network.API')
|
||||
@mock.patch('nova.network.neutron.API')
|
||||
def test_get_metadata_by_address(self, mock_net_api, mock_get_context):
|
||||
mock_get_context.return_value = 'CONTEXT'
|
||||
api = mock.Mock()
|
||||
|
|
|
@ -55,7 +55,7 @@ class TestProfiler(test.NoDBTestCase):
|
|||
'nova.conductor.rpcapi.ComputeTaskAPI',
|
||||
'nova.conductor.rpcapi.ConductorAPI',
|
||||
'nova.image.api.API',
|
||||
'nova.network.neutronv2.api.ClientWrapper',
|
||||
'nova.network.neutron.ClientWrapper',
|
||||
'nova.scheduler.manager.SchedulerManager',
|
||||
'nova.scheduler.rpcapi.SchedulerAPI',
|
||||
'nova.virt.libvirt.vif.LibvirtGenericVIFDriver',
|
||||
|
|
|
@ -78,5 +78,5 @@ def set_stubs(test):
|
|||
fake_vim_prop)
|
||||
test.stub_out('nova.virt.vmwareapi.driver.VMwareAPISession._is_vim_object',
|
||||
fake_is_vim_object)
|
||||
test.stub_out('nova.network.neutronv2.api.API.update_instance_vnic_index',
|
||||
test.stub_out('nova.network.neutron.API.update_instance_vnic_index',
|
||||
lambda *args, **kwargs: None)
|
||||
|
|
|
@ -45,7 +45,7 @@ from nova.console import type as ctype
|
|||
from nova import context as nova_context
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova import network
|
||||
from nova.network import neutron
|
||||
from nova import objects
|
||||
from nova.objects import fields
|
||||
from nova import utils
|
||||
|
@ -146,7 +146,7 @@ class VMwareVMOps(object):
|
|||
self._datastore_browser_mapping = {}
|
||||
self._imagecache = imagecache.ImageCacheManager(self._session,
|
||||
self._base_folder)
|
||||
self._network_api = network.API()
|
||||
self._network_api = neutron.API()
|
||||
|
||||
def _get_base_folder(self):
|
||||
# Enable more than one compute node to run on the same host
|
||||
|
|
Loading…
Reference in New Issue