Browse Source

Use exceptions from neutron-lib

Related-Blueprint: neutron-lib

Change-Id: Ia014468bd621c4ee6aea95bf19328c61070174c4
changes/61/308461/5
Henry Gessau 6 years ago
parent
commit
ae5bad49cc
  1. 2
      neutron/agent/common/ovs_lib.py
  2. 2
      neutron/agent/dhcp/agent.py
  3. 2
      neutron/agent/l2/extensions/qos.py
  4. 5
      neutron/agent/linux/dhcp.py
  5. 7
      neutron/agent/linux/ip_lib.py
  6. 2
      neutron/agent/linux/ip_link_support.py
  7. 2
      neutron/agent/linux/keepalived.py
  8. 2
      neutron/agent/linux/openvswitch_firewall/firewall.py
  9. 3
      neutron/agent/linux/tc_lib.py
  10. 2
      neutron/agent/ovsdb/native/idlutils.py
  11. 2
      neutron/api/api_common.py
  12. 3
      neutron/api/rpc/callbacks/exceptions.py
  13. 15
      neutron/api/rpc/handlers/dhcp_rpc.py
  14. 2
      neutron/api/rpc/handlers/l3_rpc.py
  15. 2
      neutron/api/rpc/handlers/resources_rpc.py
  16. 2
      neutron/api/v2/attributes.py
  17. 5
      neutron/api/v2/base.py
  18. 2
      neutron/api/v2/resource.py
  19. 3
      neutron/callbacks/exceptions.py
  20. 2
      neutron/common/rpc.py
  21. 2
      neutron/db/api.py
  22. 2
      neutron/db/bgp_db.py
  23. 5
      neutron/db/db_base_plugin_common.py
  24. 67
      neutron/db/db_base_plugin_v2.py
  25. 2
      neutron/db/dns_db.py
  26. 2
      neutron/db/dvr_mac_db.py
  27. 2
      neutron/db/external_net_db.py
  28. 21
      neutron/db/ipam_backend_mixin.py
  29. 2
      neutron/db/ipam_non_pluggable_backend.py
  30. 2
      neutron/db/ipam_pluggable_backend.py
  31. 2
      neutron/db/l3_db.py
  32. 2
      neutron/db/l3_dvr_db.py
  33. 2
      neutron/db/l3_hamode_db.py
  34. 2
      neutron/db/migration/alembic_migrations/versions/mitaka/expand/1df244e556f5_add_unique_ha_router_agent_port_bindings.py
  35. 7
      neutron/db/quota/driver.py
  36. 2
      neutron/db/rbac_db_mixin.py
  37. 2
      neutron/db/rbac_db_models.py
  38. 2
      neutron/db/sqlalchemyutils.py
  39. 2
      neutron/extensions/address_scope.py
  40. 3
      neutron/extensions/agent.py
  41. 2
      neutron/extensions/allowedaddresspairs.py
  42. 2
      neutron/extensions/availability_zone.py
  43. 4
      neutron/extensions/bgp.py
  44. 2
      neutron/extensions/bgp_dragentscheduler.py
  45. 3
      neutron/extensions/dhcpagentscheduler.py
  46. 2
      neutron/extensions/dns.py
  47. 2
      neutron/extensions/dvr.py
  48. 3
      neutron/extensions/external_net.py
  49. 3
      neutron/extensions/extra_dhcp_opt.py
  50. 3
      neutron/extensions/extraroute.py
  51. 3
      neutron/extensions/flavors.py
  52. 2
      neutron/extensions/l3.py
  53. 5
      neutron/extensions/l3_ext_ha_mode.py
  54. 2
      neutron/extensions/l3agentscheduler.py
  55. 2
      neutron/extensions/metering.py
  56. 2
      neutron/extensions/multiprovidernet.py
  57. 3
      neutron/extensions/portsecurity.py
  58. 3
      neutron/extensions/providernet.py
  59. 5
      neutron/extensions/quotasv2.py
  60. 3
      neutron/extensions/rbac.py
  61. 5
      neutron/extensions/securitygroup.py
  62. 2
      neutron/extensions/tag.py
  63. 4
      neutron/extensions/vlantransparent.py
  64. 2
      neutron/ipam/drivers/neutrondb_ipam/driver.py
  65. 3
      neutron/ipam/exceptions.py
  66. 3
      neutron/ipam/subnet_alloc.py
  67. 3
      neutron/objects/rbac_db.py
  68. 2
      neutron/pecan_wsgi/app.py
  69. 2
      neutron/pecan_wsgi/controllers/quota.py
  70. 5
      neutron/plugins/common/utils.py
  71. 3
      neutron/plugins/ml2/common/exceptions.py
  72. 2
      neutron/plugins/ml2/drivers/l2pop/db.py
  73. 5
      neutron/plugins/ml2/drivers/mech_sriov/agent/common/exceptions.py
  74. 3
      neutron/plugins/ml2/drivers/mech_sriov/mech_driver/exceptions.py
  75. 5
      neutron/plugins/ml2/drivers/type_flat.py
  76. 2
      neutron/plugins/ml2/drivers/type_geneve.py
  77. 2
      neutron/plugins/ml2/drivers/type_gre.py
  78. 2
      neutron/plugins/ml2/drivers/type_local.py
  79. 2
      neutron/plugins/ml2/drivers/type_tunnel.py
  80. 2
      neutron/plugins/ml2/drivers/type_vlan.py
  81. 2
      neutron/plugins/ml2/drivers/type_vxlan.py
  82. 2
      neutron/plugins/ml2/managers.py
  83. 2
      neutron/plugins/ml2/plugin.py
  84. 2
      neutron/plugins/ml2/rpc.py
  85. 3
      neutron/policy.py
  86. 5
      neutron/quota/__init__.py
  87. 5
      neutron/services/auto_allocate/db.py
  88. 3
      neutron/services/auto_allocate/exceptions.py
  89. 3
      neutron/services/bgp/driver/exceptions.py
  90. 2
      neutron/services/provider_configuration.py
  91. 2
      neutron/services/timestamp/timestamp_db.py
  92. 2
      neutron/tests/base.py
  93. 2
      neutron/tests/functional/db/test_ipam.py
  94. 2
      neutron/tests/functional/pecan_wsgi/test_functional.py
  95. 2
      neutron/tests/retargetable/client_fixtures.py
  96. 2
      neutron/tests/unit/agent/common/test_ovs_lib.py
  97. 2
      neutron/tests/unit/agent/dhcp/test_agent.py
  98. 2
      neutron/tests/unit/agent/l2/extensions/test_qos.py
  99. 5
      neutron/tests/unit/agent/l3/test_agent.py
  100. 5
      neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py
  101. Some files were not shown because too many files have changed in this diff Show More

