Fix deprecation warnings

Remove deprecation warnings for various constants
and exceptions that have moved to neutron_lib.

Fix miscellaneous other deprecations.

Uses constants instead of l3_constants when importing
neutron-lib constants.

Co-Authored By: Henry Gessau <gessau@gmail.com>
Co-Authored By: Gary Kotton <gkotton@vmware.com>

Change-Id: Ib0e8ff5c3e23677c1009241a1818cbc8a3430c38
changes/72/353472/22
Gary Kotton 2016-08-12 07:06:50 -07:00 committed by Henry Gessau
parent d30610c8da
commit 9f09f27c5d
69 changed files with 492 additions and 526 deletions

View File

@ -372,7 +372,7 @@ class L3NATAgent(ha.AgentMixin,
self.l3_ext_manager = (
l3_ext_manager.L3AgentExtensionsManager(self.conf))
self.l3_ext_manager.initialize(
connection, l3_constants.L3_AGENT_MODE)
connection, lib_const.L3_AGENT_MODE)
def router_deleted(self, context, router_id):
"""Deal with router deletion RPC message."""
@ -560,7 +560,7 @@ class L3NATAgent(ha.AgentMixin,
ext_net_id = (r['external_gateway_info'] or {}).get(
'network_id')
is_snat_agent = (self.conf.agent_mode ==
l3_constants.L3_AGENT_MODE_DVR_SNAT)
lib_const.L3_AGENT_MODE_DVR_SNAT)
if ext_net_id:
ns_manager.keep_ext_net(ext_net_id)
elif is_snat_agent:

View File

@ -19,7 +19,6 @@ from neutron.agent.l3 import dvr_edge_router
from neutron.agent.l3 import dvr_snat_ns
from neutron.agent.l3 import ha_router
from neutron.agent.l3 import router_info
from neutron.common import constants as l3_constants
class DvrEdgeHaRouter(dvr_edge_router.DvrEdgeRouter,
@ -105,7 +104,7 @@ class DvrEdgeHaRouter(dvr_edge_router.DvrEdgeRouter,
def _is_this_snat_host(self):
return (self.agent_conf.agent_mode
== l3_constants.L3_AGENT_MODE_DVR_SNAT)
== constants.L3_AGENT_MODE_DVR_SNAT)
def _dvr_internal_network_removed(self, port):
super(DvrEdgeHaRouter, self)._dvr_internal_network_removed(port)

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import constants as l3_constants
from neutron_lib import constants as lib_constants
from oslo_log import log as logging
from neutron._i18n import _LE
@ -235,8 +235,8 @@ class DvrEdgeRouter(dvr_local_router.DvrLocalRouter):
if external_port:
external_port_scopemark = self._get_port_devicename_scopemark(
[external_port], self.get_external_device_name)
for ip_version in (l3_constants.IP_VERSION_4,
l3_constants.IP_VERSION_6):
for ip_version in (lib_constants.IP_VERSION_4,
lib_constants.IP_VERSION_6):
ports_scopemark[ip_version].update(
external_port_scopemark[ip_version])

View File

@ -16,7 +16,8 @@ import binascii
import collections
import netaddr
from neutron_lib import constants as l3_constants
from neutron_lib import constants as lib_constants
from neutron_lib import exceptions
from oslo_log import log as logging
from oslo_utils import excutils
import six
@ -26,7 +27,6 @@ from neutron.agent.l3 import dvr_fip_ns
from neutron.agent.l3 import dvr_router_base
from neutron.agent.linux import ip_lib
from neutron.common import constants as n_const
from neutron.common import exceptions
from neutron.common import utils as common_utils
LOG = logging.getLogger(__name__)
@ -163,18 +163,18 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase):
# Special Handling for DVR - update FIP namespace
ip_cidr = common_utils.ip_to_cidr(fip['floating_ip_address'])
self.floating_ip_added_dist(fip, ip_cidr)
return l3_constants.FLOATINGIP_STATUS_ACTIVE
return lib_constants.FLOATINGIP_STATUS_ACTIVE
def remove_floating_ip(self, device, ip_cidr):
self.floating_ip_removed_dist(ip_cidr)
def move_floating_ip(self, fip):
self.floating_ip_moved_dist(fip)
return l3_constants.FLOATINGIP_STATUS_ACTIVE
return lib_constants.FLOATINGIP_STATUS_ACTIVE
def _get_internal_port(self, subnet_id):
"""Return internal router port based on subnet_id."""
router_ports = self.router.get(l3_constants.INTERFACE_KEY, [])
router_ports = self.router.get(lib_constants.INTERFACE_KEY, [])
for port in router_ports:
fips = port['fixed_ips']
for f in fips:
@ -252,7 +252,7 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase):
subnet_ports = self.agent.get_ports_by_subnet(subnet_id)
for p in subnet_ports:
if p['device_owner'] not in l3_constants.ROUTER_INTERFACE_OWNERS:
if p['device_owner'] not in lib_constants.ROUTER_INTERFACE_OWNERS:
for fixed_ip in p['fixed_ips']:
self._update_arp_entry(fixed_ip['ip_address'],
p['mac_address'],
@ -460,7 +460,7 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase):
def _get_address_scope_mark(self):
# Prepare address scope iptables rule for internal ports
internal_ports = self.router.get(l3_constants.INTERFACE_KEY, [])
internal_ports = self.router.get(lib_constants.INTERFACE_KEY, [])
ports_scopemark = self._get_port_devicename_scopemark(
internal_ports, self.get_internal_device_name)
# DVR local router will use rfp port as external port
@ -474,7 +474,7 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase):
ext_scope = self._get_external_address_scope()
ext_scope_mark = self.get_address_scope_mark_mask(ext_scope)
ports_scopemark[l3_constants.IP_VERSION_4][ext_device_name] = (
ports_scopemark[lib_constants.IP_VERSION_4][ext_device_name] = (
ext_scope_mark)
return ports_scopemark
@ -536,7 +536,7 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase):
self.router_id)
rtr_2_fip, _fip_2_rtr = self.rtr_fip_subnet.get_pair()
exist_routes = device.route.list_routes(
l3_constants.IP_VERSION_4, via=str(rtr_2_fip.ip))
lib_constants.IP_VERSION_4, via=str(rtr_2_fip.ip))
return {common_utils.ip_to_cidr(route['cidr'])
for route in exist_routes}

