use l3 api def from neutron-lib

Commit I81748aa0e48b1275df3e1ea41b1d36a117d0097d added the l3 extension
API definition to neutron-lib and commit
I2324a3a02789c798248cab41c278a2d9981d24be rehomed the l3 exceptions,
while Ifd79eb1a92853e49bd4ef028e7a7bd89811c6957 shims the l3
exceptions.

This patch consumes the l3 api def by:
- Removing the code from neutron that's now in lib.
- Using lib's version of the code where applicable.
- Tidying up the related unit tests as now that the l3 api def from lib
is used the necessary fixture is already setup in the parent chain when
setting up the unit test class.

NeutronLibImpact

Change-Id: If2e66e06b83e15ee2851ea2bc3b64ad366e675dd
This commit is contained in:
Boden R 2017-10-26 09:18:20 -06:00
parent 3249bd193e
commit 54444407f4
28 changed files with 111 additions and 276 deletions

View File

@ -17,6 +17,7 @@ from neutron_lib.api.definitions import portbindings
from neutron_lib import constants from neutron_lib import constants
from neutron_lib import context as neutron_context from neutron_lib import context as neutron_context
from neutron_lib import exceptions from neutron_lib import exceptions
from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.plugins import constants as plugin_constants from neutron_lib.plugins import constants as plugin_constants
from neutron_lib.plugins import directory from neutron_lib.plugins import directory
from oslo_config import cfg from oslo_config import cfg
@ -26,7 +27,6 @@ import oslo_messaging
from neutron.common import constants as n_const from neutron.common import constants as n_const
from neutron.common import utils from neutron.common import utils
from neutron.db import api as db_api from neutron.db import api as db_api
from neutron.extensions import l3
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -254,7 +254,7 @@ class L3RpcCallback(object):
self.l3plugin.update_floatingip_status(context, self.l3plugin.update_floatingip_status(context,
floatingip_id, floatingip_id,
status) status)
except l3.FloatingIPNotFound: except l3_exc.FloatingIPNotFound:
LOG.debug("Floating IP: %s no longer present.", LOG.debug("Floating IP: %s no longer present.",
floatingip_id) floatingip_id)
# Find all floating IPs known to have been the given router # Find all floating IPs known to have been the given router

View File

@ -12,6 +12,7 @@
# under the License. # under the License.
from neutron_lib.api.definitions import availability_zone as az_def from neutron_lib.api.definitions import availability_zone as az_def
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.callbacks import events from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources from neutron_lib.callbacks import resources
@ -21,7 +22,6 @@ from neutron_lib.plugins import directory
from neutron.common import utils from neutron.common import utils
from neutron.db import _resource_extend as resource_extend from neutron.db import _resource_extend as resource_extend
from neutron.db import l3_attrs_db from neutron.db import l3_attrs_db
from neutron.extensions import l3
@resource_extend.has_resource_extenders @resource_extend.has_resource_extenders
@ -30,7 +30,7 @@ class RouterAvailabilityZoneMixin(l3_attrs_db.ExtraAttributesMixin):
"""Mixin class to enable router's availability zone attributes.""" """Mixin class to enable router's availability zone attributes."""
@staticmethod @staticmethod
@resource_extend.extends([l3.ROUTERS]) @resource_extend.extends([l3_apidef.ROUTERS])
def _add_az_to_response(router_res, router_db): def _add_az_to_response(router_res, router_db):
l3_plugin = directory.get_plugin(constants.L3) l3_plugin = directory.get_plugin(constants.L3)
if not utils.is_extension_supported(l3_plugin, if not utils.is_extension_supported(l3_plugin,

View File

@ -27,6 +27,7 @@ from neutron_lib.callbacks import resources
from neutron_lib import constants from neutron_lib import constants
from neutron_lib import context as ctx from neutron_lib import context as ctx
from neutron_lib import exceptions as exc from neutron_lib import exceptions as exc
from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.plugins import constants as plugin_constants from neutron_lib.plugins import constants as plugin_constants
from neutron_lib.plugins import directory from neutron_lib.plugins import directory
from oslo_config import cfg from oslo_config import cfg
@ -53,7 +54,6 @@ from neutron.db import models_v2
from neutron.db import rbac_db_mixin as rbac_mixin from neutron.db import rbac_db_mixin as rbac_mixin
from neutron.db import rbac_db_models as rbac_db from neutron.db import rbac_db_models as rbac_db
from neutron.db import standardattrdescription_db as stattr_db from neutron.db import standardattrdescription_db as stattr_db
from neutron.extensions import l3
from neutron import ipam from neutron import ipam
from neutron.ipam import exceptions as ipam_exc from neutron.ipam import exceptions as ipam_exc
from neutron.ipam import subnet_alloc from neutron.ipam import subnet_alloc
@ -651,7 +651,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
for id in router_ids: for id in router_ids:
try: try:
self._update_router_gw_port(context, id, network, subnet) self._update_router_gw_port(context, id, network, subnet)
except l3.RouterNotFound: except l3_exc.RouterNotFound:
LOG.debug("Router %(id)s was concurrently deleted while " LOG.debug("Router %(id)s was concurrently deleted while "
"updating GW port for subnet %(s)s", "updating GW port for subnet %(s)s",
{'id': id, 's': subnet}) {'id': id, 's': subnet})
@ -1422,7 +1422,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
try: try:
ctx_admin = context.elevated() ctx_admin = context.elevated()
router = self.get_router(ctx_admin, device_id) router = self.get_router(ctx_admin, device_id)
except l3.RouterNotFound: except l3_exc.RouterNotFound:
return return
else: else:
l3plugin = directory.get_plugin(plugin_constants.L3) l3plugin = directory.get_plugin(plugin_constants.L3)
@ -1431,7 +1431,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
ctx_admin = context.elevated() ctx_admin = context.elevated()
router = l3plugin.get_router(ctx_admin, router = l3plugin.get_router(ctx_admin,
device_id) device_id)
except l3.RouterNotFound: except l3_exc.RouterNotFound:
return return
else: else:
# raise as extension doesn't support L3 anyways. # raise as extension doesn't support L3 anyways.

View File

@ -14,6 +14,7 @@
# under the License. # under the License.
from neutron_lib.api.definitions import dns as dns_apidef from neutron_lib.api.definitions import dns as dns_apidef
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.api import validators from neutron_lib.api import validators
from neutron_lib import exceptions as n_exc from neutron_lib import exceptions as n_exc
from neutron_lib.exceptions import dns as dns_exc from neutron_lib.exceptions import dns as dns_exc
@ -23,7 +24,6 @@ from oslo_log import log as logging
from neutron._i18n import _ from neutron._i18n import _
from neutron.common import utils from neutron.common import utils
from neutron.db import _resource_extend as resource_extend from neutron.db import _resource_extend as resource_extend
from neutron.extensions import l3
from neutron.objects import floatingip as fip_obj from neutron.objects import floatingip as fip_obj
from neutron.objects import network from neutron.objects import network
from neutron.objects import ports as port_obj from neutron.objects import ports as port_obj
@ -66,7 +66,7 @@ class DNSDbMixin(object):
driver=cfg.CONF.external_dns_driver) driver=cfg.CONF.external_dns_driver)
@staticmethod @staticmethod
@resource_extend.extends([l3.FLOATINGIPS]) @resource_extend.extends([l3_apidef.FLOATINGIPS])
def _extend_floatingip_dict_dns(floatingip_res, floatingip_db): def _extend_floatingip_dict_dns(floatingip_res, floatingip_db):
floatingip_res['dns_domain'] = '' floatingip_res['dns_domain'] = ''
floatingip_res['dns_name'] = '' floatingip_res['dns_name'] = ''

View File