2
neutron/agent/common/ovs_lib.py

@ -19,6 +19,7 @@ import operator
import time
import uuid
from neutron_lib import exceptions
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import excutils
@ -29,7 +30,6 @@ from neutron._i18n import _, _LE, _LI, _LW
from neutron.agent.common import utils
from neutron.agent.linux import ip_lib
from neutron.agent.ovsdb import api as ovsdb
from neutron.common import exceptions
from neutron.plugins.common import constants as p_const
from neutron.plugins.ml2.drivers.openvswitch.agent.common \
import constants

2
neutron/agent/dhcp/agent.py

@ -17,6 +17,7 @@ import collections
import os
import eventlet
from neutron_lib import exceptions
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging
@ -29,7 +30,6 @@ from neutron.agent.linux import external_process
from neutron.agent.metadata import driver as metadata_driver
from neutron.agent import rpc as agent_rpc
from neutron.common import constants
from neutron.common import exceptions
from neutron.common import rpc as n_rpc
from neutron.common import topics
from neutron.common import utils

2
neutron/agent/l2/extensions/qos.py

@ -16,6 +16,7 @@
import abc
import collections
from neutron_lib import exceptions
from oslo_concurrency import lockutils
from oslo_log import log as logging
import six
@ -26,7 +27,6 @@ from neutron.api.rpc.callbacks.consumer import registry
from neutron.api.rpc.callbacks import events
from neutron.api.rpc.callbacks import resources
from neutron.api.rpc.handlers import resources_rpc
from neutron.common import exceptions
from neutron import manager
LOG = logging.getLogger(__name__)

5
neutron/agent/linux/dhcp.py

@ -21,6 +21,7 @@ import shutil
import time
import netaddr
from neutron_lib import exceptions
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging
@ -34,7 +35,7 @@ from neutron.agent.linux import external_process
from neutron.agent.linux import ip_lib
from neutron.agent.linux import iptables_manager
from neutron.common import constants
from neutron.common import exceptions
from neutron.common import exceptions as n_exc
from neutron.common import ipv6_utils
from neutron.common import utils as common_utils
from neutron.extensions import extra_dhcp_opt as edo_ext
@ -1129,7 +1130,7 @@ class DeviceManager(object):
port.id, {'port': {'network_id': network.id,
'device_id': device_id}})
except oslo_messaging.RemoteError as e:
if e.exc_type == exceptions.DhcpPortInUse:
if e.exc_type == n_exc.DhcpPortInUse:
LOG.info(_LI("Skipping DHCP port %s as it is "
"already in use"), port.id)
continue

7
neutron/agent/linux/ip_lib.py

@ -18,6 +18,7 @@ import re
import eventlet
import netaddr
from neutron_lib import exceptions
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import excutils
@ -26,7 +27,7 @@ import six
from neutron._i18n import _, _LE
from neutron.agent.common import utils
from neutron.common import constants
from neutron.common import exceptions
from neutron.common import exceptions as n_exc
LOG = logging.getLogger(__name__)
@ -239,7 +240,7 @@ class IPWrapper(SubProcessBase):
if port and len(port) == 2:
cmd.extend(['port', port[0], port[1]])
elif port:
raise exceptions.NetworkVxlanPortRangeError(vxlan_range=port)
raise n_exc.NetworkVxlanPortRangeError(vxlan_range=port)
self._as_root([], 'link', cmd)
return (IPDevice(name, namespace=self.namespace))
@ -699,7 +700,7 @@ class IpRouteCommand(IpDeviceCommandBase):
with excutils.save_and_reraise_exception() as ctx:
if "Cannot find device" in str(rte):
ctx.reraise = False
raise exceptions.DeviceNotFoundError(device_name=self.name)
raise n_exc.DeviceNotFoundError(device_name=self.name)
def delete_gateway(self, gateway, table=None):
ip_version = get_ip_version(gateway)

