diff --git a/doc/source/devref/service_extensions.rst b/doc/source/devref/service_extensions.rst index 069b59b5d47..e23ada1018d 100644 --- a/doc/source/devref/service_extensions.rst +++ b/doc/source/devref/service_extensions.rst @@ -55,14 +55,14 @@ Calling the Core Plugin from Services There are many cases where a service may want to create a resource managed by the core plugin (e.g. ports, networks, subnets). This -can be achieved by importing the Neutron Manager and getting a direct +can be achieved by importing the plugins directory and getting a direct reference to the core plugin: .. code:: python - from neutron import manager + from neutron_lib.plugins import directory - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() plugin.create_port(context, port_dict) diff --git a/neutron/api/extensions.py b/neutron/api/extensions.py index e846e5d9d4d..4697ead237e 100644 --- a/neutron/api/extensions.py +++ b/neutron/api/extensions.py @@ -18,6 +18,7 @@ import collections import imp import os +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_log import log as logging from oslo_middleware import base @@ -29,7 +30,6 @@ import webob.exc from neutron._i18n import _, _LE, _LI, _LW from neutron.common import exceptions import neutron.extensions -from neutron import manager from neutron.plugins.common import constants as const from neutron.services import provider_configuration from neutron import wsgi @@ -665,7 +665,7 @@ class PluginAwareExtensionManager(ExtensionManager): @classmethod def get_instance(cls): if cls._instance is None: - service_plugins = manager.NeutronManager.get_service_plugins() + service_plugins = directory.get_plugins() cls._instance = cls(get_extensions_path(service_plugins), service_plugins) return cls._instance diff --git a/neutron/api/rpc/agentnotifiers/dhcp_rpc_agent_api.py b/neutron/api/rpc/agentnotifiers/dhcp_rpc_agent_api.py index aeed3949486..7fed042dfa2 100644 --- a/neutron/api/rpc/agentnotifiers/dhcp_rpc_agent_api.py +++ b/neutron/api/rpc/agentnotifiers/dhcp_rpc_agent_api.py @@ -14,6 +14,7 @@ # limitations under the License. from neutron_lib import constants +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_log import log as logging import oslo_messaging @@ -26,7 +27,6 @@ from neutron.common import constants as n_const from neutron.common import rpc as n_rpc from neutron.common import topics from neutron.common import utils -from neutron import manager LOG = logging.getLogger(__name__) @@ -90,7 +90,7 @@ class DhcpAgentNotifyAPI(object): @property def plugin(self): if self._plugin is None: - self._plugin = manager.NeutronManager.get_plugin() + self._plugin = directory.get_plugin() return self._plugin def _schedule_network(self, context, network, existing_agents): @@ -166,8 +166,7 @@ class DhcpAgentNotifyAPI(object): if 'subnet' in payload and payload['subnet'].get('segment_id'): # if segment_id exists then the segment service plugin # must be loaded - nm = manager.NeutronManager - segment_plugin = nm.get_service_plugins()['segments'] + segment_plugin = directory.get_plugin('segments') segment = segment_plugin.get_segment( context, payload['subnet']['segment_id']) network['candidate_hosts'] = segment['hosts'] diff --git a/neutron/api/rpc/agentnotifiers/l3_rpc_agent_api.py b/neutron/api/rpc/agentnotifiers/l3_rpc_agent_api.py index b8eaf4a2557..d166c36227c 100644 --- a/neutron/api/rpc/agentnotifiers/l3_rpc_agent_api.py +++ b/neutron/api/rpc/agentnotifiers/l3_rpc_agent_api.py @@ -16,6 +16,7 @@ import random from neutron_lib import constants +from neutron_lib.plugins import directory from oslo_log import log as logging import oslo_messaging @@ -24,8 +25,6 @@ from neutron.api.rpc.agentnotifiers import utils as ag_utils from neutron.common import rpc as n_rpc from neutron.common import topics from neutron.common import utils -from neutron import manager -from neutron.plugins.common import constants as service_constants LOG = logging.getLogger(__name__) @@ -57,8 +56,7 @@ class L3AgentNotifyAPI(object): shuffle_agents): """Notify changed routers to hosting l3 agents.""" adminContext = context if context.is_admin else context.elevated() - plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + plugin = directory.get_plugin(constants.L3) for router_id in router_ids: hosts = plugin.get_hosts_to_notify(adminContext, router_id) if shuffle_agents: @@ -87,8 +85,7 @@ class L3AgentNotifyAPI(object): def _notification(self, context, method, router_ids, operation, shuffle_agents, schedule_routers=True): """Notify all the agents that are hosting the routers.""" - plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + plugin = directory.get_plugin(constants.L3) if not plugin: LOG.error(_LE('No plugin for L3 routing registered. Cannot notify ' 'agents with the message %s'), method) diff --git a/neutron/api/rpc/agentnotifiers/metering_rpc_agent_api.py b/neutron/api/rpc/agentnotifiers/metering_rpc_agent_api.py index b1cf4de5a8b..c553a9af414 100644 --- a/neutron/api/rpc/agentnotifiers/metering_rpc_agent_api.py +++ b/neutron/api/rpc/agentnotifiers/metering_rpc_agent_api.py @@ -13,6 +13,7 @@ # under the License. from neutron_lib import constants +from neutron_lib.plugins import directory from oslo_log import log as logging import oslo_messaging import six @@ -21,8 +22,6 @@ from neutron.common import rpc as n_rpc from neutron.common import topics from neutron.common import utils from neutron.db import agentschedulers_db -from neutron import manager -from neutron.plugins.common import constants as service_constants LOG = logging.getLogger(__name__) @@ -38,8 +37,7 @@ class MeteringAgentNotifyAPI(object): def _agent_notification(self, context, method, routers): """Notify l3 metering agents hosted by l3 agent hosts.""" adminContext = context if context.is_admin else context.elevated() - plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + plugin = directory.get_plugin(constants.L3) l3_routers = {} state = agentschedulers_db.get_admin_state_up_filter() @@ -74,8 +72,7 @@ class MeteringAgentNotifyAPI(object): def _notification(self, context, method, routers): """Notify all the agents that are hosting the routers.""" - plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + plugin = directory.get_plugin(constants.L3) if utils.is_extension_supported( plugin, constants.L3_AGENT_SCHEDULER_EXT_ALIAS): self._agent_notification(context, method, routers) diff --git a/neutron/api/rpc/callbacks/version_manager.py b/neutron/api/rpc/callbacks/version_manager.py index ffd005bcec9..bc397a702f1 100644 --- a/neutron/api/rpc/callbacks/version_manager.py +++ b/neutron/api/rpc/callbacks/version_manager.py @@ -15,11 +15,11 @@ import copy import pprint import time +from neutron_lib.plugins import directory from oslo_log import log as logging from oslo_utils import importutils from neutron.api.rpc.callbacks import exceptions -from neutron import manager LOG = logging.getLogger(__name__) @@ -196,7 +196,7 @@ class CachedResourceConsumerTracker(object): def _update_consumer_versions(self): new_tracker = ResourceConsumerTracker() - neutron_plugin = manager.NeutronManager.get_plugin() + neutron_plugin = directory.get_plugin() agents_db = _import_agents_db() # If you use RPC callbacks, your plugin needs to implement # AgentsDbMixin so that we know which resource versions your diff --git a/neutron/api/rpc/handlers/dhcp_rpc.py b/neutron/api/rpc/handlers/dhcp_rpc.py index 06c0a16dcb4..70defc6293f 100644 --- a/neutron/api/rpc/handlers/dhcp_rpc.py +++ b/neutron/api/rpc/handlers/dhcp_rpc.py @@ -19,6 +19,7 @@ import operator from neutron_lib import constants from neutron_lib import exceptions +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_db import exception as db_exc from oslo_log import log as logging @@ -34,7 +35,6 @@ from neutron.db import api as db_api from neutron.db import provisioning_blocks from neutron.extensions import portbindings from neutron.extensions import segment as segment_ext -from neutron import manager from neutron.plugins.common import utils as p_utils from neutron.quota import resource_registry @@ -79,7 +79,7 @@ class DhcpRpcCallback(object): def _get_active_networks(self, context, **kwargs): """Retrieve and return a list of the active networks.""" host = kwargs.get('host') - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() if utils.is_extension_supported( plugin, constants.DHCP_AGENT_SCHEDULER_EXT_ALIAS): if cfg.CONF.network_auto_schedule: @@ -140,7 +140,7 @@ class DhcpRpcCallback(object): host = kwargs.get('host') LOG.debug('get_active_networks_info from %s', host) networks = self._get_active_networks(context, **kwargs) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() filters = {'network_id': [network['id'] for network in networks]} ports = plugin.get_ports(context, filters=filters) filters['enable_dhcp'] = [True] @@ -153,7 +153,7 @@ class DhcpRpcCallback(object): # inside a segment. If the segment service plugin is loaded and # there are active dhcp enabled subnets, then filter out the subnets # that are not on the host's segment. - seg_plug = manager.NeutronManager.get_service_plugins().get( + seg_plug = directory.get_plugin( segment_ext.SegmentPluginBase.get_plugin_type()) seg_subnets = [subnet for subnet in subnets if subnet.get('segment_id')] @@ -189,7 +189,7 @@ class DhcpRpcCallback(object): LOG.debug('Network %(network_id)s requested from ' '%(host)s', {'network_id': network_id, 'host': host}) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() try: network = plugin.get_network(context, network_id) except exceptions.NetworkNotFound: @@ -198,7 +198,7 @@ class DhcpRpcCallback(object): return filters = dict(network_id=[network_id]) subnets = plugin.get_subnets(context, filters=filters) - seg_plug = manager.NeutronManager.get_service_plugins().get( + seg_plug = directory.get_plugin( segment_ext.SegmentPluginBase.get_plugin_type()) if seg_plug and subnets: seg_subnets = [subnet for subnet in subnets @@ -231,7 +231,7 @@ class DhcpRpcCallback(object): LOG.debug('DHCP port deletion for %(network_id)s request from ' '%(host)s', {'network_id': network_id, 'host': host}) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() plugin.delete_ports_by_device_id(context, device_id, network_id) @db_api.retry_db_errors @@ -255,7 +255,7 @@ class DhcpRpcCallback(object): port['port'][portbindings.HOST_ID] = host if 'mac_address' not in port['port']: port['port']['mac_address'] = constants.ATTR_NOT_SPECIFIED - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() return self._port_action(plugin, context, port, 'create_port') @db_api.retry_db_errors @@ -265,7 +265,7 @@ class DhcpRpcCallback(object): port = kwargs.get('port') port['id'] = kwargs.get('port_id') port['port'][portbindings.HOST_ID] = host - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() try: old_port = plugin.get_port(context, port['id']) if (old_port['device_id'] != n_const.DEVICE_ID_RESERVED_DHCP_PORT diff --git a/neutron/api/rpc/handlers/dvr_rpc.py b/neutron/api/rpc/handlers/dvr_rpc.py index 73a5918be9a..b85f4c69204 100644 --- a/neutron/api/rpc/handlers/dvr_rpc.py +++ b/neutron/api/rpc/handlers/dvr_rpc.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.plugins import directory from oslo_log import helpers as log_helpers from oslo_log import log as logging import oslo_messaging @@ -20,7 +21,6 @@ import oslo_messaging from neutron.common import constants from neutron.common import rpc as n_rpc from neutron.common import topics -from neutron import manager LOG = logging.getLogger(__name__) @@ -85,7 +85,7 @@ class DVRServerRpcCallback(object): @property def plugin(self): if not getattr(self, '_plugin', None): - self._plugin = manager.NeutronManager.get_plugin() + self._plugin = directory.get_plugin() return self._plugin def get_dvr_mac_address_list(self, context): diff --git a/neutron/api/rpc/handlers/l3_rpc.py b/neutron/api/rpc/handlers/l3_rpc.py index db0fcaf34ea..b0622c19001 100644 --- a/neutron/api/rpc/handlers/l3_rpc.py +++ b/neutron/api/rpc/handlers/l3_rpc.py @@ -15,6 +15,7 @@ from neutron_lib import constants from neutron_lib import exceptions +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_log import log as logging import oslo_messaging @@ -26,8 +27,6 @@ from neutron import context as neutron_context from neutron.db import api as db_api from neutron.extensions import l3 from neutron.extensions import portbindings -from neutron import manager -from neutron.plugins.common import constants as plugin_constants LOG = logging.getLogger(__name__) @@ -52,14 +51,13 @@ class L3RpcCallback(object): @property def plugin(self): if not hasattr(self, '_plugin'): - self._plugin = manager.NeutronManager.get_plugin() + self._plugin = directory.get_plugin() return self._plugin @property def l3plugin(self): if not hasattr(self, '_l3plugin'): - self._l3plugin = manager.NeutronManager.get_service_plugins()[ - plugin_constants.L3_ROUTER_NAT] + self._l3plugin = directory.get_plugin(constants.L3) return self._l3plugin def get_router_ids(self, context, host): @@ -209,8 +207,7 @@ class L3RpcCallback(object): return net_id def get_service_plugin_list(self, context, **kwargs): - plugins = manager.NeutronManager.get_service_plugins() - return plugins.keys() + return directory.get_plugins().keys() @db_api.retry_db_errors def update_floatingip_statuses(self, context, router_id, fip_statuses): diff --git a/neutron/api/rpc/handlers/metadata_rpc.py b/neutron/api/rpc/handlers/metadata_rpc.py index 39034397a98..7b5df2b9114 100644 --- a/neutron/api/rpc/handlers/metadata_rpc.py +++ b/neutron/api/rpc/handlers/metadata_rpc.py @@ -13,10 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +from neutron_lib.plugins import directory import oslo_messaging from neutron.common import constants -from neutron import manager class MetadataRpcCallback(object): @@ -36,7 +36,7 @@ class MetadataRpcCallback(object): @property def plugin(self): if not hasattr(self, '_plugin'): - self._plugin = manager.NeutronManager.get_plugin() + self._plugin = directory.get_plugin() return self._plugin def get_ports(self, context, filters): diff --git a/neutron/api/rpc/handlers/securitygroups_rpc.py b/neutron/api/rpc/handlers/securitygroups_rpc.py index 53dad8638e5..89abcee7bdc 100644 --- a/neutron/api/rpc/handlers/securitygroups_rpc.py +++ b/neutron/api/rpc/handlers/securitygroups_rpc.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.plugins import directory from oslo_log import log as logging import oslo_messaging @@ -20,7 +21,6 @@ from neutron.common import constants from neutron.common import rpc as n_rpc from neutron.common import topics from neutron.common import utils -from neutron import manager LOG = logging.getLogger(__name__) @@ -74,7 +74,7 @@ class SecurityGroupServerRpcCallback(object): @property def plugin(self): - return manager.NeutronManager.get_plugin() + return directory.get_plugin() def _get_devices_info(self, context, devices): return dict( diff --git a/neutron/api/v2/resource_helper.py b/neutron/api/v2/resource_helper.py index 1a10c01489e..c9f160a7b5a 100644 --- a/neutron/api/v2/resource_helper.py +++ b/neutron/api/v2/resource_helper.py @@ -13,13 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_log import log as logging from neutron.api import extensions from neutron.api.v2 import base -from neutron import manager -from neutron.plugins.common import constants from neutron.quota import resource_registry LOG = logging.getLogger(__name__) @@ -73,10 +73,7 @@ def build_resource_info(plural_mappings, resource_map, which_service, which_service = constants.CORE if action_map is None: action_map = {} - if which_service != constants.CORE: - plugin = manager.NeutronManager.get_service_plugins()[which_service] - else: - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin(which_service) path_prefix = getattr(plugin, "path_prefix", "") LOG.debug('Service %(service)s assigned prefix: %(prefix)s', {'service': which_service, 'prefix': path_prefix}) diff --git a/neutron/api/v2/router.py b/neutron/api/v2/router.py index 93b19f7de69..afe3d245b3d 100644 --- a/neutron/api/v2/router.py +++ b/neutron/api/v2/router.py @@ -14,6 +14,7 @@ # limitations under the License. from neutron_lib import constants +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_service import wsgi as base_wsgi import routes as routes_mapper @@ -73,7 +74,8 @@ class APIRouter(base_wsgi.Router): def __init__(self, **local_config): mapper = routes_mapper.Mapper() - plugin = manager.NeutronManager.get_plugin() + manager.init() + plugin = directory.get_plugin() ext_mgr = extensions.PluginAwareExtensionManager.get_instance() ext_mgr.extend_resources("2.0", attributes.RESOURCE_ATTRIBUTE_MAP) diff --git a/neutron/cmd/eventlet/usage_audit.py b/neutron/cmd/eventlet/usage_audit.py index 402d92c5423..56fe7a0d06a 100644 --- a/neutron/cmd/eventlet/usage_audit.py +++ b/neutron/cmd/eventlet/usage_audit.py @@ -19,11 +19,13 @@ subnets. import sys +from neutron_lib import constants +from neutron_lib.plugins import directory + from neutron.common import config from neutron.common import rpc as n_rpc from neutron import context from neutron import manager -from neutron.plugins.common import constants def main(): @@ -31,9 +33,9 @@ def main(): config.setup_logging() cxt = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() - l3_plugin = manager.NeutronManager.get_service_plugins().get( - constants.L3_ROUTER_NAT) + manager.init() + plugin = directory.get_plugin() + l3_plugin = directory.get_plugin(constants.L3) notifier = n_rpc.get_notifier('network') for network in plugin.get_networks(cxt): notifier.info(cxt, 'network.exists', {'network': network}) diff --git a/neutron/core_extensions/qos.py b/neutron/core_extensions/qos.py index 6b9f1365c14..121e1e3ce3b 100644 --- a/neutron/core_extensions/qos.py +++ b/neutron/core_extensions/qos.py @@ -13,10 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.plugins import directory + from neutron.common import exceptions as n_exc from neutron.core_extensions import base from neutron.db import api as db_api -from neutron import manager from neutron.objects.qos import policy as policy_object from neutron.plugins.common import constants as plugin_constants from neutron.services.qos import qos_consts @@ -27,8 +28,8 @@ class QosCoreResourceExtension(base.CoreResourceExtension): @property def plugin_loaded(self): if not hasattr(self, '_plugin_loaded'): - service_plugins = manager.NeutronManager.get_service_plugins() - self._plugin_loaded = plugin_constants.QOS in service_plugins + self._plugin_loaded = ( + plugin_constants.QOS in directory.get_plugins()) return self._plugin_loaded def _get_policy_obj(self, context, policy_id): diff --git a/neutron/db/agents_db.py b/neutron/db/agents_db.py index 3492b6fbeac..04b747d92ad 100644 --- a/neutron/db/agents_db.py +++ b/neutron/db/agents_db.py @@ -19,6 +19,7 @@ import debtcollector from eventlet import greenthread from neutron_lib.api import converters from neutron_lib import constants +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_log import log as logging import oslo_messaging @@ -43,7 +44,6 @@ from neutron.db import api as db_api from neutron.db.models import agent as agent_model from neutron.extensions import agent as ext_agent from neutron.extensions import availability_zone as az_ext -from neutron import manager LOG = logging.getLogger(__name__) @@ -455,7 +455,7 @@ class AgentExtRpcCallback(object): "server start timestamp: %(server_time)s", log_dict) return if not self.plugin: - self.plugin = manager.NeutronManager.get_plugin() + self.plugin = directory.get_plugin() agent_status, agent_state = self.plugin.create_or_update_agent( context, agent_state) self._update_local_agent_resource_versions(context, agent_state) diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index ff251e8b63e..31c8d8b92fa 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -20,6 +20,7 @@ from neutron_lib.api import validators from neutron_lib import constants from neutron_lib.db import utils as db_utils from neutron_lib import exceptions as exc +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_db import exception as os_db_exc from oslo_db.sqlalchemy import utils as sa_utils @@ -55,11 +56,9 @@ from neutron.extensions import l3 from neutron import ipam from neutron.ipam import exceptions as ipam_exc from neutron.ipam import subnet_alloc -from neutron import manager from neutron import neutron_plugin_base_v2 from neutron.objects import base as base_obj from neutron.objects import subnetpool as subnetpool_obj -from neutron.plugins.common import constants as service_constants LOG = logging.getLogger(__name__) @@ -584,8 +583,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, raise exc.BadRequest(resource='subnets', msg=reason) def _update_router_gw_ports(self, context, network, subnet): - l3plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + l3plugin = directory.get_plugin(constants.L3) if l3plugin: gw_ports = self._get_router_gw_ports_by_network(context, network['id']) @@ -1343,9 +1341,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, except l3.RouterNotFound: return else: - l3plugin = ( - manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT)) + l3plugin = directory.get_plugin(constants.L3) if l3plugin: try: ctx_admin = context.elevated() diff --git a/neutron/db/dvr_mac_db.py b/neutron/db/dvr_mac_db.py index 7f817118b40..2a3b981d737 100644 --- a/neutron/db/dvr_mac_db.py +++ b/neutron/db/dvr_mac_db.py @@ -15,6 +15,7 @@ from neutron_lib import constants from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_db import exception as db_exc from oslo_log import helpers as log_helpers @@ -33,7 +34,6 @@ from neutron.db.models import dvr as dvr_models from neutron.db import models_v2 from neutron.extensions import dvr as ext_dvr from neutron.extensions import portbindings -from neutron import manager _deprecate._moved_global('DistributedVirtualRouterMacAddress', new_module=dvr_models) @@ -61,7 +61,7 @@ cfg.CONF.register_opts(dvr_mac_address_opts) def _delete_mac_associated_with_agent(resource, event, trigger, context, agent, **kwargs): host = agent['host'] - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() if [a for a in plugin.get_agents(context, filters={'host': [host]}) if a['id'] != agent['id']]: # there are still agents on this host, don't mess with the mac entry @@ -98,7 +98,7 @@ class DVRDbMixin(ext_dvr.DVRMacAddressPluginBase): return self._plugin except AttributeError: pass - self._plugin = manager.NeutronManager.get_plugin() + self._plugin = directory.get_plugin() return self._plugin def _get_dvr_mac_address_by_host(self, context, host): diff --git a/neutron/db/external_net_db.py b/neutron/db/external_net_db.py index fe00f57c4ca..37d90d07f55 100644 --- a/neutron/db/external_net_db.py +++ b/neutron/db/external_net_db.py @@ -14,8 +14,9 @@ # under the License. from neutron_lib.api import validators -from neutron_lib import constants as lib_constants +from neutron_lib import constants from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from sqlalchemy.orm import exc from sqlalchemy.sql import expression as expr @@ -34,11 +35,9 @@ from neutron.db import models_v2 from neutron.db import rbac_db_models as rbac_db from neutron.extensions import external_net from neutron.extensions import rbac as rbac_ext -from neutron import manager -from neutron.plugins.common import constants as service_constants -DEVICE_OWNER_ROUTER_GW = lib_constants.DEVICE_OWNER_ROUTER_GW +DEVICE_OWNER_ROUTER_GW = constants.DEVICE_OWNER_ROUTER_GW _deprecate._moved_global('ExternalNetwork', new_module=ext_net_models) @@ -180,8 +179,7 @@ class External_net_db_mixin(object): net_data[external_net.EXTERNAL] = False def _process_l3_delete(self, context, network_id): - l3plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + l3plugin = directory.get_plugin(constants.L3) if l3plugin: l3plugin.delete_disassociated_floatingips(context, network_id) diff --git a/neutron/db/l3_agentschedulers_db.py b/neutron/db/l3_agentschedulers_db.py index 6f268f30054..0299f2f8d70 100644 --- a/neutron/db/l3_agentschedulers_db.py +++ b/neutron/db/l3_agentschedulers_db.py @@ -14,6 +14,7 @@ # under the License. from neutron_lib import constants +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_db import exception as db_exc from oslo_log import log as logging @@ -36,8 +37,6 @@ from neutron.db.models import l3_attrs from neutron.db.models import l3agent as rb_model from neutron.extensions import l3agentscheduler from neutron.extensions import router_availability_zone as router_az -from neutron import manager -from neutron.plugins.common import constants as service_constants _deprecate._moved_global('RouterL3AgentBinding', @@ -169,8 +168,7 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase, router_id = router['id'] agent_id = agent['id'] if self.router_scheduler: - plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + plugin = directory.get_plugin(constants.L3) try: if router.get('ha'): self.router_scheduler.create_ha_port_and_bind( @@ -217,8 +215,7 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase, self._unbind_router(context, router_id, agent_id) router = self.get_router(context, router_id) - plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + plugin = directory.get_plugin(constants.L3) if router.get('ha'): plugin.delete_ha_interfaces_on_host(context, router_id, agent.host) # NOTE(Swami): Need to verify if there are DVR serviceable diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py index 56975545ed6..4e57ab85308 100644 --- a/neutron/db/l3_db.py +++ b/neutron/db/l3_db.py @@ -18,8 +18,9 @@ import itertools from debtcollector import removals import netaddr from neutron_lib.api import validators -from neutron_lib import constants as lib_constants +from neutron_lib import constants from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from oslo_log import log as logging from oslo_utils import excutils from oslo_utils import uuidutils @@ -46,8 +47,6 @@ from neutron.db import models_v2 from neutron.db import standardattrdescription_db as st_attr from neutron.extensions import external_net from neutron.extensions import l3 -from neutron import manager -from neutron.plugins.common import constants from neutron.plugins.common import utils as p_utils LOG = logging.getLogger(__name__) @@ -58,10 +57,10 @@ _deprecate._moved_global('Router', new_module=l3_models) _deprecate._moved_global('FloatingIP', new_module=l3_models) -DEVICE_OWNER_HA_REPLICATED_INT = lib_constants.DEVICE_OWNER_HA_REPLICATED_INT -DEVICE_OWNER_ROUTER_INTF = lib_constants.DEVICE_OWNER_ROUTER_INTF -DEVICE_OWNER_ROUTER_GW = lib_constants.DEVICE_OWNER_ROUTER_GW -DEVICE_OWNER_FLOATINGIP = lib_constants.DEVICE_OWNER_FLOATINGIP +DEVICE_OWNER_HA_REPLICATED_INT = constants.DEVICE_OWNER_HA_REPLICATED_INT +DEVICE_OWNER_ROUTER_INTF = constants.DEVICE_OWNER_ROUTER_INTF +DEVICE_OWNER_ROUTER_GW = constants.DEVICE_OWNER_ROUTER_GW +DEVICE_OWNER_FLOATINGIP = constants.DEVICE_OWNER_FLOATINGIP EXTERNAL_GW_INFO = l3.EXTERNAL_GW_INFO # Maps API field to DB column @@ -108,7 +107,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, @property def _core_plugin(self): - return manager.NeutronManager.get_plugin() + return directory.get_plugin() def _get_router(self, context, router_id): try: @@ -224,13 +223,13 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, @db_api.retry_if_session_inactive() def update_router(self, context, id, router): r = router['router'] - gw_info = r.pop(EXTERNAL_GW_INFO, lib_constants.ATTR_NOT_SPECIFIED) + gw_info = r.pop(EXTERNAL_GW_INFO, constants.ATTR_NOT_SPECIFIED) original = self.get_router(context, id) # check whether router needs and can be rescheduled to the proper # l3 agent (associated with given external network); # do check before update in DB as an exception will be raised # in case no proper l3 agent found - if gw_info != lib_constants.ATTR_NOT_SPECIFIED: + if gw_info != constants.ATTR_NOT_SPECIFIED: candidates = self._check_router_needs_rescheduling( context, id, gw_info) # Update the gateway outside of the DB update since it involves L2 @@ -241,8 +240,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, candidates = None router_db = self._update_router_db(context, id, r) if candidates: - l3_plugin = manager.NeutronManager.get_service_plugins().get( - constants.L3_ROUTER_NAT) + l3_plugin = directory.get_plugin(constants.L3) l3_plugin.reschedule_router(context, id, candidates) updated = self._make_router_dict(router_db) registry.notify(resources.ROUTER, events.AFTER_UPDATE, self, @@ -278,11 +276,10 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, # first get plugin supporting l3 agent scheduling # (either l3 service plugin or core_plugin) - l3_plugin = manager.NeutronManager.get_service_plugins().get( - constants.L3_ROUTER_NAT) + l3_plugin = directory.get_plugin(constants.L3) if (not utils.is_extension_supported( l3_plugin, - lib_constants.L3_AGENT_SCHEDULER_EXT_ALIAS) or + constants.L3_AGENT_SCHEDULER_EXT_ALIAS) or l3_plugin.router_scheduler is None): # that might mean that we are dealing with non-agent-based # implementation of l3 services @@ -321,7 +318,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, # Port has no 'tenant-id', as it is hidden from user port_data = {'tenant_id': '', # intentionally not set 'network_id': network_id, - 'fixed_ips': ext_ips or lib_constants.ATTR_NOT_SPECIFIED, + 'fixed_ips': ext_ips or constants.ATTR_NOT_SPECIFIED, 'device_id': router['id'], 'device_owner': DEVICE_OWNER_ROUTER_GW, 'admin_state_up': True, @@ -1023,11 +1020,11 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, RouterPort.router_id, models_v2.IPAllocation.ip_address).join( models_v2.Port, models_v2.IPAllocation).filter( models_v2.Port.network_id == internal_port['network_id'], - RouterPort.port_type.in_(lib_constants.ROUTER_INTERFACE_OWNERS), + RouterPort.port_type.in_(constants.ROUTER_INTERFACE_OWNERS), models_v2.IPAllocation.subnet_id == internal_subnet['id'] ).join(gw_port, gw_port.device_id == RouterPort.router_id).filter( gw_port.network_id == external_network_id, - gw_port.device_owner == lib_constants.DEVICE_OWNER_ROUTER_GW + gw_port.device_owner == constants.DEVICE_OWNER_ROUTER_GW ).distinct() first_router_id = None @@ -1172,7 +1169,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, gw_port = router.gw_port for fixed_ip in gw_port.fixed_ips: addr = netaddr.IPAddress(fixed_ip.ip_address) - if addr.version == lib_constants.IP_VERSION_4: + if addr.version == constants.IP_VERSION_4: next_hop = fixed_ip.ip_address break return {'fixed_ip_address': internal_ip_address, @@ -1190,7 +1187,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, return any(s.ip_version == 4 for s in net.subnets) def _create_floatingip(self, context, floatingip, - initial_status=lib_constants.FLOATINGIP_STATUS_ACTIVE): + initial_status=constants.FLOATINGIP_STATUS_ACTIVE): fip = floatingip['floatingip'] fip_id = uuidutils.generate_uuid() @@ -1212,7 +1209,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, 'admin_state_up': True, 'device_id': 'PENDING', 'device_owner': DEVICE_OWNER_FLOATINGIP, - 'status': lib_constants.PORT_STATUS_NOTAPPLICABLE, + 'status': constants.PORT_STATUS_NOTAPPLICABLE, 'name': ''} if fip.get('floating_ip_address'): port['fixed_ips'] = [ @@ -1278,7 +1275,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, @db_api.retry_if_session_inactive() def create_floatingip(self, context, floatingip, - initial_status=lib_constants.FLOATINGIP_STATUS_ACTIVE): + initial_status=constants.FLOATINGIP_STATUS_ACTIVE): return self._create_floatingip(context, floatingip, initial_status) def _update_floatingip(self, context, id, floatingip): @@ -1629,8 +1626,8 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, port['subnets'] = [] port['extra_subnets'] = [] - port['address_scopes'] = {lib_constants.IP_VERSION_4: None, - lib_constants.IP_VERSION_6: None} + port['address_scopes'] = {constants.IP_VERSION_4: None, + constants.IP_VERSION_6: None} scopes = {} for subnet in subnets_by_network[port['network_id']]: @@ -1665,18 +1662,18 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, for floating_ip in floating_ips: router = routers_dict.get(floating_ip['router_id']) if router: - router_floatingips = router.get(lib_constants.FLOATINGIP_KEY, + router_floatingips = router.get(constants.FLOATINGIP_KEY, []) router_floatingips.append(floating_ip) - router[lib_constants.FLOATINGIP_KEY] = router_floatingips + router[constants.FLOATINGIP_KEY] = router_floatingips def _process_interfaces(self, routers_dict, interfaces): for interface in interfaces: router = routers_dict.get(interface['device_id']) if router: - router_interfaces = router.get(lib_constants.INTERFACE_KEY, []) + router_interfaces = router.get(constants.INTERFACE_KEY, []) router_interfaces.append(interface) - router[lib_constants.INTERFACE_KEY] = router_interfaces + router[constants.INTERFACE_KEY] = router_interfaces def _get_router_info_list(self, context, router_ids=None, active=None, device_owners=None): @@ -1803,7 +1800,7 @@ class L3_NAT_db_mixin(L3_NAT_dbonly_mixin, L3RpcNotifierMixin): return router_interface_info def create_floatingip(self, context, floatingip, - initial_status=lib_constants.FLOATINGIP_STATUS_ACTIVE): + initial_status=constants.FLOATINGIP_STATUS_ACTIVE): floatingip_dict = super(L3_NAT_db_mixin, self).create_floatingip( context, floatingip, initial_status) router_id = floatingip_dict['router_id'] @@ -1851,8 +1848,7 @@ def _prevent_l3_port_delete_callback(resource, event, trigger, **kwargs): context = kwargs['context'] port_id = kwargs['port_id'] port_check = kwargs['port_check'] - l3plugin = manager.NeutronManager.get_service_plugins().get( - constants.L3_ROUTER_NAT) + l3plugin = directory.get_plugin(constants.L3) if l3plugin and port_check: l3plugin.prevent_l3_port_deletion(context, port_id) @@ -1860,14 +1856,12 @@ def _prevent_l3_port_delete_callback(resource, event, trigger, **kwargs): def _notify_routers_callback(resource, event, trigger, **kwargs): context = kwargs['context'] router_ids = kwargs['router_ids'] - l3plugin = manager.NeutronManager.get_service_plugins().get( - constants.L3_ROUTER_NAT) + l3plugin = directory.get_plugin(constants.L3) l3plugin.notify_routers_updated(context, router_ids) def _notify_subnet_gateway_ip_update(resource, event, trigger, **kwargs): - l3plugin = manager.NeutronManager.get_service_plugins().get( - constants.L3_ROUTER_NAT) + l3plugin = directory.get_plugin(constants.L3) if not l3plugin: return context = kwargs['context'] @@ -1875,7 +1869,7 @@ def _notify_subnet_gateway_ip_update(resource, event, trigger, **kwargs): subnet_id = kwargs['subnet_id'] query = context.session.query(models_v2.Port).filter_by( network_id=network_id, - device_owner=lib_constants.DEVICE_OWNER_ROUTER_GW) + device_owner=constants.DEVICE_OWNER_ROUTER_GW) query = query.join(models_v2.Port.fixed_ips).filter( models_v2.IPAllocation.subnet_id == subnet_id) router_ids = set(port['device_id'] for port in query) @@ -1899,8 +1893,7 @@ def _notify_subnetpool_address_scope_update(resource, event, query = query.distinct() router_ids = [r[0] for r in query] - l3plugin = manager.NeutronManager.get_service_plugins().get( - constants.L3_ROUTER_NAT) + l3plugin = directory.get_plugin(constants.L3) l3plugin.notify_routers_updated(context, router_ids) diff --git a/neutron/db/l3_dvr_db.py b/neutron/db/l3_dvr_db.py index 88ad40f009e..514217c38a5 100644 --- a/neutron/db/l3_dvr_db.py +++ b/neutron/db/l3_dvr_db.py @@ -16,6 +16,7 @@ import collections from neutron_lib.api import validators from neutron_lib import constants as const from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_log import helpers as log_helper from oslo_log import log as logging @@ -39,8 +40,6 @@ from neutron.db import models_v2 from neutron.extensions import l3 from neutron.extensions import portbindings from neutron.ipam import utils as ipam_utils -from neutron import manager -from neutron.plugins.common import constants from neutron.plugins.common import utils as p_utils @@ -505,8 +504,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, L3_NAT_with_dvr_db_mixin, self).remove_router_interface( context, router_id, interface_info) - plugin = manager.NeutronManager.get_service_plugins().get( - constants.L3_ROUTER_NAT) + plugin = directory.get_plugin(const.L3) router_hosts_before = plugin._get_dvr_hosts_for_router( context, router_id) diff --git a/neutron/db/l3_dvrscheduler_db.py b/neutron/db/l3_dvrscheduler_db.py index adefaa4ee42..37ebca34340 100644 --- a/neutron/db/l3_dvrscheduler_db.py +++ b/neutron/db/l3_dvrscheduler_db.py @@ -14,6 +14,7 @@ # under the License. from neutron_lib import constants as n_const +from neutron_lib.plugins import directory from oslo_log import log as logging from sqlalchemy import or_ @@ -27,8 +28,6 @@ from neutron.db import l3_agentschedulers_db as l3agent_sch_db from neutron.db.models import l3agent as rb_model from neutron.db import models_v2 from neutron.extensions import portbindings -from neutron import manager -from neutron.plugins.common import constants as service_constants from neutron.plugins.ml2 import db as ml2_db from neutron.plugins.ml2 import models as ml2_models @@ -95,8 +94,7 @@ class L3_DVRsch_db_mixin(l3agent_sch_db.L3AgentSchedulerDbMixin): # Make sure we create the floatingip agent gateway port # for the destination node if fip is associated with this # fixed port - l3plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + l3plugin = directory.get_plugin(n_const.L3) ( l3plugin. check_for_fip_and_create_agent_gw_port_on_host_if_not_exists( @@ -372,8 +370,7 @@ def _notify_l3_agent_new_port(resource, event, trigger, **kwargs): return if n_utils.is_dvr_serviced(port['device_owner']): - l3plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + l3plugin = directory.get_plugin(n_const.L3) context = kwargs['context'] l3plugin.dvr_handle_new_service_port(context, port) l3plugin.update_arp_entry_for_dvr_service_port(context, port) @@ -382,8 +379,7 @@ def _notify_l3_agent_new_port(resource, event, trigger, **kwargs): def _notify_port_delete(event, resource, trigger, **kwargs): context = kwargs['context'] port = kwargs['port'] - l3plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + l3plugin = directory.get_plugin(n_const.L3) if port: port_host = port.get(portbindings.HOST_ID) allowed_address_pairs_list = port.get('allowed_address_pairs') @@ -406,8 +402,7 @@ def _notify_l3_agent_port_update(resource, event, trigger, **kwargs): original_device_owner = original_port.get('device_owner', '') new_device_owner = new_port.get('device_owner', '') is_new_device_dvr_serviced = n_utils.is_dvr_serviced(new_device_owner) - l3plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + l3plugin = directory.get_plugin(n_const.L3) context = kwargs['context'] is_port_no_longer_serviced = ( n_utils.is_dvr_serviced(original_device_owner) and diff --git a/neutron/db/l3_hascheduler_db.py b/neutron/db/l3_hascheduler_db.py index fccf7b8f51e..bbb6139a5cd 100644 --- a/neutron/db/l3_hascheduler_db.py +++ b/neutron/db/l3_hascheduler_db.py @@ -13,6 +13,7 @@ # under the License. from neutron_lib import constants +from neutron_lib.plugins import directory from sqlalchemy import func from sqlalchemy import sql @@ -25,8 +26,6 @@ from neutron.db.models import l3 as l3_models from neutron.db.models import l3_attrs from neutron.db.models import l3agent as rb_model from neutron.extensions import portbindings -from neutron import manager -from neutron.plugins.common import constants as service_constants class L3_HA_scheduler_db_mixin(l3_sch_db.AZL3AgentSchedulerDbMixin): @@ -103,8 +102,7 @@ def _notify_l3_agent_ha_port_update(resource, event, trigger, **kwargs): if (new_device_owner == constants.DEVICE_OWNER_ROUTER_HA_INTF and new_port['status'] == constants.PORT_STATUS_ACTIVE and original_port['status'] != new_port['status']): - l3plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + l3plugin = directory.get_plugin(constants.L3) l3plugin.l3_rpc_notifier.routers_updated_on_host( context, [new_port['device_id']], host) diff --git a/neutron/db/metering/metering_rpc.py b/neutron/db/metering/metering_rpc.py index 7b34fd5cb45..bc943a92a38 100644 --- a/neutron/db/metering/metering_rpc.py +++ b/neutron/db/metering/metering_rpc.py @@ -13,13 +13,12 @@ # under the License. from neutron_lib import constants as consts +from neutron_lib.plugins import directory from oslo_log import log as logging import oslo_messaging from neutron._i18n import _LE from neutron.common import utils -from neutron import manager -from neutron.plugins.common import constants as service_constants LOG = logging.getLogger(__name__) @@ -32,8 +31,7 @@ class MeteringRpcCallbacks(object): self.meter_plugin = meter_plugin def get_sync_data_metering(self, context, **kwargs): - l3_plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + l3_plugin = directory.get_plugin(consts.L3) if not l3_plugin: return diff --git a/neutron/db/rbac_db_models.py b/neutron/db/rbac_db_models.py index c70f5b01898..8e5318b6652 100644 --- a/neutron/db/rbac_db_models.py +++ b/neutron/db/rbac_db_models.py @@ -17,13 +17,13 @@ import abc from neutron_lib.db import model_base from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory import sqlalchemy as sa from sqlalchemy.ext import declarative from sqlalchemy.orm import validates from neutron._i18n import _ from neutron.api.v2 import attributes as attr -from neutron import manager ACCESS_SHARED = 'access_as_shared' @@ -97,7 +97,7 @@ class NetworkRBAC(RBACColumns, model_base.BASEV2): def get_valid_actions(self): actions = (ACCESS_SHARED,) - pl = manager.NeutronManager.get_plugin() + pl = directory.get_plugin() if 'external-net' in pl.supported_extension_aliases: actions += (ACCESS_EXTERNAL,) return actions diff --git a/neutron/extensions/address_scope.py b/neutron/extensions/address_scope.py index 0930233dffc..61a979255fe 100644 --- a/neutron/extensions/address_scope.py +++ b/neutron/extensions/address_scope.py @@ -17,13 +17,13 @@ import abc from neutron_lib.api import converters from neutron_lib import constants from neutron_lib import exceptions as nexception +from neutron_lib.plugins import directory import six from neutron._i18n import _ from neutron.api import extensions from neutron.api.v2 import attributes as attr from neutron.api.v2 import base -from neutron import manager ADDRESS_SCOPE = 'address_scope' ADDRESS_SCOPES = '%ss' % ADDRESS_SCOPE @@ -118,7 +118,7 @@ class Address_scope(extensions.ExtensionDescriptor): """Returns Ext Resources.""" my_plurals = [(key, key[:-1]) for key in RESOURCE_ATTRIBUTE_MAP.keys()] attr.PLURALS.update(dict(my_plurals)) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() collection_name = ADDRESS_SCOPES.replace('_', '-') params = RESOURCE_ATTRIBUTE_MAP.get(ADDRESS_SCOPES, dict()) controller = base.create_resource(collection_name, diff --git a/neutron/extensions/agent.py b/neutron/extensions/agent.py index 1ef06af73ce..1073939d1aa 100644 --- a/neutron/extensions/agent.py +++ b/neutron/extensions/agent.py @@ -17,13 +17,13 @@ import abc from neutron_lib.api import converters from neutron_lib import exceptions +from neutron_lib.plugins import directory import six from neutron._i18n import _ from neutron.api import extensions from neutron.api.v2 import attributes as attr from neutron.api.v2 import base -from neutron import manager # Attribute Map @@ -100,7 +100,7 @@ class Agent(extensions.ExtensionDescriptor): """Returns Ext Resources.""" my_plurals = [(key, key[:-1]) for key in RESOURCE_ATTRIBUTE_MAP.keys()] attr.PLURALS.update(dict(my_plurals)) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() params = RESOURCE_ATTRIBUTE_MAP.get(RESOURCE_NAME + 's') controller = base.create_resource(RESOURCE_NAME + 's', RESOURCE_NAME, diff --git a/neutron/extensions/auto_allocated_topology.py b/neutron/extensions/auto_allocated_topology.py index cdc1ec07fe6..2b533b8908b 100644 --- a/neutron/extensions/auto_allocated_topology.py +++ b/neutron/extensions/auto_allocated_topology.py @@ -15,10 +15,10 @@ # under the License. from neutron_lib.api import converters +from neutron_lib.plugins import directory from neutron.api import extensions from neutron.api.v2 import base -from neutron import manager RESOURCE_NAME = "auto_allocated_topology" COLLECTION_NAME = "auto_allocated_topologies" @@ -67,8 +67,7 @@ class Auto_allocated_topology(extensions.ExtensionDescriptor): params = RESOURCE_ATTRIBUTE_MAP.get(COLLECTION_NAME, dict()) controller = base.create_resource(COLLECTION_NAME, EXT_ALIAS, - manager.NeutronManager. - get_service_plugins()[EXT_ALIAS], + directory.get_plugin(EXT_ALIAS), params, allow_bulk=False) return [extensions.ResourceExtension(EXT_ALIAS, controller)] diff --git a/neutron/extensions/availability_zone.py b/neutron/extensions/availability_zone.py index e9b744264b2..98dbedc40d5 100644 --- a/neutron/extensions/availability_zone.py +++ b/neutron/extensions/availability_zone.py @@ -16,6 +16,7 @@ import abc from neutron_lib.api import validators from neutron_lib import exceptions +from neutron_lib.plugins import directory from oslo_serialization import jsonutils import six @@ -23,7 +24,6 @@ from neutron._i18n import _ from neutron.api import extensions from neutron.api.v2 import attributes as attr from neutron.api.v2 import base -from neutron import manager AZ_HINTS_DB_LEN = 255 @@ -106,7 +106,7 @@ class Availability_zone(extensions.ExtensionDescriptor): """Returns Ext Resources.""" my_plurals = [(key, key[:-1]) for key in RESOURCE_ATTRIBUTE_MAP.keys()] attr.PLURALS.update(dict(my_plurals)) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() params = RESOURCE_ATTRIBUTE_MAP.get(AVAILABILITY_ZONES) controller = base.create_resource(AVAILABILITY_ZONES, RESOURCE_NAME, plugin, params) diff --git a/neutron/extensions/dhcpagentscheduler.py b/neutron/extensions/dhcpagentscheduler.py index 41f922e9f21..f53bb145b45 100644 --- a/neutron/extensions/dhcpagentscheduler.py +++ b/neutron/extensions/dhcpagentscheduler.py @@ -17,6 +17,7 @@ import abc from neutron_lib import constants from neutron_lib import exceptions +from neutron_lib.plugins import directory import six from neutron._i18n import _ @@ -25,7 +26,6 @@ from neutron.api.v2 import base from neutron.api.v2 import resource from neutron.common import rpc as n_rpc from neutron.extensions import agent -from neutron import manager from neutron import policy from neutron import wsgi @@ -37,7 +37,7 @@ DHCP_AGENTS = DHCP_AGENT + 's' class NetworkSchedulerController(wsgi.Controller): def index(self, request, **kwargs): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() policy.enforce(request.context, "get_%s" % DHCP_NETS, {}) @@ -45,7 +45,7 @@ class NetworkSchedulerController(wsgi.Controller): request.context, kwargs['agent_id']) def create(self, request, body, **kwargs): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() policy.enforce(request.context, "create_%s" % DHCP_NET, {}) @@ -57,7 +57,7 @@ class NetworkSchedulerController(wsgi.Controller): return result def delete(self, request, id, **kwargs): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() policy.enforce(request.context, "delete_%s" % DHCP_NET, {}) @@ -70,7 +70,7 @@ class NetworkSchedulerController(wsgi.Controller): class DhcpAgentsHostingNetworkController(wsgi.Controller): def index(self, request, **kwargs): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() policy.enforce(request.context, "get_%s" % DHCP_AGENTS, {}) diff --git a/neutron/extensions/flavors.py b/neutron/extensions/flavors.py index 27cede39cb6..3ebc43bce07 100644 --- a/neutron/extensions/flavors.py +++ b/neutron/extensions/flavors.py @@ -15,13 +15,13 @@ from neutron_lib.api import converters from neutron_lib.api import validators from neutron_lib import exceptions as nexception +from neutron_lib.plugins import directory from neutron._i18n import _ from neutron.api import extensions from neutron.api.v2 import attributes as attr from neutron.api.v2 import base from neutron.api.v2 import resource_helper -from neutron import manager from neutron.plugins.common import constants @@ -74,8 +74,7 @@ class InvalidFlavorServiceType(nexception.InvalidInput): def _validate_flavor_service_type(validate_type, valid_values=None): """Ensure requested flavor service type plugin is loaded.""" - plugins = manager.NeutronManager.get_service_plugins() - if validate_type not in plugins: + if not directory.get_plugin(validate_type): raise InvalidFlavorServiceType(service_type=validate_type) validators.add_validator('validate_flavor_service_type', @@ -204,8 +203,7 @@ class Flavors(extensions.ExtensionDescriptor): plural_mappings, RESOURCE_ATTRIBUTE_MAP, constants.FLAVORS) - plugin = manager.NeutronManager.get_service_plugins()[ - constants.FLAVORS] + plugin = directory.get_plugin(constants.FLAVORS) for collection_name in SUB_RESOURCE_ATTRIBUTE_MAP: # Special handling needed for sub-resources with 'y' ending # (e.g. proxies -> proxy) diff --git a/neutron/extensions/l3agentscheduler.py b/neutron/extensions/l3agentscheduler.py index d70f88af481..aae7bc55e59 100644 --- a/neutron/extensions/l3agentscheduler.py +++ b/neutron/extensions/l3agentscheduler.py @@ -17,6 +17,7 @@ import abc from neutron_lib import constants from neutron_lib import exceptions +from neutron_lib.plugins import directory from oslo_log import log as logging import six import webob.exc @@ -27,8 +28,6 @@ from neutron.api.v2 import base from neutron.api.v2 import resource from neutron.common import rpc as n_rpc from neutron.extensions import agent -from neutron import manager -from neutron.plugins.common import constants as service_constants from neutron import policy from neutron import wsgi @@ -44,8 +43,7 @@ L3_AGENTS = L3_AGENT + 's' class RouterSchedulerController(wsgi.Controller): def get_plugin(self): - plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + plugin = directory.get_plugin(constants.L3) if not plugin: LOG.error(_LE('No plugin for L3 routing registered to handle ' 'router scheduling')) @@ -87,8 +85,7 @@ class RouterSchedulerController(wsgi.Controller): class L3AgentsHostingRouterController(wsgi.Controller): def get_plugin(self): - plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + plugin = directory.get_plugin(constants.L3) if not plugin: LOG.error(_LE('No plugin for L3 routing registered to handle ' 'router scheduling')) diff --git a/neutron/extensions/qos.py b/neutron/extensions/qos.py index ca2539d2adb..9b0ebd116c9 100644 --- a/neutron/extensions/qos.py +++ b/neutron/extensions/qos.py @@ -18,6 +18,7 @@ import itertools import re from neutron_lib.api import converters +from neutron_lib.plugins import directory import six from neutron.api import extensions @@ -25,7 +26,6 @@ from neutron.api.v2 import attributes as attr from neutron.api.v2 import base from neutron.api.v2 import resource_helper from neutron.common import constants as common_constants -from neutron import manager from neutron.objects.qos import rule as rule_object from neutron.plugins.common import constants from neutron.services.qos import qos_consts @@ -169,7 +169,7 @@ class Qos(extensions.ExtensionDescriptor): translate_name=True, allow_bulk=True) - plugin = manager.NeutronManager.get_service_plugins()[constants.QOS] + plugin = directory.get_plugin(constants.QOS) for collection_name in SUB_RESOURCE_ATTRIBUTE_MAP: resource_name = collection_name[:-1] parent = SUB_RESOURCE_ATTRIBUTE_MAP[collection_name].get('parent') diff --git a/neutron/extensions/quotasv2.py b/neutron/extensions/quotasv2.py index e671c5b7b33..e90f5c43188 100644 --- a/neutron/extensions/quotasv2.py +++ b/neutron/extensions/quotasv2.py @@ -15,6 +15,7 @@ from neutron_lib.api import converters from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_utils import importutils import webob @@ -26,7 +27,6 @@ from neutron.api.v2 import base from neutron.api.v2 import resource from neutron.common import constants as const from neutron.common import exceptions -from neutron import manager from neutron.pecan_wsgi import controllers from neutron.pecan_wsgi.controllers import utils as pecan_utils from neutron import quota @@ -153,7 +153,7 @@ class Quotasv2(extensions.ExtensionDescriptor): def get_resources(cls): """Returns Ext Resources.""" controller = resource.Resource( - QuotaSetsController(manager.NeutronManager.get_plugin()), + QuotaSetsController(directory.get_plugin()), faults=base.FAULT_MAP) return [extensions.ResourceExtension( Quotasv2.get_alias(), diff --git a/neutron/extensions/rbac.py b/neutron/extensions/rbac.py index 0092abab8b0..b37ae844cdb 100644 --- a/neutron/extensions/rbac.py +++ b/neutron/extensions/rbac.py @@ -14,6 +14,7 @@ # under the License. from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from neutron._i18n import _ from neutron.api import extensions @@ -21,7 +22,6 @@ from neutron.api.v2 import attributes as attr from neutron.api.v2 import base from neutron.conf import quota from neutron.db import rbac_db_models -from neutron import manager from neutron.quota import resource_registry @@ -106,7 +106,7 @@ class Rbac(extensions.ExtensionDescriptor): """Returns Ext Resources.""" plural_mappings = {'rbac_policies': 'rbac_policy'} attr.PLURALS.update(plural_mappings) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() params = RESOURCE_ATTRIBUTE_MAP['rbac_policies'] collection_name = 'rbac-policies' resource_name = 'rbac_policy' diff --git a/neutron/extensions/securitygroup.py b/neutron/extensions/securitygroup.py index 055be8e6abe..2955937e1f8 100644 --- a/neutron/extensions/securitygroup.py +++ b/neutron/extensions/securitygroup.py @@ -19,6 +19,7 @@ import netaddr from neutron_lib.api import validators from neutron_lib import constants as const from neutron_lib import exceptions as nexception +from neutron_lib.plugins import directory from oslo_utils import netutils from oslo_utils import uuidutils import six @@ -29,7 +30,6 @@ from neutron.api.v2 import attributes as attr from neutron.api.v2 import base from neutron.common import exceptions from neutron.conf import quota -from neutron import manager from neutron.quota import resource_registry @@ -306,7 +306,7 @@ class Securitygroup(extensions.ExtensionDescriptor): my_plurals = [(key, key[:-1]) for key in RESOURCE_ATTRIBUTE_MAP.keys()] attr.PLURALS.update(dict(my_plurals)) exts = [] - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() for resource_name in ['security_group', 'security_group_rule']: collection_name = resource_name.replace('_', '-') + "s" params = RESOURCE_ATTRIBUTE_MAP.get(resource_name + "s", dict()) diff --git a/neutron/extensions/segment.py b/neutron/extensions/segment.py index fd39c7107f8..6dd12ada8fb 100644 --- a/neutron/extensions/segment.py +++ b/neutron/extensions/segment.py @@ -17,12 +17,12 @@ import six from neutron_lib.api import converters from neutron_lib import constants +from neutron_lib.plugins import directory from neutron.api import extensions from neutron.api.v2 import attributes from neutron.api.v2 import base from neutron.extensions import providernet -from neutron import manager SEGMENT = 'segment' SEGMENTS = '%ss' % SEGMENT @@ -115,7 +115,7 @@ class Segment(extensions.ExtensionDescriptor): controller = base.create_resource( SEGMENTS, SEGMENT, - manager.NeutronManager.get_service_plugins()[SEGMENTS], + directory.get_plugin(SEGMENTS), resource_attributes) return [extensions.ResourceExtension(SEGMENTS, controller, diff --git a/neutron/extensions/tag.py b/neutron/extensions/tag.py index a09dfa97796..e3c33873071 100644 --- a/neutron/extensions/tag.py +++ b/neutron/extensions/tag.py @@ -15,6 +15,7 @@ import abc from neutron_lib.api import validators from neutron_lib import exceptions +from neutron_lib.plugins import directory import six import webob.exc @@ -23,7 +24,6 @@ from neutron.api import extensions from neutron.api.v2 import attributes from neutron.api.v2 import base from neutron.api.v2 import resource as api_resource -from neutron import manager from neutron.services import service_base @@ -74,8 +74,7 @@ def validate_tags(body): class TagController(object): def __init__(self): - self.plugin = (manager.NeutronManager.get_service_plugins() - [TAG_PLUGIN_TYPE]) + self.plugin = directory.get_plugin(TAG_PLUGIN_TYPE) def index(self, request, **kwargs): # GET /v2.0/networks/{network_id}/tags diff --git a/neutron/ipam/drivers/neutrondb_ipam/driver.py b/neutron/ipam/drivers/neutrondb_ipam/driver.py index 1858d5daac4..4f2443fac67 100644 --- a/neutron/ipam/drivers/neutrondb_ipam/driver.py +++ b/neutron/ipam/drivers/neutrondb_ipam/driver.py @@ -18,6 +18,7 @@ import random import netaddr from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from oslo_db import exception as db_exc from oslo_log import log from oslo_utils import uuidutils @@ -29,7 +30,6 @@ from neutron.ipam import exceptions as ipam_exc from neutron.ipam import requests as ipam_req from neutron.ipam import subnet_alloc from neutron.ipam import utils as ipam_utils -from neutron import manager LOG = log.getLogger(__name__) @@ -110,7 +110,7 @@ class NeutronDbSubnet(ipam_base.Subnet): @classmethod def _fetch_subnet(cls, context, id): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() return plugin._get_subnet(context, id) def __init__(self, internal_id, ctx, cidr=None, diff --git a/neutron/manager.py b/neutron/manager.py index 808c2394e7e..cd0f0f8502e 100644 --- a/neutron/manager.py +++ b/neutron/manager.py @@ -14,8 +14,8 @@ # under the License. from collections import defaultdict -import weakref - +from neutron_lib import constants as lib_const +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_log import log as logging import oslo_messaging @@ -102,8 +102,11 @@ class NeutronManager(object): Neutron's Manager class is responsible for parsing a config file and instantiating the correct plugin that concretely implements neutron_plugin_base class. - The caller should make sure that NeutronManager is a singleton. """ + # TODO(armax): use of the singleton pattern for this class is vestigial, + # and it is mainly relied on by the unit tests. It is safer to get rid + # of it once the entire codebase (neutron + subprojects) has switched + # entirely to using the plugins directory. _instance = None __trace_args__ = {"name": "rpc"} @@ -123,18 +126,17 @@ class NeutronManager(object): # for performance metrics. plugin_provider = cfg.CONF.core_plugin LOG.info(_LI("Loading core plugin: %s"), plugin_provider) - self.plugin = self._get_plugin_instance(CORE_PLUGINS_NAMESPACE, - plugin_provider) + # NOTE(armax): keep hold of the actual plugin object + plugin = self._get_plugin_instance(CORE_PLUGINS_NAMESPACE, + plugin_provider) + directory.add_plugin(lib_const.CORE, plugin) msg = validate_post_plugin_load() if msg: LOG.critical(msg) raise Exception(msg) - # core plugin as a part of plugin collection simplifies - # checking extensions - # TODO(enikanorov): make core plugin the same as - # the rest of service plugins - self.service_plugins = {constants.CORE: self.plugin} + # load services from the core plugin first + self._load_services_from_core_plugin(plugin) self._load_service_plugins() # Used by pecan WSGI self.resource_plugin_mappings = {} @@ -161,16 +163,15 @@ class NeutronManager(object): plugin_class = self.load_class_for_provider(namespace, plugin_provider) return plugin_class() - def _load_services_from_core_plugin(self): + def _load_services_from_core_plugin(self, plugin): """Puts core plugin in service_plugins for supported services.""" LOG.debug("Loading services supported by the core plugin") # supported service types are derived from supported extensions - for ext_alias in getattr(self.plugin, - "supported_extension_aliases", []): + for ext_alias in getattr(plugin, "supported_extension_aliases", []): if ext_alias in constants.EXT_TO_SERVICE_MAPPING: service_type = constants.EXT_TO_SERVICE_MAPPING[ext_alias] - self.service_plugins[service_type] = self.plugin + directory.add_plugin(service_type, plugin) LOG.info(_LI("Service %s is supported by the core plugin"), service_type) @@ -184,9 +185,6 @@ class NeutronManager(object): Starts from the core plugin and checks if it supports advanced services then loads classes provided in configuration. """ - # load services from the core plugin first - self._load_services_from_core_plugin() - plugin_providers = cfg.CONF.service_plugins plugin_providers.extend(self._get_default_service_plugins()) LOG.debug("Loading service plugins: %s", plugin_providers) @@ -201,22 +199,25 @@ class NeutronManager(object): # only one implementation of svc_type allowed # specifying more than one plugin # for the same type is a fatal exception - if plugin_inst.get_plugin_type() in self.service_plugins: + # TODO(armax): simplify this by moving the conditional into the + # directory itself. + plugin_type = plugin_inst.get_plugin_type() + if directory.get_plugin(plugin_type): raise ValueError(_("Multiple plugins for service " - "%s were configured") % - plugin_inst.get_plugin_type()) + "%s were configured") % plugin_type) - self.service_plugins[plugin_inst.get_plugin_type()] = plugin_inst + directory.add_plugin(plugin_type, plugin_inst) # search for possible agent notifiers declared in service plugin # (needed by agent management extension) - if (hasattr(self.plugin, 'agent_notifiers') and + plugin = directory.get_plugin() + if (hasattr(plugin, 'agent_notifiers') and hasattr(plugin_inst, 'agent_notifiers')): - self.plugin.agent_notifiers.update(plugin_inst.agent_notifiers) + plugin.agent_notifiers.update(plugin_inst.agent_notifiers) LOG.debug("Successfully loaded %(type)s plugin. " "Description: %(desc)s", - {"type": plugin_inst.get_plugin_type(), + {"type": plugin_type, "desc": plugin_inst.get_plugin_description()}) @classmethod @@ -240,23 +241,6 @@ class NeutronManager(object): cls._create_instance() return cls._instance - @classmethod - def get_plugin(cls): - # Return a weakref to minimize gc-preventing references. - return weakref.proxy(cls.get_instance().plugin) - - @classmethod - def get_service_plugins(cls): - # Return weakrefs to minimize gc-preventing references. - service_plugins = cls.get_instance().service_plugins - return dict((x, weakref.proxy(y)) - for x, y in six.iteritems(service_plugins)) - - @classmethod - def get_unique_service_plugins(cls): - service_plugins = cls.get_instance().service_plugins - return tuple(weakref.proxy(x) for x in set(service_plugins.values())) - @classmethod def set_plugin_for_resource(cls, resource, plugin): cls.get_instance().resource_plugin_mappings[resource] = plugin @@ -283,7 +267,7 @@ class NeutronManager(object): # probably should be removed @classmethod def get_service_plugin_by_path_prefix(cls, path_prefix): - service_plugins = cls.get_unique_service_plugins() + service_plugins = directory.get_unique_plugins() for service_plugin in service_plugins: plugin_path_prefix = getattr(service_plugin, 'path_prefix', None) if plugin_path_prefix and plugin_path_prefix == path_prefix: @@ -298,3 +282,10 @@ class NeutronManager(object): @classmethod def get_resources_for_path_prefix(cls, path_prefix): return cls.get_instance().path_prefix_resource_mappings[path_prefix] + + +def init(): + """Call to load the plugins (core+services) machinery.""" + # TODO(armax): use is_loaded() when available + if not directory.get_plugins(): + NeutronManager.get_instance() diff --git a/neutron/notifiers/nova.py b/neutron/notifiers/nova.py index f5eb71cd300..dec1270b667 100644 --- a/neutron/notifiers/nova.py +++ b/neutron/notifiers/nova.py @@ -16,6 +16,7 @@ from keystoneauth1 import loading as ks_loading from neutron_lib import constants from neutron_lib import exceptions as exc +from neutron_lib.plugins import directory from novaclient import client as nova_client from novaclient import exceptions as nova_exceptions from oslo_config import cfg @@ -28,7 +29,6 @@ from neutron.callbacks import events from neutron.callbacks import registry from neutron.callbacks import resources from neutron import context -from neutron import manager from neutron.notifiers import batch_notifier @@ -102,15 +102,6 @@ class Notifier(object): 'name': VIF_DELETED, 'tag': port['id']} - @property - def _plugin(self): - # NOTE(arosen): this cannot be set in __init__ currently since - # this class is initialized at the same time as NeutronManager() - # which is decorated with synchronized() - if not hasattr(self, '_plugin_ref'): - self._plugin_ref = manager.NeutronManager.get_plugin() - return self._plugin_ref - def _send_nova_notification(self, resource, event, trigger, action=None, original=None, data=None, **kwargs): @@ -162,7 +153,7 @@ class Notifier(object): ctx = context.get_admin_context() try: - port = self._plugin.get_port(ctx, port_id) + port = directory.get_plugin().get_port(ctx, port_id) except exc.PortNotFound: LOG.debug("Port %s was deleted, no need to send any " "notification", port_id) diff --git a/neutron/objects/db/api.py b/neutron/objects/db/api.py index 8bd9eae9b11..3ac1c9e8440 100644 --- a/neutron/objects/db/api.py +++ b/neutron/objects/db/api.py @@ -14,15 +14,14 @@ # backends from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from oslo_utils import uuidutils -from neutron import manager - # Common database operation implementations def _get_filter_query(context, model, **kwargs): # TODO(jlibosva): decompose _get_collection_query from plugin instance - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with context.session.begin(subtransactions=True): filters = _kwargs_to_filters(**kwargs) query = plugin._get_collection_query(context, model, filters) @@ -46,7 +45,7 @@ def get_objects(context, model, _pager=None, **kwargs): with context.session.begin(subtransactions=True): filters = _kwargs_to_filters(**kwargs) # TODO(ihrachys): decompose _get_collection from plugin instance - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() return plugin._get_collection( context, model, # TODO(ihrachys): avoid this no-op call per model found diff --git a/neutron/objects/qos/rule_type.py b/neutron/objects/qos/rule_type.py index b06af937d8e..fd5d9c16580 100644 --- a/neutron/objects/qos/rule_type.py +++ b/neutron/objects/qos/rule_type.py @@ -10,10 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.plugins import directory from oslo_versionedobjects import base as obj_base from oslo_versionedobjects import fields as obj_fields -from neutron import manager from neutron.objects import base from neutron.services.qos import qos_consts @@ -42,7 +42,7 @@ class QosRuleType(base.NeutronObject): def get_objects(cls, validate_filters=True, **kwargs): if validate_filters: cls.validate_filters(**kwargs) - core_plugin = manager.NeutronManager.get_plugin() + core_plugin = directory.get_plugin() # TODO(ihrachys): apply filters to returned result return [cls(type=type_) for type_ in core_plugin.supported_qos_rule_types] diff --git a/neutron/pecan_wsgi/hooks/ownership_validation.py b/neutron/pecan_wsgi/hooks/ownership_validation.py index e3c4af38168..4294d007d18 100644 --- a/neutron/pecan_wsgi/hooks/ownership_validation.py +++ b/neutron/pecan_wsgi/hooks/ownership_validation.py @@ -13,11 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.plugins import directory from pecan import hooks import webob from neutron._i18n import _ -from neutron import manager class OwnershipValidationHook(hooks.PecanHook): @@ -38,7 +38,7 @@ class OwnershipValidationHook(hooks.PecanHook): if (neutron_context.is_admin or neutron_context.is_advsvc or resource not in ('port', 'subnet')): return - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() network = plugin.get_network(neutron_context, resource_item['network_id']) # do not perform the check on shared networks diff --git a/neutron/pecan_wsgi/startup.py b/neutron/pecan_wsgi/startup.py index 343ec2c5304..0a553c805fe 100644 --- a/neutron/pecan_wsgi/startup.py +++ b/neutron/pecan_wsgi/startup.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.plugins import directory from oslo_log import log from neutron._i18n import _LW @@ -31,13 +32,14 @@ LOG = log.getLogger(__name__) def initialize_all(): + manager.init() ext_mgr = extensions.PluginAwareExtensionManager.get_instance() ext_mgr.extend_resources("2.0", attributes.RESOURCE_ATTRIBUTE_MAP) # At this stage we have a fully populated resource attribute map; # build Pecan controllers and routes for all core resources for resource, collection in router.RESOURCES.items(): resource_registry.register_resource_by_name(resource) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() new_controller = res_ctrl.CollectionsController(collection, resource, plugin=plugin) manager.NeutronManager.set_controller_for_resource( diff --git a/neutron/plugins/ml2/db.py b/neutron/plugins/ml2/db.py index 1dba508bd36..4b36b1a2196 100644 --- a/neutron/plugins/ml2/db.py +++ b/neutron/plugins/ml2/db.py @@ -14,6 +14,7 @@ # under the License. from neutron_lib import constants as n_const +from neutron_lib.plugins import directory from oslo_db import exception as db_exc from oslo_log import log from oslo_utils import uuidutils @@ -28,7 +29,6 @@ from neutron.callbacks import resources from neutron.db.models import securitygroup as sg_models from neutron.db import models_v2 from neutron.extensions import portbindings -from neutron import manager from neutron.plugins.ml2 import models from neutron.services.segments import exceptions as seg_exc @@ -215,7 +215,7 @@ def get_sg_ids_grouped_by_port(context, port_ids): def make_port_dict_with_security_groups(port, sec_groups): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() port_dict = plugin._make_port_dict(port) port_dict['security_groups'] = sec_groups port_dict['security_group_rules'] = [] diff --git a/neutron/plugins/ml2/drivers/l2pop/mech_driver.py b/neutron/plugins/ml2/drivers/l2pop/mech_driver.py index cce40a4fe7a..b547019df8c 100644 --- a/neutron/plugins/ml2/drivers/l2pop/mech_driver.py +++ b/neutron/plugins/ml2/drivers/l2pop/mech_driver.py @@ -15,6 +15,7 @@ from neutron_lib import constants as const from neutron_lib import exceptions +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_log import log as logging @@ -22,8 +23,6 @@ from neutron._i18n import _, _LW from neutron import context as n_context from neutron.db import api as db_api from neutron.db import l3_hamode_db -from neutron import manager -from neutron.plugins.common import constants as service_constants from neutron.plugins.ml2 import driver_api as api from neutron.plugins.ml2.drivers.l2pop import config # noqa from neutron.plugins.ml2.drivers.l2pop import db as l2pop_db @@ -238,8 +237,7 @@ class L2populationMechanismDriver(api.MechanismDriver): def update_port_down(self, context): port = context.current agent_host = context.host - l3plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + l3plugin = directory.get_plugin(const.L3) # when agent transitions to backup, don't remove flood flows if agent_host and l3plugin and getattr( l3plugin, "list_router_ids_on_host", None): diff --git a/neutron/plugins/ml2/extensions/dns_integration.py b/neutron/plugins/ml2/extensions/dns_integration.py index 476cdcda3e0..71e29d4b465 100644 --- a/neutron/plugins/ml2/extensions/dns_integration.py +++ b/neutron/plugins/ml2/extensions/dns_integration.py @@ -14,6 +14,7 @@ # under the License. from neutron_lib.api import validators +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_log import log as logging @@ -24,7 +25,6 @@ from neutron.callbacks import resources from neutron.db import models_v2 from neutron.db import segments_db from neutron.extensions import dns -from neutron import manager from neutron.objects import network as net_obj from neutron.objects import ports as port_obj from neutron.plugins.common import utils as plugin_utils @@ -264,7 +264,7 @@ class DNSExtensionDriver(api.ExtensionDriver): dns_data_db) def _get_network(self, context, network_id): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() return plugin.get_network(context, network_id) diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index d0eb6a914b2..f636923c05c 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -17,6 +17,7 @@ from eventlet import greenthread from neutron_lib.api import validators from neutron_lib import constants as const from neutron_lib import exceptions as exc +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_db import exception as os_db_exception from oslo_log import helpers as log_helpers @@ -71,8 +72,6 @@ from neutron.extensions import portbindings from neutron.extensions import portsecurity as psec from neutron.extensions import providernet as provider from neutron.extensions import vlantransparent -from neutron import manager -from neutron.plugins.common import constants as service_constants from neutron.plugins.ml2.common import exceptions as ml2_exc from neutron.plugins.ml2 import config # noqa from neutron.plugins.ml2 import db @@ -1591,8 +1590,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, self._pre_delete_port(context, id, l3_port_check) # TODO(armax): get rid of the l3 dependency in the with block router_ids = [] - l3plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + l3plugin = directory.get_plugin(const.L3) session = context.session with session.begin(subtransactions=True): diff --git a/neutron/plugins/ml2/rpc.py b/neutron/plugins/ml2/rpc.py index 8d1bf82b61c..81a7994f7df 100644 --- a/neutron/plugins/ml2/rpc.py +++ b/neutron/plugins/ml2/rpc.py @@ -15,6 +15,7 @@ from neutron_lib import constants as n_const from neutron_lib import exceptions +from neutron_lib.plugins import directory from oslo_log import log import oslo_messaging from sqlalchemy.orm import exc @@ -29,7 +30,6 @@ from neutron.db import l3_hamode_db from neutron.db import provisioning_blocks from neutron.extensions import portbindings from neutron.extensions import portsecurity as psec -from neutron import manager from neutron.plugins.ml2 import db as ml2_db from neutron.plugins.ml2 import driver_api as api from neutron.plugins.ml2.drivers import type_tunnel @@ -70,7 +70,7 @@ class RpcCallbacks(type_tunnel.TunnelRpcCallbackMixin): "%(agent_id)s with host %(host)s", {'device': device, 'agent_id': agent_id, 'host': host}) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() port_id = plugin._device_to_port_id(rpc_context, device) port_context = plugin.get_bound_port_context(rpc_context, port_id, @@ -175,7 +175,7 @@ class RpcCallbacks(type_tunnel.TunnelRpcCallbackMixin): LOG.debug("Device %(device)s no longer exists at agent " "%(agent_id)s", {'device': device, 'agent_id': agent_id}) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() port_id = plugin._device_to_port_id(rpc_context, device) port_exists = True if (host and not plugin.port_bound_to_host(rpc_context, @@ -206,7 +206,7 @@ class RpcCallbacks(type_tunnel.TunnelRpcCallbackMixin): host = kwargs.get('host') LOG.debug("Device %(device)s up at agent %(agent_id)s", {'device': device, 'agent_id': agent_id}) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() port_id = plugin._device_to_port_id(rpc_context, device) port = plugin.port_bound_to_host(rpc_context, port_id, host) if host and not port: @@ -232,7 +232,7 @@ class RpcCallbacks(type_tunnel.TunnelRpcCallbackMixin): n_const.PORT_STATUS_ACTIVE, host, port=port) def update_port_status_to_active(self, port, rpc_context, port_id, host): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() if port and port['device_owner'] == n_const.DEVICE_OWNER_DVR_INTERFACE: # NOTE(kevinbenton): we have to special case DVR ports because of # the special multi-binding status update logic they have that @@ -254,7 +254,7 @@ class RpcCallbacks(type_tunnel.TunnelRpcCallbackMixin): def notify_ha_port_status(self, port_id, rpc_context, status, host, port=None): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() l2pop_driver = plugin.mechanism_manager.mech_drivers.get( 'l2population') if not l2pop_driver: diff --git a/neutron/policy.py b/neutron/policy.py index 19541a99218..276563760ad 100644 --- a/neutron/policy.py +++ b/neutron/policy.py @@ -18,6 +18,7 @@ import re from neutron_lib import constants from neutron_lib import exceptions +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_db import exception as db_exc from oslo_log import log as logging @@ -251,11 +252,7 @@ class OwnerCheck(policy.Check): # resource is handled by the core plugin. It might be worth # having a way to map resources to plugins so to make this # check more general - # NOTE(ihrachys): if import is put in global, circular - # import failure occurs - manager = importutils.import_module('neutron.manager') - f = getattr(manager.NeutronManager.get_instance().plugin, - 'get_%s' % parent_res) + f = getattr(directory.get_plugin(), 'get_%s' % parent_res) # f *must* exist, if not found it is better to let neutron # explode. Check will be performed with admin context context = importutils.import_module('neutron.context') diff --git a/neutron/service.py b/neutron/service.py index 27bca9dfddb..bf9d10b966b 100644 --- a/neutron/service.py +++ b/neutron/service.py @@ -17,6 +17,7 @@ import inspect import os import random +from neutron_lib.plugins import directory from oslo_concurrency import processutils from oslo_config import cfg from oslo_log import log as logging @@ -36,7 +37,6 @@ from neutron.common import rpc as n_rpc from neutron.conf import service from neutron import context from neutron.db import api as session -from neutron import manager from neutron import worker as neutron_worker from neutron import wsgi @@ -150,9 +150,8 @@ class RpcReportsWorker(RpcWorker): def _get_rpc_workers(): - plugin = manager.NeutronManager.get_plugin() - service_plugins = ( - manager.NeutronManager.get_service_plugins().values()) + plugin = directory.get_plugin() + service_plugins = directory.get_plugins().values() if cfg.CONF.rpc_workers < 1: cfg.CONF.set_override('rpc_workers', 1) @@ -185,8 +184,8 @@ def _get_rpc_workers(): def _get_plugins_workers(): - # NOTE(twilson) get_service_plugins also returns the core plugin - plugins = manager.NeutronManager.get_unique_service_plugins() + # NOTE(twilson) get_plugins also returns the core plugin + plugins = directory.get_unique_plugins() # TODO(twilson) Instead of defaulting here, come up with a good way to # share a common get_workers default between NeutronPluginBaseV2 and diff --git a/neutron/services/auto_allocate/db.py b/neutron/services/auto_allocate/db.py index 9cab246a9a4..a2407432de1 100644 --- a/neutron/services/auto_allocate/db.py +++ b/neutron/services/auto_allocate/db.py @@ -14,7 +14,9 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from oslo_db import exception as db_exc from oslo_log import log as logging from sqlalchemy import sql @@ -33,8 +35,6 @@ from neutron.db.models import external_net as ext_net_models from neutron.db import models_v2 from neutron.db import standard_attr from neutron.extensions import l3 -from neutron import manager -from neutron.plugins.common import constants from neutron.plugins.common import utils as p_utils from neutron.services.auto_allocate import exceptions from neutron.services.auto_allocate import models @@ -101,14 +101,13 @@ class AutoAllocatedTopologyMixin(common_db_mixin.CommonDbMixin): @property def core_plugin(self): if not getattr(self, '_core_plugin', None): - self._core_plugin = manager.NeutronManager.get_plugin() + self._core_plugin = directory.get_plugin() return self._core_plugin @property def l3_plugin(self): if not getattr(self, '_l3_plugin', None): - self._l3_plugin = manager.NeutronManager.get_service_plugins().get( - constants.L3_ROUTER_NAT) + self._l3_plugin = directory.get_plugin(constants.L3) return self._l3_plugin def get_auto_allocated_topology(self, context, tenant_id, fields=None): diff --git a/neutron/services/l3_router/README b/neutron/services/l3_router/README index f6ca35bed85..220255bf595 100644 --- a/neutron/services/l3_router/README +++ b/neutron/services/l3_router/README @@ -10,12 +10,11 @@ The required changes to a core plugin are in that case: anymore. - Remove "router" from 'supported_extension_aliases'. - Modify any 'self' references to members in L3_NAT_db_mixin to instead use - 'manager.NeutronManager.get_service_plugins().get(constants.L3_ROUTER_NAT)' + 'directory.get_plugin(constants.L3)' For example, self.prevent_l3_port_deletion(...) becomes something like - plugin = manager.NeutronManager.get_service_plugins().get( - constants.L3_ROUTER_NAT) + plugin = directory.get_plugin(constants.L3) if plugin: plugin.prevent_l3_port_deletion(...) diff --git a/neutron/services/l3_router/service_providers/driver_controller.py b/neutron/services/l3_router/service_providers/driver_controller.py index 637a591af43..83e0828205f 100644 --- a/neutron/services/l3_router/service_providers/driver_controller.py +++ b/neutron/services/l3_router/service_providers/driver_controller.py @@ -14,6 +14,7 @@ from neutron_lib import constants as lib_const from neutron_lib import exceptions as lib_exc +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_log import log as logging @@ -22,7 +23,6 @@ from neutron.callbacks import events from neutron.callbacks import registry from neutron.callbacks import resources from neutron.db import servicetype_db as st_db -from neutron import manager from neutron.plugins.common import constants from neutron.services import provider_configuration from neutron.services import service_base @@ -64,8 +64,7 @@ class DriverController(object): @property def _flavor_plugin(self): if not hasattr(self, '_flavor_plugin_ref'): - _service_plugins = manager.NeutronManager.get_service_plugins() - self._flavor_plugin_ref = _service_plugins[constants.FLAVORS] + self._flavor_plugin_ref = directory.get_plugin(constants.FLAVORS) return self._flavor_plugin_ref def _set_router_provider(self, resource, event, trigger, context, router, diff --git a/neutron/services/segments/db.py b/neutron/services/segments/db.py index 2cfec2c57a9..8cc4ee595f7 100644 --- a/neutron/services/segments/db.py +++ b/neutron/services/segments/db.py @@ -19,6 +19,7 @@ import functools from neutron_lib import constants from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from oslo_db import exception as db_exc from oslo_log import helpers as log_helpers from oslo_utils import uuidutils @@ -286,7 +287,7 @@ def _add_segment_host_mapping_for_segment(resource, event, trigger, if not segment.physical_network: return - cp = manager.NeutronManager.get_plugin() + cp = directory.get_plugin() check_segment_for_agent = getattr(cp, 'check_segment_for_agent', None) if not hasattr(cp, 'get_agents') or not check_segment_for_agent: # not an agent-supporting plugin diff --git a/neutron/services/segments/plugin.py b/neutron/services/segments/plugin.py index c2ff2224bc4..d9146cc236d 100644 --- a/neutron/services/segments/plugin.py +++ b/neutron/services/segments/plugin.py @@ -14,6 +14,8 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.plugins import directory + from neutron._i18n import _ from neutron.api.v2 import attributes from neutron.callbacks import events @@ -24,13 +26,12 @@ from neutron.db import models_v2 from neutron.extensions import ip_allocation from neutron.extensions import l2_adjacency from neutron.extensions import segment -from neutron import manager from neutron.services.segments import db from neutron.services.segments import exceptions def _extend_network_dict_binding(plugin, network_res, network_db): - if not manager.NeutronManager.get_service_plugins().get('segments'): + if not directory.get_plugin('segments'): return # TODO(carl_baldwin) Make this work with service subnets when it's a thing. @@ -44,7 +45,7 @@ def _extend_subnet_dict_binding(plugin, subnet_res, subnet_db): def _extend_port_dict_binding(plugin, port_res, port_db): - if not manager.NeutronManager.get_service_plugins().get('segments'): + if not directory.get_plugin('segments'): return value = ip_allocation.IP_ALLOCATION_IMMEDIATE diff --git a/neutron/services/trunk/rpc/server.py b/neutron/services/trunk/rpc/server.py index 8fd143fd221..3c8c2953953 100644 --- a/neutron/services/trunk/rpc/server.py +++ b/neutron/services/trunk/rpc/server.py @@ -14,6 +14,7 @@ import collections +from neutron_lib.plugins import directory from oslo_log import helpers as log_helpers from oslo_log import log as logging import oslo_messaging @@ -26,7 +27,6 @@ from neutron.api.rpc.handlers import resources_rpc from neutron.common import rpc as n_rpc from neutron.db import api as db_api from neutron.extensions import portbindings -from neutron import manager from neutron.objects import trunk as trunk_objects from neutron.services.trunk import constants as trunk_consts from neutron.services.trunk import exceptions as trunk_exc @@ -76,7 +76,7 @@ class TrunkSkeleton(object): @property def core_plugin(self): if not self._core_plugin: - self._core_plugin = manager.NeutronManager.get_plugin() + self._core_plugin = directory.get_plugin() return self._core_plugin @log_helpers.log_method_call diff --git a/neutron/services/trunk/rules.py b/neutron/services/trunk/rules.py index d6f48b1b264..afa105e58d8 100644 --- a/neutron/services/trunk/rules.py +++ b/neutron/services/trunk/rules.py @@ -15,11 +15,11 @@ from neutron_lib.api import converters from neutron_lib.api import validators from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from neutron._i18n import _ from neutron.common import utils as n_utils from neutron.extensions import portbindings -from neutron import manager from neutron.objects import trunk as trunk_objects from neutron.plugins.ml2 import driver_api as api from neutron.services.trunk import exceptions as trunk_exc @@ -102,7 +102,7 @@ class TrunkPortValidator(object): def is_bound(self, context): """Return true if the port is bound, false otherwise.""" # Validate that the given port_id does not have a port binding. - core_plugin = manager.NeutronManager.get_plugin() + core_plugin = directory.get_plugin() self._port = core_plugin.get_port(context, self.port_id) return bool(self._port.get(portbindings.HOST_ID)) @@ -112,7 +112,7 @@ class TrunkPortValidator(object): # An unbound port can be trunked, always. return True - trunk_plugin = manager.NeutronManager.get_service_plugins()['trunk'] + trunk_plugin = directory.get_plugin('trunk') vif_type = self._port.get(portbindings.VIF_TYPE) binding_host = self._port.get(portbindings.HOST_ID) @@ -135,7 +135,7 @@ class TrunkPortValidator(object): def check_not_in_use(self, context): """Raises PortInUse for ports assigned for device purposes.""" - core_plugin = manager.NeutronManager.get_plugin() + core_plugin = directory.get_plugin() self._port = core_plugin.get_port(context, self.port_id) # NOTE(armax): the trunk extension itself does not make use of the # device_id field, because it has no reason to. If need be, this @@ -175,7 +175,7 @@ class SubPortsValidator(object): If the network or port cannot be obtained, or if MTU is not defined, returns None. """ - core_plugin = manager.NeutronManager.get_plugin() + core_plugin = directory.get_plugin() if not n_utils.is_extension_supported(core_plugin, 'net-mtu'): return diff --git a/neutron/services/trunk/utils.py b/neutron/services/trunk/utils.py index 4f9f680606d..bcd69b0eafa 100644 --- a/neutron/services/trunk/utils.py +++ b/neutron/services/trunk/utils.py @@ -12,14 +12,15 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.plugins import directory + from neutron.common import utils -from neutron import manager def get_agent_types_by_host(context, host): """Return the agent types registered on the host.""" agent_types = [] - core_plugin = manager.NeutronManager.get_plugin() + core_plugin = directory.get_plugin() if utils.is_extension_supported(core_plugin, 'agent'): agents = core_plugin.get_agents( context.elevated(), filters={'host': [host]}) diff --git a/neutron/tests/base.py b/neutron/tests/base.py index d47e4e63f73..3f1d6b8eff5 100644 --- a/neutron/tests/base.py +++ b/neutron/tests/base.py @@ -30,6 +30,7 @@ from debtcollector import moves import eventlet.timeout import fixtures import mock +from neutron_lib.plugins import directory from oslo_concurrency.fixture import lockutils from oslo_config import cfg from oslo_messaging import conffixture as messaging_conffixture @@ -302,6 +303,7 @@ class BaseTestCase(DietTestCase): self.setup_rpc_mocks() self.setup_config() self.setup_test_registry_instance() + self.setup_test_directory_instance() policy.init() self.addCleanup(policy.reset) @@ -371,6 +373,14 @@ class BaseTestCase(DietTestCase): mock.patch.object(registry, '_get_callback_manager', return_value=self._callback_manager).start() + def setup_test_directory_instance(self): + """Give a private copy of the directory to each test.""" + # TODO(armax): switch to using a fixture to stop relying on stubbing + # out _get_plugin_directory directly. + self._plugin_directory = directory._PluginDirectory() + mock.patch.object(directory, '_get_plugin_directory', + return_value=self._plugin_directory).start() + def setup_config(self, args=None): """Tests that need a non-default config can override this method.""" self.config_parse(args=args) @@ -391,11 +401,13 @@ class BaseTestCase(DietTestCase): for k, v in six.iteritems(kw): CONF.set_override(k, v, group) - def setup_coreplugin(self, core_plugin=None): + def setup_coreplugin(self, core_plugin=None, load_plugins=True): cp = PluginFixture(core_plugin) self.useFixture(cp) self.patched_dhcp_periodic = cp.patched_dhcp_periodic self.patched_default_svc_plugins = cp.patched_default_svc_plugins + if load_plugins: + manager.init() def setup_notification_driver(self, notification_driver=None): self.addCleanup(fake_notifier.reset) diff --git a/neutron/tests/functional/pecan_wsgi/test_controllers.py b/neutron/tests/functional/pecan_wsgi/test_controllers.py index 302bc143c82..1e3160f8fd8 100644 --- a/neutron/tests/functional/pecan_wsgi/test_controllers.py +++ b/neutron/tests/functional/pecan_wsgi/test_controllers.py @@ -14,6 +14,7 @@ import uuid import mock from neutron_lib import constants as n_const +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_db import exception as db_exc from oslo_policy import policy as oslo_policy @@ -26,7 +27,6 @@ from neutron import context from neutron import manager from neutron.pecan_wsgi.controllers import root as controllers from neutron.pecan_wsgi.controllers import utils as controller_utils -from neutron.plugins.common import constants from neutron import policy from neutron.tests.common import helpers from neutron.tests.functional.pecan_wsgi import test_functional @@ -56,7 +56,7 @@ class TestRootController(test_functional.PecanFunctionalTest): def setUp(self): super(TestRootController, self).setUp() self.setup_service_plugin() - self.plugin = manager.NeutronManager.get_plugin() + self.plugin = directory.get_plugin() self.ctx = context.get_admin_context() def setup_service_plugin(self): @@ -438,7 +438,7 @@ class TestPaginationAndSorting(test_functional.PecanFunctionalTest): cfg.CONF.set_override('allow_pagination', True) cfg.CONF.set_override('allow_sorting', True) super(TestPaginationAndSorting, self).setUp() - self.plugin = manager.NeutronManager.get_plugin() + self.plugin = directory.get_plugin() self.ctx = context.get_admin_context() self._create_networks(self.RESOURCE_COUNT) self.networks = self._get_collection()['networks'] @@ -658,7 +658,7 @@ class TestRequestProcessing(TestRootController): self.assertEqual('router', self.req_stash['resource_type']) # make sure the core plugin was identified as the handler for ports self.assertEqual( - manager.NeutronManager.get_service_plugins()['L3_ROUTER_NAT'], + directory.get_plugin(n_const.L3), self.req_stash['plugin']) def test_service_plugin_uri(self): @@ -684,10 +684,9 @@ class TestRouterController(TestResourceController): ['neutron.services.l3_router.l3_router_plugin.L3RouterPlugin', 'neutron.services.flavors.flavors_plugin.FlavorsPlugin']) super(TestRouterController, self).setUp() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() ctx = context.get_admin_context() - service_plugins = manager.NeutronManager.get_service_plugins() - l3_plugin = service_plugins[constants.L3_ROUTER_NAT] + l3_plugin = directory.get_plugin(n_const.L3) network_id = pecan_utils.create_network(ctx, plugin)['id'] self.subnet = pecan_utils.create_subnet(ctx, plugin, network_id) self.router = pecan_utils.create_router(ctx, l3_plugin) @@ -734,7 +733,7 @@ class TestDHCPAgentShimControllers(test_functional.PecanFunctionalTest): 'create_dhcp-networks': 'role:admin', 'delete_dhcp-networks': 'role:admin'}), overwrite=False) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() ctx = context.get_admin_context() self.network = pecan_utils.create_network(ctx, plugin) self.agent = helpers.register_dhcp_agent() @@ -788,8 +787,7 @@ class TestL3AgentShimControllers(test_functional.PecanFunctionalTest): 'get_l3-routers': 'role:admin'}), overwrite=False) ctx = context.get_admin_context() - service_plugins = manager.NeutronManager.get_service_plugins() - l3_plugin = service_plugins[constants.L3_ROUTER_NAT] + l3_plugin = directory.get_plugin(n_const.L3) self.router = pecan_utils.create_router(ctx, l3_plugin) self.agent = helpers.register_l3_agent() # NOTE(blogan): Not sending notifications because this test is for diff --git a/neutron/tests/functional/pecan_wsgi/test_functional.py b/neutron/tests/functional/pecan_wsgi/test_functional.py index 13ca6f0c82b..d2f85df410f 100644 --- a/neutron/tests/functional/pecan_wsgi/test_functional.py +++ b/neutron/tests/functional/pecan_wsgi/test_functional.py @@ -24,17 +24,19 @@ from pecan.testing import load_test_app import testtools from neutron.api import extensions as exts +from neutron import manager from neutron.tests.unit import testlib_api class PecanFunctionalTest(testlib_api.SqlTestCase): def setUp(self, service_plugins=None, extensions=None): - self.setup_coreplugin('ml2') + self.setup_coreplugin('ml2', load_plugins=False) super(PecanFunctionalTest, self).setUp() self.addCleanup(exts.PluginAwareExtensionManager.clear_instance) self.addCleanup(set_config, {}, overwrite=True) self.set_config_overrides() + manager.init() ext_mgr = exts.PluginAwareExtensionManager.get_instance() if extensions: ext_mgr.extensions = extensions diff --git a/neutron/tests/functional/pecan_wsgi/test_hooks.py b/neutron/tests/functional/pecan_wsgi/test_hooks.py index b26c637af1b..0eda686f31b 100644 --- a/neutron/tests/functional/pecan_wsgi/test_hooks.py +++ b/neutron/tests/functional/pecan_wsgi/test_hooks.py @@ -14,6 +14,7 @@ # under the License. import mock +from neutron_lib.plugins import directory from oslo_policy import policy as oslo_policy from oslo_serialization import jsonutils @@ -283,7 +284,7 @@ class TestMetricsNotifierHook(test_functional.PecanFunctionalTest): def test_bad_create_doesnt_emit_end(self): req_headers = {'X-Project-Id': 'tenid', 'X-Roles': 'admin'} payload = {'network': {'name': 'meh'}} - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with mock.patch.object(plugin, 'create_network', side_effect=ValueError): response = self.app.post_json( @@ -305,7 +306,7 @@ class TestMetricsNotifierHook(test_functional.PecanFunctionalTest): self.assertEqual(201, response.status_int) json_body = jsonutils.loads(response.body) self.mock_notifier.reset_mock() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with mock.patch.object(plugin, 'update_network', side_effect=ValueError): response = self.app.put_json( @@ -327,7 +328,7 @@ class TestMetricsNotifierHook(test_functional.PecanFunctionalTest): self.assertEqual(201, response.status_int) json_body = jsonutils.loads(response.body) self.mock_notifier.reset_mock() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with mock.patch.object(plugin, 'delete_network', side_effect=ValueError): response = self.app.delete( diff --git a/neutron/tests/functional/test_server.py b/neutron/tests/functional/test_server.py index aa4a5e00614..04234283f47 100644 --- a/neutron/tests/functional/test_server.py +++ b/neutron/tests/functional/test_server.py @@ -25,6 +25,7 @@ from oslo_config import cfg import psutil from neutron.common import utils +from neutron import manager from neutron import service from neutron.tests import base from neutron import worker as neutron_worker @@ -223,7 +224,7 @@ class TestRPCServer(TestNeutronServer): def setUp(self): super(TestRPCServer, self).setUp() - self.setup_coreplugin('ml2') + self.setup_coreplugin('ml2', load_plugins=False) self._plugin_patcher = mock.patch(TARGET_PLUGIN, autospec=True) self.plugin = self._plugin_patcher.start() self.plugin.return_value.rpc_workers_supported = True @@ -235,7 +236,7 @@ class TestRPCServer(TestNeutronServer): # receiving SIGHUP. with mock.patch("neutron.service.RpcWorker.start") as start_method: with mock.patch( - "neutron.manager.NeutronManager.get_plugin" + "neutron_lib.plugins.directory.get_plugin" ) as get_plugin: start_method.side_effect = self._fake_start get_plugin.return_value = self.plugin @@ -257,12 +258,13 @@ class TestPluginWorker(TestNeutronServer): def setUp(self): super(TestPluginWorker, self).setUp() - self.setup_coreplugin('ml2') + self.setup_coreplugin('ml2', load_plugins=False) self._plugin_patcher = mock.patch(TARGET_PLUGIN, autospec=True) self.plugin = self._plugin_patcher.start() + manager.init() def _start_plugin(self, workers=1): - with mock.patch('neutron.manager.NeutronManager.get_plugin') as gp: + with mock.patch('neutron_lib.plugins.directory.get_plugin') as gp: gp.return_value = self.plugin plugin_workers_launcher = service.start_plugins_workers() plugin_workers_launcher.wait() diff --git a/neutron/tests/retargetable/client_fixtures.py b/neutron/tests/retargetable/client_fixtures.py index e59bfdb6d94..86be75334ff 100644 --- a/neutron/tests/retargetable/client_fixtures.py +++ b/neutron/tests/retargetable/client_fixtures.py @@ -19,6 +19,7 @@ import abc import fixtures from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory import six from neutron import context @@ -76,6 +77,7 @@ class PluginClientFixture(AbstractClientFixture): self.useFixture(testlib_api.StaticSqlFixture()) self.useFixture(self.plugin_conf) self.useFixture(base.PluginFixture(self.plugin_conf.plugin_name)) + manager.init() @property def ctx(self): @@ -85,7 +87,7 @@ class PluginClientFixture(AbstractClientFixture): @property def plugin(self): - return manager.NeutronManager.get_plugin() + return directory.get_plugin() @property def NotFound(self): diff --git a/neutron/tests/unit/_test_extension_portbindings.py b/neutron/tests/unit/_test_extension_portbindings.py index d78b5eede21..f56b005b6c5 100644 --- a/neutron/tests/unit/_test_extension_portbindings.py +++ b/neutron/tests/unit/_test_extension_portbindings.py @@ -13,13 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.plugins import directory from oslo_config import cfg from six.moves import http_client as httplib from webob import exc from neutron import context from neutron.extensions import portbindings -from neutron import manager from neutron.tests.unit.db import test_db_base_plugin_v2 @@ -75,7 +75,7 @@ class PortBindingsTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): self._check_response_no_portbindings(non_admin_port) def test_ports_vif_details(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() cfg.CONF.set_default('allow_overlapping_ips', True) with self.port(), self.port(): ctx = context.get_admin_context() diff --git a/neutron/tests/unit/agent/test_securitygroups_rpc.py b/neutron/tests/unit/agent/test_securitygroups_rpc.py index 228f64bee0b..c039eb88d78 100644 --- a/neutron/tests/unit/agent/test_securitygroups_rpc.py +++ b/neutron/tests/unit/agent/test_securitygroups_rpc.py @@ -18,6 +18,7 @@ import contextlib import mock from neutron_lib import constants as const +from neutron_lib.plugins import directory from oslo_config import cfg import oslo_messaging from oslo_utils import netutils @@ -33,7 +34,6 @@ from neutron import context from neutron.db import securitygroups_rpc_base as sg_db_rpc from neutron.extensions import allowedaddresspairs as addr_pair from neutron.extensions import securitygroup as ext_sg -from neutron import manager from neutron.tests import base from neutron.tests import tools from neutron.tests.unit.extensions import test_securitygroup as test_sg @@ -123,7 +123,7 @@ class SGServerRpcCallBackTestCase(test_sg.SecurityGroupDBTestCase): plugin = plugin or TEST_PLUGIN_CLASS set_firewall_driver(FIREWALL_NOOP_DRIVER) super(SGServerRpcCallBackTestCase, self).setUp(plugin) - self.notifier = manager.NeutronManager.get_plugin().notifier + self.notifier = directory.get_plugin().notifier self.rpc = securitygroups_rpc.SecurityGroupServerRpcCallback() def _test_security_group_port(self, device_owner, gw_ip, @@ -284,7 +284,7 @@ class SGServerRpcCallBackTestCase(test_sg.SecurityGroupDBTestCase): @contextlib.contextmanager def _port_with_addr_pairs_and_security_group(self): - plugin_obj = manager.NeutronManager.get_plugin() + plugin_obj = directory.get_plugin() if ('allowed-address-pairs' not in plugin_obj.supported_extension_aliases): self.skipTest("Test depends on allowed-address-pairs extension") diff --git a/neutron/tests/unit/api/rpc/agentnotifiers/test_dhcp_rpc_agent_api.py b/neutron/tests/unit/api/rpc/agentnotifiers/test_dhcp_rpc_agent_api.py index 1f29b03269c..ed3feb2aeaf 100644 --- a/neutron/tests/unit/api/rpc/agentnotifiers/test_dhcp_rpc_agent_api.py +++ b/neutron/tests/unit/api/rpc/agentnotifiers/test_dhcp_rpc_agent_api.py @@ -16,6 +16,7 @@ import datetime import mock +from neutron_lib.plugins import directory from oslo_utils import timeutils from neutron.api.rpc.agentnotifiers import dhcp_rpc_agent_api @@ -184,11 +185,10 @@ class TestDhcpAgentNotifyAPI(base.BaseTestCase): self.notifier.plugin.get_network.return_value = {'id': network_id} segment_sp = mock.Mock() segment_sp.get_segment.return_value = segment - with mock.patch('neutron.manager.NeutronManager.get_service_plugins', - return_value={'segments': segment_sp}): - self._test__notify_agents('subnet_create_end', - expected_scheduling=1, expected_casts=1, - payload=subnet) + directory.add_plugin('segments', segment_sp) + self._test__notify_agents('subnet_create_end', + expected_scheduling=1, expected_casts=1, + payload=subnet) get_agents = self.notifier.plugin.get_dhcp_agents_hosting_networks get_agents.assert_called_once_with( mock.ANY, [network_id], hosts=segment['hosts']) diff --git a/neutron/tests/unit/api/rpc/callbacks/test_version_manager.py b/neutron/tests/unit/api/rpc/callbacks/test_version_manager.py index 9e9bf0e63c3..63eb3da72df 100644 --- a/neutron/tests/unit/api/rpc/callbacks/test_version_manager.py +++ b/neutron/tests/unit/api/rpc/callbacks/test_version_manager.py @@ -110,7 +110,7 @@ class CachedResourceConsumerTrackerTest(base.BaseTestCase): tracker.set_versions(CONSUMER_1, {TEST_RESOURCE_TYPE: TEST_VERSION_A}) - self.get_plugin = mock.patch('neutron.manager.NeutronManager' + self.get_plugin = mock.patch('neutron_lib.plugins.directory' '.get_plugin').start() self.get_plugin.return_value = _FakePlugin() diff --git a/neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py b/neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py index c8f28e84550..fc9955710ee 100644 --- a/neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py +++ b/neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py @@ -16,6 +16,7 @@ import mock from neutron_lib import constants from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from oslo_db import exception as db_exc from neutron.api.rpc.handlers import dhcp_rpc @@ -32,10 +33,8 @@ class TestDhcpRpcCallback(base.BaseTestCase): def setUp(self): super(TestDhcpRpcCallback, self).setUp() - self.plugin_p = mock.patch('neutron.manager.NeutronManager.get_plugin') - get_plugin = self.plugin_p.start() self.plugin = mock.MagicMock() - get_plugin.return_value = self.plugin + directory.add_plugin(constants.CORE, self.plugin) self.callbacks = dhcp_rpc.DhcpRpcCallback() self.log_p = mock.patch('neutron.api.rpc.handlers.dhcp_rpc.LOG') self.log = self.log_p.start() @@ -44,10 +43,8 @@ class TestDhcpRpcCallback(base.BaseTestCase): self.mock_set_dirty = set_dirty_p.start() self.utils_p = mock.patch('neutron.plugins.common.utils.create_port') self.utils = self.utils_p.start() - self.segment_p = mock.patch( - 'neutron.manager.NeutronManager.get_service_plugins') - self.get_service_plugins = self.segment_p.start() self.segment_plugin = mock.MagicMock() + directory.add_plugin('segments', self.segment_plugin) def test_group_by_network_id(self): port1 = {'network_id': 'a'} @@ -72,9 +69,6 @@ class TestDhcpRpcCallback(base.BaseTestCase): self.assertEqual(expected, networks) def test_get_active_networks_info_with_routed_networks(self): - self.get_service_plugins.return_value = { - 'segments': self.segment_plugin - } plugin_retval = [{'id': 'a'}, {'id': 'b'}] port = {'network_id': 'a'} subnets = [{'network_id': 'b', 'id': 'c', 'segment_id': '1'}, @@ -213,22 +207,13 @@ class TestDhcpRpcCallback(base.BaseTestCase): self._test_get_network_info() def test_get_network_info_with_routed_network(self): - self.get_service_plugins.return_value = { - 'segments': self.segment_plugin - } self._test_get_network_info(segmented_network=True, routed_network=True) def test_get_network_info_with_segmented_network_but_not_routed(self): - self.get_service_plugins.return_value = { - 'segments': self.segment_plugin - } self._test_get_network_info(segmented_network=True) def test_get_network_info_with_non_segmented_network(self): - self.get_service_plugins.return_value = { - 'segments': self.segment_plugin - } self._test_get_network_info() def test_update_dhcp_port_verify_port_action_port_dict(self): diff --git a/neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py b/neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py index 6adb2af16bb..bbc54fe5a3f 100644 --- a/neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py +++ b/neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py @@ -14,11 +14,11 @@ # limitations under the License. from neutron_lib import constants +from neutron_lib.plugins import directory from oslo_config import cfg from neutron.api.rpc.handlers import l3_rpc from neutron import context -from neutron import manager from neutron.tests.unit.db import test_db_base_plugin_v2 from neutron.tests.unit import testlib_api @@ -28,7 +28,7 @@ class TestL3RpcCallback(testlib_api.SqlTestCase): def setUp(self): super(TestL3RpcCallback, self).setUp() self.setup_coreplugin(test_db_base_plugin_v2.DB_PLUGIN_KLASS) - self.plugin = manager.NeutronManager.get_plugin() + self.plugin = directory.get_plugin() self.ctx = context.get_admin_context() cfg.CONF.set_override('ipv6_pd_enabled', True) self.callbacks = l3_rpc.L3RpcCallback() diff --git a/neutron/tests/unit/api/test_extensions.py b/neutron/tests/unit/api/test_extensions.py index 4aafac138f5..8ceb225a0b9 100644 --- a/neutron/tests/unit/api/test_extensions.py +++ b/neutron/tests/unit/api/test_extensions.py @@ -18,6 +18,7 @@ import copy import fixtures import mock +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_log import log as logging from oslo_serialization import jsonutils @@ -34,7 +35,6 @@ from neutron.api import extensions from neutron.api.v2 import attributes from neutron.common import config from neutron.common import exceptions -from neutron import manager from neutron.plugins.common import constants from neutron import quota from neutron.tests import base @@ -1004,7 +1004,7 @@ class ExtensionExtendedAttributeTestCase(base.BaseTestCase): # the global attribute map attributes.RESOURCE_ATTRIBUTE_MAP.update( extattr.EXTENDED_ATTRIBUTES_2_0) - self.agentscheduler_dbMinxin = manager.NeutronManager.get_plugin() + self.agentscheduler_dbMinxin = directory.get_plugin() self.addCleanup(self.restore_attribute_map) quota.QUOTAS._driver = None diff --git a/neutron/tests/unit/api/v2/test_base.py b/neutron/tests/unit/api/v2/test_base.py index ebf75e8c3b0..7cece7caf44 100644 --- a/neutron/tests/unit/api/v2/test_base.py +++ b/neutron/tests/unit/api/v2/test_base.py @@ -19,6 +19,7 @@ import mock from neutron_lib.api import converters from neutron_lib import constants from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_db import exception as db_exc from oslo_policy import policy as oslo_policy @@ -36,7 +37,6 @@ from neutron.api.v2 import base as v2_base from neutron.api.v2 import router from neutron.callbacks import registry from neutron import context -from neutron import manager from neutron import policy from neutron import quota from neutron.quota import resource_registry @@ -101,7 +101,7 @@ class APIv2TestBase(base.BaseTestCase): # Create the default configurations self.config_parse() # Update the plugin - self.setup_coreplugin(plugin) + self.setup_coreplugin(plugin, load_plugins=False) cfg.CONF.set_override('allow_pagination', True) cfg.CONF.set_override('allow_sorting', True) self._plugin_patcher = mock.patch(plugin, autospec=True) @@ -1160,7 +1160,7 @@ class SubresourceTest(base.BaseTestCase): self.useFixture(tools.AttributeMapMemento()) self.config_parse() - self.setup_coreplugin(plugin) + self.setup_coreplugin(plugin, load_plugins=False) self._plugin_patcher = mock.patch(plugin, autospec=True) self.plugin = self._plugin_patcher.start() @@ -1188,7 +1188,7 @@ class SubresourceTest(base.BaseTestCase): parent = SUB_RESOURCES['dummy'].get('parent') params = RESOURCE_ATTRIBUTE_MAP['dummies'] member_actions = {'mactions': 'GET'} - _plugin = manager.NeutronManager.get_plugin() + _plugin = directory.get_plugin() controller = v2_base.create_resource(collection_name, resource_name, _plugin, params, member_actions=member_actions, @@ -1492,15 +1492,14 @@ class ExtensionTestCase(base.BaseTestCase): self.config_parse() # Update the plugin and extensions path - self.setup_coreplugin(plugin) + self.setup_coreplugin(plugin, load_plugins=False) cfg.CONF.set_override('api_extensions_path', EXTDIR) self._plugin_patcher = mock.patch(plugin, autospec=True) self.plugin = self._plugin_patcher.start() # Instantiate mock plugin and enable the V2attributes extension - manager.NeutronManager.get_plugin().supported_extension_aliases = ( - ["v2attrs"]) + self.plugin.return_value.supported_extension_aliases = ["v2attrs"] api = router.APIRouter() self.api = webtest.TestApp(api) diff --git a/neutron/tests/unit/core_extensions/test_qos.py b/neutron/tests/unit/core_extensions/test_qos.py index 1070ba14fcb..00ebd8bec5b 100644 --- a/neutron/tests/unit/core_extensions/test_qos.py +++ b/neutron/tests/unit/core_extensions/test_qos.py @@ -48,7 +48,7 @@ class QosCoreResourceExtensionTestCase(base.BaseTestCase): plugins = {} if plugin_loaded: plugins[plugin_constants.QOS] = None - return mock.patch('neutron.manager.NeutronManager.get_service_plugins', + return mock.patch('neutron_lib.plugins.directory.get_plugins', return_value=plugins) def test_process_fields_no_qos_plugin_loaded(self): diff --git a/neutron/tests/unit/db/test_agentschedulers_db.py b/neutron/tests/unit/db/test_agentschedulers_db.py index da4b8e9fdd5..f09ee2eb116 100644 --- a/neutron/tests/unit/db/test_agentschedulers_db.py +++ b/neutron/tests/unit/db/test_agentschedulers_db.py @@ -17,6 +17,7 @@ import datetime import mock from neutron_lib import constants +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_db import exception as db_exc import oslo_messaging @@ -37,8 +38,6 @@ from neutron.db.models import l3agent as rb_model from neutron.extensions import agent from neutron.extensions import dhcpagentscheduler from neutron.extensions import l3agentscheduler -from neutron import manager -from neutron.plugins.common import constants as service_constants from neutron.tests.common import helpers from neutron.tests import fake_notifier from neutron.tests import tools @@ -257,8 +256,7 @@ class OvsAgentSchedulerTestCaseBase(test_l3.L3NatTestCaseMixin, # the global attribute map attributes.RESOURCE_ATTRIBUTE_MAP.update( agent.RESOURCE_ATTRIBUTE_MAP) - self.l3plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + self.l3plugin = directory.get_plugin(constants.L3) self.l3_notify_p = mock.patch( 'neutron.extensions.l3agentscheduler.notify') self.patched_l3_notify = self.l3_notify_p.start() @@ -531,7 +529,7 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): self.assertEqual(0, len(dhcp_agents['agents'])) def test_network_scheduler_with_hosted_network(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() helpers.register_dhcp_agent(DHCP_HOSTA) with self.port() as port1: dhcp_agents = self._list_dhcp_agents_hosting_network( @@ -619,7 +617,7 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): self.assertEqual(0, num_after_remove) def test_list_active_networks_on_not_registered_yet_dhcp_agent(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() nets = plugin.list_active_networks_on_active_dhcp_agent( self.adminContext, host=DHCP_HOSTA) self.assertEqual([], nets) @@ -674,9 +672,7 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): agt.heartbeat_timestamp - datetime.timedelta(hours=1)) self.adminContext.session.commit() - plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) - + plugin = directory.get_plugin(constants.L3) plugin.reschedule_routers_from_down_agents() def _set_agent_admin_state_up(self, host, state): @@ -693,8 +689,7 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): # schedule the router to host A l3_rpc_cb.get_router_ids(self.adminContext, host=L3_HOSTA) - plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + plugin = directory.get_plugin(constants.L3) mock.patch.object( plugin, 'reschedule_router', side_effect=[ @@ -715,14 +710,12 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): mock_ctx = mock.Mock() get_ctx.return_value = mock_ctx mock_ctx.session.query.side_effect = db_exc.DBError() - plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + plugin = directory.get_plugin(constants.L3) # check that no exception is raised plugin.reschedule_routers_from_down_agents() def test_router_rescheduler_iterates_after_reschedule_failure(self): - plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + plugin = directory.get_plugin(constants.L3) l3_rpc_cb = l3_rpc.L3RpcCallback() self._register_agent_states() with self.router() as r1, self.router() as r2: @@ -754,8 +747,7 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): self.assertFalse(rr.called) def test_router_is_not_rescheduled_if_agent_is_back_online(self): - plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + plugin = directory.get_plugin(constants.L3) l3_rpc_cb = l3_rpc.L3RpcCallback() agent = helpers.register_l3_agent(host=L3_HOSTA) with self.router(),\ @@ -1301,7 +1293,7 @@ class OvsDhcpAgentNotifierTestCase(test_agent.AgentDBTestMixIn, mock.patch.object( self.plugin, 'filter_hosts_with_network_access', side_effect=lambda context, network_id, hosts: hosts).start() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() self.dhcp_notifier = plugin.agent_notifiers[constants.AGENT_TYPE_DHCP] self.dhcp_notifier_cast = mock.patch( 'neutron.api.rpc.agentnotifiers.dhcp_rpc_agent_api.' @@ -1434,7 +1426,7 @@ class OvsDhcpAgentNotifierTestCase(test_agent.AgentDBTestMixIn, dhcp_notifier_schedule = mock.patch( 'neutron.api.rpc.agentnotifiers.dhcp_rpc_agent_api.' 'DhcpAgentNotifyAPI._schedule_network').start() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with self.subnet() as subnet,\ self.port(subnet=subnet, device_id=device_id),\ mock.patch.object(plugin, @@ -1490,8 +1482,7 @@ class OvsL3AgentNotifierTestCase(test_l3.L3NatTestCaseMixin, fake_notifier.reset() def test_router_add_to_l3_agent_notification(self): - l3_plugin = (manager.NeutronManager.get_service_plugins() - [service_constants.L3_ROUTER_NAT]) + l3_plugin = directory.get_plugin(constants.L3) l3_notifier = l3_plugin.agent_notifiers[constants.AGENT_TYPE_L3] with mock.patch.object( l3_notifier.client, @@ -1513,8 +1504,7 @@ class OvsL3AgentNotifierTestCase(test_l3.L3NatTestCaseMixin, self._assert_notify(notifications, expected_event_type) def test_router_remove_from_l3_agent_notification(self): - l3_plugin = (manager.NeutronManager.get_service_plugins() - [service_constants.L3_ROUTER_NAT]) + l3_plugin = directory.get_plugin(constants.L3) l3_notifier = l3_plugin.agent_notifiers[constants.AGENT_TYPE_L3] with mock.patch.object( l3_notifier.client, @@ -1539,8 +1529,7 @@ class OvsL3AgentNotifierTestCase(test_l3.L3NatTestCaseMixin, self._assert_notify(notifications, expected_event_type) def test_agent_updated_l3_agent_notification(self): - l3_plugin = (manager.NeutronManager.get_service_plugins() - [service_constants.L3_ROUTER_NAT]) + l3_plugin = directory.get_plugin(constants.L3) l3_notifier = l3_plugin.agent_notifiers[constants.AGENT_TYPE_L3] with mock.patch.object( l3_notifier.client, diff --git a/neutron/tests/unit/db/test_allowedaddresspairs_db.py b/neutron/tests/unit/db/test_allowedaddresspairs_db.py index 68fa18c6b13..045889207ac 100644 --- a/neutron/tests/unit/db/test_allowedaddresspairs_db.py +++ b/neutron/tests/unit/db/test_allowedaddresspairs_db.py @@ -14,6 +14,7 @@ # limitations under the License. from neutron_lib.api import validators +from neutron_lib.plugins import directory from oslo_config import cfg from webob import exc as web_exc @@ -23,7 +24,6 @@ from neutron.db import portsecurity_db from neutron.extensions import allowedaddresspairs as addr_pair from neutron.extensions import portsecurity as psec from neutron.extensions import securitygroup as secgroup -from neutron import manager from neutron.tests.unit.db import test_db_base_plugin_v2 @@ -37,7 +37,7 @@ class AllowedAddressPairTestCase( super(AllowedAddressPairTestCase, self).setUp(plugin) # Check if a plugin supports security groups - plugin_obj = manager.NeutronManager.get_plugin() + plugin_obj = directory.get_plugin() self._skip_port_security = ('port-security' not in plugin_obj.supported_extension_aliases) diff --git a/neutron/tests/unit/db/test_db_base_plugin_v2.py b/neutron/tests/unit/db/test_db_base_plugin_v2.py index a06b841a40b..5e164a3cf1b 100644 --- a/neutron/tests/unit/db/test_db_base_plugin_v2.py +++ b/neutron/tests/unit/db/test_db_base_plugin_v2.py @@ -23,6 +23,7 @@ import mock import netaddr from neutron_lib import constants from neutron_lib import exceptions as lib_exc +from neutron_lib.plugins import directory from neutron_lib.utils import helpers from oslo_concurrency import lockutils from oslo_config import cfg @@ -56,7 +57,6 @@ from neutron.db.models import securitygroup as sg_models from neutron.db import models_v2 from neutron.db import standard_attr from neutron.ipam import exceptions as ipam_exc -from neutron import manager from neutron.tests import base from neutron.tests import tools from neutron.tests.unit.api import test_extensions @@ -93,7 +93,7 @@ def _fake_get_sorting_helper(self, request): # instead of directly using NeutronDbPluginV2TestCase def _get_create_db_method(resource): ml2_method = '_create_%s_db' % resource - if hasattr(manager.NeutronManager.get_plugin(), ml2_method): + if hasattr(directory.get_plugin(), ml2_method): return ml2_method else: return 'create_%s' % resource @@ -120,7 +120,7 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase): plugin = DB_PLUGIN_KLASS # Update the plugin - self.setup_coreplugin(plugin) + self.setup_coreplugin(plugin, load_plugins=False) cfg.CONF.set_override( 'service_plugins', [test_lib.test_config.get(key, default) @@ -138,7 +138,7 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase): self.port_create_status = 'ACTIVE' def _is_native_bulk_supported(): - plugin_obj = manager.NeutronManager.get_plugin() + plugin_obj = directory.get_plugin() native_bulk_attr_name = ("_%s__native_bulk_support" % plugin_obj.__class__.__name__) return getattr(plugin_obj, native_bulk_attr_name, False) @@ -148,9 +148,9 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase): def _is_native_pagination_support(): native_pagination_attr_name = ( "_%s__native_pagination_support" % - manager.NeutronManager.get_plugin().__class__.__name__) + directory.get_plugin().__class__.__name__) return (cfg.CONF.allow_pagination and - getattr(manager.NeutronManager.get_plugin(), + getattr(directory.get_plugin(), native_pagination_attr_name, False)) self._skip_native_pagination = not _is_native_pagination_support() @@ -158,12 +158,12 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase): def _is_native_sorting_support(): native_sorting_attr_name = ( "_%s__native_sorting_support" % - manager.NeutronManager.get_plugin().__class__.__name__) + directory.get_plugin().__class__.__name__) return (cfg.CONF.allow_sorting and - getattr(manager.NeutronManager.get_plugin(), + getattr(directory.get_plugin(), native_sorting_attr_name, False)) - self.plugin = manager.NeutronManager.get_plugin() + self.plugin = directory.get_plugin() self._skip_native_sorting = not _is_native_sorting_support() if ext_mgr: self.ext_api = test_extensions.setup_extensions_middleware(ext_mgr) @@ -1083,7 +1083,7 @@ class TestPortsV2(NeutronDbPluginV2TestCase): tenid = p['port']['tenant_id'] ctx = context.Context(user_id=None, tenant_id=tenid, is_admin=False) - pl = manager.NeutronManager.get_plugin() + pl = directory.get_plugin() count = pl.get_ports_count(ctx, filters={'tenant_id': [tenid]}) self.assertEqual(4, count) @@ -1098,9 +1098,9 @@ class TestPortsV2(NeutronDbPluginV2TestCase): with mock.patch('six.moves.builtins.hasattr', new=fakehasattr): - orig = manager.NeutronManager.get_plugin().create_port + orig = directory.get_plugin().create_port method_to_patch = _get_create_db_method('port') - with mock.patch.object(manager.NeutronManager.get_plugin(), + with mock.patch.object(directory.get_plugin(), method_to_patch) as patched_plugin: def side_effect(*args, **kwargs): @@ -1123,7 +1123,7 @@ class TestPortsV2(NeutronDbPluginV2TestCase): self.skipTest("Plugin does not support native bulk port create") ctx = context.get_admin_context() with self.network() as net: - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() orig = plugin.create_port method_to_patch = _get_create_db_method('port') with mock.patch.object(plugin, method_to_patch) as patched_plugin: @@ -2443,7 +2443,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s res.status_int) def test_delete_ports_by_device_id(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() ctx = context.get_admin_context() with self.subnet() as subnet: with self.port(subnet=subnet, device_id='owner1') as p1,\ @@ -2486,7 +2486,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s expected_code=webob.exc.HTTPOk.code) def test_delete_ports_by_device_id_second_call_failure(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() self._test_delete_ports_by_device_id_second_call_failure(plugin) def _test_delete_ports_ignores_port_not_found(self, plugin): @@ -2509,7 +2509,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s "deleting some of the same ports.") def test_delete_ports_ignores_port_not_found(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() self._test_delete_ports_ignores_port_not_found(plugin) @@ -2597,7 +2597,7 @@ class TestNetworksV2(NeutronDbPluginV2TestCase): # must query db to see whether subnet's shared attribute # has been updated or not ctx = context.Context('', '', is_admin=True) - subnet_db = manager.NeutronManager.get_plugin().get_subnet( + subnet_db = directory.get_plugin().get_subnet( ctx, subnet['subnet']['id']) self.assertTrue(subnet_db['shared']) @@ -2774,12 +2774,12 @@ class TestNetworksV2(NeutronDbPluginV2TestCase): return False return real_has_attr(item, attr) - orig = manager.NeutronManager.get_plugin().create_network + orig = directory.get_plugin().create_network #ensures the API choose the emulation code path with mock.patch('six.moves.builtins.hasattr', new=fakehasattr): method_to_patch = _get_create_db_method('network') - with mock.patch.object(manager.NeutronManager.get_plugin(), + with mock.patch.object(directory.get_plugin(), method_to_patch) as patched_plugin: def side_effect(*args, **kwargs): @@ -2796,9 +2796,9 @@ class TestNetworksV2(NeutronDbPluginV2TestCase): def test_create_networks_bulk_native_plugin_failure(self): if self._skip_native_bulk: self.skipTest("Plugin does not support native bulk network create") - orig = manager.NeutronManager.get_plugin().create_network + orig = directory.get_plugin().create_network method_to_patch = _get_create_db_method('network') - with mock.patch.object(manager.NeutronManager.get_plugin(), + with mock.patch.object(directory.get_plugin(), method_to_patch) as patched_plugin: def side_effect(*args, **kwargs): @@ -3249,9 +3249,9 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): with mock.patch('six.moves.builtins.hasattr', new=fakehasattr): - orig = manager.NeutronManager.get_plugin().create_subnet + orig = directory.get_plugin().create_subnet method_to_patch = _get_create_db_method('subnet') - with mock.patch.object(manager.NeutronManager.get_plugin(), + with mock.patch.object(directory.get_plugin(), method_to_patch) as patched_plugin: def side_effect(*args, **kwargs): @@ -3272,7 +3272,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): def test_create_subnets_bulk_native_plugin_failure(self): if self._skip_native_bulk: self.skipTest("Plugin does not support native bulk subnet create") - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() orig = plugin.create_subnet method_to_patch = _get_create_db_method('subnet') with mock.patch.object(plugin, method_to_patch) as patched_plugin: @@ -4043,7 +4043,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): def _test_validate_subnet_ipv6_modes(self, cur_subnet=None, expect_success=True, **modes): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() ctx = context.get_admin_context() new_subnet = {'ip_version': 6, 'cidr': 'fe80::/64', @@ -4060,7 +4060,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): def _test_validate_subnet_ipv6_pd_modes(self, cur_subnet=None, expect_success=True, **modes): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() ctx = context.get_admin_context() new_subnet = {'ip_version': 6, 'cidr': n_const.PROVISIONAL_IPV6_PD_PREFIX, @@ -4252,7 +4252,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): '_get_subnet', return_value=v6_subnet).start() # Add an IPv6 auto-address subnet to the network - with mock.patch.object(manager.NeutronManager.get_plugin(), + with mock.patch.object(directory.get_plugin(), 'update_port') as mock_updated_port: v6_subnet = self._make_subnet(self.fmt, network, 'fe80::1', 'fe80::/64', ip_version=6, @@ -4945,7 +4945,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): 'ip_version': 4, 'enable_dhcp': True, 'tenant_id': network['network']['tenant_id']} - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() if hasattr(plugin, '_validate_subnet'): self.assertRaises(lib_exc.InvalidInput, plugin._validate_subnet, @@ -5274,7 +5274,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): 'dns_nameservers': ['8.8.8.8'], 'host_routes': [{'destination': '135.207.0.0/16', 'nexthop': '1.2.3.4'}]} - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() e = self.assertRaises(exception, plugin._validate_subnet, context.get_admin_context(), @@ -6355,7 +6355,7 @@ class NeutronDbPluginV2AsMixinTestCase(NeutronDbPluginV2TestCase, self.assertEqual(net['status'], 'BUILD') def test_get_user_allocation_for_dhcp_port_returns_none(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with self.network() as net, self.network() as net1: with self.subnet(network=net, cidr='10.0.0.0/24') as subnet,\ self.subnet(network=net1, cidr='10.0.1.0/24') as subnet1: @@ -6409,7 +6409,7 @@ class TestNetworks(testlib_api.SqlTestCase): def _test_update_shared_net_used(self, device_owner, expected_exception=None): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() ctx = context.get_admin_context() network, net_id = self._create_network(plugin, ctx) diff --git a/neutron/tests/unit/db/test_dvr_mac_db.py b/neutron/tests/unit/db/test_dvr_mac_db.py index 7171dd88a23..b9d16352c5a 100644 --- a/neutron/tests/unit/db/test_dvr_mac_db.py +++ b/neutron/tests/unit/db/test_dvr_mac_db.py @@ -15,6 +15,7 @@ import mock from neutron_lib import constants +from neutron_lib.plugins import directory from neutron.callbacks import events from neutron.callbacks import registry @@ -24,7 +25,6 @@ from neutron.db import dvr_mac_db from neutron.db.models import dvr as dvr_models from neutron.extensions import dvr from neutron.extensions import portbindings -from neutron import manager from neutron.tests.unit.plugins.ml2 import test_plugin @@ -77,7 +77,7 @@ class DvrDbMixinTestCase(test_plugin.Ml2PluginV2TestCase): self.ctx, "foo_host_2") def test_mac_not_cleared_on_agent_delete_event_with_remaining_agents(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() self._create_dvr_mac_entry('host_1', 'mac_1') self._create_dvr_mac_entry('host_2', 'mac_2') agent1 = {'host': 'host_1', 'id': 'a1'} @@ -91,7 +91,7 @@ class DvrDbMixinTestCase(test_plugin.Ml2PluginV2TestCase): self.assertFalse(notifier.dvr_mac_address_update.called) def test_mac_cleared_on_agent_delete_event(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() self._create_dvr_mac_entry('host_1', 'mac_1') self._create_dvr_mac_entry('host_2', 'mac_2') agent = {'host': 'host_1', 'id': 'a1'} diff --git a/neutron/tests/unit/db/test_l3_db.py b/neutron/tests/unit/db/test_l3_db.py index 00954c7731e..574575d792c 100644 --- a/neutron/tests/unit/db/test_l3_db.py +++ b/neutron/tests/unit/db/test_l3_db.py @@ -16,6 +16,7 @@ import mock from neutron_lib import constants as n_const from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory import testtools from neutron.callbacks import events @@ -24,7 +25,6 @@ from neutron.callbacks import resources from neutron.db import l3_db from neutron.db.models import l3 as l3_models from neutron.extensions import l3 -from neutron import manager from neutron.tests import base @@ -49,7 +49,7 @@ class TestL3_NAT_dbonly_mixin(base.BaseTestCase): def test__get_subnets_by_network_no_query(self): """Basic test that no query is performed if no Ports are passed""" context = mock.Mock() - with mock.patch.object(manager.NeutronManager, 'get_plugin') as get_p: + with mock.patch.object(directory, 'get_plugin') as get_p: self.db._get_subnets_by_network_list(context, []) self.assertFalse(context.session.query.called) self.assertFalse(get_p.called) @@ -61,7 +61,7 @@ class TestL3_NAT_dbonly_mixin(base.BaseTestCase): query.__iter__.return_value = [(mock.sentinel.subnet_db, mock.sentinel.address_scope_id)] - with mock.patch.object(manager.NeutronManager, 'get_plugin') as get_p: + with mock.patch.object(directory, 'get_plugin') as get_p: get_p()._make_subnet_dict.return_value = { 'network_id': mock.sentinel.network_id} subnets = self.db._get_subnets_by_network_list( @@ -74,7 +74,7 @@ class TestL3_NAT_dbonly_mixin(base.BaseTestCase): def test__populate_ports_for_subnets_none(self): """Basic test that the method runs correctly with no ports""" ports = [] - with mock.patch.object(manager.NeutronManager, 'get_plugin') as get_p: + with mock.patch.object(directory, 'get_plugin') as get_p: get_p().get_networks.return_value = [] self.db._populate_mtu_and_subnets_for_ports(mock.sentinel.context, ports) @@ -96,7 +96,7 @@ class TestL3_NAT_dbonly_mixin(base.BaseTestCase): ports = [{'network_id': 'net_id', 'id': 'port_id', 'fixed_ips': [{'subnet_id': mock.sentinel.subnet_id}]}] - with mock.patch.object(manager.NeutronManager, 'get_plugin') as get_p: + with mock.patch.object(directory, 'get_plugin') as get_p: get_p().get_networks.return_value = [{'id': 'net_id', 'mtu': 1446}] self.db._populate_mtu_and_subnets_for_ports(mock.sentinel.context, ports) @@ -147,19 +147,19 @@ class TestL3_NAT_dbonly_mixin(base.BaseTestCase): ({'id': 'id2'}, 'scope2'), ({'id': 'id3'}, 'scope3')], result) - @mock.patch.object(manager.NeutronManager, 'get_plugin') + @mock.patch.object(directory, 'get_plugin') def test_prevent_l3_port_deletion_port_not_found(self, gp): # port not found doesn't prevent gp.return_value.get_port.side_effect = n_exc.PortNotFound(port_id='1') self.db.prevent_l3_port_deletion(None, None) - @mock.patch.object(manager.NeutronManager, 'get_plugin') + @mock.patch.object(directory, 'get_plugin') def test_prevent_l3_port_device_owner_not_router(self, gp): # ignores other device owners gp.return_value.get_port.return_value = {'device_owner': 'cat'} self.db.prevent_l3_port_deletion(None, None) - @mock.patch.object(manager.NeutronManager, 'get_plugin') + @mock.patch.object(directory, 'get_plugin') def test_prevent_l3_port_no_fixed_ips(self, gp): # without fixed IPs is allowed gp.return_value.get_port.return_value = { @@ -168,7 +168,7 @@ class TestL3_NAT_dbonly_mixin(base.BaseTestCase): } self.db.prevent_l3_port_deletion(None, None) - @mock.patch.object(manager.NeutronManager, 'get_plugin') + @mock.patch.object(directory, 'get_plugin') def test_prevent_l3_port_no_router(self, gp): # without router is allowed gp.return_value.get_port.return_value = { @@ -179,7 +179,7 @@ class TestL3_NAT_dbonly_mixin(base.BaseTestCase): self.db.get_router.side_effect = l3.RouterNotFound(router_id='44') self.db.prevent_l3_port_deletion(mock.Mock(), None) - @mock.patch.object(manager.NeutronManager, 'get_plugin') + @mock.patch.object(directory, 'get_plugin') def test_prevent_l3_port_existing_router(self, gp): gp.return_value.get_port.return_value = { 'device_owner': n_const.DEVICE_OWNER_ROUTER_INTF, @@ -189,7 +189,7 @@ class TestL3_NAT_dbonly_mixin(base.BaseTestCase): with testtools.ExpectedException(n_exc.ServicePortInUse): self.db.prevent_l3_port_deletion(mock.Mock(), None) - @mock.patch.object(manager.NeutronManager, 'get_plugin') + @mock.patch.object(directory, 'get_plugin') def test_prevent_l3_port_existing_floating_ip(self, gp): gp.return_value.get_port.return_value = { 'device_owner': n_const.DEVICE_OWNER_FLOATINGIP, diff --git a/neutron/tests/unit/db/test_l3_dvr_db.py b/neutron/tests/unit/db/test_l3_dvr_db.py index 835541018df..677ae30cfce 100644 --- a/neutron/tests/unit/db/test_l3_dvr_db.py +++ b/neutron/tests/unit/db/test_l3_dvr_db.py @@ -14,8 +14,9 @@ # limitations under the License. import mock -from neutron_lib import constants as l3_const +from neutron_lib import constants as const from neutron_lib import exceptions +from neutron_lib.plugins import directory from oslo_utils import uuidutils import testtools @@ -29,8 +30,6 @@ from neutron.db import common_db_mixin from neutron.db import l3_agentschedulers_db from neutron.db import l3_dvr_db from neutron.extensions import portbindings -from neutron import manager -from neutron.plugins.common import constants as plugin_const from neutron.tests.unit.db import test_db_base_plugin_v2 _uuid = uuidutils.generate_uuid @@ -47,7 +46,7 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): def setUp(self): super(L3DvrTestCase, self).setUp(plugin='ml2') - self.core_plugin = manager.NeutronManager.get_plugin() + self.core_plugin = directory.get_plugin() self.ctx = context.get_admin_context() self.mixin = FakeL3Plugin() @@ -125,7 +124,7 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): self.mixin._update_distributed_attr.call_count) def _test_get_device_owner(self, is_distributed=False, - expected=l3_const.DEVICE_OWNER_ROUTER_INTF, + expected=const.DEVICE_OWNER_ROUTER_INTF, pass_router_id=True): router = { 'name': 'foo_router', @@ -148,7 +147,7 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): def test__get_device_owner_distributed(self): self._test_get_device_owner( is_distributed=True, - expected=l3_const.DEVICE_OWNER_DVR_INTERFACE, + expected=const.DEVICE_OWNER_DVR_INTERFACE, pass_router_id=False) def _test__is_distributed_router(self, router, expected): @@ -173,34 +172,32 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): self._test__is_distributed_router(router, True) def test__get_agent_gw_ports_exist_for_network(self): - with mock.patch.object(manager.NeutronManager, 'get_plugin') as gp: - plugin = mock.Mock() - gp.return_value = plugin - plugin.get_ports.return_value = [] - self.mixin._get_agent_gw_ports_exist_for_network( - self.ctx, 'network_id', 'host', 'agent_id') + plugin = mock.Mock() + directory.add_plugin(const.CORE, plugin) + plugin.get_ports.return_value = [] + self.mixin._get_agent_gw_ports_exist_for_network( + self.ctx, 'network_id', 'host', 'agent_id') plugin.get_ports.assert_called_with(self.ctx, { 'network_id': ['network_id'], 'device_id': ['agent_id'], - 'device_owner': [l3_const.DEVICE_OWNER_AGENT_GW]}) + 'device_owner': [const.DEVICE_OWNER_AGENT_GW]}) def _test_prepare_direct_delete_dvr_internal_ports(self, port): - with mock.patch.object(manager.NeutronManager, 'get_plugin') as gp: - plugin = mock.Mock() - gp.return_value = plugin - plugin.get_port.return_value = port - self.mixin._router_exists = mock.Mock(return_value=True) - self.assertRaises(exceptions.ServicePortInUse, - self.mixin.prevent_l3_port_deletion, - self.ctx, - port['id']) + plugin = mock.Mock() + directory.add_plugin(const.CORE, plugin) + plugin.get_port.return_value = port + self.mixin._router_exists = mock.Mock(return_value=True) + self.assertRaises(exceptions.ServicePortInUse, + self.mixin.prevent_l3_port_deletion, + self.ctx, + port['id']) def test_prevent_delete_floatingip_agent_gateway_port(self): port = { 'id': 'my_port_id', 'fixed_ips': mock.ANY, 'device_id': 'r_id', - 'device_owner': l3_const.DEVICE_OWNER_AGENT_GW + 'device_owner': const.DEVICE_OWNER_AGENT_GW } self._test_prepare_direct_delete_dvr_internal_ports(port) @@ -209,7 +206,7 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): 'id': 'my_port_id', 'fixed_ips': mock.ANY, 'device_id': 'r_id', - 'device_owner': l3_const.DEVICE_OWNER_ROUTER_SNAT + 'device_owner': const.DEVICE_OWNER_ROUTER_SNAT } self._test_prepare_direct_delete_dvr_internal_ports(port) @@ -248,7 +245,7 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): def test__port_has_ipv6_address_for_dvr_snat_port(self): port = { 'id': 'my_port_id', - 'device_owner': l3_const.DEVICE_OWNER_ROUTER_SNAT, + 'device_owner': const.DEVICE_OWNER_ROUTER_SNAT, } result, pv6 = self.setup_port_has_ipv6_address(port) self.assertFalse(result) @@ -257,7 +254,7 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): def test__port_has_ipv6_address_for_non_snat_ports(self): port = { 'id': 'my_port_id', - 'device_owner': l3_const.DEVICE_OWNER_DVR_INTERFACE, + 'device_owner': const.DEVICE_OWNER_DVR_INTERFACE, } result, pv6 = self.setup_port_has_ipv6_address(port) self.assertTrue(result) @@ -268,23 +265,22 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): 'id': 'my_port_id', portbindings.HOST_ID: 'foo_host', 'network_id': 'ext_network_id', - 'device_owner': l3_const.DEVICE_OWNER_ROUTER_GW + 'device_owner': const.DEVICE_OWNER_ROUTER_GW }, { 'id': 'my_new_port_id', portbindings.HOST_ID: 'my_foo_host', 'network_id': 'ext_network_id', - 'device_owner': l3_const.DEVICE_OWNER_ROUTER_GW + 'device_owner': const.DEVICE_OWNER_ROUTER_GW }] - with mock.patch.object(manager.NeutronManager, 'get_plugin') as gp: - plugin = mock.Mock() - gp.return_value = plugin - plugin.get_ports.return_value = ports - self.mixin.delete_floatingip_agent_gateway_port( - self.ctx, port_host, 'ext_network_id') + plugin = mock.Mock() + directory.add_plugin(const.CORE, plugin) + plugin.get_ports.return_value = ports + self.mixin.delete_floatingip_agent_gateway_port( + self.ctx, port_host, 'ext_network_id') plugin.get_ports.assert_called_with(self.ctx, filters={ 'network_id': ['ext_network_id'], - 'device_owner': [l3_const.DEVICE_OWNER_AGENT_GW]}) + 'device_owner': [const.DEVICE_OWNER_AGENT_GW]}) if port_host: plugin.ipam.delete_port.assert_called_once_with( self.ctx, 'my_port_id') @@ -307,15 +303,16 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): gw_port_db = { 'id': 'my_gw_id', 'network_id': 'ext_net_id', - 'device_owner': l3_const.DEVICE_OWNER_ROUTER_GW + 'device_owner': const.DEVICE_OWNER_ROUTER_GW } router.gw_port = gw_port_db else: router.gw_port = None - with mock.patch.object(manager.NeutronManager, 'get_plugin') as gp,\ - mock.patch.object(l3_dvr_db.l3_db.L3_NAT_db_mixin, - '_delete_current_gw_port'),\ + plugin = mock.Mock() + directory.add_plugin(const.CORE, plugin) + with mock.patch.object(l3_dvr_db.l3_db.L3_NAT_db_mixin, + '_delete_current_gw_port'),\ mock.patch.object( self.mixin, '_get_router') as grtr,\ @@ -328,8 +325,6 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): mock.patch.object( self.mixin.l3_rpc_notifier, 'delete_fipnamespace_for_ext_net') as del_fip: - plugin = mock.Mock() - gp.return_value = plugin plugin.get_ports.return_value = port grtr.return_value = router self.mixin._delete_current_gw_port( @@ -351,12 +346,12 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): port = [{ 'id': 'my_port_id', 'network_id': 'ext_net_id', - 'device_owner': l3_const.DEVICE_OWNER_ROUTER_GW + 'device_owner': const.DEVICE_OWNER_ROUTER_GW }, { 'id': 'my_new_port_id', 'network_id': 'ext_net_id', - 'device_owner': l3_const.DEVICE_OWNER_ROUTER_GW + 'device_owner': const.DEVICE_OWNER_ROUTER_GW }] rtr, plugin, d_csnat_port, d_agent_gw_port, del_fip = ( self._setup_delete_current_gw_port_deletes_fip_agent_gw_port( @@ -411,7 +406,7 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): def test_floatingip_on_port_not_host(self): router, fip = self._floatingip_on_port_test_setup(None) - self.assertNotIn(l3_const.FLOATINGIP_KEY, router) + self.assertNotIn(const.FLOATINGIP_KEY, router) self.assertNotIn(n_const.FLOATINGIP_AGENT_INTF_KEY, router) def test_floatingip_on_port_with_host(self): @@ -419,9 +414,9 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): self.assertTrue(self.mixin._get_fip_sync_interfaces.called) - self.assertIn(l3_const.FLOATINGIP_KEY, router) + self.assertIn(const.FLOATINGIP_KEY, router) self.assertIn(n_const.FLOATINGIP_AGENT_INTF_KEY, router) - self.assertIn(fip, router[l3_const.FLOATINGIP_KEY]) + self.assertIn(fip, router[const.FLOATINGIP_KEY]) self.assertIn('fip_interface', router[n_const.FLOATINGIP_AGENT_INTF_KEY]) @@ -509,24 +504,20 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): {'subnet_id': subnet2['subnet']['id']}) csnat_filters = {'device_owner': - [l3_const.DEVICE_OWNER_ROUTER_SNAT]} + [const.DEVICE_OWNER_ROUTER_SNAT]} csnat_ports = self.core_plugin.get_ports( self.ctx, filters=csnat_filters) self.assertEqual(2, len(csnat_ports)) dvr_filters = {'device_owner': - [l3_const.DEVICE_OWNER_DVR_INTERFACE]} + [const.DEVICE_OWNER_DVR_INTERFACE]} dvr_ports = self.core_plugin.get_ports( self.ctx, filters=dvr_filters) self.assertEqual(2, len(dvr_ports)) - with mock.patch.object(manager.NeutronManager, - 'get_service_plugins') as get_svc_plugin: - get_svc_plugin.return_value = { - plugin_const.L3_ROUTER_NAT: plugin} - self.mixin.manager = manager - self.mixin.remove_router_interface( - self.ctx, router['id'], {'port_id': dvr_ports[0]['id']}) + directory.add_plugin(const.L3, plugin) + self.mixin.remove_router_interface( + self.ctx, router['id'], {'port_id': dvr_ports[0]['id']}) csnat_ports = self.core_plugin.get_ports( self.ctx, filters=csnat_filters) @@ -561,11 +552,7 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): {'subnet_id': subnet_v4['subnet']['id']}) self.mixin.add_router_interface(self.ctx, router['id'], {'subnet_id': subnet_v6['subnet']['id']}) - get_svc_plugin = mock.patch.object( - manager.NeutronManager, 'get_service_plugins').start() - get_svc_plugin.return_value = { - plugin_const.L3_ROUTER_NAT: plugin} - self.mixin.manager = manager + directory.add_plugin(const.L3, plugin) return router, subnet_v4, subnet_v6 def test_undo_router_interface_change_on_csnat_error(self): @@ -610,12 +597,12 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): def test_remove_router_interface_csnat_ports_removal_with_ipv6(self): router, subnet_v4, subnet_v6 = self._setup_router_with_v4_and_v6() csnat_filters = {'device_owner': - [l3_const.DEVICE_OWNER_ROUTER_SNAT]} + [const.DEVICE_OWNER_ROUTER_SNAT]} csnat_ports = self.core_plugin.get_ports( self.ctx, filters=csnat_filters) self.assertEqual(2, len(csnat_ports)) dvr_filters = {'device_owner': - [l3_const.DEVICE_OWNER_DVR_INTERFACE]} + [const.DEVICE_OWNER_DVR_INTERFACE]} dvr_ports = self.core_plugin.get_ports( self.ctx, filters=dvr_filters) self.assertEqual(2, len(dvr_ports)) @@ -642,7 +629,7 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): self.ctx, router['id'], {'subnet_id': subnet_v4['subnet']['id']}) csnat_filters = {'device_owner': - [l3_const.DEVICE_OWNER_ROUTER_SNAT]} + [const.DEVICE_OWNER_ROUTER_SNAT]} csnat_ports = self.core_plugin.get_ports( self.ctx, filters=csnat_filters) self.core_plugin.update_port(self.ctx, csnat_ports[0]['id'], @@ -697,46 +684,45 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): router_dict = {'name': 'test_router', 'admin_state_up': True, 'distributed': True} router = self._create_router(router_dict) - with mock.patch.object(manager.NeutronManager, 'get_plugin') as gp: - plugin = mock.Mock() - l3_notify = self.mixin.l3_rpc_notifier = mock.Mock() - gp.return_value = plugin - port = { - 'id': 'my_port_id', - 'fixed_ips': [ - {'subnet_id': '51edc9e0-24f9-47f2-8e1e-2a41cb691323', - 'ip_address': '10.0.0.11'}, - {'subnet_id': '2b7c8a07-6f8e-4937-8701-f1d5da1a807c', - 'ip_address': '10.0.0.21'}, - {'subnet_id': '48534187-f077-4e81-93ff-81ec4cc0ad3b', - 'ip_address': 'fd45:1515:7e0:0:f816:3eff:fe1a:1111'}], - 'mac_address': 'my_mac', - 'device_owner': device_owner - } - dvr_port = { - 'id': 'dvr_port_id', - 'fixed_ips': mock.ANY, - 'device_owner': l3_const.DEVICE_OWNER_DVR_INTERFACE, - 'device_id': router['id'] - } - plugin.get_ports.return_value = [dvr_port] - if action == 'add': - self.mixin.update_arp_entry_for_dvr_service_port( - self.ctx, port) - self.assertEqual(3, l3_notify.add_arp_entry.call_count) - elif action == 'del': - self.mixin.delete_arp_entry_for_dvr_service_port( - self.ctx, port) - self.assertEqual(3, l3_notify.del_arp_entry.call_count) + plugin = mock.Mock() + directory.add_plugin(const.CORE, plugin) + l3_notify = self.mixin.l3_rpc_notifier = mock.Mock() + port = { + 'id': 'my_port_id', + 'fixed_ips': [ + {'subnet_id': '51edc9e0-24f9-47f2-8e1e-2a41cb691323', + 'ip_address': '10.0.0.11'}, + {'subnet_id': '2b7c8a07-6f8e-4937-8701-f1d5da1a807c', + 'ip_address': '10.0.0.21'}, + {'subnet_id': '48534187-f077-4e81-93ff-81ec4cc0ad3b', + 'ip_address': 'fd45:1515:7e0:0:f816:3eff:fe1a:1111'}], + 'mac_address': 'my_mac', + 'device_owner': device_owner + } + dvr_port = { + 'id': 'dvr_port_id', + 'fixed_ips': mock.ANY, + 'device_owner': const.DEVICE_OWNER_DVR_INTERFACE, + 'device_id': router['id'] + } + plugin.get_ports.return_value = [dvr_port] + if action == 'add': + self.mixin.update_arp_entry_for_dvr_service_port( + self.ctx, port) + self.assertEqual(3, l3_notify.add_arp_entry.call_count) + elif action == 'del': + self.mixin.delete_arp_entry_for_dvr_service_port( + self.ctx, port) + self.assertEqual(3, l3_notify.del_arp_entry.call_count) def test_update_arp_entry_for_dvr_service_port_added(self): action = 'add' - device_owner = l3_const.DEVICE_OWNER_LOADBALANCER + device_owner = const.DEVICE_OWNER_LOADBALANCER self._test_update_arp_entry_for_dvr_service_port(device_owner, action) def test_update_arp_entry_for_dvr_service_port_deleted(self): action = 'del' - device_owner = l3_const.DEVICE_OWNER_LOADBALANCER + device_owner = const.DEVICE_OWNER_LOADBALANCER self._test_update_arp_entry_for_dvr_service_port(device_owner, action) def test_add_router_interface_csnat_ports_failure(self): @@ -766,7 +752,7 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): } router_ports = self.core_plugin.get_ports(self.ctx, filters) self.assertEqual(1, len(router_ports)) - self.assertEqual(l3_const.DEVICE_OWNER_ROUTER_GW, + self.assertEqual(const.DEVICE_OWNER_ROUTER_GW, router_ports[0]['device_owner']) def test_add_router_interface_by_port_failure(self): diff --git a/neutron/tests/unit/db/test_l3_hamode_db.py b/neutron/tests/unit/db/test_l3_hamode_db.py index 834f38b086f..168cc57ef10 100644 --- a/neutron/tests/unit/db/test_l3_hamode_db.py +++ b/neutron/tests/unit/db/test_l3_hamode_db.py @@ -15,6 +15,7 @@ import mock from neutron_lib import constants from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_db import exception as db_exc from oslo_utils import uuidutils @@ -36,7 +37,6 @@ from neutron.extensions import l3 from neutron.extensions import l3_ext_ha_mode from neutron.extensions import portbindings from neutron.extensions import providernet -from neutron import manager from neutron.scheduler import l3_agent_scheduler from neutron.tests.common import helpers from neutron.tests.unit import testlib_api @@ -57,13 +57,14 @@ class L3HATestFramework(testlib_api.SqlTestCase): self.admin_ctx = context.get_admin_context() self.setup_coreplugin('ml2') - self.core_plugin = manager.NeutronManager.get_plugin() + self.core_plugin = directory.get_plugin() notif_p = mock.patch.object(l3_hamode_db.L3_HA_NAT_db_mixin, '_notify_ha_interfaces_updated') self.notif_m = notif_p.start() cfg.CONF.set_override('allow_overlapping_ips', True) self.plugin = FakeL3PluginWithAgents() + directory.add_plugin(constants.L3, self.plugin) self.plugin.router_scheduler = l3_agent_scheduler.ChanceScheduler() self.agent1 = helpers.register_l3_agent() self.agent2 = helpers.register_l3_agent( @@ -412,14 +413,10 @@ class L3HATestCase(L3HATestFramework): self.admin_ctx, [router['id']]) self.assertEqual(2, len(bound_agents)) - with mock.patch.object(manager.NeutronManager, - 'get_service_plugins') as mock_manager: - self.plugin._unbind_ha_router(self.admin_ctx, router['id']) - + self.plugin._unbind_ha_router(self.admin_ctx, router['id']) bound_agents = self.plugin.get_l3_agents_hosting_routers( self.admin_ctx, [router['id']]) self.assertEqual(0, len(bound_agents)) - self.assertEqual(2, mock_manager.call_count) def test_get_ha_sync_data_for_host_with_non_dvr_agent(self): with mock.patch.object(self.plugin, diff --git a/neutron/tests/unit/dummy_plugin.py b/neutron/tests/unit/dummy_plugin.py index 7ceb2060f18..e180cb84809 100644 --- a/neutron/tests/unit/dummy_plugin.py +++ b/neutron/tests/unit/dummy_plugin.py @@ -14,13 +14,13 @@ # under the License. from neutron_lib import exceptions +from neutron_lib.plugins import directory from oslo_utils import uuidutils from neutron.api import extensions from neutron.api.v2 import base from neutron.db import servicetype_db from neutron.extensions import servicetype -from neutron import manager from neutron.plugins.common import constants from neutron.services import service_base @@ -70,8 +70,7 @@ class Dummy(object): @classmethod def get_resources(cls): """Returns Extended Resource for dummy management.""" - n_mgr = manager.NeutronManager.get_instance() - dummy_inst = n_mgr.get_service_plugins()['DUMMY'] + dummy_inst = directory.get_plugin('DUMMY') controller = base.create_resource( COLLECTION_NAME, RESOURCE_NAME, dummy_inst, RESOURCE_ATTRIBUTE_MAP[COLLECTION_NAME]) diff --git a/neutron/tests/unit/extensions/base.py b/neutron/tests/unit/extensions/base.py index 31a7f36fc16..6fc1c5f7228 100644 --- a/neutron/tests/unit/extensions/base.py +++ b/neutron/tests/unit/extensions/base.py @@ -25,6 +25,7 @@ import webtest from neutron.api import extensions from neutron.api.v2 import attributes +from neutron import manager from neutron import quota from neutron.tests import tools from neutron.tests.unit.api import test_extensions @@ -55,8 +56,8 @@ class ExtensionTestCase(testlib_api.WebTestCase): # Create the default configurations self.config_parse() - #just stubbing core plugin with plugin - self.setup_coreplugin(plugin) + # just stubbing core plugin with plugin + self.setup_coreplugin(plugin, load_plugins=False) cfg.CONF.set_override('core_plugin', plugin) if service_type: cfg.CONF.set_override('service_plugins', [plugin]) @@ -66,6 +67,8 @@ class ExtensionTestCase(testlib_api.WebTestCase): instance = self.plugin.return_value if service_type: instance.get_plugin_type.return_value = service_type + manager.init() + if supported_extension_aliases is not None: instance.supported_extension_aliases = supported_extension_aliases if allow_pagination: diff --git a/neutron/tests/unit/extensions/extensionattribute.py b/neutron/tests/unit/extensions/extensionattribute.py index dcf2c8c2385..a17857fd003 100644 --- a/neutron/tests/unit/extensions/extensionattribute.py +++ b/neutron/tests/unit/extensions/extensionattribute.py @@ -15,9 +15,10 @@ import abc +from neutron_lib.plugins import directory + from neutron.api import extensions from neutron.api.v2 import base -from neutron import manager from neutron.quota import resource_registry @@ -64,7 +65,7 @@ class Extensionattribute(extensions.ExtensionDescriptor): def get_resources(cls): """Returns Ext Resources.""" exts = [] - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() resource_name = 'ext_test_resource' collection_name = resource_name + "s" params = RESOURCE_ATTRIBUTE_MAP.get(collection_name, dict()) diff --git a/neutron/tests/unit/extensions/test_dns.py b/neutron/tests/unit/extensions/test_dns.py index 3005dd41055..084a40b205e 100644 --- a/neutron/tests/unit/extensions/test_dns.py +++ b/neutron/tests/unit/extensions/test_dns.py @@ -16,13 +16,13 @@ import math import netaddr from neutron_lib import constants +from neutron_lib.plugins import directory from oslo_config import cfg from neutron.common import utils from neutron import context from neutron.db import db_base_plugin_v2 from neutron.extensions import dns -from neutron import manager from neutron.plugins.ml2 import config from neutron.tests.unit.db import test_db_base_plugin_v2 from neutron.tests.unit.plugins.ml2 import test_plugin @@ -125,7 +125,7 @@ class DnsExtensionTestCase(test_plugin.Ml2PluginV2TestCase): self.assertIn('mac_address', port['port']) ips = port['port']['fixed_ips'] self.assertEqual(1, len(ips)) - subnet_db = manager.NeutronManager.get_plugin().get_subnet( + subnet_db = directory.get_plugin().get_subnet( context.get_admin_context(), ips[0]['subnet_id']) self.assertIn(netaddr.IPAddress(ips[0]['ip_address']), netaddr.IPSet(netaddr.IPNetwork(subnet_db['cidr']))) diff --git a/neutron/tests/unit/extensions/test_external_net.py b/neutron/tests/unit/extensions/test_external_net.py index c54c5f0cc7e..aa8a49e9c90 100644 --- a/neutron/tests/unit/extensions/test_external_net.py +++ b/neutron/tests/unit/extensions/test_external_net.py @@ -15,6 +15,7 @@ import mock from neutron_lib import constants +from neutron_lib.plugins import directory from oslo_utils import uuidutils import testtools from webob import exc @@ -22,7 +23,6 @@ from webob import exc from neutron import context from neutron.db import models_v2 from neutron.extensions import external_net as external_net -from neutron import manager from neutron.tests.unit.api.v2 import test_base from neutron.tests.unit.db import test_db_base_plugin_v2 @@ -96,7 +96,7 @@ class ExtNetDBTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): query_params='router:external=False') def test_get_network_succeeds_without_filter(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() ctx = context.Context(None, None, is_admin=True) result = plugin.get_networks(ctx, filters=None) self.assertEqual([], result) @@ -126,19 +126,19 @@ class ExtNetDBTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): res = req.get_response(self.api) self.assertEqual(exc.HTTPOk.code, res.status_int) ctx = context.Context(None, None, is_admin=True) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() result = plugin.get_networks(ctx) self.assertFalse(result[0]['shared']) def test_network_filter_hook_admin_context(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() ctx = context.Context(None, None, is_admin=True) model = models_v2.Network conditions = plugin._network_filter_hook(ctx, model, []) self.assertEqual([], conditions) def test_network_filter_hook_nonadmin_context(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() ctx = context.Context('edinson', 'cavani') model = models_v2.Network txt = ("networkrbacs.action = :action_1 AND " @@ -184,13 +184,11 @@ class ExtNetDBTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): self.assertTrue(ext_net['network'][external_net.EXTERNAL]) def test_delete_network_check_disassociated_floatingips(self): - with mock.patch.object(manager.NeutronManager, - 'get_service_plugins') as srv_plugins: - l3_mock = mock.Mock() - srv_plugins.return_value = {'L3_ROUTER_NAT': l3_mock} - with self.network() as net: - req = self.new_delete_request('networks', net['network']['id']) - res = req.get_response(self.api) - self.assertEqual(exc.HTTPNoContent.code, res.status_int) - (l3_mock.delete_disassociated_floatingips - .assert_called_once_with(mock.ANY, net['network']['id'])) + l3_mock = mock.Mock() + directory.add_plugin('L3_ROUTER_NAT', l3_mock) + with self.network() as net: + req = self.new_delete_request('networks', net['network']['id']) + res = req.get_response(self.api) + self.assertEqual(exc.HTTPNoContent.code, res.status_int) + (l3_mock.delete_disassociated_floatingips + .assert_called_once_with(mock.ANY, net['network']['id'])) diff --git a/neutron/tests/unit/extensions/test_l3.py b/neutron/tests/unit/extensions/test_l3.py index 29f8c2474b4..eb6480fd1b0 100644 --- a/neutron/tests/unit/extensions/test_l3.py +++ b/neutron/tests/unit/extensions/test_l3.py @@ -21,6 +21,7 @@ import mock import netaddr from neutron_lib import constants as lib_constants from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_utils import importutils from oslo_utils import uuidutils @@ -49,7 +50,6 @@ from neutron.db import models_v2 from neutron.extensions import external_net from neutron.extensions import l3 from neutron.extensions import portbindings -from neutron import manager from neutron.plugins.common import constants as service_constants from neutron.tests import base from neutron.tests.common import helpers @@ -93,9 +93,9 @@ class L3NatExtensionTestCase(test_extensions_base.ExtensionTestCase): def setUp(self): super(L3NatExtensionTestCase, self).setUp() self._setUpExtension( - 'neutron.extensions.l3.RouterPluginBase', None, - l3.RESOURCE_ATTRIBUTE_MAP, l3.L3, '', - allow_pagination=True, allow_sorting=True, + 'neutron.services.l3_router.l3_router_plugin.L3RouterPlugin', + lib_constants.L3, l3.RESOURCE_ATTRIBUTE_MAP, + l3.L3, '', allow_pagination=True, allow_sorting=True, supported_extension_aliases=['router'], use_quota=True) @@ -257,8 +257,7 @@ class TestL3NatBasePlugin(db_base_plugin_v2.NeutronDbPluginV2, super(TestL3NatBasePlugin, self).delete_network(context, id) def delete_port(self, context, id, l3_port_check=True): - plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + plugin = directory.get_plugin(lib_constants.L3) if plugin: if l3_port_check: plugin.prevent_l3_port_deletion(context, id) @@ -1244,7 +1243,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): def test_router_add_interface_delete_port_after_failure(self): with self.router() as r, self.subnet(enable_dhcp=False) as s: - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() # inject a failure in the update port that happens at the end # to ensure the port gets deleted with mock.patch.object( @@ -2045,8 +2044,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): self.assertIsNotNone(body['floatingip']['router_id']) def test_create_floatingip_non_admin_context_agent_notification(self): - plugin = manager.NeutronManager.get_service_plugins()[ - service_constants.L3_ROUTER_NAT] + plugin = directory.get_plugin(lib_constants.L3) if not hasattr(plugin, 'l3_rpc_notifier'): self.skipTest("Plugin does not support l3_rpc_notifier") @@ -2848,8 +2846,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): def test_floatingip_via_router_interface_returns_201(self): # Override get_router_for_floatingip, as # networking-midonet's L3 service plugin would do. - plugin = manager.NeutronManager.get_service_plugins()[ - service_constants.L3_ROUTER_NAT] + plugin = directory.get_plugin(lib_constants.L3) with mock.patch.object(plugin, "get_router_for_floatingip", self._get_router_for_floatingip_without_device_owner_check): self._test_floatingip_via_router_interface(exc.HTTPCreated.code) @@ -2989,8 +2986,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): self.assertEqual(exc.HTTPConflict.code, res.status_int) def test_router_specify_id_backend(self): - plugin = manager.NeutronManager.get_service_plugins()[ - service_constants.L3_ROUTER_NAT] + plugin = directory.get_plugin(lib_constants.L3) router_req = {'router': {'id': _uuid(), 'name': 'router', 'tenant_id': 'foo', 'admin_state_up': True}} @@ -3045,8 +3041,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): def test_create_router_gateway_fails_nested(self): # Force _update_router_gw_info failure - plugin = manager.NeutronManager.get_service_plugins()[ - service_constants.L3_ROUTER_NAT] + plugin = directory.get_plugin(lib_constants.L3) if not isinstance(plugin, l3_db.L3_NAT_dbonly_mixin): self.skipTest("Plugin is not L3_NAT_dbonly_mixin") ctx = context.Context('', 'foo') @@ -3077,8 +3072,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): def test_create_router_gateway_fails_nested_delete_router_failed(self): # Force _update_router_gw_info failure - plugin = manager.NeutronManager.get_service_plugins()[ - service_constants.L3_ROUTER_NAT] + plugin = directory.get_plugin(lib_constants.L3) if not isinstance(plugin, l3_db.L3_NAT_dbonly_mixin): self.skipTest("Plugin is not L3_NAT_dbonly_mixin") ctx = context.Context('', 'foo') @@ -3115,8 +3109,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): def test_router_add_interface_by_port_fails_nested(self): # Force _validate_router_port_info failure - plugin = manager.NeutronManager.get_service_plugins()[ - service_constants.L3_ROUTER_NAT] + plugin = directory.get_plugin(lib_constants.L3) if not isinstance(plugin, l3_db.L3_NAT_dbonly_mixin): self.skipTest("Plugin is not L3_NAT_dbonly_mixin") orig_update_port = self.plugin.update_port @@ -3169,8 +3162,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): """Test to make sure notification to routers occurs when the gateway ip address of a subnet of the external network is changed. """ - plugin = manager.NeutronManager.get_service_plugins()[ - service_constants.L3_ROUTER_NAT] + plugin = directory.get_plugin(lib_constants.L3) if not hasattr(plugin, 'l3_rpc_notifier'): self.skipTest("Plugin does not support l3_rpc_notifier") # make sure the callback is registered. @@ -3201,8 +3193,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): ['fake_device'], None) def test__notify_subnetpool_address_scope_update(self): - plugin = manager.NeutronManager.get_service_plugins()[ - service_constants.L3_ROUTER_NAT] + plugin = directory.get_plugin(lib_constants.L3) tenant_id = _uuid() with mock.patch.object( @@ -3349,8 +3340,7 @@ class L3AgentDbTestCaseBase(L3NatTestCaseMixin): l3_rpc_agent_api_str = ( 'neutron.api.rpc.agentnotifiers.l3_rpc_agent_api.L3AgentNotifyAPI') with mock.patch(l3_rpc_agent_api_str): - plugin = manager.NeutronManager.get_service_plugins()[ - service_constants.L3_ROUTER_NAT] + plugin = directory.get_plugin(lib_constants.L3) notifyApi = plugin.l3_rpc_notifier kargs = [item for item in args] kargs.append(notifyApi) @@ -3518,8 +3508,7 @@ class L3NatDBIntAgentSchedulingTestCase(L3BaseForIntTests, self.adminContext = context.get_admin_context() def _assert_router_on_agent(self, router_id, agent_host): - plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + plugin = directory.get_plugin(lib_constants.L3) agents = plugin.list_l3_agents_hosting_router( self.adminContext, router_id)['agents'] self.assertEqual(1, len(agents)) @@ -3576,8 +3565,7 @@ class L3NatDBIntAgentSchedulingTestCase(L3BaseForIntTests, self._assert_router_on_agent(r['router']['id'], 'host2') def test_router_update_gateway_scheduling_not_supported(self): - plugin = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + plugin = directory.get_plugin(lib_constants.L3) mock.patch.object(plugin, 'router_supports_scheduling', return_value=False).start() with self.router() as r: @@ -3716,8 +3704,7 @@ class L3NatDBTestCaseMixin(object): def setUp(self): super(L3NatDBTestCaseMixin, self).setUp() - plugin = manager.NeutronManager.get_service_plugins()[ - service_constants.L3_ROUTER_NAT] + plugin = directory.get_plugin(lib_constants.L3) if not isinstance(plugin, l3_db.L3_NAT_dbonly_mixin): self.skipTest("Plugin is not L3_NAT_dbonly_mixin") @@ -3726,8 +3713,7 @@ class L3NatDBTestCaseMixin(object): the exception is propagated. """ - plugin = manager.NeutronManager.get_service_plugins()[ - service_constants.L3_ROUTER_NAT] + plugin = directory.get_plugin(lib_constants.L3) ctx = context.Context('', 'foo') class MyException(Exception): @@ -3760,8 +3746,7 @@ class L3NatDBSepTestCase(L3BaseForSepTests, L3NatTestCaseBase, """Unit tests for a separate L3 routing service plugin.""" def test_port_deletion_prevention_handles_missing_port(self): - pl = manager.NeutronManager.get_service_plugins().get( - service_constants.L3_ROUTER_NAT) + pl = directory.get_plugin(lib_constants.L3) self.assertIsNone( pl.prevent_l3_port_deletion(context.get_admin_context(), 'fakeid') ) diff --git a/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py b/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py index 740eced6f82..0aa8ead6ba3 100644 --- a/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py +++ b/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py @@ -17,6 +17,7 @@ import mock import netaddr from neutron_lib import constants +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_db import exception as db_exc from oslo_serialization import jsonutils @@ -34,7 +35,6 @@ from neutron.db.models import l3 as l3_models from neutron.db import models_v2 from neutron.extensions import l3 from neutron.extensions import l3_ext_gw_mode -from neutron import manager from neutron.objects import network as net_obj from neutron.objects import subnet as subnet_obj from neutron.tests import base @@ -400,7 +400,7 @@ class ExtGwModeIntTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase, with self.router() as r, self.subnet() as s: ext_net_id = s['subnet']['network_id'] self._set_net_external(ext_net_id) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with mock.patch.object(plugin, '_get_port', side_effect=ValueError()): self._set_router_external_gateway(r['router']['id'], diff --git a/neutron/tests/unit/extensions/test_portsecurity.py b/neutron/tests/unit/extensions/test_portsecurity.py index fac36ca073c..07821caab1e 100644 --- a/neutron/tests/unit/extensions/test_portsecurity.py +++ b/neutron/tests/unit/extensions/test_portsecurity.py @@ -14,6 +14,7 @@ # limitations under the License. from neutron_lib.api import validators +from neutron_lib.plugins import directory from webob import exc from neutron import context @@ -23,7 +24,6 @@ from neutron.db import portsecurity_db from neutron.db import securitygroups_db from neutron.extensions import portsecurity as psec from neutron.extensions import securitygroup as ext_sg -from neutron import manager from neutron.tests.unit.db import test_db_base_plugin_v2 from neutron.tests.unit.extensions import test_securitygroup @@ -41,7 +41,7 @@ class PortSecurityTestCase( super(PortSecurityTestCase, self).setUp(plugin=plugin, ext_mgr=ext_mgr) # Check if a plugin supports security groups - plugin_obj = manager.NeutronManager.get_plugin() + plugin_obj = directory.get_plugin() self._skip_security_group = ('security-group' not in plugin_obj.supported_extension_aliases) diff --git a/neutron/tests/unit/extensions/test_providernet.py b/neutron/tests/unit/extensions/test_providernet.py index fcd98a3056e..3804780d313 100644 --- a/neutron/tests/unit/extensions/test_providernet.py +++ b/neutron/tests/unit/extensions/test_providernet.py @@ -14,6 +14,8 @@ # under the License. import mock +from neutron_lib import constants +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_utils import uuidutils from webob import exc as web_exc @@ -23,7 +25,6 @@ from neutron.api import extensions from neutron.api.v2 import router from neutron import context from neutron.extensions import providernet as pnet -from neutron import manager from neutron import quota from neutron.tests import tools from neutron.tests.unit.api import test_extensions @@ -60,7 +61,7 @@ class ProvidernetExtensionTestCase(testlib_api.WebTestCase): self.useFixture(tools.AttributeMapMemento()) # Update the plugin and extensions path - self.setup_coreplugin(plugin) + self.setup_coreplugin(plugin, load_plugins=False) cfg.CONF.set_override('allow_pagination', True) cfg.CONF.set_override('allow_sorting', True) self._plugin_patcher = mock.patch(plugin, autospec=True) @@ -68,9 +69,9 @@ class ProvidernetExtensionTestCase(testlib_api.WebTestCase): # Ensure Quota checks never fail because of mock instance = self.plugin.return_value instance.get_networks_count.return_value = 1 - # Instantiate mock plugin and enable the 'provider' extension - manager.NeutronManager.get_plugin().supported_extension_aliases = ( - ["provider"]) + # Register mock plugin and enable the 'provider' extension + instance.supported_extension_aliases = ["provider"] + directory.add_plugin(constants.CORE, instance) ext_mgr = ProviderExtensionManager() self.ext_mdw = test_extensions.setup_extensions_middleware(ext_mgr) self.addCleanup(self._plugin_patcher.stop) diff --git a/neutron/tests/unit/extensions/test_securitygroup.py b/neutron/tests/unit/extensions/test_securitygroup.py index 3983cf5a02b..187c7d3bf06 100644 --- a/neutron/tests/unit/extensions/test_securitygroup.py +++ b/neutron/tests/unit/extensions/test_securitygroup.py @@ -18,6 +18,7 @@ import contextlib import mock from neutron_lib.api import validators from neutron_lib import constants as const +from neutron_lib.plugins import directory from oslo_config import cfg import oslo_db.exception as exc import six @@ -31,7 +32,6 @@ from neutron.db import db_base_plugin_v2 from neutron.db import securitygroups_db from neutron.extensions import securitygroup as ext_sg from neutron.extensions import standardattrdescription -from neutron import manager from neutron.tests import base from neutron.tests.unit.db import test_db_base_plugin_v2 @@ -589,7 +589,7 @@ class TestSecurityGroups(SecurityGroupDBTestCase): self.assertEqual(sg_rule[0][k], v) def test_get_security_group_on_port_from_wrong_tenant(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() if not hasattr(plugin, '_get_security_groups_on_port'): self.skipTest("plugin doesn't use the mixin with this method") neutron_context = context.get_admin_context() diff --git a/neutron/tests/unit/extensions/test_timestamp.py b/neutron/tests/unit/extensions/test_timestamp.py index f6153d32827..87a67471434 100644 --- a/neutron/tests/unit/extensions/test_timestamp.py +++ b/neutron/tests/unit/extensions/test_timestamp.py @@ -16,6 +16,7 @@ import datetime import six import mock +from neutron_lib.plugins import directory from oslo_utils import timeutils from neutron import context @@ -55,15 +56,15 @@ class TimeStampChangedsinceTestCase(test_db_base_plugin_v2. ext_mgr = TimeStampExtensionManager() super(TimeStampChangedsinceTestCase, self).setUp(plugin=self.plugin, ext_mgr=ext_mgr) - self.addCleanup(manager.NeutronManager. - get_service_plugins()['timestamp']. - unregister_db_events) + self.addCleanup( + directory.get_plugin('timestamp').unregister_db_events) self.addCleanup(manager.NeutronManager.clear_instance) - def setup_coreplugin(self, core_plugin=None): + def setup_coreplugin(self, core_plugin=None, load_plugins=True): super(TimeStampChangedsinceTestCase, self).setup_coreplugin( - self.plugin) + self.plugin, load_plugins=False) self.patched_default_svc_plugins.return_value = ['timestamp'] + manager.init() def _get_resp_with_changed_since(self, resource_type, changed_since): query_params = 'changed_since=%s' % changed_since @@ -227,7 +228,7 @@ class TimeStampChangedsinceTestCase(test_db_base_plugin_v2. def test_timestamp_fields_ignored_in_update(self): ctx = context.get_admin_context() with self.port() as port: - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() port = plugin.get_port(ctx, port['port']['id']) port['name'] = 'updated' port['created_at'] = '2011-04-06T14:34:23' diff --git a/neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_driver.py b/neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_driver.py index 4183f990dff..9d990c6b077 100644 --- a/neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_driver.py +++ b/neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_driver.py @@ -17,6 +17,7 @@ import mock import netaddr from neutron_lib import constants from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from neutron.common import constants as n_const from neutron import context @@ -24,7 +25,6 @@ from neutron.ipam.drivers.neutrondb_ipam import db_models from neutron.ipam.drivers.neutrondb_ipam import driver from neutron.ipam import exceptions as ipam_exc from neutron.ipam import requests as ipam_req -from neutron import manager from neutron.tests.unit.db import test_db_base_plugin_v2 as test_db_plugin from neutron.tests.unit import testlib_api @@ -73,7 +73,7 @@ class TestNeutronDbIpamPool(testlib_api.SqlTestCase, self.setup_coreplugin(test_db_plugin.DB_PLUGIN_KLASS) # Prepare environment for tests - self.plugin = manager.NeutronManager.get_plugin() + self.plugin = directory.get_plugin() self.ctx = context.get_admin_context() self.network, self.net_id = self._create_network(self.plugin, self.ctx) @@ -264,7 +264,7 @@ class TestNeutronDbIpamSubnet(testlib_api.SqlTestCase, self.setup_coreplugin(test_db_plugin.DB_PLUGIN_KLASS) # Prepare environment for tests - self.plugin = manager.NeutronManager.get_plugin() + self.plugin = directory.get_plugin() self.ctx = context.get_admin_context() self.network, self.net_id = self._create_network(self.plugin, self.ctx) diff --git a/neutron/tests/unit/ipam/test_subnet_alloc.py b/neutron/tests/unit/ipam/test_subnet_alloc.py index 689e87ee54a..4a666bdbd9f 100644 --- a/neutron/tests/unit/ipam/test_subnet_alloc.py +++ b/neutron/tests/unit/ipam/test_subnet_alloc.py @@ -16,6 +16,7 @@ import mock import netaddr from neutron_lib import constants +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_db import exception as db_exc from oslo_utils import uuidutils @@ -24,7 +25,6 @@ from neutron.common import exceptions as n_exc from neutron import context from neutron.ipam import requests as ipam_req from neutron.ipam import subnet_alloc -from neutron import manager from neutron.tests.unit.db import test_db_base_plugin_v2 from neutron.tests.unit import testlib_api @@ -35,7 +35,7 @@ class TestSubnetAllocation(testlib_api.SqlTestCase): super(TestSubnetAllocation, self).setUp() self._tenant_id = 'test-tenant' self.setup_coreplugin(test_db_base_plugin_v2.DB_PLUGIN_KLASS) - self.plugin = manager.NeutronManager.get_plugin() + self.plugin = directory.get_plugin() self.ctx = context.get_admin_context() cfg.CONF.set_override('allow_overlapping_ips', True) diff --git a/neutron/tests/unit/notifiers/test_nova.py b/neutron/tests/unit/notifiers/test_nova.py index 6bd0e03c718..c6599405b24 100644 --- a/neutron/tests/unit/notifiers/test_nova.py +++ b/neutron/tests/unit/notifiers/test_nova.py @@ -17,6 +17,7 @@ import mock from neutron_lib import constants as n_const from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from novaclient import exceptions as nova_exceptions from oslo_config import cfg from oslo_utils import uuidutils @@ -41,7 +42,7 @@ class TestNovaNotify(base.BaseTestCase): 'device_owner': DEVICE_OWNER_COMPUTE} self.nova_notifier = nova.Notifier() - self.nova_notifier._plugin_ref = FakePlugin() + directory.add_plugin(n_const.CORE, FakePlugin()) def test_notify_port_status_all_values(self): states = [n_const.PORT_STATUS_ACTIVE, n_const.PORT_STATUS_DOWN, @@ -180,7 +181,7 @@ class TestNovaNotify(base.BaseTestCase): def test_delete_floatingip_deleted_port_no_notify(self): port_id = 'bee50827-bcee-4cc8-91c1-a27b0ce54222' with mock.patch.object( - self.nova_notifier._plugin_ref, 'get_port', + directory.get_plugin(), 'get_port', side_effect=n_exc.PortNotFound(port_id=port_id)): returned_obj = {'floatingip': {'port_id': port_id}} diff --git a/neutron/tests/unit/objects/db/test_api.py b/neutron/tests/unit/objects/db/test_api.py index b77746ef95c..7d8cab8f7d8 100644 --- a/neutron/tests/unit/objects/db/test_api.py +++ b/neutron/tests/unit/objects/db/test_api.py @@ -12,10 +12,10 @@ import mock from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from neutron import context from neutron.db import models_v2 -from neutron import manager from neutron.objects import base from neutron.objects.db import api from neutron.tests import base as test_base @@ -40,7 +40,7 @@ class GetObjectsTestCase(test_base.BaseTestCase): limit = mock.sentinel.limit pager = base.Pager(marker=marker, limit=limit) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with mock.patch.object(plugin, '_get_collection') as get_collection: with mock.patch.object(api, 'get_object') as get_object: api.get_objects(ctxt, model, _pager=pager) diff --git a/neutron/tests/unit/objects/qos/test_rule_type.py b/neutron/tests/unit/objects/qos/test_rule_type.py index 67fc0ef3089..ef6d971492f 100644 --- a/neutron/tests/unit/objects/qos/test_rule_type.py +++ b/neutron/tests/unit/objects/qos/test_rule_type.py @@ -14,8 +14,8 @@ # class on the common base class for all objects import mock +from neutron_lib.plugins import directory -from neutron import manager from neutron.objects.qos import rule_type from neutron.services.qos import qos_consts from neutron.tests import base as test_base @@ -27,12 +27,12 @@ DB_PLUGIN_KLASS = 'neutron.db.db_base_plugin_v2.NeutronDbPluginV2' class QosRuleTypeObjectTestCase(test_base.BaseTestCase): def setUp(self): + super(QosRuleTypeObjectTestCase, self).setUp() self.config_parse() self.setup_coreplugin(DB_PLUGIN_KLASS) - super(QosRuleTypeObjectTestCase, self).setUp() def test_get_objects(self): - core_plugin = manager.NeutronManager.get_plugin() + core_plugin = directory.get_plugin() rule_types_mock = mock.PropertyMock( return_value=qos_consts.VALID_RULE_TYPES) with mock.patch.object(core_plugin, 'supported_qos_rule_types', diff --git a/neutron/tests/unit/plugins/ml2/base.py b/neutron/tests/unit/plugins/ml2/base.py index 6f10c658c89..ddb6e258ba9 100644 --- a/neutron/tests/unit/plugins/ml2/base.py +++ b/neutron/tests/unit/plugins/ml2/base.py @@ -12,8 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron import manager -from neutron.plugins.common import constants as plugin_constants +from neutron_lib import constants +from neutron_lib.plugins import directory + from neutron.tests.unit.plugins.ml2 import test_plugin @@ -30,9 +31,8 @@ class ML2TestFramework(test_plugin.Ml2PluginV2TestCase): def setUp(self): super(ML2TestFramework, self).setUp() - self.core_plugin = manager.NeutronManager.get_instance().get_plugin() - self.l3_plugin = manager.NeutronManager.get_service_plugins().get( - plugin_constants.L3_ROUTER_NAT) + self.core_plugin = directory.get_plugin() + self.l3_plugin = directory.get_plugin(constants.L3) def _create_router(self, distributed=False, ha=False): return self.l3_plugin.create_router( diff --git a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py index e3ec9ccc5df..29939f5fdfd 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py +++ b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py @@ -16,6 +16,7 @@ import mock from neutron_lib import constants from neutron_lib import exceptions +from neutron_lib.plugins import directory from oslo_serialization import jsonutils import testtools @@ -29,8 +30,6 @@ from neutron.db import l3_agentschedulers_db from neutron.db import l3_hamode_db from neutron.extensions import portbindings from neutron.extensions import providernet as pnet -from neutron import manager -from neutron.plugins.common import constants as service_constants from neutron.plugins.ml2 import driver_context from neutron.plugins.ml2.drivers.l2pop import db as l2pop_db from neutron.plugins.ml2.drivers.l2pop import mech_driver as l2pop_mech_driver @@ -224,7 +223,7 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase): def _bind_ha_network_ports(self, router_id): port_bindings = self.plugin.get_ha_router_port_bindings( self.adminContext, [router_id]) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() for port_binding in port_bindings: filters = {'id': [port_binding.port_id]} @@ -237,7 +236,7 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase): {attributes.PORT: port}) def _get_first_interface(self, net_id, router_id): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() device_filter = {'device_id': [router_id], 'device_owner': [constants.DEVICE_OWNER_HA_REPLICATED_INT]} @@ -277,11 +276,8 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase): # is added on HOST4. # HOST4 should get flood entries for HOST1 and HOST2 router = self._create_ha_router() - service_plugins = manager.NeutronManager.get_service_plugins() - service_plugins[service_constants.L3_ROUTER_NAT] = self.plugin - with self.subnet(network=self._network, enable_dhcp=False) as snet, \ - mock.patch('neutron.manager.NeutronManager.get_service_plugins', - return_value=service_plugins): + directory.add_plugin(constants.L3, self.plugin) + with self.subnet(network=self._network, enable_dhcp=False) as snet: subnet = snet['subnet'] port = self._add_router_interface(subnet, router, HOST) @@ -313,11 +309,8 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase): # Remove_fdb should carry flood entry of only HOST2 and not HOST router = self._create_ha_router() - service_plugins = manager.NeutronManager.get_service_plugins() - service_plugins[service_constants.L3_ROUTER_NAT] = self.plugin - with self.subnet(network=self._network, enable_dhcp=False) as snet, \ - mock.patch('neutron.manager.NeutronManager.get_service_plugins', - return_value=service_plugins): + directory.add_plugin(constants.L3, self.plugin) + with self.subnet(network=self._network, enable_dhcp=False) as snet: host_arg = {portbindings.HOST_ID: HOST, 'admin_state_up': True} with self.port(subnet=snet, device_owner=DEVICE_OWNER_COMPUTE, @@ -349,11 +342,8 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase): # Both HA agents should be notified to other agents. router = self._create_ha_router() - service_plugins = manager.NeutronManager.get_service_plugins() - service_plugins[service_constants.L3_ROUTER_NAT] = self.plugin - with self.subnet(network=self._network, enable_dhcp=False) as snet, \ - mock.patch('neutron.manager.NeutronManager.get_service_plugins', - return_value=service_plugins): + directory.add_plugin(constants.L3, self.plugin) + with self.subnet(network=self._network, enable_dhcp=False) as snet: host_arg = {portbindings.HOST_ID: HOST_4, 'admin_state_up': True} with self.port(subnet=snet, device_owner=DEVICE_OWNER_COMPUTE, @@ -1006,7 +996,7 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase): p1['status'] = 'ACTIVE' self.mock_fanout.reset_mock() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() plugin.update_port(self.adminContext, p1['id'], port1) self.assertFalse(self.mock_fanout.called) diff --git a/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py b/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py index 2dabcd8a5c3..cf279af8f58 100644 --- a/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py +++ b/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py @@ -18,12 +18,12 @@ import uuid import mock import netaddr from neutron_lib import constants +from neutron_lib.plugins import directory import testtools from neutron import context from neutron.extensions import dns from neutron.extensions import providernet as pnet -from neutron import manager from neutron.objects import ports as port_obj from neutron.plugins.ml2 import config from neutron.plugins.ml2.extensions import dns_integration @@ -57,7 +57,7 @@ class DNSIntegrationTestCase(test_plugin.Ml2PluginV2TestCase): super(DNSIntegrationTestCase, self).setUp() dns_integration.DNS_DRIVER = None dns_integration.subscribe() - self.plugin = manager.NeutronManager.get_plugin() + self.plugin = directory.get_plugin() config.cfg.CONF.set_override('dns_domain', self._domain) def _create_port_for_test(self, provider_net=True, dns_domain=True, diff --git a/neutron/tests/unit/plugins/ml2/test_ext_portsecurity.py b/neutron/tests/unit/plugins/ml2/test_ext_portsecurity.py index 94b7127094e..4d7f1d343a7 100644 --- a/neutron/tests/unit/plugins/ml2/test_ext_portsecurity.py +++ b/neutron/tests/unit/plugins/ml2/test_ext_portsecurity.py @@ -13,9 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.plugins import directory + from neutron import context from neutron.extensions import portsecurity as psec -from neutron import manager from neutron.plugins.ml2 import config from neutron.tests.unit.extensions import test_portsecurity as test_psec from neutron.tests.unit.plugins.ml2 import test_plugin @@ -32,7 +33,7 @@ class PSExtDriverTestCase(test_plugin.Ml2PluginV2TestCase, super(PSExtDriverTestCase, self).setUp() def test_create_net_port_security_default(self): - _core_plugin = manager.NeutronManager.get_plugin() + _core_plugin = directory.get_plugin() admin_ctx = context.get_admin_context() args = {'network': {'name': 'test', diff --git a/neutron/tests/unit/plugins/ml2/test_extension_driver_api.py b/neutron/tests/unit/plugins/ml2/test_extension_driver_api.py index a1e29dd9d92..f8b0cb0bf11 100644 --- a/neutron/tests/unit/plugins/ml2/test_extension_driver_api.py +++ b/neutron/tests/unit/plugins/ml2/test_extension_driver_api.py @@ -13,9 +13,9 @@ import uuid import mock +from neutron_lib.plugins import directory from neutron import context -from neutron import manager from neutron.plugins.ml2 import config from neutron.tests.unit.plugins.ml2.drivers import ext_test from neutron.tests.unit.plugins.ml2 import test_plugin @@ -30,7 +30,7 @@ class ExtensionDriverTestCase(test_plugin.Ml2PluginV2TestCase): self._extension_drivers, group='ml2') super(ExtensionDriverTestCase, self).setUp() - self._plugin = manager.NeutronManager.get_plugin() + self._plugin = directory.get_plugin() self._ctxt = context.get_admin_context() def _verify_network_create(self, code, exc_reason): @@ -183,7 +183,7 @@ class DBExtensionDriverTestCase(test_plugin.Ml2PluginV2TestCase): self._extension_drivers, group='ml2') super(DBExtensionDriverTestCase, self).setUp() - self._plugin = manager.NeutronManager.get_plugin() + self._plugin = directory.get_plugin() self._ctxt = context.get_admin_context() def test_network_attr(self): diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py index 4ab7d1aa60b..cf5dceb3351 100644 --- a/neutron/tests/unit/plugins/ml2/test_plugin.py +++ b/neutron/tests/unit/plugins/ml2/test_plugin.py @@ -24,6 +24,7 @@ import webob from neutron_lib import constants from neutron_lib import exceptions as exc +from neutron_lib.plugins import directory from oslo_db import exception as db_exc from oslo_utils import uuidutils from sqlalchemy.orm import exc as sqla_exc @@ -47,7 +48,6 @@ from neutron.extensions import external_net from neutron.extensions import multiprovidernet as mpnet from neutron.extensions import portbindings from neutron.extensions import providernet as pnet -from neutron import manager from neutron.plugins.common import constants as p_const from neutron.plugins.ml2.common import exceptions as ml2_exc from neutron.plugins.ml2 import config @@ -149,7 +149,7 @@ class Ml2PluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase): [self.phys_vrange, self.phys2_vrange], group='ml2_type_vlan') self.setup_parent() - self.driver = manager.NeutronManager.get_plugin() + self.driver = directory.get_plugin() self.context = context.get_admin_context() @@ -296,7 +296,7 @@ class TestMl2NetworksV2(test_plugin.TestNetworksV2, kwargs['network']['id']) def test_port_delete_helper_tolerates_failure(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with mock.patch.object(plugin, "delete_port", side_effect=exc.PortNotFound(port_id="123")): plugin._delete_ports(mock.MagicMock(), [mock.MagicMock()]) @@ -306,7 +306,7 @@ class TestMl2NetworksV2(test_plugin.TestNetworksV2, plugin._delete_ports(mock.MagicMock(), [mock.MagicMock()]) def test_subnet_delete_helper_tolerates_failure(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with mock.patch.object(plugin, "delete_subnet", side_effect=exc.SubnetNotFound(subnet_id="1")): plugin._delete_subnets(mock.MagicMock(), [mock.MagicMock()]) @@ -376,7 +376,7 @@ class TestMl2NetworksV2(test_plugin.TestNetworksV2, self.assertEqual(expected, actual) def test_create_network_segment_allocation_fails(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with mock.patch.object( plugin.type_manager, 'create_network_segments', side_effect=db_exc.RetryRequest(ValueError()) @@ -532,7 +532,7 @@ class TestMl2SubnetsV2(test_plugin.TestSubnetsV2, {'subnet_id': s3['subnet']['id']}] with self.port(subnet=s1, fixed_ips=fixed_ips, device_owner=constants.DEVICE_OWNER_DHCP) as p: - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() orig_update = plugin.update_port def delete_before_update(ctx, *args, **kwargs): @@ -609,7 +609,7 @@ class TestMl2SubnetsV2(test_plugin.TestSubnetsV2, filter_by(subnet_id=subnet_id). join(models_v2.Port).first()) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() # we mock _subnet_check_ip_allocations with method # that creates DHCP port 'in the middle' of subnet_delete # causing retry this way subnet is deleted on the @@ -673,7 +673,7 @@ class TestMl2DbOperationBoundsTenant(TestMl2DbOperationBounds): class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): def test__port_provisioned_with_blocks(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() ups = mock.patch.object(plugin, 'update_port_status').start() with self.port() as port: mock.patch('neutron.plugins.ml2.plugin.db.get_port').start() @@ -684,7 +684,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): self.assertFalse(ups.called) def test__port_provisioned_no_binding(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with self.network() as net: net_id = net['network']['id'] port_id = 'fake_id' @@ -705,8 +705,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): 'create_port_postcommit', side_effect=ml2_exc.MechanismDriverError( method='create_port_postcommit')): - l3_plugin = manager.NeutronManager.get_service_plugins().get( - p_const.L3_ROUTER_NAT) + l3_plugin = directory.get_plugin(constants.L3) data = {'router': {'name': 'router', 'admin_state_up': True, 'tenant_id': self.context.tenant_id}} r = l3_plugin.create_router(self.context, data) @@ -723,8 +722,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): with mock.patch.object(ml2_plugin.Ml2Plugin, '_bind_port_if_needed', side_effect=ml2_exc.MechanismDriverError( method='_bind_port_if_needed')): - l3_plugin = manager.NeutronManager.get_service_plugins().get( - p_const.L3_ROUTER_NAT) + l3_plugin = directory.get_plugin(constants.L3) data = {'router': {'name': 'router', 'admin_state_up': True, 'tenant_id': self.context.tenant_id}} r = l3_plugin.create_router(self.context, data) @@ -743,7 +741,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): def test_update_port_status_short_id(self): ctx = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with self.port() as port: with mock.patch.object(ml2_db, 'get_binding_levels', return_value=[]) as mock_gbl: @@ -754,7 +752,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): def _add_fake_dhcp_agent(self): agent = mock.Mock(configurations='{"notifies_port_ready": true}') - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() self.get_dhcp_mock = mock.patch.object( plugin, 'get_dhcp_agents_hosting_networks', return_value=[agent]).start() @@ -783,7 +781,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): def test_dhcp_provisioning_blocks_inserted_on_update(self): ctx = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() self._add_fake_dhcp_agent() with self.port() as port: with mock.patch.object(provisioning_blocks, @@ -800,7 +798,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): def test_create_update_get_port_same_fixed_ips_order(self): ctx = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() initial_fixed_ips = [{'ip_address': '10.0.0.5'}, {'ip_address': '10.0.0.7'}, {'ip_address': '10.0.0.6'}] @@ -816,7 +814,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): def test_update_port_fixed_ip_changed(self): ctx = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() fixed_ip_data = [{'ip_address': '10.0.0.4'}] with self.port(fixed_ips=fixed_ip_data) as port,\ mock.patch.object( @@ -829,7 +827,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): def test_update_port_status_with_network(self): registry.clear() # don't care about callback behavior ctx = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with self.port() as port: net = plugin.get_network(ctx, port['port']['network_id']) with mock.patch.object(plugin, 'get_network') as get_net: @@ -844,14 +842,14 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): def test_update_non_existent_port(self): ctx = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() data = {'port': {'admin_state_up': False}} self.assertRaises(exc.PortNotFound, plugin.update_port, ctx, 'invalid-uuid', data) def test_delete_non_existent_port(self): ctx = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with mock.patch.object(ml2_plugin.LOG, 'debug') as log_debug: plugin.delete_port(ctx, 'invalid-uuid', l3_port_check=False) log_debug.assert_has_calls([ @@ -860,8 +858,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): ]) def test_l3_cleanup_on_net_delete(self): - l3plugin = manager.NeutronManager.get_service_plugins().get( - p_const.L3_ROUTER_NAT) + l3plugin = directory.get_plugin(constants.L3) kwargs = {'arg_list': (external_net.EXTERNAL,), external_net.EXTERNAL: True} with self.network(**kwargs) as n: @@ -879,7 +876,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): def test_create_ports_bulk_port_binding_failure(self): ctx = context.get_admin_context() with self.network() as net: - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with mock.patch.object(plugin, '_bind_port_if_needed', side_effect=ml2_exc.MechanismDriverError( @@ -895,7 +892,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): def test_create_ports_bulk_with_sec_grp(self): ctx = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with self.network() as net,\ mock.patch.object(plugin.notifier, 'security_groups_member_updated') as m_upd,\ @@ -920,7 +917,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): def test_create_ports_bulk_with_sec_grp_member_provider_update(self): ctx = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with self.network() as net,\ mock.patch.object(plugin.notifier, 'security_groups_member_updated') as m_upd,\ @@ -955,7 +952,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): def test_create_ports_bulk_with_sec_grp_provider_update_ipv6(self): ctx = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() fake_prefix = '2001:db8::/64' fake_gateway = 'fe80::1' with self.network() as net: @@ -986,9 +983,8 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): def test_delete_port_no_notify_in_disassociate_floatingips(self): ctx = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() - l3plugin = manager.NeutronManager.get_service_plugins().get( - p_const.L3_ROUTER_NAT) + plugin = directory.get_plugin() + l3plugin = directory.get_plugin(constants.L3) with self.port() as port,\ mock.patch.object( l3plugin, @@ -1027,8 +1023,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): def test_disassociate_floatingips_do_notify_returns_nothing(self): ctx = context.get_admin_context() - l3plugin = manager.NeutronManager.get_service_plugins().get( - p_const.L3_ROUTER_NAT) + l3plugin = directory.get_plugin(constants.L3) with self.port() as port: port_id = port['port']['id'] @@ -1066,7 +1061,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): def test_delete_port_tolerates_db_deadlock(self): ctx = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with self.port() as port: port_db, binding = ml2_db.get_locked_port_and_binding( ctx.session, port['port']['id']) @@ -1144,7 +1139,7 @@ class TestMl2PortsV2WithRevisionPlugin(Ml2PluginV2TestCase): def test_update_port_status_bumps_revision(self): ctx = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() host_arg = {portbindings.HOST_ID: HOST} with self.port(arg_list=(portbindings.HOST_ID,), **host_arg) as port: @@ -1165,11 +1160,10 @@ class TestMl2PortsV2WithL3(test_plugin.TestPortsV2, Ml2PluginV2TestCase): def test_update_port_status_notify_port_event_after_update(self): ctx = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() # enable subscription for events l3_router_plugin.L3RouterPlugin() - l3plugin = manager.NeutronManager.get_service_plugins().get( - p_const.L3_ROUTER_NAT) + l3plugin = directory.get_plugin(constants.L3) host_arg = {portbindings.HOST_ID: HOST} with mock.patch.object(l3plugin.l3_rpc_notifier, 'routers_updated_on_host') as mock_updated: @@ -1188,7 +1182,7 @@ class TestMl2PluginOnly(Ml2PluginV2TestCase): """For testing methods that don't call drivers""" def test__verify_service_plugins_requirements(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with mock.patch.dict(ml2_plugin.SERVICE_PLUGINS_REQUIRED_DRIVERS, {self.l3_plugin: self._mechanism_drivers}),\ mock.patch.object(plugin.extension_manager, @@ -1198,7 +1192,7 @@ class TestMl2PluginOnly(Ml2PluginV2TestCase): plugin._verify_service_plugins_requirements() def test__verify_service_plugins_requirements_missing_driver(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with mock.patch.dict(ml2_plugin.SERVICE_PLUGINS_REQUIRED_DRIVERS, {self.l3_plugin: ['test_required_driver']}),\ mock.patch.object(plugin.extension_manager, @@ -1211,7 +1205,7 @@ class TestMl2PluginOnly(Ml2PluginV2TestCase): ) def _test_check_mac_update_allowed(self, vif_type, expect_change=True): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() port = {'mac_address': "fake_mac", 'id': "fake_id"} if expect_change: new_attrs = {"mac_address": "dummy_mac"} @@ -1262,7 +1256,7 @@ class TestMl2PluginOnly(Ml2PluginV2TestCase): class Test_GetNetworkMtu(Ml2PluginV2TestCase): def test_get_mtu_with_physical_net(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() mock_type_driver = mock.MagicMock() plugin.type_manager.drivers['driver1'] = mock.Mock() plugin.type_manager.drivers['driver1'].obj = mock_type_driver @@ -1275,7 +1269,7 @@ class Test_GetNetworkMtu(Ml2PluginV2TestCase): mock_type_driver.get_mtu.assert_called_once_with('physnet1') def _register_type_driver_with_mtu(self, driver, mtu): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() class FakeDriver(object): def get_mtu(self, physical_network=None): @@ -1286,7 +1280,7 @@ class Test_GetNetworkMtu(Ml2PluginV2TestCase): plugin.type_manager.drivers[driver] = driver_mock def test_single_segment(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() self._register_type_driver_with_mtu('driver1', 1400) net = { @@ -1301,7 +1295,7 @@ class Test_GetNetworkMtu(Ml2PluginV2TestCase): self.assertEqual(1400, plugin._get_network_mtu(net)) def test_multiple_segments_returns_minimal_mtu(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() self._register_type_driver_with_mtu('driver1', 1400) self._register_type_driver_with_mtu('driver2', 1300) @@ -1321,7 +1315,7 @@ class Test_GetNetworkMtu(Ml2PluginV2TestCase): self.assertEqual(1300, plugin._get_network_mtu(net)) def test_no_segments(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() self._register_type_driver_with_mtu('driver1', 1400) net = { @@ -1332,7 +1326,7 @@ class Test_GetNetworkMtu(Ml2PluginV2TestCase): self.assertEqual(1400, plugin._get_network_mtu(net)) def test_get_mtu_None_returns_0(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() self._register_type_driver_with_mtu('driver1', None) net = { @@ -1343,7 +1337,7 @@ class Test_GetNetworkMtu(Ml2PluginV2TestCase): self.assertEqual(0, plugin._get_network_mtu(net)) def test_unknown_segment_type_ignored(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() self._register_type_driver_with_mtu('driver1', None) self._register_type_driver_with_mtu('driver2', 1300) @@ -1369,23 +1363,20 @@ class TestMl2DvrPortsV2(TestMl2PortsV2): extensions = ['router', constants.L3_AGENT_SCHEDULER_EXT_ALIAS, constants.L3_DISTRIBUTED_EXT_ALIAS] - self.plugin = manager.NeutronManager.get_plugin() + self.plugin = directory.get_plugin() self.l3plugin = mock.Mock() type(self.l3plugin).supported_extension_aliases = ( mock.PropertyMock(return_value=extensions)) - self.service_plugins = {'L3_ROUTER_NAT': self.l3plugin} def test_delete_port_notifies_l3_plugin(self, floating_ip=False): + directory.add_plugin(constants.L3, self.l3plugin) ns_to_delete = {'host': 'myhost', 'agent_id': 'vm_l3_agent', 'router_id': 'my_router'} router_ids = set() if floating_ip: router_ids.add(ns_to_delete['router_id']) - with mock.patch.object(manager.NeutronManager, - 'get_service_plugins', - return_value=self.service_plugins),\ - self.port() as port,\ + with self.port() as port,\ mock.patch.object(registry, 'notify') as notify,\ mock.patch.object(self.l3plugin, 'disassociate_floatingips', @@ -1408,8 +1399,7 @@ class TestMl2DvrPortsV2(TestMl2PortsV2): self.test_delete_port_notifies_l3_plugin(floating_ip=True) def test_concurrent_csnat_port_delete(self): - plugin = manager.NeutronManager.get_service_plugins()[ - p_const.L3_ROUTER_NAT] + plugin = directory.get_plugin(constants.L3) r = plugin.create_router( self.context, {'router': {'name': 'router', 'admin_state_up': True, @@ -1497,7 +1487,7 @@ class TestMl2PortBinding(Ml2PluginV2TestCase, def test_return_on_concurrent_delete_and_binding(self): # create a port and delete it so we have an expired mechanism context with self.port() as port: - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() binding = ml2_db.get_locked_port_and_binding(self.context.session, port['port']['id'])[1] binding['host'] = 'test' @@ -1518,7 +1508,7 @@ class TestMl2PortBinding(Ml2PluginV2TestCase, def _create_port_and_bound_context(self, port_vif_type, bound_vif_type): with self.port() as port: - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() binding = ml2_db.get_locked_port_and_binding(self.context.session, port['port']['id'])[1] binding['host'] = 'fake_host' @@ -1618,7 +1608,7 @@ class TestMl2PortBinding(Ml2PluginV2TestCase, def test_update_port_binding_host_id_none(self): with self.port() as port: - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() binding = ml2_db.get_locked_port_and_binding(self.context.session, port['port']['id'])[1] binding['host'] = 'test' @@ -1635,7 +1625,7 @@ class TestMl2PortBinding(Ml2PluginV2TestCase, def test_update_port_binding_host_id_not_changed(self): with self.port() as port: - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() binding = ml2_db.get_locked_port_and_binding(self.context.session, port['port']['id'])[1] binding['host'] = 'test' @@ -1659,7 +1649,7 @@ class TestMl2PortBinding(Ml2PluginV2TestCase, vif_type=portbindings.VIF_TYPE_OVS, vnic_type=portbindings.VNIC_NORMAL, status=constants.PORT_STATUS_DOWN) - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() mock_network = {'id': 'net_id'} mock_port = {'id': 'port_id'} context = mock.Mock() @@ -1677,7 +1667,7 @@ class TestMl2PortBinding(Ml2PluginV2TestCase, self.assertEqual(host_id, mech_context._binding.host) def test_update_distributed_port_binding_on_concurrent_port_delete(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with self.port() as port: port = { 'id': port['port']['id'], @@ -1691,7 +1681,7 @@ class TestMl2PortBinding(Ml2PluginV2TestCase, self.assertIsNone(res) def test_update_distributed_port_binding_on_non_existent_port(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() port = { 'id': 'foo_port_id', portbindings.HOST_ID: 'foo_host', @@ -2444,7 +2434,7 @@ class TestMl2PluginCreateUpdateDeletePort(base.BaseTestCase): super(TestMl2PluginCreateUpdateDeletePort, self).setUp() # TODO(ihrachys): revisit plugin setup once we decouple # neutron.objects.db.api from core plugin instance - self.setup_coreplugin(PLUGIN_NAME) + self.setup_coreplugin(PLUGIN_NAME, load_plugins=False) self.context = mock.MagicMock() self.context.session.is_active = False self.notify_p = mock.patch('neutron.callbacks.registry.notify') @@ -2458,6 +2448,7 @@ class TestMl2PluginCreateUpdateDeletePort(base.BaseTestCase): def _create_plugin_for_create_update_port(self): plugin = ml2_plugin.Ml2Plugin() + directory.add_plugin(constants.CORE, plugin) plugin.extension_manager = mock.Mock() plugin.type_manager = mock.Mock() plugin.mechanism_manager = mock.Mock() @@ -2548,9 +2539,9 @@ class TestMl2PluginCreateUpdateDeletePort(base.BaseTestCase): with mock.patch.object(ml2_plugin.Ml2Plugin, '__init__', return_value=None),\ - mock.patch.object(manager.NeutronManager, - 'get_service_plugins', - return_value={'L3_ROUTER_NAT': l3plugin}),\ + mock.patch.object(directory, + 'get_plugins', + return_value={constants.L3: l3plugin}),\ mock.patch.object(ml2_plugin.Ml2Plugin, '_get_network_mtu'): plugin = self._create_plugin_for_create_update_port() @@ -2564,14 +2555,14 @@ class TestMl2PluginCreateUpdateDeletePort(base.BaseTestCase): class TestTransactionGuard(Ml2PluginV2TestCase): def test_delete_network_guard(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() ctx = context.get_admin_context() with ctx.session.begin(subtransactions=True): with testtools.ExpectedException(RuntimeError): plugin.delete_network(ctx, 'id') def test_delete_subnet_guard(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() ctx = context.get_admin_context() with ctx.session.begin(subtransactions=True): with testtools.ExpectedException(RuntimeError): @@ -2685,7 +2676,7 @@ class TestML2Segments(Ml2PluginV2TestCase): def test_prevent_delete_segment_with_tenant_port(self): fake_owner_compute = constants.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' ml2_db.subscribe() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with self.port(device_owner=fake_owner_compute) as port: binding = ml2_db.get_locked_port_and_binding(self.context.session, port['port']['id'])[1] diff --git a/neutron/tests/unit/plugins/ml2/test_port_binding.py b/neutron/tests/unit/plugins/ml2/test_port_binding.py index 50e488f968f..78101e141f6 100644 --- a/neutron/tests/unit/plugins/ml2/test_port_binding.py +++ b/neutron/tests/unit/plugins/ml2/test_port_binding.py @@ -15,10 +15,10 @@ import mock from neutron_lib import constants as const +from neutron_lib.plugins import directory from neutron import context from neutron.extensions import portbindings -from neutron import manager from neutron.plugins.ml2 import config from neutron.plugins.ml2 import driver_context from neutron.plugins.ml2 import models as ml2_models @@ -39,7 +39,7 @@ class PortBindingTestCase(test_plugin.NeutronDbPluginV2TestCase): group='ml2_type_vlan') super(PortBindingTestCase, self).setUp('ml2') self.port_create_status = 'DOWN' - self.plugin = manager.NeutronManager.get_plugin() + self.plugin = directory.get_plugin() self.plugin.start_rpc_listeners() def _check_response(self, port, vif_type, has_port_filter, bound, status): @@ -176,7 +176,7 @@ class PortBindingTestCase(test_plugin.NeutronDbPluginV2TestCase): def test_process_binding_port_host_id_changed(self): ctx = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() host_id = {portbindings.HOST_ID: 'host1'} with self.port(**host_id) as port: # Since the port is DOWN at first diff --git a/neutron/tests/unit/plugins/ml2/test_rpc.py b/neutron/tests/unit/plugins/ml2/test_rpc.py index 3351f897338..fcc6692f5ce 100644 --- a/neutron/tests/unit/plugins/ml2/test_rpc.py +++ b/neutron/tests/unit/plugins/ml2/test_rpc.py @@ -21,6 +21,7 @@ import collections import mock from neutron_lib import constants +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_context import context as oslo_context import oslo_messaging @@ -48,9 +49,8 @@ class RpcCallbacksTestCase(base.BaseTestCase): self.notifier = plugin_rpc.AgentNotifierApi(topics.AGENT) self.callbacks = plugin_rpc.RpcCallbacks(self.notifier, self.type_manager) - self.manager = mock.patch.object( - plugin_rpc.manager, 'NeutronManager').start() - self.plugin = self.manager.get_plugin() + self.plugin = mock.MagicMock() + directory.add_plugin(constants.CORE, self.plugin) def _test_update_device_up(self, host=None): kwargs = { diff --git a/neutron/tests/unit/plugins/ml2/test_security_group.py b/neutron/tests/unit/plugins/ml2/test_security_group.py index cc1056ccd75..d3dfd1c3237 100644 --- a/neutron/tests/unit/plugins/ml2/test_security_group.py +++ b/neutron/tests/unit/plugins/ml2/test_security_group.py @@ -18,10 +18,10 @@ import math import mock from neutron_lib import constants as const +from neutron_lib.plugins import directory from neutron import context from neutron.extensions import securitygroup as ext_sg -from neutron import manager from neutron.tests import tools from neutron.tests.unit.agent import test_securitygroups_rpc as test_sg_rpc from neutron.tests.unit.api.v2 import test_base @@ -51,7 +51,7 @@ class TestMl2SecurityGroups(Ml2SecurityGroupsTestCase, def setUp(self): super(TestMl2SecurityGroups, self).setUp() self.ctx = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() plugin.start_rpc_listeners() def _make_port_with_new_sec_group(self, net_id): @@ -73,7 +73,7 @@ class TestMl2SecurityGroups(Ml2SecurityGroupsTestCase, self._make_port_with_new_sec_group(n['network']['id']), self._make_port_without_sec_group(n['network']['id']) ] - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() # should match full ID and starting chars ports = plugin.get_ports_from_devices(self.ctx, [orig_ports[0]['id'], orig_ports[1]['id'][0:8], @@ -91,12 +91,12 @@ class TestMl2SecurityGroups(Ml2SecurityGroupsTestCase, self._delete('ports', p['id']) def test_security_group_get_ports_from_devices_with_bad_id(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() ports = plugin.get_ports_from_devices(self.ctx, ['bad_device_id']) self.assertFalse(ports) def test_security_group_no_db_calls_with_no_ports(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() with mock.patch( 'neutron.plugins.ml2.db.get_sg_ids_grouped_by_port' ) as get_mock: @@ -104,7 +104,7 @@ class TestMl2SecurityGroups(Ml2SecurityGroupsTestCase, self.assertFalse(get_mock.called) def test_large_port_count_broken_into_parts(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() max_ports_per_query = 5 ports_to_query = 73 for max_ports_per_query in (1, 2, 5, 7, 9, 31): @@ -133,7 +133,7 @@ class TestMl2SecurityGroups(Ml2SecurityGroupsTestCase, ) def test_full_uuids_skip_port_id_lookup(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() # when full UUIDs are provided, the _or statement should only # have one matching 'IN' criteria for all of the IDs with mock.patch('neutron.plugins.ml2.db.or_') as or_mock,\ diff --git a/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py b/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py index 26cd449dd47..0eb37611537 100644 --- a/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py +++ b/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py @@ -297,6 +297,7 @@ class TestAutoScheduleNetworks(TestDhcpSchedulerBaseTestCase): class TestAutoScheduleSegments(test_plugin.Ml2PluginV2TestCase, TestDhcpSchedulerBaseTestCase): """Unit test scenarios for ChanceScheduler""" + CORE_PLUGIN = 'neutron.plugins.ml2.plugin.Ml2Plugin' def setUp(self): super(TestAutoScheduleSegments, self).setUp() diff --git a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py index 41a461ec787..d38488da083 100644 --- a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py +++ b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py @@ -20,6 +20,7 @@ import uuid import mock from neutron_lib import constants +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_utils import importutils from oslo_utils import timeutils @@ -768,7 +769,7 @@ class L3SchedulerTestCaseMixin(test_l3.L3NatTestCaseMixin, ext_mgr=ext_mgr) self.adminContext = n_context.get_admin_context() - self.plugin = manager.NeutronManager.get_plugin() + self.plugin = directory.get_plugin() self.plugin.router_scheduler = importutils.import_object( 'neutron.scheduler.l3_agent_scheduler.ChanceScheduler' ) @@ -893,8 +894,8 @@ class L3DvrScheduler(l3_db.L3_NAT_db_mixin, class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): def setUp(self): - self.setup_coreplugin('ml2') super(L3DvrSchedulerTestCase, self).setUp() + self.setup_coreplugin('ml2') self.adminContext = n_context.get_admin_context() self.dut = L3DvrScheduler() @@ -927,30 +928,27 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): port = kwargs.get('original_port') port_addr_pairs = port['allowed_address_pairs'] l3plugin = mock.Mock() - - with mock.patch.object(manager.NeutronManager, - 'get_service_plugins', - return_value={'L3_ROUTER_NAT': l3plugin}): - l3_dvrscheduler_db._notify_l3_agent_port_update( - 'port', 'after_update', mock.ANY, **kwargs) - l3plugin._get_allowed_address_pair_fixed_ips.return_value = ( - ['10.1.0.21']) - self.assertTrue( - l3plugin.remove_unbound_allowed_address_pair_port_binding. - called) - l3plugin.remove_unbound_allowed_address_pair_port_binding.\ - assert_called_once_with( - self.adminContext, - port, - port_addr_pairs[0]) - self.assertFalse( - l3plugin.update_arp_entry_for_dvr_service_port.called) - l3plugin.delete_arp_entry_for_dvr_service_port.\ - assert_called_once_with( - self.adminContext, - port, - fixed_ips_to_delete=mock.ANY) - self.assertFalse(l3plugin.dvr_handle_new_service_port.called) + directory.add_plugin(constants.L3, l3plugin) + l3_dvrscheduler_db._notify_l3_agent_port_update( + 'port', 'after_update', mock.ANY, **kwargs) + l3plugin._get_allowed_address_pair_fixed_ips.return_value = ( + ['10.1.0.21']) + self.assertTrue( + l3plugin.remove_unbound_allowed_address_pair_port_binding. + called) + l3plugin.remove_unbound_allowed_address_pair_port_binding.\ + assert_called_once_with( + self.adminContext, + port, + port_addr_pairs[0]) + self.assertFalse( + l3plugin.update_arp_entry_for_dvr_service_port.called) + l3plugin.delete_arp_entry_for_dvr_service_port.\ + assert_called_once_with( + self.adminContext, + port, + fixed_ips_to_delete=mock.ANY) + self.assertFalse(l3plugin.dvr_handle_new_service_port.called) def test__notify_l3_agent_update_port_with_allowed_address_pairs(self): port_id = str(uuid.uuid4()) @@ -977,23 +975,20 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): port = kwargs.get('port') port_addr_pairs = port['allowed_address_pairs'] l3plugin = mock.Mock() - - with mock.patch.object(manager.NeutronManager, - 'get_service_plugins', - return_value={'L3_ROUTER_NAT': l3plugin}): - l3_dvrscheduler_db._notify_l3_agent_port_update( - 'port', 'after_update', mock.ANY, **kwargs) - self.assertTrue( - l3plugin.update_unbound_allowed_address_pair_port_binding. - called) - l3plugin.update_unbound_allowed_address_pair_port_binding.\ - assert_called_once_with( - self.adminContext, - port, - port_addr_pairs[0]) - self.assertTrue( - l3plugin.update_arp_entry_for_dvr_service_port.called) - self.assertTrue(l3plugin.dvr_handle_new_service_port.called) + directory.add_plugin(constants.L3, l3plugin) + l3_dvrscheduler_db._notify_l3_agent_port_update( + 'port', 'after_update', mock.ANY, **kwargs) + self.assertTrue( + l3plugin.update_unbound_allowed_address_pair_port_binding. + called) + l3plugin.update_unbound_allowed_address_pair_port_binding.\ + assert_called_once_with( + self.adminContext, + port, + port_addr_pairs[0]) + self.assertTrue( + l3plugin.update_arp_entry_for_dvr_service_port.called) + self.assertTrue(l3plugin.dvr_handle_new_service_port.called) def test__notify_l3_agent_update_port_no_removing_routers(self): port_id = 'fake-port' @@ -1010,24 +1005,21 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): 'mac_address_updated': True } - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() l3plugin = mock.Mock() l3plugin.supported_extension_aliases = [ 'router', constants.L3_AGENT_SCHEDULER_EXT_ALIAS, constants.L3_DISTRIBUTED_EXT_ALIAS ] - - with mock.patch.object(manager.NeutronManager, - 'get_service_plugins', - return_value={'L3_ROUTER_NAT': l3plugin}): - l3_dvrscheduler_db._notify_l3_agent_port_update( - 'port', 'after_update', plugin, **kwargs) - self.assertFalse( - l3plugin.update_arp_entry_for_dvr_service_port.called) - self.assertFalse( - l3plugin.dvr_handle_new_service_port.called) - self.assertFalse(l3plugin.remove_router_from_l3_agent.called) - self.assertFalse(l3plugin.get_dvr_routers_to_remove.called) + directory.add_plugin(constants.L3, l3plugin) + l3_dvrscheduler_db._notify_l3_agent_port_update( + 'port', 'after_update', plugin, **kwargs) + self.assertFalse( + l3plugin.update_arp_entry_for_dvr_service_port.called) + self.assertFalse( + l3plugin.dvr_handle_new_service_port.called) + self.assertFalse(l3plugin.remove_router_from_l3_agent.called) + self.assertFalse(l3plugin.get_dvr_routers_to_remove.called) def test__notify_l3_agent_new_port_action(self): kwargs = { @@ -1038,16 +1030,14 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): }, } l3plugin = mock.Mock() - with mock.patch.object(manager.NeutronManager, - 'get_service_plugins', - return_value={'L3_ROUTER_NAT': l3plugin}): - l3_dvrscheduler_db._notify_l3_agent_new_port( - 'port', 'after_create', mock.ANY, **kwargs) - l3plugin.update_arp_entry_for_dvr_service_port.\ - assert_called_once_with( - self.adminContext, kwargs.get('port')) - l3plugin.dvr_handle_new_service_port.assert_called_once_with( + directory.add_plugin(constants.L3, l3plugin) + l3_dvrscheduler_db._notify_l3_agent_new_port( + 'port', 'after_create', mock.ANY, **kwargs) + l3plugin.update_arp_entry_for_dvr_service_port.\ + assert_called_once_with( self.adminContext, kwargs.get('port')) + l3plugin.dvr_handle_new_service_port.assert_called_once_with( + self.adminContext, kwargs.get('port')) def test__notify_l3_agent_new_port_no_action(self): kwargs = { @@ -1058,15 +1048,13 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): } } l3plugin = mock.Mock() - with mock.patch.object(manager.NeutronManager, - 'get_service_plugins', - return_value={'L3_ROUTER_NAT': l3plugin}): - l3_dvrscheduler_db._notify_l3_agent_new_port( - 'port', 'after_create', mock.ANY, **kwargs) - self.assertFalse( - l3plugin.update_arp_entry_for_dvr_service_port.called) - self.assertFalse( - l3plugin.dvr_handle_new_service_port.called) + directory.add_plugin(constants.L3, l3plugin) + l3_dvrscheduler_db._notify_l3_agent_new_port( + 'port', 'after_create', mock.ANY, **kwargs) + self.assertFalse( + l3plugin.update_arp_entry_for_dvr_service_port.called) + self.assertFalse( + l3plugin.dvr_handle_new_service_port.called) def test__notify_l3_agent_update_port_with_migration_port_profile(self): kwargs = { @@ -1082,16 +1070,14 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): }, } l3plugin = mock.Mock() - with mock.patch.object(manager.NeutronManager, - 'get_service_plugins', - return_value={'L3_ROUTER_NAT': l3plugin}): - l3_dvrscheduler_db._notify_l3_agent_port_update( - 'port', 'after_update', mock.ANY, **kwargs) - l3plugin.dvr_handle_new_service_port.assert_called_once_with( - self.adminContext, kwargs.get('port'), dest_host='vm-host2') - l3plugin.update_arp_entry_for_dvr_service_port.\ - assert_called_once_with( - self.adminContext, kwargs.get('port')) + directory.add_plugin(constants.L3, l3plugin) + l3_dvrscheduler_db._notify_l3_agent_port_update( + 'port', 'after_update', mock.ANY, **kwargs) + l3plugin.dvr_handle_new_service_port.assert_called_once_with( + self.adminContext, kwargs.get('port'), dest_host='vm-host2') + l3plugin.update_arp_entry_for_dvr_service_port.\ + assert_called_once_with( + self.adminContext, kwargs.get('port')) def test__notify_l3_agent_update_port_no_action(self): kwargs = { @@ -1106,18 +1092,16 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): }, } l3plugin = mock.Mock() - with mock.patch.object(manager.NeutronManager, - 'get_service_plugins', - return_value={'L3_ROUTER_NAT': l3plugin}): - l3_dvrscheduler_db._notify_l3_agent_port_update( - 'port', 'after_update', mock.ANY, **kwargs) + directory.add_plugin(constants.L3, l3plugin) + l3_dvrscheduler_db._notify_l3_agent_port_update( + 'port', 'after_update', mock.ANY, **kwargs) - self.assertFalse( - l3plugin.update_arp_entry_for_dvr_service_port.called) - self.assertFalse( - l3plugin.dvr_handle_new_service_port.called) - self.assertFalse(l3plugin.remove_router_from_l3_agent.called) - self.assertFalse(l3plugin.get_dvr_routers_to_remove.called) + self.assertFalse( + l3plugin.update_arp_entry_for_dvr_service_port.called) + self.assertFalse( + l3plugin.dvr_handle_new_service_port.called) + self.assertFalse(l3plugin.remove_router_from_l3_agent.called) + self.assertFalse(l3plugin.get_dvr_routers_to_remove.called) def test__notify_l3_agent_update_port_with_mac_address_update(self): kwargs = { @@ -1133,16 +1117,14 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): 'mac_address_updated': True } l3plugin = mock.Mock() - with mock.patch.object(manager.NeutronManager, - 'get_service_plugins', - return_value={'L3_ROUTER_NAT': l3plugin}): - l3_dvrscheduler_db._notify_l3_agent_port_update( - 'port', 'after_update', mock.ANY, **kwargs) + directory.add_plugin(constants.L3, l3plugin) + l3_dvrscheduler_db._notify_l3_agent_port_update( + 'port', 'after_update', mock.ANY, **kwargs) - l3plugin.update_arp_entry_for_dvr_service_port.\ - assert_called_once_with( - self.adminContext, kwargs.get('port')) - self.assertFalse(l3plugin.dvr_handle_new_service_port.called) + l3plugin.update_arp_entry_for_dvr_service_port.\ + assert_called_once_with( + self.adminContext, kwargs.get('port')) + self.assertFalse(l3plugin.dvr_handle_new_service_port.called) def test__notify_l3_agent_port_binding_change(self): self._test__notify_l3_agent_port_binding_change() @@ -1181,11 +1163,9 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): }, } l3plugin = mock.Mock() - with mock.patch.object(manager.NeutronManager, - 'get_service_plugins', - return_value={'L3_ROUTER_NAT': l3plugin}),\ - mock.patch.object(l3plugin, 'get_dvr_routers_to_remove', - return_value=routers_to_remove),\ + directory.add_plugin(constants.L3, l3plugin) + with mock.patch.object(l3plugin, 'get_dvr_routers_to_remove', + return_value=routers_to_remove),\ mock.patch.object(l3plugin, '_get_floatingip_on_port', return_value=fip): l3_dvrscheduler_db._notify_l3_agent_port_update( @@ -1224,19 +1204,17 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): } } - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() l3plugin = mock.Mock() l3plugin.supported_extension_aliases = [ 'router', constants.L3_AGENT_SCHEDULER_EXT_ALIAS, constants.L3_DISTRIBUTED_EXT_ALIAS ] - with mock.patch.object(manager.NeutronManager, - 'get_service_plugins', - return_value={'L3_ROUTER_NAT': l3plugin}),\ - mock.patch.object(l3plugin, 'get_dvr_routers_to_remove', - return_value=[{'agent_id': 'foo_agent', - 'router_id': 'foo_id', - 'host': source_host}]),\ + directory.add_plugin(constants.L3, l3plugin) + with mock.patch.object(l3plugin, 'get_dvr_routers_to_remove', + return_value=[{'agent_id': 'foo_agent', + 'router_id': 'foo_id', + 'host': source_host}]),\ mock.patch.object(l3plugin, '_get_floatingip_on_port', return_value=None): l3_dvrscheduler_db._notify_l3_agent_port_update( @@ -1254,12 +1232,13 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): assert_called_once_with(mock.ANY, 'foo_id', source_host)) def test__notify_port_delete(self): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() l3plugin = mock.Mock() l3plugin.supported_extension_aliases = [ 'router', constants.L3_AGENT_SCHEDULER_EXT_ALIAS, constants.L3_DISTRIBUTED_EXT_ALIAS ] + directory.add_plugin(constants.L3, l3plugin) port = { 'id': str(uuid.uuid4()), 'device_id': 'abcd', @@ -1267,27 +1246,24 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): portbindings.HOST_ID: 'host1', } - with mock.patch.object(manager.NeutronManager, - 'get_service_plugins', - return_value={'L3_ROUTER_NAT': l3plugin}): - kwargs = { - 'context': self.adminContext, - 'port': port, - 'removed_routers': [ - {'agent_id': 'foo_agent', 'router_id': 'foo_id'}, - ], - } - removed_routers = [{'agent_id': 'foo_agent', - 'router_id': 'foo_id', - 'host': 'foo_host'}] - l3plugin.get_dvr_routers_to_remove.return_value = removed_routers - l3_dvrscheduler_db._notify_port_delete( - 'port', 'after_delete', plugin, **kwargs) - l3plugin.delete_arp_entry_for_dvr_service_port.\ - assert_called_once_with( - self.adminContext, mock.ANY) - (l3plugin.l3_rpc_notifier.router_removed_from_agent. - assert_called_once_with(mock.ANY, 'foo_id', 'foo_host')) + kwargs = { + 'context': self.adminContext, + 'port': port, + 'removed_routers': [ + {'agent_id': 'foo_agent', 'router_id': 'foo_id'}, + ], + } + removed_routers = [{'agent_id': 'foo_agent', + 'router_id': 'foo_id', + 'host': 'foo_host'}] + l3plugin.get_dvr_routers_to_remove.return_value = removed_routers + l3_dvrscheduler_db._notify_port_delete( + 'port', 'after_delete', plugin, **kwargs) + l3plugin.delete_arp_entry_for_dvr_service_port.\ + assert_called_once_with( + self.adminContext, mock.ANY) + (l3plugin.l3_rpc_notifier.router_removed_from_agent. + assert_called_once_with(mock.ANY, 'foo_id', 'foo_host')) def test_dvr_handle_new_service_port(self): port = { @@ -1447,7 +1423,7 @@ class L3HATestCaseMixin(testlib_api.SqlTestCase, mock.patch('neutron.common.rpc.get_client').start() self.plugin = L3HAPlugin() - self.setup_coreplugin('ml2') + self.setup_coreplugin('ml2', load_plugins=False) cfg.CONF.set_override('service_plugins', ['neutron.services.l3_router.' 'l3_router_plugin.L3RouterPlugin']) @@ -1457,6 +1433,7 @@ class L3HATestCaseMixin(testlib_api.SqlTestCase, 'neutron.scheduler.l3_agent_scheduler.ChanceScheduler' ) + manager.init() self._register_l3_agents() @staticmethod diff --git a/neutron/tests/unit/services/l3_router/service_providers/test_driver_controller.py b/neutron/tests/unit/services/l3_router/service_providers/test_driver_controller.py index 784d8661312..ea9db7558c9 100644 --- a/neutron/tests/unit/services/l3_router/service_providers/test_driver_controller.py +++ b/neutron/tests/unit/services/l3_router/service_providers/test_driver_controller.py @@ -13,13 +13,12 @@ # under the License. import mock -from mock import patch from neutron_lib import constants from neutron_lib import exceptions as lib_exc +from neutron_lib.plugins import directory import testtools from neutron import context -from neutron import manager from neutron.plugins.common import constants as p_cons from neutron.services.l3_router.service_providers import driver_controller from neutron.services import provider_configuration @@ -125,13 +124,11 @@ class TestDriverController(testlib_api.SqlTestCase): self.fake_l3.get_router.side_effect = ValueError self.dc._get_provider_for_router(self.ctx, body['id']) - @patch.object(manager.NeutronManager, "get_service_plugins") - def test__flavor_plugin(self, get_service_plugins): - _fake_flavor_plugin = mock.sentinel.fla_plugin - get_service_plugins.return_value = {p_cons.FLAVORS: - _fake_flavor_plugin} + def test__flavor_plugin(self): + directory.add_plugin(p_cons.FLAVORS, mock.Mock()) _dc = driver_controller.DriverController(self.fake_l3) - self.assertEqual(_fake_flavor_plugin, _dc._flavor_plugin) + self.assertEqual( + directory.get_plugin(p_cons.FLAVORS), _dc._flavor_plugin) class Test_LegacyPlusProviderConfiguration(base.BaseTestCase): diff --git a/neutron/tests/unit/services/metering/test_metering_plugin.py b/neutron/tests/unit/services/metering/test_metering_plugin.py index 96ac309d95f..3ca8729532f 100644 --- a/neutron/tests/unit/services/metering/test_metering_plugin.py +++ b/neutron/tests/unit/services/metering/test_metering_plugin.py @@ -13,6 +13,7 @@ # under the License. import mock +from neutron_lib.plugins import directory from oslo_utils import uuidutils from neutron.api.v2 import attributes as attr @@ -22,7 +23,6 @@ from neutron.db.metering import metering_rpc from neutron.db.models import agent as agent_model from neutron.extensions import l3 as ext_l3 from neutron.extensions import metering as ext_metering -from neutron import manager from neutron.plugins.common import constants from neutron.tests.common import helpers from neutron.tests import tools @@ -433,8 +433,7 @@ class TestMeteringPluginRpcFromL3Agent( self).setUp(plugin=plugin, service_plugins=service_plugins, ext_mgr=ext_mgr) - self.meter_plugin = manager.NeutronManager.get_service_plugins().get( - constants.METERING) + self.meter_plugin = directory.get_plugin(constants.METERING) self.tenant_id = 'admin_tenant_id' self.tenant_id_1 = 'tenant_id_1' diff --git a/neutron/tests/unit/services/qos/notification_drivers/test_manager.py b/neutron/tests/unit/services/qos/notification_drivers/test_manager.py index d3ac31950da..2282895a812 100644 --- a/neutron/tests/unit/services/qos/notification_drivers/test_manager.py +++ b/neutron/tests/unit/services/qos/notification_drivers/test_manager.py @@ -38,7 +38,7 @@ class TestQosDriversManagerBase(base.BaseQosTestCase): def setUp(self): super(TestQosDriversManagerBase, self).setUp() self.config_parse() - self.setup_coreplugin() + self.setup_coreplugin(load_plugins=False) config = cfg.ConfigOpts() driver_mgr_config.register_qos_plugin_opts(config) self.policy_data = {'policy': { diff --git a/neutron/tests/unit/services/qos/test_qos_plugin.py b/neutron/tests/unit/services/qos/test_qos_plugin.py index 2aa996b4fd0..d65407d703b 100644 --- a/neutron/tests/unit/services/qos/test_qos_plugin.py +++ b/neutron/tests/unit/services/qos/test_qos_plugin.py @@ -11,6 +11,7 @@ # under the License. import mock +from neutron_lib.plugins import directory from oslo_config import cfg from oslo_utils import uuidutils @@ -32,7 +33,7 @@ class TestQosPlugin(base.BaseQosTestCase): def setUp(self): super(TestQosPlugin, self).setUp() - self.setup_coreplugin() + self.setup_coreplugin(load_plugins=False) mock.patch('neutron.objects.db.api.create_object').start() mock.patch('neutron.objects.db.api.update_object').start() @@ -49,10 +50,8 @@ class TestQosPlugin(base.BaseQosTestCase): cfg.CONF.set_override("core_plugin", DB_PLUGIN_KLASS) cfg.CONF.set_override("service_plugins", ["qos"]) - mgr = manager.NeutronManager.get_instance() - self.qos_plugin = mgr.get_service_plugins().get( - constants.QOS) - + manager.init() + self.qos_plugin = directory.get_plugin(constants.QOS) self.qos_plugin.notification_driver_manager = mock.Mock() self.ctxt = context.Context('fake_user', 'fake_tenant') @@ -375,7 +374,7 @@ class TestQosPlugin(base.BaseQosTestCase): 'create_policy_bandwidth_limit_rules') def test_get_rule_types(self): - core_plugin = manager.NeutronManager.get_plugin() + core_plugin = directory.get_plugin() rule_types_mock = mock.PropertyMock( return_value=qos_consts.VALID_RULE_TYPES) filters = {'type': 'type_id'} diff --git a/neutron/tests/unit/services/revisions/test_revision_plugin.py b/neutron/tests/unit/services/revisions/test_revision_plugin.py index 63825f3402f..fec7a069355 100644 --- a/neutron/tests/unit/services/revisions/test_revision_plugin.py +++ b/neutron/tests/unit/services/revisions/test_revision_plugin.py @@ -15,10 +15,11 @@ import mock import netaddr +from neutron_lib import constants +from neutron_lib.plugins import directory from neutron import context as nctx from neutron.db import models_v2 -from neutron import manager from neutron.plugins.ml2 import config from neutron.tests.unit.plugins.ml2 import test_plugin @@ -43,13 +44,12 @@ class TestRevisionPlugin(test_plugin.Ml2PluginV2TestCase): mock.patch('neutron.services.qos.notification_drivers.message_queue' '.RpcQosServiceNotificationDriver').start() super(TestRevisionPlugin, self).setUp() - self.cp = manager.NeutronManager.get_plugin() - self.l3p = (manager.NeutronManager. - get_service_plugins()['L3_ROUTER_NAT']) + self.cp = directory.get_plugin() + self.l3p = directory.get_plugin(constants.L3) self.ctx = nctx.get_admin_context() def test_handle_expired_object(self): - rp = manager.NeutronManager.get_service_plugins()['revision_plugin'] + rp = directory.get_plugin('revision_plugin') with self.port(): with self.ctx.session.begin(): ipal_obj = self.ctx.session.query(models_v2.IPAllocation).one() @@ -155,7 +155,7 @@ class TestRevisionPlugin(test_plugin.Ml2PluginV2TestCase): def test_qos_policy_bump_port_revision(self): with self.port() as port: rev = port['port']['revision_number'] - qos_plugin = manager.NeutronManager.get_service_plugins()['QOS'] + qos_plugin = directory.get_plugin('QOS') qos_policy = {'policy': {'name': "policy1", 'tenant_id': "tenant1"}} qos_obj = qos_plugin.create_policy(self.ctx, qos_policy) @@ -167,7 +167,7 @@ class TestRevisionPlugin(test_plugin.Ml2PluginV2TestCase): def test_qos_policy_bump_network_revision(self): with self.network() as network: rev = network['network']['revision_number'] - qos_plugin = manager.NeutronManager.get_service_plugins()['QOS'] + qos_plugin = directory.get_plugin('QOS') qos_policy = {'policy': {'name': "policy1", 'tenant_id': "tenant1"}} qos_obj = qos_plugin.create_policy(self.ctx, qos_policy) diff --git a/neutron/tests/unit/services/trunk/rpc/test_server.py b/neutron/tests/unit/services/trunk/rpc/test_server.py index 76ae532f6de..141ed4cade2 100644 --- a/neutron/tests/unit/services/trunk/rpc/test_server.py +++ b/neutron/tests/unit/services/trunk/rpc/test_server.py @@ -12,6 +12,7 @@ # under the License. import mock +from neutron_lib.plugins import directory from oslo_config import cfg import oslo_messaging @@ -19,7 +20,6 @@ from neutron.api.rpc.callbacks import events from neutron.api.rpc.callbacks import resources from neutron.api.rpc.handlers import resources_rpc from neutron.extensions import portbindings -from neutron import manager from neutron.objects import trunk as trunk_obj from neutron.plugins.ml2 import plugin as ml2_plugin from neutron.services.trunk import constants @@ -44,7 +44,7 @@ class TrunkSkeletonTest(test_plugin.Ml2PluginV2TestCase): trunk_plugin.TrunkPlugin, 'check_compatibility').start() self.trunk_plugin = trunk_plugin.TrunkPlugin() self.trunk_plugin.add_segmentation_type('vlan', lambda x: True) - self.core_plugin = manager.NeutronManager.get_plugin() + self.core_plugin = directory.get_plugin() def _create_test_trunk(self, port, subports=None): subports = subports if subports else [] diff --git a/neutron/tests/unit/services/trunk/test_plugin.py b/neutron/tests/unit/services/trunk/test_plugin.py index 638f70d8977..c57df350652 100644 --- a/neutron/tests/unit/services/trunk/test_plugin.py +++ b/neutron/tests/unit/services/trunk/test_plugin.py @@ -14,14 +14,13 @@ # limitations under the License. import mock - +from neutron_lib.plugins import directory import testtools from neutron.callbacks import events from neutron.callbacks import registry from neutron.callbacks import resources from neutron.extensions import portbindings -from neutron import manager from neutron.objects import trunk as trunk_objects from neutron.services.trunk import callbacks from neutron.services.trunk import constants @@ -76,7 +75,7 @@ class TrunkPluginTestCase(test_plugin.Ml2PluginV2TestCase): exception): subport = create_subport_dict(child_port['port']['id']) self._create_test_trunk(parent_port, [subport]) - core_plugin = manager.NeutronManager.get_plugin() + core_plugin = directory.get_plugin() self.assertRaises(exception, core_plugin.delete_port, self.context, port_id) @@ -95,7 +94,7 @@ class TrunkPluginTestCase(test_plugin.Ml2PluginV2TestCase): def test_delete_trunk_raise_in_use(self): with self.port() as port: trunk = self._create_test_trunk(port) - core_plugin = manager.NeutronManager.get_plugin() + core_plugin = directory.get_plugin() port['port']['binding:host_id'] = 'host' core_plugin.update_port(self.context, port['port']['id'], port) self.assertRaises(trunk_exc.TrunkInUse, diff --git a/neutron/tests/unit/services/trunk/test_rules.py b/neutron/tests/unit/services/trunk/test_rules.py index c6c122a7809..7bf1346a331 100644 --- a/neutron/tests/unit/services/trunk/test_rules.py +++ b/neutron/tests/unit/services/trunk/test_rules.py @@ -17,10 +17,11 @@ import mock import testtools +from neutron_lib.api.definitions import trunk as trunk_api from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from oslo_utils import uuidutils -from neutron import manager from neutron.plugins.common import utils from neutron.plugins.ml2 import driver_api as api from neutron.services.trunk import constants @@ -152,7 +153,7 @@ class SubPortsValidatorMtuSanityTestCase(test_plugin.Ml2PluginV2TestCase): def _test_validate_subport_trunk_mtu( self, subport_net_mtu, trunk_net_mtu): - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() orig_get_network = plugin.get_network def get_network_adjust_mtu(*args, **kwargs): @@ -211,7 +212,8 @@ class TrunkPortValidatorTestCase(test_plugin.Ml2PluginV2TestCase): trunk = {'port_id': trunk_parent['port']['id'], 'tenant_id': 'test_tenant', 'sub_ports': []} - self.trunk_plugin.create_trunk(self.context, {'trunk': trunk}) + self.trunk_plugin.create_trunk( + self.context, {trunk_api.ALIAS: trunk}) validator = rules.TrunkPortValidator(trunk_parent['port']['id']) self.assertRaises(trunk_exc.ParentPortInUse, validator.validate, @@ -225,7 +227,8 @@ class TrunkPortValidatorTestCase(test_plugin.Ml2PluginV2TestCase): 'sub_ports': [{'port_id': subport['port']['id'], 'segmentation_type': 'vlan', 'segmentation_id': 2}]} - self.trunk_plugin.create_trunk(self.context, {'trunk': trunk}) + self.trunk_plugin.create_trunk( + self.context, {trunk_api.ALIAS: trunk}) validator = rules.TrunkPortValidator(subport['port']['id']) self.assertRaises(trunk_exc.TrunkPortInUse, validator.validate, @@ -233,7 +236,7 @@ class TrunkPortValidatorTestCase(test_plugin.Ml2PluginV2TestCase): def test_validate_port_has_binding_host(self): with self.port() as port: - core_plugin = manager.NeutronManager.get_plugin() + core_plugin = directory.get_plugin() port['port']['binding:host_id'] = 'host' core_plugin.update_port(self.context, port['port']['id'], port) validator = rules.TrunkPortValidator(port['port']['id']) @@ -258,11 +261,9 @@ class TrunkPortValidatorTestCase(test_plugin.Ml2PluginV2TestCase): # need to trigger a driver registration fakes.FakeDriverCanTrunkBoundPort.create() self.trunk_plugin = trunk_plugin.TrunkPlugin() - with self.port() as port, \ - mock.patch.object(manager.NeutronManager, - "get_service_plugins") as f: - f.return_value = {'trunk': self.trunk_plugin} - core_plugin = manager.NeutronManager.get_plugin() + directory.add_plugin('trunk', self.trunk_plugin) + with self.port() as port: + core_plugin = directory.get_plugin() port['port']['binding:host_id'] = 'host' core_plugin.update_port(self.context, port['port']['id'], port) validator = rules.TrunkPortValidator(port['port']['id']) @@ -273,13 +274,11 @@ class TrunkPortValidatorTestCase(test_plugin.Ml2PluginV2TestCase): # need to trigger a driver registration fakes.FakeDriverCanTrunkBoundPort.create() self.trunk_plugin = trunk_plugin.TrunkPlugin() + directory.add_plugin('trunk', self.trunk_plugin) with self.port() as port, \ - mock.patch.object(manager.NeutronManager, - "get_service_plugins") as f, \ mock.patch.object(trunk_utils, "is_driver_compatible", return_value=True) as g: - f.return_value = {'trunk': self.trunk_plugin} - core_plugin = manager.NeutronManager.get_plugin() + core_plugin = directory.get_plugin() port['port']['binding:host_id'] = 'host' core_plugin.update_port(self.context, port['port']['id'], port) validator = rules.TrunkPortValidator(port['port']['id']) @@ -295,14 +294,12 @@ class TrunkPortValidatorTestCase(test_plugin.Ml2PluginV2TestCase): d1 = fakes.FakeDriver.create() d2 = fakes.FakeDriverWithAgent.create() self.trunk_plugin = trunk_plugin.TrunkPlugin() + directory.add_plugin('trunk', self.trunk_plugin) self.trunk_plugin._drivers = [d1, d2] with self.port() as port, \ - mock.patch.object(manager.NeutronManager, - "get_service_plugins") as f, \ mock.patch.object(trunk_utils, "is_driver_compatible", return_value=True): - f.return_value = {'trunk': self.trunk_plugin} - core_plugin = manager.NeutronManager.get_plugin() + core_plugin = directory.get_plugin() port['port']['binding:host_id'] = 'host' core_plugin.update_port(self.context, port['port']['id'], port) validator = rules.TrunkPortValidator(port['port']['id']) @@ -318,7 +315,7 @@ class TrunkPortValidatorTestCase(test_plugin.Ml2PluginV2TestCase): def test_check_not_in_use_raises(self): with self.port() as port: - core_plugin = manager.NeutronManager.get_plugin() + core_plugin = directory.get_plugin() port['port']['device_id'] = 'foo_device_id' core_plugin.update_port(self.context, port['port']['id'], port) validator = rules.TrunkPortValidator(port['port']['id']) diff --git a/neutron/tests/unit/test_manager.py b/neutron/tests/unit/test_manager.py index 3ee3b956fa4..98ec5720571 100644 --- a/neutron/tests/unit/test_manager.py +++ b/neutron/tests/unit/test_manager.py @@ -16,6 +16,7 @@ import weakref import fixtures +from neutron_lib.plugins import directory from oslo_config import cfg from neutron import manager @@ -42,7 +43,7 @@ class NeutronManagerTestCase(base.BaseTestCase): def setUp(self): super(NeutronManagerTestCase, self).setUp() self.config_parse() - self.setup_coreplugin() + self.setup_coreplugin(load_plugins=False) self.useFixture( fixtures.MonkeyPatch('neutron.manager.NeutronManager._instance')) @@ -51,8 +52,8 @@ class NeutronManagerTestCase(base.BaseTestCase): cfg.CONF.set_override("service_plugins", ["neutron.tests.unit.dummy_plugin." "DummyServicePlugin"]) - mgr = manager.NeutronManager.get_instance() - plugin = mgr.get_service_plugins()[constants.DUMMY] + manager.init() + plugin = directory.get_plugin(constants.DUMMY) self.assertIsInstance( plugin, dummy_plugin.DummyServicePlugin, @@ -61,8 +62,8 @@ class NeutronManagerTestCase(base.BaseTestCase): def test_service_plugin_by_name_is_loaded(self): cfg.CONF.set_override("core_plugin", DB_PLUGIN_KLASS) cfg.CONF.set_override("service_plugins", ["dummy"]) - mgr = manager.NeutronManager.get_instance() - plugin = mgr.get_service_plugins()[constants.DUMMY] + manager.init() + plugin = directory.get_plugin(constants.DUMMY) self.assertIsInstance( plugin, dummy_plugin.DummyServicePlugin, @@ -104,8 +105,8 @@ class NeutronManagerTestCase(base.BaseTestCase): cfg.CONF.set_override("core_plugin", "neutron.tests.unit.test_manager." "MultiServiceCorePlugin") - mgr = manager.NeutronManager.get_instance() - svc_plugins = mgr.get_service_plugins() + manager.init() + svc_plugins = directory.get_plugins() self.assertEqual(3, len(svc_plugins)) self.assertIn(constants.CORE, svc_plugins.keys()) self.assertIn(constants.LOADBALANCER, svc_plugins.keys()) @@ -116,8 +117,8 @@ class NeutronManagerTestCase(base.BaseTestCase): 'neutron.tests.unit.dummy_plugin.DummyServicePlugin': 'DUMMY' } cfg.CONF.set_override("core_plugin", DB_PLUGIN_KLASS) - mgr = manager.NeutronManager.get_instance() - svc_plugins = mgr.get_service_plugins() + manager.init() + svc_plugins = directory.get_plugins() self.assertIn('DUMMY', svc_plugins) def test_post_plugin_validation(self): @@ -147,7 +148,8 @@ class NeutronManagerTestCase(base.BaseTestCase): expected = {'l3': 'l3_agent_notifier', 'dhcp': 'dhcp_agent_notifier', 'dummy': 'dummy_agent_notifier'} - core_plugin = manager.NeutronManager.get_plugin() + manager.init() + core_plugin = directory.get_plugin() self.assertEqual(expected, core_plugin.agent_notifiers) def test_load_class_for_provider(self): @@ -168,8 +170,8 @@ class NeutronManagerTestCase(base.BaseTestCase): self.path_prefix = path_prefix x_plugin, y_plugin = pclass('xpa'), pclass('ypa') - nm.service_plugins['x'], nm.service_plugins['y'] = x_plugin, y_plugin - + directory.add_plugin('x', x_plugin) + directory.add_plugin('y', y_plugin) self.assertEqual(weakref.proxy(x_plugin), nm.get_service_plugin_by_path_prefix('xpa')) self.assertEqual(weakref.proxy(y_plugin), diff --git a/neutron/tests/unit/test_policy.py b/neutron/tests/unit/test_policy.py index 59b21cccae4..d4a837a41a6 100644 --- a/neutron/tests/unit/test_policy.py +++ b/neutron/tests/unit/test_policy.py @@ -18,6 +18,7 @@ import mock from neutron_lib import constants from neutron_lib import exceptions +from neutron_lib.plugins import directory from oslo_db import exception as db_exc from oslo_policy import fixture as op_fixture from oslo_policy import policy as oslo_policy @@ -28,7 +29,6 @@ import neutron from neutron.api.v2 import attributes from neutron.common import constants as n_const from neutron import context -from neutron import manager from neutron import policy from neutron.tests import base @@ -220,10 +220,7 @@ class NeutronPolicyTestCase(base.BaseTestCase): self.context = context.Context('fake', 'fake', roles=['user']) plugin_klass = importutils.import_class( "neutron.db.db_base_plugin_v2.NeutronDbPluginV2") - self.manager_patcher = mock.patch('neutron.manager.NeutronManager') - fake_manager = self.manager_patcher.start() - fake_manager_instance = fake_manager.return_value - fake_manager_instance.plugin = plugin_klass() + directory.add_plugin(constants.CORE, plugin_klass()) def _set_rules(self, **kwargs): rules_dict = { @@ -515,7 +512,7 @@ class NeutronPolicyTestCase(base.BaseTestCase): return {'tenant_id': 'fake'} action = "create_port:mac" - with mock.patch.object(manager.NeutronManager.get_instance().plugin, + with mock.patch.object(directory.get_plugin(), 'get_network', new=fakegetnetwork): target = {'network_id': 'whatever'} result = policy.enforce(self.context, action, target) @@ -530,7 +527,7 @@ class NeutronPolicyTestCase(base.BaseTestCase): # so long that we verify that, if *f* blows up, the behavior of the # policy engine to propagate the exception is preserved action = "create_port:mac" - with mock.patch.object(manager.NeutronManager.get_instance().plugin, + with mock.patch.object(directory.get_plugin(), 'get_network', new=fakegetnetwork): target = {'network_id': 'whatever'} self.assertRaises(NotImplementedError, @@ -542,7 +539,7 @@ class NeutronPolicyTestCase(base.BaseTestCase): def test_retryrequest_on_notfound(self): failure = exceptions.NetworkNotFound(net_id='whatever') action = "create_port:mac" - with mock.patch.object(manager.NeutronManager.get_instance().plugin, + with mock.patch.object(directory.get_plugin(), 'get_network', side_effect=failure): target = {'network_id': 'whatever'} try: @@ -560,7 +557,7 @@ class NeutronPolicyTestCase(base.BaseTestCase): admin_or_network_owner="role:admin or " "tenant_id:%(network_tenant_id)s") action = "create_port:mac" - with mock.patch.object(manager.NeutronManager.get_instance().plugin, + with mock.patch.object(directory.get_plugin(), 'get_network', new=fakegetnetwork): target = {'network_id': 'whatever'} result = policy.enforce(self.context, action, target)