@ -14,6 +14,7 @@
# under the License. # under the License.
import netaddr import netaddr
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.exceptions import extraroute as xroute_exc from neutron_lib.exceptions import extraroute as xroute_exc
from neutron_lib.utils import helpers from neutron_lib.utils import helpers
from oslo_config import cfg from oslo_config import cfg
@ -24,7 +25,6 @@ from neutron.common import utils
from neutron.conf.db import extraroute_db from neutron.conf.db import extraroute_db
from neutron.db import _resource_extend as resource_extend from neutron.db import _resource_extend as resource_extend
from neutron.db import l3_db from neutron.db import l3_db
from neutron.extensions import l3
from neutron.objects import router as l3_obj from neutron.objects import router as l3_obj
@ -38,7 +38,7 @@ class ExtraRoute_dbonly_mixin(l3_db.L3_NAT_dbonly_mixin):
"""Mixin class to support extra route configuration on router.""" """Mixin class to support extra route configuration on router."""
@staticmethod @staticmethod
@resource_extend.extends([l3.ROUTERS]) @resource_extend.extends([l3_apidef.ROUTERS])
def _extend_router_dict_extraroute(router_res, router_db): def _extend_router_dict_extraroute(router_res, router_db):
router_res['routes'] = (ExtraRoute_dbonly_mixin. router_res['routes'] = (ExtraRoute_dbonly_mixin.
_make_extra_route_list( _make_extra_route_list(

View File

@ -12,13 +12,13 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.api.validators import availability_zone as az_validator from neutron_lib.api.validators import availability_zone as az_validator
from oslo_config import cfg from oslo_config import cfg
from neutron._i18n import _ from neutron._i18n import _
from neutron.db import _resource_extend as resource_extend from neutron.db import _resource_extend as resource_extend
from neutron.db.models import l3_attrs from neutron.db.models import l3_attrs
from neutron.extensions import l3
def get_attr_info(): def get_attr_info():
@ -38,7 +38,7 @@ class ExtraAttributesMixin(object):
"""Mixin class to enable router's extra attributes.""" """Mixin class to enable router's extra attributes."""
@staticmethod @staticmethod
@resource_extend.extends([l3.ROUTERS]) @resource_extend.extends([l3_apidef.ROUTERS])
def _extend_extra_router_dict(router_res, router_db): def _extend_extra_router_dict(router_res, router_db):
extra_attrs = router_db['extra_attributes'] or {} extra_attrs = router_db['extra_attributes'] or {}
for name, info in get_attr_info().items(): for name, info in get_attr_info().items():

View File

@ -17,6 +17,7 @@ import random
import netaddr import netaddr
from neutron_lib.api.definitions import external_net as extnet_apidef from neutron_lib.api.definitions import external_net as extnet_apidef
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.api import validators from neutron_lib.api import validators
from neutron_lib.callbacks import events from neutron_lib.callbacks import events
from neutron_lib.callbacks import exceptions from neutron_lib.callbacks import exceptions
@ -25,6 +26,7 @@ from neutron_lib.callbacks import resources
from neutron_lib import constants from neutron_lib import constants
from neutron_lib import context as n_ctx from neutron_lib import context as n_ctx
from neutron_lib import exceptions as n_exc from neutron_lib import exceptions as n_exc
from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.plugins import constants as plugin_constants from neutron_lib.plugins import constants as plugin_constants
from neutron_lib.plugins import directory from neutron_lib.plugins import directory
from neutron_lib.services import base as base_services from neutron_lib.services import base as base_services
@ -61,7 +63,7 @@ DEVICE_OWNER_HA_REPLICATED_INT = constants.DEVICE_OWNER_HA_REPLICATED_INT
DEVICE_OWNER_ROUTER_INTF = constants.DEVICE_OWNER_ROUTER_INTF DEVICE_OWNER_ROUTER_INTF = constants.DEVICE_OWNER_ROUTER_INTF
DEVICE_OWNER_ROUTER_GW = constants.DEVICE_OWNER_ROUTER_GW DEVICE_OWNER_ROUTER_GW = constants.DEVICE_OWNER_ROUTER_GW
DEVICE_OWNER_FLOATINGIP = constants.DEVICE_OWNER_FLOATINGIP DEVICE_OWNER_FLOATINGIP = constants.DEVICE_OWNER_FLOATINGIP
EXTERNAL_GW_INFO = l3.EXTERNAL_GW_INFO EXTERNAL_GW_INFO = l3_apidef.EXTERNAL_GW_INFO
# Maps API field to DB column # Maps API field to DB column
# API parameter name and Database column names may differ. # API parameter name and Database column names may differ.
@ -182,7 +184,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
router = model_query.get_by_id( router = model_query.get_by_id(
context, l3_models.Router, router_id) context, l3_models.Router, router_id)
except exc.NoResultFound: except exc.NoResultFound:
raise l3.RouterNotFound(router_id=router_id) raise l3_exc.RouterNotFound(router_id=router_id)
return router return router
def _make_router_dict(self, router, fields=None, process_extensions=True): def _make_router_dict(self, router, fields=None, process_extensions=True):
@ -203,7 +205,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
# class inheriting from CommonDbMixin, which is true for all existing # class inheriting from CommonDbMixin, which is true for all existing
# plugins. # plugins.
if process_extensions: if process_extensions:
resource_extend.apply_funcs(l3.ROUTERS, res, router) resource_extend.apply_funcs(l3_apidef.ROUTERS, res, router)
return db_utils.resource_fields(res, fields) return db_utils.resource_fields(res, fields)
def _create_router_db(self, context, router, tenant_id): def _create_router_db(self, context, router, tenant_id):
@ -427,7 +429,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
old_network_id = router.gw_port['network_id'] old_network_id = router.gw_port['network_id']
if self.router_gw_port_has_floating_ips(admin_ctx, router_id): if self.router_gw_port_has_floating_ips(admin_ctx, router_id):
raise l3.RouterExternalGatewayInUseByFloatingIp( raise l3_exc.RouterExternalGatewayInUseByFloatingIp(
router_id=router_id, net_id=router.gw_port['network_id']) router_id=router_id, net_id=router.gw_port['network_id'])
gw_ips = [x['ip_address'] for x in router.gw_port['fixed_ips']] gw_ips = [x['ip_address'] for x in router.gw_port['fixed_ips']]
gw_port_id = router.gw_port['id'] gw_port_id = router.gw_port['id']
@ -459,7 +461,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
# NOTE(armax): preserve old check's behavior # NOTE(armax): preserve old check's behavior
if len(e.errors) == 1: if len(e.errors) == 1:
raise e.errors[0].error raise e.errors[0].error
raise l3.RouterInUse(router_id=router.id, reason=e) raise l3_exc.RouterInUse(router_id=router.id, reason=e)
def _create_gw_port(self, context, router_id, router, new_network_id, def _create_gw_port(self, context, router_id, router, new_network_id,
ext_ips): ext_ips):
@ -544,7 +546,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
device_owner = self._get_device_owner(context, router) device_owner = self._get_device_owner(context, router)
if any(rp.port_type == device_owner if any(rp.port_type == device_owner
for rp in router.attached_ports): for rp in router.attached_ports):
raise l3.RouterInUse(router_id=router_id) raise l3_exc.RouterInUse(router_id=router_id)
return router return router
@db_api.retry_if_session_inactive() @db_api.retry_if_session_inactive()
@ -750,7 +752,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
# raise the underlying exception # raise the underlying exception
reason = (_('cannot perform router interface attachment ' reason = (_('cannot perform router interface attachment '
'due to %(reason)s') % {'reason': e}) 'due to %(reason)s') % {'reason': e})
raise l3.RouterInterfaceAttachmentConflict(reason=reason) raise l3_exc.RouterInterfaceAttachmentConflict(reason=reason)
def _add_interface_by_port(self, context, router, port_id, owner): def _add_interface_by_port(self, context, router, port_id, owner):
# Update owner before actual process in order to avoid the # Update owner before actual process in order to avoid the
@ -922,11 +924,11 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
# NOTE(armax): preserve old check's behavior # NOTE(armax): preserve old check's behavior
if len(e.errors) == 1: if len(e.errors) == 1:
raise e.errors[0].error raise e.errors[0].error
raise l3.RouterInUse(router_id=router_id, reason=e) raise l3_exc.RouterInUse(router_id=router_id, reason=e)
fip_objs = l3_obj.FloatingIP.get_objects(context, router_id=router_id) fip_objs = l3_obj.FloatingIP.get_objects(context, router_id=router_id)
for fip_obj in fip_objs: for fip_obj in fip_objs:
if fip_obj.fixed_ip_address in subnet_cidr: if fip_obj.fixed_ip_address in subnet_cidr:
raise l3.RouterInterfaceInUseByFloatingIP( raise l3_exc.RouterInterfaceInUseByFloatingIP(
router_id=router_id, subnet_id=subnet_id) router_id=router_id, subnet_id=subnet_id)
def _remove_interface_by_port(self, context, router_id, def _remove_interface_by_port(self, context, router_id,
@ -941,11 +943,11 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
try: try:
port = self._core_plugin.get_port(context, obj.port_id) port = self._core_plugin.get_port(context, obj.port_id)
except n_exc.PortNotFound: except n_exc.PortNotFound:
raise l3.RouterInterfaceNotFound(router_id=router_id, raise l3_exc.RouterInterfaceNotFound(
port_id=port_id) router_id=router_id, port_id=port_id)
else: else:
raise l3.RouterInterfaceNotFound(router_id=router_id, raise l3_exc.RouterInterfaceNotFound(
port_id=port_id) router_id=router_id, port_id=port_id)
port_subnet_ids = [fixed_ip['subnet_id'] port_subnet_ids = [fixed_ip['subnet_id']
for fixed_ip in port['fixed_ips']] for fixed_ip in port['fixed_ips']]
if subnet_id and subnet_id not in port_subnet_ids: if subnet_id and subnet_id not in port_subnet_ids:
@ -991,8 +993,8 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
return (p, [subnet]) return (p, [subnet])
except exc.NoResultFound: except exc.NoResultFound:
pass pass
raise l3.RouterInterfaceNotFoundForSubnet(router_id=router_id, raise l3_exc.RouterInterfaceNotFoundForSubnet(
subnet_id=subnet_id) router_id=router_id, subnet_id=subnet_id)
@db_api.retry_if_session_inactive() @db_api.retry_if_session_inactive()
def remove_router_interface(self, context, router_id, interface_info): def remove_router_interface(self, context, router_id, interface_info):
@ -1041,7 +1043,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
def _get_floatingip(self, context, id): def _get_floatingip(self, context, id):
floatingip = l3_obj.FloatingIP.get_object(context, id=id) floatingip = l3_obj.FloatingIP.get_object(context, id=id)
if not floatingip: if not floatingip:
raise l3.FloatingIPNotFound(floatingip_id=id) raise l3_exc.FloatingIPNotFound(floatingip_id=id)
return floatingip return floatingip
def _make_floatingip_dict(self, floatingip, fields=None, def _make_floatingip_dict(self, floatingip, fields=None,
@ -1064,7 +1066,8 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
# TODO(lujinluo): Change floatingip.db_obj to floatingip once all # TODO(lujinluo): Change floatingip.db_obj to floatingip once all
# codes are migrated to use Floating IP OVO object. # codes are migrated to use Floating IP OVO object.
if process_extensions: if process_extensions:
resource_extend.apply_funcs(l3.FLOATINGIPS, res, floatingip.db_obj) resource_extend.apply_funcs(
l3_apidef.FLOATINGIPS, res, floatingip.db_obj)
return db_utils.resource_fields(res, fields) return db_utils.resource_fields(res, fields)
def _get_router_for_floatingip(self, context, internal_port, def _get_router_for_floatingip(self, context, internal_port,
@ -1116,7 +1119,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
if first_router_id: if first_router_id:
return first_router_id return first_router_id
raise l3.ExternalGatewayForFloatingIPNotFound( raise l3_exc.ExternalGatewayForFloatingIPNotFound(
subnet_id=internal_subnet['id'], subnet_id=internal_subnet['id'],
external_network_id=external_network_id, external_network_id=external_network_id,
port_id=internal_port['id']) port_id=internal_port['id'])
@ -1211,7 +1214,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
if fip_exists: if fip_exists:
floating_ip_address = (str(floatingip_obj.floating_ip_address) floating_ip_address = (str(floatingip_obj.floating_ip_address)
if floatingip_obj.floating_ip_address else None) if floatingip_obj.floating_ip_address else None)
raise l3.FloatingIPPortAlreadyAssociated( raise l3_exc.FloatingIPPortAlreadyAssociated(
port_id=fip['port_id'], port_id=fip['port_id'],
fip_id=floatingip_obj.id, fip_id=floatingip_obj.id,
floating_ip_address=floating_ip_address, floating_ip_address=floating_ip_address,
@ -1355,7 +1358,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
dns_data) dns_data)
# TODO(lujinluo): Change floatingip_db to floatingip_obj once all # TODO(lujinluo): Change floatingip_db to floatingip_obj once all
# codes are migrated to use Floating IP OVO object. # codes are migrated to use Floating IP OVO object.
resource_extend.apply_funcs(l3.FLOATINGIPS, floatingip_dict, resource_extend.apply_funcs(l3_apidef.FLOATINGIPS, floatingip_dict,
floatingip_db) floatingip_db)
return floatingip_dict return floatingip_dict
@ -1398,7 +1401,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
dns_data) dns_data)
# TODO(lujinluo): Change floatingip_db to floatingip_obj once all # TODO(lujinluo): Change floatingip_db to floatingip_obj once all
# codes are migrated to use Floating IP OVO object. # codes are migrated to use Floating IP OVO object.
resource_extend.apply_funcs(l3.FLOATINGIPS, floatingip_dict, resource_extend.apply_funcs(l3_apidef.FLOATINGIPS, floatingip_dict,
floatingip_db) floatingip_db)
return old_floatingip, floatingip_dict return old_floatingip, floatingip_dict
@ -1477,7 +1480,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
try: try:
self.get_router(context.elevated(), router_id) self.get_router(context.elevated(), router_id)
return True return True
except l3.RouterNotFound: except l3_exc.RouterNotFound:
return False return False
def prevent_l3_port_deletion(self, context, port_id): def prevent_l3_port_deletion(self, context, port_id):

View File

@ -14,6 +14,7 @@
import collections import collections
import netaddr import netaddr
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.api.definitions import portbindings from neutron_lib.api.definitions import portbindings
from neutron_lib.api import validators from neutron_lib.api import validators
from neutron_lib.callbacks import events from neutron_lib.callbacks import events
@ -22,6 +23,7 @@ from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources from neutron_lib.callbacks import resources
from neutron_lib import constants as const from neutron_lib import constants as const
from neutron_lib import exceptions as n_exc from neutron_lib import exceptions as n_exc
from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.plugins import constants as plugin_constants from neutron_lib.plugins import constants as plugin_constants
from neutron_lib.plugins import directory from neutron_lib.plugins import directory
from oslo_config import cfg from oslo_config import cfg
@ -39,7 +41,6 @@ from neutron.db import l3_attrs_db
from neutron.db import l3_db from neutron.db import l3_db
from neutron.db.models import allowed_address_pair as aap_models from neutron.db.models import allowed_address_pair as aap_models
from neutron.db import models_v2 from neutron.db import models_v2
from neutron.extensions import l3
from neutron.ipam import utils as ipam_utils from neutron.ipam import utils as ipam_utils
from neutron.objects import agent as ag_obj from neutron.objects import agent as ag_obj
from neutron.objects import base as base_obj from neutron.objects import base as base_obj
@ -101,7 +102,7 @@ class DVRResourceOperationHandler(object):
# NOTE(armax): preserve old check's behavior # NOTE(armax): preserve old check's behavior
if len(e.errors) == 1: if len(e.errors) == 1:
raise e.errors[0].error raise e.errors[0].error
raise l3.RouterInUse(router_id=router_db['id'], reason=e) raise l3_exc.RouterInUse(router_id=router_db['id'], reason=e)
return True return True
@registry.receives(resources.ROUTER, [events.PRECOMMIT_UPDATE]) @registry.receives(resources.ROUTER, [events.PRECOMMIT_UPDATE])
@ -147,7 +148,8 @@ class DVRResourceOperationHandler(object):
context, router_id, router, context, router_id, router,
request_attrs, router_db, request_attrs, router_db,
**kwargs): **kwargs):
if router.get(l3.EXTERNAL_GW_INFO) and not router['distributed']: if (router.get(l3_apidef.EXTERNAL_GW_INFO) and
not router['distributed']):
old_router = kwargs['old_router'] old_router = kwargs['old_router']
if old_router and old_router['distributed']: if old_router and old_router['distributed']:
self.delete_csnat_router_interface_ports( self.delete_csnat_router_interface_ports(
@ -159,7 +161,8 @@ class DVRResourceOperationHandler(object):
context, router_id, router, context, router_id, router,
request_attrs, router_db, request_attrs, router_db,
**kwargs): **kwargs):
if not router.get(l3.EXTERNAL_GW_INFO) or not router['distributed']: if (not router.get(l3_apidef.EXTERNAL_GW_INFO) or
not router['distributed']):
# we don't care if it's not distributed or not attached to an # we don't care if it's not distributed or not attached to an
# external network # external network
return return
@ -168,7 +171,7 @@ class DVRResourceOperationHandler(object):
# gateway attachment # gateway attachment
old_router = kwargs['old_router'] old_router = kwargs['old_router']
do_create = (not old_router['distributed'] or do_create = (not old_router['distributed'] or
not old_router.get(l3.EXTERNAL_GW_INFO)) not old_router.get(l3_apidef.EXTERNAL_GW_INFO))
if not do_create: if not do_create:
return return
if not self._create_snat_intf_ports_if_not_exists( if not self._create_snat_intf_ports_if_not_exists(
@ -1010,7 +1013,7 @@ class L3_NAT_with_dvr_db_mixin(_DVRAgentInterfaceMixin,
try: try:
# using admin context as router may belong to admin tenant # using admin context as router may belong to admin tenant
router = self._get_router(context.elevated(), router_id) router = self._get_router(context.elevated(), router_id)
except l3.RouterNotFound: except l3_exc.RouterNotFound:
LOG.warning("Router %s was not found. " LOG.warning("Router %s was not found. "
"Skipping agent notification.", "Skipping agent notification.",
router_id) router_id)

View File

@ -12,11 +12,11 @@
# under the License. # under the License.
# #
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.services.qos import constants as qos_consts from neutron_lib.services.qos import constants as qos_consts
from neutron.common import exceptions as n_exc from neutron.common import exceptions as n_exc
from neutron.db import _resource_extend as resource_extend from neutron.db import _resource_extend as resource_extend
from neutron.extensions import l3
from neutron.objects.db import api as obj_db_api from neutron.objects.db import api as obj_db_api
from neutron.objects.qos import policy as policy_object from neutron.objects.qos import policy as policy_object
@ -26,7 +26,7 @@ class FloatingQoSDbMixin(object):
"""Mixin class to enable floating IP's QoS extra attributes.""" """Mixin class to enable floating IP's QoS extra attributes."""
@staticmethod @staticmethod
@resource_extend.extends([l3.FLOATINGIPS]) @resource_extend.extends([l3_apidef.FLOATINGIPS])
def _extend_extra_fip_dict(fip_res, fip_db): def _extend_extra_fip_dict(fip_res, fip_db):
if fip_db.get('qos_policy_binding'): if fip_db.get('qos_policy_binding'):
fip_res[qos_consts.QOS_POLICY_ID] = ( fip_res[qos_consts.QOS_POLICY_ID] = (

View File

@ -13,6 +13,7 @@
# under the License. # under the License.
# #
from neutron_lib.api.definitions import l3 as l3_apidef
from oslo_config import cfg from oslo_config import cfg
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy import sql from sqlalchemy import sql
@ -21,14 +22,11 @@ from neutron.conf.db import l3_gwmode_db
from neutron.db import _resource_extend as resource_extend from neutron.db import _resource_extend as resource_extend
from neutron.db import l3_db from neutron.db import l3_db
from neutron.db.models import l3 as l3_models from neutron.db.models import l3 as l3_models
from neutron.extensions import l3
l3_gwmode_db.register_db_l3_gwmode_opts() l3_gwmode_db.register_db_l3_gwmode_opts()
EXTERNAL_GW_INFO = l3.EXTERNAL_GW_INFO
# Modify the Router Data Model adding the enable_snat attribute # Modify the Router Data Model adding the enable_snat attribute
setattr(l3_models.Router, 'enable_snat', setattr(l3_models.Router, 'enable_snat',
sa.Column(sa.Boolean, default=True, server_default=sql.true(), sa.Column(sa.Boolean, default=True, server_default=sql.true(),
@ -40,11 +38,11 @@ class L3_NAT_dbonly_mixin(l3_db.L3_NAT_dbonly_mixin):
"""Mixin class to add configurable gateway modes.""" """Mixin class to add configurable gateway modes."""
@staticmethod @staticmethod
@resource_extend.extends([l3.ROUTERS]) @resource_extend.extends([l3_apidef.ROUTERS])
def _extend_router_dict_gw_mode(router_res, router_db): def _extend_router_dict_gw_mode(router_res, router_db):
if router_db.gw_port_id: if router_db.gw_port_id:
nw_id = router_db.gw_port['network_id'] nw_id = router_db.gw_port['network_id']
router_res[EXTERNAL_GW_INFO] = { router_res[l3_apidef.EXTERNAL_GW_INFO] = {
'network_id': nw_id, 'network_id': nw_id,
'enable_snat': router_db.enable_snat, 'enable_snat': router_db.enable_snat,
'external_fixed_ips': [ 'external_fixed_ips': [
@ -84,7 +82,8 @@ class L3_NAT_dbonly_mixin(l3_db.L3_NAT_dbonly_mixin):
if gw_port_id and gw_ports.get(gw_port_id): if gw_port_id and gw_ports.get(gw_port_id):
rtr['gw_port'] = gw_ports[gw_port_id] rtr['gw_port'] = gw_ports[gw_port_id]
# Add enable_snat key # Add enable_snat key
rtr['enable_snat'] = rtr[EXTERNAL_GW_INFO]['enable_snat'] rtr['enable_snat'] = rtr[
l3_apidef.EXTERNAL_GW_INFO]['enable_snat']
return routers return routers

View File

@ -25,6 +25,7 @@ from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources from neutron_lib.callbacks import resources
from neutron_lib import constants from neutron_lib import constants
from neutron_lib import exceptions as n_exc from neutron_lib import exceptions as n_exc
from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.exceptions import l3_ext_ha_mode as l3ha_exc from neutron_lib.exceptions import l3_ext_ha_mode as l3ha_exc
from neutron_lib.objects import exceptions as obj_base from neutron_lib.objects import exceptions as obj_base
from oslo_config import cfg from oslo_config import cfg
@ -47,7 +48,6 @@ from neutron.db.availability_zone import router as router_az_db
from neutron.db import l3_dvr_db from neutron.db import l3_dvr_db
from neutron.db.l3_dvr_db import is_distributed_router from neutron.db.l3_dvr_db import is_distributed_router
from neutron.db.models import l3ha as l3ha_model from neutron.db.models import l3ha as l3ha_model
from neutron.extensions import l3
from neutron.objects import base from neutron.objects import base
from neutron.objects import l3_hamode from neutron.objects import l3_hamode
from neutron.objects import router as l3_obj from neutron.objects import router as l3_obj
@ -258,7 +258,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
'Failed to create HA router agent PortBinding, ' 'Failed to create HA router agent PortBinding, '
'Router %s has already been removed ' 'Router %s has already been removed '
'by concurrent operation', router_id) 'by concurrent operation', router_id)
raise l3.RouterNotFound(router_id=router_id) raise l3_exc.RouterNotFound(router_id=router_id)
def add_ha_port(self, context, router_id, network_id, tenant_id): def add_ha_port(self, context, router_id, network_id, tenant_id):
# NOTE(kevinbenton): we have to block any ongoing transactions because # NOTE(kevinbenton): we have to block any ongoing transactions because

View File

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.db import constants as db_const from neutron_lib.db import constants as db_const
from neutron_lib.db import model_base from neutron_lib.db import model_base
import sqlalchemy as sa import sqlalchemy as sa
@ -18,7 +19,6 @@ from sqlalchemy import orm
from neutron.db.models import l3agent as rb_model from neutron.db.models import l3agent as rb_model
from neutron.db import models_v2 from neutron.db import models_v2
from neutron.db import standard_attr from neutron.db import standard_attr
from neutron.extensions import l3
class RouterPort(model_base.BASEV2): class RouterPort(model_base.BASEV2):
@ -62,8 +62,8 @@ class Router(standard_attr.HasStandardAttributes, model_base.BASEV2,
l3_agents = orm.relationship( l3_agents = orm.relationship(
'Agent', lazy='subquery', viewonly=True, 'Agent', lazy='subquery', viewonly=True,
secondary=rb_model.RouterL3AgentBinding.__table__) secondary=rb_model.RouterL3AgentBinding.__table__)
api_collections = [l3.ROUTERS] api_collections = [l3_apidef.ROUTERS]
collection_resource_map = {l3.ROUTERS: l3.ROUTER} collection_resource_map = {l3_apidef.ROUTERS: l3_apidef.ROUTER}
tag_support = True tag_support = True
@ -104,8 +104,8 @@ class FloatingIP(standard_attr.HasStandardAttributes, model_base.BASEV2,
name=('uniq_floatingips0floatingnetworkid' name=('uniq_floatingips0floatingnetworkid'
'0fixedportid0fixedipaddress')), '0fixedportid0fixedipaddress')),
model_base.BASEV2.__table_args__,) model_base.BASEV2.__table_args__,)
api_collections = [l3.FLOATINGIPS] api_collections = [l3_apidef.FLOATINGIPS]
collection_resource_map = {l3.FLOATINGIPS: l3.FLOATINGIP} collection_resource_map = {l3_apidef.FLOATINGIPS: l3_apidef.FLOATINGIP}
tag_support = True tag_support = True

View File

@ -15,10 +15,8 @@
import abc import abc
from neutron_lib.api import converters from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.api import extensions from neutron_lib.api import extensions
from neutron_lib.db import constants as db_const
from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.plugins import constants from neutron_lib.plugins import constants
import six import six
@ -26,146 +24,22 @@ from neutron.api.v2 import resource_helper
from neutron.conf import quota from neutron.conf import quota
# TODO(boden): remove these shims on l3 api def consumption
RouterNotFound = l3_exc.RouterNotFound
RouterInUse = l3_exc.RouterInUse
RouterInterfaceNotFound = l3_exc.RouterInterfaceNotFound
RouterInterfaceNotFoundForSubnet = l3_exc.RouterInterfaceNotFoundForSubnet
RouterInterfaceInUseByFloatingIP = l3_exc.RouterInterfaceInUseByFloatingIP
FloatingIPNotFound = l3_exc.FloatingIPNotFound
ExternalGatewayForFloatingIPNotFound = (
l3_exc.ExternalGatewayForFloatingIPNotFound)
FloatingIPPortAlreadyAssociated = l3_exc.FloatingIPPortAlreadyAssociated
RouterExternalGatewayInUseByFloatingIp = (
l3_exc.RouterExternalGatewayInUseByFloatingIp)
RouterInterfaceAttachmentConflict = l3_exc.RouterInterfaceAttachmentConflict
ROUTER = 'router'
ROUTERS = 'routers'
FLOATINGIP = 'floatingip'
FLOATINGIPS = '%ss' % FLOATINGIP
EXTERNAL_GW_INFO = 'external_gateway_info'
RESOURCE_ATTRIBUTE_MAP = {
ROUTERS: {
'id': {'allow_post': False, 'allow_put': False,
'validate': {'type:uuid': None},
'is_visible': True,
'primary_key': True},
'name': {'allow_post': True, 'allow_put': True,
'validate': {'type:string': db_const.NAME_FIELD_SIZE},
'is_visible': True, 'default': ''},
'admin_state_up': {'allow_post': True, 'allow_put': True,
'default': True,
'convert_to': converters.convert_to_boolean,
'is_visible': True},
'status': {'allow_post': False, 'allow_put': False,
'is_visible': True},
'tenant_id': {'allow_post': True, 'allow_put': False,
'required_by_policy': True,
'validate': {
'type:string': db_const.PROJECT_ID_FIELD_SIZE},
'is_visible': True},
EXTERNAL_GW_INFO: {'allow_post': True, 'allow_put': True,
'is_visible': True, 'default': None,
'enforce_policy': True,
'validate': {
'type:dict_or_nodata': {
'network_id': {'type:uuid': None,
'required': True},
'external_fixed_ips': {
'convert_list_to':
converters.convert_kvp_list_to_dict,
'type:fixed_ips': None,
'default': None,
'required': False,
}
}
}}
},
FLOATINGIPS: {
'id': {'allow_post': False, 'allow_put': False,
'validate': {'type:uuid': None},
'is_visible': True,
'primary_key': True},
'floating_ip_address': {'allow_post': True, 'allow_put': False,
'validate': {'type:ip_address_or_none': None},
'is_visible': True, 'default': None,
'enforce_policy': True},
'subnet_id': {'allow_post': True, 'allow_put': False,
'validate': {'type:uuid_or_none': None},
'is_visible': False, # Use False for input only attr
'default': None},
'floating_network_id': {'allow_post': True, 'allow_put': False,
'validate': {'type:uuid': None},
'is_visible': True},
'router_id': {'allow_post': False, 'allow_put': False,
'validate': {'type:uuid_or_none': None},
'is_visible': True, 'default': None},
'port_id': {'allow_post': True, 'allow_put': True,
'validate': {'type:uuid_or_none': None},
'is_visible': True, 'default': None,
'required_by_policy': True},
'fixed_ip_address': {'allow_post': True, 'allow_put': True,
'validate': {'type:ip_address_or_none': None},
'is_visible': True, 'default': None},
'tenant_id': {'allow_post': True, 'allow_put': False,
'required_by_policy': True,
'validate': {
'type:string': db_const.PROJECT_ID_FIELD_SIZE},
'is_visible': True},
'status': {'allow_post': False, 'allow_put': False,
'is_visible': True},
},
}
# Register the configuration options # Register the configuration options
quota.register_quota_opts(quota.l3_quota_opts) quota.register_quota_opts(quota.l3_quota_opts)
class L3(extensions.ExtensionDescriptor): class L3(extensions.APIExtensionDescriptor):
api_definition = l3_apidef
@classmethod
def get_name(cls):
return "Neutron L3 Router"
@classmethod
def get_alias(cls):
return "router"
@classmethod
def get_description(cls):
return ("Router abstraction for basic L3 forwarding"
" between L2 Neutron networks and access to external"
" networks via a NAT gateway.")
@classmethod
def get_updated(cls):
return "2012-07-20T10:00:00-00:00"
@classmethod @classmethod
def get_resources(cls): def get_resources(cls):
"""Returns Ext Resources.""" """Returns Ext Resources."""
plural_mappings = resource_helper.build_plural_mappings( plural_mappings = resource_helper.build_plural_mappings(
{}, RESOURCE_ATTRIBUTE_MAP) {}, l3_apidef.RESOURCE_ATTRIBUTE_MAP)
action_map = {'router': {'add_router_interface': 'PUT', return resource_helper.build_resource_info(
'remove_router_interface': 'PUT'}} plural_mappings, l3_apidef.RESOURCE_ATTRIBUTE_MAP,
return resource_helper.build_resource_info(plural_mappings, constants.L3, action_map=l3_apidef.ACTION_MAP,
RESOURCE_ATTRIBUTE_MAP, register_quota=True)
constants.L3,
action_map=action_map,
register_quota=True)
def update_attributes_map(self, attributes):
super(L3, self).update_attributes_map(
attributes, extension_attrs_map=RESOURCE_ATTRIBUTE_MAP)
def get_extended_resources(self, version):
if version == "2.0":
return RESOURCE_ATTRIBUTE_MAP
else:
return {}
@six.add_metaclass(abc.ABCMeta) @six.add_metaclass(abc.ABCMeta)

View File

@ -11,6 +11,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.api.definitions import port as port_def from neutron_lib.api.definitions import port as port_def
from neutron_lib.api.definitions import subnet as subnet_def from neutron_lib.api.definitions import subnet as subnet_def
from neutron_lib.api.definitions import subnetpool as subnetpool_def from neutron_lib.api.definitions import subnetpool as subnetpool_def
@ -20,7 +21,6 @@ from neutron_lib.plugins import directory
from neutron.api import extensions from neutron.api import extensions
from neutron.api.v2 import resource as api_resource from neutron.api.v2 import resource as api_resource
from neutron.extensions import l3
from neutron.extensions import tagging from neutron.extensions import tagging
@ -32,7 +32,7 @@ TAG_SUPPORTED_RESOURCES = {
subnet_def.COLLECTION_NAME: subnet_def.RESOURCE_NAME, subnet_def.COLLECTION_NAME: subnet_def.RESOURCE_NAME,
port_def.COLLECTION_NAME: port_def.RESOURCE_NAME, port_def.COLLECTION_NAME: port_def.RESOURCE_NAME,
subnetpool_def.COLLECTION_NAME: subnetpool_def.RESOURCE_NAME, subnetpool_def.COLLECTION_NAME: subnetpool_def.RESOURCE_NAME,
l3.ROUTERS: l3.ROUTER, l3_apidef.ROUTERS: l3_apidef.ROUTER,
} }

View File

@ -21,6 +21,7 @@ import random
from neutron_lib.api.definitions import availability_zone as az_def from neutron_lib.api.definitions import availability_zone as az_def
from neutron_lib import constants as lib_const from neutron_lib import constants as lib_const
from neutron_lib.exceptions import l3 as l3_exc
from oslo_config import cfg from oslo_config import cfg
from oslo_db import exception as db_exc from oslo_db import exception as db_exc
from oslo_log import log as logging from oslo_log import log as logging
@ -31,7 +32,6 @@ from neutron.common import utils
from neutron.conf.db import l3_hamode_db from neutron.conf.db import l3_hamode_db
from neutron.db import api as db_api from neutron.db import api as db_api
from neutron.db.models import l3agent as rb_model from neutron.db.models import l3agent as rb_model
from neutron.extensions import l3
from neutron.objects import l3agent as rb_obj from neutron.objects import l3agent as rb_obj
@ -307,7 +307,7 @@ class L3Scheduler(object):
# and RouterPort tables # and RouterPort tables
plugin._core_plugin.delete_port(context, port_id, plugin._core_plugin.delete_port(context, port_id,
l3_port_check=False) l3_port_check=False)
except l3.RouterNotFound: except l3_exc.RouterNotFound:
LOG.debug('Router %s has already been removed ' LOG.debug('Router %s has already been removed '
'by concurrent operation', router_id) 'by concurrent operation', router_id)
# we try to clear the HA network here in case the port we created # we try to clear the HA network here in case the port we created

View File

@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.api.definitions import network as net_def from neutron_lib.api.definitions import network as net_def
from neutron_lib.callbacks import events from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry from neutron_lib.callbacks import registry
@ -30,7 +31,6 @@ from neutron.db import _resource_extend as resource_extend
from neutron.db import _utils as db_utils from neutron.db import _utils as db_utils
from neutron.db import api as db_api from neutron.db import api as db_api
from neutron.db import common_db_mixin from neutron.db import common_db_mixin
from neutron.extensions import l3
from neutron.objects import auto_allocate as auto_allocate_obj from neutron.objects import auto_allocate as auto_allocate_obj
from neutron.objects import base as base_obj from neutron.objects import base as base_obj
from neutron.objects import network as net_obj from neutron.objects import network as net_obj
@ -297,7 +297,8 @@ class AutoAllocatedTopologyMixin(common_db_mixin.CommonDbMixin):
"""Uplink tenant subnet(s) to external network.""" """Uplink tenant subnet(s) to external network."""
router_args = { router_args = {
'name': 'auto_allocated_router', 'name': 'auto_allocated_router',
l3.EXTERNAL_GW_INFO: {'network_id': default_external_network}, l3_apidef.EXTERNAL_GW_INFO: {
'network_id': default_external_network},
'tenant_id': tenant_id, 'tenant_id': tenant_id,
'admin_state_up': True 'admin_state_up': True
} }

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib import constants as n_const from neutron_lib import constants as n_const
from neutron_lib.plugins import constants as plugin_constants from neutron_lib.plugins import constants as plugin_constants
from neutron_lib.services import base as service_base from neutron_lib.services import base as service_base
@ -36,7 +37,6 @@ from neutron.db import l3_gwmode_db
from neutron.db import l3_hamode_db from neutron.db import l3_hamode_db
from neutron.db import l3_hascheduler_db from neutron.db import l3_hascheduler_db
from neutron.db.models import l3 as l3_models from neutron.db.models import l3 as l3_models
from neutron.extensions import l3
from neutron.quota import resource_registry from neutron.quota import resource_registry
from neutron import service from neutron import service
from neutron.services.l3_router.service_providers import driver_controller from neutron.services.l3_router.service_providers import driver_controller
@ -153,6 +153,6 @@ class L3RouterPlugin(service_base.ServicePluginBase,
initial_status=n_const.FLOATINGIP_STATUS_DOWN) initial_status=n_const.FLOATINGIP_STATUS_DOWN)
@staticmethod @staticmethod
@resource_extend.extends([l3.ROUTERS]) @resource_extend.extends([l3_apidef.ROUTERS])
def add_flavor_id(router_res, router_db): def add_flavor_id(router_res, router_db):
router_res['flavor_id'] = router_db['flavor_id'] router_res['flavor_id'] = router_db['flavor_id']

View File

@ -14,11 +14,11 @@
import mock import mock
from neutron_lib.api.definitions import external_net as extnet_apidef from neutron_lib.api.definitions import external_net as extnet_apidef
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.api.definitions import portbindings from neutron_lib.api.definitions import portbindings
from neutron_lib import constants from neutron_lib import constants
from neutron.common import topics from neutron.common import topics
from neutron.extensions import l3
from neutron.tests.common import helpers from neutron.tests.common import helpers
from neutron.tests.functional.services.l3_router import \ from neutron.tests.functional.services.l3_router import \
test_l3_dvr_router_plugin test_l3_dvr_router_plugin
@ -235,7 +235,7 @@ class L3DvrHATestCase(test_l3_dvr_router_plugin.L3DvrTestCase):
gw_info = {'network_id': ext_net['network']['id']} gw_info = {'network_id': ext_net['network']['id']}
self.l3_plugin.update_router( self.l3_plugin.update_router(
self.context, router['id'], self.context, router['id'],
{'router': {l3.EXTERNAL_GW_INFO: gw_info}}) {'router': {l3_apidef.EXTERNAL_GW_INFO: gw_info}})
self.l3_plugin.add_router_interface( self.l3_plugin.add_router_interface(
self.context, router['id'], self.context, router['id'],
{'subnet_id': subnet['subnet']['id']}) {'subnet_id': subnet['subnet']['id']})
@ -266,7 +266,7 @@ class L3DvrHATestCase(test_l3_dvr_router_plugin.L3DvrTestCase):
gw_info = {'network_id': ext_net['network']['id']} gw_info = {'network_id': ext_net['network']['id']}
self.l3_plugin.update_router( self.l3_plugin.update_router(
self.context, router['id'], self.context, router['id'],
{'router': {l3.EXTERNAL_GW_INFO: gw_info}}) {'router': {l3_apidef.EXTERNAL_GW_INFO: gw_info}})
self.l3_plugin.add_router_interface( self.l3_plugin.add_router_interface(
self.context, router['id'], self.context, router['id'],
{'subnet_id': subnet['subnet']['id']}) {'subnet_id': subnet['subnet']['id']})
@ -312,12 +312,12 @@ class L3DvrHATestCase(test_l3_dvr_router_plugin.L3DvrTestCase):
gw_info = {'network_id': ext_net['network']['id']} gw_info = {'network_id': ext_net['network']['id']}
self.l3_plugin.update_router( self.l3_plugin.update_router(
self.context, router['id'], self.context, router['id'],
{'router': {l3.EXTERNAL_GW_INFO: gw_info}}) {'router': {l3_apidef.EXTERNAL_GW_INFO: gw_info}})
def _clear_external_gateway(self, router): def _clear_external_gateway(self, router):
self.l3_plugin.update_router( self.l3_plugin.update_router(
self.context, router['id'], self.context, router['id'],
{'router': {l3.EXTERNAL_GW_INFO: {}}}) {'router': {l3_apidef.EXTERNAL_GW_INFO: {}}})
def _remove_interface_from_router(self, router, subnet): def _remove_interface_from_router(self, router, subnet):
self.l3_plugin.remove_router_interface( self.l3_plugin.remove_router_interface(

View File

@ -14,6 +14,7 @@
import mock import mock
from neutron_lib.api.definitions import external_net as extnet_apidef from neutron_lib.api.definitions import external_net as extnet_apidef
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.api.definitions import portbindings from neutron_lib.api.definitions import portbindings
from neutron_lib.callbacks import events from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry from neutron_lib.callbacks import registry
@ -25,7 +26,6 @@ from neutron_lib import context
from neutron.api.rpc.handlers import l3_rpc from neutron.api.rpc.handlers import l3_rpc
from neutron.common import constants as n_const from neutron.common import constants as n_const
from neutron.common import topics from neutron.common import topics
from neutron.extensions import l3
from neutron.tests.common import helpers from neutron.tests.common import helpers
from neutron.tests.unit.plugins.ml2 import base as ml2_test_base from neutron.tests.unit.plugins.ml2 import base as ml2_test_base
@ -160,7 +160,7 @@ class L3DvrTestCase(L3DvrTestCaseBase):
gw_info = {'network_id': ext_net['network']['id']} gw_info = {'network_id': ext_net['network']['id']}
self.l3_plugin.update_router( self.l3_plugin.update_router(
self.context, router['id'], self.context, router['id'],
{'router': {l3.EXTERNAL_GW_INFO: gw_info}}) {'router': {l3_apidef.EXTERNAL_GW_INFO: gw_info}})
snat_router_intfs = self.l3_plugin._get_snat_sync_interfaces( snat_router_intfs = self.l3_plugin._get_snat_sync_interfaces(
self.context, [router['id']]) self.context, [router['id']])

View File

@ -21,13 +21,13 @@ from neutron_lib.callbacks import resources
from neutron_lib import constants as n_const from neutron_lib import constants as n_const
from neutron_lib import context from neutron_lib import context
from neutron_lib import exceptions as n_exc from neutron_lib import exceptions as n_exc
from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.plugins import directory from neutron_lib.plugins import directory
from oslo_utils import uuidutils from oslo_utils import uuidutils
import testtools import testtools
from neutron.db import l3_db from neutron.db import l3_db
from neutron.db.models import l3 as l3_models from neutron.db.models import l3 as l3_models
from neutron.extensions import l3
from neutron.objects import router as l3_obj from neutron.objects import router as l3_obj
from neutron.tests import base from neutron.tests import base
@ -184,7 +184,7 @@ class TestL3_NAT_dbonly_mixin(base.BaseTestCase):
'device_id': '44', 'id': 'f', 'device_id': '44', 'id': 'f',
'fixed_ips': [{'ip_address': '1.1.1.1', 'subnet_id': '4'}]} 'fixed_ips': [{'ip_address': '1.1.1.1', 'subnet_id': '4'}]}
self.db.get_router = mock.Mock() self.db.get_router = mock.Mock()
self.db.get_router.side_effect = l3.RouterNotFound(router_id='44') self.db.get_router.side_effect = l3_exc.RouterNotFound(router_id='44')
self.db.prevent_l3_port_deletion(mock.Mock(), None) self.db.prevent_l3_port_deletion(mock.Mock(), None)
@mock.patch.object(directory, 'get_plugin') @mock.patch.object(directory, 'get_plugin')

View File

@ -21,6 +21,7 @@ from neutron_lib.callbacks import resources
from neutron_lib import constants as const from neutron_lib import constants as const
from neutron_lib import context from neutron_lib import context
from neutron_lib import exceptions from neutron_lib import exceptions
from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.plugins import constants as plugin_constants from neutron_lib.plugins import constants as plugin_constants
from neutron_lib.plugins import directory from neutron_lib.plugins import directory
from oslo_utils import uuidutils from oslo_utils import uuidutils
@ -31,7 +32,6 @@ from neutron.db import l3_dvr_db
from neutron.db import l3_dvrscheduler_db from neutron.db import l3_dvrscheduler_db
from neutron.db.models import l3 as l3_models from neutron.db.models import l3 as l3_models
from neutron.db import models_v2 from neutron.db import models_v2
from neutron.extensions import l3
from neutron.objects import agent as agent_obj from neutron.objects import agent as agent_obj
from neutron.objects import router as router_obj from neutron.objects import router as router_obj
from neutron.tests.unit.db import test_db_base_plugin_v2 from neutron.tests.unit.db import test_db_base_plugin_v2
@ -854,7 +854,7 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase):
self.mixin, '_add_csnat_router_interface_port') as f: self.mixin, '_add_csnat_router_interface_port') as f:
f.side_effect = RuntimeError() f.side_effect = RuntimeError()
self.assertRaises( self.assertRaises(
l3.RouterInterfaceAttachmentConflict, l3_exc.RouterInterfaceAttachmentConflict,
self.mixin.add_router_interface, self.mixin.add_router_interface,
self.ctx, router['id'], self.ctx, router['id'],
{'subnet_id': subnet['subnet']['id']}) {'subnet_id': subnet['subnet']['id']})
@ -885,7 +885,7 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase):
router_obj.RouterPort, 'create') as rtrport_update: router_obj.RouterPort, 'create') as rtrport_update:
rtrport_update.side_effect = Exception() rtrport_update.side_effect = Exception()
self.assertRaises( self.assertRaises(
l3.RouterInterfaceAttachmentConflict, l3_exc.RouterInterfaceAttachmentConflict,
self.mixin.add_router_interface, self.mixin.add_router_interface,
self.ctx, router['id'], self.ctx, router['id'],
{'subnet_id': subnet['subnet']['id']}) {'subnet_id': subnet['subnet']['id']})

View File

@ -24,6 +24,7 @@ from neutron_lib.callbacks import resources
from neutron_lib import constants from neutron_lib import constants
from neutron_lib import context from neutron_lib import context
from neutron_lib import exceptions as n_exc from neutron_lib import exceptions as n_exc
from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.exceptions import l3_ext_ha_mode as l3ha_exc from neutron_lib.exceptions import l3_ext_ha_mode as l3ha_exc
from neutron_lib.objects import exceptions from neutron_lib.objects import exceptions
from neutron_lib.plugins import constants as plugin_constants from neutron_lib.plugins import constants as plugin_constants
@ -43,7 +44,6 @@ from neutron.db import common_db_mixin
from neutron.db import l3_agentschedulers_db from neutron.db import l3_agentschedulers_db
from neutron.db import l3_hamode_db from neutron.db import l3_hamode_db
from neutron.db.models import l3ha as l3ha_model from neutron.db.models import l3ha as l3ha_model
from neutron.extensions import l3
from neutron.objects import l3_hamode from neutron.objects import l3_hamode
from neutron.scheduler import l3_agent_scheduler from neutron.scheduler import l3_agent_scheduler
from neutron.services.revisions import revision_plugin from neutron.services.revisions import revision_plugin
@ -279,7 +279,7 @@ class L3HATestCase(L3HATestFramework):
def test_ha_router_delete_with_distributed(self): def test_ha_router_delete_with_distributed(self):
router = self._create_router(ha=True, distributed=True) router = self._create_router(ha=True, distributed=True)
self.plugin.delete_router(self.admin_ctx, router['id']) self.plugin.delete_router(self.admin_ctx, router['id'])
self.assertRaises(l3.RouterNotFound, self.plugin._get_router, self.assertRaises(l3_exc.RouterNotFound, self.plugin._get_router,
self.admin_ctx, router['id']) self.admin_ctx, router['id'])
def test_migration_from_ha(self): def test_migration_from_ha(self):
@ -1064,7 +1064,7 @@ class L3HAModeDbTestCase(L3HATestFramework):
self.plugin.add_router_interface(self.admin_ctx, self.plugin.add_router_interface(self.admin_ctx,
router['id'], router['id'],
interface_info) interface_info)
self.assertRaises(l3.RouterInUse, self.plugin.delete_router, self.assertRaises(l3_exc.RouterInUse, self.plugin.delete_router,
self.admin_ctx, router['id']) self.admin_ctx, router['id'])
bindings = self.plugin.get_ha_router_port_bindings( bindings = self.plugin.get_ha_router_port_bindings(
self.admin_ctx, [router['id']]) self.admin_ctx, [router['id']])

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import copy
from neutron_lib.api.definitions import extraroute as xroute_apidef from neutron_lib.api.definitions import extraroute as xroute_apidef
from neutron_lib import constants from neutron_lib import constants
from neutron_lib import context from neutron_lib import context
@ -36,7 +34,6 @@ _get_path = test_base._get_path
class ExtraRouteTestExtensionManager(object): class ExtraRouteTestExtensionManager(object):
def get_resources(self): def get_resources(self):
l3.L3().update_attributes_map(xroute_apidef.RESOURCE_ATTRIBUTE_MAP)
return l3.L3.get_resources() return l3.L3.get_resources()
def get_actions(self): def get_actions(self):
@ -498,8 +495,6 @@ class ExtraRouteDBIntTestCase(test_l3.L3NatDBIntTestCase,
ExtraRouteDBTestCaseBase): ExtraRouteDBTestCaseBase):
def setUp(self, plugin=None, ext_mgr=None): def setUp(self, plugin=None, ext_mgr=None):
self._backup = copy.deepcopy(l3.RESOURCE_ATTRIBUTE_MAP)
self.addCleanup(self._restore)
if not plugin: if not plugin:
plugin = ('neutron.tests.unit.extensions.test_extraroute.' plugin = ('neutron.tests.unit.extensions.test_extraroute.'
'TestExtraRouteIntPlugin') 'TestExtraRouteIntPlugin')
@ -511,15 +506,10 @@ class ExtraRouteDBIntTestCase(test_l3.L3NatDBIntTestCase,
ext_mgr=ext_mgr) ext_mgr=ext_mgr)
self.setup_notification_driver() self.setup_notification_driver()
def _restore(self):
l3.RESOURCE_ATTRIBUTE_MAP = self._backup
class ExtraRouteDBSepTestCase(test_l3.L3NatDBSepTestCase, class ExtraRouteDBSepTestCase(test_l3.L3NatDBSepTestCase,
ExtraRouteDBTestCaseBase): ExtraRouteDBTestCaseBase):
def setUp(self): def setUp(self):
self._backup = copy.deepcopy(l3.RESOURCE_ATTRIBUTE_MAP)
self.addCleanup(self._restore)
# the plugin without L3 support # the plugin without L3 support
plugin = 'neutron.tests.unit.extensions.test_l3.TestNoL3NatPlugin' plugin = 'neutron.tests.unit.extensions.test_l3.TestNoL3NatPlugin'
# the L3 service plugin # the L3 service plugin
@ -536,6 +526,3 @@ class ExtraRouteDBSepTestCase(test_l3.L3NatDBSepTestCase,
service_plugins=service_plugins) service_plugins=service_plugins)
self.setup_notification_driver() self.setup_notification_driver()
def _restore(self):
l3.RESOURCE_ATTRIBUTE_MAP = self._backup

View File

@ -19,8 +19,8 @@ import copy
import mock import mock
import netaddr import netaddr
from neutron_lib.api.definitions import dns as dns_apidef
from neutron_lib.api.definitions import external_net as extnet_apidef from neutron_lib.api.definitions import external_net as extnet_apidef
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.api.definitions import portbindings from neutron_lib.api.definitions import portbindings
from neutron_lib.callbacks import events from neutron_lib.callbacks import events
from neutron_lib.callbacks import exceptions from neutron_lib.callbacks import exceptions
@ -29,6 +29,7 @@ from neutron_lib.callbacks import resources
from neutron_lib import constants as lib_constants from neutron_lib import constants as lib_constants
from neutron_lib import context from neutron_lib import context
from neutron_lib import exceptions as n_exc from neutron_lib import exceptions as n_exc
from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.plugins import constants as plugin_constants from neutron_lib.plugins import constants as plugin_constants
from neutron_lib.plugins import directory from neutron_lib.plugins import directory
from oslo_config import cfg from oslo_config import cfg
@ -623,7 +624,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
self.extension_called = True self.extension_called = True
resource_extend.register_funcs( resource_extend.register_funcs(
l3.ROUTERS, [_extend_router_dict_test_attr]) l3_apidef.ROUTERS, [_extend_router_dict_test_attr])
self.assertFalse(self.extension_called) self.assertFalse(self.extension_called)
with self.router(): with self.router():
self.assertTrue(self.extension_called) self.assertTrue(self.extension_called)
@ -897,7 +898,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
plugin = directory.get_plugin(plugin_constants.L3) plugin = directory.get_plugin(plugin_constants.L3)
mock.patch.object( mock.patch.object(
plugin, 'update_router', plugin, 'update_router',
side_effect=l3.RouterNotFound(router_id='1')).start() side_effect=l3_exc.RouterNotFound(router_id='1')).start()
# ensure the router disappearing doesn't interfere with subnet # ensure the router disappearing doesn't interfere with subnet
# creation # creation
self._create_subnet(self.fmt, net_id=n['network']['id'], self._create_subnet(self.fmt, net_id=n['network']['id'],
@ -2985,7 +2986,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
if first_router_id: if first_router_id:
return first_router_id return first_router_id
raise l3.ExternalGatewayForFloatingIPNotFound( raise l3_exc.ExternalGatewayForFloatingIPNotFound(
subnet_id=internal_subnet['id'], subnet_id=internal_subnet['id'],
external_network_id=external_network_id, external_network_id=external_network_id,
port_id=internal_port['id']) port_id=internal_port['id'])
@ -3646,7 +3647,7 @@ class L3AgentDbTestCaseBase(L3NatTestCaseMixin):
def test_router_create_event_exception_preserved(self): def test_router_create_event_exception_preserved(self):
# this exception should be propagated out of the callback and # this exception should be propagated out of the callback and
# converted into its API equivalent of 404 # converted into its API equivalent of 404
e404 = mock.Mock(side_effect=l3.RouterNotFound(router_id='1')) e404 = mock.Mock(side_effect=l3_exc.RouterNotFound(router_id='1'))
registry.subscribe(e404, resources.ROUTER, events.PRECOMMIT_CREATE) registry.subscribe(e404, resources.ROUTER, events.PRECOMMIT_CREATE)
res = self._create_router(self.fmt, 'tenid') res = self._create_router(self.fmt, 'tenid')
self.assertEqual(exc.HTTPNotFound.code, res.status_int) self.assertEqual(exc.HTTPNotFound.code, res.status_int)
@ -3668,7 +3669,7 @@ class L3AgentDbTestCaseBase(L3NatTestCaseMixin):
def test_router_update_event_exception_preserved(self): def test_router_update_event_exception_preserved(self):
# this exception should be propagated out of the callback and # this exception should be propagated out of the callback and
# converted into its API equivalent of 404 # converted into its API equivalent of 404
e404 = mock.Mock(side_effect=l3.RouterNotFound(router_id='1')) e404 = mock.Mock(side_effect=l3_exc.RouterNotFound(router_id='1'))
registry.subscribe(e404, resources.ROUTER, events.PRECOMMIT_UPDATE) registry.subscribe(e404, resources.ROUTER, events.PRECOMMIT_UPDATE)
with self.router(name='a') as r: with self.router(name='a') as r:
self._update('routers', r['router']['id'], self._update('routers', r['router']['id'],
@ -3689,7 +3690,7 @@ class L3AgentDbTestCaseBase(L3NatTestCaseMixin):
def test_router_delete_event_exception_preserved(self): def test_router_delete_event_exception_preserved(self):
# this exception should be propagated out of the callback and # this exception should be propagated out of the callback and
# converted into its API equivalent of 409 # converted into its API equivalent of 409
e409 = mock.Mock(side_effect=l3.RouterInUse(router_id='1')) e409 = mock.Mock(side_effect=l3_exc.RouterInUse(router_id='1'))
registry.subscribe(e409, resources.ROUTER, events.PRECOMMIT_DELETE) registry.subscribe(e409, resources.ROUTER, events.PRECOMMIT_DELETE)
with self.router() as r: with self.router() as r:
self._delete('routers', r['router']['id'], self._delete('routers', r['router']['id'],
@ -3997,7 +3998,6 @@ class L3NatDBSepTestCase(L3BaseForSepTests, L3NatTestCaseBase,
class L3TestExtensionManagerWithDNS(L3TestExtensionManager): class L3TestExtensionManagerWithDNS(L3TestExtensionManager):
def get_resources(self): def get_resources(self):
l3.L3().update_attributes_map(dns_apidef.RESOURCE_ATTRIBUTE_MAP)
return l3.L3.get_resources() return l3.L3.get_resources()
@ -4017,8 +4017,6 @@ class L3NatDBFloatingIpTestCaseWithDNS(L3BaseForSepTests, L3NatTestCaseMixin):
_extension_drivers = ['dns'] _extension_drivers = ['dns']
def setUp(self): def setUp(self):
self._l3_resource_backup = copy.deepcopy(l3.RESOURCE_ATTRIBUTE_MAP)
self.addCleanup(self._restore)
ext_mgr = L3TestExtensionManagerWithDNS() ext_mgr = L3TestExtensionManagerWithDNS()
plugin = 'neutron.plugins.ml2.plugin.Ml2Plugin' plugin = 'neutron.plugins.ml2.plugin.Ml2Plugin'
cfg.CONF.set_override('extension_drivers', cfg.CONF.set_override('extension_drivers',
@ -4030,9 +4028,6 @@ class L3NatDBFloatingIpTestCaseWithDNS(L3BaseForSepTests, L3NatTestCaseMixin):
self.mock_client.reset_mock() self.mock_client.reset_mock()
self.mock_admin_client.reset_mock() self.mock_admin_client.reset_mock()
def _restore(self):
l3.RESOURCE_ATTRIBUTE_MAP = self._l3_resource_backup
def _create_network(self, fmt, name, admin_state_up, def _create_network(self, fmt, name, admin_state_up,
arg_list=None, set_context=False, tenant_id=None, arg_list=None, set_context=False, tenant_id=None,
**kwargs): **kwargs):

View File

@ -14,11 +14,9 @@
# under the License. # under the License.
# #
import copy
import mock import mock
import netaddr import netaddr
from neutron_lib.api.definitions import l3_ext_gw_mode as l3gwm_apidef from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib import constants from neutron_lib import constants
from neutron_lib import context as nctx from neutron_lib import context as nctx
from neutron_lib.plugins import directory from neutron_lib.plugins import directory
@ -58,10 +56,6 @@ FAKE_ROUTER_PORT_MAC = 'bb:bb:bb:bb:bb:bb'
class TestExtensionManager(object): class TestExtensionManager(object):
def get_resources(self): def get_resources(self):
# Simulate extension of L3 attribute map
for key in l3.RESOURCE_ATTRIBUTE_MAP.keys():
l3.RESOURCE_ATTRIBUTE_MAP[key].update(
l3gwm_apidef.RESOURCE_ATTRIBUTE_MAP.get(key, {}))
return l3.L3.get_resources() return l3.L3.get_resources()
def get_actions(self): def get_actions(self):
@ -303,14 +297,14 @@ class TestL3GwModeMixin(testlib_api.SqlTestCase):
def test_make_router_dict_no_ext_gw(self): def test_make_router_dict_no_ext_gw(self):
self._reset_ext_gw() self._reset_ext_gw()
router_dict = self.target_object._make_router_dict(self.router) router_dict = self.target_object._make_router_dict(self.router)
self.assertIsNone(router_dict[l3.EXTERNAL_GW_INFO]) self.assertIsNone(router_dict[l3_apidef.EXTERNAL_GW_INFO])
def test_make_router_dict_with_ext_gw(self): def test_make_router_dict_with_ext_gw(self):
router_dict = self.target_object._make_router_dict(self.router) router_dict = self.target_object._make_router_dict(self.router)
self.assertEqual({'network_id': self.ext_net_id, self.assertEqual({'network_id': self.ext_net_id,
'enable_snat': True, 'enable_snat': True,
'external_fixed_ips': []}, 'external_fixed_ips': []},
router_dict[l3.EXTERNAL_GW_INFO]) router_dict[l3_apidef.EXTERNAL_GW_INFO])
def test_make_router_dict_with_ext_gw_snat_disabled(self): def test_make_router_dict_with_ext_gw_snat_disabled(self):
self.router.enable_snat = False self.router.enable_snat = False
@ -318,7 +312,7 @@ class TestL3GwModeMixin(testlib_api.SqlTestCase):
self.assertEqual({'network_id': self.ext_net_id, self.assertEqual({'network_id': self.ext_net_id,
'enable_snat': False, 'enable_snat': False,
'external_fixed_ips': []}, 'external_fixed_ips': []},
router_dict[l3.EXTERNAL_GW_INFO]) router_dict[l3_apidef.EXTERNAL_GW_INFO])
def test_build_routers_list_no_ext_gw(self): def test_build_routers_list_no_ext_gw(self):
self._reset_ext_gw() self._reset_ext_gw()
@ -368,8 +362,6 @@ class ExtGwModeIntTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase,
test_l3.L3NatTestCaseMixin): test_l3.L3NatTestCaseMixin):
def setUp(self, plugin=None, svc_plugins=None, ext_mgr=None): def setUp(self, plugin=None, svc_plugins=None, ext_mgr=None):
# Store l3 resource attribute map as it will be updated
self._l3_attribute_map_bk = copy.deepcopy(l3.RESOURCE_ATTRIBUTE_MAP)
plugin = plugin or ( plugin = plugin or (
'neutron.tests.unit.extensions.test_l3_ext_gw_mode.' 'neutron.tests.unit.extensions.test_l3_ext_gw_mode.'
'TestDbIntPlugin') 'TestDbIntPlugin')
@ -379,10 +371,6 @@ class ExtGwModeIntTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase,
super(ExtGwModeIntTestCase, self).setUp(plugin=plugin, super(ExtGwModeIntTestCase, self).setUp(plugin=plugin,
ext_mgr=ext_mgr, ext_mgr=ext_mgr,
service_plugins=svc_plugins) service_plugins=svc_plugins)
self.addCleanup(self.restore_l3_attribute_map)
def restore_l3_attribute_map(self):
l3.RESOURCE_ATTRIBUTE_MAP = self._l3_attribute_map_bk
def _set_router_external_gateway(self, router_id, network_id, def _set_router_external_gateway(self, router_id, network_id,
snat_enabled=None, snat_enabled=None,
@ -531,9 +519,9 @@ class ExtGwModeSepTestCase(ExtGwModeIntTestCase):
def setUp(self, plugin=None): def setUp(self, plugin=None):
# Store l3 resource attribute map as it will be updated # Store l3 resource attribute map as it will be updated
self._l3_attribute_map_bk = {} self._l3_attribute_map_bk = {}
for item in l3.RESOURCE_ATTRIBUTE_MAP: for item in l3_apidef.RESOURCE_ATTRIBUTE_MAP:
self._l3_attribute_map_bk[item] = ( self._l3_attribute_map_bk[item] = (
l3.RESOURCE_ATTRIBUTE_MAP[item].copy()) l3_apidef.RESOURCE_ATTRIBUTE_MAP[item].copy())
plugin = plugin or ( plugin = plugin or (
'neutron.tests.unit.extensions.test_l3.TestNoL3NatPlugin') 'neutron.tests.unit.extensions.test_l3.TestNoL3NatPlugin')
# the L3 service plugin # the L3 service plugin
@ -544,4 +532,3 @@ class ExtGwModeSepTestCase(ExtGwModeIntTestCase):
cfg.CONF.set_default('allow_overlapping_ips', True) cfg.CONF.set_default('allow_overlapping_ips', True)
super(ExtGwModeSepTestCase, self).setUp(plugin=plugin, super(ExtGwModeSepTestCase, self).setUp(plugin=plugin,
svc_plugins=svc_plugins) svc_plugins=svc_plugins)
self.addCleanup(self.restore_l3_attribute_map)

View File

@ -28,8 +28,6 @@ from neutron.tests.unit.extensions import test_l3
class FloatingIPQoSTestExtensionManager(object): class FloatingIPQoSTestExtensionManager(object):
def get_resources(self): def get_resources(self):
l3.RESOURCE_ATTRIBUTE_MAP['floatingips'].update(
qos_fip.EXTENDED_ATTRIBUTES_2_0['floatingips'])
return l3.L3.get_resources() return l3.L3.get_resources()
def get_actions(self): def get_actions(self):

View File

@ -11,9 +11,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import copy
from neutron_lib.api.definitions import router_availability_zone as raz_apidef
from neutron_lib.plugins import constants from neutron_lib.plugins import constants
from neutron.db.availability_zone import router as router_az_db from neutron.db.availability_zone import router as router_az_db
@ -55,20 +52,10 @@ class TestAZRouterCase(test_az.AZTestCommon, test_l3.L3NatTestCaseMixin):
'test_router_availability_zone.AZRouterTestPlugin') 'test_router_availability_zone.AZRouterTestPlugin')
service_plugins = {'l3_plugin_name': l3_plugin} service_plugins = {'l3_plugin_name': l3_plugin}
self._backup()
l3.RESOURCE_ATTRIBUTE_MAP['routers'].update(
raz_apidef.RESOURCE_ATTRIBUTE_MAP['routers'])
ext_mgr = AZL3ExtensionManager() ext_mgr = AZL3ExtensionManager()
super(TestAZRouterCase, self).setUp(plugin=plugin, ext_mgr=ext_mgr, super(TestAZRouterCase, self).setUp(plugin=plugin, ext_mgr=ext_mgr,
service_plugins=service_plugins) service_plugins=service_plugins)
def _backup(self):
self.contents_backup = copy.deepcopy(l3.RESOURCE_ATTRIBUTE_MAP)
self.addCleanup(self._restore)
def _restore(self):
l3.RESOURCE_ATTRIBUTE_MAP = self.contents_backup
def test_create_router_with_az(self): def test_create_router_with_az(self):
self._register_azs() self._register_azs()
az_hints = ['nova2'] az_hints = ['nova2']

View File

@ -21,6 +21,7 @@ import mock
from neutron_lib.api.definitions import portbindings from neutron_lib.api.definitions import portbindings
from neutron_lib import constants from neutron_lib import constants
from neutron_lib import context as n_context from neutron_lib import context as n_context
from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.plugins import constants as plugin_constants from neutron_lib.plugins import constants as plugin_constants
from neutron_lib.plugins import directory from neutron_lib.plugins import directory
from oslo_config import cfg from oslo_config import cfg
@ -37,7 +38,6 @@ from neutron.db import l3_dvr_ha_scheduler_db
from neutron.db import l3_dvrscheduler_db from neutron.db import l3_dvrscheduler_db
from neutron.db import l3_hamode_db from neutron.db import l3_hamode_db
from neutron.db import l3_hascheduler_db from neutron.db import l3_hascheduler_db
from neutron.extensions import l3
from neutron.extensions import l3agentscheduler as l3agent from neutron.extensions import l3agentscheduler as l3agent
from neutron import manager from neutron import manager
from neutron.objects import agent as agent_obj from neutron.objects import agent as agent_obj
@ -1399,7 +1399,8 @@ class L3HATestCaseMixin(testlib_api.SqlTestCase,
with mock.patch.object(self.plugin.router_scheduler, 'bind_router'): with mock.patch.object(self.plugin.router_scheduler, 'bind_router'):
with mock.patch.object( with mock.patch.object(
self.plugin, 'add_ha_port', self.plugin, 'add_ha_port',
side_effect=l3.RouterNotFound(router_id='foo_router')),\ side_effect=l3_exc.RouterNotFound(
router_id='foo_router')),\
mock.patch.object( mock.patch.object(
self.plugin, 'safe_delete_ha_network') as sd_ha_net: self.plugin, 'safe_delete_ha_network') as sd_ha_net:
self.plugin.router_scheduler.create_ha_port_and_bind( self.plugin.router_scheduler.create_ha_port_and_bind(