2
neutron/agent/linux/ip_link_support.py

@ -15,11 +15,11 @@
import re
from neutron_lib import exceptions as n_exc
from oslo_log import log as logging
from neutron._i18n import _, _LE
from neutron.agent.linux import utils
from neutron.common import exceptions as n_exc
LOG = logging.getLogger(__name__)

2
neutron/agent/linux/keepalived.py

@ -17,13 +17,13 @@ import itertools
import os
import netaddr
from neutron_lib import exceptions
from oslo_config import cfg
from oslo_log import log as logging
from neutron._i18n import _, _LE
from neutron.agent.linux import external_process
from neutron.common import constants
from neutron.common import exceptions
from neutron.common import utils as common_utils
VALID_STATES = ['MASTER', 'BACKUP']

2
neutron/agent/linux/openvswitch_firewall/firewall.py

@ -14,6 +14,7 @@
# under the License.
import netaddr
from neutron_lib import exceptions
from oslo_log import log as logging
from neutron._i18n import _, _LE, _LW
@ -21,7 +22,6 @@ from neutron.agent import firewall
from neutron.agent.linux.openvswitch_firewall import constants as ovsfw_consts
from neutron.agent.linux.openvswitch_firewall import rules
from neutron.common import constants
from neutron.common import exceptions
from neutron.common import ipv6_utils
from neutron.plugins.ml2.drivers.openvswitch.agent.common import constants \
as ovs_consts

3
neutron/agent/linux/tc_lib.py

@ -15,9 +15,10 @@
import re
from neutron_lib import exceptions
from neutron._i18n import _
from neutron.agent.linux import ip_lib
from neutron.common import exceptions
INGRESS_QDISC_ID = "ffff:"

2
neutron/agent/ovsdb/native/idlutils.py

@ -17,13 +17,13 @@ import os
import time
import uuid
from neutron_lib import exceptions
from ovs.db import idl
from ovs import jsonrpc
from ovs import poller
from ovs import stream
from neutron._i18n import _
from neutron.common import exceptions
RowLookup = collections.namedtuple('RowLookup',

2
neutron/api/api_common.py

@ -15,6 +15,7 @@
import functools
from neutron_lib import exceptions
from oslo_config import cfg
from oslo_log import log as logging
from six.moves.urllib import parse
@ -22,7 +23,6 @@ from webob import exc
from neutron._i18n import _, _LW
from neutron.common import constants
from neutron.common import exceptions
LOG = logging.getLogger(__name__)

3
neutron/api/rpc/callbacks/exceptions.py

@ -10,8 +10,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import exceptions
from neutron._i18n import _
from neutron.common import exceptions
class CallbackWrongResourceType(exceptions.NeutronException):

15
neutron/api/rpc/handlers/dhcp_rpc.py

@ -17,6 +17,7 @@ import copy
import itertools
import operator
from neutron_lib import exceptions
from oslo_config import cfg
from oslo_db import exception as db_exc
from oslo_log import log as logging
@ -91,18 +92,20 @@ class DhcpRpcCallback(object):
return plugin.update_port(context, port['id'], port)
else:
msg = _('Unrecognized action')
raise n_exc.Invalid(message=msg)
except (db_exc.DBError, n_exc.NetworkNotFound,
n_exc.SubnetNotFound, n_exc.IpAddressGenerationFailure) as e:
raise exceptions.Invalid(message=msg)
except (db_exc.DBError,
exceptions.NetworkNotFound,
exceptions.SubnetNotFound,
exceptions.IpAddressGenerationFailure) as e:
with excutils.save_and_reraise_exception(reraise=False) as ctxt:
if isinstance(e, n_exc.IpAddressGenerationFailure):
if isinstance(e, exceptions.IpAddressGenerationFailure):
# Check if the subnet still exists and if it does not,
# this is the reason why the ip address generation failed.
# In any other unlikely event re-raise
try:
subnet_id = port['port']['fixed_ips'][0]['subnet_id']
plugin.get_subnet(context, subnet_id)
except n_exc.SubnetNotFound:
except exceptions.SubnetNotFound:
pass
else:
ctxt.reraise = True
@ -158,7 +161,7 @@ class DhcpRpcCallback(object):
plugin = manager.NeutronManager.get_plugin()
try:
network = plugin.get_network(context, network_id)
except n_exc.NetworkNotFound:
except exceptions.NetworkNotFound:
LOG.debug("Network %s could not be found, it might have "
"been deleted concurrently.", network_id)
return

2
neutron/api/rpc/handlers/l3_rpc.py

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from neutron_lib import exceptions
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging
@ -20,7 +21,6 @@ from oslo_serialization import jsonutils
import six
from neutron.common import constants
from neutron.common import exceptions
from neutron.common import utils
from neutron import context as neutron_context
from neutron.db import api as db_api

2
neutron/api/rpc/handlers/resources_rpc.py

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import exceptions
from oslo_log import helpers as log_helpers
from oslo_log import log as logging
import oslo_messaging
@ -23,7 +24,6 @@ from neutron.api.rpc.callbacks.producer import registry as prod_registry
from neutron.api.rpc.callbacks import resources
from neutron.api.rpc.callbacks import version_manager
from neutron.common import constants
from neutron.common import exceptions
from neutron.common import rpc as n_rpc
from neutron.common import topics
from neutron.objects import base as obj_base

2
neutron/api/v2/attributes.py

@ -17,6 +17,7 @@ import functools
import re
import netaddr
from neutron_lib import exceptions as n_exc
from oslo_log import log as logging
from oslo_utils import uuidutils
import six
@ -24,7 +25,6 @@ import webob.exc
from neutron._i18n import _
from neutron.common import constants
from neutron.common import exceptions as n_exc
LOG = logging.getLogger(__name__)

5
neutron/api/v2/base.py

@ -17,6 +17,7 @@ import collections
import copy
import netaddr
from neutron_lib import exceptions
from oslo_config import cfg
from oslo_log import log as logging
from oslo_policy import policy as oslo_policy
@ -30,7 +31,7 @@ from neutron.api.rpc.agentnotifiers import dhcp_rpc_agent_api
from neutron.api.v2 import attributes
from neutron.api.v2 import resource as wsgi_resource
from neutron.common import constants as const
from neutron.common import exceptions
from neutron.common import exceptions as n_exc
from neutron.common import rpc as n_rpc
from neutron.db import api as db_api
from neutron import policy
@ -453,7 +454,7 @@ class Controller(object):
{self._resource: delta},
self._plugin)
reservations.append(reservation)
except exceptions.QuotaResourceUnknown as e:
except n_exc.QuotaResourceUnknown as e:
# We don't want to quota this resource
LOG.debug(e)

