diff --git a/neutron/agent/dhcp/agent.py b/neutron/agent/dhcp/agent.py index b3bf8544b4e..b2e436b4369 100644 --- a/neutron/agent/dhcp/agent.py +++ b/neutron/agent/dhcp/agent.py @@ -17,6 +17,7 @@ import collections import os import eventlet +from neutron_lib import constants from neutron_lib import exceptions from oslo_config import cfg from oslo_log import log as logging @@ -29,7 +30,7 @@ from neutron.agent.linux import dhcp 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 constants as n_const from neutron.common import rpc as n_rpc from neutron.common import topics from neutron.common import utils @@ -428,7 +429,7 @@ class DhcpPluginApi(object): self.host = host target = oslo_messaging.Target( topic=topic, - namespace=constants.RPC_NAMESPACE_DHCP_PLUGIN, + namespace=n_const.RPC_NAMESPACE_DHCP_PLUGIN, version='1.0') self.client = n_rpc.get_client(target) @@ -580,7 +581,7 @@ class DhcpAgentWithStateReport(DhcpAgent): ctx = context.get_admin_context_without_session() agent_status = self.state_rpc.report_state( ctx, self.agent_state, True) - if agent_status == constants.AGENT_REVIVED: + if agent_status == n_const.AGENT_REVIVED: LOG.info(_LI("Agent has just been revived. " "Scheduling full sync")) self.schedule_resync("Agent has just been revived") diff --git a/neutron/agent/l3/agent.py b/neutron/agent/l3/agent.py index ddcb50da5f1..9e0893ed3eb 100644 --- a/neutron/agent/l3/agent.py +++ b/neutron/agent/l3/agent.py @@ -15,6 +15,7 @@ import eventlet import netaddr +from neutron_lib import constants as lib_const from oslo_config import cfg from oslo_log import log as logging import oslo_messaging @@ -646,7 +647,7 @@ class L3NATAgentWithStateReport(L3NATAgent): 'interface_driver': self.conf.interface_driver, 'log_agent_heartbeats': self.conf.AGENT.log_agent_heartbeats}, 'start_flag': True, - 'agent_type': l3_constants.AGENT_TYPE_L3} + 'agent_type': lib_const.AGENT_TYPE_L3} report_interval = self.conf.AGENT.report_interval if report_interval: self.heartbeat = loopingcall.FixedIntervalLoopingCall( @@ -663,9 +664,9 @@ class L3NATAgentWithStateReport(L3NATAgent): ex_gw_port = ri.get_ex_gw_port() if ex_gw_port: num_ex_gw_ports += 1 - num_interfaces += len(ri.router.get(l3_constants.INTERFACE_KEY, + num_interfaces += len(ri.router.get(lib_const.INTERFACE_KEY, [])) - num_floating_ips += len(ri.router.get(l3_constants.FLOATINGIP_KEY, + num_floating_ips += len(ri.router.get(lib_const.FLOATINGIP_KEY, [])) configurations = self.agent_state['configurations'] configurations['routers'] = num_routers diff --git a/neutron/agent/l3/dvr_edge_ha_router.py b/neutron/agent/l3/dvr_edge_ha_router.py index da356682719..06a124930c9 100644 --- a/neutron/agent/l3/dvr_edge_ha_router.py +++ b/neutron/agent/l3/dvr_edge_ha_router.py @@ -13,6 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants + from neutron.agent.l3.dvr_edge_router import DvrEdgeRouter from neutron.agent.l3 import dvr_snat_ns from neutron.agent.l3.ha_router import HaRouter @@ -75,7 +77,7 @@ class DvrEdgeHaRouter(DvrEdgeRouter, HaRouter): snat_interface = self._get_snat_int_device_name(port['id']) self.driver.unplug(snat_interface, namespace=self.ha_namespace, - prefix=l3_constants.SNAT_INT_DEV_PREFIX) + prefix=constants.SNAT_INT_DEV_PREFIX) self._clear_vips(snat_interface) super(DvrEdgeHaRouter, self)._external_gateway_removed( ex_gw_port, interface_name) diff --git a/neutron/agent/l3/dvr_edge_router.py b/neutron/agent/l3/dvr_edge_router.py index dc285e2d282..e2912272c5c 100644 --- a/neutron/agent/l3/dvr_edge_router.py +++ b/neutron/agent/l3/dvr_edge_router.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants as l3_constants from oslo_log import log as logging from neutron._i18n import _LE @@ -20,7 +21,6 @@ from neutron.agent.l3 import dvr_snat_ns from neutron.agent.l3 import router_info as router from neutron.agent.linux import ip_lib from neutron.agent.linux import iptables_manager -from neutron.common import constants as l3_constants LOG = logging.getLogger(__name__) diff --git a/neutron/agent/l3/dvr_local_router.py b/neutron/agent/l3/dvr_local_router.py index ff02f76316e..72bc1bbb16a 100644 --- a/neutron/agent/l3/dvr_local_router.py +++ b/neutron/agent/l3/dvr_local_router.py @@ -16,6 +16,7 @@ import binascii import collections import netaddr +from neutron_lib import constants as l3_constants from oslo_log import log as logging from oslo_utils import excutils import six @@ -24,7 +25,7 @@ from neutron._i18n import _LE, _LW 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 l3_constants +from neutron.common import constants as n_const from neutron.common import exceptions from neutron.common import utils as common_utils @@ -347,7 +348,7 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase): def get_floating_agent_gw_interface(self, ext_net_id): """Filter Floating Agent GW port for the external network.""" - fip_ports = self.router.get(l3_constants.FLOATINGIP_AGENT_INTF_KEY, []) + fip_ports = self.router.get(n_const.FLOATINGIP_AGENT_INTF_KEY, []) return next( (p for p in fip_ports if p['network_id'] == ext_net_id), None) diff --git a/neutron/agent/l3/ha_router.py b/neutron/agent/l3/ha_router.py index b7d7031fd7c..060be8165e2 100644 --- a/neutron/agent/l3/ha_router.py +++ b/neutron/agent/l3/ha_router.py @@ -16,6 +16,7 @@ import os import shutil import netaddr +from neutron_lib import constants as n_consts from oslo_log import log as logging from neutron._i18n import _LE @@ -23,7 +24,6 @@ from neutron.agent.l3 import router_info as router from neutron.agent.linux import external_process from neutron.agent.linux import ip_lib from neutron.agent.linux import keepalived -from neutron.common import constants as n_consts from neutron.common import utils as common_utils from neutron.extensions import portbindings diff --git a/neutron/agent/l3/legacy_router.py b/neutron/agent/l3/legacy_router.py index b725c3b590b..56ad76882ac 100644 --- a/neutron/agent/l3/legacy_router.py +++ b/neutron/agent/l3/legacy_router.py @@ -12,9 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants as l3_constants + from neutron.agent.l3 import router_info as router from neutron.agent.linux import ip_lib -from neutron.common import constants as l3_constants class LegacyRouter(router.RouterInfo): diff --git a/neutron/agent/l3/router_info.py b/neutron/agent/l3/router_info.py index d3f68d318cc..b876f199789 100644 --- a/neutron/agent/l3/router_info.py +++ b/neutron/agent/l3/router_info.py @@ -14,6 +14,7 @@ import collections import netaddr +from neutron_lib import constants as l3_constants from oslo_log import log as logging from neutron._i18n import _, _LE, _LW @@ -21,7 +22,7 @@ from neutron.agent.l3 import namespaces 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 l3_constants +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 @@ -351,7 +352,7 @@ class RouterInfo(object): def _internal_network_updated(self, port, subnet_id, prefix, old_prefix, updated_cidrs): interface_name = self.get_internal_device_name(port['id']) - if prefix != l3_constants.PROVISIONAL_IPV6_PD_PREFIX: + if prefix != n_const.PROVISIONAL_IPV6_PD_PREFIX: fixed_ips = port['fixed_ips'] for fixed_ip in fixed_ips: if fixed_ip['subnet_id'] == subnet_id: @@ -432,7 +433,7 @@ class RouterInfo(object): if 'subnets' in port: for subnet in port['subnets']: if (netaddr.IPNetwork(subnet['cidr']).version == 6 and - subnet['cidr'] != l3_constants.PROVISIONAL_IPV6_PD_PREFIX): + subnet['cidr'] != n_const.PROVISIONAL_IPV6_PD_PREFIX): return True def enable_radvd(self, internal_ports=None): @@ -707,7 +708,7 @@ class RouterInfo(object): 'snat', '-m mark ! --mark %s/%s ' '-m conntrack --ctstate DNAT ' '-j SNAT --to-source %s' - % (ext_in_mark, l3_constants.ROUTER_MARK_MASK, ex_gw_ip)) + % (ext_in_mark, n_const.ROUTER_MARK_MASK, ex_gw_ip)) return [dont_snat_traffic_to_internal_ports_if_not_to_floating_ip, snat_internal_traffic_to_floating_ip] @@ -721,7 +722,7 @@ class RouterInfo(object): mark = self.agent_conf.external_ingress_mark mark_packets_entering_external_gateway_port = ( 'mark', '-i %s -j MARK --set-xmark %s/%s' % - (interface_name, mark, l3_constants.ROUTER_MARK_MASK)) + (interface_name, mark, n_const.ROUTER_MARK_MASK)) return [mark_packets_entering_external_gateway_port] def _empty_snat_chains(self, iptables_manager): diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index 91a701db710..97e96fd81f0 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -21,6 +21,7 @@ import shutil import time import netaddr +from neutron_lib import constants from neutron_lib import exceptions from oslo_config import cfg from oslo_log import log as logging @@ -34,7 +35,7 @@ from neutron.agent.common import utils as agent_common_utils 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 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 @@ -351,8 +352,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 [constants.DHCPV6_STATEFUL, - constants.DHCPV6_STATELESS] or + if (addr_mode in [n_const.DHCPV6_STATEFUL, + n_const.DHCPV6_STATELESS] or not addr_mode and not ra_mode): mode = 'static' @@ -510,7 +511,7 @@ class Dnsmasq(DhcpLocalProcess): fixed_ips, key=lambda fip: ((fip.subnet_id in v6_nets) and ( v6_nets[fip.subnet_id].ipv6_address_mode == ( - constants.DHCPV6_STATELESS))), + n_const.DHCPV6_STATELESS))), reverse=True) def _iter_hosts(self): @@ -545,11 +546,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 (constants.IPV6_SLAAC, - constants.DHCPV6_STATELESS) + no_dhcp = addr_mode in (n_const.IPV6_SLAAC, + n_const.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 == constants.IPV6_SLAAC + no_opts = addr_mode == n_const.IPV6_SLAAC # If dns_name attribute is supported by ports API, return the # dns_assignment generated by the Neutron server. Otherwise, @@ -770,7 +771,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 == constants.IPV6_SLAAC)): + addr_mode == n_const.IPV6_SLAAC)): continue if subnet.dns_nameservers: options.append( @@ -1124,7 +1125,7 @@ class DeviceManager(object): {'device_id': device_id, 'network_id': network.id}) for port in network.ports: port_device_id = getattr(port, 'device_id', None) - if port_device_id == constants.DEVICE_ID_RESERVED_DHCP_PORT: + if port_device_id == n_const.DEVICE_ID_RESERVED_DHCP_PORT: try: port = self.plugin.update_dhcp_port( port.id, {'port': {'network_id': network.id, diff --git a/neutron/agent/linux/interface.py b/neutron/agent/linux/interface.py index ba5dbb0b2c1..acbeef22f29 100644 --- a/neutron/agent/linux/interface.py +++ b/neutron/agent/linux/interface.py @@ -16,6 +16,7 @@ import abc import netaddr +from neutron_lib import constants from oslo_config import cfg from oslo_log import log as logging from oslo_log import versionutils @@ -56,7 +57,7 @@ class LinuxInterfaceDriver(object): # from linux IF_NAMESIZE DEV_NAME_LEN = 14 - DEV_NAME_PREFIX = n_const.TAP_DEVICE_PREFIX + DEV_NAME_PREFIX = constants.TAP_DEVICE_PREFIX def __init__(self, conf): self.conf = conf @@ -181,8 +182,8 @@ class LinuxInterfaceDriver(object): # Manage on-link routes (routes without an associated address) new_onlink_cidrs = set(s['cidr'] for s in extra_subnets or []) - v4_onlink = device.route.list_onlink_routes(n_const.IP_VERSION_4) - v6_onlink = device.route.list_onlink_routes(n_const.IP_VERSION_6) + v4_onlink = device.route.list_onlink_routes(constants.IP_VERSION_4) + v6_onlink = device.route.list_onlink_routes(constants.IP_VERSION_6) existing_onlink_cidrs = set(r['cidr'] for r in v4_onlink + v6_onlink) for route in new_onlink_cidrs - existing_onlink_cidrs: @@ -292,7 +293,7 @@ class NullDriver(LinuxInterfaceDriver): class OVSInterfaceDriver(LinuxInterfaceDriver): """Driver for creating an internal interface on an OVS bridge.""" - DEV_NAME_PREFIX = n_const.TAP_DEVICE_PREFIX + DEV_NAME_PREFIX = constants.TAP_DEVICE_PREFIX def __init__(self, conf): super(OVSInterfaceDriver, self).__init__(conf) @@ -302,7 +303,7 @@ class OVSInterfaceDriver(LinuxInterfaceDriver): def _get_tap_name(self, dev_name, prefix=None): if self.conf.ovs_use_veth: dev_name = dev_name.replace(prefix or self.DEV_NAME_PREFIX, - n_const.TAP_DEVICE_PREFIX) + constants.TAP_DEVICE_PREFIX) return dev_name def _ovs_add_port(self, bridge, device_name, port_id, mac_address, @@ -381,7 +382,7 @@ class OVSInterfaceDriver(LinuxInterfaceDriver): class IVSInterfaceDriver(LinuxInterfaceDriver): """Driver for creating an internal interface on an IVS bridge.""" - DEV_NAME_PREFIX = n_const.TAP_DEVICE_PREFIX + DEV_NAME_PREFIX = constants.TAP_DEVICE_PREFIX def __init__(self, conf): super(IVSInterfaceDriver, self).__init__(conf) @@ -389,7 +390,7 @@ class IVSInterfaceDriver(LinuxInterfaceDriver): def _get_tap_name(self, dev_name, prefix=None): dev_name = dev_name.replace(prefix or self.DEV_NAME_PREFIX, - n_const.TAP_DEVICE_PREFIX) + constants.TAP_DEVICE_PREFIX) return dev_name def _ivs_add_port(self, device_name, port_id, mac_address): @@ -450,7 +451,7 @@ class BridgeInterfaceDriver(LinuxInterfaceDriver): # Enable agent to define the prefix tap_name = device_name.replace(prefix or self.DEV_NAME_PREFIX, - n_const.TAP_DEVICE_PREFIX) + constants.TAP_DEVICE_PREFIX) # Create ns_veth in a namespace if one is configured. root_veth, ns_veth = ip.add_veth(tap_name, device_name, namespace2=namespace) diff --git a/neutron/agent/linux/ip_lib.py b/neutron/agent/linux/ip_lib.py index 0cb2a87405d..44f9bbb76d2 100644 --- a/neutron/agent/linux/ip_lib.py +++ b/neutron/agent/linux/ip_lib.py @@ -18,6 +18,7 @@ import re import eventlet import netaddr +from neutron_lib import constants from neutron_lib import exceptions from oslo_config import cfg from oslo_log import log as logging @@ -26,7 +27,6 @@ import six from neutron._i18n import _, _LE from neutron.agent.common import utils -from neutron.common import constants from neutron.common import exceptions as n_exc LOG = logging.getLogger(__name__) diff --git a/neutron/agent/linux/iptables_firewall.py b/neutron/agent/linux/iptables_firewall.py index 00d4535e8aa..06034d65b13 100644 --- a/neutron/agent/linux/iptables_firewall.py +++ b/neutron/agent/linux/iptables_firewall.py @@ -17,6 +17,7 @@ import collections import re import netaddr +from neutron_lib import constants from oslo_config import cfg from oslo_log import log as logging import six @@ -28,7 +29,6 @@ from neutron.agent.linux import ipset_manager from neutron.agent.linux import iptables_comments as ic from neutron.agent.linux import iptables_manager from neutron.agent.linux import utils -from neutron.common import constants from neutron.common import exceptions as n_exc from neutron.common import ipv6_utils from neutron.common import utils as c_utils diff --git a/neutron/agent/linux/openvswitch_firewall/constants.py b/neutron/agent/linux/openvswitch_firewall/constants.py index f34578ec455..c03fdc3ba8d 100644 --- a/neutron/agent/linux/openvswitch_firewall/constants.py +++ b/neutron/agent/linux/openvswitch_firewall/constants.py @@ -13,7 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron.common import constants +from neutron_lib import constants + +from neutron.common import constants as n_const OF_STATE_NOT_TRACKED = "-trk" OF_STATE_TRACKED = "+trk" @@ -42,6 +44,6 @@ protocol_to_nw_proto = { PROTOCOLS_WITH_PORTS = (constants.PROTO_NAME_TCP, constants.PROTO_NAME_UDP) ethertype_to_dl_type_map = { - constants.IPv4: constants.ETHERTYPE_IP, - constants.IPv6: constants.ETHERTYPE_IPV6, + constants.IPv4: n_const.ETHERTYPE_IP, + constants.IPv6: n_const.ETHERTYPE_IPV6, } diff --git a/neutron/agent/linux/openvswitch_firewall/firewall.py b/neutron/agent/linux/openvswitch_firewall/firewall.py index f7a16fb4e0c..fa43b983d2b 100644 --- a/neutron/agent/linux/openvswitch_firewall/firewall.py +++ b/neutron/agent/linux/openvswitch_firewall/firewall.py @@ -14,6 +14,7 @@ # under the License. import netaddr +from neutron_lib import constants as lib_const from neutron_lib import exceptions from oslo_log import log as logging @@ -367,14 +368,14 @@ class OVSFirewallDriver(firewall.FirewallDriver): self._initialize_ingress(port) def _initialize_egress_ipv6_icmp(self, port): - for icmp_type in constants.ICMPV6_ALLOWED_TYPES: + for icmp_type in lib_const.ICMPV6_ALLOWED_TYPES: self._add_flow( table=ovs_consts.BASE_EGRESS_TABLE, priority=95, in_port=port.ofport, reg_port=port.ofport, dl_type=constants.ETHERTYPE_IPV6, - nw_proto=constants.PROTO_NUM_IPV6_ICMP, + nw_proto=lib_const.PROTO_NUM_IPV6_ICMP, icmp_type=icmp_type, actions='normal' ) @@ -439,7 +440,7 @@ class OVSFirewallDriver(firewall.FirewallDriver): reg_port=port.ofport, in_port=port.ofport, dl_type=dl_type, - nw_proto=constants.PROTO_NUM_UDP, + nw_proto=lib_const.PROTO_NUM_UDP, tp_src=src_port, tp_dst=dst_port, actions='resubmit(,{:d})'.format( @@ -455,7 +456,7 @@ class OVSFirewallDriver(firewall.FirewallDriver): in_port=port.ofport, reg_port=port.ofport, dl_type=dl_type, - nw_proto=constants.PROTO_NUM_UDP, + nw_proto=lib_const.PROTO_NUM_UDP, tp_src=src_port, tp_dst=dst_port, actions='drop' @@ -546,14 +547,14 @@ class OVSFirewallDriver(firewall.FirewallDriver): ) def _initialize_ingress_ipv6_icmp(self, port): - for icmp_type in constants.ICMPV6_ALLOWED_TYPES: + for icmp_type in lib_const.ICMPV6_ALLOWED_TYPES: self._add_flow( table=ovs_consts.BASE_INGRESS_TABLE, priority=100, reg_port=port.ofport, dl_dst=port.mac, dl_type=constants.ETHERTYPE_IPV6, - nw_proto=constants.PROTO_NUM_IPV6_ICMP, + nw_proto=lib_const.PROTO_NUM_IPV6_ICMP, icmp_type=icmp_type, actions='strip_vlan,output:{:d}'.format(port.ofport), ) @@ -579,7 +580,7 @@ class OVSFirewallDriver(firewall.FirewallDriver): priority=95, reg_port=port.ofport, dl_type=dl_type, - nw_proto=constants.PROTO_NUM_UDP, + nw_proto=lib_const.PROTO_NUM_UDP, tp_src=src_port, tp_dst=dst_port, actions='strip_vlan,output:{:d}'.format(port.ofport), diff --git a/neutron/agent/linux/openvswitch_firewall/rules.py b/neutron/agent/linux/openvswitch_firewall/rules.py index b096d64fe7c..1c7c5f7d471 100644 --- a/neutron/agent/linux/openvswitch_firewall/rules.py +++ b/neutron/agent/linux/openvswitch_firewall/rules.py @@ -20,7 +20,6 @@ from oslo_log import log as logging from neutron.agent import firewall from neutron.agent.linux import ip_lib from neutron.agent.linux.openvswitch_firewall import constants as ovsfw_consts -from neutron.common import constants from neutron.common import utils from neutron.plugins.ml2.drivers.openvswitch.agent.common import constants \ as ovs_consts @@ -83,7 +82,7 @@ def create_protocol_flows(direction, flow_template, port, rule): try: flow_template['nw_proto'] = ovsfw_consts.protocol_to_nw_proto[protocol] if rule['ethertype'] == n_consts.IPv6 and protocol == 'icmp': - flow_template['nw_proto'] = constants.PROTO_NUM_IPV6_ICMP + flow_template['nw_proto'] = n_consts.PROTO_NUM_IPV6_ICMP except KeyError: pass diff --git a/neutron/agent/linux/utils.py b/neutron/agent/linux/utils.py index bff3102b0bf..a5d2b43ad77 100644 --- a/neutron/agent/linux/utils.py +++ b/neutron/agent/linux/utils.py @@ -26,6 +26,7 @@ import threading import eventlet from eventlet.green import subprocess from eventlet import greenthread +from neutron_lib import constants from oslo_config import cfg from oslo_log import log as logging from oslo_rootwrap import client @@ -35,7 +36,6 @@ from six.moves import http_client as httplib from neutron._i18n import _, _LE from neutron.agent.common import config -from neutron.common import constants from neutron.common import utils from neutron import wsgi diff --git a/neutron/agent/metadata/agent.py b/neutron/agent/metadata/agent.py index db83093dcda..c772fb6ea39 100644 --- a/neutron/agent/metadata/agent.py +++ b/neutron/agent/metadata/agent.py @@ -16,6 +16,7 @@ import hashlib import hmac import httplib2 +from neutron_lib import constants from oslo_config import cfg from oslo_log import log as logging import oslo_messaging @@ -112,7 +113,7 @@ class MetadataProxyHandler(object): filters = {} if router_id: filters['device_id'] = [router_id] - filters['device_owner'] = n_const.ROUTER_INTERFACE_OWNERS + filters['device_owner'] = constants.ROUTER_INTERFACE_OWNERS if ip_address: filters['fixed_ips'] = {'ip_address': [ip_address]} if networks: @@ -251,7 +252,7 @@ class UnixDomainMetadataProxy(object): 'log_agent_heartbeats': cfg.CONF.AGENT.log_agent_heartbeats, }, 'start_flag': True, - 'agent_type': n_const.AGENT_TYPE_METADATA} + 'agent_type': constants.AGENT_TYPE_METADATA} report_interval = cfg.CONF.AGENT.report_interval if report_interval: self.heartbeat = loopingcall.FixedIntervalLoopingCall( diff --git a/neutron/agent/rpc.py b/neutron/agent/rpc.py index 784f7414654..28f2a0935ff 100644 --- a/neutron/agent/rpc.py +++ b/neutron/agent/rpc.py @@ -16,12 +16,13 @@ from datetime import datetime import itertools +from neutron_lib import constants from oslo_log import log as logging import oslo_messaging from oslo_utils import uuidutils from neutron._i18n import _LW -from neutron.common import constants +from neutron.common import constants as n_const from neutron.common import rpc as n_rpc from neutron.common import topics @@ -68,7 +69,7 @@ class PluginReportStateAPI(object): """ def __init__(self, topic): target = oslo_messaging.Target(topic=topic, version='1.0', - namespace=constants.RPC_NAMESPACE_STATE) + namespace=n_const.RPC_NAMESPACE_STATE) self.client = n_rpc.get_client(target) def report_state(self, context, agent_state, use_call=False): diff --git a/neutron/api/rpc/agentnotifiers/dhcp_rpc_agent_api.py b/neutron/api/rpc/agentnotifiers/dhcp_rpc_agent_api.py index e504f329ffb..1bb88ad94d4 100644 --- a/neutron/api/rpc/agentnotifiers/dhcp_rpc_agent_api.py +++ b/neutron/api/rpc/agentnotifiers/dhcp_rpc_agent_api.py @@ -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_log import log as logging import oslo_messaging @@ -21,7 +22,7 @@ from neutron._i18n import _LE, _LW from neutron.callbacks import events from neutron.callbacks import registry from neutron.callbacks import resources -from neutron.common import constants +from neutron.common import constants as n_const from neutron.common import rpc as n_rpc from neutron.common import topics from neutron.common import utils @@ -118,7 +119,7 @@ class DhcpAgentNotifyAPI(object): return enabled_agents def _is_reserved_dhcp_port(self, port): - return port.get('device_id') == constants.DEVICE_ID_RESERVED_DHCP_PORT + return port.get('device_id') == n_const.DEVICE_ID_RESERVED_DHCP_PORT def _notify_agents(self, context, method, payload, network_id): """Notify all the agents that are hosting the network.""" diff --git a/neutron/api/rpc/agentnotifiers/l3_rpc_agent_api.py b/neutron/api/rpc/agentnotifiers/l3_rpc_agent_api.py index f239ed67681..70ab9f39533 100644 --- a/neutron/api/rpc/agentnotifiers/l3_rpc_agent_api.py +++ b/neutron/api/rpc/agentnotifiers/l3_rpc_agent_api.py @@ -15,11 +15,11 @@ import random +from neutron_lib import constants from oslo_log import log as logging import oslo_messaging from neutron._i18n import _LE -from neutron.common import constants from neutron.common import rpc as n_rpc from neutron.common import topics from neutron.common import utils diff --git a/neutron/api/rpc/agentnotifiers/metering_rpc_agent_api.py b/neutron/api/rpc/agentnotifiers/metering_rpc_agent_api.py index 6787781b866..b1cf4de5a8b 100644 --- a/neutron/api/rpc/agentnotifiers/metering_rpc_agent_api.py +++ b/neutron/api/rpc/agentnotifiers/metering_rpc_agent_api.py @@ -12,11 +12,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 import oslo_messaging import six -from neutron.common import constants from neutron.common import rpc as n_rpc from neutron.common import topics from neutron.common import utils diff --git a/neutron/api/rpc/handlers/dhcp_rpc.py b/neutron/api/rpc/handlers/dhcp_rpc.py index df110a04f8d..8722187452e 100644 --- a/neutron/api/rpc/handlers/dhcp_rpc.py +++ b/neutron/api/rpc/handlers/dhcp_rpc.py @@ -17,6 +17,7 @@ import copy import itertools import operator +from neutron_lib import constants from neutron_lib import exceptions from oslo_config import cfg from oslo_db import exception as db_exc @@ -25,8 +26,7 @@ import oslo_messaging from oslo_utils import excutils from neutron._i18n import _, _LW -from neutron.api.v2 import attributes -from neutron.common import constants +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 api as db_api @@ -65,7 +65,7 @@ class DhcpRpcCallback(object): # DHCP agent since Juno, so similar rationale for not bumping the # major version as above applies here too. target = oslo_messaging.Target( - namespace=constants.RPC_NAMESPACE_DHCP_PLUGIN, + namespace=n_const.RPC_NAMESPACE_DHCP_PLUGIN, version='1.4') def _get_active_networks(self, context, **kwargs): @@ -203,7 +203,7 @@ class DhcpRpcCallback(object): port['port']['device_owner'] = constants.DEVICE_OWNER_DHCP port['port'][portbindings.HOST_ID] = host if 'mac_address' not in port['port']: - port['port']['mac_address'] = attributes.ATTR_NOT_SPECIFIED + port['port']['mac_address'] = constants.ATTR_NOT_SPECIFIED plugin = manager.NeutronManager.get_plugin() return self._port_action(plugin, context, port, 'create_port') @@ -216,7 +216,7 @@ class DhcpRpcCallback(object): port['port'][portbindings.HOST_ID] = host plugin = manager.NeutronManager.get_plugin() old_port = plugin.get_port(context, port['id']) - if (old_port['device_id'] != constants.DEVICE_ID_RESERVED_DHCP_PORT + if (old_port['device_id'] != n_const.DEVICE_ID_RESERVED_DHCP_PORT and old_port['device_id'] != utils.get_dhcp_agent_device_id(port['port']['network_id'], host)): raise n_exc.DhcpPortInUse(port_id=port['id']) diff --git a/neutron/api/rpc/handlers/l3_rpc.py b/neutron/api/rpc/handlers/l3_rpc.py index 18deea94f50..a09528b40cf 100644 --- a/neutron/api/rpc/handlers/l3_rpc.py +++ b/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 constants from neutron_lib import exceptions from oslo_config import cfg from oslo_log import log as logging @@ -20,7 +21,7 @@ import oslo_messaging from oslo_serialization import jsonutils import six -from neutron.common import constants +from neutron.common import constants as n_const from neutron.common import utils from neutron import context as neutron_context from neutron.db import api as db_api @@ -119,7 +120,7 @@ class L3RpcCallback(object): gw_port_host, router.get('gw_port'), router['id']) - for p in router.get(constants.SNAT_ROUTER_INTF_KEY, []): + for p in router.get(n_const.SNAT_ROUTER_INTF_KEY, []): self._ensure_host_set_on_port(context, gw_port_host, p, router['id']) diff --git a/neutron/api/v2/attributes.py b/neutron/api/v2/attributes.py index 581af5bcdb9..5ab202372c3 100644 --- a/neutron/api/v2/attributes.py +++ b/neutron/api/v2/attributes.py @@ -15,8 +15,10 @@ import functools import re +import sys import netaddr +from neutron_lib import constants from neutron_lib import exceptions as n_exc from oslo_log import log as logging from oslo_utils import uuidutils @@ -24,12 +26,12 @@ import six import webob.exc from neutron._i18n import _ -from neutron.common import constants +from neutron.common import _deprecate +from neutron.common import constants as n_const LOG = logging.getLogger(__name__) -ATTR_NOT_SPECIFIED = object() # Defining a constant to avoid repeating string literal in several modules SHARED = 'shared' @@ -75,7 +77,7 @@ def _verify_dict_keys(expected_keys, target_dict, strict=True): def is_attr_set(attribute): - return not (attribute is None or attribute is ATTR_NOT_SPECIFIED) + return not (attribute is None or attribute is constants.ATTR_NOT_SPECIFIED) def _validate_list_of_items(item_validator, data, *args, **kwargs): @@ -192,8 +194,8 @@ def _validate_mac_address(data, valid_values=None): valid_mac = False if valid_mac: - valid_mac = not netaddr.EUI(data) in map(netaddr.EUI, - constants.INVALID_MAC_ADDRESSES) + valid_mac = not netaddr.EUI(data) in map( + netaddr.EUI, constants.INVALID_MAC_ADDRESSES) # TODO(arosen): The code in this file should be refactored # so it catches the correct exceptions. _validate_no_whitespace # raises AttributeError if data is None. @@ -600,13 +602,10 @@ def convert_to_list(data): return [data] -HEX_ELEM = '[0-9A-Fa-f]' -UUID_PATTERN = '-'.join([HEX_ELEM + '{8}', HEX_ELEM + '{4}', - HEX_ELEM + '{4}', HEX_ELEM + '{4}', - HEX_ELEM + '{12}']) # Note: In order to ensure that the MAC address is unicast the first byte # must be even. -MAC_PATTERN = "^%s[aceACE02468](:%s{2}){5}$" % (HEX_ELEM, HEX_ELEM) +MAC_PATTERN = "^%s[aceACE02468](:%s{2}){5}$" % (constants.HEX_ELEM, + constants.HEX_ELEM) # Dictionary that maintains a list of validation functions validators = {'type:dict': _validate_dict, @@ -721,12 +720,12 @@ RESOURCE_ATTRIBUTE_MAP = { 'convert_to': convert_to_boolean, 'is_visible': True}, 'mac_address': {'allow_post': True, 'allow_put': True, - 'default': ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'validate': {'type:mac_address': None}, 'enforce_policy': True, 'is_visible': True}, 'fixed_ips': {'allow_post': True, 'allow_put': True, - 'default': ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'convert_list_to': convert_kvp_list_to_dict, 'validate': {'type:fixed_ips': None}, 'enforce_policy': True, @@ -764,7 +763,7 @@ RESOURCE_ATTRIBUTE_MAP = { 'is_visible': True}, 'subnetpool_id': {'allow_post': True, 'allow_put': False, - 'default': ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'required_by_policy': False, 'validate': {'type:subnetpool_id_or_none': None}, 'is_visible': True}, @@ -772,31 +771,31 @@ RESOURCE_ATTRIBUTE_MAP = { 'allow_put': False, 'validate': {'type:non_negative': None}, 'convert_to': convert_to_int, - 'default': ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'required_by_policy': False, 'is_visible': False}, 'cidr': {'allow_post': True, 'allow_put': False, - 'default': ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'validate': {'type:subnet_or_none': None}, 'required_by_policy': False, 'is_visible': True}, 'gateway_ip': {'allow_post': True, 'allow_put': True, - 'default': ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'validate': {'type:ip_address_or_none': None}, 'is_visible': True}, 'allocation_pools': {'allow_post': True, 'allow_put': True, - 'default': ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'validate': {'type:ip_pools': None}, 'is_visible': True}, 'dns_nameservers': {'allow_post': True, 'allow_put': True, 'convert_to': convert_none_to_empty_list, - 'default': ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'validate': {'type:nameservers': None}, 'is_visible': True}, 'host_routes': {'allow_post': True, 'allow_put': True, 'convert_to': convert_none_to_empty_list, - 'default': ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'validate': {'type:hostroutes': None}, 'is_visible': True}, 'tenant_id': {'allow_post': True, 'allow_put': False, @@ -808,13 +807,13 @@ RESOURCE_ATTRIBUTE_MAP = { 'convert_to': convert_to_boolean, 'is_visible': True}, 'ipv6_ra_mode': {'allow_post': True, 'allow_put': False, - 'default': ATTR_NOT_SPECIFIED, - 'validate': {'type:values': constants.IPV6_MODES}, + 'default': constants.ATTR_NOT_SPECIFIED, + 'validate': {'type:values': n_const.IPV6_MODES}, 'is_visible': True}, 'ipv6_address_mode': {'allow_post': True, 'allow_put': False, - 'default': ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'validate': {'type:values': - constants.IPV6_MODES}, + n_const.IPV6_MODES}, 'is_visible': True}, SHARED: {'allow_post': False, 'allow_put': False, @@ -847,7 +846,7 @@ RESOURCE_ATTRIBUTE_MAP = { 'allow_put': True, 'validate': {'type:non_negative': None}, 'convert_to': convert_to_int, - 'default': ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'is_visible': True}, 'ip_version': {'allow_post': False, 'allow_put': False, @@ -856,17 +855,17 @@ RESOURCE_ATTRIBUTE_MAP = { 'allow_put': True, 'validate': {'type:non_negative': None}, 'convert_to': convert_to_int, - 'default': ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'is_visible': True}, 'min_prefixlen': {'allow_post': True, 'allow_put': True, - 'default': ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'validate': {'type:non_negative': None}, 'convert_to': convert_to_int, 'is_visible': True}, 'max_prefixlen': {'allow_post': True, 'allow_put': True, - 'default': ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'validate': {'type:non_negative': None}, 'convert_to': convert_to_int, 'is_visible': True}, @@ -951,7 +950,7 @@ def fill_default_value(attr_info, res_dict, def convert_value(attr_info, res_dict, exc_cls=ValueError): for attr, attr_vals in six.iteritems(attr_info): if (attr not in res_dict or - res_dict[attr] is ATTR_NOT_SPECIFIED): + res_dict[attr] is constants.ATTR_NOT_SPECIFIED): continue # Convert values if necessary if 'convert_to' in attr_vals: @@ -990,3 +989,22 @@ def verify_attributes(res_dict, attr_info): if extra_keys: msg = _("Unrecognized attribute(s) '%s'") % ', '.join(extra_keys) raise webob.exc.HTTPBadRequest(msg) + + +# Shim added to move the following to neutron_lib.constants: +# ATTR_NOT_SPECIFIED +# HEX_ELEM +# UUID_PATTERN + +# 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. +# If you're wondering why we bother saving _OLD_REF, it is because if we +# do not, then the original module we are overwriting gets garbage collected, +# and then you will find some super strange behavior with inherited classes +# and the like. Saving a ref keeps it around. + +# WARNING: THESE MUST BE THE LAST TWO LINES IN THIS MODULE +_OLD_REF = sys.modules[__name__] +sys.modules[__name__] = _deprecate._DeprecateSubset(globals(), constants) +# WARNING: THESE MUST BE THE LAST TWO LINES IN THIS MODULE diff --git a/neutron/api/v2/base.py b/neutron/api/v2/base.py index 6b1cd14d22b..d5fb688b041 100644 --- a/neutron/api/v2/base.py +++ b/neutron/api/v2/base.py @@ -17,6 +17,7 @@ import collections import copy import netaddr +from neutron_lib import constants from neutron_lib import exceptions from oslo_config import cfg from oslo_log import log as logging @@ -30,7 +31,7 @@ from neutron.api import api_common 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 constants as n_const from neutron.common import exceptions as n_exc from neutron.common import rpc as n_rpc from neutron.db import api as db_api @@ -80,7 +81,7 @@ class Controller(object): # use plugin's dhcp notifier, if this is already instantiated agent_notifiers = getattr(plugin, 'agent_notifiers', {}) self._dhcp_agent_notifier = ( - agent_notifiers.get(const.AGENT_TYPE_DHCP) or + agent_notifiers.get(constants.AGENT_TYPE_DHCP) or dhcp_rpc_agent_api.DhcpAgentNotifyAPI() ) if cfg.CONF.notify_nova_on_port_data_changes: @@ -602,7 +603,7 @@ class Controller(object): # Make a list of attributes to be updated to inform the policy engine # which attributes are set explicitly so that it can distinguish them # from the ones that are set to their default values. - orig_obj[const.ATTRIBUTES_TO_UPDATE] = body[self._resource].keys() + orig_obj[n_const.ATTRIBUTES_TO_UPDATE] = body[self._resource].keys() try: policy.enforce(request.context, action, diff --git a/neutron/cmd/netns_cleanup.py b/neutron/cmd/netns_cleanup.py index 6010b72ca47..49a32eadb83 100644 --- a/neutron/cmd/netns_cleanup.py +++ b/neutron/cmd/netns_cleanup.py @@ -17,6 +17,7 @@ import itertools import re import time +from neutron_lib import constants from oslo_config import cfg from oslo_log import log as logging from oslo_utils import importutils @@ -32,7 +33,6 @@ from neutron.agent.linux import dhcp from neutron.agent.linux import external_process from neutron.agent.linux import interface from neutron.agent.linux import ip_lib -from neutron.api.v2 import attributes from neutron.common import config @@ -111,7 +111,7 @@ def eligible_for_deletion(conf, namespace, force=False): else: prefixes = itertools.chain(*NS_PREFIXES.values()) ns_mangling_pattern = '(%s%s)' % ('|'.join(prefixes), - attributes.UUID_PATTERN) + constants.UUID_PATTERN) # filter out namespaces without UUID as the name if not re.match(ns_mangling_pattern, namespace): diff --git a/neutron/cmd/sanity/checks.py b/neutron/cmd/sanity/checks.py index 439ce253954..0e3897a1233 100644 --- a/neutron/cmd/sanity/checks.py +++ b/neutron/cmd/sanity/checks.py @@ -18,6 +18,7 @@ import shutil import tempfile import netaddr +from neutron_lib import constants as n_consts from oslo_config import cfg from oslo_log import log as logging from oslo_utils import uuidutils @@ -31,7 +32,7 @@ from neutron.agent.linux import ip_lib from neutron.agent.linux import ip_link_support from neutron.agent.linux import keepalived from neutron.agent.linux import utils as agent_utils -from neutron.common import constants as n_consts +from neutron.common import constants from neutron.plugins.common import constants as const from neutron.plugins.ml2.drivers.openvswitch.agent.common \ import constants as ovs_const @@ -135,7 +136,7 @@ def icmpv6_header_match_supported(): return ofctl_arg_supported(cmd='add-flow', table=ovs_const.ARP_SPOOF_TABLE, priority=1, - dl_type=n_consts.ETHERTYPE_IPV6, + dl_type=constants.ETHERTYPE_IPV6, nw_proto=n_consts.PROTO_NUM_IPV6_ICMP, icmp_type=n_consts.ICMPV6_TYPE_NA, nd_target='fdf8:f53b:82e4::10', diff --git a/neutron/common/_deprecate.py b/neutron/common/_deprecate.py index cba2f0acd7a..4d2c37741ae 100644 --- a/neutron/common/_deprecate.py +++ b/neutron/common/_deprecate.py @@ -14,7 +14,6 @@ import copy import debtcollector import inspect -import os from neutron._i18n import _ @@ -29,16 +28,12 @@ class _DeprecateSubset(object): if (not name.startswith("__") and not inspect.ismodule(a) and name in vars(self.other_mod)): - # These should be enabled after most have been cleaned up - # in neutron proper, which may not happen during the busy M-3. - - if os.getenv('NEUTRON_SHOW_DEPRECATION_WARNINGS'): - debtcollector.deprecate( - name, - message='moved to neutron_lib', - version='mitaka', - removal_version='newton', - stacklevel=4) + debtcollector.deprecate( + name, + message='moved to neutron_lib', + version='mitaka', + removal_version='newton', + stacklevel=4) return vars(self.other_mod)[name] diff --git a/neutron/common/constants.py b/neutron/common/constants.py index 626bd969a10..db2f5c03c1a 100644 --- a/neutron/common/constants.py +++ b/neutron/common/constants.py @@ -22,13 +22,6 @@ from neutron.common import _deprecate ROUTER_PORT_OWNERS = lib_constants.ROUTER_INTERFACE_OWNERS_SNAT + \ (lib_constants.DEVICE_OWNER_ROUTER_GW,) -# TODO(anilvenkata) Below constants should be added to neutron-lib -DEVICE_OWNER_HA_REPLICATED_INT = (lib_constants.DEVICE_OWNER_NETWORK_PREFIX + - "ha_router_replicated_interface") -ROUTER_INTERFACE_OWNERS = lib_constants.ROUTER_INTERFACE_OWNERS + \ - (DEVICE_OWNER_HA_REPLICATED_INT,) -ROUTER_INTERFACE_OWNERS_SNAT = lib_constants.ROUTER_INTERFACE_OWNERS_SNAT + \ - (DEVICE_OWNER_HA_REPLICATED_INT,) ROUTER_STATUS_ACTIVE = 'ACTIVE' # NOTE(kevinbenton): a BUILD status for routers could be added in the future @@ -65,96 +58,23 @@ ETHERTYPE_ARP = 0x0806 ETHERTYPE_IP = 0x0800 ETHERTYPE_IPV6 = 0x86DD -# Protocol names and numbers for Security Groups/Firewalls -PROTO_NAME_AH = 'ah' -PROTO_NAME_DCCP = 'dccp' -PROTO_NAME_EGP = 'egp' -PROTO_NAME_ESP = 'esp' -PROTO_NAME_GRE = 'gre' -PROTO_NAME_ICMP = 'icmp' -PROTO_NAME_IGMP = 'igmp' -PROTO_NAME_IPV6_ENCAP = 'ipv6-encap' -PROTO_NAME_IPV6_FRAG = 'ipv6-frag' -PROTO_NAME_IPV6_ICMP = 'ipv6-icmp' -PROTO_NAME_IPV6_NONXT = 'ipv6-nonxt' -PROTO_NAME_IPV6_OPTS = 'ipv6-opts' -PROTO_NAME_IPV6_ROUTE = 'ipv6-route' -PROTO_NAME_OSPF = 'ospf' -PROTO_NAME_PGM = 'pgm' -PROTO_NAME_RSVP = 'rsvp' -PROTO_NAME_SCTP = 'sctp' -PROTO_NAME_TCP = 'tcp' -PROTO_NAME_UDP = 'udp' -PROTO_NAME_UDPLITE = 'udplite' -PROTO_NAME_VRRP = 'vrrp' - # TODO(amotoki): It should be moved to neutron-lib. # For backward-compatibility of security group rule API, # we keep the old value for IPv6 ICMP. # It should be clean up in the future. PROTO_NAME_IPV6_ICMP_LEGACY = 'icmpv6' -PROTO_NUM_AH = 51 -PROTO_NUM_DCCP = 33 -PROTO_NUM_EGP = 8 -PROTO_NUM_ESP = 50 -PROTO_NUM_GRE = 47 -PROTO_NUM_ICMP = 1 -PROTO_NUM_IGMP = 2 -PROTO_NUM_IPV6_ENCAP = 41 -PROTO_NUM_IPV6_FRAG = 44 -PROTO_NUM_IPV6_ICMP = 58 -PROTO_NUM_IPV6_NONXT = 59 -PROTO_NUM_IPV6_OPTS = 60 -PROTO_NUM_IPV6_ROUTE = 43 -PROTO_NUM_OSPF = 89 -PROTO_NUM_PGM = 113 -PROTO_NUM_RSVP = 46 -PROTO_NUM_SCTP = 132 -PROTO_NUM_TCP = 6 -PROTO_NUM_UDP = 17 -PROTO_NUM_UDPLITE = 136 -PROTO_NUM_VRRP = 112 - -IP_PROTOCOL_MAP = {PROTO_NAME_AH: PROTO_NUM_AH, - PROTO_NAME_DCCP: PROTO_NUM_DCCP, - PROTO_NAME_EGP: PROTO_NUM_EGP, - PROTO_NAME_ESP: PROTO_NUM_ESP, - PROTO_NAME_GRE: PROTO_NUM_GRE, - PROTO_NAME_ICMP: PROTO_NUM_ICMP, - PROTO_NAME_IGMP: PROTO_NUM_IGMP, - PROTO_NAME_IPV6_ENCAP: PROTO_NUM_IPV6_ENCAP, - PROTO_NAME_IPV6_FRAG: PROTO_NUM_IPV6_FRAG, - PROTO_NAME_IPV6_ICMP: PROTO_NUM_IPV6_ICMP, - PROTO_NAME_IPV6_NONXT: PROTO_NUM_IPV6_NONXT, - PROTO_NAME_IPV6_OPTS: PROTO_NUM_IPV6_OPTS, - PROTO_NAME_IPV6_ROUTE: PROTO_NUM_IPV6_ROUTE, - PROTO_NAME_OSPF: PROTO_NUM_OSPF, - PROTO_NAME_PGM: PROTO_NUM_PGM, - PROTO_NAME_RSVP: PROTO_NUM_RSVP, - PROTO_NAME_SCTP: PROTO_NUM_SCTP, - PROTO_NAME_TCP: PROTO_NUM_TCP, - PROTO_NAME_UDP: PROTO_NUM_UDP, - PROTO_NAME_UDPLITE: PROTO_NUM_UDPLITE, - PROTO_NAME_VRRP: PROTO_NUM_VRRP} - -IP_PROTOCOL_NAME_ALIASES = {PROTO_NAME_IPV6_ICMP_LEGACY: PROTO_NAME_IPV6_ICMP} +IP_PROTOCOL_NAME_ALIASES = { + PROTO_NAME_IPV6_ICMP_LEGACY: lib_constants.PROTO_NAME_IPV6_ICMP} VALID_DSCP_MARKS = [0, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 46, 48, 56] -IP_PROTOCOL_NUM_TO_NAME_MAP = {str(v): k for k, v in IP_PROTOCOL_MAP.items()} +IP_PROTOCOL_NUM_TO_NAME_MAP = { + str(v): k for k, v in lib_constants.IP_PROTOCOL_MAP.items()} -# List of ICMPv6 types that should be allowed by default: -# Multicast Listener Query (130), -# Multicast Listener Report (131), -# Multicast Listener Done (132), # Neighbor Solicitation (135), ICMPV6_TYPE_NC = 135 -# Neighbor Advertisement (136) -ICMPV6_TYPE_NA = 136 -ICMPV6_ALLOWED_TYPES = [130, 131, 132, 135, 136] -ICMPV6_TYPE_RA = 134 DHCPV6_STATEFUL = 'dhcpv6-stateful' DHCPV6_STATELESS = 'dhcpv6-stateless' @@ -163,33 +83,18 @@ IPV6_MODES = [DHCPV6_STATEFUL, DHCPV6_STATELESS, IPV6_SLAAC] IPV6_LLA_PREFIX = 'fe80::/64' -# Human-readable ID to which the subnetpool ID should be set to -# indicate that IPv6 Prefix Delegation is enabled for a given subnet -IPV6_PD_POOL_ID = 'prefix_delegation' - # Special provisional prefix for IPv6 Prefix Delegation PROVISIONAL_IPV6_PD_PREFIX = '::/64' # Timeout in seconds for getting an IPv6 LLA LLA_TASK_TIMEOUT = 40 -# Linux interface max length -DEVICE_NAME_MAX_LEN = 15 - -# vhost-user device names start with "vhu" -VHOST_USER_DEVICE_PREFIX = 'vhu' -# Device names start with "macvtap" -MACVTAP_DEVICE_PREFIX = 'macvtap' -# The vswitch side of a veth pair for a nova iptables filter setup -VETH_DEVICE_PREFIX = 'qvo' -# prefix for SNAT interface in DVR -SNAT_INT_DEV_PREFIX = 'sg-' - # Possible prefixes to partial port IDs in interface names used by the OVS, # Linux Bridge, and IVS VIF drivers in Nova and the neutron agents. See the # 'get_ovs_interfaceid' method in Nova (nova/virt/libvirt/vif.py) for details. -INTERFACE_PREFIXES = (lib_constants.TAP_DEVICE_PREFIX, VETH_DEVICE_PREFIX, - SNAT_INT_DEV_PREFIX) +INTERFACE_PREFIXES = (lib_constants.TAP_DEVICE_PREFIX, + lib_constants.VETH_DEVICE_PREFIX, + lib_constants.SNAT_INT_DEV_PREFIX) ATTRIBUTES_TO_UPDATE = 'attributes_to_update' diff --git a/neutron/common/ipv6_utils.py b/neutron/common/ipv6_utils.py index a0c8f0cc704..1635fe72169 100644 --- a/neutron/common/ipv6_utils.py +++ b/neutron/common/ipv6_utils.py @@ -19,6 +19,7 @@ IPv6-related utilities and helper functions. import os import netaddr +from neutron_lib import constants as const from oslo_log import log from neutron._i18n import _, _LI @@ -83,4 +84,4 @@ def is_ipv6_pd_enabled(subnet): """Returns True if the subnetpool_id of the given subnet is equal to constants.IPV6_PD_POOL_ID """ - return subnet.get('subnetpool_id') == constants.IPV6_PD_POOL_ID + return subnet.get('subnetpool_id') == const.IPV6_PD_POOL_ID diff --git a/neutron/common/utils.py b/neutron/common/utils.py index b164bb32fc4..ab49087f7c0 100644 --- a/neutron/common/utils.py +++ b/neutron/common/utils.py @@ -35,6 +35,7 @@ import uuid from eventlet.green import subprocess import netaddr +from neutron_lib import constants as n_const from oslo_concurrency import lockutils from oslo_config import cfg from oslo_db import exception as db_exc @@ -46,7 +47,6 @@ import six from stevedore import driver from neutron._i18n import _, _LE -from neutron.common import constants as n_const from neutron.db import api as db_api TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" diff --git a/neutron/db/address_scope_db.py b/neutron/db/address_scope_db.py index 0ec0bc9458b..1af5d766ebc 100644 --- a/neutron/db/address_scope_db.py +++ b/neutron/db/address_scope_db.py @@ -12,13 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from oslo_utils import uuidutils import sqlalchemy as sa from sqlalchemy.orm import exc from neutron._i18n import _ from neutron.api.v2 import attributes as attr -from neutron.common import constants from neutron.db import db_base_plugin_v2 from neutron.db import model_base from neutron.extensions import address_scope as ext_address_scope diff --git a/neutron/db/agents_db.py b/neutron/db/agents_db.py index 70c7ab0680d..7f0e89fc7fb 100644 --- a/neutron/db/agents_db.py +++ b/neutron/db/agents_db.py @@ -16,6 +16,7 @@ import datetime from eventlet import greenthread +from neutron_lib import constants from oslo_config import cfg from oslo_db import exception as db_exc from oslo_log import log as logging @@ -34,7 +35,7 @@ from neutron.api.v2 import attributes from neutron.callbacks import events from neutron.callbacks import registry from neutron.callbacks import resources -from neutron.common import constants +from neutron.common import constants as n_const from neutron import context from neutron.db import api as db_api from neutron.db import model_base @@ -350,7 +351,7 @@ class AgentDbMixin(ext_agent.AgentPluginBase, AgentAvailabilityZoneMixin): Returns agent status from server point of view: alive, new or revived. It could be used by agent to do some sync with the server if needed. """ - status = constants.AGENT_ALIVE + status = n_const.AGENT_ALIVE with context.session.begin(subtransactions=True): res_keys = ['agent_type', 'binary', 'host', 'topic'] res = dict((k, agent_state[k]) for k in res_keys) @@ -368,7 +369,7 @@ class AgentDbMixin(ext_agent.AgentPluginBase, AgentAvailabilityZoneMixin): agent_db = self._get_agent_by_type_and_host( context, agent_state['agent_type'], agent_state['host']) if not agent_db.is_active: - status = constants.AGENT_REVIVED + status = n_const.AGENT_REVIVED if 'resource_versions' not in agent_state: # updating agent_state with resource_versions taken # from db so that @@ -392,7 +393,7 @@ class AgentDbMixin(ext_agent.AgentPluginBase, AgentAvailabilityZoneMixin): greenthread.sleep(0) context.session.add(agent_db) self._log_heartbeat(agent_state, agent_db, configurations_dict) - status = constants.AGENT_NEW + status = n_const.AGENT_NEW greenthread.sleep(0) return status @@ -452,7 +453,7 @@ class AgentExtRpcCallback(object): """ target = oslo_messaging.Target(version='1.1', - namespace=constants.RPC_NAMESPACE_STATE) + namespace=n_const.RPC_NAMESPACE_STATE) START_TIME = timeutils.utcnow() def __init__(self, plugin=None): diff --git a/neutron/db/agentschedulers_db.py b/neutron/db/agentschedulers_db.py index 3cb4294dfdf..2f90bf9f5fb 100644 --- a/neutron/db/agentschedulers_db.py +++ b/neutron/db/agentschedulers_db.py @@ -17,6 +17,7 @@ import datetime import random import time +from neutron_lib import constants from oslo_config import cfg from oslo_log import log as logging from oslo_service import loopingcall @@ -26,7 +27,7 @@ from sqlalchemy import orm from sqlalchemy.orm import exc from neutron._i18n import _, _LE, _LI, _LW -from neutron.common import constants +from neutron.common import constants as n_const from neutron.common import utils from neutron import context as ncontext from neutron.db import agents_db @@ -392,7 +393,7 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler # DHCP agent per network so we don't have to worry about one # update_port passing and another failing for port in ports: - port['device_id'] = constants.DEVICE_ID_RESERVED_DHCP_PORT + port['device_id'] = n_const.DEVICE_ID_RESERVED_DHCP_PORT self.update_port(context, port['id'], dict(port=port)) with context.session.begin(): context.session.delete(binding) diff --git a/neutron/db/bgp_db.py b/neutron/db/bgp_db.py index fd29c1020b0..f5760e51b79 100644 --- a/neutron/db/bgp_db.py +++ b/neutron/db/bgp_db.py @@ -14,6 +14,7 @@ import itertools +from neutron_lib import constants as lib_consts from neutron_lib import exceptions as n_exc from oslo_db import exception as oslo_db_exc from oslo_log import log as logging @@ -24,8 +25,6 @@ from sqlalchemy import orm from sqlalchemy.orm import aliased from sqlalchemy.orm import exc as sa_exc -from neutron_lib import constants as lib_consts - from neutron._i18n import _ from neutron.api.v2 import attributes as attr from neutron.db import address_scope_db diff --git a/neutron/db/db_base_plugin_common.py b/neutron/db/db_base_plugin_common.py index 8f574233465..79c23b80e6e 100644 --- a/neutron/db/db_base_plugin_common.py +++ b/neutron/db/db_base_plugin_common.py @@ -15,13 +15,14 @@ import functools +from neutron_lib import constants 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 constants as n_const from neutron.common import exceptions from neutron.common import utils from neutron.db import common_db_mixin @@ -274,7 +275,7 @@ class DbBasePluginCommon(common_db_mixin.CommonDbMixin): 'name': network['name'], 'tenant_id': network['tenant_id'], 'admin_state_up': network['admin_state_up'], - 'mtu': network.get('mtu', constants.DEFAULT_NETWORK_MTU), + 'mtu': network.get('mtu', n_const.DEFAULT_NETWORK_MTU), 'status': network['status'], 'subnets': [subnet['id'] for subnet in network['subnets']]} diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 285323fd59a..b57826eef60 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -16,6 +16,7 @@ import functools import netaddr +from neutron_lib import constants from neutron_lib import exceptions as exc from oslo_config import cfg from oslo_db import exception as db_exc @@ -33,7 +34,7 @@ from neutron.callbacks import events from neutron.callbacks import exceptions from neutron.callbacks import registry from neutron.callbacks import resources -from neutron.common import constants +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 @@ -326,7 +327,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, 'id': n.get('id') or uuidutils.generate_uuid(), 'name': n['name'], 'admin_state_up': n['admin_state_up'], - 'mtu': n.get('mtu', constants.DEFAULT_NETWORK_MTU), + 'mtu': n.get('mtu', n_const.DEFAULT_NETWORK_MTU), 'status': n.get('status', constants.NET_STATUS_ACTIVE), 'description': n.get('description')} network = models_v2.Network(**args) @@ -532,8 +533,8 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, "subnets.") raise exc.BadRequest(resource='subnets', msg=reason) - mode_list = [constants.IPV6_SLAAC, - constants.DHCPV6_STATELESS] + mode_list = [n_const.IPV6_SLAAC, + n_const.DHCPV6_STATELESS] ra_mode = subnet.get('ipv6_ra_mode') if ra_mode not in mode_list: @@ -607,10 +608,10 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, :param subnet: The subnet dict from the request """ use_default_subnetpool = subnet.get('use_default_subnetpool') - if use_default_subnetpool == attributes.ATTR_NOT_SPECIFIED: + if use_default_subnetpool == constants.ATTR_NOT_SPECIFIED: use_default_subnetpool = False subnetpool_id = subnet.get('subnetpool_id') - if subnetpool_id == attributes.ATTR_NOT_SPECIFIED: + if subnetpool_id == constants.ATTR_NOT_SPECIFIED: subnetpool_id = None if use_default_subnetpool and subnetpool_id: @@ -655,8 +656,8 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, def create_subnet(self, context, subnet): s = subnet['subnet'] - cidr = s.get('cidr', attributes.ATTR_NOT_SPECIFIED) - prefixlen = s.get('prefixlen', attributes.ATTR_NOT_SPECIFIED) + cidr = s.get('cidr', constants.ATTR_NOT_SPECIFIED) + prefixlen = s.get('prefixlen', constants.ATTR_NOT_SPECIFIED) has_cidr = attributes.is_attr_set(cidr) has_prefixlen = attributes.is_attr_set(prefixlen) @@ -684,7 +685,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, subnetpool_id = None self._validate_subnet(context, s) else: - prefix = constants.PROVISIONAL_IPV6_PD_PREFIX + prefix = n_const.PROVISIONAL_IPV6_PD_PREFIX subnet['subnet']['cidr'] = prefix self._validate_subnet_for_pd(s) else: @@ -974,7 +975,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, sp = subnetpool['subnetpool'] sp_reader = subnet_alloc.SubnetPoolReader(sp) - if sp_reader.address_scope_id is attributes.ATTR_NOT_SPECIFIED: + if sp_reader.address_scope_id is constants.ATTR_NOT_SPECIFIED: sp_reader.address_scope_id = None if sp_reader.is_default: self._check_default_subnetpool_exists(context, @@ -1016,9 +1017,9 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, def _updated_subnetpool_dict(self, model, new_pool): updated = {} - new_prefixes = new_pool.get('prefixes', attributes.ATTR_NOT_SPECIFIED) + new_prefixes = new_pool.get('prefixes', constants.ATTR_NOT_SPECIFIED) orig_prefixes = [str(x.cidr) for x in model['prefixes']] - if new_prefixes is not attributes.ATTR_NOT_SPECIFIED: + if new_prefixes is not constants.ATTR_NOT_SPECIFIED: orig_set = netaddr.IPSet(orig_prefixes) new_set = netaddr.IPSet(new_prefixes) if not orig_set.issubset(new_set): @@ -1038,8 +1039,8 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, return updated def _write_key(self, key, update, orig, new_dict): - new_val = new_dict.get(key, attributes.ATTR_NOT_SPECIFIED) - if new_val is not attributes.ATTR_NOT_SPECIFIED: + new_val = new_dict.get(key, constants.ATTR_NOT_SPECIFIED) + if new_val is not constants.ATTR_NOT_SPECIFIED: update[key] = new_dict[key] else: update[key] = orig[key] @@ -1233,7 +1234,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, self._get_network(context, network_id) # Create the port - if p['mac_address'] is attributes.ATTR_NOT_SPECIFIED: + if p['mac_address'] is constants.ATTR_NOT_SPECIFIED: db_port = self._create_port(context, network_id, port_data) p['mac_address'] = db_port['mac_address'] else: diff --git a/neutron/db/dvr_mac_db.py b/neutron/db/dvr_mac_db.py index e7ec6161c4a..08cceb3ac47 100644 --- a/neutron/db/dvr_mac_db.py +++ b/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 constants from neutron_lib import exceptions as n_exc from oslo_config import cfg from oslo_db import exception as db_exc @@ -26,7 +27,6 @@ from neutron._i18n import _, _LE from neutron.callbacks import events from neutron.callbacks import registry from neutron.callbacks import resources -from neutron.common import constants from neutron.common import utils from neutron.db import model_base from neutron.db import models_v2 diff --git a/neutron/db/external_net_db.py b/neutron/db/external_net_db.py index f9d9fa4bdfe..72d020402ff 100644 --- a/neutron/db/external_net_db.py +++ b/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 constants as l3_constants from neutron_lib import exceptions as n_exc import sqlalchemy as sa from sqlalchemy import orm @@ -26,7 +27,6 @@ from neutron.callbacks import events 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.db import db_base_plugin_v2 from neutron.db import l3_db from neutron.db import model_base diff --git a/neutron/db/ipam_backend_mixin.py b/neutron/db/ipam_backend_mixin.py index f08ceaaa496..2927bcb83c2 100644 --- a/neutron/db/ipam_backend_mixin.py +++ b/neutron/db/ipam_backend_mixin.py @@ -17,6 +17,7 @@ import collections import itertools import netaddr +from neutron_lib import constants as const from neutron_lib import exceptions as exc from oslo_config import cfg from oslo_db import exception as db_exc @@ -51,7 +52,7 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon): @staticmethod def _gateway_ip_str(subnet, cidr_net): - if subnet.get('gateway_ip') is attributes.ATTR_NOT_SPECIFIED: + if subnet.get('gateway_ip') is const.ATTR_NOT_SPECIFIED: return str(netaddr.IPNetwork(cidr_net).network + 1) return subnet.get('gateway_ip') @@ -311,7 +312,7 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon): # Subnets are all the subnets belonging to the same network. if not subnets: msg = _('IP allocation requires subnets for network') - raise n_exc.InvalidInput(error_message=msg) + raise exc.InvalidInput(error_message=msg) if 'subnet_id' in fixed: def get_matching_subnet(): @@ -370,7 +371,7 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon): # (non-optional, e.g. IPv6 SLAAC) addresses. # NOTE: Need to check the SNAT ports for DVR routers here since # they consume an IP. - if device_owner in constants.ROUTER_INTERFACE_OWNERS_SNAT: + if device_owner in const.ROUTER_INTERFACE_OWNERS_SNAT: return True subnet = self._get_subnet(context, subnet_id) diff --git a/neutron/db/ipam_non_pluggable_backend.py b/neutron/db/ipam_non_pluggable_backend.py index 16939901266..4da0298ab1d 100644 --- a/neutron/db/ipam_non_pluggable_backend.py +++ b/neutron/db/ipam_non_pluggable_backend.py @@ -14,6 +14,7 @@ # under the License. import netaddr +from neutron_lib import constants from neutron_lib import exceptions as n_exc from oslo_db import exception as db_exc from oslo_log import log as logging @@ -22,8 +23,7 @@ from sqlalchemy import orm from sqlalchemy.orm import exc from neutron._i18n import _ -from neutron.api.v2 import attributes -from neutron.common import constants +from neutron.common import constants as n_const from neutron.common import ipv6_utils from neutron.db import ipam_backend_mixin from neutron.db import models_v2 @@ -246,7 +246,7 @@ class IpamNonPluggableBackend(ipam_backend_mixin.IpamBackendMixin): is_auto_addr_subnet = ipv6_utils.is_auto_address_subnet(subnet) if ('ip_address' in fixed and - subnet['cidr'] != constants.PROVISIONAL_IPV6_PD_PREFIX): + subnet['cidr'] != n_const.PROVISIONAL_IPV6_PD_PREFIX): # Ensure that the IP's are unique if not IpamNonPluggableBackend._check_unique_ip( context, network_id, @@ -352,7 +352,7 @@ class IpamNonPluggableBackend(ipam_backend_mixin.IpamBackendMixin): v4, v6_stateful, v6_stateless = self._classify_subnets( context, subnets) - fixed_configured = p['fixed_ips'] is not attributes.ATTR_NOT_SPECIFIED + fixed_configured = p['fixed_ips'] is not constants.ATTR_NOT_SPECIFIED if fixed_configured: configured_ips = self._test_fixed_ips_for_port(context, p["network_id"], @@ -435,7 +435,7 @@ class IpamNonPluggableBackend(ipam_backend_mixin.IpamBackendMixin): # gateway_ip and allocation pools should be validated or generated # only for specific request - if subnet['cidr'] is not attributes.ATTR_NOT_SPECIFIED: + if subnet['cidr'] is not constants.ATTR_NOT_SPECIFIED: subnet['gateway_ip'] = self._gateway_ip_str(subnet, subnet['cidr']) # allocation_pools are converted to list of IPRanges diff --git a/neutron/db/ipam_pluggable_backend.py b/neutron/db/ipam_pluggable_backend.py index b31188a6138..7b570b01456 100644 --- a/neutron/db/ipam_pluggable_backend.py +++ b/neutron/db/ipam_pluggable_backend.py @@ -16,6 +16,7 @@ import copy import netaddr +from neutron_lib import constants from neutron_lib import exceptions as n_exc from oslo_db import exception as db_exc from oslo_log import log as logging @@ -23,8 +24,6 @@ from oslo_utils import excutils from sqlalchemy import and_ from neutron._i18n import _, _LE -from neutron.api.v2 import attributes -from neutron.common import constants from neutron.common import ipv6_utils from neutron.db import ipam_backend_mixin from neutron.db import models_v2 @@ -191,7 +190,7 @@ class IpamPluggableBackend(ipam_backend_mixin.IpamBackendMixin): v4, v6_stateful, v6_stateless = self._classify_subnets( context, subnets) - fixed_configured = p['fixed_ips'] is not attributes.ATTR_NOT_SPECIFIED + fixed_configured = p['fixed_ips'] is not constants.ATTR_NOT_SPECIFIED if fixed_configured: ips = self._test_fixed_ips_for_port(context, p["network_id"], @@ -411,7 +410,7 @@ class IpamPluggableBackend(ipam_backend_mixin.IpamBackendMixin): # gateway_ip and allocation pools should be validated or generated # only for specific request - if subnet['cidr'] is not attributes.ATTR_NOT_SPECIFIED: + if subnet['cidr'] is not constants.ATTR_NOT_SPECIFIED: subnet['gateway_ip'] = self._gateway_ip_str(subnet, subnet['cidr']) subnet['allocation_pools'] = self._prepare_allocation_pools( diff --git a/neutron/db/l3_agentschedulers_db.py b/neutron/db/l3_agentschedulers_db.py index 0298251a081..b0516072ee1 100644 --- a/neutron/db/l3_agentschedulers_db.py +++ b/neutron/db/l3_agentschedulers_db.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from oslo_config import cfg from oslo_db import exception as db_exc from oslo_log import log as logging @@ -26,7 +27,7 @@ from sqlalchemy.orm import joinedload from sqlalchemy import sql from neutron._i18n import _, _LE, _LI, _LW -from neutron.common import constants +from neutron.common import constants as n_const from neutron.common import utils as n_utils from neutron import context as n_ctx from neutron.db import agents_db @@ -148,8 +149,8 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase, def _get_agent_mode(self, agent_db): agent_conf = self.get_configuration_dict(agent_db) - return agent_conf.get(constants.L3_AGENT_MODE, - constants.L3_AGENT_MODE_LEGACY) + return agent_conf.get(n_const.L3_AGENT_MODE, + n_const.L3_AGENT_MODE_LEGACY) def validate_agent_router_combination(self, context, agent, router): """Validate if the router can be correctly assigned to the agent. @@ -166,10 +167,10 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase, agent_mode = self._get_agent_mode(agent) - if agent_mode == constants.L3_AGENT_MODE_DVR: + if agent_mode == n_const.L3_AGENT_MODE_DVR: raise l3agentscheduler.DVRL3CannotAssignToDvrAgent() - if (agent_mode == constants.L3_AGENT_MODE_LEGACY and + if (agent_mode == n_const.L3_AGENT_MODE_LEGACY and router.get('distributed')): raise l3agentscheduler.RouterL3AgentMismatch( router_id=router['id'], agent_id=agent['id']) @@ -249,7 +250,7 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase, """ agent = self._get_agent(context, agent_id) agent_mode = self._get_agent_mode(agent) - if agent_mode == constants.L3_AGENT_MODE_DVR: + if agent_mode == n_const.L3_AGENT_MODE_DVR: raise l3agentscheduler.DVRL3CannotRemoveFromDvrAgent() self._unbind_router(context, router_id, agent_id) @@ -481,10 +482,10 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase, continue agent_conf = self.get_configuration_dict(l3_agent) - agent_mode = agent_conf.get(constants.L3_AGENT_MODE, - constants.L3_AGENT_MODE_LEGACY) - if (agent_mode == constants.L3_AGENT_MODE_DVR or - (agent_mode == constants.L3_AGENT_MODE_LEGACY and + agent_mode = agent_conf.get(n_const.L3_AGENT_MODE, + n_const.L3_AGENT_MODE_LEGACY) + if (agent_mode == n_const.L3_AGENT_MODE_DVR or + (agent_mode == n_const.L3_AGENT_MODE_LEGACY and is_router_distributed)): continue diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py index 9fc17a0cf8c..49b0df7a01f 100644 --- a/neutron/db/l3_db.py +++ b/neutron/db/l3_db.py @@ -15,6 +15,7 @@ import itertools import netaddr +from neutron_lib import constants as l3_constants from neutron_lib import exceptions as n_exc from oslo_log import log as logging from oslo_utils import excutils @@ -31,7 +32,7 @@ from neutron.callbacks import events 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 constants as n_const from neutron.common import ipv6_utils from neutron.common import rpc as n_rpc from neutron.common import utils @@ -191,7 +192,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, query = (context.session.query(Router.id). filter( Router.id.in_(router_ids), - Router.status != l3_constants.ROUTER_STATUS_ALLOCATING)) + Router.status != n_const.ROUTER_STATUS_ALLOCATING)) valid_routers = set(r.id for r in query) if router_ids - valid_routers: LOG.debug("Removing routers that were either concurrently " @@ -204,7 +205,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, with context.session.begin(subtransactions=True): # pre-generate id so it will be available when # configuring external gw port - status = router.get('status', l3_constants.ROUTER_STATUS_ACTIVE) + status = router.get('status', n_const.ROUTER_STATUS_ACTIVE) router_db = Router(id=(router.get('id') or uuidutils.generate_uuid()), tenant_id=tenant_id, @@ -240,12 +241,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, attributes.ATTR_NOT_SPECIFIED) + gw_info = r.pop(EXTERNAL_GW_INFO, l3_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 != attributes.ATTR_NOT_SPECIFIED: + if gw_info != l3_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 @@ -330,7 +331,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 attributes.ATTR_NOT_SPECIFIED, + 'fixed_ips': ext_ips or l3_constants.ATTR_NOT_SPECIFIED, 'device_id': router['id'], 'device_owner': DEVICE_OWNER_ROUTER_GW, 'admin_state_up': True, @@ -547,7 +548,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, router_subnets.append(ip['subnet_id']) # Ignore temporary Prefix Delegation CIDRs new_subnets = [s for s in new_subnets - if s['cidr'] != l3_constants.PROVISIONAL_IPV6_PD_PREFIX] + if s['cidr'] != n_const.PROVISIONAL_IPV6_PD_PREFIX] id_filter = {'id': router_subnets} subnets = self._core_plugin.get_subnets(context.elevated(), filters=id_filter) @@ -1742,7 +1743,7 @@ def _notify_subnetpool_address_scope_update(resource, event, models_v2.Subnet.network_id == models_v2.Port.network_id) query = query.filter( models_v2.Subnet.subnetpool_id == subnetpool_id, - RouterPort.port_type.in_(l3_constants.ROUTER_PORT_OWNERS)) + RouterPort.port_type.in_(n_const.ROUTER_PORT_OWNERS)) query = query.distinct() router_ids = [r[0] for r in query] diff --git a/neutron/db/l3_dvr_db.py b/neutron/db/l3_dvr_db.py index fd02ff921e5..75267bbee48 100644 --- a/neutron/db/l3_dvr_db.py +++ b/neutron/db/l3_dvr_db.py @@ -13,6 +13,7 @@ # under the License. import collections +from neutron_lib import constants as const from neutron_lib import exceptions as n_exc from oslo_config import cfg from oslo_log import helpers as log_helper @@ -54,9 +55,9 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, router_device_owners = ( l3_db.L3_NAT_db_mixin.router_device_owners + - (l3_const.DEVICE_OWNER_DVR_INTERFACE, - l3_const.DEVICE_OWNER_ROUTER_SNAT, - l3_const.DEVICE_OWNER_AGENT_GW)) + (const.DEVICE_OWNER_DVR_INTERFACE, + const.DEVICE_OWNER_ROUTER_SNAT, + const.DEVICE_OWNER_AGENT_GW)) extra_attributes = ( l3_attrs_db.ExtraAttributesMixin.extra_attributes + [{ @@ -110,8 +111,8 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, self, context, router_id, router_db, data): """Update the model to support the dvr case of a router.""" if data.get('distributed'): - old_owner = l3_const.DEVICE_OWNER_ROUTER_INTF - new_owner = l3_const.DEVICE_OWNER_DVR_INTERFACE + old_owner = const.DEVICE_OWNER_ROUTER_INTF + new_owner = const.DEVICE_OWNER_DVR_INTERFACE for rp in router_db.attached_ports.filter_by(port_type=old_owner): rp.port_type = new_owner rp.port.device_owner = new_owner @@ -168,7 +169,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, # on all hosts when it is the last gateway port in the # given external network. filters = {'network_id': [gw_ext_net_id], - 'device_owner': [l3_const.DEVICE_OWNER_ROUTER_GW]} + 'device_owner': [const.DEVICE_OWNER_ROUTER_GW]} ext_net_gw_ports = self._core_plugin.get_ports( context.elevated(), filters) if not ext_net_gw_ports: @@ -198,7 +199,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, if router_is_uuid: router = self._get_router(context, router) if is_distributed_router(router): - return l3_const.DEVICE_OWNER_DVR_INTERFACE + return const.DEVICE_OWNER_DVR_INTERFACE return super(L3_NAT_with_dvr_db_mixin, self)._get_device_owner(context, router) @@ -289,7 +290,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, # same network id if one exists cs_port = self._find_router_port_by_network_and_device_owner( router, subnet['network_id'], - l3_const.DEVICE_OWNER_ROUTER_SNAT) + const.DEVICE_OWNER_ROUTER_SNAT) if cs_port: fixed_ips = list(cs_port['port']['fixed_ips']) fixed_ips.append(fixed_ip) @@ -322,7 +323,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, def _port_has_ipv6_address(self, port, csnat_port_check=True): """Overridden to return False if DVR SNAT port.""" if csnat_port_check: - if port['device_owner'] == l3_const.DEVICE_OWNER_ROUTER_SNAT: + if port['device_owner'] == const.DEVICE_OWNER_ROUTER_SNAT: return False return super(L3_NAT_with_dvr_db_mixin, self)._port_has_ipv6_address(port) @@ -350,7 +351,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, # If router has a gateway port, check if it has IPV6 subnet cs_port = ( self._find_router_port_by_network_and_device_owner( - router, network_id, l3_const.DEVICE_OWNER_ROUTER_SNAT)) + router, network_id, const.DEVICE_OWNER_ROUTER_SNAT)) if cs_port: fixed_ips = ( [fixedip for fixedip in @@ -415,7 +416,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, qry = context.session.query(l3_db.RouterPort) qry = qry.filter( l3_db.RouterPort.router_id.in_(router_ids), - l3_db.RouterPort.port_type == l3_const.DEVICE_OWNER_ROUTER_SNAT + l3_db.RouterPort.port_type == const.DEVICE_OWNER_ROUTER_SNAT ) interfaces = collections.defaultdict(list) for rp in qry: @@ -472,14 +473,14 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, for floating_ip in floating_ips: router = routers_dict.get(floating_ip['router_id']) if router: - router_floatingips = router.get(l3_const.FLOATINGIP_KEY, []) + router_floatingips = router.get(const.FLOATINGIP_KEY, []) if router['distributed']: if (floating_ip.get('host', None) != host and floating_ip.get('dest_host') is None): continue LOG.debug("Floating IP host: %s", floating_ip['host']) router_floatingips.append(floating_ip) - router[l3_const.FLOATINGIP_KEY] = router_floatingips + router[const.FLOATINGIP_KEY] = router_floatingips if not fip_sync_interfaces: fip_sync_interfaces = self._get_fip_sync_interfaces( context, agent.id) @@ -492,7 +493,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, if not fip_agent_id: return [] filters = {'device_id': [fip_agent_id], - 'device_owner': [l3_const.DEVICE_OWNER_AGENT_GW]} + 'device_owner': [const.DEVICE_OWNER_AGENT_GW]} interfaces = self._core_plugin.get_ports(context.elevated(), filters) LOG.debug("Return the FIP ports: %s ", interfaces) return interfaces @@ -502,7 +503,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, active=None): routers, interfaces, floating_ips = self._get_router_info_list( context, router_ids=router_ids, active=active, - device_owners=l3_const.ROUTER_INTERFACE_OWNERS) + device_owners=const.ROUTER_INTERFACE_OWNERS) dvr_router_ids = set(router['id'] for router in routers if is_distributed_router(router)) floating_ip_port_ids = [fip['port_id'] for fip in floating_ips @@ -576,7 +577,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, filters = { 'network_id': [network_id], 'device_id': [agent_id], - 'device_owner': [l3_const.DEVICE_OWNER_AGENT_GW] + 'device_owner': [const.DEVICE_OWNER_AGENT_GW] } ports = self._core_plugin.get_ports(context, filters) if ports: @@ -586,7 +587,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, self, context, host_id, ext_net_id): """Function to delete FIP gateway port with given ext_net_id.""" # delete any fip agent gw port - device_filter = {'device_owner': [l3_const.DEVICE_OWNER_AGENT_GW], + device_filter = {'device_owner': [const.DEVICE_OWNER_AGENT_GW], 'network_id': [ext_net_id]} ports = self._core_plugin.get_ports(context, filters=device_filter) @@ -620,7 +621,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, create a new one. """ l3_agent_db = self._get_agent_by_type_and_host( - context, l3_const.AGENT_TYPE_L3, host) + context, const.AGENT_TYPE_L3, host) if l3_agent_db: LOG.debug("Agent ID exists: %s", l3_agent_db['id']) f_port = self._get_agent_gw_ports_exist_for_network( @@ -631,7 +632,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, port_data = {'tenant_id': '', 'network_id': network_id, 'device_id': l3_agent_db['id'], - 'device_owner': l3_const.DEVICE_OWNER_AGENT_GW, + 'device_owner': const.DEVICE_OWNER_AGENT_GW, portbindings.HOST_ID: host, 'admin_state_up': True, 'name': ''} @@ -652,7 +653,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, qry = context.session.query(l3_db.RouterPort) qry = qry.filter_by( router_id=router_id, - port_type=l3_const.DEVICE_OWNER_ROUTER_SNAT + port_type=const.DEVICE_OWNER_ROUTER_SNAT ) ports = [self._core_plugin._make_port_dict(rp.port, None) @@ -666,7 +667,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, 'network_id': network_id, 'fixed_ips': [{'subnet_id': subnet_id}], 'device_id': router.id, - 'device_owner': l3_const.DEVICE_OWNER_ROUTER_SNAT, + 'device_owner': const.DEVICE_OWNER_ROUTER_SNAT, 'admin_state_up': True, 'name': ''} snat_port = p_utils.create_port(self._core_plugin, context, @@ -679,7 +680,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, router_port = l3_db.RouterPort( port_id=snat_port['id'], router_id=router.id, - port_type=l3_const.DEVICE_OWNER_ROUTER_SNAT + port_type=const.DEVICE_OWNER_ROUTER_SNAT ) context.session.add(router_port) @@ -705,7 +706,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, int_ports = ( rp.port for rp in router.attached_ports.filter_by( - port_type=l3_const.DEVICE_OWNER_DVR_INTERFACE + port_type=const.DEVICE_OWNER_DVR_INTERFACE ) ) LOG.info(_LI('SNAT interface port list does not exist,' @@ -729,7 +730,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, ip_address = fixed_ip['ip_address'] subnet = fixed_ip['subnet_id'] filters = {'fixed_ips': {'subnet_id': [subnet]}, - 'device_owner': [l3_const.DEVICE_OWNER_DVR_INTERFACE]} + 'device_owner': [const.DEVICE_OWNER_DVR_INTERFACE]} ports = self._core_plugin.get_ports(context, filters=filters) router_id = next((port['device_id'] for port in ports), None) if not router_id: @@ -807,7 +808,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, ports = [ rp.port.id for rp in router.attached_ports.filter_by( - port_type=l3_const.DEVICE_OWNER_ROUTER_SNAT) + port_type=const.DEVICE_OWNER_ROUTER_SNAT) if rp.port ] @@ -828,7 +829,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, l3_port_check=False) def create_floatingip(self, context, floatingip, - initial_status=l3_const.FLOATINGIP_STATUS_ACTIVE): + initial_status=const.FLOATINGIP_STATUS_ACTIVE): floating_ip = self._create_floatingip( context, floatingip, initial_status) self._notify_floating_ip_change(context, floating_ip) @@ -878,7 +879,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, def _get_address_pair_active_port_with_fip( self, context, port_dict, port_addr_pair_ip): port_valid_state = (port_dict['admin_state_up'] or - (port_dict['status'] == l3_const.PORT_STATUS_ACTIVE)) + (port_dict['status'] == const.PORT_STATUS_ACTIVE)) if not port_valid_state: return query = context.session.query(l3_db.FloatingIP).filter( diff --git a/neutron/db/l3_dvrscheduler_db.py b/neutron/db/l3_dvrscheduler_db.py index bda5b3f42df..d91e81070a2 100644 --- a/neutron/db/l3_dvrscheduler_db.py +++ b/neutron/db/l3_dvrscheduler_db.py @@ -13,13 +13,14 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants as n_const from oslo_log import log as logging from sqlalchemy import or_ 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.common import constants as const from neutron.common import utils as n_utils from neutron.db import agentschedulers_db @@ -286,8 +287,8 @@ class L3_DVRsch_db_mixin(l3agent_sch_db.L3AgentSchedulerDbMixin): # dvr routers are not explicitly scheduled to agents on hosts with # dvr serviceable ports, so need special handling - if self._get_agent_mode(agent_db) in [n_const.L3_AGENT_MODE_DVR, - n_const.L3_AGENT_MODE_DVR_SNAT]: + if self._get_agent_mode(agent_db) in [const.L3_AGENT_MODE_DVR, + const.L3_AGENT_MODE_DVR_SNAT]: if not router_ids: result_set |= set(self._get_dvr_router_ids_for_host( context, agent_db['host'])) diff --git a/neutron/db/l3_hamode_db.py b/neutron/db/l3_hamode_db.py index 383d9a8f967..025ebd781cf 100644 --- a/neutron/db/l3_hamode_db.py +++ b/neutron/db/l3_hamode_db.py @@ -16,6 +16,7 @@ import functools import netaddr +from neutron_lib import constants from neutron_lib import exceptions as n_exc from oslo_config import cfg from oslo_db import exception as db_exc @@ -29,7 +30,7 @@ from sqlalchemy import orm from neutron._i18n import _, _LI from neutron.api.v2 import attributes -from neutron.common import constants +from neutron.common import constants as n_const 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 @@ -60,12 +61,12 @@ L3_HA_OPTS = [ "scheduled on. If it is set to 0 then the router will " "be scheduled on every agent.")), cfg.IntOpt('min_l3_agents_per_router', - default=constants.MINIMUM_AGENTS_FOR_HA, + default=n_const.MINIMUM_AGENTS_FOR_HA, help=_("Minimum number of L3 agents which a HA router will be " "scheduled on. If it is set to 0 then the router will " "be scheduled on every agent.")), cfg.StrOpt('l3_ha_net_cidr', - default=constants.L3_HA_NET_CIDR, + default=n_const.L3_HA_NET_CIDR, help=_('Subnet used for the l3 HA admin network.')), cfg.StrOpt('l3_ha_network_type', default='', help=_("The network type to use when creating the HA network " @@ -109,11 +110,11 @@ class L3HARouterAgentPortBinding(model_base.BASEV2): ondelete='CASCADE')) agent = orm.relationship(agents_db.Agent) - state = sa.Column(sa.Enum(constants.HA_ROUTER_STATE_ACTIVE, - constants.HA_ROUTER_STATE_STANDBY, + state = sa.Column(sa.Enum(n_const.HA_ROUTER_STATE_ACTIVE, + n_const.HA_ROUTER_STATE_STANDBY, name='l3_ha_states'), - default=constants.HA_ROUTER_STATE_STANDBY, - server_default=constants.HA_ROUTER_STATE_STANDBY) + default=n_const.HA_ROUTER_STATE_STANDBY, + server_default=n_const.HA_ROUTER_STATE_STANDBY) class L3HARouterNetwork(model_base.BASEV2): @@ -177,7 +178,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin, raise l3_ha.HAMaximumAgentsNumberNotValid( max_agents=max_agents, min_agents=min_agents) - if min_agents < constants.MINIMUM_AGENTS_FOR_HA: + if min_agents < n_const.MINIMUM_AGENTS_FOR_HA: raise l3_ha.HAMinimumAgentsNumberNotValid() def __init__(self): @@ -242,7 +243,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin, def _create_ha_subnet(self, context, network_id, tenant_id): args = {'network_id': network_id, 'tenant_id': '', - 'name': constants.HA_SUBNET_NAME % tenant_id, + 'name': n_const.HA_SUBNET_NAME % tenant_id, 'ip_version': 4, 'cidr': cfg.CONF.l3_ha_net_cidr, 'enable_dhcp': False, @@ -281,7 +282,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin, admin_ctx = context.elevated() args = {'network': - {'name': constants.HA_NETWORK_NAME % tenant_id, + {'name': n_const.HA_NETWORK_NAME % tenant_id, 'tenant_id': '', 'shared': False, 'admin_state_up': True}} @@ -313,8 +314,8 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin, min_agents = cfg.CONF.min_l3_agents_per_router num_agents = len(self.get_l3_agents(context, active=True, - filters={'agent_modes': [constants.L3_AGENT_MODE_LEGACY, - constants.L3_AGENT_MODE_DVR_SNAT]})) + filters={'agent_modes': [n_const.L3_AGENT_MODE_LEGACY, + n_const.L3_AGENT_MODE_DVR_SNAT]})) max_agents = cfg.CONF.max_l3_agents_per_router if max_agents: if max_agents > num_agents: @@ -363,7 +364,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin, 'admin_state_up': True, 'device_id': router_id, 'device_owner': constants.DEVICE_OWNER_ROUTER_HA_INTF, - 'name': constants.HA_PORT_NAME % tenant_id} + 'name': n_const.HA_PORT_NAME % tenant_id} creation = functools.partial(p_utils.create_port, self._core_plugin, context, {'port': args}) content = functools.partial(self._create_ha_port_binding, context, @@ -455,7 +456,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin, if is_ha: # we set the allocating status to hide it from the L3 agents # until we have created all of the requisite interfaces/networks - router['router']['status'] = constants.ROUTER_STATUS_ALLOCATING + router['router']['status'] = n_const.ROUTER_STATUS_ALLOCATING router_dict = super(L3_HA_NAT_db_mixin, self).create_router(context, router) @@ -473,7 +474,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin, self.schedule_router(context, router_dict['id']) router_dict['status'] = self._update_router_db( context, router_dict['id'], - {'status': constants.ROUTER_STATUS_ACTIVE})['status'] + {'status': n_const.ROUTER_STATUS_ACTIVE})['status'] self._notify_ha_interfaces_updated(context, router_db.id, schedule_routers=False) except Exception: @@ -525,7 +526,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin, # Keep in mind that if we want conversion to be hitless, this # status cannot be used because agents treat hidden routers as # deleted routers. - data['status'] = constants.ROUTER_STATUS_ALLOCATING + data['status'] = n_const.ROUTER_STATUS_ALLOCATING with context.session.begin(subtransactions=True): router_db = super(L3_HA_NAT_db_mixin, self)._update_router_db( @@ -557,7 +558,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin, self.schedule_router(context, router_id) router_db = super(L3_HA_NAT_db_mixin, self)._update_router_db( - context, router_id, {'status': constants.ROUTER_STATUS_ACTIVE}) + context, router_id, {'status': n_const.ROUTER_STATUS_ACTIVE}) self._notify_ha_interfaces_updated(context, router_db.id, schedule_routers=False) @@ -638,11 +639,11 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin, bindings = self.get_ha_router_port_bindings(context, [router_id]) dead_agents = [ binding.agent for binding in bindings - if binding.state == constants.HA_ROUTER_STATE_ACTIVE and + if binding.state == n_const.HA_ROUTER_STATE_ACTIVE and not binding.agent.is_active] for dead_agent in dead_agents: self.update_routers_states( - context, {router_id: constants.HA_ROUTER_STATE_STANDBY}, + context, {router_id: n_const.HA_ROUTER_STATE_STANDBY}, dead_agent.host) if dead_agents: @@ -668,7 +669,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin, # and l2pop would not work correctly. return next( (agent.host for agent, state in bindings - if state == constants.HA_ROUTER_STATE_ACTIVE), + if state == n_const.HA_ROUTER_STATE_ACTIVE), None) @log_helpers.log_method_call @@ -683,7 +684,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin, router = routers_dict.get(binding.router_id) router[constants.HA_INTERFACE_KEY] = port_dict - router[constants.HA_ROUTER_STATE_KEY] = binding.state + router[n_const.HA_ROUTER_STATE_KEY] = binding.state for router in routers_dict.values(): interface = router.get(constants.HA_INTERFACE_KEY) @@ -696,8 +697,8 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin, def get_ha_sync_data_for_host(self, context, host, agent, router_ids=None, active=None): agent_mode = self._get_agent_mode(agent) - dvr_agent_mode = (agent_mode in [constants.L3_AGENT_MODE_DVR_SNAT, - constants.L3_AGENT_MODE_DVR]) + dvr_agent_mode = (agent_mode in [n_const.L3_AGENT_MODE_DVR_SNAT, + n_const.L3_AGENT_MODE_DVR]) if (dvr_agent_mode and n_utils.is_extension_supported( self, constants.L3_DISTRIBUTED_EXT_ALIAS)): # DVR has to be handled differently @@ -734,7 +735,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin, constants.DEVICE_OWNER_ROUTER_SNAT]} ports = self._core_plugin.get_ports(admin_ctx, filters=device_filter) active_ports = (port for port in ports - if states[port['device_id']] == constants.HA_ROUTER_STATE_ACTIVE) + if states[port['device_id']] == n_const.HA_ROUTER_STATE_ACTIVE) for port in active_ports: port[portbindings.HOST_ID] = host diff --git a/neutron/db/metering/metering_rpc.py b/neutron/db/metering/metering_rpc.py index 19e8e903aca..21f915630b0 100644 --- a/neutron/db/metering/metering_rpc.py +++ b/neutron/db/metering/metering_rpc.py @@ -12,11 +12,11 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants as consts from oslo_log import log as logging import oslo_messaging from neutron._i18n import _LE -from neutron.common import constants as consts from neutron.common import utils from neutron import manager from neutron.plugins.common import constants as service_constants diff --git a/neutron/db/migration/alembic_migrations/versions/newton/contract/7bbb25278f53_device_owner_ha_replicate_int.py b/neutron/db/migration/alembic_migrations/versions/newton/contract/7bbb25278f53_device_owner_ha_replicate_int.py index 4788c8b98ed..0b35706c7af 100644 --- a/neutron/db/migration/alembic_migrations/versions/newton/contract/7bbb25278f53_device_owner_ha_replicate_int.py +++ b/neutron/db/migration/alembic_migrations/versions/newton/contract/7bbb25278f53_device_owner_ha_replicate_int.py @@ -26,10 +26,9 @@ revision = '7bbb25278f53' down_revision = '4ffceebfcdc' from alembic import op +from neutron_lib import constants import sqlalchemy as sa -from neutron.common import constants - ROUTER_ATTR_TABLE = 'router_extra_attributes' ROUTER_PORTS_TABLE = 'routerports' diff --git a/neutron/db/securitygroups_db.py b/neutron/db/securitygroups_db.py index 73af6f8cc48..9381ad6dfe2 100644 --- a/neutron/db/securitygroups_db.py +++ b/neutron/db/securitygroups_db.py @@ -13,6 +13,7 @@ # under the License. import netaddr +from neutron_lib import constants from oslo_db import exception as db_exc from oslo_log import log as logging from oslo_utils import uuidutils @@ -27,7 +28,7 @@ from neutron.callbacks import events from neutron.callbacks import exceptions from neutron.callbacks import registry from neutron.callbacks import resources -from neutron.common import constants +from neutron.common import constants as n_const from neutron.common import utils from neutron.db import api as db_api from neutron.db import db_base_plugin_v2 @@ -420,8 +421,8 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): # problems with comparing int and string in PostgreSQL. Here this # string is converted to int to give an opportunity to use it as # before. - if protocol in constants.IP_PROTOCOL_NAME_ALIASES: - protocol = constants.IP_PROTOCOL_NAME_ALIASES[protocol] + if protocol in n_const.IP_PROTOCOL_NAME_ALIASES: + protocol = n_const.IP_PROTOCOL_NAME_ALIASES[protocol] return int(constants.IP_PROTOCOL_MAP.get(protocol, protocol)) def _get_ip_proto_name_and_num(self, protocol): @@ -430,8 +431,8 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): protocol = str(protocol) if protocol in constants.IP_PROTOCOL_MAP: return [protocol, str(constants.IP_PROTOCOL_MAP.get(protocol))] - elif protocol in constants.IP_PROTOCOL_NUM_TO_NAME_MAP: - return [constants.IP_PROTOCOL_NUM_TO_NAME_MAP.get(protocol), + elif protocol in n_const.IP_PROTOCOL_NUM_TO_NAME_MAP: + return [n_const.IP_PROTOCOL_NUM_TO_NAME_MAP.get(protocol), protocol] return [protocol, protocol] @@ -468,7 +469,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): if rule['protocol'] in [constants.PROTO_NAME_IPV6_ENCAP, constants.PROTO_NAME_IPV6_FRAG, constants.PROTO_NAME_IPV6_ICMP, - constants.PROTO_NAME_IPV6_ICMP_LEGACY, + n_const.PROTO_NAME_IPV6_ICMP_LEGACY, constants.PROTO_NAME_IPV6_NONXT, constants.PROTO_NAME_IPV6_OPTS, constants.PROTO_NAME_IPV6_ROUTE]: diff --git a/neutron/db/securitygroups_rpc_base.py b/neutron/db/securitygroups_rpc_base.py index 694824b429d..53e39a0270e 100644 --- a/neutron/db/securitygroups_rpc_base.py +++ b/neutron/db/securitygroups_rpc_base.py @@ -14,6 +14,7 @@ # under the License. import netaddr +from neutron_lib import constants as const from oslo_log import log as logging from sqlalchemy.orm import exc @@ -32,7 +33,7 @@ LOG = logging.getLogger(__name__) DIRECTION_IP_PREFIX = {'ingress': 'source_ip_prefix', 'egress': 'dest_ip_prefix'} -DHCP_RULE_PORT = {4: (67, 68, n_const.IPv4), 6: (547, 546, n_const.IPv6)} +DHCP_RULE_PORT = {4: (67, 68, const.IPv4), 6: (547, 546, const.IPv6)} class SecurityGroupServerRpcMixin(sg_db.SecurityGroupDbMixin): @@ -133,7 +134,7 @@ class SecurityGroupServerRpcMixin(sg_db.SecurityGroupDbMixin): sg_provider_updated_networks = set() sec_groups = set() for port in ports: - if port['device_owner'] == n_const.DEVICE_OWNER_DHCP: + if port['device_owner'] == const.DEVICE_OWNER_DHCP: sg_provider_updated_networks.add( port['network_id']) # For IPv6, provider rule need to be updated in case router @@ -141,7 +142,7 @@ class SecurityGroupServerRpcMixin(sg_db.SecurityGroupDbMixin): # NOTE (Swami): ROUTER_INTERFACE_OWNERS check is required # since it includes the legacy router interface device owners # and DVR router interface device owners. - elif port['device_owner'] in n_const.ROUTER_INTERFACE_OWNERS: + elif port['device_owner'] in const.ROUTER_INTERFACE_OWNERS: if any(netaddr.IPAddress(fixed_ip['ip_address']).version == 6 for fixed_ip in port['fixed_ips']): sg_provider_updated_networks.add( @@ -308,7 +309,7 @@ class SecurityGroupServerRpcMixin(sg_db.SecurityGroupDbMixin): models_v2.IPAllocation.ip_address) query = query.join(models_v2.IPAllocation) query = query.filter(models_v2.Port.network_id.in_(network_ids)) - owner = n_const.DEVICE_OWNER_DHCP + owner = const.DEVICE_OWNER_DHCP query = query.filter(models_v2.Port.device_owner == owner) ips = {} @@ -371,7 +372,7 @@ class SecurityGroupServerRpcMixin(sg_db.SecurityGroupDbMixin): query = query.filter( models_v2.IPAllocation.ip_address == subnet['gateway_ip']) query = query.filter( - models_v2.Port.device_owner.in_(n_const.ROUTER_INTERFACE_OWNERS)) + models_v2.Port.device_owner.in_(const.ROUTER_INTERFACE_OWNERS)) try: mac_address = query.one()[0] except (exc.NoResultFound, exc.MultipleResultsFound): @@ -431,10 +432,10 @@ class SecurityGroupServerRpcMixin(sg_db.SecurityGroupDbMixin): ra_ips = ips.get(port['network_id']) for ra_ip in ra_ips: ra_rule = {'direction': 'ingress', - 'ethertype': n_const.IPv6, - 'protocol': n_const.PROTO_NAME_IPV6_ICMP, + 'ethertype': const.IPv6, + 'protocol': const.PROTO_NAME_IPV6_ICMP, 'source_ip_prefix': ra_ip, - 'source_port_range_min': n_const.ICMPV6_TYPE_RA} + 'source_port_range_min': const.ICMPV6_TYPE_RA} port['security_group_rules'].append(ra_rule) def _apply_provider_rule(self, context, ports): diff --git a/neutron/debug/debug_agent.py b/neutron/debug/debug_agent.py index cda800f1b06..50bb89f03e4 100644 --- a/neutron/debug/debug_agent.py +++ b/neutron/debug/debug_agent.py @@ -17,12 +17,12 @@ import shlex import socket import netaddr +from neutron_lib import constants from oslo_log import log as logging from neutron._i18n import _LW from neutron.agent.linux import dhcp from neutron.agent.linux import ip_lib -from neutron.common import constants from neutron.extensions import portbindings LOG = logging.getLogger(__name__) diff --git a/neutron/extensions/address_scope.py b/neutron/extensions/address_scope.py index f80cf378f9c..1484f09e2c5 100644 --- a/neutron/extensions/address_scope.py +++ b/neutron/extensions/address_scope.py @@ -14,6 +14,7 @@ import abc +from neutron_lib import constants from neutron_lib import exceptions as nexception import six @@ -62,7 +63,7 @@ RESOURCE_ATTRIBUTE_MAP = { attr.SUBNETPOOLS: { ADDRESS_SCOPE_ID: {'allow_post': True, 'allow_put': True, - 'default': attr.ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'validate': {'type:uuid_or_none': None}, 'is_visible': True} }, diff --git a/neutron/extensions/allowedaddresspairs.py b/neutron/extensions/allowedaddresspairs.py index 0bbe3515fd1..0e3e7df32df 100644 --- a/neutron/extensions/allowedaddresspairs.py +++ b/neutron/extensions/allowedaddresspairs.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from neutron_lib import exceptions as nexception from oslo_config import cfg import webob.exc @@ -103,7 +104,7 @@ EXTENDED_ATTRIBUTES_2_0 = { 'validate': {'type:validate_allowed_address_pairs': None}, 'enforce_policy': True, - 'default': attr.ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'is_visible': True}, } } diff --git a/neutron/extensions/default_subnetpools.py b/neutron/extensions/default_subnetpools.py index fa50834f296..94995cd040e 100644 --- a/neutron/extensions/default_subnetpools.py +++ b/neutron/extensions/default_subnetpools.py @@ -11,9 +11,10 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants + from neutron.api import extensions from neutron.api.v2 import attributes -from neutron.common import constants EXTENDED_ATTRIBUTES_2_0 = { diff --git a/neutron/extensions/dhcpagentscheduler.py b/neutron/extensions/dhcpagentscheduler.py index 727aef7c7b5..413387ea3c3 100644 --- a/neutron/extensions/dhcpagentscheduler.py +++ b/neutron/extensions/dhcpagentscheduler.py @@ -15,13 +15,13 @@ import abc +from neutron_lib import constants from neutron_lib import exceptions 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 constants from neutron.common import rpc as n_rpc from neutron.extensions import agent from neutron import manager diff --git a/neutron/extensions/dvr.py b/neutron/extensions/dvr.py index a47a0e1f19c..0783ae9a794 100644 --- a/neutron/extensions/dvr.py +++ b/neutron/extensions/dvr.py @@ -14,13 +14,13 @@ import abc +from neutron_lib import constants from neutron_lib import exceptions import six from neutron._i18n import _ from neutron.api import extensions from neutron.api.v2 import attributes -from neutron.common import constants DISTRIBUTED = 'distributed' EXTENDED_ATTRIBUTES_2_0 = { @@ -28,7 +28,7 @@ EXTENDED_ATTRIBUTES_2_0 = { DISTRIBUTED: {'allow_post': True, 'allow_put': True, 'is_visible': True, - 'default': attributes.ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'convert_to': attributes.convert_to_boolean_if_not_none, 'enforce_policy': True}, } diff --git a/neutron/extensions/extraroute.py b/neutron/extensions/extraroute.py index 903d4e0cfae..ac859df23cd 100644 --- a/neutron/extensions/extraroute.py +++ b/neutron/extensions/extraroute.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from neutron_lib import exceptions as nexception from neutron._i18n import _ @@ -41,7 +42,8 @@ EXTENDED_ATTRIBUTES_2_0 = { 'routes': {'allow_post': False, 'allow_put': True, 'validate': {'type:hostroutes': None}, 'convert_to': attr.convert_none_to_empty_list, - 'is_visible': True, 'default': attr.ATTR_NOT_SPECIFIED}, + 'is_visible': True, + 'default': constants.ATTR_NOT_SPECIFIED}, } } diff --git a/neutron/extensions/l3_ext_ha_mode.py b/neutron/extensions/l3_ext_ha_mode.py index 62442ecc1b0..aacb2016b0c 100644 --- a/neutron/extensions/l3_ext_ha_mode.py +++ b/neutron/extensions/l3_ext_ha_mode.py @@ -12,19 +12,19 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from neutron_lib import exceptions from neutron._i18n import _ from neutron.api import extensions from neutron.api.v2 import attributes -from neutron.common import constants - +from neutron.common import constants as n_const HA_INFO = 'ha' EXTENDED_ATTRIBUTES_2_0 = { 'routers': { HA_INFO: {'allow_post': True, 'allow_put': True, - 'default': attributes.ATTR_NOT_SPECIFIED, 'is_visible': True, + 'default': constants.ATTR_NOT_SPECIFIED, 'is_visible': True, 'enforce_policy': True, 'convert_to': attributes.convert_to_boolean_if_not_none} } @@ -90,7 +90,7 @@ class HAMaximumAgentsNumberNotValid(exceptions.NeutronException): class HAMinimumAgentsNumberNotValid(exceptions.NeutronException): message = (_("min_l3_agents_per_router config parameter is not valid. " "It has to be equal to or more than %s for HA.") % - constants.MINIMUM_AGENTS_FOR_HA) + n_const.MINIMUM_AGENTS_FOR_HA) class L3_ext_ha_mode(extensions.ExtensionDescriptor): diff --git a/neutron/extensions/l3agentscheduler.py b/neutron/extensions/l3agentscheduler.py index d28c134d620..33f5c31ad1c 100644 --- a/neutron/extensions/l3agentscheduler.py +++ b/neutron/extensions/l3agentscheduler.py @@ -15,6 +15,7 @@ import abc +from neutron_lib import constants from neutron_lib import exceptions from oslo_log import log as logging import webob.exc @@ -23,7 +24,6 @@ from neutron._i18n import _, _LE from neutron.api import extensions from neutron.api.v2 import base from neutron.api.v2 import resource -from neutron.common import constants from neutron.common import rpc as n_rpc from neutron.extensions import agent from neutron import manager diff --git a/neutron/extensions/multiprovidernet.py b/neutron/extensions/multiprovidernet.py index 1f725478b5a..2a701bc1421 100644 --- a/neutron/extensions/multiprovidernet.py +++ b/neutron/extensions/multiprovidernet.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from neutron_lib import exceptions as nexception import webob.exc @@ -34,14 +35,14 @@ class SegmentsContainDuplicateEntry(nexception.InvalidInput): def _convert_and_validate_segments(segments, valid_values=None): for segment in segments: - segment.setdefault(pnet.NETWORK_TYPE, attr.ATTR_NOT_SPECIFIED) - segment.setdefault(pnet.PHYSICAL_NETWORK, attr.ATTR_NOT_SPECIFIED) + segment.setdefault(pnet.NETWORK_TYPE, constants.ATTR_NOT_SPECIFIED) + segment.setdefault(pnet.PHYSICAL_NETWORK, constants.ATTR_NOT_SPECIFIED) segmentation_id = segment.get(pnet.SEGMENTATION_ID) if segmentation_id: segment[pnet.SEGMENTATION_ID] = attr.convert_to_int( segmentation_id) else: - segment[pnet.SEGMENTATION_ID] = attr.ATTR_NOT_SPECIFIED + segment[pnet.SEGMENTATION_ID] = constants.ATTR_NOT_SPECIFIED if len(segment.keys()) != 3: msg = (_("Unrecognized attribute(s) '%s'") % ', '.join(set(segment.keys()) - @@ -75,7 +76,7 @@ EXTENDED_ATTRIBUTES_2_0 = { SEGMENTS: {'allow_post': True, 'allow_put': True, 'validate': {'type:convert_segments': None}, 'convert_list_to': attr.convert_kvp_list_to_dict, - 'default': attr.ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'enforce_policy': True, 'is_visible': True}, } diff --git a/neutron/extensions/portbindings.py b/neutron/extensions/portbindings.py index 3b61175f9e4..ca1db137ef7 100644 --- a/neutron/extensions/portbindings.py +++ b/neutron/extensions/portbindings.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants + from neutron.api import extensions -from neutron.api.v2 import attributes # The type of vnic that this port should be attached to VNIC_TYPE = 'binding:vnic_type' @@ -102,11 +103,11 @@ VNIC_TYPES = [VNIC_NORMAL, VNIC_DIRECT, VNIC_MACVTAP, VNIC_BAREMETAL, EXTENDED_ATTRIBUTES_2_0 = { 'ports': { VIF_TYPE: {'allow_post': False, 'allow_put': False, - 'default': attributes.ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'enforce_policy': True, 'is_visible': True}, VIF_DETAILS: {'allow_post': False, 'allow_put': False, - 'default': attributes.ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'enforce_policy': True, 'is_visible': True}, VNIC_TYPE: {'allow_post': True, 'allow_put': True, @@ -115,11 +116,11 @@ EXTENDED_ATTRIBUTES_2_0 = { 'validate': {'type:values': VNIC_TYPES}, 'enforce_policy': True}, HOST_ID: {'allow_post': True, 'allow_put': True, - 'default': attributes.ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'is_visible': True, 'enforce_policy': True}, PROFILE: {'allow_post': True, 'allow_put': True, - 'default': attributes.ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'enforce_policy': True, 'validate': {'type:dict_or_none': None}, 'is_visible': True}, diff --git a/neutron/extensions/portsecurity.py b/neutron/extensions/portsecurity.py index af15d577864..e17b5b8fa16 100644 --- a/neutron/extensions/portsecurity.py +++ b/neutron/extensions/portsecurity.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from neutron_lib import exceptions as nexception from neutron._i18n import _ @@ -44,7 +45,7 @@ EXTENDED_ATTRIBUTES_2_0 = { 'ports': { PORTSECURITY: {'allow_post': True, 'allow_put': True, 'convert_to': attributes.convert_to_boolean, - 'default': attributes.ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'enforce_policy': True, 'is_visible': True}, } diff --git a/neutron/extensions/providernet.py b/neutron/extensions/providernet.py index 9c3abe81897..91232c0685d 100644 --- a/neutron/extensions/providernet.py +++ b/neutron/extensions/providernet.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from neutron_lib import exceptions as n_exc from neutron._i18n import _ @@ -33,19 +34,19 @@ EXTENDED_ATTRIBUTES_2_0 = { 'networks': { NETWORK_TYPE: {'allow_post': True, 'allow_put': True, 'validate': {'type:string': NETWORK_TYPE_MAX_LEN}, - 'default': attributes.ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'enforce_policy': True, 'is_visible': True}, PHYSICAL_NETWORK: {'allow_post': True, 'allow_put': True, 'validate': {'type:string': PHYSICAL_NETWORK_MAX_LEN}, - 'default': attributes.ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'enforce_policy': True, 'is_visible': True}, SEGMENTATION_ID: {'allow_post': True, 'allow_put': True, 'convert_to': attributes.convert_to_int, 'enforce_policy': True, - 'default': attributes.ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'is_visible': True}, } } diff --git a/neutron/extensions/securitygroup.py b/neutron/extensions/securitygroup.py index a81416bdbea..9bcb7c349f1 100644 --- a/neutron/extensions/securitygroup.py +++ b/neutron/extensions/securitygroup.py @@ -16,6 +16,7 @@ import abc import netaddr +from neutron_lib import constants as const from neutron_lib import exceptions as nexception from oslo_config import cfg from oslo_utils import uuidutils @@ -25,7 +26,7 @@ from neutron._i18n import _ from neutron.api import extensions from neutron.api.v2 import attributes as attr from neutron.api.v2 import base -from neutron.common import constants as const +from neutron.common import constants as n_const from neutron.common import exceptions from neutron import manager from neutron.quota import resource_registry @@ -217,7 +218,7 @@ attr.validators['type:name_not_default'] = _validate_name_not_default # in neutron.common.constants. IP_PROTOCOL_MAP in neutron-lib should # be updated and neutron should consume it once Mitaka backport is done. sg_supported_protocols = ([None] + list(const.IP_PROTOCOL_MAP.keys()) + - list(const.IP_PROTOCOL_NAME_ALIASES.keys())) + list(n_const.IP_PROTOCOL_NAME_ALIASES.keys())) sg_supported_ethertypes = ['IPv4', 'IPv6'] SECURITYGROUPS = 'security_groups' SECURITYGROUPRULES = 'security_group_rules' @@ -283,7 +284,7 @@ EXTENDED_ATTRIBUTES_2_0 = { 'allow_put': True, 'is_visible': True, 'convert_to': convert_to_uuid_list_or_none, - 'default': attr.ATTR_NOT_SPECIFIED}}} + 'default': const.ATTR_NOT_SPECIFIED}}} security_group_quota_opts = [ cfg.IntOpt('quota_security_group', default=10, diff --git a/neutron/extensions/subnetallocation.py b/neutron/extensions/subnetallocation.py index f735b9e82a2..73393182b0f 100644 --- a/neutron/extensions/subnetallocation.py +++ b/neutron/extensions/subnetallocation.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants + from neutron.api import extensions -from neutron.common import constants class Subnetallocation(extensions.ExtensionDescriptor): diff --git a/neutron/extensions/vlantransparent.py b/neutron/extensions/vlantransparent.py index 92e69722745..9514ab9755f 100644 --- a/neutron/extensions/vlantransparent.py +++ b/neutron/extensions/vlantransparent.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from neutron_lib import exceptions from oslo_config import cfg from oslo_log import log as logging @@ -33,7 +34,7 @@ EXTENDED_ATTRIBUTES_2_0 = { 'networks': { VLANTRANSPARENT: {'allow_post': True, 'allow_put': False, 'convert_to': attributes.convert_to_boolean, - 'default': attributes.ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'is_visible': True}, }, } diff --git a/neutron/ipam/requests.py b/neutron/ipam/requests.py index bf5f9d176f7..f3d35ed206e 100644 --- a/neutron/ipam/requests.py +++ b/neutron/ipam/requests.py @@ -13,12 +13,12 @@ import abc import netaddr +from neutron_lib import constants from oslo_utils import uuidutils import six from neutron._i18n import _ from neutron.api.v2 import attributes -from neutron.common import constants from neutron.common import ipv6_utils from neutron.common import utils as common_utils from neutron.ipam import exceptions as ipam_exc diff --git a/neutron/ipam/subnet_alloc.py b/neutron/ipam/subnet_alloc.py index 4d8c8c95176..108540f7e1d 100644 --- a/neutron/ipam/subnet_alloc.py +++ b/neutron/ipam/subnet_alloc.py @@ -17,13 +17,12 @@ import math import operator import netaddr +from neutron_lib import constants from neutron_lib import exceptions as lib_exc from oslo_db import exception as db_exc from oslo_utils import uuidutils 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.db import models_v2 from neutron.ipam import driver @@ -259,8 +258,8 @@ class SubnetPoolReader(object): return netaddr.IPNetwork(cidr).prefixlen def _read_id(self, subnetpool): - id = subnetpool.get('id', attributes.ATTR_NOT_SPECIFIED) - if id is attributes.ATTR_NOT_SPECIFIED: + id = subnetpool.get('id', constants.ATTR_NOT_SPECIFIED) + if id is constants.ATTR_NOT_SPECIFIED: id = uuidutils.generate_uuid() self.id = id @@ -291,13 +290,13 @@ class SubnetPoolReader(object): prefixlen_attr = type + '_prefixlen' prefix_attr = type + '_prefix' prefixlen = subnetpool.get(prefixlen_attr, - attributes.ATTR_NOT_SPECIFIED) + constants.ATTR_NOT_SPECIFIED) wildcard = self._sp_helper.wildcard(self.ip_version) - if prefixlen is attributes.ATTR_NOT_SPECIFIED and default_bound: + if prefixlen is constants.ATTR_NOT_SPECIFIED and default_bound: prefixlen = default_bound - if prefixlen is not attributes.ATTR_NOT_SPECIFIED: + if prefixlen is not constants.ATTR_NOT_SPECIFIED: prefix_cidr = '/'.join((wildcard, str(prefixlen))) setattr(self, prefix_attr, prefix_cidr) @@ -316,7 +315,7 @@ class SubnetPoolReader(object): raise n_exc.PrefixVersionMismatch() self.default_quota = subnetpool.get('default_quota') - if self.default_quota is attributes.ATTR_NOT_SPECIFIED: + if self.default_quota is constants.ATTR_NOT_SPECIFIED: self.default_quota = None self.ip_version = ip_version @@ -324,7 +323,7 @@ class SubnetPoolReader(object): def _read_address_scope(self, subnetpool): self.address_scope_id = subnetpool.get('address_scope_id', - attributes.ATTR_NOT_SPECIFIED) + constants.ATTR_NOT_SPECIFIED) def _compact_subnetpool_prefix_list(self, prefix_list): """Compact any overlapping prefixes in prefix_list and return the diff --git a/neutron/ipam/utils.py b/neutron/ipam/utils.py index 3c01a8f334e..1c062d76bd5 100644 --- a/neutron/ipam/utils.py +++ b/neutron/ipam/utils.py @@ -14,7 +14,7 @@ # under the License. import netaddr -from neutron.common import constants +from neutron_lib import constants def check_subnet_ip(cidr, ip_address): diff --git a/neutron/notifiers/nova.py b/neutron/notifiers/nova.py index 57f636e0c06..d9620e65719 100644 --- a/neutron/notifiers/nova.py +++ b/neutron/notifiers/nova.py @@ -14,6 +14,7 @@ # under the License. from keystoneauth1 import loading as ks_loading +from neutron_lib import constants from novaclient import client as nova_client from novaclient import exceptions as nova_exceptions from oslo_config import cfg @@ -22,7 +23,6 @@ from oslo_utils import uuidutils from sqlalchemy.orm import attributes as sql_attr from neutron._i18n import _LE, _LI, _LW -from neutron.common import constants from neutron import context from neutron import manager from neutron.notifiers import batch_notifier diff --git a/neutron/objects/common_types.py b/neutron/objects/common_types.py index ccf67534aa2..7a30c06bfc0 100644 --- a/neutron/objects/common_types.py +++ b/neutron/objects/common_types.py @@ -12,6 +12,7 @@ # under the License. import netaddr +from neutron_lib import constants as n_const from oslo_versionedobjects import fields as obj_fields import six @@ -122,7 +123,7 @@ class EtherTypeEnumField(obj_fields.AutoTypedField): class IpProtocolEnumField(obj_fields.AutoTypedField): AUTO_TYPE = obj_fields.Enum( - valid_values=list(constants.IP_PROTOCOL_MAP.keys())) + valid_values=list(n_const.IP_PROTOCOL_MAP.keys())) class MACAddress(obj_fields.FieldType): diff --git a/neutron/objects/qos/rule.py b/neutron/objects/qos/rule.py index 9903185e2a5..67b332e9e4d 100644 --- a/neutron/objects/qos/rule.py +++ b/neutron/objects/qos/rule.py @@ -16,11 +16,11 @@ import abc import sys +from neutron_lib import constants from oslo_versionedobjects import base as obj_base from oslo_versionedobjects import fields as obj_fields import six -from neutron.common import constants from neutron.common import utils from neutron.db import api as db_api from neutron.db.qos import models as qos_db_model diff --git a/neutron/pecan_wsgi/hooks/notifier.py b/neutron/pecan_wsgi/hooks/notifier.py index 7ebeb95e735..e2c8d9829f7 100644 --- a/neutron/pecan_wsgi/hooks/notifier.py +++ b/neutron/pecan_wsgi/hooks/notifier.py @@ -13,13 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from oslo_config import cfg from oslo_log import log from oslo_serialization import jsonutils from pecan import hooks from neutron.api.rpc.agentnotifiers import dhcp_rpc_agent_api -from neutron.common import constants from neutron.common import rpc as n_rpc from neutron import manager from neutron.pecan_wsgi import constants as pecan_constants diff --git a/neutron/plugins/common/utils.py b/neutron/plugins/common/utils.py index f96f3a0d488..76be89dd5cd 100644 --- a/neutron/plugins/common/utils.py +++ b/neutron/plugins/common/utils.py @@ -18,6 +18,7 @@ Common utilities and helper functions for OpenStack Networking Plugins. import hashlib +from neutron_lib import constants as n_const from neutron_lib import exceptions from oslo_config import cfg from oslo_log import log as logging @@ -26,7 +27,6 @@ import webob.exc from neutron._i18n import _, _LI from neutron.api.v2 import attributes -from neutron.common import constants as n_const from neutron.common import exceptions as n_exc from neutron.plugins.common import constants as p_const diff --git a/neutron/plugins/ml2/db.py b/neutron/plugins/ml2/db.py index 24e10348305..d3043e822c7 100644 --- a/neutron/plugins/ml2/db.py +++ b/neutron/plugins/ml2/db.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants as n_const from oslo_db import exception as db_exc from oslo_log import log from oslo_utils import uuidutils @@ -21,7 +22,6 @@ from sqlalchemy import or_ from sqlalchemy.orm import exc from neutron._i18n import _LE -from neutron.common import constants as n_const from neutron.db import models_v2 from neutron.db import securitygroups_db as sg_db from neutron.db import segments_db diff --git a/neutron/plugins/ml2/driver_context.py b/neutron/plugins/ml2/driver_context.py index f6e71a6ca98..e4ef711a1ba 100644 --- a/neutron/plugins/ml2/driver_context.py +++ b/neutron/plugins/ml2/driver_context.py @@ -13,11 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from oslo_log import log from oslo_serialization import jsonutils from neutron._i18n import _LW -from neutron.common import constants from neutron.extensions import portbindings from neutron.plugins.ml2 import db from neutron.plugins.ml2 import driver_api as api diff --git a/neutron/plugins/ml2/drivers/agent/_common_agent.py b/neutron/plugins/ml2/drivers/agent/_common_agent.py index fe884554d0e..0e0263d586a 100644 --- a/neutron/plugins/ml2/drivers/agent/_common_agent.py +++ b/neutron/plugins/ml2/drivers/agent/_common_agent.py @@ -18,6 +18,7 @@ import collections import sys import time +from neutron_lib import constants from oslo_config import cfg from oslo_log import log as logging from oslo_service import loopingcall @@ -29,7 +30,7 @@ from neutron.agent import rpc as agent_rpc from neutron.agent import securitygroups_rpc as sg_rpc from neutron.api.rpc.callbacks import resources from neutron.common import config as common_config -from neutron.common import constants +from neutron.common import constants as n_const from neutron.common import topics from neutron import context from neutron.plugins.ml2.drivers.agent import _agent_manager_base as amb @@ -118,7 +119,7 @@ class CommonAgentLoop(service.Service): agent_status = self.state_rpc.report_state(self.context, self.agent_state, True) - if agent_status == constants.AGENT_REVIVED: + if agent_status == n_const.AGENT_REVIVED: LOG.info(_LI('%s Agent has just been revived. ' 'Doing a full sync.'), self.agent_type) diff --git a/neutron/plugins/ml2/drivers/l2pop/mech_driver.py b/neutron/plugins/ml2/drivers/l2pop/mech_driver.py index fbb5dab514e..622f6388cd3 100644 --- a/neutron/plugins/ml2/drivers/l2pop/mech_driver.py +++ b/neutron/plugins/ml2/drivers/l2pop/mech_driver.py @@ -13,11 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants as const from oslo_config import cfg from oslo_log import log as logging from neutron._i18n import _LW -from neutron.common import constants as const from neutron import context as n_context from neutron.db import api as db_api from neutron.plugins.ml2.common import exceptions as ml2_exc diff --git a/neutron/plugins/ml2/drivers/l2pop/rpc_manager/l2population_rpc.py b/neutron/plugins/ml2/drivers/l2pop/rpc_manager/l2population_rpc.py index 6d03ac57a91..09e53d60739 100644 --- a/neutron/plugins/ml2/drivers/l2pop/rpc_manager/l2population_rpc.py +++ b/neutron/plugins/ml2/drivers/l2pop/rpc_manager/l2population_rpc.py @@ -16,11 +16,11 @@ import abc import itertools +from neutron_lib import constants as n_const from oslo_config import cfg from oslo_log import helpers as log_helpers import six -from neutron.common import constants as n_const from neutron.plugins.ml2.drivers.l2pop import rpc as l2pop_rpc diff --git a/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py b/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py index 2c02ac0096e..479b3c654f7 100644 --- a/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py @@ -22,6 +22,7 @@ import sys import netaddr +from neutron_lib import constants from oslo_config import cfg from oslo_log import log as logging import oslo_messaging @@ -35,7 +36,6 @@ from neutron.agent.linux import ip_lib from neutron.agent.linux import utils from neutron.agent import securitygroups_rpc as sg_rpc from neutron.common import config as common_config -from neutron.common import constants from neutron.common import exceptions from neutron.common import topics from neutron.common import utils as n_utils diff --git a/neutron/plugins/ml2/drivers/linuxbridge/mech_driver/mech_linuxbridge.py b/neutron/plugins/ml2/drivers/linuxbridge/mech_driver/mech_linuxbridge.py index 6bf19c672db..4c7337abee8 100644 --- a/neutron/plugins/ml2/drivers/linuxbridge/mech_driver/mech_linuxbridge.py +++ b/neutron/plugins/ml2/drivers/linuxbridge/mech_driver/mech_linuxbridge.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants + from neutron.agent import securitygroups_rpc -from neutron.common import constants from neutron.extensions import portbindings from neutron.plugins.common import constants as p_constants from neutron.plugins.ml2.drivers import mech_agent diff --git a/neutron/plugins/ml2/drivers/macvtap/agent/macvtap_neutron_agent.py b/neutron/plugins/ml2/drivers/macvtap/agent/macvtap_neutron_agent.py index 37405d17bcb..96aaf14ef65 100644 --- a/neutron/plugins/ml2/drivers/macvtap/agent/macvtap_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/macvtap/agent/macvtap_neutron_agent.py @@ -17,6 +17,7 @@ import os import sys +from neutron_lib import constants from oslo_config import cfg from oslo_log import log as logging import oslo_messaging @@ -27,7 +28,6 @@ from neutron.agent.linux import ip_lib from neutron.agent.linux import utils from neutron.agent import securitygroups_rpc as sg_rpc from neutron.common import config as common_config -from neutron.common import constants from neutron.common import topics from neutron.common import utils as n_utils from neutron.plugins.common import constants as p_constants diff --git a/neutron/plugins/ml2/drivers/macvtap/macvtap_common.py b/neutron/plugins/ml2/drivers/macvtap/macvtap_common.py index fe395285e7a..3d51d37eff6 100644 --- a/neutron/plugins/ml2/drivers/macvtap/macvtap_common.py +++ b/neutron/plugins/ml2/drivers/macvtap/macvtap_common.py @@ -14,7 +14,8 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron.common import constants as n_const +from neutron_lib import constants as n_const + from neutron.plugins.common import utils as p_utils MAX_VLAN_POSTFIX_LEN = 5 diff --git a/neutron/plugins/ml2/drivers/macvtap/mech_driver/mech_macvtap.py b/neutron/plugins/ml2/drivers/macvtap/mech_driver/mech_macvtap.py index 5da8a760001..23aa169167b 100644 --- a/neutron/plugins/ml2/drivers/macvtap/mech_driver/mech_macvtap.py +++ b/neutron/plugins/ml2/drivers/macvtap/mech_driver/mech_macvtap.py @@ -14,9 +14,9 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from oslo_log import log -from neutron.common import constants from neutron.extensions import portbindings from neutron.plugins.common import constants as p_constants from neutron.plugins.ml2 import driver_api as api diff --git a/neutron/plugins/ml2/drivers/mech_sriov/agent/sriov_nic_agent.py b/neutron/plugins/ml2/drivers/mech_sriov/agent/sriov_nic_agent.py index 53481cd816a..1ff8d154511 100644 --- a/neutron/plugins/ml2/drivers/mech_sriov/agent/sriov_nic_agent.py +++ b/neutron/plugins/ml2/drivers/mech_sriov/agent/sriov_nic_agent.py @@ -20,6 +20,7 @@ import socket import sys import time +from neutron_lib import constants as n_constants from oslo_config import cfg from oslo_log import log as logging import oslo_messaging @@ -32,7 +33,6 @@ from neutron.agent import rpc as agent_rpc from neutron.agent import securitygroups_rpc as sg_rpc from neutron.api.rpc.callbacks import resources from neutron.common import config as common_config -from neutron.common import constants as n_constants from neutron.common import topics from neutron.common import utils as n_utils from neutron import context diff --git a/neutron/plugins/ml2/drivers/mech_sriov/mech_driver/mech_driver.py b/neutron/plugins/ml2/drivers/mech_sriov/mech_driver/mech_driver.py index 42f2f10b48c..8de1d5c5a34 100644 --- a/neutron/plugins/ml2/drivers/mech_sriov/mech_driver/mech_driver.py +++ b/neutron/plugins/ml2/drivers/mech_sriov/mech_driver/mech_driver.py @@ -13,11 +13,11 @@ # 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_log import log from neutron._i18n import _, _LE, _LW -from neutron.common import constants from neutron.extensions import portbindings from neutron.plugins.common import constants as p_const from neutron.plugins.ml2 import driver_api as api diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/common/config.py b/neutron/plugins/ml2/drivers/openvswitch/agent/common/config.py index 8399824ad52..bc442ec4bc5 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/common/config.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/common/config.py @@ -12,11 +12,11 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants as n_const from oslo_config import cfg from neutron._i18n import _ from neutron.agent.common import config -from neutron.common import constants as n_const from neutron.plugins.common import constants as p_const from neutron.plugins.ml2.drivers.openvswitch.agent.common \ import constants diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/openflow/ovs_ofctl/br_dvr_process.py b/neutron/plugins/ml2/drivers/openvswitch/agent/openflow/ovs_ofctl/br_dvr_process.py index 6fdb06440e0..18a8525dc85 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/openflow/ovs_ofctl/br_dvr_process.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/openflow/ovs_ofctl/br_dvr_process.py @@ -29,7 +29,7 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron.common import constants +from neutron_lib import constants class OVSDVRProcessMixin(object): diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/openflow/ovs_ofctl/br_int.py b/neutron/plugins/ml2/drivers/openvswitch/agent/openflow/ovs_ofctl/br_int.py index bc7a4eb423c..34b6b7de815 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/openflow/ovs_ofctl/br_int.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/openflow/ovs_ofctl/br_int.py @@ -21,7 +21,9 @@ import netaddr -from neutron.common import constants as const +from neutron_lib import constants as const + +from neutron.common import constants as n_const from neutron.plugins.common import constants as p_const from neutron.plugins.ml2.drivers.openvswitch.agent.common import constants from neutron.plugins.ml2.drivers.openvswitch.agent.openflow.ovs_ofctl \ @@ -119,14 +121,14 @@ class OVSIntegrationBridge(ovs_bridge.OVSAgentBridge): for ip in ip_addresses: self.install_normal( table_id=constants.ARP_SPOOF_TABLE, priority=2, - dl_type=const.ETHERTYPE_IPV6, + dl_type=n_const.ETHERTYPE_IPV6, nw_proto=const.PROTO_NUM_IPV6_ICMP, icmp_type=const.ICMPV6_TYPE_NA, nd_target=ip, in_port=port) # Now that the rules are ready, direct icmpv6 neighbor advertisement # traffic from the port into the anti-spoof table. self.add_flow(table=constants.LOCAL_SWITCHING, - priority=10, dl_type=const.ETHERTYPE_IPV6, + priority=10, dl_type=n_const.ETHERTYPE_IPV6, nw_proto=const.PROTO_NUM_IPV6_ICMP, icmp_type=const.ICMPV6_TYPE_NA, in_port=port, actions=("resubmit(,%s)" % constants.ARP_SPOOF_TABLE)) diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py index d5a62c28522..842f58f5f22 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py @@ -15,13 +15,13 @@ import sys +from neutron_lib import constants as n_const from oslo_config import cfg from oslo_log import log as logging import oslo_messaging from oslo_utils import excutils from neutron._i18n import _LE, _LI, _LW -from neutron.common import constants as n_const from neutron.common import utils as n_utils from neutron.plugins.common import constants as p_const from neutron.plugins.ml2.drivers.openvswitch.agent.common import constants diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py index bce4fd7f4b9..fdf6998afa5 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py @@ -20,6 +20,7 @@ import sys import time import netaddr +from neutron_lib import constants as n_const from oslo_config import cfg from oslo_log import log as logging import oslo_messaging @@ -39,7 +40,7 @@ from neutron.agent import securitygroups_rpc as sg_rpc from neutron.api.rpc.callbacks import resources from neutron.api.rpc.handlers import dvr_rpc from neutron.common import config -from neutron.common import constants as n_const +from neutron.common import constants as c_const from neutron.common import ipv6_utils as ipv6 from neutron.common import topics from neutron.common import utils as n_utils @@ -311,7 +312,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin, agent_status = self.state_rpc.report_state(self.context, self.agent_state, True) - if agent_status == n_const.AGENT_REVIVED: + if agent_status == c_const.AGENT_REVIVED: LOG.info(_LI('Agent has just been revived. ' 'Doing a full sync.')) self.fullsync = True @@ -913,7 +914,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin, if netaddr.IPNetwork(ip).version == 6} # Allow neighbor advertisements for LLA address. ipv6_addresses |= {str(ipv6.get_ipv6_addr_by_EUI64( - n_const.IPV6_LLA_PREFIX, mac)) + c_const.IPV6_LLA_PREFIX, mac)) for mac in mac_addresses} if not has_zero_prefixlen_address(ipv6_addresses): # Install protection only when prefix is not zero because a /0 diff --git a/neutron/plugins/ml2/drivers/openvswitch/mech_driver/mech_openvswitch.py b/neutron/plugins/ml2/drivers/openvswitch/mech_driver/mech_openvswitch.py index 5ac14f0a6a8..5b4079b69f6 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/mech_driver/mech_openvswitch.py +++ b/neutron/plugins/ml2/drivers/openvswitch/mech_driver/mech_openvswitch.py @@ -15,10 +15,10 @@ import os +from neutron_lib import constants from oslo_config import cfg from neutron.agent import securitygroups_rpc -from neutron.common import constants from neutron.extensions import portbindings from neutron.plugins.common import constants as p_constants from neutron.plugins.ml2 import driver_api as api diff --git a/neutron/plugins/ml2/managers.py b/neutron/plugins/ml2/managers.py index d5a8538d9d6..cfffc414549 100644 --- a/neutron/plugins/ml2/managers.py +++ b/neutron/plugins/ml2/managers.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from neutron_lib import exceptions as exc from oslo_config import cfg from oslo_log import log @@ -143,7 +144,7 @@ class TypeManager(stevedore.named.NamedExtensionManager): def _get_attribute(self, attrs, key): value = attrs.get(key) - if value is attributes.ATTR_NOT_SPECIFIED: + if value is constants.ATTR_NOT_SPECIFIED: value = None return value diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 2e9cc39bd49..ff32459d0b8 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -14,6 +14,7 @@ # under the License. from eventlet import greenthread +from neutron_lib import constants as const from neutron_lib import exceptions as exc from oslo_concurrency import lockutils from oslo_config import cfg @@ -41,7 +42,7 @@ from neutron.callbacks import events from neutron.callbacks import exceptions from neutron.callbacks import registry from neutron.callbacks import resources -from neutron.common import constants as const +from neutron.common import constants as n_const from neutron.common import ipv6_utils from neutron.common import rpc as n_rpc from neutron.common import topics @@ -255,7 +256,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, port_id = port['id'] changes = False - host = attributes.ATTR_NOT_SPECIFIED + host = const.ATTR_NOT_SPECIFIED if attrs and portbindings.HOST_ID in attrs: host = attrs.get(portbindings.HOST_ID) or '' @@ -276,7 +277,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, if attrs and portbindings.PROFILE in attrs: profile = attrs.get(portbindings.PROFILE) or {} - if profile not in (None, attributes.ATTR_NOT_SPECIFIED, + if profile not in (None, const.ATTR_NOT_SPECIFIED, self._get_profile(binding)): binding.profile = jsonutils.dumps(profile) if len(binding.profile) > models.BINDING_PROFILE_LEN: @@ -1611,7 +1612,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, # REVISIT(rkukura): Consider calling into MechanismDrivers to # process device names, or having MechanismDrivers supply list # of device prefixes to strip. - for prefix in const.INTERFACE_PREFIXES: + for prefix in n_const.INTERFACE_PREFIXES: if device.startswith(prefix): return device[len(prefix):] # REVISIT(irenab): Consider calling into bound MD to diff --git a/neutron/plugins/ml2/rpc.py b/neutron/plugins/ml2/rpc.py index 0ed1f968c93..57992ff0681 100644 --- a/neutron/plugins/ml2/rpc.py +++ b/neutron/plugins/ml2/rpc.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants as n_const from neutron_lib import exceptions from oslo_log import log import oslo_messaging @@ -24,7 +25,6 @@ from neutron.api.rpc.handlers import securitygroups_rpc as sg_rpc 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.common import rpc as n_rpc from neutron.common import topics from neutron.extensions import portbindings diff --git a/neutron/policy.py b/neutron/policy.py index f79787f03ec..aefc6ce7bbe 100644 --- a/neutron/policy.py +++ b/neutron/policy.py @@ -16,6 +16,7 @@ import collections import re +from neutron_lib import constants from neutron_lib import exceptions as lib_exc from oslo_config import cfg from oslo_db import exception as db_exc @@ -90,10 +91,10 @@ def _is_attribute_explicitly_set(attribute_name, resource, target, action): # default value of an attribute, but check whether it was explicitly # marked as being updated instead. return (attribute_name in target[const.ATTRIBUTES_TO_UPDATE] and - target[attribute_name] is not attributes.ATTR_NOT_SPECIFIED) + target[attribute_name] is not constants.ATTR_NOT_SPECIFIED) return ('default' in resource[attribute_name] and attribute_name in target and - target[attribute_name] is not attributes.ATTR_NOT_SPECIFIED and + target[attribute_name] is not constants.ATTR_NOT_SPECIFIED and target[attribute_name] != resource[attribute_name]['default']) diff --git a/neutron/scheduler/dhcp_agent_scheduler.py b/neutron/scheduler/dhcp_agent_scheduler.py index b7368800fd4..fbf8f2e0e80 100644 --- a/neutron/scheduler/dhcp_agent_scheduler.py +++ b/neutron/scheduler/dhcp_agent_scheduler.py @@ -17,13 +17,13 @@ import collections import heapq +from neutron_lib import constants from oslo_config import cfg from oslo_db import exception as db_exc from oslo_log import log as logging from sqlalchemy import sql from neutron._i18n import _LI, _LW -from neutron.common import constants from neutron.db import agents_db from neutron.db import agentschedulers_db from neutron.db import api as db_api diff --git a/neutron/scheduler/l3_agent_scheduler.py b/neutron/scheduler/l3_agent_scheduler.py index ebe13045532..5b5beb9a45c 100644 --- a/neutron/scheduler/l3_agent_scheduler.py +++ b/neutron/scheduler/l3_agent_scheduler.py @@ -19,6 +19,7 @@ import functools import itertools import random +from neutron_lib import constants as lib_const from oslo_config import cfg from oslo_db import exception as db_exc from oslo_log import log as logging @@ -135,7 +136,7 @@ class L3Scheduler(object): :returns: True if routers have been successfully assigned to host """ l3_agent = plugin.get_enabled_agent_on_host( - context, constants.AGENT_TYPE_L3, host) + context, lib_const.AGENT_TYPE_L3, host) if not l3_agent: return False @@ -143,7 +144,7 @@ class L3Scheduler(object): context, plugin, router_ids) if not unscheduled_routers: if utils.is_extension_supported( - plugin, constants.L3_HA_MODE_EXT_ALIAS): + plugin, lib_const.L3_HA_MODE_EXT_ALIAS): return self._schedule_ha_routers_to_additional_agent( plugin, context, l3_agent) diff --git a/neutron/services/bgp/bgp_plugin.py b/neutron/services/bgp/bgp_plugin.py index af8cd849809..9d6bc8b0254 100644 --- a/neutron/services/bgp/bgp_plugin.py +++ b/neutron/services/bgp/bgp_plugin.py @@ -13,6 +13,7 @@ # under the License. from netaddr import IPAddress +from neutron_lib import constants as n_const from oslo_config import cfg from oslo_log import log as logging from oslo_utils import importutils @@ -22,7 +23,6 @@ from neutron.api.rpc.handlers import bgp_speaker_rpc as bs_rpc 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.common import rpc as n_rpc from neutron import context from neutron.db import bgp_db diff --git a/neutron/services/l3_router/l3_router_plugin.py b/neutron/services/l3_router/l3_router_plugin.py index 801a46328bd..c10668cbc11 100644 --- a/neutron/services/l3_router/l3_router_plugin.py +++ b/neutron/services/l3_router/l3_router_plugin.py @@ -13,13 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants as n_const from oslo_config import cfg from oslo_log import helpers as log_helpers from oslo_utils import importutils from neutron.api.rpc.agentnotifiers import l3_rpc_agent_api from neutron.api.rpc.handlers import l3_rpc -from neutron.common import constants as n_const from neutron.common import rpc as n_rpc from neutron.common import topics from neutron.db import common_db_mixin diff --git a/neutron/services/metering/agents/metering_agent.py b/neutron/services/metering/agents/metering_agent.py index 59fd14cf073..213e901885b 100644 --- a/neutron/services/metering/agents/metering_agent.py +++ b/neutron/services/metering/agents/metering_agent.py @@ -15,6 +15,7 @@ import sys import time +from neutron_lib import constants from oslo_config import cfg from oslo_log import log as logging import oslo_messaging @@ -27,7 +28,7 @@ from neutron._i18n import _, _LE, _LI, _LW from neutron.agent.common import config from neutron.agent import rpc as agent_rpc from neutron.common import config as common_config -from neutron.common import constants as constants +from neutron.common import constants as n_const from neutron.common import rpc as n_rpc from neutron.common import topics from neutron.common import utils @@ -145,7 +146,7 @@ class MeteringAgent(MeteringPluginRpc, manager.Manager): self.label_tenant_id = {} for router in self.routers.values(): tenant_id = router['tenant_id'] - labels = router.get(constants.METERING_LABEL_KEY, []) + labels = router.get(n_const.METERING_LABEL_KEY, []) for label in labels: label_id = label['id'] self.label_tenant_id[label_id] = tenant_id diff --git a/neutron/tests/base.py b/neutron/tests/base.py index 8f8bae21338..6e3d8b3a9bc 100644 --- a/neutron/tests/base.py +++ b/neutron/tests/base.py @@ -25,6 +25,7 @@ import weakref import eventlet.timeout import fixtures import mock +from neutron_lib import constants from oslo_concurrency.fixture import lockutils from oslo_config import cfg from oslo_messaging import conffixture as messaging_conffixture @@ -40,7 +41,6 @@ from neutron.api.rpc.callbacks.consumer import registry as rpc_consumer_reg from neutron.callbacks import manager as registry_manager from neutron.callbacks import registry from neutron.common import config -from neutron.common import constants from neutron.common import rpc as n_rpc from neutron.common import utils from neutron.db import agentschedulers_db diff --git a/neutron/tests/common/agents/ovs_agent.py b/neutron/tests/common/agents/ovs_agent.py index e10632582db..b93bc3861e0 100755 --- a/neutron/tests/common/agents/ovs_agent.py +++ b/neutron/tests/common/agents/ovs_agent.py @@ -15,10 +15,10 @@ import hashlib import sys +from neutron_lib import constants as n_const from oslo_utils import encodeutils from neutron.cmd.eventlet.plugins.ovs_neutron_agent import main as _main -from neutron.common import constants as n_const from neutron.plugins.ml2.drivers.openvswitch.agent.ovs_neutron_agent \ import OVSNeutronAgent diff --git a/neutron/tests/common/base.py b/neutron/tests/common/base.py index eff4a0bf44c..02387f63393 100644 --- a/neutron/tests/common/base.py +++ b/neutron/tests/common/base.py @@ -14,10 +14,10 @@ import functools import unittest.case +from neutron_lib import constants as n_const from oslo_db.sqlalchemy import test_base import testtools.testcase -from neutron.common import constants as n_const from neutron.tests import base from neutron.tests import tools diff --git a/neutron/tests/common/conn_testers.py b/neutron/tests/common/conn_testers.py index 948f35ef819..aedc31ef8c8 100644 --- a/neutron/tests/common/conn_testers.py +++ b/neutron/tests/common/conn_testers.py @@ -15,12 +15,12 @@ import functools import fixtures -from neutron_lib import constants as n_consts +from neutron_lib import constants from oslo_utils import uuidutils from neutron.agent import firewall from neutron.agent.linux import ip_lib -from neutron.common import constants +from neutron.common import constants as n_consts from neutron.tests.common import machine_fixtures from neutron.tests.common import net_helpers @@ -29,8 +29,8 @@ from neutron.tests.common import net_helpers # sufficient for correct scenarios but not too high because of negative # tests. ICMP_VERSION_TIMEOUTS = { - n_consts.IP_VERSION_4: 1, - n_consts.IP_VERSION_6: 2, + constants.IP_VERSION_4: 1, + constants.IP_VERSION_6: 2, } @@ -61,7 +61,7 @@ class ConnectionTester(fixtures.Fixture): UDP = net_helpers.NetcatTester.UDP TCP = net_helpers.NetcatTester.TCP ICMP = constants.PROTO_NAME_ICMP - ARP = constants.ETHERTYPE_NAME_ARP + ARP = n_consts.ETHERTYPE_NAME_ARP INGRESS = firewall.INGRESS_DIRECTION EGRESS = firewall.EGRESS_DIRECTION diff --git a/neutron/tests/common/helpers.py b/neutron/tests/common/helpers.py index e5a9f4eed50..a8324faa569 100644 --- a/neutron/tests/common/helpers.py +++ b/neutron/tests/common/helpers.py @@ -15,12 +15,13 @@ import datetime import os +from neutron_lib import constants from oslo_utils import timeutils import six import testtools import neutron -from neutron.common import constants +from neutron.common import constants as n_const from neutron.common import topics from neutron import context from neutron.db import agents_db @@ -74,7 +75,7 @@ def _register_agent(agent): admin_context, agent['agent_type'], agent['host']) -def register_l3_agent(host=HOST, agent_mode=constants.L3_AGENT_MODE_LEGACY, +def register_l3_agent(host=HOST, agent_mode=n_const.L3_AGENT_MODE_LEGACY, internal_only=True, ext_net_id='', ext_bridge='', router_id=None, az=DEFAULT_AZ): agent = _get_l3_agent_dict(host, agent_mode, internal_only, ext_net_id, diff --git a/neutron/tests/common/l3_test_common.py b/neutron/tests/common/l3_test_common.py index f0509625f78..aac5760d736 100644 --- a/neutron/tests/common/l3_test_common.py +++ b/neutron/tests/common/l3_test_common.py @@ -15,10 +15,11 @@ import copy import netaddr +from neutron_lib import constants as l3_constants from oslo_utils import uuidutils from six import moves -from neutron.common import constants as l3_constants +from neutron.common import constants as n_const _uuid = uuidutils.generate_uuid @@ -268,9 +269,9 @@ def router_append_pd_enabled_subnet(router, count=1): 'subnet_id': subnet_id}], 'mac_address': str(mac_address), 'subnets': [{'id': subnet_id, - 'cidr': l3_constants.PROVISIONAL_IPV6_PD_PREFIX, + 'cidr': n_const.PROVISIONAL_IPV6_PD_PREFIX, 'gateway_ip': '::1', - 'ipv6_ra_mode': l3_constants.IPV6_SLAAC, + 'ipv6_ra_mode': n_const.IPV6_SLAAC, 'subnetpool_id': l3_constants.IPV6_PD_POOL_ID}]} interfaces.append(intf) pd_intfs.append(intf) diff --git a/neutron/tests/common/net_helpers.py b/neutron/tests/common/net_helpers.py index e03fabc481f..0068e569053 100644 --- a/neutron/tests/common/net_helpers.py +++ b/neutron/tests/common/net_helpers.py @@ -27,6 +27,7 @@ import subprocess import fixtures import netaddr +from neutron_lib import constants as n_const from oslo_config import cfg from oslo_utils import uuidutils import six @@ -37,7 +38,6 @@ from neutron.agent.linux import bridge_lib from neutron.agent.linux import interface from neutron.agent.linux import ip_lib from neutron.agent.linux import utils -from neutron.common import constants as n_const from neutron.db import db_base_plugin_common from neutron.plugins.ml2.drivers.linuxbridge.agent import \ linuxbridge_neutron_agent as linuxbridge_agent diff --git a/neutron/tests/fullstack/resources/config.py b/neutron/tests/fullstack/resources/config.py index 29c0528bfdf..d75b32b2ec0 100644 --- a/neutron/tests/fullstack/resources/config.py +++ b/neutron/tests/fullstack/resources/config.py @@ -15,8 +15,8 @@ import tempfile import fixtures +from neutron_lib import constants -from neutron.common import constants from neutron.plugins.ml2.extensions import qos as qos_ext from neutron.tests import base from neutron.tests.common import config_fixtures diff --git a/neutron/tests/fullstack/resources/environment.py b/neutron/tests/fullstack/resources/environment.py index e58d3134755..9695c5d610a 100644 --- a/neutron/tests/fullstack/resources/environment.py +++ b/neutron/tests/fullstack/resources/environment.py @@ -13,12 +13,12 @@ # under the License. import fixtures +from neutron_lib import constants from neutronclient.common import exceptions as nc_exc from oslo_config import cfg from neutron.agent.linux import ip_lib from neutron.agent.linux import utils -from neutron.common import constants from neutron.common import utils as common_utils from neutron.plugins.ml2.drivers.linuxbridge.agent import \ linuxbridge_neutron_agent as lb_agent diff --git a/neutron/tests/fullstack/test_connectivity.py b/neutron/tests/fullstack/test_connectivity.py index 48edbc902b8..8701e4ef979 100644 --- a/neutron/tests/fullstack/test_connectivity.py +++ b/neutron/tests/fullstack/test_connectivity.py @@ -12,10 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from oslo_utils import uuidutils import testscenarios -from neutron.common import constants from neutron.tests.fullstack import base from neutron.tests.fullstack.resources import environment from neutron.tests.fullstack.resources import machine diff --git a/neutron/tests/fullstack/test_qos.py b/neutron/tests/fullstack/test_qos.py index 7512d14d570..6d95c4012f3 100644 --- a/neutron/tests/fullstack/test_qos.py +++ b/neutron/tests/fullstack/test_qos.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from oslo_utils import uuidutils import testscenarios @@ -19,7 +20,6 @@ from neutron.agent.common import ovs_lib from neutron.agent.linux import bridge_lib from neutron.agent.linux import tc_lib from neutron.agent.linux import utils -from neutron.common import constants from neutron.services.qos import qos_consts from neutron.tests.fullstack import base from neutron.tests.fullstack.resources import environment diff --git a/neutron/tests/functional/agent/l2/base.py b/neutron/tests/functional/agent/l2/base.py index 2ba41006090..37bf76ab9f6 100644 --- a/neutron/tests/functional/agent/l2/base.py +++ b/neutron/tests/functional/agent/l2/base.py @@ -18,6 +18,7 @@ import random import eventlet import mock +from neutron_lib import constants as n_const from oslo_config import cfg from oslo_utils import uuidutils @@ -28,7 +29,6 @@ from neutron.agent.linux import interface from neutron.agent.linux import polling from neutron.agent.linux import utils as agent_utils from neutron.common import config as common_config -from neutron.common import constants as n_const from neutron.common import utils from neutron.plugins.common import constants as p_const from neutron.plugins.ml2.drivers.openvswitch.agent.common import config \ diff --git a/neutron/tests/functional/agent/l3/framework.py b/neutron/tests/functional/agent/l3/framework.py index eccc51de5c0..5528c011175 100644 --- a/neutron/tests/functional/agent/l3/framework.py +++ b/neutron/tests/functional/agent/l3/framework.py @@ -17,6 +17,7 @@ import functools import mock import netaddr +from neutron_lib import constants as l3_constants from oslo_config import cfg from oslo_log import log as logging from oslo_utils import uuidutils @@ -30,7 +31,7 @@ from neutron.agent.linux import external_process from neutron.agent.linux import ip_lib from neutron.agent.linux import utils from neutron.common import config as common_config -from neutron.common import constants as l3_constants +from neutron.common import constants as n_const from neutron.common import utils as common_utils from neutron.tests.common import l3_test_common from neutron.tests.common import net_helpers @@ -218,7 +219,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase): router = self.manage_router(self.agent, router_info) # Add multiple-IPv6-prefix internal router port - slaac = l3_constants.IPV6_SLAAC + slaac = n_const.IPV6_SLAAC slaac_mode = {'ra_mode': slaac, 'address_mode': slaac} subnet_modes = [slaac_mode] * 2 self._add_internal_interface_by_subnet(router.router, diff --git a/neutron/tests/functional/agent/l3/test_dvr_router.py b/neutron/tests/functional/agent/l3/test_dvr_router.py index d06fd4d40c8..da36b55160e 100644 --- a/neutron/tests/functional/agent/l3/test_dvr_router.py +++ b/neutron/tests/functional/agent/l3/test_dvr_router.py @@ -17,6 +17,7 @@ import functools import mock import netaddr +from neutron_lib import constants as l3_constants import testtools from neutron.agent.l3 import agent as neutron_l3_agent @@ -25,7 +26,7 @@ from neutron.agent.l3 import namespaces from neutron.agent.linux import ip_lib from neutron.agent.linux import iptables_manager from neutron.agent.linux import utils -from neutron.common import constants as l3_constants +from neutron.common import constants as n_const from neutron.extensions import portbindings from neutron.tests.common import l3_test_common from neutron.tests.common import machine_fixtures @@ -248,7 +249,7 @@ class TestDvrRouter(framework.L3AgentTestFramework): def _add_fip_agent_gw_port_info_to_router(self, router, external_gw_port): # Add fip agent gateway port information to the router_info fip_gw_port_list = router.get( - l3_constants.FLOATINGIP_AGENT_INTF_KEY, []) + n_const.FLOATINGIP_AGENT_INTF_KEY, []) if not fip_gw_port_list and external_gw_port: # Get values from external gateway port fixed_ip = external_gw_port['fixed_ips'][0] @@ -258,7 +259,7 @@ class TestDvrRouter(framework.L3AgentTestFramework): fip_gw_port_ip = str(netaddr.IPAddress(port_ip) + 5) # Add floatingip agent gateway port info to router prefixlen = netaddr.IPNetwork(float_subnet['cidr']).prefixlen - router[l3_constants.FLOATINGIP_AGENT_INTF_KEY] = [ + router[n_const.FLOATINGIP_AGENT_INTF_KEY] = [ {'subnets': [ {'cidr': float_subnet['cidr'], 'gateway_ip': float_subnet['gateway_ip'], @@ -276,9 +277,9 @@ class TestDvrRouter(framework.L3AgentTestFramework): def _add_snat_port_info_to_router(self, router, internal_ports): # Add snat port information to the router - snat_port_list = router.get(l3_constants.SNAT_ROUTER_INTF_KEY, []) + snat_port_list = router.get(n_const.SNAT_ROUTER_INTF_KEY, []) if not snat_port_list and internal_ports: - router[l3_constants.SNAT_ROUTER_INTF_KEY] = [] + router[n_const.SNAT_ROUTER_INTF_KEY] = [] for port in internal_ports: # Get values from internal port fixed_ip = port['fixed_ips'][0] @@ -305,7 +306,7 @@ class TestDvrRouter(framework.L3AgentTestFramework): # Get the address scope if there is any if 'address_scopes' in port: snat_router_port['address_scopes'] = port['address_scopes'] - router[l3_constants.SNAT_ROUTER_INTF_KEY].append( + router[n_const.SNAT_ROUTER_INTF_KEY].append( snat_router_port) def _assert_dvr_external_device(self, router): @@ -387,7 +388,7 @@ class TestDvrRouter(framework.L3AgentTestFramework): # We need to fetch the floatingip agent gateway port info # from the router_info floating_agent_gw_port = ( - router.router[l3_constants.FLOATINGIP_AGENT_INTF_KEY]) + router.router[n_const.FLOATINGIP_AGENT_INTF_KEY]) self.assertTrue(floating_agent_gw_port) external_gw_port = floating_agent_gw_port[0] @@ -589,11 +590,11 @@ class TestDvrRouter(framework.L3AgentTestFramework): """ self.agent.conf.agent_mode = 'dvr' router_info = self.generate_dvr_router_info() - fip_agent_gw_port = router_info[l3_constants.FLOATINGIP_AGENT_INTF_KEY] + fip_agent_gw_port = router_info[n_const.FLOATINGIP_AGENT_INTF_KEY] # Now let us not pass the FLOATINGIP_AGENT_INTF_KEY, to emulate # that the server did not create the port, since there was no valid # host binding. - router_info[l3_constants.FLOATINGIP_AGENT_INTF_KEY] = [] + router_info[n_const.FLOATINGIP_AGENT_INTF_KEY] = [] self.mock_plugin_api.get_agent_gateway_port.return_value = ( fip_agent_gw_port[0]) router1 = self.manage_router(self.agent, router_info) @@ -631,10 +632,10 @@ class TestDvrRouter(framework.L3AgentTestFramework): """ self.agent.conf.agent_mode = 'dvr_snat' router_info = self.generate_dvr_router_info() - snat_internal_port = router_info[l3_constants.SNAT_ROUTER_INTF_KEY] + snat_internal_port = router_info[n_const.SNAT_ROUTER_INTF_KEY] router1 = self.manage_router(self.agent, router_info) csnat_internal_port = ( - router1.router[l3_constants.SNAT_ROUTER_INTF_KEY]) + router1.router[n_const.SNAT_ROUTER_INTF_KEY]) # Now save the internal device name to verify later internal_device_name = router1._get_snat_int_device_name( csnat_internal_port[0]['id']) @@ -650,7 +651,7 @@ class TestDvrRouter(framework.L3AgentTestFramework): # Now let us not pass the SNAT_ROUTER_INTF_KEY, to emulate # that the server did not send it, since the interface has been # removed. - router1.router[l3_constants.SNAT_ROUTER_INTF_KEY] = [] + router1.router[n_const.SNAT_ROUTER_INTF_KEY] = [] self.agent._process_updated_router(router1.router) router_updated = self.agent.router_info[router_info['id']] self._assert_snat_namespace_exists(router_updated) @@ -822,7 +823,7 @@ class TestDvrRouter(framework.L3AgentTestFramework): router_info[l3_constants.INTERFACE_KEY][1]['address_scopes'] = ( address_scope2) # Renew the address scope - router_info[l3_constants.SNAT_ROUTER_INTF_KEY] = [] + router_info[n_const.SNAT_ROUTER_INTF_KEY] = [] self._add_snat_port_info_to_router( router_info, router_info[l3_constants.INTERFACE_KEY]) diff --git a/neutron/tests/functional/agent/l3/test_ha_router.py b/neutron/tests/functional/agent/l3/test_ha_router.py index fd134af7324..e41cecedaec 100644 --- a/neutron/tests/functional/agent/l3/test_ha_router.py +++ b/neutron/tests/functional/agent/l3/test_ha_router.py @@ -16,13 +16,14 @@ import copy import mock +from neutron_lib import constants as l3_constants import six from neutron.agent.l3 import agent as neutron_l3_agent from neutron.agent.l3 import namespaces from neutron.agent.linux import ip_lib from neutron.agent.linux import utils -from neutron.common import constants as l3_constants +from neutron.common import constants from neutron.common import utils as common_utils from neutron.tests.common import l3_test_common from neutron.tests.common import net_helpers @@ -193,7 +194,7 @@ class L3HATestCase(framework.L3AgentTestFramework): self.assertIn(ip_addr, config) interface_id = router.router[l3_constants.INTERFACE_KEY][0]['id'] - slaac = l3_constants.IPV6_SLAAC + slaac = constants.IPV6_SLAAC slaac_mode = {'ra_mode': slaac, 'address_mode': slaac} # Add a second IPv6 subnet to the router internal interface. diff --git a/neutron/tests/functional/agent/l3/test_legacy_router.py b/neutron/tests/functional/agent/l3/test_legacy_router.py index 35e6272b45a..79cc72473fc 100644 --- a/neutron/tests/functional/agent/l3/test_legacy_router.py +++ b/neutron/tests/functional/agent/l3/test_legacy_router.py @@ -15,6 +15,7 @@ import mock +from neutron_lib import constants as l3_constants from neutron.agent.l3 import namespace_manager from neutron.agent.l3 import namespaces @@ -22,7 +23,6 @@ from neutron.agent.linux import ip_lib from neutron.callbacks import events from neutron.callbacks import registry from neutron.callbacks import resources -from neutron.common import constants as l3_constants from neutron.tests.common import machine_fixtures from neutron.tests.common import net_helpers from neutron.tests.functional.agent.l3 import framework diff --git a/neutron/tests/functional/agent/linux/test_iptables.py b/neutron/tests/functional/agent/linux/test_iptables.py index 95f1a9fdb48..d8ff5dc6e05 100644 --- a/neutron/tests/functional/agent/linux/test_iptables.py +++ b/neutron/tests/functional/agent/linux/test_iptables.py @@ -14,11 +14,11 @@ # under the License. import os.path +from neutron_lib import constants import testtools from neutron.agent.linux import iptables_manager from neutron.agent.linux import utils -from neutron.common import constants from neutron.tests import base from neutron.tests.common import machine_fixtures from neutron.tests.common import net_helpers diff --git a/neutron/tests/functional/agent/linux/test_linuxbridge_arp_protect.py b/neutron/tests/functional/agent/linux/test_linuxbridge_arp_protect.py index 02cd0f8810b..868d840f047 100644 --- a/neutron/tests/functional/agent/linux/test_linuxbridge_arp_protect.py +++ b/neutron/tests/functional/agent/linux/test_linuxbridge_arp_protect.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron.common import constants from neutron.common import utils +from neutron_lib import constants + from neutron.plugins.ml2.drivers.linuxbridge.agent import arp_protect from neutron.tests.common import machine_fixtures from neutron.tests.common import net_helpers diff --git a/neutron/tests/functional/agent/test_firewall.py b/neutron/tests/functional/agent/test_firewall.py index 52ed8d459f0..59500f05362 100644 --- a/neutron/tests/functional/agent/test_firewall.py +++ b/neutron/tests/functional/agent/test_firewall.py @@ -22,6 +22,7 @@ import functools import random import netaddr +from neutron_lib import constants from oslo_config import cfg from oslo_log import log as logging import testscenarios @@ -31,7 +32,6 @@ from neutron.agent.linux import iptables_firewall from neutron.agent.linux import openvswitch_firewall from neutron.agent import securitygroups_rpc as sg_cfg from neutron.cmd.sanity import checks -from neutron.common import constants from neutron.tests.common import conn_testers from neutron.tests.functional import base diff --git a/neutron/tests/functional/agent/test_ovs_flows.py b/neutron/tests/functional/agent/test_ovs_flows.py index d2854dc36b5..f92434e8003 100644 --- a/neutron/tests/functional/agent/test_ovs_flows.py +++ b/neutron/tests/functional/agent/test_ovs_flows.py @@ -18,6 +18,7 @@ import fixtures import mock import testscenarios +from neutron_lib import constants as n_const from oslo_config import cfg from oslo_serialization import jsonutils from oslo_utils import importutils @@ -26,7 +27,6 @@ from testtools.content import text_content from neutron.agent.common import utils from neutron.agent.linux import ip_lib from neutron.cmd.sanity import checks -from neutron.common import constants as n_const from neutron.plugins.ml2.drivers.openvswitch.agent.common import constants from neutron.plugins.ml2.drivers.openvswitch.agent \ import ovs_neutron_agent as ovsagt diff --git a/neutron/tests/functional/cmd/test_linuxbridge_cleanup.py b/neutron/tests/functional/cmd/test_linuxbridge_cleanup.py index 74af2bc2187..4d7c9b4b2d2 100644 --- a/neutron/tests/functional/cmd/test_linuxbridge_cleanup.py +++ b/neutron/tests/functional/cmd/test_linuxbridge_cleanup.py @@ -15,9 +15,9 @@ import fixtures import mock +from neutron_lib import constants from neutron.agent.linux import ip_lib -from neutron.common import constants from neutron.plugins.ml2.drivers.linuxbridge.agent import \ linuxbridge_neutron_agent as lb_agent from neutron.tests.common import config_fixtures diff --git a/neutron/tests/functional/db/test_ipam.py b/neutron/tests/functional/db/test_ipam.py index 5ea2ea7e9e8..308e3bfb77e 100644 --- a/neutron/tests/functional/db/test_ipam.py +++ b/neutron/tests/functional/db/test_ipam.py @@ -13,13 +13,12 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from neutron_lib import exceptions as n_exc from oslo_config import cfg from oslo_db.sqlalchemy import session import testtools -from neutron.api.v2 import attributes -from neutron.common import constants from neutron import context from neutron.db import db_base_plugin_v2 as base_plugin from neutron.db import model_base @@ -120,19 +119,19 @@ class IpamTestCase(object): 'enable_dhcp': False, 'gateway_ip': '10.10.10.1', 'shared': False, - 'allocation_pools': attributes.ATTR_NOT_SPECIFIED, - 'dns_nameservers': attributes.ATTR_NOT_SPECIFIED, - 'host_routes': attributes.ATTR_NOT_SPECIFIED} + 'allocation_pools': constants.ATTR_NOT_SPECIFIED, + 'dns_nameservers': constants.ATTR_NOT_SPECIFIED, + 'host_routes': constants.ATTR_NOT_SPECIFIED} return self.plugin.create_subnet(self.cxt, {'subnet': subnet}) def _create_port(self, port_id, fixed_ips=None): port_fixed_ips = (fixed_ips if fixed_ips else - attributes.ATTR_NOT_SPECIFIED) + constants.ATTR_NOT_SPECIFIED) port = {'tenant_id': self.tenant_id, 'name': 'test_port', 'id': port_id, 'network_id': self.network_id, - 'mac_address': attributes.ATTR_NOT_SPECIFIED, + 'mac_address': constants.ATTR_NOT_SPECIFIED, 'admin_state_up': True, 'status': constants.PORT_STATUS_ACTIVE, 'device_id': 'test_dev_id', diff --git a/neutron/tests/functional/pecan_wsgi/test_controllers.py b/neutron/tests/functional/pecan_wsgi/test_controllers.py index ece019a0297..4e0a14ca2e6 100644 --- a/neutron/tests/functional/pecan_wsgi/test_controllers.py +++ b/neutron/tests/functional/pecan_wsgi/test_controllers.py @@ -13,6 +13,7 @@ from collections import namedtuple import mock +from neutron_lib import constants as n_const from oslo_config import cfg from oslo_policy import policy as oslo_policy from oslo_serialization import jsonutils @@ -20,8 +21,6 @@ import pecan from pecan import request from neutron.api import extensions -from neutron.api.v2 import attributes -from neutron.common import constants as n_const from neutron import context from neutron import manager from neutron.pecan_wsgi.controllers import root as controllers @@ -251,7 +250,7 @@ class TestResourceController(TestRootController): self.port = self.plugin.create_port(context.get_admin_context(), { 'port': {'tenant_id': 'tenid', 'network_id': network_id, - 'fixed_ips': attributes.ATTR_NOT_SPECIFIED, + 'fixed_ips': n_const.ATTR_NOT_SPECIFIED, 'mac_address': '00:11:22:33:44:55', 'admin_state_up': True, 'device_id': 'FF', 'device_owner': 'pecan', 'name': 'pecan'}}) diff --git a/neutron/tests/functional/plugins/ml2/drivers/macvtap/agent/test_macvtap_neutron_agent.py b/neutron/tests/functional/plugins/ml2/drivers/macvtap/agent/test_macvtap_neutron_agent.py index 04825f9c6da..6e87a6f11d1 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/macvtap/agent/test_macvtap_neutron_agent.py +++ b/neutron/tests/functional/plugins/ml2/drivers/macvtap/agent/test_macvtap_neutron_agent.py @@ -14,7 +14,8 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron.common import constants +from neutron_lib import constants + from neutron.plugins.ml2.drivers.macvtap.agent import macvtap_neutron_agent from neutron.tests.common import net_helpers from neutron.tests.functional import base as functional_base diff --git a/neutron/tests/functional/plugins/ml2/test_plugin.py b/neutron/tests/functional/plugins/ml2/test_plugin.py index da94ab9ecfb..97c46a6f44d 100644 --- a/neutron/tests/functional/plugins/ml2/test_plugin.py +++ b/neutron/tests/functional/plugins/ml2/test_plugin.py @@ -13,7 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron.common import constants +from neutron_lib import constants + from neutron import context from neutron.db import agents_db from neutron.extensions import portbindings diff --git a/neutron/tests/functional/scheduler/test_dhcp_agent_scheduler.py b/neutron/tests/functional/scheduler/test_dhcp_agent_scheduler.py index 41eab24b119..784d8c08f16 100644 --- a/neutron/tests/functional/scheduler/test_dhcp_agent_scheduler.py +++ b/neutron/tests/functional/scheduler/test_dhcp_agent_scheduler.py @@ -16,10 +16,10 @@ import collections from operator import attrgetter +from neutron_lib import constants import six import testscenarios -from neutron.api.v2 import attributes from neutron import context from neutron.db import agents_db from neutron.db import agentschedulers_db @@ -600,10 +600,10 @@ class TestDHCPSchedulerWithNetworkAccessibility( 'ip_version': 4, 'network_id': net['id'], 'cidr': '10.0.0.0/24', - 'gateway_ip': attributes.ATTR_NOT_SPECIFIED, - 'allocation_pools': attributes.ATTR_NOT_SPECIFIED, - 'dns_nameservers': attributes.ATTR_NOT_SPECIFIED, - 'host_routes': attributes.ATTR_NOT_SPECIFIED, + 'gateway_ip': constants.ATTR_NOT_SPECIFIED, + 'allocation_pools': constants.ATTR_NOT_SPECIFIED, + 'dns_nameservers': constants.ATTR_NOT_SPECIFIED, + 'host_routes': constants.ATTR_NOT_SPECIFIED, 'tenant_id': 'tenant_one', 'enable_dhcp': True}}) diff --git a/neutron/tests/functional/services/l3_router/test_l3_dvr_ha_router_plugin.py b/neutron/tests/functional/services/l3_router/test_l3_dvr_ha_router_plugin.py index 834303e47fd..6db493e7305 100644 --- a/neutron/tests/functional/services/l3_router/test_l3_dvr_ha_router_plugin.py +++ b/neutron/tests/functional/services/l3_router/test_l3_dvr_ha_router_plugin.py @@ -13,8 +13,9 @@ # under the License. import mock +from neutron_lib import constants -from neutron.common import constants +from neutron.common import constants as n_const from neutron.common import topics from neutron.extensions import external_net from neutron.extensions import l3_ext_ha_mode @@ -31,7 +32,7 @@ class L3DvrHATestCase(test_l3_dvr_router_plugin.L3DvrTestCase): super(L3DvrHATestCase, self).setUp() self.l3_agent_2 = helpers.register_l3_agent( host="standby", - agent_mode=constants.L3_AGENT_MODE_DVR_SNAT) + agent_mode=n_const.L3_AGENT_MODE_DVR_SNAT) def test_update_router_db_cvr_to_dvrha(self): router = self._create_router(distributed=False, ha=False) @@ -131,7 +132,7 @@ class L3DvrHATestCase(test_l3_dvr_router_plugin.L3DvrTestCase): HOST1, HOST2, HOST3 = 'host1', 'host2', 'host3' for host in [HOST1, HOST2, HOST3]: helpers.register_l3_agent( - host=host, agent_mode=constants.L3_AGENT_MODE_DVR) + host=host, agent_mode=n_const.L3_AGENT_MODE_DVR) router = self._create_router(distributed=True, ha=True) arg_list = (portbindings.HOST_ID,) diff --git a/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py b/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py index 66a0371ce74..fe3d41c746f 100644 --- a/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py +++ b/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py @@ -13,10 +13,10 @@ # under the License. import mock +from neutron_lib import constants from neutron.api.rpc.handlers import l3_rpc -from neutron.api.v2 import attributes -from neutron.common import constants +from neutron.common import constants as n_const from neutron.common import topics from neutron import context from neutron.extensions import external_net @@ -32,7 +32,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): def setUp(self): super(L3DvrTestCase, self).setUp() self.l3_agent = helpers.register_l3_agent( - agent_mode=constants.L3_AGENT_MODE_DVR_SNAT) + agent_mode=n_const.L3_AGENT_MODE_DVR_SNAT) def _create_router(self, distributed=True, ha=False): return (super(L3DvrTestCase, self). @@ -129,8 +129,8 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): self.context, {'port': {'tenant_id': '', 'network_id': network_id, - 'mac_address': attributes.ATTR_NOT_SPECIFIED, - 'fixed_ips': attributes.ATTR_NOT_SPECIFIED, + 'mac_address': constants.ATTR_NOT_SPECIFIED, + 'fixed_ips': constants.ATTR_NOT_SPECIFIED, 'device_id': self.l3_agent['id'], 'device_owner': constants.DEVICE_OWNER_AGENT_GW, portbindings.HOST_ID: '', @@ -283,9 +283,9 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): {'port': {portbindings.HOST_ID: 'host2'}}) # and create l3 agents on corresponding hosts helpers.register_l3_agent(host='host1', - agent_mode=constants.L3_AGENT_MODE_DVR) + agent_mode=n_const.L3_AGENT_MODE_DVR) helpers.register_l3_agent(host='host2', - agent_mode=constants.L3_AGENT_MODE_DVR) + agent_mode=n_const.L3_AGENT_MODE_DVR) # make net external ext_net_id = ext_subnet['subnet']['network_id'] @@ -456,7 +456,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): def test_update_service_port_with_allowed_address_pairs(self): HOST1 = 'host1' helpers.register_l3_agent( - host=HOST1, agent_mode=constants.L3_AGENT_MODE_DVR) + host=HOST1, agent_mode=n_const.L3_AGENT_MODE_DVR) router = self._create_router() private_net1 = self._make_network(self.fmt, 'net1', True) test_allocation_pools = [{'start': '10.1.0.2', @@ -595,10 +595,10 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): # register l3 agents in dvr mode in addition to existing dvr_snat agent HOST1 = 'host1' helpers.register_l3_agent( - host=HOST1, agent_mode=constants.L3_AGENT_MODE_DVR) + host=HOST1, agent_mode=n_const.L3_AGENT_MODE_DVR) HOST2 = 'host2' helpers.register_l3_agent( - host=HOST2, agent_mode=constants.L3_AGENT_MODE_DVR) + host=HOST2, agent_mode=n_const.L3_AGENT_MODE_DVR) router = self._create_router() with self.subnet() as subnet: self.l3_plugin.add_router_interface( @@ -636,7 +636,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): HOST = 'host1' non_admin_tenant = 'tenant1' helpers.register_l3_agent( - host=HOST, agent_mode=constants.L3_AGENT_MODE_DVR) + host=HOST, agent_mode=n_const.L3_AGENT_MODE_DVR) router = self._create_router() with self.network(shared=True) as net,\ self.subnet(network=net) as subnet,\ @@ -682,7 +682,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): HOST1, HOST2 = 'host1', 'host2' for host in [HOST1, HOST2]: helpers.register_l3_agent( - host=host, agent_mode=constants.L3_AGENT_MODE_DVR) + host=host, agent_mode=n_const.L3_AGENT_MODE_DVR) router = self._create_router() arg_list = (portbindings.HOST_ID,) @@ -753,7 +753,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): HOST1, HOST2, HOST3 = 'host1', 'host2', 'host3' for host in [HOST1, HOST2, HOST3]: helpers.register_l3_agent( - host=host, agent_mode=constants.L3_AGENT_MODE_DVR) + host=host, agent_mode=n_const.L3_AGENT_MODE_DVR) router = self._create_router() arg_list = (portbindings.HOST_ID,) @@ -1094,7 +1094,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): def test_remove_router_interface(self): HOST1 = 'host1' helpers.register_l3_agent( - host=HOST1, agent_mode=constants.L3_AGENT_MODE_DVR) + host=HOST1, agent_mode=n_const.L3_AGENT_MODE_DVR) router = self._create_router() arg_list = (portbindings.HOST_ID,) with self.subnet() as subnet,\ diff --git a/neutron/tests/functional/tests/common/exclusive_resources/test_port.py b/neutron/tests/functional/tests/common/exclusive_resources/test_port.py index 98d2c9bac26..9d845b26b9f 100644 --- a/neutron/tests/functional/tests/common/exclusive_resources/test_port.py +++ b/neutron/tests/functional/tests/common/exclusive_resources/test_port.py @@ -12,7 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron.common import constants +from neutron_lib import constants + from neutron.tests import base from neutron.tests.common.exclusive_resources import port diff --git a/neutron/tests/unit/agent/dhcp/test_agent.py b/neutron/tests/unit/agent/dhcp/test_agent.py index 6a91862b497..ef83ac13507 100644 --- a/neutron/tests/unit/agent/dhcp/test_agent.py +++ b/neutron/tests/unit/agent/dhcp/test_agent.py @@ -20,6 +20,7 @@ import uuid import eventlet import mock +from neutron_lib import constants as const from neutron_lib import exceptions from oslo_config import cfg import oslo_messaging @@ -32,7 +33,7 @@ from neutron.agent import dhcp_agent as entry from neutron.agent.linux import dhcp from neutron.agent.linux import interface from neutron.common import config as common_config -from neutron.common import constants as const +from neutron.common import constants as n_const from neutron.common import utils from neutron import context from neutron.tests import base @@ -428,11 +429,11 @@ class TestDhcpAgent(base.BaseTestCase): with mock.patch.object(dhcp.state_rpc, 'report_state') as report_state,\ mock.patch.object(dhcp, "run"): - report_state.return_value = const.AGENT_ALIVE + report_state.return_value = n_const.AGENT_ALIVE dhcp._report_state() self.assertEqual({}, dhcp.needs_resync_reasons) - report_state.return_value = const.AGENT_REVIVED + report_state.return_value = n_const.AGENT_REVIVED dhcp._report_state() self.assertEqual(dhcp.needs_resync_reasons[None], ['Agent has just been revived']) diff --git a/neutron/tests/unit/agent/l3/test_agent.py b/neutron/tests/unit/agent/l3/test_agent.py index 9efa0b4142c..b1cb392d434 100644 --- a/neutron/tests/unit/agent/l3/test_agent.py +++ b/neutron/tests/unit/agent/l3/test_agent.py @@ -20,6 +20,7 @@ from itertools import combinations as iter_combinations import eventlet import mock import netaddr +from neutron_lib import constants as l3_constants from neutron_lib import exceptions as exc from oslo_log import log import oslo_messaging @@ -48,7 +49,7 @@ from neutron.agent.linux import ra from neutron.agent.metadata import driver as metadata_driver from neutron.agent import rpc as agent_rpc from neutron.common import config as base_config -from neutron.common import constants as l3_constants +from neutron.common import constants as n_const from neutron.common import exceptions as n_exc from neutron.extensions import portbindings from neutron.plugins.common import constants as p_const @@ -236,12 +237,12 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): 'report_state') as report_state: agent = l3_agent.L3NATAgentWithStateReport(host=HOSTNAME, conf=self.conf) - report_state.return_value = l3_constants.AGENT_REVIVED + report_state.return_value = n_const.AGENT_REVIVED agent._report_state() self.assertTrue(agent.fullsync) agent.fullsync = False - report_state.return_value = l3_constants.AGENT_ALIVE + report_state.return_value = n_const.AGENT_ALIVE agent._report_state() self.assertFalse(agent.fullsync) @@ -739,7 +740,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): '-o %s -j SNAT --to-source %s' % (interface_name, source_nat_ip), '-m mark ! --mark 0x2/%s -m conntrack --ctstate DNAT ' '-j SNAT --to-source %s' % - (l3_constants.ROUTER_MARK_MASK, source_nat_ip)] + (n_const.ROUTER_MARK_MASK, source_nat_ip)] for r in nat_rules: if negate: self.assertNotIn(r.rule, expected_rules) @@ -747,7 +748,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): self.assertIn(r.rule, expected_rules) expected_rules = [ '-i %s -j MARK --set-xmark 0x2/%s' % - (interface_name, l3_constants.ROUTER_MARK_MASK), + (interface_name, n_const.ROUTER_MARK_MASK), '-o %s -m connmark --mark 0x0/%s -j CONNMARK ' '--save-mark --nfmask %s --ctmask %s' % (interface_name, @@ -926,7 +927,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): router = l3_test_common.prepare_router_data(enable_snat=True) router[l3_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] - router[l3_constants.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port + router[n_const.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port router['distributed'] = True agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) ri = dvr_router.DvrEdgeRouter( @@ -993,7 +994,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): router = l3_test_common.prepare_router_data(enable_snat=True) router[l3_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] - router[l3_constants.FLOATINGIP_AGENT_INTF_KEY] = [] + router[n_const.FLOATINGIP_AGENT_INTF_KEY] = [] router['distributed'] = True agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) ri = dvr_router.DvrEdgeRouter( @@ -1038,7 +1039,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): router = l3_test_common.prepare_router_data(enable_snat=True) router[l3_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] - router[l3_constants.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port + router[n_const.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port router['distributed'] = True agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) ri = dvr_router.DvrEdgeRouter( @@ -1090,7 +1091,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): router = l3_test_common.prepare_router_data(enable_snat=True) router[l3_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] - router[l3_constants.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port + router[n_const.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port router['distributed'] = True agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) ri = dvr_router.DvrEdgeRouter( @@ -1352,7 +1353,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): def test_process_router_ipv6_slaac_interface_added(self): router = l3_test_common.prepare_router_data() ri = self._process_router_ipv6_interface_added( - router, ra_mode=l3_constants.IPV6_SLAAC) + router, ra_mode=n_const.IPV6_SLAAC) self._assert_ri_process_enabled(ri) # Expect radvd configured with prefix radvd_config_str = self.utils_replace_file.call_args[0][1] @@ -1362,7 +1363,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): def test_process_router_ipv6_dhcpv6_stateful_interface_added(self): router = l3_test_common.prepare_router_data() ri = self._process_router_ipv6_interface_added( - router, ra_mode=l3_constants.DHCPV6_STATEFUL) + router, ra_mode=n_const.DHCPV6_STATEFUL) self._assert_ri_process_enabled(ri) # Expect radvd configured with prefix radvd_config_str = self.utils_replace_file.call_args[0][1] @@ -1372,12 +1373,12 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): def test_process_router_ipv6_subnets_added(self): router = l3_test_common.prepare_router_data() ri = self._process_router_ipv6_subnet_added(router, ipv6_subnet_modes=[ - {'ra_mode': l3_constants.IPV6_SLAAC, - 'address_mode': l3_constants.IPV6_SLAAC}, - {'ra_mode': l3_constants.DHCPV6_STATELESS, - 'address_mode': l3_constants.DHCPV6_STATELESS}, - {'ra_mode': l3_constants.DHCPV6_STATEFUL, - 'address_mode': l3_constants.DHCPV6_STATEFUL}]) + {'ra_mode': n_const.IPV6_SLAAC, + 'address_mode': n_const.IPV6_SLAAC}, + {'ra_mode': n_const.DHCPV6_STATELESS, + 'address_mode': n_const.DHCPV6_STATELESS}, + {'ra_mode': n_const.DHCPV6_STATEFUL, + 'address_mode': n_const.DHCPV6_STATEFUL}]) self._assert_ri_process_enabled(ri) radvd_config_str = self.utils_replace_file.call_args[0][1] # Assert we have a prefix from IPV6_SLAAC and a prefix from @@ -1397,8 +1398,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): l3_test_common.router_append_subnet( router, count=1, ip_version=6, ipv6_subnet_modes=[ - {'ra_mode': l3_constants.IPV6_SLAAC, - 'address_mode': l3_constants.IPV6_SLAAC}]) + {'ra_mode': n_const.IPV6_SLAAC, + 'address_mode': n_const.IPV6_SLAAC}]) self._process_router_instance_for_agent(agent, ri, router) self._assert_ri_process_enabled(ri) radvd_config = self.utils_replace_file.call_args[0][1].split() @@ -1416,8 +1417,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): router, count=1, ip_version=6, ipv6_subnet_modes=[ - {'ra_mode': l3_constants.IPV6_SLAAC, - 'address_mode': l3_constants.IPV6_SLAAC}], + {'ra_mode': n_const.IPV6_SLAAC, + 'address_mode': n_const.IPV6_SLAAC}], interface_id=interface_id) self._process_router_instance_for_agent(agent, ri, router) # radvd should have been enabled again and the interface @@ -1485,8 +1486,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): # Add an IPv6 interface with two subnets and reprocess l3_test_common.router_append_subnet( router, count=2, ip_version=6, - ipv6_subnet_modes=([{'ra_mode': l3_constants.IPV6_SLAAC, - 'address_mode': l3_constants.IPV6_SLAAC}] + ipv6_subnet_modes=([{'ra_mode': n_const.IPV6_SLAAC, + 'address_mode': n_const.IPV6_SLAAC}] * 2)) self._process_router_instance_for_agent(agent, ri, router) self._assert_ri_process_enabled(ri) @@ -1742,7 +1743,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): snat_rule2 = ("-A %s-snat -m mark ! --mark 0x2/%s " "-m conntrack --ctstate DNAT " "-j SNAT --to-source %s") % ( - wrap_name, l3_constants.ROUTER_MARK_MASK, + wrap_name, n_const.ROUTER_MARK_MASK, ex_gw_port['fixed_ips'][0]['ip_address']) self.assertIn(jump_float_rule, nat_rules) @@ -1755,7 +1756,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): mangle_rules = list(map(str, ri.iptables_manager.ipv4['mangle'].rules)) mangle_rule = ("-A %s-mark -i iface " "-j MARK --set-xmark 0x2/%s" % - (wrap_name, l3_constants.ROUTER_MARK_MASK)) + (wrap_name, n_const.ROUTER_MARK_MASK)) self.assertIn(mangle_rule, mangle_rules) def test_process_router_delete_stale_internal_devices(self): @@ -2331,8 +2332,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): def test_generate_radvd_mtu_conf(self): router = l3_test_common.prepare_router_data() - ipv6_subnet_modes = [{'ra_mode': l3_constants.IPV6_SLAAC, - 'address_mode': l3_constants.IPV6_SLAAC}] + ipv6_subnet_modes = [{'ra_mode': n_const.IPV6_SLAAC, + 'address_mode': n_const.IPV6_SLAAC}] network_mtu = '1446' ri = self._process_router_ipv6_subnet_added(router, ipv6_subnet_modes, @@ -2350,12 +2351,12 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): def test_generate_radvd_conf_other_and_managed_flag(self): # expected = {ra_mode: (AdvOtherConfigFlag, AdvManagedFlag), ...} - expected = {l3_constants.IPV6_SLAAC: (False, False), - l3_constants.DHCPV6_STATELESS: (True, False), - l3_constants.DHCPV6_STATEFUL: (False, True)} + expected = {n_const.IPV6_SLAAC: (False, False), + n_const.DHCPV6_STATELESS: (True, False), + n_const.DHCPV6_STATEFUL: (False, True)} - modes = [l3_constants.IPV6_SLAAC, l3_constants.DHCPV6_STATELESS, - l3_constants.DHCPV6_STATEFUL] + modes = [n_const.IPV6_SLAAC, n_const.DHCPV6_STATELESS, + n_const.DHCPV6_STATEFUL] mode_combos = list(iter_chain(*[[list(combo) for combo in iter_combinations(modes, i)] for i in range(1, len(modes) + 1)])) @@ -2384,8 +2385,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): self.conf.set_override('min_rtr_adv_interval', 22) self.conf.set_override('max_rtr_adv_interval', 66) router = l3_test_common.prepare_router_data() - ipv6_subnet_modes = [{'ra_mode': l3_constants.IPV6_SLAAC, - 'address_mode': l3_constants.IPV6_SLAAC}] + ipv6_subnet_modes = [{'ra_mode': n_const.IPV6_SLAAC, + 'address_mode': n_const.IPV6_SLAAC}] ri = self._process_router_ipv6_subnet_added(router, ipv6_subnet_modes) ri.radvd._generate_radvd_conf(router[l3_constants.INTERFACE_KEY]) @@ -2396,8 +2397,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): def test_generate_radvd_rdnss_conf(self): router = l3_test_common.prepare_router_data() - ipv6_subnet_modes = [{'ra_mode': l3_constants.IPV6_SLAAC, - 'address_mode': l3_constants.IPV6_SLAAC}] + ipv6_subnet_modes = [{'ra_mode': n_const.IPV6_SLAAC, + 'address_mode': n_const.IPV6_SLAAC}] dns_list = ['fd01:1::100', 'fd01:1::200', 'fd01::300', 'fd01::400'] ri = self._process_router_ipv6_subnet_added(router, ipv6_subnet_modes, @@ -2454,7 +2455,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): requestor_id, ri, False)) for subnet in intf['subnets']: expected_pd_update[subnet['id']] = ( - l3_constants.PROVISIONAL_IPV6_PD_PREFIX) + n_const.PROVISIONAL_IPV6_PD_PREFIX) # Implement the prefix update notifier # Keep track of the updated prefix @@ -2489,7 +2490,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): requestor_id, ri, False)) for subnet in intf['subnets']: expected_pd_update += [{subnet['id']: - l3_constants.PROVISIONAL_IPV6_PD_PREFIX}] + n_const.PROVISIONAL_IPV6_PD_PREFIX}] # Implement the prefix update notifier # Keep track of the updated prefix diff --git a/neutron/tests/unit/agent/l3/test_dvr_local_router.py b/neutron/tests/unit/agent/l3/test_dvr_local_router.py index dc7d4785ce3..a75f814b514 100644 --- a/neutron/tests/unit/agent/l3/test_dvr_local_router.py +++ b/neutron/tests/unit/agent/l3/test_dvr_local_router.py @@ -14,6 +14,7 @@ import mock import netaddr +from neutron_lib import constants as l3_constants from oslo_log import log from oslo_utils import uuidutils @@ -28,7 +29,7 @@ from neutron.agent.linux import external_process from neutron.agent.linux import interface from neutron.agent.linux import ip_lib from neutron.common import config as base_config -from neutron.common import constants as l3_constants +from neutron.common import constants as n_const from neutron.common import utils as common_utils from neutron.extensions import portbindings from neutron.tests import base @@ -506,7 +507,7 @@ class TestDvrRouterOperations(base.BaseTestCase): ) router = l3_test_common.prepare_router_data(enable_snat=True) - router[l3_constants.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port + router[n_const.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port router['distributed'] = True agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) ri = dvr_router.DvrLocalRouter( diff --git a/neutron/tests/unit/agent/l3/test_legacy_router.py b/neutron/tests/unit/agent/l3/test_legacy_router.py index c9bf570ca21..4a6dff8e74a 100644 --- a/neutron/tests/unit/agent/l3/test_legacy_router.py +++ b/neutron/tests/unit/agent/l3/test_legacy_router.py @@ -13,11 +13,11 @@ # under the License. import mock +from neutron_lib import constants as l3_constants from oslo_utils import uuidutils from neutron.agent.l3 import legacy_router from neutron.agent.linux import ip_lib -from neutron.common import constants as l3_constants from neutron.tests import base _uuid = uuidutils.generate_uuid diff --git a/neutron/tests/unit/agent/l3/test_router_info.py b/neutron/tests/unit/agent/l3/test_router_info.py index 35c1f247ac5..bff7fca3f25 100644 --- a/neutron/tests/unit/agent/l3/test_router_info.py +++ b/neutron/tests/unit/agent/l3/test_router_info.py @@ -11,12 +11,12 @@ # under the License. import mock +from neutron_lib import constants as l3_constants from oslo_utils import uuidutils from neutron.agent.common import config as agent_config from neutron.agent.l3 import router_info from neutron.agent.linux import ip_lib -from neutron.common import constants as l3_constants from neutron.common import exceptions as n_exc from neutron.tests import base diff --git a/neutron/tests/unit/agent/linux/openvswitch_firewall/test_firewall.py b/neutron/tests/unit/agent/linux/openvswitch_firewall/test_firewall.py index f7e67162afd..85bdfd0dd32 100644 --- a/neutron/tests/unit/agent/linux/openvswitch_firewall/test_firewall.py +++ b/neutron/tests/unit/agent/linux/openvswitch_firewall/test_firewall.py @@ -13,13 +13,14 @@ # under the License. import mock +from neutron_lib import constants import testtools from neutron.agent.common import ovs_lib from neutron.agent import firewall from neutron.agent.linux.openvswitch_firewall import constants as ovsfw_consts from neutron.agent.linux.openvswitch_firewall import firewall as ovsfw -from neutron.common import constants +from neutron.common import constants as n_const from neutron.plugins.ml2.drivers.openvswitch.agent.common import constants \ as ovs_consts from neutron.tests import base @@ -377,7 +378,7 @@ class TestOVSFirewallDriver(base.BaseTestCase): actions='ct(commit,zone=NXM_NX_REG6[0..15]),' 'strip_vlan,output:{:d}'.format(self.port_ofport), dl_dst=self.port_mac, - dl_type="0x{:04x}".format(constants.ETHERTYPE_IP), + dl_type="0x{:04x}".format(n_const.ETHERTYPE_IP), nw_proto=constants.PROTO_NUM_TCP, priority=70, reg5=self.port_ofport, @@ -420,7 +421,7 @@ class TestOVSFirewallDriver(base.BaseTestCase): actions='resubmit(,{:d})'.format( ovs_consts.ACCEPT_OR_INGRESS_TABLE), dl_src=self.port_mac, - dl_type="0x{:04x}".format(constants.ETHERTYPE_IP), + dl_type="0x{:04x}".format(n_const.ETHERTYPE_IP), nw_proto=constants.PROTO_NUM_UDP, priority=70, ct_state=ovsfw_consts.OF_STATE_NEW_NOT_ESTABLISHED, diff --git a/neutron/tests/unit/agent/linux/openvswitch_firewall/test_rules.py b/neutron/tests/unit/agent/linux/openvswitch_firewall/test_rules.py index bab030c7134..637b0a1e127 100644 --- a/neutron/tests/unit/agent/linux/openvswitch_firewall/test_rules.py +++ b/neutron/tests/unit/agent/linux/openvswitch_firewall/test_rules.py @@ -13,11 +13,12 @@ # under the License. import mock +from neutron_lib import constants from neutron.agent import firewall from neutron.agent.linux.openvswitch_firewall import firewall as ovsfw from neutron.agent.linux.openvswitch_firewall import rules -from neutron.common import constants +from neutron.common import constants as n_const from neutron.plugins.ml2.drivers.openvswitch.agent.common import constants \ as ovs_consts from neutron.tests import base @@ -76,7 +77,7 @@ class TestCreateFlowsFromRuleAndPort(base.BaseTestCase): } expected_template = { 'priority': 70, - 'dl_type': constants.ETHERTYPE_IP, + 'dl_type': n_const.ETHERTYPE_IP, 'reg_port': self.port.ofport, } self._test_create_flows_from_rule_and_port_helper(rule, @@ -91,7 +92,7 @@ class TestCreateFlowsFromRuleAndPort(base.BaseTestCase): } expected_template = { 'priority': 70, - 'dl_type': constants.ETHERTYPE_IP, + 'dl_type': n_const.ETHERTYPE_IP, 'reg_port': self.port.ofport, 'nw_src': '192.168.0.0/24', 'nw_dst': '10.0.0.1/32', @@ -108,7 +109,7 @@ class TestCreateFlowsFromRuleAndPort(base.BaseTestCase): } expected_template = { 'priority': 70, - 'dl_type': constants.ETHERTYPE_IP, + 'dl_type': n_const.ETHERTYPE_IP, 'reg_port': self.port.ofport, 'nw_src': '192.168.0.0/24', } @@ -122,7 +123,7 @@ class TestCreateFlowsFromRuleAndPort(base.BaseTestCase): } expected_template = { 'priority': 70, - 'dl_type': constants.ETHERTYPE_IPV6, + 'dl_type': n_const.ETHERTYPE_IPV6, 'reg_port': self.port.ofport, } self._test_create_flows_from_rule_and_port_helper(rule, @@ -137,7 +138,7 @@ class TestCreateFlowsFromRuleAndPort(base.BaseTestCase): } expected_template = { 'priority': 70, - 'dl_type': constants.ETHERTYPE_IPV6, + 'dl_type': n_const.ETHERTYPE_IPV6, 'reg_port': self.port.ofport, 'ipv6_src': '2001:db8:bbbb::1/64', 'ipv6_dst': '2001:db8:aaaa::1/64', @@ -154,7 +155,7 @@ class TestCreateFlowsFromRuleAndPort(base.BaseTestCase): } expected_template = { 'priority': 70, - 'dl_type': constants.ETHERTYPE_IPV6, + 'dl_type': n_const.ETHERTYPE_IPV6, 'reg_port': self.port.ofport, 'ipv6_src': '2001:db8:bbbb::1/64', } diff --git a/neutron/tests/unit/agent/linux/test_dhcp.py b/neutron/tests/unit/agent/linux/test_dhcp.py index 58db0c99447..758f4745036 100644 --- a/neutron/tests/unit/agent/linux/test_dhcp.py +++ b/neutron/tests/unit/agent/linux/test_dhcp.py @@ -17,6 +17,7 @@ import os import mock import netaddr +from neutron_lib import constants from oslo_config import cfg from neutron.agent.common import config @@ -24,7 +25,7 @@ from neutron.agent.dhcp import config as dhcp_config from neutron.agent.linux import dhcp from neutron.agent.linux import external_process from neutron.common import config as base_config -from neutron.common import constants +from neutron.common import constants as n_const from neutron.common import utils from neutron.extensions import extra_dhcp_opt as edo_ext from neutron.tests import base @@ -87,7 +88,7 @@ class FakeReservedPort(object): FakeIPAllocation('192.168.0.6', 'dddddddd-dddd-dddd-dddd-dddddddddddd')] self.mac_address = '00:00:80:aa:bb:ee' - self.device_id = constants.DEVICE_ID_RESERVED_DHCP_PORT + self.device_id = n_const.DEVICE_ID_RESERVED_DHCP_PORT self.extra_dhcp_opts = [] self.id = id @@ -464,7 +465,7 @@ class FakeV6SubnetDHCPStateful(Dictable): self.host_routes = [FakeV6HostRoute()] self.dns_nameservers = ['2001:0200:feed:7ac0::1'] self.ipv6_ra_mode = None - self.ipv6_address_mode = constants.DHCPV6_STATEFUL + self.ipv6_address_mode = n_const.DHCPV6_STATEFUL class FakeV6SubnetSlaac(object): @@ -475,7 +476,7 @@ class FakeV6SubnetSlaac(object): self.gateway_ip = 'ffda:3ba5:a17a:4ba3::1' self.enable_dhcp = True self.host_routes = [FakeV6HostRoute()] - self.ipv6_address_mode = constants.IPV6_SLAAC + self.ipv6_address_mode = n_const.IPV6_SLAAC self.ipv6_ra_mode = None @@ -488,7 +489,7 @@ class FakeV6SubnetStateless(object): self.enable_dhcp = True self.dns_nameservers = [] self.host_routes = [] - self.ipv6_address_mode = constants.DHCPV6_STATELESS + self.ipv6_address_mode = n_const.DHCPV6_STATELESS self.ipv6_ra_mode = None @@ -1063,7 +1064,7 @@ class TestDnsmasq(TestBase): possible_leases = 0 for i, s in enumerate(network.subnets): if (s.ip_version != 6 - or s.ipv6_address_mode == constants.DHCPV6_STATEFUL): + or s.ipv6_address_mode == n_const.DHCPV6_STATEFUL): if s.ip_version == 4: expected.extend([prefix % ( i, s.cidr.split('/')[0], lease_duration, seconds)]) diff --git a/neutron/tests/unit/agent/linux/test_interface.py b/neutron/tests/unit/agent/linux/test_interface.py index 0f56c5b289f..e8c262337a1 100644 --- a/neutron/tests/unit/agent/linux/test_interface.py +++ b/neutron/tests/unit/agent/linux/test_interface.py @@ -14,6 +14,7 @@ # under the License. import mock +from neutron_lib import constants from oslo_log import versionutils import testtools @@ -22,7 +23,6 @@ from neutron.agent.common import ovs_lib from neutron.agent.linux import interface from neutron.agent.linux import ip_lib from neutron.agent.linux import utils -from neutron.common import constants from neutron.tests import base diff --git a/neutron/tests/unit/agent/linux/test_iptables_firewall.py b/neutron/tests/unit/agent/linux/test_iptables_firewall.py index 7700d266eb9..37630d668af 100644 --- a/neutron/tests/unit/agent/linux/test_iptables_firewall.py +++ b/neutron/tests/unit/agent/linux/test_iptables_firewall.py @@ -16,6 +16,7 @@ import copy import mock +from neutron_lib import constants from oslo_config import cfg import six import testtools @@ -25,7 +26,6 @@ from neutron.agent.linux import ipset_manager from neutron.agent.linux import iptables_comments as ic from neutron.agent.linux import iptables_firewall from neutron.agent import securitygroups_rpc as sg_cfg -from neutron.common import constants from neutron.common import exceptions as n_exc from neutron.common import utils from neutron.tests import base diff --git a/neutron/tests/unit/agent/linux/test_keepalived.py b/neutron/tests/unit/agent/linux/test_keepalived.py index b29b1f64906..7a912053418 100644 --- a/neutron/tests/unit/agent/linux/test_keepalived.py +++ b/neutron/tests/unit/agent/linux/test_keepalived.py @@ -12,10 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants as n_consts import testtools from neutron.agent.linux import keepalived -from neutron.common import constants as n_consts from neutron.tests import base # Keepalived user guide: diff --git a/neutron/tests/unit/agent/metadata/test_agent.py b/neutron/tests/unit/agent/metadata/test_agent.py index 287aa8ee584..c9fc5704f3b 100644 --- a/neutron/tests/unit/agent/metadata/test_agent.py +++ b/neutron/tests/unit/agent/metadata/test_agent.py @@ -13,6 +13,7 @@ # under the License. import mock +from neutron_lib import constants as n_const import testtools import webob @@ -20,7 +21,6 @@ from neutron.agent.linux import utils as agent_utils from neutron.agent.metadata import agent from neutron.agent.metadata import config from neutron.agent import metadata_agent -from neutron.common import constants as n_const from neutron.common import utils from neutron.tests import base diff --git a/neutron/tests/unit/agent/test_securitygroups_rpc.py b/neutron/tests/unit/agent/test_securitygroups_rpc.py index 3cdc1abadf0..8ea5bdb37ce 100644 --- a/neutron/tests/unit/agent/test_securitygroups_rpc.py +++ b/neutron/tests/unit/agent/test_securitygroups_rpc.py @@ -17,6 +17,7 @@ import collections import contextlib import mock +from neutron_lib import constants as const from oslo_config import cfg import oslo_messaging from testtools import matchers @@ -26,7 +27,7 @@ from neutron.agent import firewall as firewall_base from neutron.agent.linux import iptables_manager from neutron.agent import securitygroups_rpc as sg_rpc from neutron.api.rpc.handlers import securitygroups_rpc -from neutron.common import constants as const +from neutron.common import constants as n_const from neutron.common import ipv6_utils as ipv6 from neutron.common import rpc as n_rpc from neutron import context @@ -578,7 +579,7 @@ class SGServerRpcCallBackTestCase(test_sg.SecurityGroupDBTestCase): dhcp_rest = self.deserialize(self.fmt, dhcp_port) dhcp_mac = dhcp_rest['port']['mac_address'] dhcp_lla_ip = str(ipv6.get_ipv6_addr_by_EUI64( - const.IPV6_LLA_PREFIX, + n_const.IPV6_LLA_PREFIX, dhcp_mac)) res1 = self._create_port( @@ -680,7 +681,7 @@ class SGServerRpcCallBackTestCase(test_sg.SecurityGroupDBTestCase): with self.network() as n,\ self.subnet(n, gateway_ip=fake_gateway, cidr=fake_prefix, ip_version=6, - ipv6_ra_mode=const.IPV6_SLAAC + ipv6_ra_mode=n_const.IPV6_SLAAC ) as subnet_v6,\ self.security_group() as sg1: sg1_id = sg1['security_group']['id'] @@ -702,7 +703,7 @@ class SGServerRpcCallBackTestCase(test_sg.SecurityGroupDBTestCase): gateway_mac = gateway_res['port']['mac_address'] gateway_port_id = gateway_res['port']['id'] gateway_lla_ip = str(ipv6.get_ipv6_addr_by_EUI64( - const.IPV6_LLA_PREFIX, + n_const.IPV6_LLA_PREFIX, gateway_mac)) ports_rest1 = self._make_port( @@ -748,7 +749,7 @@ class SGServerRpcCallBackTestCase(test_sg.SecurityGroupDBTestCase): with self.network() as n,\ self.subnet(n, gateway_ip=fake_gateway, cidr=fake_prefix, ip_version=6, - ipv6_ra_mode=const.IPV6_SLAAC + ipv6_ra_mode=n_const.IPV6_SLAAC ) as subnet_v6,\ self.security_group() as sg1: sg1_id = sg1['security_group']['id'] @@ -770,7 +771,7 @@ class SGServerRpcCallBackTestCase(test_sg.SecurityGroupDBTestCase): gateway_mac = gateway_res['port']['mac_address'] gateway_port_id = gateway_res['port']['id'] gateway_lla_ip = str(ipv6.get_ipv6_addr_by_EUI64( - const.IPV6_LLA_PREFIX, + n_const.IPV6_LLA_PREFIX, gateway_mac)) # Create another router interface port interface_res = self._make_port( @@ -823,7 +824,7 @@ class SGServerRpcCallBackTestCase(test_sg.SecurityGroupDBTestCase): with self.network() as n,\ self.subnet(n, gateway_ip=fake_gateway, cidr=fake_prefix, ip_version=6, - ipv6_ra_mode=const.IPV6_SLAAC + ipv6_ra_mode=n_const.IPV6_SLAAC ) as subnet_v6,\ self.security_group() as sg1: sg1_id = sg1['security_group']['id'] @@ -845,7 +846,7 @@ class SGServerRpcCallBackTestCase(test_sg.SecurityGroupDBTestCase): gateway_mac = gateway_res['port']['mac_address'] gateway_port_id = gateway_res['port']['id'] gateway_lla_ip = str(ipv6.get_ipv6_addr_by_EUI64( - const.IPV6_LLA_PREFIX, + n_const.IPV6_LLA_PREFIX, gateway_mac)) ports_rest1 = self._make_port( @@ -891,7 +892,7 @@ class SGServerRpcCallBackTestCase(test_sg.SecurityGroupDBTestCase): with self.network() as n,\ self.subnet(n, gateway_ip=fake_gateway, cidr=fake_prefix, ip_version=6, - ipv6_ra_mode=const.IPV6_SLAAC + ipv6_ra_mode=n_const.IPV6_SLAAC ) as subnet_v6,\ self.security_group() as sg1: sg1_id = sg1['security_group']['id'] @@ -939,7 +940,7 @@ class SGServerRpcCallBackTestCase(test_sg.SecurityGroupDBTestCase): fake_prefix = FAKE_PREFIX[const.IPv6] with self.network() as n,\ self.subnet(n, gateway_ip=None, cidr=fake_prefix, - ip_version=6, ipv6_ra_mode=const.IPV6_SLAAC + ip_version=6, ipv6_ra_mode=n_const.IPV6_SLAAC ) as subnet_v6,\ self.security_group() as sg1: sg1_id = sg1['security_group']['id'] diff --git a/neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py b/neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py index a9e3de0668f..17ef1d8c130 100644 --- a/neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py +++ b/neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py @@ -14,11 +14,12 @@ # limitations under the License. import mock +from neutron_lib import constants from neutron_lib import exceptions as n_exc from oslo_db import exception as db_exc from neutron.api.rpc.handlers import dhcp_rpc -from neutron.common import constants +from neutron.common import constants as n_const from neutron.common import exceptions from neutron.common import utils from neutron.extensions import portbindings @@ -181,7 +182,7 @@ class TestDhcpRpcCallback(base.BaseTestCase): self.assertEqual(expected_port, port) self.plugin.get_port.return_value = { - 'device_id': constants.DEVICE_ID_RESERVED_DHCP_PORT} + 'device_id': n_const.DEVICE_ID_RESERVED_DHCP_PORT} self.callbacks._port_action = _fake_port_action self.callbacks.update_dhcp_port(mock.Mock(), host='foo_host', @@ -233,7 +234,7 @@ class TestDhcpRpcCallback(base.BaseTestCase): 'id': 'foo_port_id' } self.plugin.get_port.return_value = { - 'device_id': constants.DEVICE_ID_RESERVED_DHCP_PORT} + 'device_id': n_const.DEVICE_ID_RESERVED_DHCP_PORT} self.callbacks.update_dhcp_port(mock.Mock(), host='foo_host', port_id='foo_port_id', diff --git a/neutron/tests/unit/api/v2/test_attributes.py b/neutron/tests/unit/api/v2/test_attributes.py index 17947527e8c..29bca694ae5 100644 --- a/neutron/tests/unit/api/v2/test_attributes.py +++ b/neutron/tests/unit/api/v2/test_attributes.py @@ -17,6 +17,7 @@ import string import mock import netaddr +from neutron_lib import constants from neutron_lib import exceptions as n_exc from oslo_utils import uuidutils import testtools @@ -24,7 +25,6 @@ import webob.exc from neutron._i18n import _ from neutron.api.v2 import attributes -from neutron.common import constants from neutron import context from neutron.tests import base from neutron.tests import tools @@ -51,7 +51,7 @@ class TestAttributes(base.BaseTestCase): return dictionary, constraints def test_is_attr_set(self): - data = attributes.ATTR_NOT_SPECIFIED + data = constants.ATTR_NOT_SPECIFIED self.assertIs(attributes.is_attr_set(data), False) data = None @@ -444,11 +444,11 @@ class TestAttributes(base.BaseTestCase): def test_uuid_pattern(self): data = 'garbage' - msg = attributes._validate_regex(data, attributes.UUID_PATTERN) + msg = attributes._validate_regex(data, constants.UUID_PATTERN) self.assertIsNotNone(msg) data = '00000000-ffff-ffff-ffff-000000000000' - msg = attributes._validate_regex(data, attributes.UUID_PATTERN) + msg = attributes._validate_regex(data, constants.UUID_PATTERN) self.assertIsNone(msg) def test_mac_pattern(self): @@ -940,12 +940,12 @@ class TestResDict(base.BaseTestCase): attr_info = { 'key': { 'allow_post': True, - 'default': attributes.ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, }, } self._test_fill_default_value(attr_info, {'key': 'X'}, {'key': 'X'}) self._test_fill_default_value( - attr_info, {'key': attributes.ATTR_NOT_SPECIFIED}, {}) + attr_info, {'key': constants.ATTR_NOT_SPECIFIED}, {}) attr_info = { 'key': { @@ -978,8 +978,8 @@ class TestResDict(base.BaseTestCase): }, } self._test_convert_value(attr_info, - {'key': attributes.ATTR_NOT_SPECIFIED}, - {'key': attributes.ATTR_NOT_SPECIFIED}) + {'key': constants.ATTR_NOT_SPECIFIED}, + {'key': constants.ATTR_NOT_SPECIFIED}) self._test_convert_value(attr_info, {'key': 'X'}, {'key': 'X'}) self._test_convert_value(attr_info, {'other_key': 'X'}, {'other_key': 'X'}) @@ -990,8 +990,8 @@ class TestResDict(base.BaseTestCase): }, } self._test_convert_value(attr_info, - {'key': attributes.ATTR_NOT_SPECIFIED}, - {'key': attributes.ATTR_NOT_SPECIFIED}) + {'key': constants.ATTR_NOT_SPECIFIED}, + {'key': constants.ATTR_NOT_SPECIFIED}) self._test_convert_value(attr_info, {'key': 1}, {'key': '1'}) self._test_convert_value(attr_info, {'key': 1}, {'key': 1}) self.assertRaises(n_exc.InvalidInput, self._test_convert_value, @@ -1003,8 +1003,8 @@ class TestResDict(base.BaseTestCase): }, } self._test_convert_value(attr_info, - {'key': attributes.ATTR_NOT_SPECIFIED}, - {'key': attributes.ATTR_NOT_SPECIFIED}) + {'key': constants.ATTR_NOT_SPECIFIED}, + {'key': constants.ATTR_NOT_SPECIFIED}) uuid_str = '01234567-1234-1234-1234-1234567890ab' self._test_convert_value(attr_info, {'key': uuid_str}, {'key': uuid_str}) diff --git a/neutron/tests/unit/api/v2/test_base.py b/neutron/tests/unit/api/v2/test_base.py index 0bf54bd4c3c..461922caf9c 100644 --- a/neutron/tests/unit/api/v2/test_base.py +++ b/neutron/tests/unit/api/v2/test_base.py @@ -16,6 +16,7 @@ import os import mock +from neutron_lib import constants from neutron_lib import exceptions as n_exc from oslo_config import cfg from oslo_db import exception as db_exc @@ -920,8 +921,8 @@ class JSONV2TestCase(APIv2TestBase, testlib_api.WebTestCase): 'device_id': device_id, 'admin_state_up': True}} full_input = {'port': {'admin_state_up': True, - 'mac_address': attributes.ATTR_NOT_SPECIFIED, - 'fixed_ips': attributes.ATTR_NOT_SPECIFIED, + 'mac_address': constants.ATTR_NOT_SPECIFIED, + 'fixed_ips': constants.ATTR_NOT_SPECIFIED, 'device_owner': ''}} full_input['port'].update(initial_input['port']) return_value = {'id': _uuid(), 'status': 'ACTIVE', diff --git a/neutron/tests/unit/common/test_utils.py b/neutron/tests/unit/common/test_utils.py index 9f532787da4..de724865198 100644 --- a/neutron/tests/unit/common/test_utils.py +++ b/neutron/tests/unit/common/test_utils.py @@ -18,12 +18,12 @@ import re import eventlet import mock import netaddr +from neutron_lib import constants from neutron_lib import exceptions as exc from oslo_log import log as logging import six import testtools -from neutron.common import constants from neutron.common import exceptions as n_exc from neutron.common import utils from neutron.plugins.common import constants as p_const diff --git a/neutron/tests/unit/db/metering/test_metering_db.py b/neutron/tests/unit/db/metering/test_metering_db.py index f2db17f6e1b..f274abc1187 100644 --- a/neutron/tests/unit/db/metering/test_metering_db.py +++ b/neutron/tests/unit/db/metering/test_metering_db.py @@ -14,11 +14,11 @@ import contextlib +from neutron_lib import constants as n_consts import webob.exc from neutron.api import extensions from neutron.common import config -from neutron.common import constants as n_consts from neutron import context import neutron.extensions from neutron.extensions import metering diff --git a/neutron/tests/unit/db/test_agents_db.py b/neutron/tests/unit/db/test_agents_db.py index fe0ac5febe6..f3c0c726fb1 100644 --- a/neutron/tests/unit/db/test_agents_db.py +++ b/neutron/tests/unit/db/test_agents_db.py @@ -18,13 +18,13 @@ import copy import datetime import mock +from neutron_lib import constants from neutron_lib import exceptions as n_exc from oslo_config import cfg from oslo_db import exception as exc from oslo_utils import timeutils import testscenarios -from neutron.common import constants from neutron import context from neutron.db import agents_db from neutron.db import db_base_plugin_v2 as base_plugin diff --git a/neutron/tests/unit/db/test_agentschedulers_db.py b/neutron/tests/unit/db/test_agentschedulers_db.py index 8bcaff63ef4..692e1b96de1 100644 --- a/neutron/tests/unit/db/test_agentschedulers_db.py +++ b/neutron/tests/unit/db/test_agentschedulers_db.py @@ -16,6 +16,7 @@ import datetime import mock +from neutron_lib import constants from oslo_config import cfg from oslo_db import exception as db_exc import oslo_messaging @@ -27,7 +28,7 @@ from neutron.api.rpc.agentnotifiers import dhcp_rpc_agent_api from neutron.api.rpc.handlers import dhcp_rpc from neutron.api.rpc.handlers import l3_rpc from neutron.api.v2 import attributes -from neutron.common import constants +from neutron.common import constants as n_const from neutron import context from neutron.db import agents_db from neutron.db import agentschedulers_db @@ -618,7 +619,7 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): network_id=port1['port']['network_id']) port_list = self.deserialize('json', port_res) self.assertEqual(port_list['ports'][0]['device_id'], - constants.DEVICE_ID_RESERVED_DHCP_PORT) + n_const.DEVICE_ID_RESERVED_DHCP_PORT) def _test_get_active_networks_from_admin_state_down_agent(self, keep_services): @@ -1083,9 +1084,9 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): def test_dvr_router_csnat_rescheduling(self): helpers.register_l3_agent( - host=L3_HOSTA, agent_mode=constants.L3_AGENT_MODE_DVR_SNAT) + host=L3_HOSTA, agent_mode=n_const.L3_AGENT_MODE_DVR_SNAT) helpers.register_l3_agent( - host=L3_HOSTB, agent_mode=constants.L3_AGENT_MODE_DVR_SNAT) + host=L3_HOSTB, agent_mode=n_const.L3_AGENT_MODE_DVR_SNAT) with self.subnet() as s: net_id = s['subnet']['network_id'] self._set_net_external(net_id) @@ -1110,9 +1111,9 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): def test_dvr_router_manual_rescheduling(self): helpers.register_l3_agent( - host=L3_HOSTA, agent_mode=constants.L3_AGENT_MODE_DVR_SNAT) + host=L3_HOSTA, agent_mode=n_const.L3_AGENT_MODE_DVR_SNAT) helpers.register_l3_agent( - host=L3_HOSTB, agent_mode=constants.L3_AGENT_MODE_DVR_SNAT) + host=L3_HOSTB, agent_mode=n_const.L3_AGENT_MODE_DVR_SNAT) with self.subnet() as s: net_id = s['subnet']['network_id'] self._set_net_external(net_id) @@ -1395,7 +1396,7 @@ class OvsDhcpAgentNotifierTestCase(test_agent.AgentDBTestMixIn, {'admin_state_up': False}, DHCP_HOSTA) def _network_port_create( - self, hosts, gateway=attributes.ATTR_NOT_SPECIFIED, owner=None): + self, hosts, gateway=constants.ATTR_NOT_SPECIFIED, owner=None): for host in hosts: helpers.register_dhcp_agent(host) with self.network() as net1: @@ -1462,7 +1463,7 @@ class OvsDhcpAgentNotifierTestCase(test_agent.AgentDBTestMixIn, return mock_sched.called def test_reserved_dhcp_port_creation(self): - device_id = constants.DEVICE_ID_RESERVED_DHCP_PORT + device_id = n_const.DEVICE_ID_RESERVED_DHCP_PORT self.assertFalse(self._is_schedule_network_called(device_id)) def test_unreserved_dhcp_port_creation(self): diff --git a/neutron/tests/unit/db/test_bgp_db.py b/neutron/tests/unit/db/test_bgp_db.py index ff1a76ae622..301bc13285e 100644 --- a/neutron/tests/unit/db/test_bgp_db.py +++ b/neutron/tests/unit/db/test_bgp_db.py @@ -14,10 +14,10 @@ import contextlib import netaddr +from neutron_lib import constants from neutron_lib import exceptions as n_exc from oslo_utils import uuidutils -from neutron.api.v2 import attributes as attrs from neutron.extensions import bgp from neutron.extensions import external_net from neutron.extensions import portbindings @@ -436,13 +436,14 @@ class BgpTests(test_plugin.Ml2PluginV2TestCase, network1_id = network1['network']['id'] network2_id = network2['network']['id'] network3_id = network3['network']['id'] - base_subnet_data = {'allocation_pools': attrs.ATTR_NOT_SPECIFIED, - 'cidr': attrs.ATTR_NOT_SPECIFIED, - 'prefixlen': attrs.ATTR_NOT_SPECIFIED, - 'ip_version': 4, - 'enable_dhcp': True, - 'dns_nameservers': attrs.ATTR_NOT_SPECIFIED, - 'host_routes': attrs.ATTR_NOT_SPECIFIED} + base_subnet_data = { + 'allocation_pools': constants.ATTR_NOT_SPECIFIED, + 'cidr': constants.ATTR_NOT_SPECIFIED, + 'prefixlen': constants.ATTR_NOT_SPECIFIED, + 'ip_version': 4, + 'enable_dhcp': True, + 'dns_nameservers': constants.ATTR_NOT_SPECIFIED, + 'host_routes': constants.ATTR_NOT_SPECIFIED} subnet1_data = {'network_id': network1_id, 'subnetpool_id': sp1['id'], 'name': 'subnet1', @@ -701,8 +702,8 @@ class BgpTests(test_plugin.Ml2PluginV2TestCase, 'admin_state_up': True, 'device_id': _uuid(), 'device_owner': 'compute:nova', - 'mac_address': attrs.ATTR_NOT_SPECIFIED, - 'fixed_ips': attrs.ATTR_NOT_SPECIFIED}} + 'mac_address': constants.ATTR_NOT_SPECIFIED, + 'fixed_ips': constants.ATTR_NOT_SPECIFIED}} fixed_port = self.plugin.create_port(self.context, fixed_port_data) fip_data = {'floatingip': {'floating_network_id': gw_net_id, @@ -753,8 +754,8 @@ class BgpTests(test_plugin.Ml2PluginV2TestCase, 'admin_state_up': True, 'device_id': _uuid(), 'device_owner': 'compute:nova', - 'mac_address': attrs.ATTR_NOT_SPECIFIED, - 'fixed_ips': attrs.ATTR_NOT_SPECIFIED}} + 'mac_address': constants.ATTR_NOT_SPECIFIED, + 'fixed_ips': constants.ATTR_NOT_SPECIFIED}} fixed_port = self.plugin.create_port(self.context, fixed_port_data) fip_data = {'floatingip': {'floating_network_id': gw_net_id, @@ -807,8 +808,8 @@ class BgpTests(test_plugin.Ml2PluginV2TestCase, 'admin_state_up': True, 'device_id': _uuid(), 'device_owner': 'compute:nova', - 'mac_address': attrs.ATTR_NOT_SPECIFIED, - 'fixed_ips': attrs.ATTR_NOT_SPECIFIED, + 'mac_address': constants.ATTR_NOT_SPECIFIED, + 'fixed_ips': constants.ATTR_NOT_SPECIFIED, portbindings.HOST_ID: 'test-host'}} fixed_port = self.plugin.create_port(self.context, fixed_port_data) @@ -872,8 +873,8 @@ class BgpTests(test_plugin.Ml2PluginV2TestCase, 'admin_state_up': True, 'device_id': _uuid(), 'device_owner': 'compute:nova', - 'mac_address': attrs.ATTR_NOT_SPECIFIED, - 'fixed_ips': attrs.ATTR_NOT_SPECIFIED, + 'mac_address': constants.ATTR_NOT_SPECIFIED, + 'fixed_ips': constants.ATTR_NOT_SPECIFIED, portbindings.HOST_ID: 'test-host'}} fixed_port = self.plugin.create_port(self.context, fixed_port_data) @@ -928,8 +929,8 @@ class BgpTests(test_plugin.Ml2PluginV2TestCase, 'admin_state_up': True, 'device_id': _uuid(), 'device_owner': 'compute:nova', - 'mac_address': attrs.ATTR_NOT_SPECIFIED, - 'fixed_ips': attrs.ATTR_NOT_SPECIFIED, + 'mac_address': constants.ATTR_NOT_SPECIFIED, + 'fixed_ips': constants.ATTR_NOT_SPECIFIED, portbindings.HOST_ID: 'test-host'}} fixed_port = self.plugin.create_port(self.context, fixed_port_data) @@ -984,8 +985,8 @@ class BgpTests(test_plugin.Ml2PluginV2TestCase, 'admin_state_up': True, 'device_id': _uuid(), 'device_owner': 'compute:nova', - 'mac_address': attrs.ATTR_NOT_SPECIFIED, - 'fixed_ips': attrs.ATTR_NOT_SPECIFIED}} + 'mac_address': constants.ATTR_NOT_SPECIFIED, + 'fixed_ips': constants.ATTR_NOT_SPECIFIED}} fixed_port = self.plugin.create_port(self.context, fixed_port_data) fip_data = {'floatingip': {'floating_network_id': gw_net_id, diff --git a/neutron/tests/unit/db/test_db_base_plugin_v2.py b/neutron/tests/unit/db/test_db_base_plugin_v2.py index abf5289d35f..526d0171f3b 100644 --- a/neutron/tests/unit/db/test_db_base_plugin_v2.py +++ b/neutron/tests/unit/db/test_db_base_plugin_v2.py @@ -19,6 +19,7 @@ import itertools import mock import netaddr +from neutron_lib import constants from neutron_lib import exceptions as lib_exc from oslo_config import cfg from oslo_utils import importutils @@ -32,11 +33,10 @@ import webob.exc import neutron from neutron.api import api_common from neutron.api import extensions -from neutron.api.v2 import attributes from neutron.api.v2 import router from neutron.callbacks import exceptions from neutron.callbacks import registry -from neutron.common import constants +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 test_lib @@ -332,7 +332,7 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase): data['subnet'][arg] = kwargs[arg] if ('gateway_ip' in kwargs and - kwargs['gateway_ip'] is not attributes.ATTR_NOT_SPECIFIED): + kwargs['gateway_ip'] is not constants.ATTR_NOT_SPECIFIED): data['subnet']['gateway_ip'] = kwargs['gateway_ip'] subnet_req = self.new_create_request('subnets', data, fmt) @@ -589,7 +589,7 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase): @contextlib.contextmanager def subnet(self, network=None, - gateway_ip=attributes.ATTR_NOT_SPECIFIED, + gateway_ip=constants.ATTR_NOT_SPECIFIED, cidr='10.0.0.0/24', subnetpool_id=None, fmt=None, @@ -1386,7 +1386,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s with self.subnet(gateway_ip='fe80::1', cidr='2607:f0d0:1002:51::/64', ip_version=6, - ipv6_address_mode=constants.IPV6_SLAAC) as subnet: + ipv6_address_mode=n_const.IPV6_SLAAC) as subnet: self.assertTrue( ipv6_utils.is_auto_address_subnet(subnet['subnet'])) self.check_update_port_mac(subnet=subnet) @@ -1597,8 +1597,8 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s with self.subnet( cidr='2607:f0d0:1002:51::/64', ip_version=6, - ipv6_address_mode=constants.IPV6_SLAAC, - gateway_ip=attributes.ATTR_NOT_SPECIFIED) as subnet: + ipv6_address_mode=n_const.IPV6_SLAAC, + gateway_ip=constants.ATTR_NOT_SPECIFIED) as subnet: with self.port(subnet=subnet) as port: ips = port['port']['fixed_ips'] self.assertEqual(1, len(ips)) @@ -1730,7 +1730,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s net_id=net_id, cidr='10.0.0.225/28', ip_version=4, - gateway_ip=attributes.ATTR_NOT_SPECIFIED) + gateway_ip=constants.ATTR_NOT_SPECIFIED) self.assertEqual(webob.exc.HTTPClientError.code, res.status_int) def test_requested_subnet_id_v4_and_v6(self): @@ -1744,7 +1744,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s net_id=net_id, cidr='2607:f0d0:1002:51::/124', ip_version=6, - gateway_ip=attributes.ATTR_NOT_SPECIFIED) + gateway_ip=constants.ATTR_NOT_SPECIFIED) subnet2 = self.deserialize(self.fmt, res) kwargs = {"fixed_ips": [{'subnet_id': subnet['subnet']['id']}, @@ -1773,7 +1773,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s with self.subnet(gateway_ip='fe80::1', cidr='2607:f0d0:1002:51::/64', ip_version=6, - ipv6_address_mode=constants.IPV6_SLAAC) as subnet: + ipv6_address_mode=n_const.IPV6_SLAAC) as subnet: kwargs = {"fixed_ips": [{'subnet_id': subnet['subnet']['id'], 'ip_address': '2607:f0d0:1002:51::5'}]} net_id = subnet['subnet']['network_id'] @@ -1788,7 +1788,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s with self.subnet(gateway_ip='fe80::1', cidr='fe80::/64', ip_version=6, - ipv6_address_mode=constants.IPV6_SLAAC) as subnet: + ipv6_address_mode=n_const.IPV6_SLAAC) as subnet: kwargs = {"fixed_ips": [{'subnet_id': subnet['subnet']['id'], 'ip_address': 'fe80::1'}]} net_id = subnet['subnet']['network_id'] @@ -1805,7 +1805,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s with self.subnet(gateway_ip='fe80::1', cidr='2607:f0d0:1002:51::/64', ip_version=6, - ipv6_address_mode=constants.IPV6_SLAAC) as subnet: + ipv6_address_mode=n_const.IPV6_SLAAC) as subnet: with self.port(subnet, fixed_ips=[{'subnet_id': subnet['subnet']['id']}]) as port: @@ -1824,7 +1824,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s cidr='2607:f0d0:1002:51::/64', ip_version=6, gateway_ip='fe80::1', - ipv6_address_mode=constants.IPV6_SLAAC) as subnet2: + ipv6_address_mode=n_const.IPV6_SLAAC) as subnet2: with self.port( subnet, fixed_ips=[{'subnet_id': subnet['subnet']['id']}, @@ -1849,7 +1849,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s cidr='2607:f0d0:1002:51::/64', ip_version=6, gateway_ip='fe80::1', - ipv6_address_mode=constants.IPV6_SLAAC): + ipv6_address_mode=n_const.IPV6_SLAAC): # Create a router port without specifying fixed_ips port = self._make_port( self.fmt, network['network']['id'], @@ -1884,7 +1884,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s res = self._create_network(fmt=self.fmt, name='net', admin_state_up=True) network = self.deserialize(self.fmt, res) - subnet = self._make_v6_subnet(network, constants.IPV6_SLAAC) + subnet = self._make_v6_subnet(network, n_const.IPV6_SLAAC) port = self._make_port(self.fmt, network['network']['id']) self.assertEqual(1, len(port['port']['fixed_ips'])) self.assertEqual(self._calc_ipv6_addr_by_EUI64(port, subnet), @@ -1898,7 +1898,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s subnet_id = subnet['subnet']['id'] fixed_ips = [{'subnet_id': subnet_id}] with self.port(subnet=subnet, fixed_ips=fixed_ips) as port: - if addr_mode == constants.IPV6_SLAAC: + if addr_mode == n_const.IPV6_SLAAC: exp_ip_addr = self._calc_ipv6_addr_by_EUI64(port, subnet) else: exp_ip_addr = 'fe80::2' @@ -1909,15 +1909,15 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s def test_create_port_with_ipv6_slaac_subnet_in_fixed_ips(self): self._test_create_port_with_ipv6_subnet_in_fixed_ips( - addr_mode=constants.IPV6_SLAAC) + addr_mode=n_const.IPV6_SLAAC) def test_create_port_with_ipv6_pd_subnet_in_fixed_ips(self): self._test_create_port_with_ipv6_subnet_in_fixed_ips( - addr_mode=constants.IPV6_SLAAC, ipv6_pd=True) + addr_mode=n_const.IPV6_SLAAC, ipv6_pd=True) def test_create_port_with_ipv6_dhcp_stateful_subnet_in_fixed_ips(self): self._test_create_port_with_ipv6_subnet_in_fixed_ips( - addr_mode=constants.DHCPV6_STATEFUL) + addr_mode=n_const.DHCPV6_STATEFUL) def test_create_port_with_multiple_ipv4_and_ipv6_subnets(self): """Test port create with multiple IPv4, IPv6 DHCP/SLAAC subnets.""" @@ -1930,13 +1930,13 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s {'gateway': '10.0.1.1', 'cidr': '10.0.1.0/24', 'ip_version': 4, 'ra_addr_mode': None}, {'gateway': 'fe80::1', 'cidr': 'fe80::/64', - 'ip_version': 6, 'ra_addr_mode': constants.IPV6_SLAAC}, + 'ip_version': 6, 'ra_addr_mode': n_const.IPV6_SLAAC}, {'gateway': 'fe81::1', 'cidr': 'fe81::/64', - 'ip_version': 6, 'ra_addr_mode': constants.IPV6_SLAAC}, + 'ip_version': 6, 'ra_addr_mode': n_const.IPV6_SLAAC}, {'gateway': 'fe82::1', 'cidr': 'fe82::/64', - 'ip_version': 6, 'ra_addr_mode': constants.DHCPV6_STATEFUL}, + 'ip_version': 6, 'ra_addr_mode': n_const.DHCPV6_STATEFUL}, {'gateway': 'fe83::1', 'cidr': 'fe83::/64', - 'ip_version': 6, 'ra_addr_mode': constants.DHCPV6_STATEFUL}] + 'ip_version': 6, 'ra_addr_mode': n_const.DHCPV6_STATEFUL}] subnets = {} for sub_dict in sub_dicts: subnet = self._make_subnet( @@ -1954,15 +1954,15 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s # IPv4 subnets, one of the DHCPv6 subnets, and both of the IPv6 # SLAAC subnets. self.assertEqual(4, len(port['port']['fixed_ips'])) - addr_mode_count = {None: 0, constants.DHCPV6_STATEFUL: 0, - constants.IPV6_SLAAC: 0} + addr_mode_count = {None: 0, n_const.DHCPV6_STATEFUL: 0, + n_const.IPV6_SLAAC: 0} for fixed_ip in port['port']['fixed_ips']: subnet_id = fixed_ip['subnet_id'] if subnet_id in subnets: addr_mode_count[subnets[subnet_id]['ra_addr_mode']] += 1 self.assertEqual(1, addr_mode_count[None]) - self.assertEqual(1, addr_mode_count[constants.DHCPV6_STATEFUL]) - self.assertEqual(2, addr_mode_count[constants.IPV6_SLAAC]) + self.assertEqual(1, addr_mode_count[n_const.DHCPV6_STATEFUL]) + self.assertEqual(2, addr_mode_count[n_const.IPV6_SLAAC]) def test_delete_port_with_ipv6_slaac_address(self): """Test that a port with an IPv6 SLAAC address can be deleted.""" @@ -1970,7 +1970,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s admin_state_up=True) network = self.deserialize(self.fmt, res) # Create a port that has an associated IPv6 SLAAC address - self._make_v6_subnet(network, constants.IPV6_SLAAC) + self._make_v6_subnet(network, n_const.IPV6_SLAAC) res = self._create_port(self.fmt, net_id=network['network']['id']) port = self.deserialize(self.fmt, res) self.assertEqual(1, len(port['port']['fixed_ips'])) @@ -1987,7 +1987,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s # Create a port using an IPv4 subnet and an IPv6 SLAAC subnet self._make_subnet(self.fmt, network, gateway='10.0.0.1', cidr='10.0.0.0/24', ip_version=4) - subnet_v6 = self._make_v6_subnet(network, constants.IPV6_SLAAC) + subnet_v6 = self._make_v6_subnet(network, n_const.IPV6_SLAAC) res = self._create_port(self.fmt, net_id=network['network']['id']) port = self.deserialize(self.fmt, res) self.assertEqual(2, len(port['port']['fixed_ips'])) @@ -2011,7 +2011,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s # Create a port using an IPv4 subnet and an IPv6 SLAAC subnet subnet_v4 = self._make_subnet(self.fmt, network, gateway='10.0.0.1', cidr='10.0.0.0/24', ip_version=4) - subnet_v6 = self._make_v6_subnet(network, constants.IPV6_SLAAC) + subnet_v6 = self._make_v6_subnet(network, n_const.IPV6_SLAAC) res = self._create_port(self.fmt, net_id=network['network']['id']) port = self.deserialize(self.fmt, res) self.assertEqual(2, len(port['port']['fixed_ips'])) @@ -2038,12 +2038,12 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s gateway='2001:100::1', cidr='2001:100::0/64', ip_version=6, - ipv6_ra_mode=constants.IPV6_SLAAC) + ipv6_ra_mode=n_const.IPV6_SLAAC) v6_subnet_2 = self._make_subnet(self.fmt, network, gateway='2001:200::1', cidr='2001:200::0/64', ip_version=6, - ipv6_ra_mode=constants.IPV6_SLAAC) + ipv6_ra_mode=n_const.IPV6_SLAAC) port = self._make_port(self.fmt, network['network']['id']) port_mac = port['port']['mac_address'] cidr_1 = v6_subnet_1['subnet']['cidr'] @@ -3251,8 +3251,8 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): network = self.deserialize(self.fmt, res) subnet = self._make_subnet(self.fmt, network, gateway='fe80::1', cidr='fe80::/64', ip_version=6, - ipv6_ra_mode=constants.IPV6_SLAAC, - ipv6_address_mode=constants.IPV6_SLAAC) + ipv6_ra_mode=n_const.IPV6_SLAAC, + ipv6_address_mode=n_const.IPV6_SLAAC) kwargs = {} if port_owner: kwargs['device_owner'] = port_owner @@ -3552,8 +3552,8 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): 'allocation_pools': allocation_pools} self._test_create_subnet(expected=expected, gateway_ip=gateway, cidr=cidr, ip_version=6, - ipv6_ra_mode=constants.DHCPV6_STATEFUL, - ipv6_address_mode=constants.DHCPV6_STATEFUL) + ipv6_ra_mode=n_const.DHCPV6_STATEFUL, + ipv6_address_mode=n_const.DHCPV6_STATEFUL) # Gateway is first IP in IPv6 DHCPv6 stateful subnet gateway = '2001::1' allocation_pools = [{'start': '2001::2', @@ -3563,19 +3563,19 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): 'allocation_pools': allocation_pools} self._test_create_subnet(expected=expected, gateway_ip=gateway, cidr=cidr, ip_version=6, - ipv6_ra_mode=constants.DHCPV6_STATEFUL, - ipv6_address_mode=constants.DHCPV6_STATEFUL) + ipv6_ra_mode=n_const.DHCPV6_STATEFUL, + ipv6_address_mode=n_const.DHCPV6_STATEFUL) # If gateway_ip is not specified, allocate first IP from the subnet expected = {'gateway_ip': gateway, 'cidr': cidr} self._test_create_subnet(expected=expected, cidr=cidr, ip_version=6, - ipv6_ra_mode=constants.IPV6_SLAAC, - ipv6_address_mode=constants.IPV6_SLAAC) + ipv6_ra_mode=n_const.IPV6_SLAAC, + ipv6_address_mode=n_const.IPV6_SLAAC) @testtools.skipIf(tools.is_bsd(), 'bug/1484837') def test_create_subnet_ipv6_pd_gw_values(self): - cidr = constants.PROVISIONAL_IPV6_PD_PREFIX + cidr = n_const.PROVISIONAL_IPV6_PD_PREFIX # Gateway is last IP in IPv6 DHCPv6 Stateless subnet gateway = '::ffff:ffff:ffff:ffff' allocation_pools = [{'start': '::1', @@ -3585,8 +3585,8 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): 'allocation_pools': allocation_pools} self._test_create_subnet(expected=expected, gateway_ip=gateway, cidr=cidr, ip_version=6, - ipv6_ra_mode=constants.DHCPV6_STATELESS, - ipv6_address_mode=constants.DHCPV6_STATELESS) + ipv6_ra_mode=n_const.DHCPV6_STATELESS, + ipv6_address_mode=n_const.DHCPV6_STATELESS) # Gateway is first IP in IPv6 DHCPv6 Stateless subnet gateway = '::1' allocation_pools = [{'start': '::2', @@ -3596,15 +3596,15 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): 'allocation_pools': allocation_pools} self._test_create_subnet(expected=expected, gateway_ip=gateway, cidr=cidr, ip_version=6, - ipv6_ra_mode=constants.DHCPV6_STATELESS, - ipv6_address_mode=constants.DHCPV6_STATELESS) + ipv6_ra_mode=n_const.DHCPV6_STATELESS, + ipv6_address_mode=n_const.DHCPV6_STATELESS) # If gateway_ip is not specified, allocate first IP from the subnet expected = {'gateway_ip': gateway, 'cidr': cidr} self._test_create_subnet(expected=expected, cidr=cidr, ip_version=6, - ipv6_ra_mode=constants.IPV6_SLAAC, - ipv6_address_mode=constants.IPV6_SLAAC) + ipv6_ra_mode=n_const.IPV6_SLAAC, + ipv6_address_mode=n_const.IPV6_SLAAC) def test_create_subnet_gw_outside_cidr_returns_201(self): with self.network() as network: @@ -3719,7 +3719,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): @testtools.skipIf(tools.is_bsd(), 'bug/1484837') def test_create_subnet_with_v6_pd_allocation_pool(self): gateway_ip = '::1' - cidr = constants.PROVISIONAL_IPV6_PD_PREFIX + cidr = n_const.PROVISIONAL_IPV6_PD_PREFIX allocation_pools = [{'start': '::2', 'end': '::ffff:ffff:ffff:fffe'}] self._test_create_subnet(gateway_ip=gateway_ip, @@ -3928,7 +3928,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): plugin = manager.NeutronManager.get_plugin() ctx = context.get_admin_context() new_subnet = {'ip_version': 6, - 'cidr': constants.PROVISIONAL_IPV6_PD_PREFIX, + 'cidr': n_const.PROVISIONAL_IPV6_PD_PREFIX, 'enable_dhcp': True, 'ipv6_address_mode': None, 'ipv6_ra_mode': None} @@ -3942,7 +3942,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): def test_create_subnet_ipv6_ra_modes(self): # Test all RA modes with no address mode specified - for ra_mode in constants.IPV6_MODES: + for ra_mode in n_const.IPV6_MODES: self._test_validate_subnet_ipv6_modes( ipv6_ra_mode=ra_mode) self._test_validate_subnet_ipv6_pd_modes( @@ -3950,7 +3950,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): def test_create_subnet_ipv6_addr_modes(self): # Test all address modes with no RA mode specified - for addr_mode in constants.IPV6_MODES: + for addr_mode in n_const.IPV6_MODES: self._test_validate_subnet_ipv6_modes( ipv6_address_mode=addr_mode) self._test_validate_subnet_ipv6_pd_modes( @@ -3958,7 +3958,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): def test_create_subnet_ipv6_same_ra_and_addr_modes(self): # Test all ipv6 modes with ra_mode==addr_mode - for ipv6_mode in constants.IPV6_MODES: + for ipv6_mode in n_const.IPV6_MODES: self._test_validate_subnet_ipv6_modes( ipv6_ra_mode=ipv6_mode, ipv6_address_mode=ipv6_mode) @@ -3969,7 +3969,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): def test_create_subnet_ipv6_different_ra_and_addr_modes(self): # Test all ipv6 modes with ra_mode!=addr_mode for ra_mode, addr_mode in itertools.permutations( - constants.IPV6_MODES, 2): + n_const.IPV6_MODES, 2): self._test_validate_subnet_ipv6_modes( expect_success=not (ra_mode and addr_mode), ipv6_ra_mode=ra_mode, @@ -3985,8 +3985,8 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): subnet = self._test_create_subnet( gateway_ip=gateway_ip, cidr=cidr, ip_version=constants.IP_VERSION_6, - ipv6_ra_mode=constants.DHCPV6_STATEFUL, - ipv6_address_mode=constants.DHCPV6_STATEFUL) + ipv6_ra_mode=n_const.DHCPV6_STATEFUL, + ipv6_address_mode=n_const.DHCPV6_STATEFUL) self.assertEqual(constants.IP_VERSION_6, subnet['subnet']['ip_version']) self.assertEqual(gateway_ip, @@ -4003,8 +4003,8 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): self._test_create_subnet( gateway_ip=gateway_ip, cidr=cidr, ip_version=constants.IP_VERSION_6, - ipv6_ra_mode=constants.DHCPV6_STATEFUL, - ipv6_address_mode=constants.DHCPV6_STATEFUL) + ipv6_ra_mode=n_const.DHCPV6_STATEFUL, + ipv6_address_mode=n_const.DHCPV6_STATEFUL) self.assertEqual(webob.exc.HTTPClientError.code, ctx_manager.exception.code) @@ -4014,8 +4014,8 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): subnet = self._test_create_subnet( gateway_ip=gateway_ip, cidr=cidr, ip_version=constants.IP_VERSION_6, - ipv6_ra_mode=constants.DHCPV6_STATEFUL, - ipv6_address_mode=constants.DHCPV6_STATEFUL) + ipv6_ra_mode=n_const.DHCPV6_STATEFUL, + ipv6_address_mode=n_const.DHCPV6_STATEFUL) self.assertEqual(constants.IP_VERSION_6, subnet['subnet']['ip_version']) self.assertEqual(gateway_ip, @@ -4029,15 +4029,15 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): self._test_create_subnet( gateway_ip=gateway_ip, cidr=cidr, ip_version=6, - ipv6_ra_mode=constants.IPV6_SLAAC, - ipv6_address_mode=constants.IPV6_SLAAC) + ipv6_ra_mode=n_const.IPV6_SLAAC, + ipv6_address_mode=n_const.IPV6_SLAAC) def test_create_subnet_ipv6_attributes_no_dhcp_enabled(self): gateway_ip = 'fe80::1' cidr = 'fe80::/64' with testlib_api.ExpectedException( webob.exc.HTTPClientError) as ctx_manager: - for mode in constants.IPV6_MODES: + for mode in n_const.IPV6_MODES: self._test_create_subnet(gateway_ip=gateway_ip, cidr=cidr, ip_version=6, enable_dhcp=False, @@ -4075,7 +4075,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): with testlib_api.ExpectedException( webob.exc.HTTPClientError) as ctx_manager: self._test_create_subnet(cidr=cidr, ip_version=4, - ipv6_ra_mode=constants.DHCPV6_STATEFUL) + ipv6_ra_mode=n_const.DHCPV6_STATEFUL) self.assertEqual(webob.exc.HTTPClientError.code, ctx_manager.exception.code) @@ -4085,7 +4085,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): webob.exc.HTTPClientError) as ctx_manager: self._test_create_subnet( cidr=cidr, ip_version=4, - ipv6_address_mode=constants.DHCPV6_STATEFUL) + ipv6_address_mode=n_const.DHCPV6_STATEFUL) self.assertEqual(webob.exc.HTTPClientError.code, ctx_manager.exception.code) @@ -4142,30 +4142,30 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): def test_create_subnet_ipv6_slaac_with_port_on_network(self): self._test_create_subnet_ipv6_auto_addr_with_port_on_network( - constants.IPV6_SLAAC) + n_const.IPV6_SLAAC) def test_create_subnet_dhcpv6_stateless_with_port_on_network(self): self._test_create_subnet_ipv6_auto_addr_with_port_on_network( - constants.DHCPV6_STATELESS) + n_const.DHCPV6_STATELESS) def test_create_subnet_ipv6_slaac_with_dhcp_port_on_network(self): self._test_create_subnet_ipv6_auto_addr_with_port_on_network( - constants.IPV6_SLAAC, + n_const.IPV6_SLAAC, device_owner=constants.DEVICE_OWNER_DHCP) def test_create_subnet_ipv6_slaac_with_router_intf_on_network(self): self._test_create_subnet_ipv6_auto_addr_with_port_on_network( - constants.IPV6_SLAAC, + n_const.IPV6_SLAAC, device_owner=constants.DEVICE_OWNER_ROUTER_INTF) def test_create_subnet_ipv6_slaac_with_snat_intf_on_network(self): self._test_create_subnet_ipv6_auto_addr_with_port_on_network( - constants.IPV6_SLAAC, + n_const.IPV6_SLAAC, device_owner=constants.DEVICE_OWNER_ROUTER_SNAT) def test_create_subnet_ipv6_slaac_with_db_reference_error(self): self._test_create_subnet_ipv6_auto_addr_with_port_on_network( - constants.IPV6_SLAAC, insert_db_reference_error=True) + n_const.IPV6_SLAAC, insert_db_reference_error=True) def test_update_subnet_no_gateway(self): with self.subnet() as subnet: @@ -4344,10 +4344,10 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): def test_update_subnet_ipv6_attributes_fails(self): with self.subnet(ip_version=6, cidr='fe80::/64', - ipv6_ra_mode=constants.IPV6_SLAAC, - ipv6_address_mode=constants.IPV6_SLAAC) as subnet: - data = {'subnet': {'ipv6_ra_mode': constants.DHCPV6_STATEFUL, - 'ipv6_address_mode': constants.DHCPV6_STATEFUL}} + ipv6_ra_mode=n_const.IPV6_SLAAC, + ipv6_address_mode=n_const.IPV6_SLAAC) as subnet: + data = {'subnet': {'ipv6_ra_mode': n_const.DHCPV6_STATEFUL, + 'ipv6_address_mode': n_const.DHCPV6_STATEFUL}} req = self.new_update_request('subnets', data, subnet['subnet']['id']) res = req.get_response(self.api) @@ -4356,8 +4356,8 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): def test_update_subnet_ipv6_ra_mode_fails(self): with self.subnet(ip_version=6, cidr='fe80::/64', - ipv6_ra_mode=constants.IPV6_SLAAC) as subnet: - data = {'subnet': {'ipv6_ra_mode': constants.DHCPV6_STATEFUL}} + ipv6_ra_mode=n_const.IPV6_SLAAC) as subnet: + data = {'subnet': {'ipv6_ra_mode': n_const.DHCPV6_STATEFUL}} req = self.new_update_request('subnets', data, subnet['subnet']['id']) res = req.get_response(self.api) @@ -4366,8 +4366,8 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): def test_update_subnet_ipv6_address_mode_fails(self): with self.subnet(ip_version=6, cidr='fe80::/64', - ipv6_address_mode=constants.IPV6_SLAAC) as subnet: - data = {'subnet': {'ipv6_address_mode': constants.DHCPV6_STATEFUL}} + ipv6_address_mode=n_const.IPV6_SLAAC) as subnet: + data = {'subnet': {'ipv6_address_mode': n_const.DHCPV6_STATEFUL}} req = self.new_update_request('subnets', data, subnet['subnet']['id']) res = req.get_response(self.api) @@ -4376,8 +4376,8 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): def test_update_subnet_ipv6_cannot_disable_dhcp(self): with self.subnet(ip_version=6, cidr='fe80::/64', - ipv6_ra_mode=constants.IPV6_SLAAC, - ipv6_address_mode=constants.IPV6_SLAAC) as subnet: + ipv6_ra_mode=n_const.IPV6_SLAAC, + ipv6_address_mode=n_const.IPV6_SLAAC) as subnet: data = {'subnet': {'enable_dhcp': False}} req = self.new_update_request('subnets', data, subnet['subnet']['id']) @@ -4389,7 +4389,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): with self.network() as network: with self.subnet(network=network) as subnet: data = {'subnet': {'ipv6_ra_mode': - constants.DHCPV6_STATEFUL}} + n_const.DHCPV6_STATEFUL}} req = self.new_update_request('subnets', data, subnet['subnet']['id']) res = req.get_response(self.api) @@ -4400,7 +4400,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): with self.network() as network: with self.subnet(network=network) as subnet: data = {'subnet': {'ipv6_address_mode': - constants.DHCPV6_STATEFUL}} + n_const.DHCPV6_STATEFUL}} req = self.new_update_request('subnets', data, subnet['subnet']['id']) res = req.get_response(self.api) @@ -6039,8 +6039,8 @@ class TestNetworks(testlib_api.SqlTestCase): def _create_port(self, plugin, ctx, net_id, device_owner, tenant_id): port = {'port': {'name': 'port', 'network_id': net_id, - 'mac_address': attributes.ATTR_NOT_SPECIFIED, - 'fixed_ips': attributes.ATTR_NOT_SPECIFIED, + 'mac_address': constants.ATTR_NOT_SPECIFIED, + 'fixed_ips': constants.ATTR_NOT_SPECIFIED, 'admin_state_up': True, 'device_id': 'device_id', 'device_owner': device_owner, diff --git a/neutron/tests/unit/db/test_dvr_mac_db.py b/neutron/tests/unit/db/test_dvr_mac_db.py index 5b7ce40299c..397488aecee 100644 --- a/neutron/tests/unit/db/test_dvr_mac_db.py +++ b/neutron/tests/unit/db/test_dvr_mac_db.py @@ -14,12 +14,12 @@ # limitations under the License. import mock +from neutron_lib import constants from oslo_config import cfg from neutron.callbacks import events from neutron.callbacks import registry from neutron.callbacks import resources -from neutron.common import constants from neutron import context from neutron.db import dvr_mac_db from neutron.extensions import dvr diff --git a/neutron/tests/unit/db/test_ipam_backend_mixin.py b/neutron/tests/unit/db/test_ipam_backend_mixin.py index c25045a63a0..ceedc1d8f40 100644 --- a/neutron/tests/unit/db/test_ipam_backend_mixin.py +++ b/neutron/tests/unit/db/test_ipam_backend_mixin.py @@ -14,8 +14,9 @@ # under the License. import mock +from neutron_lib import constants -from neutron.common import constants +from neutron.common import constants as n_const from neutron.db import ipam_backend_mixin from neutron.tests import base @@ -38,8 +39,8 @@ class TestIpamBackendMixin(base.BaseTestCase): 'subnet_id': ip[0]} for ip in ips] def _mock_slaac_subnet_on(self): - slaac_subnet = {'ipv6_address_mode': constants.IPV6_SLAAC, - 'ipv6_ra_mode': constants.IPV6_SLAAC} + slaac_subnet = {'ipv6_address_mode': n_const.IPV6_SLAAC, + 'ipv6_ra_mode': n_const.IPV6_SLAAC} self.mixin._get_subnet = mock.Mock(return_value=slaac_subnet) def _mock_slaac_subnet_off(self): @@ -90,8 +91,8 @@ class TestIpamBackendMixin(base.BaseTestCase): # mock to test auto address part pd_subnet = {'subnetpool_id': constants.IPV6_PD_POOL_ID, - 'ipv6_address_mode': constants.IPV6_SLAAC, - 'ipv6_ra_mode': constants.IPV6_SLAAC} + 'ipv6_address_mode': n_const.IPV6_SLAAC, + 'ipv6_ra_mode': n_const.IPV6_SLAAC} self.mixin._get_subnet = mock.Mock(return_value=pd_subnet) # make a copy of original_ips diff --git a/neutron/tests/unit/db/test_ipam_non_pluggable_backend.py b/neutron/tests/unit/db/test_ipam_non_pluggable_backend.py index 5f08c2a6e38..a356fff1303 100644 --- a/neutron/tests/unit/db/test_ipam_non_pluggable_backend.py +++ b/neutron/tests/unit/db/test_ipam_non_pluggable_backend.py @@ -14,10 +14,10 @@ # under the License. import mock +from neutron_lib import constants as n_const from neutron_lib import exceptions as n_exc from oslo_config import cfg -from neutron.api.v2 import attributes from neutron.common import constants from neutron.common import ipv6_utils from neutron.db import db_base_plugin_common @@ -175,7 +175,7 @@ class TestIpamNonPluggableBackend(base.BaseTestCase): 'ipv6_ra_mode': u'slaac'}] port = {'port': { 'network_id': 'fbb9b578-95eb-4b79-a116-78e5c4927176', - 'fixed_ips': attributes.ATTR_NOT_SPECIFIED, + 'fixed_ips': n_const.ATTR_NOT_SPECIFIED, 'mac_address': '12:34:56:78:44:ab', 'device_owner': 'compute'}} expected = [] @@ -208,7 +208,7 @@ class TestIpamNonPluggableBackend(base.BaseTestCase): 'ipv6_ra_mode': 'slaac'}] port = {'port': { 'network_id': 'fbb9b578-95eb-4b79-a116-78e5c4927176', - 'fixed_ips': attributes.ATTR_NOT_SPECIFIED, + 'fixed_ips': n_const.ATTR_NOT_SPECIFIED, 'mac_address': '12:34:56:78:44:ab', 'device_owner': 'compute'}} expected = [] diff --git a/neutron/tests/unit/db/test_ipam_pluggable_backend.py b/neutron/tests/unit/db/test_ipam_pluggable_backend.py index 798f01d001d..5c7db81acee 100644 --- a/neutron/tests/unit/db/test_ipam_pluggable_backend.py +++ b/neutron/tests/unit/db/test_ipam_pluggable_backend.py @@ -15,12 +15,13 @@ import mock import netaddr +from neutron_lib import constants from neutron_lib import exceptions as n_exc from oslo_config import cfg from oslo_utils import uuidutils import webob.exc -from neutron.common import constants +from neutron.common import constants as n_const from neutron.common import ipv6_utils from neutron.db import ipam_backend_mixin from neutron.db import ipam_pluggable_backend @@ -294,12 +295,12 @@ class TestDbBasePluginIpam(test_db_base.NeutronDbPluginV2TestCase): def test_create_ipv6_pd_subnet_over_ipam(self, pool_mock): mocks = self._prepare_mocks_with_pool_mock(pool_mock) cfg.CONF.set_override('ipv6_pd_enabled', True) - cidr = constants.PROVISIONAL_IPV6_PD_PREFIX + cidr = n_const.PROVISIONAL_IPV6_PD_PREFIX allocation_pools = [netaddr.IPRange('::2', '::ffff:ffff:ffff:ffff')] with self.subnet(cidr=None, ip_version=6, subnetpool_id=constants.IPV6_PD_POOL_ID, - ipv6_ra_mode=constants.IPV6_SLAAC, - ipv6_address_mode=constants.IPV6_SLAAC): + ipv6_ra_mode=n_const.IPV6_SLAAC, + ipv6_address_mode=n_const.IPV6_SLAAC): pool_mock.get_instance.assert_called_once_with(None, mock.ANY) self.assertTrue(mocks['driver'].allocate_subnet.called) request = mocks['driver'].allocate_subnet.call_args[0][0] diff --git a/neutron/tests/unit/db/test_l3_dvr_db.py b/neutron/tests/unit/db/test_l3_dvr_db.py index 5e933913729..12e870554f9 100644 --- a/neutron/tests/unit/db/test_l3_dvr_db.py +++ b/neutron/tests/unit/db/test_l3_dvr_db.py @@ -14,10 +14,11 @@ # limitations under the License. import mock +from neutron_lib import constants as l3_const from neutron_lib import exceptions from oslo_utils import uuidutils -from neutron.common import constants as l3_const +from neutron.common import constants as n_const from neutron import context from neutron.db import agents_db from neutron.db import common_db_mixin @@ -404,7 +405,7 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): router, fip = self._floatingip_on_port_test_setup(None) self.assertNotIn(l3_const.FLOATINGIP_KEY, router) - self.assertNotIn(l3_const.FLOATINGIP_AGENT_INTF_KEY, router) + self.assertNotIn(n_const.FLOATINGIP_AGENT_INTF_KEY, router) def test_floatingip_on_port_with_host(self): router, fip = self._floatingip_on_port_test_setup(_uuid()) @@ -412,10 +413,10 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): self.assertTrue(self.mixin._get_fip_sync_interfaces.called) self.assertIn(l3_const.FLOATINGIP_KEY, router) - self.assertIn(l3_const.FLOATINGIP_AGENT_INTF_KEY, router) + self.assertIn(n_const.FLOATINGIP_AGENT_INTF_KEY, router) self.assertIn(fip, router[l3_const.FLOATINGIP_KEY]) self.assertIn('fip_interface', - router[l3_const.FLOATINGIP_AGENT_INTF_KEY]) + router[n_const.FLOATINGIP_AGENT_INTF_KEY]) def _setup_test_create_floatingip( self, fip, floatingip_db, router_db): diff --git a/neutron/tests/unit/db/test_l3_hamode_db.py b/neutron/tests/unit/db/test_l3_hamode_db.py index 171fda00ad6..12c2d8abbfd 100644 --- a/neutron/tests/unit/db/test_l3_hamode_db.py +++ b/neutron/tests/unit/db/test_l3_hamode_db.py @@ -13,6 +13,7 @@ # under the License. import mock +from neutron_lib import constants from neutron_lib import exceptions as n_exc from oslo_config import cfg from oslo_db import exception as db_exc @@ -22,8 +23,7 @@ from sqlalchemy import orm import testtools from neutron.api.rpc.handlers import l3_rpc -from neutron.api.v2 import attributes -from neutron.common import constants +from neutron.common import constants as n_const from neutron import context from neutron.db import agents_db from neutron.db import common_db_mixin @@ -64,7 +64,7 @@ class L3HATestFramework(testlib_api.SqlTestCase): self.plugin.router_scheduler = l3_agent_scheduler.ChanceScheduler() self.agent1 = helpers.register_l3_agent() self.agent2 = helpers.register_l3_agent( - 'host_2', constants.L3_AGENT_MODE_DVR_SNAT) + 'host_2', n_const.L3_AGENT_MODE_DVR_SNAT) def _create_router(self, ha=True, tenant_id='tenant1', distributed=None, ctx=None, admin_state_up=True): @@ -198,19 +198,19 @@ class L3HATestCase(L3HATestFramework): def test_router_created_in_active_state(self): router = self._create_router() - self.assertEqual(constants.ROUTER_STATUS_ACTIVE, router['status']) + self.assertEqual(n_const.ROUTER_STATUS_ACTIVE, router['status']) def test_router_update_stay_active(self): router = self._create_router() router['name'] = 'test_update' router_updated = self.plugin._update_router_db(self.admin_ctx, router['id'], router) - self.assertEqual(constants.ROUTER_STATUS_ACTIVE, + self.assertEqual(n_const.ROUTER_STATUS_ACTIVE, router_updated['status']) def test_allocating_router_hidden_from_sync(self): r1, r2 = self._create_router(), self._create_router() - r1['status'] = constants.ROUTER_STATUS_ALLOCATING + r1['status'] = n_const.ROUTER_STATUS_ALLOCATING self.plugin._update_router_db(self.admin_ctx, r1['id'], r1) # store shorter name for readability get_method = self.plugin._get_active_l3_agent_routers_sync_data @@ -219,7 +219,7 @@ class L3HATestCase(L3HATestFramework): self.assertEqual(expected, get_method(self.admin_ctx, None, None, [r1['id'], r2['id']])) # but once it transitions back, all is well in the world again! - r1['status'] = constants.ROUTER_STATUS_ACTIVE + r1['status'] = n_const.ROUTER_STATUS_ACTIVE self.plugin._update_router_db(self.admin_ctx, r1['id'], r1) expected.append(self.plugin.get_router(self.admin_ctx, r1['id'])) # just compare ids since python3 won't let us sort dicts @@ -234,28 +234,28 @@ class L3HATestCase(L3HATestFramework): def check_state(context, router_id): self.assertEqual( - constants.ROUTER_STATUS_ALLOCATING, + n_const.ROUTER_STATUS_ALLOCATING, self.plugin._get_router(context, router_id)['status']) return _orig(context, router_id) with mock.patch.object(self.plugin, '_delete_ha_interfaces', side_effect=check_state) as ha_mock: router = self._migrate_router(router['id'], ha=False) self.assertTrue(ha_mock.called) - self.assertEqual(constants.ROUTER_STATUS_ACTIVE, + self.assertEqual(n_const.ROUTER_STATUS_ACTIVE, router['status']) def test_router_created_allocating_state_during_interface_create(self): _orig = self.plugin._create_ha_interfaces def check_state(context, router_db, ha_network): - self.assertEqual(constants.ROUTER_STATUS_ALLOCATING, + self.assertEqual(n_const.ROUTER_STATUS_ALLOCATING, router_db.status) return _orig(context, router_db, ha_network) with mock.patch.object(self.plugin, '_create_ha_interfaces', side_effect=check_state) as ha_mock: router = self._create_router() self.assertTrue(ha_mock.called) - self.assertEqual(constants.ROUTER_STATUS_ACTIVE, router['status']) + self.assertEqual(n_const.ROUTER_STATUS_ACTIVE, router['status']) def test_ha_router_create(self): router = self._create_router() @@ -730,7 +730,7 @@ class L3HATestCase(L3HATestFramework): routers = self.plugin.get_ha_sync_data_for_host( self.admin_ctx, self.agent1['host'], self.agent1) for router in routers: - self.assertEqual('standby', router[constants.HA_ROUTER_STATE_KEY]) + self.assertEqual('standby', router[n_const.HA_ROUTER_STATE_KEY]) states = {router1['id']: 'active', router2['id']: 'standby'} @@ -741,7 +741,7 @@ class L3HATestCase(L3HATestFramework): self.admin_ctx, self.agent1['host'], self.agent1) for router in routers: self.assertEqual(states[router['id']], - router[constants.HA_ROUTER_STATE_KEY]) + router[n_const.HA_ROUTER_STATE_KEY]) def test_set_router_states_handles_concurrently_deleted_router(self): router1 = self._create_router() @@ -754,7 +754,7 @@ class L3HATestCase(L3HATestFramework): router2['id']: 'active'}) routers = self.plugin.get_ha_sync_data_for_host( self.admin_ctx, self.agent1['host'], self.agent1) - self.assertEqual('active', routers[0][constants.HA_ROUTER_STATE_KEY]) + self.assertEqual('active', routers[0][n_const.HA_ROUTER_STATE_KEY]) def test_update_routers_states_port_not_found(self): router1 = self._create_router() @@ -777,7 +777,7 @@ class L3HATestCase(L3HATestFramework): # Test setup registers two l3 agents. # Register another l3 agent with dvr mode and assert that # get_number_of_ha_agent_candidates return 2. - helpers.register_l3_agent('host_3', constants.L3_AGENT_MODE_DVR) + helpers.register_l3_agent('host_3', n_const.L3_AGENT_MODE_DVR) num_ha_candidates = self.plugin.get_number_of_agents_for_scheduling( self.admin_ctx) self.assertEqual(2, num_ha_candidates) @@ -790,7 +790,7 @@ class L3HATestCase(L3HATestFramework): # Test setup registers two l3 agents. # Register another l3 agent with dvr mode and assert that # get_number_of_ha_agent_candidates return 2. - helpers.register_l3_agent('host_3', constants.L3_AGENT_MODE_DVR_SNAT) + helpers.register_l3_agent('host_3', n_const.L3_AGENT_MODE_DVR_SNAT) num_ha_candidates = self.plugin.get_number_of_agents_for_scheduling( self.admin_ctx) self.assertEqual(3, num_ha_candidates) @@ -927,13 +927,13 @@ class L3HAModeDbTestCase(L3HATestFramework): 'ip_version': 4, 'network_id': network_id, 'cidr': cidr, - 'gateway_ip': attributes.ATTR_NOT_SPECIFIED, - 'allocation_pools': attributes.ATTR_NOT_SPECIFIED, - 'dns_nameservers': attributes.ATTR_NOT_SPECIFIED, - 'host_routes': attributes.ATTR_NOT_SPECIFIED, + 'gateway_ip': constants.ATTR_NOT_SPECIFIED, + 'allocation_pools': constants.ATTR_NOT_SPECIFIED, + 'dns_nameservers': constants.ATTR_NOT_SPECIFIED, + 'host_routes': constants.ATTR_NOT_SPECIFIED, 'tenant_id': tenant_id, 'enable_dhcp': True, - 'ipv6_ra_mode': attributes.ATTR_NOT_SPECIFIED}} + 'ipv6_ra_mode': constants.ATTR_NOT_SPECIFIED}} created_subnet = plugin.create_subnet(ctx, subnet) return created_subnet diff --git a/neutron/tests/unit/db/test_securitygroups_db.py b/neutron/tests/unit/db/test_securitygroups_db.py index ee75d4870c2..d219476847c 100644 --- a/neutron/tests/unit/db/test_securitygroups_db.py +++ b/neutron/tests/unit/db/test_securitygroups_db.py @@ -12,6 +12,7 @@ # limitations under the License. import mock +from neutron_lib import constants import sqlalchemy import testtools @@ -19,7 +20,7 @@ from neutron.callbacks import events from neutron.callbacks import exceptions from neutron.callbacks import registry from neutron.callbacks import resources -from neutron.common import constants +from neutron.common import constants as n_const from neutron import context from neutron.db import common_db_mixin from neutron.db import securitygroups_db @@ -148,7 +149,7 @@ class SecurityGroupDbMixinTestCase(testlib_api.SqlTestCase): def test_validate_ethertype_and_protocol(self): fake_ipv4_rules = [{'protocol': constants.PROTO_NAME_IPV6_ICMP, 'ethertype': constants.IPv4}, - {'protocol': constants.PROTO_NAME_IPV6_ICMP_LEGACY, + {'protocol': n_const.PROTO_NAME_IPV6_ICMP_LEGACY, 'ethertype': constants.IPv4}, {'protocol': constants.PROTO_NAME_IPV6_ENCAP, 'ethertype': constants.IPv4}, diff --git a/neutron/tests/unit/extensions/test_address_scope.py b/neutron/tests/unit/extensions/test_address_scope.py index 75291d55f6e..dbee1ab021f 100644 --- a/neutron/tests/unit/extensions/test_address_scope.py +++ b/neutron/tests/unit/extensions/test_address_scope.py @@ -16,13 +16,13 @@ import contextlib import mock import netaddr +from neutron_lib import constants import webob.exc from neutron.api.v2 import attributes as attr from neutron.callbacks import events from neutron.callbacks import registry from neutron.callbacks import resources -from neutron.common import constants from neutron import context from neutron.db import address_scope_db from neutron.db import db_base_plugin_v2 diff --git a/neutron/tests/unit/extensions/test_agent.py b/neutron/tests/unit/extensions/test_agent.py index 687606beaac..f61a4072905 100644 --- a/neutron/tests/unit/extensions/test_agent.py +++ b/neutron/tests/unit/extensions/test_agent.py @@ -17,12 +17,13 @@ import copy from datetime import datetime import time +from neutron_lib import constants from oslo_config import cfg from oslo_utils import uuidutils from webob import exc from neutron.api.v2 import attributes -from neutron.common import constants +from neutron.common import constants as n_const from neutron import context from neutron.db import agents_db from neutron.db import db_base_plugin_v2 @@ -82,9 +83,9 @@ class AgentDBTestMixIn(object): def _register_agent_states(self, lbaas_agents=False): """Register two L3 agents and two DHCP agents.""" l3_hosta = helpers._get_l3_agent_dict( - L3_HOSTA, constants.L3_AGENT_MODE_LEGACY) + L3_HOSTA, n_const.L3_AGENT_MODE_LEGACY) l3_hostb = helpers._get_l3_agent_dict( - L3_HOSTB, constants.L3_AGENT_MODE_LEGACY) + L3_HOSTB, n_const.L3_AGENT_MODE_LEGACY) dhcp_hosta = helpers._get_dhcp_agent_dict(DHCP_HOSTA) dhcp_hostc = helpers._get_dhcp_agent_dict(DHCP_HOSTC) helpers.register_l3_agent(host=L3_HOSTA) @@ -117,9 +118,9 @@ class AgentDBTestMixIn(object): def _register_dvr_agents(self): dvr_snat_agent = helpers.register_l3_agent( - host=L3_HOSTA, agent_mode=constants.L3_AGENT_MODE_DVR_SNAT) + host=L3_HOSTA, agent_mode=n_const.L3_AGENT_MODE_DVR_SNAT) dvr_agent = helpers.register_l3_agent( - host=L3_HOSTB, agent_mode=constants.L3_AGENT_MODE_DVR) + host=L3_HOSTB, agent_mode=n_const.L3_AGENT_MODE_DVR) return [dvr_snat_agent, dvr_agent] def _register_l3_agent(self, host): diff --git a/neutron/tests/unit/extensions/test_default_subnetpools.py b/neutron/tests/unit/extensions/test_default_subnetpools.py index 5c49d7a171b..ee87a4c300e 100644 --- a/neutron/tests/unit/extensions/test_default_subnetpools.py +++ b/neutron/tests/unit/extensions/test_default_subnetpools.py @@ -11,10 +11,10 @@ # under the License. import netaddr +from neutron_lib import constants from oslo_config import cfg import webob.exc -from neutron.common import constants from neutron.db import db_base_plugin_v2 from neutron.extensions import default_subnetpools from neutron.tests.unit.db import test_db_base_plugin_v2 diff --git a/neutron/tests/unit/extensions/test_dns.py b/neutron/tests/unit/extensions/test_dns.py index 9733b3c3df7..c3ee54e1b5a 100644 --- a/neutron/tests/unit/extensions/test_dns.py +++ b/neutron/tests/unit/extensions/test_dns.py @@ -15,6 +15,7 @@ import math import netaddr +from neutron_lib import constants as n_const from oslo_config import cfg from neutron.common import constants @@ -86,7 +87,7 @@ class DnsExtensionTestCase(test_db_base_plugin_v2.TestNetworksV2): data['port'][arg] = kwargs[arg] # create a dhcp port device id if one hasn't been supplied if ('device_owner' in kwargs and - kwargs['device_owner'] == constants.DEVICE_OWNER_DHCP and + kwargs['device_owner'] == n_const.DEVICE_OWNER_DHCP and 'host' in kwargs and 'device_id' not in kwargs): device_id = utils.get_dhcp_agent_device_id(net_id, kwargs['host']) diff --git a/neutron/tests/unit/extensions/test_external_net.py b/neutron/tests/unit/extensions/test_external_net.py index 0e706836060..c54c5f0cc7e 100644 --- a/neutron/tests/unit/extensions/test_external_net.py +++ b/neutron/tests/unit/extensions/test_external_net.py @@ -14,11 +14,11 @@ # under the License. import mock +from neutron_lib import constants from oslo_utils import uuidutils import testtools from webob import exc -from neutron.common import constants from neutron import context from neutron.db import models_v2 from neutron.extensions import external_net as external_net diff --git a/neutron/tests/unit/extensions/test_extraroute.py b/neutron/tests/unit/extensions/test_extraroute.py index a63bb034317..82c1971339d 100644 --- a/neutron/tests/unit/extensions/test_extraroute.py +++ b/neutron/tests/unit/extensions/test_extraroute.py @@ -13,11 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from oslo_config import cfg from oslo_utils import uuidutils from webob import exc -from neutron.common import constants from neutron.common import utils from neutron import context from neutron.db import extraroute_db diff --git a/neutron/tests/unit/extensions/test_l3.py b/neutron/tests/unit/extensions/test_l3.py index 8438fcc96c9..09191ebfa1e 100644 --- a/neutron/tests/unit/extensions/test_l3.py +++ b/neutron/tests/unit/extensions/test_l3.py @@ -19,6 +19,7 @@ import copy import mock import netaddr +from neutron_lib import constants as l3_constants from neutron_lib import exceptions as n_exc from oslo_config import cfg from oslo_utils import importutils @@ -32,7 +33,7 @@ from neutron.callbacks import events 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 constants as n_const from neutron import context from neutron.db import common_db_mixin from neutron.db import db_base_plugin_v2 @@ -928,8 +929,8 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): self._create_subnet(self.fmt, net_id=n['network']['id'], ip_version=6, cidr='2001:db8:1::/64', - ipv6_ra_mode=l3_constants.IPV6_SLAAC, - ipv6_address_mode=l3_constants.IPV6_SLAAC)) + ipv6_ra_mode=n_const.IPV6_SLAAC, + ipv6_address_mode=n_const.IPV6_SLAAC)) res3 = self._show('routers', r['router']['id']) fips = (res3['router']['external_gateway_info'] ['external_fixed_ips']) @@ -997,9 +998,9 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): Verify the valid use-cases of an IPv6 subnet where we are allowed to associate to the Neutron Router are successful. """ - slaac = l3_constants.IPV6_SLAAC - stateful = l3_constants.DHCPV6_STATEFUL - stateless = l3_constants.DHCPV6_STATELESS + slaac = n_const.IPV6_SLAAC + stateful = n_const.DHCPV6_STATEFUL + stateless = n_const.DHCPV6_STATELESS use_cases = [{'msg': 'IPv6 Subnet Modes (slaac, none)', 'ra_mode': slaac, 'address_mode': None}, {'msg': 'IPv6 Subnet Modes (none, none)', @@ -1118,13 +1119,13 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): """ use_cases = [{'msg': 'IPv6 Subnet Modes (none, slaac)', 'ra_mode': None, - 'address_mode': l3_constants.IPV6_SLAAC}, + 'address_mode': n_const.IPV6_SLAAC}, {'msg': 'IPv6 Subnet Modes (none, dhcpv6-stateful)', 'ra_mode': None, - 'address_mode': l3_constants.DHCPV6_STATEFUL}, + 'address_mode': n_const.DHCPV6_STATEFUL}, {'msg': 'IPv6 Subnet Modes (none, dhcpv6-stateless)', 'ra_mode': None, - 'address_mode': l3_constants.DHCPV6_STATELESS}] + 'address_mode': n_const.DHCPV6_STATELESS}] for uc in use_cases: with self.router() as r, self.network() as n: with self.subnet(network=n, cidr='fd00::1/64', @@ -1466,18 +1467,18 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): self.subnet( cidr='2001:db8::/64', network=n, ip_version=6, - ipv6_ra_mode=l3_constants.IPV6_SLAAC, - ipv6_address_mode=l3_constants.IPV6_SLAAC)) as s3, ( + ipv6_ra_mode=n_const.IPV6_SLAAC, + ipv6_address_mode=n_const.IPV6_SLAAC)) as s3, ( self.subnet( cidr='2001:db8:1::/64', network=n, ip_version=6, - ipv6_ra_mode=l3_constants.DHCPV6_STATEFUL, - ipv6_address_mode=l3_constants.DHCPV6_STATEFUL)) as s4, ( + ipv6_ra_mode=n_const.DHCPV6_STATEFUL, + ipv6_address_mode=n_const.DHCPV6_STATEFUL)) as s4, ( self.subnet( cidr='2001:db8:2::/64', network=n, ip_version=6, - ipv6_ra_mode=l3_constants.DHCPV6_STATELESS, - ipv6_address_mode=l3_constants.DHCPV6_STATELESS)) as s5: + ipv6_ra_mode=n_const.DHCPV6_STATELESS, + ipv6_address_mode=n_const.DHCPV6_STATELESS)) as s5: self._set_net_external(n['network']['id']) self._add_external_gateway_to_router( r['router']['id'], @@ -2573,12 +2574,12 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): def test_router_delete_ipv6_slaac_subnet_inuse_returns_409(self): with self.router() as r: - with self._ipv6_subnet(l3_constants.IPV6_SLAAC) as s: + with self._ipv6_subnet(n_const.IPV6_SLAAC) as s: self._test_router_delete_subnet_inuse_returns_409(r, s) def test_router_delete_dhcpv6_stateless_subnet_inuse_returns_409(self): with self.router() as r: - with self._ipv6_subnet(l3_constants.DHCPV6_STATELESS) as s: + with self._ipv6_subnet(n_const.DHCPV6_STATELESS) as s: self._test_router_delete_subnet_inuse_returns_409(r, s) def test_delete_ext_net_with_disassociated_floating_ips(self): diff --git a/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py b/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py index d1d7aff1f41..3413667aa46 100644 --- a/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py +++ b/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py @@ -15,13 +15,13 @@ # import mock +from neutron_lib import constants from oslo_config import cfg from oslo_serialization import jsonutils from oslo_utils import uuidutils import testscenarios from webob import exc -from neutron.common import constants from neutron.db import api as db_api from neutron.db import external_net_db from neutron.db import l3_db diff --git a/neutron/tests/unit/extensions/test_securitygroup.py b/neutron/tests/unit/extensions/test_securitygroup.py index 893afb07d66..c7192181e13 100644 --- a/neutron/tests/unit/extensions/test_securitygroup.py +++ b/neutron/tests/unit/extensions/test_securitygroup.py @@ -16,6 +16,7 @@ import contextlib import mock +from neutron_lib import constants as const from oslo_config import cfg import oslo_db.exception as exc import six @@ -23,7 +24,7 @@ import testtools import webob.exc from neutron.api.v2 import attributes as attr -from neutron.common import constants as const +from neutron.common import constants as n_const from neutron.common import exceptions as n_exc from neutron import context from neutron.db import db_base_plugin_v2 @@ -843,7 +844,7 @@ class TestSecurityGroups(SecurityGroupDBTestCase): direction = "ingress" ethertype = const.IPv6 remote_ip_prefix = "2001::f401:56ff:fefe:d3dc/128" - protocol = const.PROTO_NAME_IPV6_ICMP_LEGACY + protocol = n_const.PROTO_NAME_IPV6_ICMP_LEGACY keys = [('remote_ip_prefix', remote_ip_prefix), ('security_group_id', security_group_id), ('direction', direction), diff --git a/neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_driver.py b/neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_driver.py index 8c0351bfbce..d0a04c9674e 100644 --- a/neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_driver.py +++ b/neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_driver.py @@ -15,10 +15,10 @@ import mock import netaddr +from neutron_lib import constants from neutron_lib import exceptions as n_exc -from neutron.api.v2 import attributes -from neutron.common import constants +from neutron.common import constants as n_const from neutron import context from neutron.db import api as ndb_api from neutron.ipam.drivers.neutrondb_ipam import driver @@ -44,18 +44,18 @@ class TestNeutronDbIpamMixin(object): return (created_network, created_network['id']) def _create_subnet(self, plugin, ctx, network_id, cidr, ip_version=4, - v6_address_mode=attributes.ATTR_NOT_SPECIFIED, - allocation_pools=attributes.ATTR_NOT_SPECIFIED): + v6_address_mode=constants.ATTR_NOT_SPECIFIED, + allocation_pools=constants.ATTR_NOT_SPECIFIED): subnet = {'subnet': {'name': 'sub', 'cidr': cidr, 'ip_version': ip_version, - 'gateway_ip': attributes.ATTR_NOT_SPECIFIED, + 'gateway_ip': constants.ATTR_NOT_SPECIFIED, 'allocation_pools': allocation_pools, 'enable_dhcp': True, - 'dns_nameservers': attributes.ATTR_NOT_SPECIFIED, - 'host_routes': attributes.ATTR_NOT_SPECIFIED, + 'dns_nameservers': constants.ATTR_NOT_SPECIFIED, + 'host_routes': constants.ATTR_NOT_SPECIFIED, 'ipv6_address_mode': v6_address_mode, - 'ipv6_ra_mode': attributes.ATTR_NOT_SPECIFIED, + 'ipv6_ra_mode': constants.ATTR_NOT_SPECIFIED, 'network_id': network_id, 'tenant_id': self._tenant_id}} return plugin.create_subnet(ctx, subnet) @@ -212,14 +212,14 @@ class TestNeutronDbIpamSubnet(testlib_api.SqlTestCase, """ def _create_and_allocate_ipam_subnet( - self, cidr, allocation_pools=attributes.ATTR_NOT_SPECIFIED, + self, cidr, allocation_pools=constants.ATTR_NOT_SPECIFIED, ip_version=4, v6_auto_address=False, tenant_id=None): - v6_address_mode = attributes.ATTR_NOT_SPECIFIED + v6_address_mode = constants.ATTR_NOT_SPECIFIED if v6_auto_address: # set ip version to 6 regardless of what's been passed to the # method ip_version = 6 - v6_address_mode = constants.IPV6_SLAAC + v6_address_mode = n_const.IPV6_SLAAC subnet = self._create_subnet( self.plugin, self.ctx, self.net_id, cidr, ip_version=ip_version, diff --git a/neutron/tests/unit/ipam/test_requests.py b/neutron/tests/unit/ipam/test_requests.py index 84d71417fe3..735a1dd0b85 100644 --- a/neutron/tests/unit/ipam/test_requests.py +++ b/neutron/tests/unit/ipam/test_requests.py @@ -12,10 +12,10 @@ import mock import netaddr +from neutron_lib import constants from oslo_config import cfg from oslo_utils import uuidutils -from neutron.common import constants from neutron.common import ipv6_utils from neutron import context from neutron.ipam import driver diff --git a/neutron/tests/unit/ipam/test_subnet_alloc.py b/neutron/tests/unit/ipam/test_subnet_alloc.py index 8b4942941f3..689e87ee54a 100644 --- a/neutron/tests/unit/ipam/test_subnet_alloc.py +++ b/neutron/tests/unit/ipam/test_subnet_alloc.py @@ -15,12 +15,11 @@ import mock import netaddr +from neutron_lib import constants from oslo_config import cfg from oslo_db import exception as db_exc from oslo_utils import uuidutils -from neutron.api.v2 import attributes -from neutron.common import constants from neutron.common import exceptions as n_exc from neutron import context from neutron.ipam import requests as ipam_req @@ -42,9 +41,9 @@ class TestSubnetAllocation(testlib_api.SqlTestCase): def _create_subnet_pool(self, plugin, ctx, name, prefix_list, min_prefixlen, ip_version, - max_prefixlen=attributes.ATTR_NOT_SPECIFIED, - default_prefixlen=attributes.ATTR_NOT_SPECIFIED, - default_quota=attributes.ATTR_NOT_SPECIFIED, + max_prefixlen=constants.ATTR_NOT_SPECIFIED, + default_prefixlen=constants.ATTR_NOT_SPECIFIED, + default_quota=constants.ATTR_NOT_SPECIFIED, shared=False, is_default=False): subnetpool = {'subnetpool': {'name': name, 'tenant_id': self._tenant_id, diff --git a/neutron/tests/unit/notifiers/test_nova.py b/neutron/tests/unit/notifiers/test_nova.py index 3315196c955..256f5f9eed5 100644 --- a/neutron/tests/unit/notifiers/test_nova.py +++ b/neutron/tests/unit/notifiers/test_nova.py @@ -15,12 +15,12 @@ import mock +from neutron_lib import constants as n_const from novaclient import exceptions as nova_exceptions from oslo_config import cfg from oslo_utils import uuidutils from sqlalchemy.orm import attributes as sql_attr -from neutron.common import constants as n_const from neutron.db import models_v2 from neutron.notifiers import nova from neutron.tests import base diff --git a/neutron/tests/unit/objects/qos/test_rule.py b/neutron/tests/unit/objects/qos/test_rule.py index aa9468a580a..60c56e290f9 100644 --- a/neutron/tests/unit/objects/qos/test_rule.py +++ b/neutron/tests/unit/objects/qos/test_rule.py @@ -10,7 +10,8 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron.common import constants +from neutron_lib import constants + from neutron.objects.qos import policy from neutron.objects.qos import rule from neutron.services.qos import qos_consts diff --git a/neutron/tests/unit/objects/test_common_types.py b/neutron/tests/unit/objects/test_common_types.py index 9463f294a74..fb1fe096c4c 100644 --- a/neutron/tests/unit/objects/test_common_types.py +++ b/neutron/tests/unit/objects/test_common_types.py @@ -13,6 +13,8 @@ import abc +from neutron_lib import constants as const + from neutron.common import constants from neutron.objects import common_types from neutron.tests import base as test_base @@ -164,7 +166,7 @@ class IpProtocolEnumFieldTest(test_base.BaseTestCase, TestField): self.field = common_types.IpProtocolEnumField() self.coerce_good_values = [(val, val) for val in - list(constants.IP_PROTOCOL_MAP.keys())] + list(const.IP_PROTOCOL_MAP.keys())] self.coerce_bad_values = ['test', '8', 10, 'Udp'] self.to_primitive_values = self.coerce_good_values self.from_primitive_values = self.coerce_good_values diff --git a/neutron/tests/unit/plugins/common/test_utils.py b/neutron/tests/unit/plugins/common/test_utils.py index c899243a4e2..f61444192c9 100644 --- a/neutron/tests/unit/plugins/common/test_utils.py +++ b/neutron/tests/unit/plugins/common/test_utils.py @@ -15,8 +15,8 @@ import hashlib import mock +from neutron_lib import constants -from neutron.common import constants from neutron.plugins.common import utils from neutron.tests import base diff --git a/neutron/tests/unit/plugins/ml2/drivers/agent/test__common_agent.py b/neutron/tests/unit/plugins/ml2/drivers/agent/test__common_agent.py index ebee051de4e..6a2b2d110ca 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/agent/test__common_agent.py +++ b/neutron/tests/unit/plugins/ml2/drivers/agent/test__common_agent.py @@ -15,10 +15,11 @@ # under the License. import mock +from neutron_lib import constants from oslo_config import cfg from neutron.agent.linux import bridge_lib -from neutron.common import constants +from neutron.common import constants as n_const from neutron.plugins.ml2.drivers.agent import _agent_manager_base as amb from neutron.plugins.ml2.drivers.agent import _common_agent as ca from neutron.tests import base @@ -464,7 +465,7 @@ class TestCommonAgentLoop(base.BaseTestCase): def test_report_state_revived(self): with mock.patch.object(self.agent.state_rpc, "report_state") as report_st: - report_st.return_value = constants.AGENT_REVIVED + report_st.return_value = n_const.AGENT_REVIVED self.agent._report_state() self.assertTrue(self.agent.fullsync) diff --git a/neutron/tests/unit/plugins/ml2/drivers/l2pop/rpc_manager/test_l2population_rpc.py b/neutron/tests/unit/plugins/ml2/drivers/l2pop/rpc_manager/test_l2population_rpc.py index d8a39a32b66..c72e95f7633 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/l2pop/rpc_manager/test_l2population_rpc.py +++ b/neutron/tests/unit/plugins/ml2/drivers/l2pop/rpc_manager/test_l2population_rpc.py @@ -15,8 +15,8 @@ # under the License. import mock +from neutron_lib import constants as n_const -from neutron.common import constants as n_const from neutron.tests.unit.plugins.ml2.drivers.l2pop.rpc_manager \ import l2population_rpc_base diff --git a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_db.py b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_db.py index 212e4af9215..a6c3fd5db56 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_db.py +++ b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_db.py @@ -12,7 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron.common import constants +from neutron_lib import constants + from neutron import context from neutron.db import models_v2 from neutron.extensions import portbindings diff --git a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py index 9022db9418b..22114fed607 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py +++ b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py @@ -14,10 +14,11 @@ # under the License. import mock +from neutron_lib import constants from oslo_serialization import jsonutils import testtools -from neutron.common import constants +from neutron.common import constants as n_const from neutron.common import topics from neutron import context from neutron.extensions import portbindings @@ -434,7 +435,7 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase): cidr='2001:db8::/64', ip_version=6, gateway_ip='fe80::1', - ipv6_address_mode=constants.IPV6_SLAAC) as subnet2: + ipv6_address_mode=n_const.IPV6_SLAAC) as subnet2: with self.port( subnet, fixed_ips=[{'subnet_id': subnet['subnet']['id']}, diff --git a/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py b/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py index a1ac66f3343..fe6228d4286 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py +++ b/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py @@ -16,12 +16,12 @@ import collections import sys import mock +from neutron_lib import constants from oslo_config import cfg from neutron.agent.linux import bridge_lib from neutron.agent.linux import ip_lib from neutron.agent.linux import utils -from neutron.common import constants from neutron.common import exceptions from neutron.plugins.common import constants as p_const from neutron.plugins.ml2.drivers.agent import _agent_manager_base as amb diff --git a/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/mech_driver/test_mech_linuxbridge.py b/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/mech_driver/test_mech_linuxbridge.py index fb28aad9c39..22b854b0277 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/mech_driver/test_mech_linuxbridge.py +++ b/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/mech_driver/test_mech_linuxbridge.py @@ -13,7 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron.common import constants +from neutron_lib import constants + from neutron.extensions import portbindings from neutron.plugins.ml2.drivers.linuxbridge.mech_driver \ import mech_linuxbridge diff --git a/neutron/tests/unit/plugins/ml2/drivers/macvtap/mech_driver/test_mech_macvtap.py b/neutron/tests/unit/plugins/ml2/drivers/macvtap/mech_driver/test_mech_macvtap.py index 918b153d9b7..a07b6a834f0 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/macvtap/mech_driver/test_mech_macvtap.py +++ b/neutron/tests/unit/plugins/ml2/drivers/macvtap/mech_driver/test_mech_macvtap.py @@ -13,7 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron.common import constants +from neutron_lib import constants + from neutron.extensions import portbindings from neutron.plugins.ml2.drivers.macvtap.mech_driver import mech_macvtap from neutron.tests.unit.plugins.ml2 import _test_mech_agent as base diff --git a/neutron/tests/unit/plugins/ml2/drivers/mech_fake_agent.py b/neutron/tests/unit/plugins/ml2/drivers/mech_fake_agent.py index 2c8744a4d1b..bd3a02a76c6 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/mech_fake_agent.py +++ b/neutron/tests/unit/plugins/ml2/drivers/mech_fake_agent.py @@ -20,8 +20,9 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants + from neutron.agent import securitygroups_rpc -from neutron.common import constants from neutron.extensions import portbindings from neutron.plugins.common import constants as p_constants from neutron.plugins.ml2.drivers import mech_agent diff --git a/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/mech_driver/test_mech_sriov_nic_switch.py b/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/mech_driver/test_mech_sriov_nic_switch.py index 211d4bf1ee4..b47ce85555f 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/mech_driver/test_mech_sriov_nic_switch.py +++ b/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/mech_driver/test_mech_sriov_nic_switch.py @@ -14,10 +14,10 @@ # limitations under the License. import mock +from neutron_lib import constants from oslo_config import cfg import testtools -from neutron.common import constants from neutron.extensions import portbindings from neutron.plugins.common import constants as p_const from neutron.plugins.ml2 import config # noqa diff --git a/neutron/tests/unit/plugins/ml2/drivers/mechanism_test.py b/neutron/tests/unit/plugins/ml2/drivers/mechanism_test.py index d58ec8bb0e0..1ec73073430 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/mechanism_test.py +++ b/neutron/tests/unit/plugins/ml2/drivers/mechanism_test.py @@ -13,7 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron.common import constants as const +from neutron_lib import constants as const + from neutron.extensions import portbindings from neutron.plugins.ml2 import driver_api as api diff --git a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/openflow/ovs_ofctl/ovs_bridge_test_base.py b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/openflow/ovs_ofctl/ovs_bridge_test_base.py index 75297e6962b..e845c978175 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/openflow/ovs_ofctl/ovs_bridge_test_base.py +++ b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/openflow/ovs_ofctl/ovs_bridge_test_base.py @@ -15,8 +15,8 @@ # under the License. import mock +from neutron_lib import constants -from neutron.common import constants from neutron.tests.unit.plugins.ml2.drivers.openvswitch.agent \ import ovs_test_base diff --git a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/openflow/ovs_ofctl/test_br_int.py b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/openflow/ovs_ofctl/test_br_int.py index 5dc9a0c2ffb..418bff51a54 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/openflow/ovs_ofctl/test_br_int.py +++ b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/openflow/ovs_ofctl/test_br_int.py @@ -15,8 +15,9 @@ # under the License. import mock +from neutron_lib import constants as const -from neutron.common import constants as const +from neutron.common import constants as n_const from neutron.tests.unit.plugins.ml2.drivers.openvswitch.agent.\ openflow.ovs_ofctl import ovs_bridge_test_base @@ -192,17 +193,17 @@ class OVSIntegrationBridgeTest(ovs_bridge_test_base.OVSBridgeTestBase): ip_addresses = ['2001:db8::1', 'fdf8:f53b:82e4::1/128'] self.br.install_icmpv6_na_spoofing_protection(port, ip_addresses) expected = [ - call.add_flow(dl_type=const.ETHERTYPE_IPV6, actions='normal', + call.add_flow(dl_type=n_const.ETHERTYPE_IPV6, actions='normal', icmp_type=const.ICMPV6_TYPE_NA, nw_proto=const.PROTO_NUM_IPV6_ICMP, nd_target='2001:db8::1', priority=2, table=24, in_port=8888), - call.add_flow(dl_type=const.ETHERTYPE_IPV6, actions='normal', + call.add_flow(dl_type=n_const.ETHERTYPE_IPV6, actions='normal', icmp_type=const.ICMPV6_TYPE_NA, nw_proto=const.PROTO_NUM_IPV6_ICMP, nd_target='fdf8:f53b:82e4::1/128', priority=2, table=24, in_port=8888), - call.add_flow(dl_type=const.ETHERTYPE_IPV6, + call.add_flow(dl_type=n_const.ETHERTYPE_IPV6, icmp_type=const.ICMPV6_TYPE_NA, nw_proto=const.PROTO_NUM_IPV6_ICMP, priority=10, table=0, in_port=8888, diff --git a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py index bd98ed61311..8ec60b4d93b 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py +++ b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py @@ -16,6 +16,7 @@ import sys import time import mock +from neutron_lib import constants as n_const from oslo_config import cfg from oslo_log import log import oslo_messaging @@ -26,7 +27,7 @@ from neutron.agent.common import ovs_lib from neutron.agent.common import utils from neutron.agent.linux import async_process from neutron.agent.linux import ip_lib -from neutron.common import constants as n_const +from neutron.common import constants as c_const from neutron.plugins.common import constants as p_const from neutron.plugins.ml2.drivers.l2pop import rpc as l2pop_rpc from neutron.plugins.ml2.drivers.openvswitch.agent.common import constants @@ -968,7 +969,7 @@ class TestOvsNeutronAgent(object): def test_report_state_revived(self): with mock.patch.object(self.agent.state_rpc, "report_state") as report_st: - report_st.return_value = n_const.AGENT_REVIVED + report_st.return_value = c_const.AGENT_REVIVED self.agent._report_state() self.assertTrue(self.agent.fullsync) diff --git a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_tunnel.py b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_tunnel.py index cbdcba8d65a..1fe9efa4313 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_tunnel.py +++ b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_tunnel.py @@ -17,13 +17,13 @@ import time import mock +from neutron_lib import constants as n_const from oslo_config import cfg from oslo_log import log import six from neutron.agent.common import ip_lib from neutron.agent.common import ovs_lib -from neutron.common import constants as n_const from neutron.plugins.common import constants as p_const from neutron.plugins.ml2.drivers.openvswitch.agent.common import constants from neutron.tests.unit.plugins.ml2.drivers.openvswitch.agent \ diff --git a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/mech_driver/test_mech_openvswitch.py b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/mech_driver/test_mech_openvswitch.py index 801479a109d..1c2edb084a5 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/mech_driver/test_mech_openvswitch.py +++ b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/mech_driver/test_mech_openvswitch.py @@ -13,9 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from oslo_config import cfg -from neutron.common import constants from neutron.extensions import portbindings from neutron.plugins.ml2.drivers.openvswitch.mech_driver \ import mech_openvswitch diff --git a/neutron/tests/unit/plugins/ml2/extensions/fake_extension.py b/neutron/tests/unit/plugins/ml2/extensions/fake_extension.py index bc739e4e118..d247c7d392c 100644 --- a/neutron/tests/unit/plugins/ml2/extensions/fake_extension.py +++ b/neutron/tests/unit/plugins/ml2/extensions/fake_extension.py @@ -10,30 +10,31 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants + from neutron._i18n import _ from neutron.api import extensions -from neutron.api.v2 import attributes as attr EXTENDED_ATTRIBUTES_2_0 = { 'networks': { 'network_extension': {'allow_post': True, 'allow_put': True, - 'default': attr.ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'is_visible': True, 'enforce_policy': True}, }, 'subnets': { 'subnet_extension': {'allow_post': True, 'allow_put': True, - 'default': attr.ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'is_visible': True, 'enforce_policy': True}, }, 'ports': { 'port_extension': {'allow_post': True, 'allow_put': True, - 'default': attr.ATTR_NOT_SPECIFIED, + 'default': constants.ATTR_NOT_SPECIFIED, 'is_visible': True, 'enforce_policy': True}, }, diff --git a/neutron/tests/unit/plugins/ml2/test_db.py b/neutron/tests/unit/plugins/ml2/test_db.py index c231ad58fb2..d145e9efc1b 100644 --- a/neutron/tests/unit/plugins/ml2/test_db.py +++ b/neutron/tests/unit/plugins/ml2/test_db.py @@ -16,10 +16,10 @@ import warnings import mock +from neutron_lib import constants from oslo_utils import uuidutils from sqlalchemy.orm import query -from neutron.common import constants from neutron import context from neutron.db import db_base_plugin_v2 from neutron.db import l3_db diff --git a/neutron/tests/unit/plugins/ml2/test_driver_context.py b/neutron/tests/unit/plugins/ml2/test_driver_context.py index e30349c9c6c..253f7b48f98 100644 --- a/neutron/tests/unit/plugins/ml2/test_driver_context.py +++ b/neutron/tests/unit/plugins/ml2/test_driver_context.py @@ -14,8 +14,8 @@ # under the License. import mock +from neutron_lib import constants -from neutron.common import constants from neutron.extensions import portbindings from neutron.plugins.ml2 import driver_context from neutron.tests import base diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py index 348fcea75ae..6ed3678f660 100644 --- a/neutron/tests/unit/plugins/ml2/test_plugin.py +++ b/neutron/tests/unit/plugins/ml2/test_plugin.py @@ -22,6 +22,7 @@ import six import testtools import webob +from neutron_lib import constants from neutron_lib import exceptions as exc from oslo_db import exception as db_exc from oslo_utils import uuidutils @@ -31,7 +32,6 @@ from neutron._i18n import _ from neutron.callbacks import events from neutron.callbacks import registry from neutron.callbacks import resources -from neutron.common import constants from neutron.common import utils from neutron import context from neutron.db import agents_db diff --git a/neutron/tests/unit/plugins/ml2/test_port_binding.py b/neutron/tests/unit/plugins/ml2/test_port_binding.py index ad9e1c2669c..09bf9bf4e5d 100644 --- a/neutron/tests/unit/plugins/ml2/test_port_binding.py +++ b/neutron/tests/unit/plugins/ml2/test_port_binding.py @@ -14,8 +14,8 @@ # under the License. import mock +from neutron_lib import constants as const -from neutron.common import constants as const from neutron import context from neutron.extensions import portbindings from neutron import manager diff --git a/neutron/tests/unit/plugins/ml2/test_rpc.py b/neutron/tests/unit/plugins/ml2/test_rpc.py index 83931f017d5..8dc7f9c700f 100644 --- a/neutron/tests/unit/plugins/ml2/test_rpc.py +++ b/neutron/tests/unit/plugins/ml2/test_rpc.py @@ -20,6 +20,7 @@ Unit Tests for ml2 rpc import collections import mock +from neutron_lib import constants from neutron_lib import exceptions from oslo_config import cfg from oslo_context import context as oslo_context @@ -27,7 +28,6 @@ import oslo_messaging from sqlalchemy.orm import exc from neutron.agent import rpc as agent_rpc -from neutron.common import constants from neutron.common import topics from neutron.plugins.ml2.drivers import type_tunnel from neutron.plugins.ml2 import managers diff --git a/neutron/tests/unit/plugins/ml2/test_security_group.py b/neutron/tests/unit/plugins/ml2/test_security_group.py index 3389a77fb96..67e0f5428f1 100644 --- a/neutron/tests/unit/plugins/ml2/test_security_group.py +++ b/neutron/tests/unit/plugins/ml2/test_security_group.py @@ -17,8 +17,8 @@ import math import mock +from neutron_lib import constants as const -from neutron.common import constants as const from neutron import context from neutron.extensions import securitygroup as ext_sg from neutron import manager diff --git a/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py b/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py index 0d87bda9744..699cc78f1ea 100644 --- a/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py +++ b/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py @@ -14,11 +14,11 @@ # limitations under the License. import mock +from neutron_lib import constants from oslo_config import cfg from oslo_utils import importutils import testscenarios -from neutron.common import constants from neutron import context from neutron.db import agentschedulers_db as sched_db from neutron.db import common_db_mixin diff --git a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py index 2c8206f565d..fbc7270deff 100644 --- a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py +++ b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py @@ -19,13 +19,14 @@ import datetime import uuid import mock +from neutron_lib import constants from oslo_config import cfg from oslo_utils import importutils from oslo_utils import timeutils from sqlalchemy import orm import testscenarios -from neutron.common import constants +from neutron.common import constants as n_const from neutron import context as n_context from neutron.db import agents_db from neutron.db import common_db_mixin @@ -286,18 +287,18 @@ class L3SchedulerBaseMixin(object): def _register_l3_agents(self, plugin=None): self.agent1 = helpers.register_l3_agent( - 'host_1', constants.L3_AGENT_MODE_LEGACY) + 'host_1', n_const.L3_AGENT_MODE_LEGACY) self.agent_id1 = self.agent1.id self.agent2 = helpers.register_l3_agent( - 'host_2', constants.L3_AGENT_MODE_LEGACY) + 'host_2', n_const.L3_AGENT_MODE_LEGACY) self.agent_id2 = self.agent2.id def _register_l3_dvr_agents(self): self.l3_dvr_agent = helpers.register_l3_agent( - HOST_DVR, constants.L3_AGENT_MODE_DVR) + HOST_DVR, n_const.L3_AGENT_MODE_DVR) self.l3_dvr_agent_id = self.l3_dvr_agent.id self.l3_dvr_snat_agent = helpers.register_l3_agent( - HOST_DVR_SNAT, constants.L3_AGENT_MODE_DVR_SNAT) + HOST_DVR_SNAT, n_const.L3_AGENT_MODE_DVR_SNAT) self.l3_dvr_snat_id = self.l3_dvr_snat_agent.id def _set_l3_agent_admin_state(self, context, agent_id, state=True): diff --git a/neutron/tests/unit/test_policy.py b/neutron/tests/unit/test_policy.py index c87084f8b5a..5f1aa1384a3 100644 --- a/neutron/tests/unit/test_policy.py +++ b/neutron/tests/unit/test_policy.py @@ -16,6 +16,7 @@ """Test of Policy Engine For Neutron""" import mock +from neutron_lib import constants as const from neutron_lib import exceptions from oslo_db import exception as db_exc from oslo_policy import fixture as op_fixture @@ -25,7 +26,7 @@ from oslo_utils import importutils import neutron from neutron.api.v2 import attributes -from neutron.common import constants as const +from neutron.common import constants as n_const from neutron.common import exceptions as n_exc from neutron import context from neutron import manager @@ -358,7 +359,7 @@ class NeutronPolicyTestCase(base.BaseTestCase): self._test_advsvc_action_on_attr('get', 'port', 'shared', False) def test_advsvc_update_port_works(self): - kwargs = {const.ATTRIBUTES_TO_UPDATE: ['shared']} + kwargs = {n_const.ATTRIBUTES_TO_UPDATE: ['shared']} self._test_advsvc_action_on_attr('update', 'port', 'shared', True, **kwargs) @@ -415,11 +416,11 @@ class NeutronPolicyTestCase(base.BaseTestCase): self._test_enforce_adminonly_attribute('create_network') def test_enforce_adminonly_attribute_update(self): - kwargs = {const.ATTRIBUTES_TO_UPDATE: ['shared']} + kwargs = {n_const.ATTRIBUTES_TO_UPDATE: ['shared']} self._test_enforce_adminonly_attribute('update_network', **kwargs) def test_reset_adminonly_attr_to_default_fails(self): - kwargs = {const.ATTRIBUTES_TO_UPDATE: ['shared']} + kwargs = {n_const.ATTRIBUTES_TO_UPDATE: ['shared']} self._test_nonadmin_action_on_attr('update', 'shared', False, oslo_policy.PolicyNotAuthorized, **kwargs)