remove neutron.common.exceptions

Today the neutron common exceptions already live in neutron-lib and are
shimmed from neutron. This patch removes the neutron.common.exceptions
module and changes neutron's imports over to use their respective
neutron-lib exception module instead.

NeutronLibImpact

Change-Id: I9704f20eb21da85d2cf024d83338b3d94593671e
This commit is contained in:
Boden R 2019-02-01 14:35:00 -07:00
parent 0e82cecda8
commit 68fd13af40
74 changed files with 286 additions and 402 deletions

View File

@ -22,6 +22,7 @@ from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources
from neutron_lib import constants as lib_const
from neutron_lib import context as n_context
from neutron_lib.exceptions import l3 as l3_exc
from oslo_config import cfg
from oslo_context import context as common_context
from oslo_log import log as logging
@ -52,7 +53,6 @@ from neutron.agent.linux import pd
from neutron.agent.metadata import driver as metadata_driver
from neutron.agent import rpc as agent_rpc
from neutron.common import constants as l3_constants
from neutron.common import exceptions as n_exc
from neutron.common import ipv6_utils
from neutron.common import rpc as n_rpc
from neutron.common import utils
@ -485,7 +485,7 @@ class L3NATAgent(ha.AgentMixin,
# Either ex_net_id or handle_internal_only_routers must be set
ex_net_id = (router['external_gateway_info'] or {}).get('network_id')
if not ex_net_id and not self.conf.handle_internal_only_routers:
raise n_exc.RouterNotCompatibleWithAgent(router_id=router['id'])
raise l3_exc.RouterNotCompatibleWithAgent(router_id=router['id'])
# If target_ex_net_id and ex_net_id are set they must be equal
target_ex_net_id = self._fetch_external_net_id()
@ -493,7 +493,7 @@ class L3NATAgent(ha.AgentMixin,
# Double check that our single external_net_id has not changed
# by forcing a check by RPC.
if ex_net_id != self._fetch_external_net_id(force=True):
raise n_exc.RouterNotCompatibleWithAgent(
raise l3_exc.RouterNotCompatibleWithAgent(
router_id=router['id'])
if router['id'] not in self.router_info:
@ -623,7 +623,7 @@ class L3NATAgent(ha.AgentMixin,
try:
self._process_router_if_compatible(router)
except n_exc.RouterNotCompatibleWithAgent as e:
except l3_exc.RouterNotCompatibleWithAgent as e:
log_verbose_exc(e.msg, router)
# Was the router previously handled by this agent?
if router['id'] in self.router_info:
@ -664,7 +664,7 @@ class L3NATAgent(ha.AgentMixin,
try:
with self.namespaces_manager as ns_manager:
self.fetch_and_sync_all_routers(context, ns_manager)
except n_exc.AbortSyncRouters:
except l3_exc.AbortSyncRouters:
self.fullsync = True
def fetch_and_sync_all_routers(self, context, ns_manager):
@ -720,7 +720,7 @@ class L3NATAgent(ha.AgentMixin,
failed_routers = chunk or router_ids
LOG.exception("Failed synchronizing routers '%s' "
"due to RPC error", failed_routers)
raise n_exc.AbortSyncRouters()
raise l3_exc.AbortSyncRouters()
self.fullsync = False
LOG.debug("periodic_sync_routers_task successfully completed")

View File

@ -16,6 +16,7 @@ import contextlib
import os
from neutron_lib import constants as lib_constants
from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.utils import runtime
from oslo_concurrency import lockutils
from oslo_log import log as logging
@ -29,7 +30,6 @@ from neutron.agent.l3 import router_info
from neutron.agent.linux import ip_lib
from neutron.agent.linux import iptables_manager
from neutron.common import constants
from neutron.common import exceptions as n_exc
from neutron.common import utils as common_utils
from neutron.ipam import utils as ipam_utils
@ -352,7 +352,7 @@ class FipNamespace(namespaces.Namespace):
'ns': ns_name})
msg = _('DVR: Gateway update route in FIP namespace failed, retry '
'should be attempted on next call')
raise n_exc.FloatingIpSetupException(msg)
raise l3_exc.FloatingIpSetupException(msg)
for fixed_ip in agent_gateway_port['fixed_ips']:
ip_lib.send_ip_addr_adv_notif(ns_name,

View File

@ -16,6 +16,7 @@ import collections
import netaddr
from neutron_lib import constants as lib_constants
from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.utils import helpers
from oslo_log import log as logging
@ -25,7 +26,6 @@ from neutron.agent.linux import ip_lib
from neutron.agent.linux import iptables_manager
from neutron.agent.linux import ra
from neutron.common import constants as n_const
from neutron.common import exceptions as n_exc
from neutron.common import ipv6_utils
from neutron.common import utils as common_utils
from neutron.ipam import utils as ipam_utils
@ -291,7 +291,7 @@ class RouterInfo(object):
# TODO(salv-orlando): Less broad catching
msg = _('L3 agent failure to setup NAT for floating IPs')
LOG.exception(msg)
raise n_exc.FloatingIpSetupException(msg)
raise l3_exc.FloatingIpSetupException(msg)
def _add_fip_addr_to_device(self, fip, device):
"""Configures the floating ip address on the device.
@ -409,7 +409,7 @@ class RouterInfo(object):
# TODO(salv-orlando): Less broad catching
msg = _('L3 agent failure to setup floating IPs')
LOG.exception(msg)
raise n_exc.FloatingIpSetupException(msg)
raise l3_exc.FloatingIpSetupException(msg)
def put_fips_in_error_state(self):
fip_statuses = {}
@ -920,7 +920,7 @@ class RouterInfo(object):
ex_gw_port)
fip_statuses = self.configure_fip_addresses(interface_name)
except n_exc.FloatingIpSetupException:
except l3_exc.FloatingIpSetupException:
# All floating IPs must be put in error state
LOG.exception("Failed to process floating IPs.")
fip_statuses = self.put_fips_in_error_state()
@ -945,8 +945,8 @@ class RouterInfo(object):
ex_gw_port)
fip_statuses = self.configure_fip_addresses(interface_name)
except (n_exc.FloatingIpSetupException,
n_exc.IpTablesApplyException):
except (l3_exc.FloatingIpSetupException,
l3_exc.IpTablesApplyException):
# All floating IPs must be put in error state
LOG.exception("Failed to process floating IPs.")
fip_statuses = self.put_fips_in_error_state()

View File

@ -22,10 +22,10 @@ import pwd
import signal
import sys
from neutron_lib import exceptions
from oslo_log import log as logging
from neutron._i18n import _
from neutron.common import exceptions
LOG = logging.getLogger(__name__)

View File

@ -18,6 +18,7 @@ import time
import netaddr
from neutron_lib import constants
from neutron_lib import exceptions
from oslo_log import log as logging
from oslo_utils import excutils
import six
@ -25,7 +26,6 @@ import six
from neutron.agent.common import ovs_lib
from neutron.agent.linux import ip_lib
from neutron.common import constants as n_const
from neutron.common import exceptions
LOG = logging.getLogger(__name__)

View File

@ -15,12 +15,12 @@ import re
import eventlet
import netaddr
from neutron_lib import exceptions
from oslo_concurrency import lockutils
from oslo_log import log as logging
from neutron.agent.linux import utils as linux_utils
from neutron.common import constants as n_const
from neutron.common import exceptions as n_exc
LOG = logging.getLogger(__name__)
CONTRACK_MGRS = {}
@ -225,7 +225,7 @@ class IpConntrackManager(object):
"""Generates a unique conntrack zone for the passed in ID."""
try:
zone = self._find_open_zone()
except n_exc.CTZoneExhaustedError:
except exceptions.CTZoneExhaustedError:
# Free some zones and try again, repeat failure will not be caught
self._free_zones_from_removed_ports()
zone = self._find_open_zone()
@ -250,4 +250,4 @@ class IpConntrackManager(object):
# gap found, let's use it!
return index + ZONE_START
# conntrack zones exhausted :( :(
raise n_exc.CTZoneExhaustedError()
raise exceptions.CTZoneExhaustedError()

View File

@ -32,7 +32,6 @@ from pyroute2 import netns
from neutron._i18n import _
from neutron.agent.common import utils
from neutron.common import exceptions as n_exc
from neutron.common import ipv6_utils
from neutron.common import utils as common_utils
from neutron.privileged.agent.linux import ip_lib as privileged
@ -285,7 +284,8 @@ class IPWrapper(SubProcessBase):
if len(srcport) == 2 and srcport[0] <= srcport[1]:
kwargs['vxlan_port_range'] = (str(srcport[0]), str(srcport[1]))
else:
raise n_exc.NetworkVxlanPortRangeError(vxlan_range=srcport)
raise exceptions.NetworkVxlanPortRangeError(
vxlan_range=srcport)
if dstport:
kwargs['vxlan_port'] = dstport
privileged.create_interface(name, self.namespace, "vxlan", **kwargs)

View File

@ -25,6 +25,8 @@ import os
import re
import sys
from neutron_lib import exceptions
from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.utils import runtime
from oslo_concurrency import lockutils
from oslo_config import cfg
@ -36,7 +38,6 @@ from neutron.agent.linux import ip_lib
from neutron.agent.linux import iptables_comments as ic
from neutron.agent.linux import utils as linux_utils
from neutron.common import constants
from neutron.common import exceptions as n_exc
from neutron.conf.agent import common as config
LOG = logging.getLogger(__name__)
@ -424,13 +425,13 @@ class IptablesManager(object):
finally:
try:
self.defer_apply_off()
except n_exc.IpTablesApplyException:
except l3_exc.IpTablesApplyException:
# already in the format we want, just reraise
raise
except Exception:
msg = _('Failure applying iptables rules')
LOG.exception(msg)
raise n_exc.IpTablesApplyException(msg)
raise l3_exc.IpTablesApplyException(msg)
def defer_apply_on(self):
self.iptables_apply_deferred = True
@ -462,7 +463,7 @@ class IptablesManager(object):
msg = (_("IPTables Rules did not converge. Diff: %s") %
'\n'.join(second))
LOG.error(msg)
raise n_exc.IpTablesApplyException(msg)
raise l3_exc.IpTablesApplyException(msg)
return first
def get_rules_for_table(self, table):
@ -495,7 +496,7 @@ class IptablesManager(object):
return self._do_run_restore(args, commands, lock=True)
err = self._do_run_restore(args, commands)
if (isinstance(err, n_exc.ProcessExecutionError) and
if (isinstance(err, exceptions.ProcessExecutionError) and
err.returncode == XTABLES_RESOURCE_PROBLEM_CODE):
# maybe we run on a platform that includes iptables commit
# 999eaa241212d3952ddff39a99d0d55a74e3639e (for example, latest

View File

@ -13,11 +13,11 @@
import re
from neutron_lib import constants
from neutron_lib import exceptions
from oslo_log import log as logging
from neutron.agent.linux import ip_lib
from neutron.agent.linux import tc_lib
from neutron.common import exceptions
LOG = logging.getLogger(__name__)

View File

@ -24,6 +24,7 @@ import time
import eventlet
from eventlet.green import subprocess
from neutron_lib import exceptions
from neutron_lib.utils import helpers
from oslo_config import cfg
from oslo_log import log as logging
@ -35,7 +36,6 @@ from six.moves import http_client as httplib
from neutron._i18n import _
from neutron.agent.linux import xenapi_root_helper
from neutron.common import exceptions
from neutron.common import utils
from neutron.conf.agent import common as config
from neutron import wsgi

View File

@ -21,6 +21,7 @@ import pwd
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources
from neutron_lib import exceptions
from oslo_config import cfg
from oslo_log import log as logging
@ -29,7 +30,7 @@ from neutron.agent.l3 import ha_router
from neutron.agent.l3 import namespaces
from neutron.agent.linux import external_process
from neutron.common import constants
from neutron.common import exceptions
LOG = logging.getLogger(__name__)

View File

@ -18,13 +18,14 @@ import os
import eventlet
from eventlet import tpool
from neutron_lib import exceptions
from neutron_lib.utils import helpers
from oslo_log import log as logging
from oslo_utils import encodeutils
import six
from neutron._i18n import _
from neutron.common import exceptions
if os.name == 'nt':
import wmi

View File

@ -18,6 +18,7 @@ import imp
import os
from neutron_lib.api import extensions as api_extensions
from neutron_lib import exceptions
from neutron_lib.plugins import directory
from oslo_config import cfg
from oslo_log import log as logging
@ -27,7 +28,6 @@ import webob.dec
import webob.exc
from neutron._i18n import _
from neutron.common import exceptions
from neutron import extensions as core_extensions
from neutron.plugins.common import constants as const
from neutron.services import provider_configuration

View File

@ -33,7 +33,6 @@ from oslo_utils import excutils
from neutron._i18n import _
from neutron.common import constants as n_const
from neutron.common import exceptions as n_exc
from neutron.common import utils
from neutron.db import provisioning_blocks
from neutron.extensions import segment as segment_ext
@ -298,7 +297,7 @@ class DhcpRpcCallback(object):
utils.get_dhcp_agent_device_id(network_id, host) or
not self._is_dhcp_agent_hosting_network(plugin, context, host,
network_id)):
raise n_exc.DhcpPortInUse(port_id=port['id'])
raise exceptions.DhcpPortInUse(port_id=port['id'])
LOG.debug('Update dhcp port %(port)s '
'from %(host)s.',
{'port': port,

View File

@ -31,7 +31,6 @@ from neutron._i18n import _
from neutron.api import api_common
from neutron.api.v2 import resource as wsgi_resource
from neutron.common import constants as n_const
from neutron.common import exceptions as n_exc
from neutron.common import rpc as n_rpc
from neutron import policy
from neutron import quota
@ -485,7 +484,7 @@ class Controller(object):
{self._resource: delta},
self._plugin)
reservations.append(reservation)
except n_exc.QuotaResourceUnknown as e:
except exceptions.QuotaResourceUnknown as e:
# We don't want to quota this resource
LOG.debug(e)

View File

@ -1,102 +0,0 @@
# Copyright 2011 VMware, Inc
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import exceptions
from neutron_lib.exceptions import l3
from neutron_lib.exceptions import qos
# TODO(boden): remove lib shims
SubnetPoolNotFound = exceptions.SubnetPoolNotFound
StateInvalid = exceptions.StateInvalid
DhcpPortInUse = exceptions.DhcpPortInUse
HostRoutesExhausted = exceptions.HostRoutesExhausted
DNSNameServersExhausted = exceptions.DNSNameServersExhausted
FlatNetworkInUse = exceptions.FlatNetworkInUse
NoNetworkFoundInMaximumAllowedAttempts = \
exceptions.NoNetworkFoundInMaximumAllowedAttempts
MalformedRequestBody = exceptions.MalformedRequestBody
InvalidAllocationPool = exceptions.InvalidAllocationPool
UnsupportedPortDeviceOwner = \
exceptions.UnsupportedPortDeviceOwner
OverlappingAllocationPools = exceptions.OverlappingAllocationPools
OutOfBoundsAllocationPool = exceptions.OutOfBoundsAllocationPool
BridgeDoesNotExist = exceptions.BridgeDoesNotExist
QuotaResourceUnknown = exceptions.QuotaResourceUnknown
QuotaMissingTenant = exceptions.QuotaMissingTenant
InvalidQuotaValue = exceptions.InvalidQuotaValue
InvalidSharedSetting = exceptions.InvalidSharedSetting
ExtensionsNotFound = exceptions.ExtensionsNotFound
GatewayConflictWithAllocationPools = \
exceptions.GatewayConflictWithAllocationPools
GatewayIpInUse = exceptions.GatewayIpInUse
NetworkVxlanPortRangeError = exceptions.NetworkVxlanPortRangeError
VxlanNetworkUnsupported = exceptions.VxlanNetworkUnsupported
DuplicatedExtension = exceptions.DuplicatedExtension
DriverCallError = exceptions.DriverCallError
DeviceIDNotOwnedByTenant = exceptions.DeviceIDNotOwnedByTenant
InvalidCIDR = exceptions.InvalidCIDR
FailToDropPrivilegesExit = exceptions.FailToDropPrivilegesExit
NetworkIdOrRouterIdRequiredError = exceptions.NetworkIdOrRouterIdRequiredError
EmptySubnetPoolPrefixList = exceptions.EmptySubnetPoolPrefixList
PrefixVersionMismatch = exceptions.PrefixVersionMismatch
UnsupportedMinSubnetPoolPrefix = exceptions.UnsupportedMinSubnetPoolPrefix
IllegalSubnetPoolPrefixBounds = exceptions.IllegalSubnetPoolPrefixBounds
IllegalSubnetPoolPrefixUpdate = exceptions.IllegalSubnetPoolPrefixUpdate
SubnetAllocationError = exceptions.SubnetAllocationError
AddressScopePrefixConflict = exceptions.AddressScopePrefixConflict
IllegalSubnetPoolAssociationToAddressScope = \
exceptions.IllegalSubnetPoolAssociationToAddressScope
IllegalSubnetPoolIpVersionAssociationToAddressScope = \
exceptions.IllegalSubnetPoolIpVersionAssociationToAddressScope
IllegalSubnetPoolUpdate = exceptions.IllegalSubnetPoolUpdate
MinPrefixSubnetAllocationError = exceptions.MinPrefixSubnetAllocationError
MaxPrefixSubnetAllocationError = exceptions.MaxPrefixSubnetAllocationError
SubnetPoolDeleteError = exceptions.SubnetPoolDeleteError
SubnetPoolQuotaExceeded = exceptions.SubnetPoolQuotaExceeded
NetworkSubnetPoolAffinityError = exceptions.NetworkSubnetPoolAffinityError
ObjectActionError = exceptions.ObjectActionError
CTZoneExhaustedError = exceptions.CTZoneExhaustedError
TenantQuotaNotFound = exceptions.TenantQuotaNotFound
MultipleFilterIDForIPFound = exceptions.MultipleFilterIDForIPFound
FilterIDForIPNotFound = exceptions.FilterIDForIPNotFound
FailedToAddQdiscToDevice = exceptions.FailedToAddQdiscToDevice
PortBindingNotFound = exceptions.PortBindingNotFound
PortBindingAlreadyActive = exceptions.PortBindingAlreadyActive
PortBindingAlreadyExists = exceptions.PortBindingAlreadyExists
PortBindingError = exceptions.PortBindingError
ProcessExecutionError = exceptions.ProcessExecutionError
QosPolicyNotFound = qos.QosPolicyNotFound
QosRuleNotFound = qos.QosRuleNotFound
QoSPolicyDefaultAlreadyExists = qos.QoSPolicyDefaultAlreadyExists
PortQosBindingNotFound = qos.PortQosBindingNotFound
PortQosBindingError = qos.PortQosBindingError
NetworkQosBindingNotFound = qos.NetworkQosBindingNotFound
FloatingIPQosBindingNotFound = qos.FloatingIPQosBindingNotFound
FloatingIPQosBindingError = qos.FloatingIPQosBindingError
NetworkQosBindingError = qos.NetworkQosBindingError
PolicyRemoveAuthorizationError = qos.PolicyRemoveAuthorizationError
QosPolicyInUse = qos.QosPolicyInUse
QosRuleNotSupported = qos.QosRuleNotSupported
QoSRuleParameterConflict = qos.QoSRuleParameterConflict
QoSRulesConflict = qos.QoSRulesConflict
RouterQosBindingNotFound = qos.RouterQosBindingNotFound
RouterQosBindingError = qos.RouterQosBindingError
RouterNotCompatibleWithAgent = l3.RouterNotCompatibleWithAgent
FloatingIpSetupException = l3.FloatingIpSetupException
IpTablesApplyException = l3.IpTablesApplyException
AbortSyncRouters = l3.AbortSyncRouters

View File

@ -14,11 +14,11 @@
# under the License.
from neutron_lib.db import api as db_api
from neutron_lib.exceptions import qos as qos_exc
from neutron_lib.plugins import constants as plugin_constants
from neutron_lib.plugins import directory
from neutron_lib.services.qos import constants as qos_consts
from neutron.common import exceptions as n_exc
from neutron.core_extensions import base
from neutron.objects.qos import policy as policy_object
@ -42,7 +42,8 @@ class QosCoreResourceExtension(base.CoreResourceExtension):
Using is_accessible expresses these conditions.
"""
if not (policy_object.QosPolicy.is_accessible(context, old_policy)):
raise n_exc.PolicyRemoveAuthorizationError(policy_id=old_policy.id)
raise qos_exc.PolicyRemoveAuthorizationError(
policy_id=old_policy.id)
def _update_port_policy(self, context, port, port_changes):
old_policy = policy_object.QosPolicy.get_port_policy(

View File

@ -27,14 +27,13 @@ from neutron_lib.db import api as db_api
from neutron_lib.db import model_query
from neutron_lib.db import resource_extend
from neutron_lib.db import utils as db_utils
from neutron_lib import exceptions as n_exc
from neutron_lib import exceptions
from neutron_lib.utils import net
from oslo_config import cfg
from oslo_log import log as logging
from sqlalchemy.orm import exc
from neutron.common import constants as n_const
from neutron.common import exceptions
from neutron.db import common_db_mixin
from neutron.db import models_v2
from neutron.objects import base as base_obj
@ -225,7 +224,7 @@ class DbBasePluginCommon(common_db_mixin.CommonDbMixin):
try:
network = model_query.get_by_id(context, models_v2.Network, id)
except exc.NoResultFound:
raise n_exc.NetworkNotFound(net_id=id)
raise exceptions.NetworkNotFound(net_id=id)
return network
def _get_subnet(self, context, id):
@ -234,13 +233,13 @@ class DbBasePluginCommon(common_db_mixin.CommonDbMixin):
try:
subnet = model_query.get_by_id(context, models_v2.Subnet, id)
except exc.NoResultFound:
raise n_exc.SubnetNotFound(subnet_id=id)
raise exceptions.SubnetNotFound(subnet_id=id)
return subnet
def _get_subnet_object(self, context, id):
subnet = subnet_obj.Subnet.get_object(context, id=id)
if not subnet:
raise n_exc.SubnetNotFound(subnet_id=id)
raise exceptions.SubnetNotFound(subnet_id=id)
return subnet
def _get_subnetpool(self, context, id):
@ -254,7 +253,7 @@ class DbBasePluginCommon(common_db_mixin.CommonDbMixin):
try:
port = model_query.get_by_id(context, models_v2.Port, id)
except exc.NoResultFound:
raise n_exc.PortNotFound(port_id=id)
raise exceptions.PortNotFound(port_id=id)
return port
def _get_route_by_subnet(self, context, subnet_id):

View File

@ -44,7 +44,6 @@ from sqlalchemy import not_
from neutron._i18n import _
from neutron.api.rpc.agentnotifiers import l3_rpc_agent_api
from neutron.common import exceptions as n_exc
from neutron.common import ipv6_utils
from neutron.common import utils
from neutron.db import db_base_plugin_common
@ -100,7 +99,7 @@ def _update_subnetpool_dict(orig_pool, new_pool):
if not orig_ip_set.issubset(new_ip_set):
msg = _("Existing prefixes must be "
"a subset of the new prefixes")
raise n_exc.IllegalSubnetPoolPrefixUpdate(msg=msg)
raise exc.IllegalSubnetPoolPrefixUpdate(msg=msg)
new_ip_set.compact()
updated['prefixes'] = [str(prefix.cidr)
for prefix in new_ip_set.iter_cidrs()]
@ -245,7 +244,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
return
ports = ports.filter(models_v2.Port.tenant_id == tenant_id)
if ports.count():
raise n_exc.InvalidSharedSetting(network=network_id)
raise exc.InvalidSharedSetting(network=network_id)
def set_ipam_backend(self):
self.ipam = ipam_pluggable_backend.IpamPluggableBackend()
@ -292,7 +291,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
if rbac.target_tenant != '*'}
allowed_projects.add(network.project_id)
if project_ids - allowed_projects:
raise n_exc.InvalidSharedSetting(network=network.name)
raise exc.InvalidSharedSetting(network=network.name)
def _validate_ipv6_attributes(self, subnet, cur_subnet):
if cur_subnet:
@ -617,13 +616,13 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
ipal.ip_address == gateway_ip,
ipal.subnet_id == cur_subnet['id']).first()
if allocated and allocated.port_id:
raise n_exc.GatewayIpInUse(
raise exc.GatewayIpInUse(
ip_address=gateway_ip,
port_id=allocated.port_id)
if validators.is_attr_set(s.get('dns_nameservers')):
if len(s['dns_nameservers']) > cfg.CONF.max_dns_nameservers:
raise n_exc.DNSNameServersExhausted(
raise exc.DNSNameServersExhausted(
subnet_id=s.get('id', _('new subnet')),
quota=cfg.CONF.max_dns_nameservers)
for dns in s['dns_nameservers']:
@ -637,7 +636,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
if validators.is_attr_set(s.get('host_routes')):
if len(s['host_routes']) > cfg.CONF.max_subnet_host_routes:
raise n_exc.HostRoutesExhausted(
raise exc.HostRoutesExhausted(
subnet_id=s.get('id', _('new subnet')),
quota=cfg.CONF.max_subnet_host_routes)
# check if the routes are all valid
@ -1102,14 +1101,14 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
if not self.is_address_scope_owned_by_tenant(context,
address_scope_id):
raise n_exc.IllegalSubnetPoolAssociationToAddressScope(
raise exc.IllegalSubnetPoolAssociationToAddressScope(
subnetpool_id=subnetpool_id, address_scope_id=address_scope_id)
as_ip_version = self.get_ip_version_for_address_scope(context,
address_scope_id)
if ip_version != as_ip_version:
raise n_exc.IllegalSubnetPoolIpVersionAssociationToAddressScope(
raise exc.IllegalSubnetPoolIpVersionAssociationToAddressScope(
subnetpool_id=subnetpool_id, address_scope_id=address_scope_id,
ip_version=as_ip_version)
@ -1122,7 +1121,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
continue
sp_set = netaddr.IPSet(sp.prefixes)
if sp_set.intersection(new_set):
raise n_exc.AddressScopePrefixConflict()
raise exc.AddressScopePrefixConflict()
def _check_subnetpool_update_allowed(self, context, subnetpool_id,
address_scope_id):
@ -1139,7 +1138,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
"%(address_scope_id)s") % {
'subnetpool_id': subnetpool_id,
'address_scope_id': address_scope_id}
raise n_exc.IllegalSubnetPoolUpdate(reason=msg)
raise exc.IllegalSubnetPoolUpdate(reason=msg)
def _check_default_subnetpool_exists(self, context, ip_version):
"""Check if a default already exists for the given IP version.
@ -1252,14 +1251,14 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
subnetpool = self._get_subnetpool(context, id=id)
if subnet_obj.Subnet.objects_exist(context, subnetpool_id=id):
reason = _("Subnet pool has existing allocations")
raise n_exc.SubnetPoolDeleteError(reason=reason)
raise exc.SubnetPoolDeleteError(reason=reason)
subnetpool.delete()
def _check_mac_addr_update(self, context, port, new_mac, device_owner):
if (device_owner and
device_owner.startswith(
constants.DEVICE_OWNER_NETWORK_PREFIX)):
raise n_exc.UnsupportedPortDeviceOwner(
raise exc.UnsupportedPortDeviceOwner(
op=_("mac address update"), port_id=id,
device_owner=device_owner)
@ -1539,7 +1538,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
return
else:
# raise as extension doesn't support L3 anyways.
raise n_exc.DeviceIDNotOwnedByTenant(
raise exc.DeviceIDNotOwnedByTenant(
device_id=device_id)
if tenant_id != router['tenant_id']:
raise n_exc.DeviceIDNotOwnedByTenant(device_id=device_id)
raise exc.DeviceIDNotOwnedByTenant(device_id=device_id)

View File

@ -30,7 +30,6 @@ from oslo_log import log as logging
from sqlalchemy.orm import exc as orm_exc
from neutron._i18n import _
from neutron.common import exceptions as n_exc
from neutron.common import ipv6_utils
from neutron.common import utils as common_utils
from neutron.db import db_base_plugin_common
@ -70,7 +69,7 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
"%(start)s - %(end)s:",
{'start': ip_pool['start'],
'end': ip_pool['end']})
raise n_exc.InvalidAllocationPool(pool=ip_pool)
raise exc.InvalidAllocationPool(pool=ip_pool)
return ip_range_pools
def delete_subnet(self, context, subnet_id):
@ -257,7 +256,7 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
for subnet in network.subnets:
if (subnet.ip_version == ip_version and
new_subnetpool_id != subnet.subnetpool_id):
raise n_exc.NetworkSubnetPoolAffinityError()
raise exc.NetworkSubnetPoolAffinityError()
def validate_allocation_pools(self, ip_pools, subnet_cidr):
"""Validate IP allocation pools.
@ -281,12 +280,12 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
end_ip.version != subnet.version):
LOG.info("Specified IP addresses do not match "
"the subnet IP version")
raise n_exc.InvalidAllocationPool(pool=ip_pool)
raise exc.InvalidAllocationPool(pool=ip_pool)
if start_ip < subnet_first_ip or end_ip > subnet_last_ip:
LOG.info("Found pool larger than subnet "
"CIDR:%(start)s - %(end)s",
{'start': start_ip, 'end': end_ip})
raise n_exc.OutOfBoundsAllocationPool(
raise exc.OutOfBoundsAllocationPool(
pool=ip_pool,
subnet_cidr=subnet_cidr)
# Valid allocation pool
@ -307,7 +306,7 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
LOG.info("Found overlapping ranges: %(l_range)s and "
"%(r_range)s",
{'l_range': l_range, 'r_range': r_range})
raise n_exc.OverlappingAllocationPools(
raise exc.OverlappingAllocationPools(
pool_1=l_range,
pool_2=r_range,
subnet_cidr=subnet_cidr)
@ -401,7 +400,7 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
def validate_gw_out_of_pools(self, gateway_ip, pools):
for pool_range in pools:
if netaddr.IPAddress(gateway_ip) in pool_range:
raise n_exc.GatewayConflictWithAllocationPools(
raise exc.GatewayConflictWithAllocationPools(
pool=pool_range,
ip_address=gateway_ip)

View File

@ -20,7 +20,6 @@ from neutron_lib.plugins import constants
from neutron_lib.plugins import directory
from oslo_log import log
from neutron.common import exceptions as n_exc
from neutron.db.quota import api as quota_api
from neutron.objects import quota as quota_obj
from neutron.quota import resource as res
@ -122,7 +121,7 @@ class DbQuotaDriver(object):
if quota_obj.Quota.delete_objects(
context, project_id=tenant_id) < 1:
# No record deleted means the quota was not found
raise n_exc.TenantQuotaNotFound(tenant_id=tenant_id)
raise exceptions.TenantQuotaNotFound(tenant_id=tenant_id)
@staticmethod
@db_api.retry_if_session_inactive()
@ -300,7 +299,7 @@ class DbQuotaDriver(object):
# Ensure no value is less than zero
unders = [key for key, val in values.items() if val < 0]
if unders:
raise n_exc.InvalidQuotaValue(unders=sorted(unders))
raise exceptions.InvalidQuotaValue(unders=sorted(unders))
# Get the applicable quotas
quotas = self._get_quotas(context, tenant_id, resources)

View File

@ -17,7 +17,7 @@ from neutron_lib.api import converters
from neutron_lib.api import extensions as api_extensions
from neutron_lib.api import faults
from neutron_lib.db import constants as const
from neutron_lib import exceptions as n_exc
from neutron_lib import exceptions
from neutron_lib.plugins import directory
from oslo_config import cfg
from oslo_utils import importutils
@ -27,7 +27,6 @@ from neutron._i18n import _
from neutron.api import extensions
from neutron.api.v2 import base
from neutron.api.v2 import resource
from neutron.common import exceptions
from neutron import quota
from neutron.quota import resource_registry
from neutron import wsgi
@ -108,7 +107,7 @@ class QuotaSetsController(wsgi.Controller):
def _check_admin(self, context,
reason=_("Only admin can view or configure quota")):
if not context.is_admin:
raise n_exc.AdminRequired(reason=reason)
raise exceptions.AdminRequired(reason=reason)
def delete(self, request, id):
self._check_admin(request.context)

View File

@ -21,7 +21,7 @@ from neutron_lib.api import extensions as api_extensions
from neutron_lib.api import validators
from neutron_lib import constants as const
from neutron_lib.db import constants as db_const
from neutron_lib import exceptions as nexception
from neutron_lib import exceptions
from neutron_lib.plugins import directory
from oslo_utils import netutils
import six
@ -29,43 +29,42 @@ import six
from neutron._i18n import _
from neutron.api import extensions
from neutron.api.v2 import base
from neutron.common import exceptions
from neutron.conf import quota
from neutron.extensions import standardattrdescription as stdattr_ext
from neutron.quota import resource_registry
# Security group Exceptions
class SecurityGroupInvalidPortRange(nexception.InvalidInput):
class SecurityGroupInvalidPortRange(exceptions.InvalidInput):
message = _("For TCP/UDP protocols, port_range_min must be "
"<= port_range_max")
class SecurityGroupInvalidProtocolForPortRange(nexception.InvalidInput):
class SecurityGroupInvalidProtocolForPortRange(exceptions.InvalidInput):
message = _("Invalid protocol %(protocol)s for port range, only "
"supported for TCP, UDP, UDPLITE, SCTP and DCCP.")
class SecurityGroupInvalidPortValue(nexception.InvalidInput):
class SecurityGroupInvalidPortValue(exceptions.InvalidInput):
message = _("Invalid value for port %(port)s")
class SecurityGroupInvalidIcmpValue(nexception.InvalidInput):
class SecurityGroupInvalidIcmpValue(exceptions.InvalidInput):
message = _("Invalid value for ICMP %(field)s (%(attr)s) "
"%(value)s. It must be 0 to 255.")
class SecurityGroupEthertypeConflictWithProtocol(nexception.InvalidInput):
class SecurityGroupEthertypeConflictWithProtocol(exceptions.InvalidInput):
message = _("Invalid ethertype %(ethertype)s for protocol "
"%(protocol)s.")
class SecurityGroupMissingIcmpType(nexception.InvalidInput):
class SecurityGroupMissingIcmpType(exceptions.InvalidInput):
message = _("ICMP code (port-range-max) %(value)s is provided"
" but ICMP type (port-range-min) is missing.")
class SecurityGroupInUse(nexception.InUse):
class SecurityGroupInUse(exceptions.InUse):
message = _("Security Group %(id)s %(reason)s.")
def __init__(self, **kwargs):
@ -74,60 +73,60 @@ class SecurityGroupInUse(nexception.InUse):
super(SecurityGroupInUse, self).__init__(**kwargs)
class SecurityGroupCannotRemoveDefault(nexception.InUse):
class SecurityGroupCannotRemoveDefault(exceptions.InUse):
message = _("Insufficient rights for removing default security group.")
class SecurityGroupCannotUpdateDefault(nexception.InUse):
class SecurityGroupCannotUpdateDefault(exceptions.InUse):
message = _("Updating default security group not allowed.")
class SecurityGroupDefaultAlreadyExists(nexception.InUse):
class SecurityGroupDefaultAlreadyExists(exceptions.InUse):
message = _("Default security group already exists.")
class SecurityGroupRuleInvalidProtocol(nexception.InvalidInput):
class SecurityGroupRuleInvalidProtocol(exceptions.InvalidInput):
message = _("Security group rule protocol %(protocol)s not supported. "
"Only protocol values %(values)s and integer representations "
"[0 to 255] are supported.")
class SecurityGroupRulesNotSingleTenant(nexception.InvalidInput):
class SecurityGroupRulesNotSingleTenant(exceptions.InvalidInput):
message = _("Multiple tenant_ids in bulk security group rule create"
" not allowed")
class SecurityGroupRemoteGroupAndRemoteIpPrefix(nexception.InvalidInput):
class SecurityGroupRemoteGroupAndRemoteIpPrefix(exceptions.InvalidInput):
message = _("Only remote_ip_prefix or remote_group_id may "
"be provided.")
class SecurityGroupProtocolRequiredWithPorts(nexception.InvalidInput):
class SecurityGroupProtocolRequiredWithPorts(exceptions.InvalidInput):
message = _("Must also specify protocol if port range is given.")
class SecurityGroupNotSingleGroupRules(nexception.InvalidInput):
class SecurityGroupNotSingleGroupRules(exceptions.InvalidInput):
message = _("Only allowed to update rules for "
"one security profile at a time")
class SecurityGroupNotFound(nexception.NotFound):
class SecurityGroupNotFound(exceptions.NotFound):
message = _("Security group %(id)s does not exist")
class SecurityGroupRuleNotFound(nexception.NotFound):
class SecurityGroupRuleNotFound(exceptions.NotFound):
message = _("Security group rule %(id)s does not exist")
class DuplicateSecurityGroupRuleInPost(nexception.InUse):
class DuplicateSecurityGroupRuleInPost(exceptions.InUse):
message = _("Duplicate Security Group Rule in POST.")
class SecurityGroupRuleExists(nexception.InUse):
class SecurityGroupRuleExists(exceptions.InUse):
message = _("Security group rule already exists. Rule id is %(rule_id)s.")
class SecurityGroupRuleInUse(nexception.InUse):
class SecurityGroupRuleInUse(exceptions.InUse):
message = _("Security Group Rule %(id)s %(reason)s.")
def __init__(self, **kwargs):
@ -136,15 +135,15 @@ class SecurityGroupRuleInUse(nexception.InUse):
super(SecurityGroupRuleInUse, self).__init__(**kwargs)
class SecurityGroupRuleParameterConflict(nexception.InvalidInput):
class SecurityGroupRuleParameterConflict(exceptions.InvalidInput):
message = _("Conflicting value ethertype %(ethertype)s for CIDR %(cidr)s")
class SecurityGroupConflict(nexception.Conflict):
class SecurityGroupConflict(exceptions.Conflict):
message = _("Error %(reason)s while attempting the operation.")
class SecurityGroupRuleInvalidEtherType(nexception.InvalidInput):
class SecurityGroupRuleInvalidEtherType(exceptions.InvalidInput):
message = _("Security group rule for ethertype '%(ethertype)s' not "
"supported. Allowed values are %(values)s.")

View File

@ -19,12 +19,11 @@ import operator
import netaddr
from neutron_lib import constants
from neutron_lib.db import api as db_api
from neutron_lib import exceptions as lib_exc
from neutron_lib import exceptions
from oslo_db import exception as db_exc
from oslo_utils import uuidutils
from neutron._i18n import _
from neutron.common import exceptions as n_exc
from neutron.db import models_v2
from neutron.ipam import driver
from neutron.ipam import exceptions as ipam_exc
@ -56,7 +55,7 @@ class SubnetAllocator(driver.Pool):
.filter_by(id=self._subnetpool['id']).scalar())
if current_hash is None:
# NOTE(cbrandily): subnetpool has been deleted
raise n_exc.SubnetPoolNotFound(
raise exceptions.SubnetPoolNotFound(
subnetpool_id=self._subnetpool['id'])
new_hash = uuidutils.generate_uuid()
@ -70,7 +69,7 @@ class SubnetAllocator(driver.Pool):
count = query.update({'hash': new_hash})
if not count:
raise db_exc.RetryRequest(lib_exc.SubnetPoolInUse(
raise db_exc.RetryRequest(exceptions.SubnetPoolInUse(
subnet_pool_id=self._subnetpool['id']))
def _get_allocated_cidrs(self):
@ -118,7 +117,7 @@ class SubnetAllocator(driver.Pool):
quota_unit)
if used + requested_units > quota:
raise n_exc.SubnetPoolQuotaExceeded()
raise exceptions.SubnetPoolQuotaExceeded()
def _allocate_any_subnet(self, request):
with db_api.CONTEXT_WRITER.using(self._context):
@ -141,8 +140,8 @@ class SubnetAllocator(driver.Pool):
gateway_ip=gateway_ip,
allocation_pools=pools)
msg = _("Insufficient prefix space to allocate subnet size /%s")
raise n_exc.SubnetAllocationError(reason=msg %
str(request.prefixlen))
raise exceptions.SubnetAllocationError(
reason=msg % str(request.prefixlen))
def _allocate_specific_subnet(self, request):
with db_api.CONTEXT_WRITER.using(self._context):
@ -160,17 +159,17 @@ class SubnetAllocator(driver.Pool):
allocation_pools=request.allocation_pools)
msg = _("Cannot allocate requested subnet from the available "
"set of prefixes")
raise n_exc.SubnetAllocationError(reason=msg)
raise exceptions.SubnetAllocationError(reason=msg)
def allocate_subnet(self, request):
max_prefixlen = int(self._subnetpool['max_prefixlen'])
min_prefixlen = int(self._subnetpool['min_prefixlen'])
if request.prefixlen > max_prefixlen:
raise n_exc.MaxPrefixSubnetAllocationError(
raise exceptions.MaxPrefixSubnetAllocationError(
prefixlen=request.prefixlen,
max_prefixlen=max_prefixlen)
if request.prefixlen < min_prefixlen:
raise n_exc.MinPrefixSubnetAllocationError(
raise exceptions.MinPrefixSubnetAllocationError(
prefixlen=request.prefixlen,
min_prefixlen=min_prefixlen)
@ -180,7 +179,7 @@ class SubnetAllocator(driver.Pool):
return self._allocate_specific_subnet(request)
else:
msg = _("Unsupported request type")
raise n_exc.SubnetAllocationError(reason=msg)
raise exceptions.SubnetAllocationError(reason=msg)
def get_subnet(self, subnet_id):
raise NotImplementedError()
@ -336,14 +335,14 @@ class SubnetPoolReader(object):
def _read_prefix_info(self, subnetpool):
prefix_list = subnetpool['prefixes']
if not prefix_list:
raise n_exc.EmptySubnetPoolPrefixList()
raise exceptions.EmptySubnetPoolPrefixList()
ip_version = None
for prefix in prefix_list:
if not ip_version:
ip_version = netaddr.IPNetwork(prefix).version
elif netaddr.IPNetwork(prefix).version != ip_version:
raise n_exc.PrefixVersionMismatch()
raise exceptions.PrefixVersionMismatch()
self.default_quota = subnetpool.get('default_quota')
if self.default_quota is constants.ATTR_NOT_SPECIFIED:
@ -385,10 +384,10 @@ class SubnetPoolHelper(object):
def validate_min_prefixlen(self, min_prefixlen, max_prefixlen):
if min_prefixlen < 0:
raise n_exc.UnsupportedMinSubnetPoolPrefix(prefix=min_prefixlen,
version=4)
raise exceptions.UnsupportedMinSubnetPoolPrefix(
prefix=min_prefixlen, version=4)
if min_prefixlen > max_prefixlen:
raise n_exc.IllegalSubnetPoolPrefixBounds(
raise exceptions.IllegalSubnetPoolPrefixBounds(
prefix_type='min_prefixlen',
prefixlen=min_prefixlen,
base_prefix_type='max_prefixlen',
@ -397,7 +396,7 @@ class SubnetPoolHelper(object):
def validate_max_prefixlen(self, prefixlen, ip_version):
max = self._PREFIX_VERSION_INFO[ip_version]['max_prefixlen']
if prefixlen > max:
raise n_exc.IllegalSubnetPoolPrefixBounds(
raise exceptions.IllegalSubnetPoolPrefixBounds(
prefix_type='max_prefixlen',
prefixlen=prefixlen,
base_prefix_type='ip_version_max',
@ -408,13 +407,13 @@ class SubnetPoolHelper(object):
max_prefixlen,
default_prefixlen):
if default_prefixlen < min_prefixlen:
raise n_exc.IllegalSubnetPoolPrefixBounds(
raise exceptions.IllegalSubnetPoolPrefixBounds(
prefix_type='default_prefixlen',
prefixlen=default_prefixlen,
base_prefix_type='min_prefixlen',
base_prefixlen=min_prefixlen)
if default_prefixlen > max_prefixlen:
raise n_exc.IllegalSubnetPoolPrefixBounds(
raise exceptions.IllegalSubnetPoolPrefixBounds(
prefix_type='default_prefixlen',
prefixlen=default_prefixlen,
base_prefix_type='max_prefixlen',

View File

@ -16,12 +16,12 @@
import itertools
from neutron_lib import constants as n_const
from neutron_lib.exceptions import qos as qos_exc
from oslo_db import exception as db_exc
from oslo_utils import versionutils
from oslo_versionedobjects import exception
from oslo_versionedobjects import fields as obj_fields
from neutron.common import exceptions
from neutron.db.models import l3
from neutron.db import models_v2
from neutron.db.qos import models as qos_db_model