2
neutron/api/v2/resource.py

@ -20,6 +20,7 @@ Utility methods for working with WSGI servers redux
import sys
import netaddr
from neutron_lib import exceptions
import oslo_i18n
from oslo_log import log as logging
from oslo_policy import policy as oslo_policy
@ -28,7 +29,6 @@ import webob.dec
import webob.exc
from neutron._i18n import _, _LE, _LI
from neutron.common import exceptions
from neutron import wsgi

3
neutron/callbacks/exceptions.py

@ -10,8 +10,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import exceptions
from neutron._i18n import _
from neutron.common import exceptions
class Invalid(exceptions.NeutronException):

2
neutron/common/rpc.py

@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import exceptions as lib_exceptions
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging
@ -33,6 +34,7 @@ NOTIFIER = None
ALLOWED_EXMODS = [
exceptions.__name__,
lib_exceptions.__name__,
]
EXTRA_EXMODS = []

2
neutron/db/api.py

@ -16,6 +16,7 @@
import contextlib
import debtcollector
from neutron_lib import exceptions as n_exc
from oslo_config import cfg
from oslo_db import api as oslo_db_api
from oslo_db import exception as db_exc
@ -23,7 +24,6 @@ from oslo_db.sqlalchemy import session
from oslo_utils import excutils
from oslo_utils import uuidutils
from neutron.common import exceptions as n_exc
from neutron.db import common_db_mixin

2
neutron/db/bgp_db.py

@ -14,6 +14,7 @@
import itertools
from neutron_lib import exceptions as n_exc
from oslo_db import exception as oslo_db_exc
from oslo_log import log as logging
from oslo_utils import uuidutils
@ -27,7 +28,6 @@ from neutron_lib import constants as lib_consts
from neutron._i18n import _
from neutron.api.v2 import attributes as attr
from neutron.common import exceptions as n_exc
from neutron.db import address_scope_db
from neutron.db import common_db_mixin as common_db
from neutron.db import l3_attrs_db

5
neutron/db/db_base_plugin_common.py

@ -15,13 +15,14 @@
import functools
from neutron_lib import exceptions as n_exc
from oslo_config import cfg
from oslo_log import log as logging
from sqlalchemy.orm import exc
from neutron.api.v2 import attributes
from neutron.common import constants
from neutron.common import exceptions as n_exc
from neutron.common import exceptions
from neutron.common import utils
from neutron.db import common_db_mixin
from neutron.db import models_v2
@ -207,7 +208,7 @@ class DbBasePluginCommon(common_db_mixin.CommonDbMixin):
try:
return self._get_by_id(context, models_v2.SubnetPool, id)
except exc.NoResultFound:
raise n_exc.SubnetPoolNotFound(subnetpool_id=id)
raise exceptions.SubnetPoolNotFound(subnetpool_id=id)
def _get_all_subnetpools(self, context):
# NOTE(tidwellr): see note in _get_all_subnets()

67
neutron/db/db_base_plugin_v2.py