View File

@ -10,11 +10,11 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import constants
from oslo_log import log as logging
from neutron.agent.l3 import namespaces
from neutron.agent.linux import ip_lib
from neutron.common import constants
LOG = logging.getLogger(__name__)
SNAT_NS_PREFIX = 'snat-'

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import constants as l3_constants
from neutron_lib import constants as lib_constants
from neutron.agent.l3 import router_info as router
from neutron.agent.linux import ip_lib
@ -21,7 +21,7 @@ from neutron.agent.linux import ip_lib
class LegacyRouter(router.RouterInfo):
def add_floating_ip(self, fip, interface_name, device):
if not self._add_fip_addr_to_device(fip, device):
return l3_constants.FLOATINGIP_STATUS_ERROR
return lib_constants.FLOATINGIP_STATUS_ERROR
# As GARP is processed in a distinct thread the call below
# won't raise an exception to be handled.
@ -29,4 +29,4 @@ class LegacyRouter(router.RouterInfo):
interface_name,
fip['floating_ip_address'],
self.agent_conf)
return l3_constants.FLOATINGIP_STATUS_ACTIVE
return lib_constants.FLOATINGIP_STATUS_ACTIVE

View File

@ -14,7 +14,7 @@
import collections
import netaddr
from neutron_lib import constants as l3_constants
from neutron_lib import constants as lib_constants
from oslo_log import log as logging
from neutron._i18n import _, _LE, _LW
@ -143,7 +143,7 @@ class RouterInfo(object):
def get_floating_ips(self):
"""Filter Floating IPs to be hosted on this agent."""
return self.router.get(l3_constants.FLOATINGIP_KEY, [])
return self.router.get(lib_constants.FLOATINGIP_KEY, [])
def floating_forward_rules(self, floating_ip, fixed_ip):
return [('PREROUTING', '-d %s/32 -j DNAT --to-destination %s' %
@ -226,7 +226,7 @@ class RouterInfo(object):
ports_scopemark = self._get_address_scope_mark()
devices_in_ext_scope = {
device for device, mark
in ports_scopemark[l3_constants.IP_VERSION_4].items()
in ports_scopemark[lib_constants.IP_VERSION_4].items()
if mark == ext_scope_mark}
# Add address scope for floatingip egress
for device in devices_in_ext_scope:
@ -279,7 +279,7 @@ class RouterInfo(object):
device.delete_addr_and_conntrack_state(ip_cidr)
def move_floating_ip(self, fip):
return l3_constants.FLOATINGIP_STATUS_ACTIVE
return lib_constants.FLOATINGIP_STATUS_ACTIVE
def remove_external_gateway_ip(self, device, ip_cidr):
device.delete_addr_and_conntrack_state(ip_cidr)
@ -311,7 +311,7 @@ class RouterInfo(object):
fip_ip = fip['floating_ip_address']
ip_cidr = common_utils.ip_to_cidr(fip_ip)
new_cidrs.add(ip_cidr)
fip_statuses[fip['id']] = l3_constants.FLOATINGIP_STATUS_ACTIVE
fip_statuses[fip['id']] = lib_constants.FLOATINGIP_STATUS_ACTIVE
if ip_cidr not in existing_cidrs:
fip_statuses[fip['id']] = self.add_floating_ip(
fip, interface_name, device)
@ -346,7 +346,7 @@ class RouterInfo(object):
for ip_addr in ex_gw_port['fixed_ips']:
ex_gw_ip = ip_addr['ip_address']
addr = netaddr.IPAddress(ex_gw_ip)
if addr.version == l3_constants.IP_VERSION_4:
if addr.version == lib_constants.IP_VERSION_4:
gw_cidrs.add(common_utils.ip_to_cidr(ex_gw_ip))
return gw_cidrs
@ -361,14 +361,14 @@ class RouterInfo(object):
def put_fips_in_error_state(self):
fip_statuses = {}
for fip in self.router.get(l3_constants.FLOATINGIP_KEY, []):
fip_statuses[fip['id']] = l3_constants.FLOATINGIP_STATUS_ERROR
for fip in self.router.get(lib_constants.FLOATINGIP_KEY, []):
fip_statuses[fip['id']] = lib_constants.FLOATINGIP_STATUS_ERROR
return fip_statuses
def delete(self, agent):
self.router['gw_port'] = None
self.router[l3_constants.INTERFACE_KEY] = []
self.router[l3_constants.FLOATINGIP_KEY] = []
self.router[lib_constants.INTERFACE_KEY] = []
self.router[lib_constants.FLOATINGIP_KEY] = []
self.process_delete(agent)
self.disable_radvd()
self.router_namespace.delete()
@ -487,7 +487,7 @@ class RouterInfo(object):
def _process_internal_ports(self, pd):
existing_port_ids = set(p['id'] for p in self.internal_ports)
internal_ports = self.router.get(l3_constants.INTERFACE_KEY, [])
internal_ports = self.router.get(lib_constants.INTERFACE_KEY, [])
current_port_ids = set(p['id'] for p in internal_ports
if p['admin_state_up'])
@ -643,8 +643,8 @@ class RouterInfo(object):
device = ip_lib.IPDevice(interface_name, namespace=ns_name)
current_gateways = set()
for ip_version in (l3_constants.IP_VERSION_4,
l3_constants.IP_VERSION_6):
for ip_version in (lib_constants.IP_VERSION_4,
lib_constants.IP_VERSION_6):
gateway = device.route.get_gateway(ip_version=ip_version)
if gateway and gateway.get('gateway'):
current_gateways.add(gateway.get('gateway'))
@ -856,7 +856,7 @@ class RouterInfo(object):
existing_floating_ips = self.floating_ips
self.floating_ips = set(fip_statuses.keys())
for fip_id in existing_floating_ips - self.floating_ips:
fip_statuses[fip_id] = l3_constants.FLOATINGIP_STATUS_DOWN
fip_statuses[fip_id] = lib_constants.FLOATINGIP_STATUS_DOWN
# filter out statuses that didn't change
fip_statuses = {f: stat for f, stat in fip_statuses.items()
if stat != FLOATINGIP_STATUS_NOCHANGE}
@ -915,8 +915,8 @@ class RouterInfo(object):
'PREROUTING', copy_address_scope_for_existing)
def _get_port_devicename_scopemark(self, ports, name_generator):
devicename_scopemark = {l3_constants.IP_VERSION_4: dict(),
l3_constants.IP_VERSION_6: dict()}
devicename_scopemark = {lib_constants.IP_VERSION_4: dict(),
lib_constants.IP_VERSION_6: dict()}
for p in ports:
device_name = name_generator(p['id'])
ip_cidrs = common_utils.fixed_ip_cidrs(p['fixed_ips'])
@ -930,7 +930,7 @@ class RouterInfo(object):
def _get_address_scope_mark(self):
# Prepare address scope iptables rule for internal ports
internal_ports = self.router.get(l3_constants.INTERFACE_KEY, [])
internal_ports = self.router.get(lib_constants.INTERFACE_KEY, [])
ports_scopemark = self._get_port_devicename_scopemark(
internal_ports, self.get_internal_device_name)
@ -939,8 +939,8 @@ class RouterInfo(object):
if external_port:
external_port_scopemark = self._get_port_devicename_scopemark(
[external_port], self.get_external_device_name)
for ip_version in (l3_constants.IP_VERSION_4,
l3_constants.IP_VERSION_6):
for ip_version in (lib_constants.IP_VERSION_4,
lib_constants.IP_VERSION_6):
ports_scopemark[ip_version].update(
external_port_scopemark[ip_version])
return ports_scopemark
@ -953,13 +953,13 @@ class RouterInfo(object):
external_port['id'])
# Process address scope iptables rules
for ip_version in (l3_constants.IP_VERSION_4,
l3_constants.IP_VERSION_6):
for ip_version in (lib_constants.IP_VERSION_4,
lib_constants.IP_VERSION_6):
scopemarks = ports_scopemark[ip_version]
iptables = iptables_manager.get_tables(ip_version)
iptables['mangle'].empty_chain('scope')
iptables['filter'].empty_chain('scope')
dont_block_external = (ip_version == l3_constants.IP_VERSION_4
dont_block_external = (ip_version == lib_constants.IP_VERSION_4
and self._snat_enabled and external_port)
for device_name, mark in scopemarks.items():
# Add address scope iptables rule
@ -982,7 +982,7 @@ class RouterInfo(object):
return
scopes = external_port.get('address_scopes', {})
return scopes.get(str(l3_constants.IP_VERSION_4))
return scopes.get(str(lib_constants.IP_VERSION_4))
def process_external_port_address_scope_routing(self, iptables_manager):
if not self._snat_enabled:

View File

@ -353,8 +353,8 @@ class Dnsmasq(DhcpLocalProcess):
# static to preserve previous behavior
addr_mode = getattr(subnet, 'ipv6_address_mode', None)
ra_mode = getattr(subnet, 'ipv6_ra_mode', None)
if (addr_mode in [n_const.DHCPV6_STATEFUL,
n_const.DHCPV6_STATELESS] or
if (addr_mode in [constants.DHCPV6_STATEFUL,
constants.DHCPV6_STATELESS] or
not addr_mode and not ra_mode):
mode = 'static'
@ -510,7 +510,7 @@ class Dnsmasq(DhcpLocalProcess):
fixed_ips,
key=lambda fip: ((fip.subnet_id in v6_nets) and (
v6_nets[fip.subnet_id].ipv6_address_mode == (
n_const.DHCPV6_STATELESS))),
constants.DHCPV6_STATELESS))),
reverse=True)
def _iter_hosts(self):
@ -545,11 +545,11 @@ class Dnsmasq(DhcpLocalProcess):
no_opts = False
if alloc.subnet_id in v6_nets:
addr_mode = v6_nets[alloc.subnet_id].ipv6_address_mode
no_dhcp = addr_mode in (n_const.IPV6_SLAAC,
n_const.DHCPV6_STATELESS)
no_dhcp = addr_mode in (constants.IPV6_SLAAC,
constants.DHCPV6_STATELESS)
# we don't setup anything for SLAAC. It doesn't make sense
# to provide options for a client that won't use DHCP
no_opts = addr_mode == n_const.IPV6_SLAAC
no_opts = addr_mode == constants.IPV6_SLAAC
# If dns_name attribute is supported by ports API, return the
# dns_assignment generated by the Neutron server. Otherwise,
@ -770,7 +770,7 @@ class Dnsmasq(DhcpLocalProcess):
addr_mode = getattr(subnet, 'ipv6_address_mode', None)
if (not subnet.enable_dhcp or
(subnet.ip_version == 6 and
addr_mode == n_const.IPV6_SLAAC)):
addr_mode == constants.IPV6_SLAAC)):
continue
if subnet.dns_nameservers:
options.append(

View File

@ -699,7 +699,7 @@ class IpRouteCommand(IpDeviceCommandBase):
with excutils.save_and_reraise_exception() as ctx:
if "Cannot find device" in str(rte):
ctx.reraise = False
raise n_exc.DeviceNotFoundError(device_name=self.name)
raise exceptions.DeviceNotFoundError(device_name=self.name)
def delete_gateway(self, gateway, table=None):
ip_version = get_ip_version(gateway)

View File

@ -17,6 +17,7 @@ from itertools import chain as iter_chain
import jinja2
import netaddr
from neutron_lib import constants
from oslo_config import cfg
from oslo_log import log as logging
import six
@ -24,7 +25,7 @@ import six
from neutron._i18n import _
from neutron.agent.linux import external_process
from neutron.agent.linux import utils
from neutron.common import constants
from neutron.common import constants as n_const
from neutron.common import utils as common_utils
@ -53,7 +54,7 @@ CONFIG_TEMPLATE = jinja2.Template("""interface {{ interface_name }}
MinRtrAdvInterval {{ min_rtr_adv_interval }};
MaxRtrAdvInterval {{ max_rtr_adv_interval }};
{% if network_mtu >= constants.IPV6_MIN_MTU %}
{% if network_mtu >= n_const.IPV6_MIN_MTU %}
AdvLinkMTU {{network_mtu}};
{% endif %}
@ -132,6 +133,7 @@ class DaemonMonitor(object):
auto_config_prefixes=auto_config_prefixes,
stateful_config_prefixes=stateful_config_prefixes,
dns_servers=dns_servers[0:MAX_RDNSS_ENTRIES],
n_const=n_const,
constants=constants,
min_rtr_adv_interval=self._agent_conf.min_rtr_adv_interval,
max_rtr_adv_interval=self._agent_conf.max_rtr_adv_interval,

View File

@ -28,7 +28,6 @@ from webob import exc
from neutron._i18n import _, _LW
from neutron.common import constants
from neutron.common import exceptions as n_exc
from neutron import wsgi
@ -386,7 +385,7 @@ class NeutronController(object):
def convert_exception_to_http_exc(e, faults, language):
serializer = wsgi.JSONDictSerializer()
if isinstance(e, n_exc.MultipleExceptions):
if isinstance(e, exceptions.MultipleExceptions):
converted_exceptions = [
convert_exception_to_http_exc(inner, faults, language)
for inner in e.inner_exceptions]

View File

@ -24,7 +24,6 @@ import webob.exc
from neutron._i18n import _
from neutron.common import _deprecate
from neutron.common import constants as n_const
# Defining a constant to avoid repeating string literal in several modules
@ -280,12 +279,12 @@ RESOURCE_ATTRIBUTE_MAP = {
'is_visible': True},
'ipv6_ra_mode': {'allow_post': True, 'allow_put': False,
'default': constants.ATTR_NOT_SPECIFIED,
'validate': {'type:values': n_const.IPV6_MODES},
'validate': {'type:values': constants.IPV6_MODES},
'is_visible': True},
'ipv6_address_mode': {'allow_post': True, 'allow_put': False,
'default': constants.ATTR_NOT_SPECIFIED,
'validate': {'type:values':
n_const.IPV6_MODES},
constants.IPV6_MODES},
'is_visible': True},
SHARED: {'allow_post': False,
'allow_put': False,

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from neutron_lib import constants
from oslo_config import cfg
from oslo_service import wsgi as base_wsgi
import routes as routes_mapper
@ -38,7 +39,7 @@ RESOURCES = {'network': 'networks',
SUB_RESOURCES = {}
COLLECTION_ACTIONS = ['index', 'create']
MEMBER_ACTIONS = ['show', 'update', 'delete']
REQUIREMENTS = {'id': attributes.UUID_PATTERN, 'format': 'json'}
REQUIREMENTS = {'id': constants.UUID_PATTERN, 'format': 'json'}
class Index(wsgi.Application):

View File

@ -13,14 +13,13 @@
from neutron_lib import exceptions
from neutron._i18n import _
from neutron.common import exceptions as n_exc
class Invalid(exceptions.NeutronException):
message = _("The value '%(value)s' for %(element)s is not valid.")
class CallbackFailure(n_exc.MultipleExceptions):
class CallbackFailure(exceptions.MultipleExceptions):
def __init__(self, errors):
self.errors = errors

View File

@ -135,8 +135,6 @@ DVR_FIP_LL_CIDR = '169.254.64.0/18'
L3_HA_NET_CIDR = '169.254.192.0/18'
METADATA_CIDR = '169.254.169.254/32'
DEVICE_OWNER_BAREMETAL_PREFIX = "baremetal:"
# Neutron-lib migration shim. This will wrap any constants that are moved
# to that library in a deprecation warning, until they can be updated to
# import directly from their new location.

View File

@ -21,19 +21,6 @@ from neutron._i18n import _
from neutron.common import _deprecate
class MultipleExceptions(Exception):
"""Container for multiple exceptions encountered.
The API layer of Neutron will automatically unpack, translate,
filter, and combine the inner exceptions in any exception derived
from this class.
"""
def __init__(self, exceptions, *args, **kwargs):
super(MultipleExceptions, self).__init__(*args, **kwargs)
self.inner_exceptions = exceptions
class SubnetPoolNotFound(e.NotFound):
message = _("Subnet pool %(subnetpool_id)s could not be found.")
@ -57,14 +44,6 @@ class NetworkQosBindingNotFound(e.NotFound):
"could not be found.")
class PolicyInitError(e.NeutronException):
message = _("Failed to init policy %(policy)s because %(reason)s.")
class PolicyCheckError(e.NeutronException):
message = _("Failed to check policy %(policy)s because %(reason)s.")
class PolicyRemoveAuthorizationError(e.NotAuthorized):
message = _("Failed to remove provided policy %(policy_id)s "
"because you are not authorized.")
@ -313,10 +292,6 @@ class SubnetPoolQuotaExceeded(e.OverQuota):
message = _("Per-tenant subnet pool prefix quota exceeded.")
class DeviceNotFoundError(e.NeutronException):
message = _("Device '%(device_name)s' does not exist.")
class NetworkSubnetPoolAffinityError(e.BadRequest):
message = _("Subnets hosted on the same network must be allocated from "
"the same subnet pool.")

View File

@ -14,11 +14,11 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import constants
from oslo_config import cfg
from neutron._i18n import _
from neutron.agent.common import config
from neutron.common import constants
OPTS = [

View File

@ -17,6 +17,7 @@ import contextlib
from debtcollector import moves
from debtcollector import removals
from neutron_lib import exceptions
from oslo_config import cfg
from oslo_db import api as oslo_db_api
from oslo_db import exception as db_exc
@ -29,7 +30,6 @@ import sqlalchemy
from sqlalchemy.orm import exc
import traceback
from neutron.common import exceptions
from neutron.common import profiler # noqa
@ -106,12 +106,12 @@ def _is_nested_instance(e, etypes):
@contextlib.contextmanager
def exc_to_retry(exceptions):
def exc_to_retry(etypes):
try:
yield
except Exception as e:
with excutils.save_and_reraise_exception() as ctx:
if _is_nested_instance(e, exceptions):
if _is_nested_instance(e, etypes):
ctx.reraise = False
raise db_exc.RetryRequest(e)

View File

@ -558,8 +558,8 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
"subnets.")
raise exc.BadRequest(resource='subnets', msg=reason)
mode_list = [n_const.IPV6_SLAAC,
n_const.DHCPV6_STATELESS]
mode_list = [constants.IPV6_SLAAC,
constants.DHCPV6_STATELESS]
ra_mode = subnet.get('ipv6_ra_mode')
if ra_mode not in mode_list:

View File

@ -14,7 +14,7 @@
# under the License.
from neutron_lib.api import validators
from neutron_lib import constants as l3_constants
from neutron_lib import constants as lib_constants
from neutron_lib import exceptions as n_exc
import sqlalchemy as sa
from sqlalchemy import orm
@ -39,7 +39,7 @@ from neutron import manager
from neutron.plugins.common import constants as service_constants
DEVICE_OWNER_ROUTER_GW = l3_constants.DEVICE_OWNER_ROUTER_GW
DEVICE_OWNER_ROUTER_GW = lib_constants.DEVICE_OWNER_ROUTER_GW
class ExternalNetwork(model_base.BASEV2):

View File

@ -18,7 +18,7 @@ import itertools
from debtcollector import removals
import netaddr
from neutron_lib.api import validators
from neutron_lib import constants as l3_constants
from neutron_lib import constants as lib_constants
from neutron_lib import exceptions as n_exc
from oslo_log import log as logging
from oslo_utils import excutils
@ -54,10 +54,10 @@ from neutron.plugins.common import utils as p_utils
LOG = logging.getLogger(__name__)
DEVICE_OWNER_HA_REPLICATED_INT = l3_constants.DEVICE_OWNER_HA_REPLICATED_INT
DEVICE_OWNER_ROUTER_INTF = l3_constants.DEVICE_OWNER_ROUTER_INTF
DEVICE_OWNER_ROUTER_GW = l3_constants.DEVICE_OWNER_ROUTER_GW
DEVICE_OWNER_FLOATINGIP = l3_constants.DEVICE_OWNER_FLOATINGIP
DEVICE_OWNER_HA_REPLICATED_INT = lib_constants.DEVICE_OWNER_HA_REPLICATED_INT
DEVICE_OWNER_ROUTER_INTF = lib_constants.DEVICE_OWNER_ROUTER_INTF
DEVICE_OWNER_ROUTER_GW = lib_constants.DEVICE_OWNER_ROUTER_GW
DEVICE_OWNER_FLOATINGIP = lib_constants.DEVICE_OWNER_FLOATINGIP
EXTERNAL_GW_INFO = l3.EXTERNAL_GW_INFO
# Maps API field to DB column
@ -288,12 +288,12 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
def update_router(self, context, id, router):
r = router['router']
gw_info = r.pop(EXTERNAL_GW_INFO, l3_constants.ATTR_NOT_SPECIFIED)
gw_info = r.pop(EXTERNAL_GW_INFO, lib_constants.ATTR_NOT_SPECIFIED)
# check whether router needs and can be rescheduled to the proper
# l3 agent (associated with given external network);
# do check before update in DB as an exception will be raised
# in case no proper l3 agent found
if gw_info != l3_constants.ATTR_NOT_SPECIFIED:
if gw_info != lib_constants.ATTR_NOT_SPECIFIED:
candidates = self._check_router_needs_rescheduling(
context, id, gw_info)
# Update the gateway outside of the DB update since it involves L2
@ -341,7 +341,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
constants.L3_ROUTER_NAT)
if (not utils.is_extension_supported(
l3_plugin,
l3_constants.L3_AGENT_SCHEDULER_EXT_ALIAS) or
lib_constants.L3_AGENT_SCHEDULER_EXT_ALIAS) or
l3_plugin.router_scheduler is None):
# that might mean that we are dealing with non-agent-based
# implementation of l3 services
@ -378,7 +378,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
# Port has no 'tenant-id', as it is hidden from user
port_data = {'tenant_id': '', # intentionally not set
'network_id': network_id,
'fixed_ips': ext_ips or l3_constants.ATTR_NOT_SPECIFIED,
'fixed_ips': ext_ips or lib_constants.ATTR_NOT_SPECIFIED,
'device_id': router['id'],
'device_owner': DEVICE_OWNER_ROUTER_GW,
'admin_state_up': True,
@ -1018,11 +1018,11 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
RouterPort.router_id, models_v2.IPAllocation.ip_address).join(
models_v2.Port, models_v2.IPAllocation).filter(
models_v2.Port.network_id == internal_port['network_id'],
RouterPort.port_type.in_(l3_constants.ROUTER_INTERFACE_OWNERS),
RouterPort.port_type.in_(lib_constants.ROUTER_INTERFACE_OWNERS),
models_v2.IPAllocation.subnet_id == internal_subnet['id']
).join(gw_port, gw_port.device_id == RouterPort.router_id).filter(
gw_port.network_id == external_network_id,
gw_port.device_owner == l3_constants.DEVICE_OWNER_ROUTER_GW
gw_port.device_owner == lib_constants.DEVICE_OWNER_ROUTER_GW
).distinct()
first_router_id = None
@ -1171,7 +1171,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
gw_port = router.gw_port
for fixed_ip in gw_port.fixed_ips:
addr = netaddr.IPAddress(fixed_ip.ip_address)
if addr.version == l3_constants.IP_VERSION_4:
if addr.version == lib_constants.IP_VERSION_4:
next_hop = fixed_ip.ip_address
break
args = {'fixed_ip_address': internal_ip_address,
@ -1192,7 +1192,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
return any(s.ip_version == 4 for s in net.subnets)
def _create_floatingip(self, context, floatingip,
initial_status=l3_constants.FLOATINGIP_STATUS_ACTIVE):
initial_status=lib_constants.FLOATINGIP_STATUS_ACTIVE):
fip = floatingip['floatingip']
fip_id = uuidutils.generate_uuid()
@ -1215,7 +1215,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
'admin_state_up': True,
'device_id': fip_id,
'device_owner': DEVICE_OWNER_FLOATINGIP,
'status': l3_constants.PORT_STATUS_NOTAPPLICABLE,
'status': lib_constants.PORT_STATUS_NOTAPPLICABLE,
'name': ''}
if fip.get('floating_ip_address'):
port['fixed_ips'] = [
@ -1268,7 +1268,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
return floatingip_dict
def create_floatingip(self, context, floatingip,
initial_status=l3_constants.FLOATINGIP_STATUS_ACTIVE):
initial_status=lib_constants.FLOATINGIP_STATUS_ACTIVE):
return self._create_floatingip(context, floatingip, initial_status)
def _update_floatingip(self, context, id, floatingip):
@ -1606,8 +1606,8 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
port['subnets'] = []
port['extra_subnets'] = []
port['address_scopes'] = {l3_constants.IP_VERSION_4: None,
l3_constants.IP_VERSION_6: None}
port['address_scopes'] = {lib_constants.IP_VERSION_4: None,
lib_constants.IP_VERSION_6: None}
scopes = {}
for subnet in subnets_by_network[port['network_id']]:
@ -1642,18 +1642,18 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
for floating_ip in floating_ips:
router = routers_dict.get(floating_ip['router_id'])
if router:
router_floatingips = router.get(l3_constants.FLOATINGIP_KEY,
router_floatingips = router.get(lib_constants.FLOATINGIP_KEY,
[])
router_floatingips.append(floating_ip)
router[l3_constants.FLOATINGIP_KEY] = router_floatingips
router[lib_constants.FLOATINGIP_KEY] = router_floatingips
def _process_interfaces(self, routers_dict, interfaces):
for interface in interfaces:
router = routers_dict.get(interface['device_id'])
if router:
router_interfaces = router.get(l3_constants.INTERFACE_KEY, [])
router_interfaces = router.get(lib_constants.INTERFACE_KEY, [])
router_interfaces.append(interface)
router[l3_constants.INTERFACE_KEY] = router_interfaces
router[lib_constants.INTERFACE_KEY] = router_interfaces
def _get_router_info_list(self, context, router_ids=None, active=None,
device_owners=None):
@ -1780,7 +1780,7 @@ class L3_NAT_db_mixin(L3_NAT_dbonly_mixin, L3RpcNotifierMixin):
return router_interface_info
def create_floatingip(self, context, floatingip,
initial_status=l3_constants.FLOATINGIP_STATUS_ACTIVE):
initial_status=lib_constants.FLOATINGIP_STATUS_ACTIVE):
floatingip_dict = super(L3_NAT_db_mixin, self).create_floatingip(
context, floatingip, initial_status)
router_id = floatingip_dict['router_id']
@ -1852,7 +1852,7 @@ def _notify_subnet_gateway_ip_update(resource, event, trigger, **kwargs):
subnet_id = kwargs['subnet_id']
query = context.session.query(models_v2.Port).filter_by(
network_id=network_id,
device_owner=l3_constants.DEVICE_OWNER_ROUTER_GW)
device_owner=lib_constants.DEVICE_OWNER_ROUTER_GW)
query = query.join(models_v2.Port.fixed_ips).filter(
models_v2.IPAllocation.subnet_id == subnet_id)
router_ids = set(port['device_id'] for port in query)

View File

@ -23,6 +23,7 @@ revision = 'a8b517cff8ab'
down_revision = '7d9d8eeec6ad'
from alembic import op
from neutron_lib import constants as lib_const
import sqlalchemy as sa
from neutron.common import constants
@ -57,11 +58,11 @@ def upgrade():
# as a result of Ifd3e007aaf2a2ed8123275aa3a9f540838e3c003 being
# back-ported
for router_port in session.query(router_ports).filter(
router_ports.c.port_type == constants.DEVICE_OWNER_ROUTER_HA_INTF):
router_ports.c.port_type == lib_const.DEVICE_OWNER_ROUTER_HA_INTF):
router_port_tuples.discard((router_port.router_id,
router_port.port_id))
new_records = [dict(router_id=router_id, port_id=port_id,
port_type=constants.DEVICE_OWNER_ROUTER_HA_INTF)
port_type=lib_const.DEVICE_OWNER_ROUTER_HA_INTF)
for router_id, port_id in router_port_tuples]
op.bulk_insert(router_ports, new_records)
session.commit()

View File

@ -26,12 +26,11 @@ revision = '030a959ceafa'
down_revision = '3d0e74aa7d37'
from alembic import op
from neutron_lib import exceptions
import sqlalchemy as sa
from neutron._i18n import _
from neutron.common import exceptions
routerports = sa.Table(
'routerports', sa.MetaData(),
sa.Column('router_id', sa.String(36)),

View File

@ -213,11 +213,13 @@ class Subnet(model_base.HasStandardAttributes, model_base.BASEV2,
ipv6_ra_mode = sa.Column(sa.Enum(constants.IPV6_SLAAC,
constants.DHCPV6_STATEFUL,
constants.DHCPV6_STATELESS,
name='ipv6_ra_modes'), nullable=True)
name='ipv6_ra_modes'),
nullable=True)
ipv6_address_mode = sa.Column(sa.Enum(constants.IPV6_SLAAC,
constants.DHCPV6_STATEFUL,
constants.DHCPV6_STATELESS,
name='ipv6_address_modes'), nullable=True)
constants.DHCPV6_STATEFUL,
constants.DHCPV6_STATELESS,
name='ipv6_address_modes'),
nullable=True)
# subnets don't have their own rbac_entries, they just inherit from
# the network rbac entries
rbac_entries = orm.relationship(

View File

@ -27,7 +27,6 @@ from neutron._i18n import _LE, _LI, _LW
from neutron.callbacks import events
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.common import constants as n_const
from neutron import context
from neutron import manager
from neutron.notifiers import batch_notifier
@ -87,7 +86,7 @@ class Notifier(object):
if (port['device_id'] and uuidutils.is_uuid_like(port['device_id'])
and port['device_owner'].startswith((
constants.DEVICE_OWNER_COMPUTE_PREFIX,
n_const.DEVICE_OWNER_BAREMETAL_PREFIX))):
constants.DEVICE_OWNER_BAREMETAL_PREFIX))):
return True
except (KeyError, AttributeError):
pass

View File

@ -14,13 +14,13 @@
import itertools
import netaddr
from neutron_lib import constants as n_const
from neutron_lib import constants as lib_constants
from neutron_lib import exceptions
from oslo_versionedobjects import fields as obj_fields
import six
from neutron._i18n import _
from neutron.common import constants
from neutron.common import exceptions
class NeutronRangeConstrainedIntegerInvalidLimit(exceptions.NeutronException):
@ -29,7 +29,7 @@ class NeutronRangeConstrainedIntegerInvalidLimit(exceptions.NeutronException):
class IPV6ModeEnumField(obj_fields.AutoTypedField):
AUTO_TYPE = obj_fields.Enum(valid_values=constants.IPV6_MODES)
AUTO_TYPE = obj_fields.Enum(valid_values=lib_constants.IPV6_MODES)
class RangeConstrainedInteger(obj_fields.Integer):
@ -56,7 +56,7 @@ class IPNetworkPrefixLen(RangeConstrainedInteger):
"""IP network (CIDR) prefix length custom Enum"""
def __init__(self, **kwargs):
super(IPNetworkPrefixLen, self).__init__(
start=0, end=n_const.IPv6_BITS,
start=0, end=lib_constants.IPv6_BITS,
**kwargs)
@ -139,8 +139,8 @@ class IpProtocolEnum(obj_fields.Enum):
super(IpProtocolEnum, self).__init__(
valid_values=list(
itertools.chain(
n_const.IP_PROTOCOL_MAP.keys(),
[str(v) for v in n_const.IP_PROTOCOL_MAP.values()]
lib_constants.IP_PROTOCOL_MAP.keys(),
[str(v) for v in lib_constants.IP_PROTOCOL_MAP.values()]
)
),
**kwargs)

View File

@ -176,7 +176,7 @@ class PolicyHook(hooks.PecanHook):
# This exception must be explicitly caught as the exception
# translation hook won't be called if an error occurs in the
# 'after' handler.
raise webob.exc.HTTPForbidden(e.message)
raise webob.exc.HTTPForbidden(str(e))
if is_single:
resp = resp[0]

View File

@ -239,7 +239,8 @@ class L2populationRpcCallBackTunnelMixin(L2populationRpcCallBackMixin):
if local_vlan_map is not None:
vlanmanager.deprecate_local_vlan_map_in_object(
"%s.get_agent_ports()" % self.__class__.__name__)
"%s.get_agent_ports()" % self.__class__.__name__,
stacklevel_extra=1)
return get_lvm_from_mapping
return get_lvm_from_manager

View File

@ -19,10 +19,11 @@ from neutron_lib import exceptions
from neutron._i18n import _
def deprecate_local_vlan_map_in_object(object_name):
def deprecate_local_vlan_map_in_object(object_name, stacklevel_extra=0):
debtcollector.deprecate(
"local_vlan_map argument for %s was deprecated." % object_name,
version="Newton", removal_version="Ocata")
version="Newton", removal_version="Ocata",
stacklevel=4 + stacklevel_extra)
class VifIdNotFound(exceptions.NeutronException):

View File

@ -17,7 +17,7 @@ import collections
import re
from neutron_lib import constants
from neutron_lib import exceptions as lib_exc
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
@ -29,7 +29,6 @@ import six
from neutron._i18n import _, _LE, _LW
from neutron.api.v2 import attributes
from neutron.common import constants as const
from neutron.common import exceptions
LOG = logging.getLogger(__name__)
@ -265,7 +264,7 @@ class OwnerCheck(policy.Check):
target[parent_foreign_key],
fields=[parent_field])
target[self.target_field] = data[parent_field]
except lib_exc.NotFound as e:
except exceptions.NotFound as e:
# NOTE(kevinbenton): a NotFound exception can occur if a
# list operation is happening at the same time as one of
# the parents and its children being deleted. So we issue

View File

@ -13,6 +13,7 @@
# under the License.
from neutron_lib import constants as lib_const
from neutron_lib import exceptions as lib_exc
from oslo_config import cfg
from oslo_log import log as logging
@ -20,7 +21,6 @@ from neutron._i18n import _
from neutron.callbacks import events
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.common import exceptions as n_exc
from neutron.db import servicetype_db as st_db
from neutron import manager
from neutron.plugins.common import constants
@ -110,7 +110,7 @@ class DriverController(object):
# attributes via the API.
try:
_ensure_driver_supports_request(drv, router)
except n_exc.Invalid:
except lib_exc.Invalid:
# the current driver does not support this request, we need to
# migrate to a new provider. populate the distributed and ha
# flags from the previous state if not in the update so we can
@ -120,7 +120,7 @@ class DriverController(object):
# the flavor will make things inconsistent. We can probably
# update the flavor automatically in the future.
if old_router['flavor_id']:
raise n_exc.Invalid(_(
raise lib_exc.Invalid(_(
"Changing the 'ha' and 'distributed' attributes on a "
"router associated with a flavor is not supported."))
if 'distributed' not in router:
@ -202,7 +202,7 @@ class _LegacyPlusProviderConfiguration(
self.add_provider({'service_type': constants.L3_ROUTER_NAT,
'name': name, 'driver': path,
'default': False})
except n_exc.Invalid:
except lib_exc.Invalid:
LOG.debug("Could not add L3 provider '%s', it may have "
"already been explicitly defined.", name)
@ -244,6 +244,6 @@ def _ensure_driver_supports_request(drv, router_body):
if flag not in [True, False]:
continue # not specified in body
if not getattr(drv, attr).is_compatible(flag):
raise n_exc.Invalid(
raise lib_exc.Invalid(
_("Provider %(name)s does not support %(key)s=%(flag)s")
% dict(name=drv.name, key=key, flag=flag))

View File

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import debtcollector
import importlib
import itertools
import os
@ -32,9 +31,7 @@ LOG = logging.getLogger(__name__)
SERVICE_PROVIDERS = 'neutron.service_providers'
debtcollector.deprecate(
'Moved serviceprovider_opts to %s' % prov_config.__name__,
version="newton", removal_version="ocata")
# TODO(HenryG): use MovedGlobals to deprecate this.
serviceprovider_opts = prov_config.serviceprovider_opts
prov_config.register_service_provider_opts()

View File

@ -22,7 +22,6 @@ import six
import testtools
import neutron
from neutron.common import constants as n_const
from neutron.common import topics
from neutron import context
from neutron.db import agents_db
@ -79,7 +78,7 @@ def _register_agent(agent, plugin=None):
admin_context, agent['agent_type'], agent['host'])
def register_l3_agent(host=HOST, agent_mode=n_const.L3_AGENT_MODE_LEGACY,
def register_l3_agent(host=HOST, agent_mode=constants.L3_AGENT_MODE_LEGACY,
internal_only=True, ext_net_id='', ext_bridge='',
az=DEFAULT_AZ):
agent = _get_l3_agent_dict(host, agent_mode, internal_only, ext_net_id,