@ -16,6 +16,7 @@
import functools
import netaddr
from neutron_lib import exceptions as exc
from oslo_config import cfg
from oslo_db import exception as db_exc
from oslo_log import log as logging
@ -76,7 +77,7 @@ def _check_subnet_not_used(context, subnet_id):
registry.notify(
resources.SUBNET, events.BEFORE_DELETE, None, **kwargs)
except exceptions.CallbackFailure as e:
raise n_exc.SubnetInUse(subnet_id=subnet_id, reason=e)
raise exc.SubnetInUse(subnet_id=subnet_id, reason=e)
class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
@ -138,7 +139,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
if not context.is_admin and net['tenant_id'] != context.tenant_id:
msg = _("Only admins can manipulate policies on networks "
"they do not own.")
raise n_exc.InvalidInput(error_message=msg)
raise exc.InvalidInput(error_message=msg)
tenant_to_check = None
if event == events.BEFORE_UPDATE:
@ -196,11 +197,11 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
netaddr.IPAddress(route['nexthop'])
except netaddr.core.AddrFormatError:
err_msg = _("Invalid route: %s") % route
raise n_exc.InvalidInput(error_message=err_msg)
raise exc.InvalidInput(error_message=err_msg)
except ValueError:
# netaddr.IPAddress would raise this
err_msg = _("Invalid route: %s") % route
raise n_exc.InvalidInput(error_message=err_msg)
raise exc.InvalidInput(error_message=err_msg)
self._validate_ip_version(ip_version, route['nexthop'], 'nexthop')
self._validate_ip_version(ip_version, route['destination'],
'destination')
@ -250,7 +251,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
msg = _('Invalid CIDR %s for IPv6 address mode. '
'OpenStack uses the EUI-64 address format, '
'which requires the prefix to be /64.')
raise n_exc.InvalidInput(
raise exc.InvalidInput(
error_message=(msg % subnet['cidr']))
def _validate_ipv6_combination(self, ra_mode, address_mode):
@ -259,13 +260,13 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
"set to '%(addr_mode)s' is not valid. "
"If both attributes are set, they must be the same value"
) % {'ra_mode': ra_mode, 'addr_mode': address_mode}
raise n_exc.InvalidInput(error_message=msg)
raise exc.InvalidInput(error_message=msg)
def _validate_ipv6_dhcp(self, ra_mode_set, address_mode_set, enable_dhcp):
if (ra_mode_set or address_mode_set) and not enable_dhcp:
msg = _("ipv6_ra_mode or ipv6_address_mode cannot be set when "
"enable_dhcp is set to False.")
raise n_exc.InvalidInput(error_message=msg)
raise exc.InvalidInput(error_message=msg)
def _validate_ipv6_update_dhcp(self, subnet, cur_subnet):
if ('enable_dhcp' in subnet and not subnet['enable_dhcp']):
@ -277,7 +278,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
subnet.get('ipv6_address_mode'))
if ra_mode_set or address_mode_set:
raise n_exc.InvalidInput(error_message=msg)
raise exc.InvalidInput(error_message=msg)
old_ra_mode_set = attributes.is_attr_set(
cur_subnet.get('ipv6_ra_mode'))
@ -285,7 +286,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
cur_subnet.get('ipv6_address_mode'))
if old_ra_mode_set or old_address_mode_set:
raise n_exc.InvalidInput(error_message=msg)
raise exc.InvalidInput(error_message=msg)
def _create_bulk(self, resource, context, request_items):
objects = []
@ -380,7 +381,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
network_id=id).first()
if port_in_use:
raise n_exc.NetworkInUse(net_id=id)
raise exc.NetworkInUse(net_id=id)
# clean up subnets
subnets = self._get_subnets_by_network(context, id)
@ -423,7 +424,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
'ip_version': ip_version}
msg = _("%(name)s '%(addr)s' does not match "
"the ip_version '%(ip_version)s'") % data
raise n_exc.InvalidInput(error_message=msg)
raise exc.InvalidInput(error_message=msg)
def _validate_subnet(self, context, s, cur_subnet=None):
"""Validate a subnet spec."""
@ -452,17 +453,17 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
"incompatible with DHCP service enabled.")
if ((ip_ver == 4 and subnet_prefixlen > 30) or
(ip_ver == 6 and subnet_prefixlen > 126)):
raise n_exc.InvalidInput(error_message=error_message)
raise exc.InvalidInput(error_message=error_message)
net = netaddr.IPNetwork(s['cidr'])
if net.is_multicast():
error_message = _("Multicast IP subnet is not supported "
"if enable_dhcp is True.")
raise n_exc.InvalidInput(error_message=error_message)
raise exc.InvalidInput(error_message=error_message)
elif net.is_loopback():
error_message = _("Loopback IP subnet is not supported "
"if enable_dhcp is True.")
raise n_exc.InvalidInput(error_message=error_message)
raise exc.InvalidInput(error_message=error_message)
if attributes.is_attr_set(s.get('gateway_ip')):
self._validate_ip_version(ip_ver, s['gateway_ip'], 'gateway_ip')
@ -471,7 +472,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
s['cidr'], s['gateway_ip']))
if is_gateway_not_valid:
error_message = _("Gateway is not valid on subnet")
raise n_exc.InvalidInput(error_message=error_message)
raise exc.InvalidInput(error_message=error_message)
# Ensure the gateway IP is not assigned to any port
# skip this check in case of create (s parameter won't have id)
# NOTE(salv-orlando): There is slight chance of a race, when
@ -498,7 +499,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
try:
netaddr.IPAddress(dns)
except Exception:
raise n_exc.InvalidInput(
raise exc.InvalidInput(
error_message=(_("Error parsing dns address %s") %
dns))
self._validate_ip_version(ip_ver, dns, 'dns_nameserver')
@ -514,11 +515,11 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
if ip_ver == 4:
if attributes.is_attr_set(s.get('ipv6_ra_mode')):
raise n_exc.InvalidInput(
raise exc.InvalidInput(
error_message=(_("ipv6_ra_mode is not valid when "
"ip_version is 4")))
if attributes.is_attr_set(s.get('ipv6_address_mode')):
raise n_exc.InvalidInput(
raise exc.InvalidInput(
error_message=(_("ipv6_address_mode is not valid when "
"ip_version is 4")))
if ip_ver == 6:
@ -529,7 +530,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
if (subnet.get('ip_version') != constants.IP_VERSION_6):
reason = _("Prefix Delegation can only be used with IPv6 "
"subnets.")
raise n_exc.BadRequest(resource='subnets', msg=reason)
raise exc.BadRequest(resource='subnets', msg=reason)
mode_list = [constants.IPV6_SLAAC,
constants.DHCPV6_STATELESS]
@ -538,13 +539,13 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
if ra_mode not in mode_list:
reason = _("IPv6 RA Mode must be SLAAC or Stateless for "
"Prefix Delegation.")
raise n_exc.BadRequest(resource='subnets', msg=reason)
raise exc.BadRequest(resource='subnets', msg=reason)
address_mode = subnet.get('ipv6_address_mode')
if address_mode not in mode_list:
reason = _("IPv6 Address Mode must be SLAAC or Stateless for "
"Prefix Delegation.")
raise n_exc.BadRequest(resource='subnets', msg=reason)
raise exc.BadRequest(resource='subnets', msg=reason)
def _update_router_gw_ports(self, context, network, subnet):
l3plugin = manager.NeutronManager.get_service_plugins().get(
@ -615,7 +616,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
if use_default_subnetpool and subnetpool_id:
msg = _('subnetpool_id and use_default_subnetpool cannot both be '
'specified')
raise n_exc.BadRequest(resource='subnets', msg=msg)
raise exc.BadRequest(resource='subnets', msg=msg)
if subnetpool_id:
return subnetpool_id
@ -631,7 +632,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
if not attributes.is_attr_set(ip_version):
msg = _('ip_version must be specified in the absence of '
'cidr and subnetpool_id')
raise n_exc.BadRequest(resource='subnets', msg=msg)
raise exc.BadRequest(resource='subnets', msg=msg)
if ip_version == 6 and cfg.CONF.ipv6_pd_enabled:
return constants.IPV6_PD_POOL_ID
@ -649,7 +650,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
return cfg.CONF.default_ipv6_subnet_pool
msg = _('No default subnetpool found for IPv%s') % ip_version
raise n_exc.BadRequest(resource='subnets', msg=msg)
raise exc.BadRequest(resource='subnets', msg=msg)
def create_subnet(self, context, subnet):
@ -661,7 +662,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
if has_cidr and has_prefixlen:
msg = _('cidr and prefixlen must not be supplied together')
raise n_exc.BadRequest(resource='subnets', msg=msg)
raise exc.BadRequest(resource='subnets', msg=msg)
if has_cidr:
# turn the CIDR into a proper subnet
@ -671,7 +672,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
subnetpool_id = self._get_subnetpool_id(context, s)
if not subnetpool_id and not has_cidr:
msg = _('a subnetpool must be specified in the absence of a cidr')
raise n_exc.BadRequest(resource='subnets', msg=msg)
raise exc.BadRequest(resource='subnets', msg=msg)
if subnetpool_id:
self.ipam.validate_pools_with_subnetpool(s)
@ -690,7 +691,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
if not has_cidr:
msg = _('A cidr must be specified in the absence of a '
'subnet pool')
raise n_exc.BadRequest(resource='subnets', msg=msg)
raise exc.BadRequest(resource='subnets', msg=msg)
self._validate_subnet(context, s)
return self._create_subnet(context, subnet, subnetpool_id)
@ -825,7 +826,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
if allocs:
LOG.debug("Subnet %s still has internal router ports, "
"cannot delete", subnet_id)
raise n_exc.SubnetInUse(subnet_id=id)
raise exc.SubnetInUse(subnet_id=id)
def delete_subnet(self, context, id):
with context.session.begin(subtransactions=True):
@ -869,7 +870,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
{'ip': alloc.ip_address,
'port_id': alloc.port_id,
'subnet': id})
raise n_exc.SubnetInUse(subnet_id=id)
raise exc.SubnetInUse(subnet_id=id)
context.session.delete(subnet)
# Delete related ipam subnet manually,
@ -966,7 +967,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
if self.get_default_subnetpool(context, ip_version):
msg = _("A default subnetpool for this IP family has already "
"been set. Only one default may exist per IP family")
raise n_exc.InvalidInput(error_message=msg)
raise exc.InvalidInput(error_message=msg)
def create_subnetpool(self, context, subnetpool):
"""Create a subnetpool"""
@ -1180,7 +1181,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
context.session.add(db_port)
return db_port
except db_exc.DBDuplicateEntry:
raise n_exc.MacAddressInUse(net_id=network_id, mac=mac_address)
raise exc.MacAddressInUse(net_id=network_id, mac=mac_address)
def _create_port(self, context, network_id, port_data):
max_retries = cfg.CONF.mac_generation_retries
@ -1189,7 +1190,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
try:
return self._create_port_with_mac(
context, network_id, port_data, mac)
except n_exc.MacAddressInUse:
except exc.MacAddressInUse:
LOG.debug('Generated mac %(mac_address)s exists on '
'network %(network_id)s',
{'mac_address': mac, 'network_id': network_id})
@ -1321,7 +1322,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
for port_id in port_ids:
try:
self.delete_port(context, port_id)
except n_exc.PortNotFound:
except exc.PortNotFound:
# Don't raise if something else concurrently deleted the port
LOG.debug("Ignoring PortNotFound when deleting port '%s'. "
"The port has already been deleted.",

2
neutron/db/dns_db.py

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import exceptions as n_exc
from oslo_config import cfg
from oslo_log import log as logging
import sqlalchemy as sa
@ -20,7 +21,6 @@ from sqlalchemy import orm
from neutron._i18n import _, _LE
from neutron.api.v2 import attributes
from neutron.common import exceptions as n_exc
from neutron.common import utils
from neutron.db import db_base_plugin_v2
from neutron.db import l3_db

2
neutron/db/dvr_mac_db.py

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import exceptions as n_exc
from oslo_config import cfg
from oslo_db import exception as db_exc
from oslo_log import helpers as log_helpers
@ -26,7 +27,6 @@ from neutron.callbacks import events
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.common import constants
from neutron.common import exceptions as n_exc
from neutron.common import utils
from neutron.db import model_base
from neutron.db import models_v2

2
neutron/db/external_net_db.py

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import exceptions as n_exc
import sqlalchemy as sa
from sqlalchemy import orm
from sqlalchemy.orm import exc
@ -26,7 +27,6 @@ from neutron.callbacks import exceptions as c_exc
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.common import constants as l3_constants
from neutron.common import exceptions as n_exc
from neutron.db import db_base_plugin_v2
from neutron.db import l3_db
from neutron.db import model_base

21
neutron/db/ipam_backend_mixin.py

@ -17,6 +17,7 @@ import collections
import itertools
import netaddr
from neutron_lib import exceptions as exc
from oslo_config import cfg
from oslo_db import exception as db_exc
from oslo_log import log as logging
@ -82,7 +83,7 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
if is_any_subnetpool_request and has_allocpool:
reason = _("allocation_pools allowed only "
"for specific subnet requests.")
raise n_exc.BadRequest(resource='subnets', msg=reason)
raise exc.BadRequest(resource='subnets', msg=reason)
def _validate_ip_version_with_subnetpool(self, subnet, subnetpool):
"""Validates ip version for subnet_pool and requested subnet"""
@ -93,7 +94,7 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
'pool_ver': str(subnetpool.ip_version)}
reason = _("Cannot allocate IPv%(req_ver)s subnet from "
"IPv%(pool_ver)s subnet pool") % args
raise n_exc.BadRequest(resource='subnets', msg=reason)
raise exc.BadRequest(resource='subnets', msg=reason)
def _update_db_port(self, context, db_port, new_port, network_id, new_mac):
# Remove all attributes in new_port which are not in the port DB model
@ -103,7 +104,7 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
models_v2.Port))
context.session.flush()
except db_exc.DBDuplicateEntry:
raise n_exc.MacAddressInUse(net_id=network_id, mac=new_mac)
raise exc.MacAddressInUse(net_id=network_id, mac=new_mac)
def _update_subnet_host_routes(self, context, id, s):
@ -212,7 +213,7 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
for cidr in new_subnet_ipset.iter_cidrs():
if cidr.prefixlen == 0:
err_msg = _("0 is not allowed as CIDR prefix length")
raise n_exc.InvalidInput(error_message=err_msg)
raise exc.InvalidInput(error_message=err_msg)
if cfg.CONF.allow_overlapping_ips:
subnet_list = network.subnets
@ -233,7 +234,7 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
{'new_cidr': new_subnet_cidr,
'subnet_id': subnet.id,
'cidr': subnet.cidr})
raise n_exc.InvalidInput(error_message=err_msg)
raise exc.InvalidInput(error_message=err_msg)
def _validate_network_subnetpools(self, network,
new_subnetpool_id, ip_version):
@ -304,7 +305,7 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
if len(fixed_ip_list) > cfg.CONF.max_fixed_ips_per_port:
msg = _('Exceeded maximum amount of fixed ips per port.')
raise n_exc.InvalidInput(error_message=msg)
raise exc.InvalidInput(error_message=msg)
def _get_subnet_for_fixed_ip(self, context, fixed, subnets):
# Subnets are all the subnets belonging to the same network.
@ -325,23 +326,23 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
"%(subnet_id)s") %
{'network_id': subnet['network_id'],
'subnet_id': fixed['subnet_id']})
raise n_exc.InvalidInput(error_message=msg)
raise exc.InvalidInput(error_message=msg)
# Ensure that the IP is valid on the subnet
if ('ip_address' in fixed and
not ipam_utils.check_subnet_ip(subnet['cidr'],
fixed['ip_address'])):
raise n_exc.InvalidIpForSubnet(ip_address=fixed['ip_address'])
raise exc.InvalidIpForSubnet(ip_address=fixed['ip_address'])
return subnet
if 'ip_address' not in fixed:
msg = _('IP allocation requires subnet_id or ip_address')
raise n_exc.InvalidInput(error_message=msg)
raise exc.InvalidInput(error_message=msg)
for subnet in subnets:
if ipam_utils.check_subnet_ip(subnet['cidr'],
fixed['ip_address']):
return subnet
raise n_exc.InvalidIpForNetwork(ip_address=fixed['ip_address'])
raise exc.InvalidIpForNetwork(ip_address=fixed['ip_address'])
def generate_pools(self, cidr, gateway_ip):
return ipam_utils.generate_pools(cidr, gateway_ip)

2
neutron/db/ipam_non_pluggable_backend.py

@ -14,6 +14,7 @@
# under the License.
import netaddr
from neutron_lib import exceptions as n_exc
from oslo_db import exception as db_exc
from oslo_log import log as logging
from sqlalchemy import and_
@ -23,7 +24,6 @@ from sqlalchemy.orm import exc
from neutron._i18n import _
from neutron.api.v2 import attributes
from neutron.common import constants
from neutron.common import exceptions as n_exc
from neutron.common import ipv6_utils
from neutron.db import ipam_backend_mixin
from neutron.db import models_v2

2
neutron/db/ipam_pluggable_backend.py

@ -16,6 +16,7 @@
import copy
import netaddr
from neutron_lib import exceptions as n_exc
from oslo_db import exception as db_exc
from oslo_log import log as logging
from oslo_utils import excutils
@ -24,7 +25,6 @@ from sqlalchemy import and_
from neutron._i18n import _, _LE
from neutron.api.v2 import attributes
from neutron.common import constants
from neutron.common import exceptions as n_exc
from neutron.common import ipv6_utils
from neutron.db import ipam_backend_mixin
from neutron.db import models_v2

2
neutron/db/l3_db.py

@ -15,6 +15,7 @@
import itertools
import netaddr
from neutron_lib import exceptions as n_exc
from oslo_log import log as logging
from oslo_utils import excutils
from oslo_utils import uuidutils
@ -31,7 +32,6 @@ from neutron.callbacks import exceptions
from neutron.callbacks import registry
from neutron.callbacks import resources
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

2
neutron/db/l3_dvr_db.py

@ -13,6 +13,7 @@
# under the License.
import collections
from neutron_lib import exceptions as n_exc
from oslo_config import cfg
from oslo_log import helpers as log_helper
from oslo_log import log as logging
@ -26,7 +27,6 @@ from neutron.callbacks import exceptions
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.common import constants as l3_const
from neutron.common import exceptions as n_exc
from neutron.common import utils as n_utils
from neutron.db import l3_agentschedulers_db as l3_sched_db
from neutron.db import l3_attrs_db

2
neutron/db/l3_hamode_db.py

@ -16,6 +16,7 @@
import functools
import netaddr
from neutron_lib import exceptions as n_exc
from oslo_config import cfg
from oslo_db import exception as db_exc
from oslo_log import helpers as log_helpers
@ -29,7 +30,6 @@ from sqlalchemy import orm
from neutron._i18n import _, _LI
from neutron.api.v2 import attributes
from neutron.common import constants
from neutron.common import exceptions as n_exc
from neutron.common import utils as n_utils
from neutron.db import agents_db
from neutron.db.availability_zone import router as router_az_db

2
neutron/db/migration/alembic_migrations/versions/mitaka/expand/1df244e556f5_add_unique_ha_router_agent_port_bindings.py

@ -26,11 +26,11 @@ revision = '1df244e556f5'
down_revision = '659bf3d90664'
from alembic import op
from neutron_lib import exceptions
import sqlalchemy as sa
from neutron._i18n import _
from neutron.common import exceptions
UNIQUE_NAME = 'uniq_ha_router_agent_port_bindings0port_id0l3_agent_id'
TABLE_NAME = 'ha_router_agent_port_bindings'

7
neutron/db/quota/driver.py

@ -13,10 +13,11 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import exceptions
from oslo_db import api as oslo_db_api
from oslo_log import log
from neutron.common import exceptions
from neutron.common import exceptions as n_exc
from neutron.db import api as db_api
from neutron.db import common_db_mixin as common_db
from neutron.db.quota import api as quota_api
@ -69,7 +70,7 @@ class DbQuotaDriver(object):
tenant_quotas = tenant_quotas.filter_by(tenant_id=tenant_id)
if not tenant_quotas.delete():
# No record deleted means the quota was not found
raise exceptions.TenantQuotaNotFound(tenant_id=tenant_id)
raise n_exc.TenantQuotaNotFound(tenant_id=tenant_id)
@staticmethod
def get_all_quotas(context, resources):
@ -251,7 +252,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 exceptions.InvalidQuotaValue(unders=sorted(unders))
raise n_exc.InvalidQuotaValue(unders=sorted(unders))
# Get the applicable quotas
quotas = self._get_quotas(context, tenant_id, resources)

2
neutron/db/rbac_db_mixin.py

@ -13,13 +13,13 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import exceptions as n_exc
from oslo_db import exception as db_exc
from sqlalchemy.orm import exc
from neutron.callbacks import events
from neutron.callbacks import exceptions as c_exc
from neutron.callbacks import registry
from neutron.common import exceptions as n_exc
from neutron.db import common_db_mixin
from neutron.db import rbac_db_models as models
from neutron.extensions import rbac as ext_rbac

2
neutron/db/rbac_db_models.py

@ -15,13 +15,13 @@
import abc