diff --git a/neutron/agent/l3/agent.py b/neutron/agent/l3/agent.py index ee04eeb877d..2aa036aef24 100644 --- a/neutron/agent/l3/agent.py +++ b/neutron/agent/l3/agent.py @@ -372,7 +372,7 @@ class L3NATAgent(ha.AgentMixin, self.l3_ext_manager = ( l3_ext_manager.L3AgentExtensionsManager(self.conf)) self.l3_ext_manager.initialize( - connection, l3_constants.L3_AGENT_MODE) + connection, lib_const.L3_AGENT_MODE) def router_deleted(self, context, router_id): """Deal with router deletion RPC message.""" @@ -560,7 +560,7 @@ class L3NATAgent(ha.AgentMixin, ext_net_id = (r['external_gateway_info'] or {}).get( 'network_id') is_snat_agent = (self.conf.agent_mode == - l3_constants.L3_AGENT_MODE_DVR_SNAT) + lib_const.L3_AGENT_MODE_DVR_SNAT) if ext_net_id: ns_manager.keep_ext_net(ext_net_id) elif is_snat_agent: diff --git a/neutron/agent/l3/dvr_edge_ha_router.py b/neutron/agent/l3/dvr_edge_ha_router.py index 6cd0dca7026..9e0f257bce3 100644 --- a/neutron/agent/l3/dvr_edge_ha_router.py +++ b/neutron/agent/l3/dvr_edge_ha_router.py @@ -19,7 +19,6 @@ from neutron.agent.l3 import dvr_edge_router from neutron.agent.l3 import dvr_snat_ns from neutron.agent.l3 import ha_router from neutron.agent.l3 import router_info -from neutron.common import constants as l3_constants class DvrEdgeHaRouter(dvr_edge_router.DvrEdgeRouter, @@ -105,7 +104,7 @@ class DvrEdgeHaRouter(dvr_edge_router.DvrEdgeRouter, def _is_this_snat_host(self): return (self.agent_conf.agent_mode - == l3_constants.L3_AGENT_MODE_DVR_SNAT) + == constants.L3_AGENT_MODE_DVR_SNAT) def _dvr_internal_network_removed(self, port): super(DvrEdgeHaRouter, self)._dvr_internal_network_removed(port) diff --git a/neutron/agent/l3/dvr_edge_router.py b/neutron/agent/l3/dvr_edge_router.py index 56b7ca87cf1..44c467d516b 100644 --- a/neutron/agent/l3/dvr_edge_router.py +++ b/neutron/agent/l3/dvr_edge_router.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron_lib import constants as l3_constants +from neutron_lib import constants as lib_constants from oslo_log import log as logging from neutron._i18n import _LE @@ -235,8 +235,8 @@ class DvrEdgeRouter(dvr_local_router.DvrLocalRouter): if external_port: external_port_scopemark = self._get_port_devicename_scopemark( [external_port], self.get_external_device_name) - for ip_version in (l3_constants.IP_VERSION_4, - l3_constants.IP_VERSION_6): + for ip_version in (lib_constants.IP_VERSION_4, + lib_constants.IP_VERSION_6): ports_scopemark[ip_version].update( external_port_scopemark[ip_version]) diff --git a/neutron/agent/l3/dvr_local_router.py b/neutron/agent/l3/dvr_local_router.py index 40f6b4e6e5b..882280514c2 100644 --- a/neutron/agent/l3/dvr_local_router.py +++ b/neutron/agent/l3/dvr_local_router.py @@ -16,7 +16,8 @@ import binascii import collections import netaddr -from neutron_lib import constants as l3_constants +from neutron_lib import constants as lib_constants +from neutron_lib import exceptions from oslo_log import log as logging from oslo_utils import excutils import six @@ -26,7 +27,6 @@ from neutron.agent.l3 import dvr_fip_ns from neutron.agent.l3 import dvr_router_base from neutron.agent.linux import ip_lib from neutron.common import constants as n_const -from neutron.common import exceptions from neutron.common import utils as common_utils LOG = logging.getLogger(__name__) @@ -163,18 +163,18 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase): # Special Handling for DVR - update FIP namespace ip_cidr = common_utils.ip_to_cidr(fip['floating_ip_address']) self.floating_ip_added_dist(fip, ip_cidr) - return l3_constants.FLOATINGIP_STATUS_ACTIVE + return lib_constants.FLOATINGIP_STATUS_ACTIVE def remove_floating_ip(self, device, ip_cidr): self.floating_ip_removed_dist(ip_cidr) def move_floating_ip(self, fip): self.floating_ip_moved_dist(fip) - return l3_constants.FLOATINGIP_STATUS_ACTIVE + return lib_constants.FLOATINGIP_STATUS_ACTIVE def _get_internal_port(self, subnet_id): """Return internal router port based on subnet_id.""" - router_ports = self.router.get(l3_constants.INTERFACE_KEY, []) + router_ports = self.router.get(lib_constants.INTERFACE_KEY, []) for port in router_ports: fips = port['fixed_ips'] for f in fips: @@ -252,7 +252,7 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase): subnet_ports = self.agent.get_ports_by_subnet(subnet_id) for p in subnet_ports: - if p['device_owner'] not in l3_constants.ROUTER_INTERFACE_OWNERS: + if p['device_owner'] not in lib_constants.ROUTER_INTERFACE_OWNERS: for fixed_ip in p['fixed_ips']: self._update_arp_entry(fixed_ip['ip_address'], p['mac_address'], @@ -460,7 +460,7 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase): def _get_address_scope_mark(self): # Prepare address scope iptables rule for internal ports - internal_ports = self.router.get(l3_constants.INTERFACE_KEY, []) + internal_ports = self.router.get(lib_constants.INTERFACE_KEY, []) ports_scopemark = self._get_port_devicename_scopemark( internal_ports, self.get_internal_device_name) # DVR local router will use rfp port as external port @@ -474,7 +474,7 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase): ext_scope = self._get_external_address_scope() ext_scope_mark = self.get_address_scope_mark_mask(ext_scope) - ports_scopemark[l3_constants.IP_VERSION_4][ext_device_name] = ( + ports_scopemark[lib_constants.IP_VERSION_4][ext_device_name] = ( ext_scope_mark) return ports_scopemark @@ -536,7 +536,7 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase): self.router_id) rtr_2_fip, _fip_2_rtr = self.rtr_fip_subnet.get_pair() exist_routes = device.route.list_routes( - l3_constants.IP_VERSION_4, via=str(rtr_2_fip.ip)) + lib_constants.IP_VERSION_4, via=str(rtr_2_fip.ip)) return {common_utils.ip_to_cidr(route['cidr']) for route in exist_routes} diff --git a/neutron/agent/l3/dvr_snat_ns.py b/neutron/agent/l3/dvr_snat_ns.py index d3a911dda70..9639add690a 100644 --- a/neutron/agent/l3/dvr_snat_ns.py +++ b/neutron/agent/l3/dvr_snat_ns.py @@ -10,11 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from oslo_log import log as logging from neutron.agent.l3 import namespaces from neutron.agent.linux import ip_lib -from neutron.common import constants LOG = logging.getLogger(__name__) SNAT_NS_PREFIX = 'snat-' diff --git a/neutron/agent/l3/legacy_router.py b/neutron/agent/l3/legacy_router.py index 56ad76882ac..6c24f345f3a 100644 --- a/neutron/agent/l3/legacy_router.py +++ b/neutron/agent/l3/legacy_router.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron_lib import constants as l3_constants +from neutron_lib import constants as lib_constants from neutron.agent.l3 import router_info as router from neutron.agent.linux import ip_lib @@ -21,7 +21,7 @@ from neutron.agent.linux import ip_lib class LegacyRouter(router.RouterInfo): def add_floating_ip(self, fip, interface_name, device): if not self._add_fip_addr_to_device(fip, device): - return l3_constants.FLOATINGIP_STATUS_ERROR + return lib_constants.FLOATINGIP_STATUS_ERROR # As GARP is processed in a distinct thread the call below # won't raise an exception to be handled. @@ -29,4 +29,4 @@ class LegacyRouter(router.RouterInfo): interface_name, fip['floating_ip_address'], self.agent_conf) - return l3_constants.FLOATINGIP_STATUS_ACTIVE + return lib_constants.FLOATINGIP_STATUS_ACTIVE diff --git a/neutron/agent/l3/router_info.py b/neutron/agent/l3/router_info.py index 4e0745bcf1b..42ea9fd601b 100644 --- a/neutron/agent/l3/router_info.py +++ b/neutron/agent/l3/router_info.py @@ -14,7 +14,7 @@ import collections import netaddr -from neutron_lib import constants as l3_constants +from neutron_lib import constants as lib_constants from oslo_log import log as logging from neutron._i18n import _, _LE, _LW @@ -143,7 +143,7 @@ class RouterInfo(object): def get_floating_ips(self): """Filter Floating IPs to be hosted on this agent.""" - return self.router.get(l3_constants.FLOATINGIP_KEY, []) + return self.router.get(lib_constants.FLOATINGIP_KEY, []) def floating_forward_rules(self, floating_ip, fixed_ip): return [('PREROUTING', '-d %s/32 -j DNAT --to-destination %s' % @@ -226,7 +226,7 @@ class RouterInfo(object): ports_scopemark = self._get_address_scope_mark() devices_in_ext_scope = { device for device, mark - in ports_scopemark[l3_constants.IP_VERSION_4].items() + in ports_scopemark[lib_constants.IP_VERSION_4].items() if mark == ext_scope_mark} # Add address scope for floatingip egress for device in devices_in_ext_scope: @@ -279,7 +279,7 @@ class RouterInfo(object): device.delete_addr_and_conntrack_state(ip_cidr) def move_floating_ip(self, fip): - return l3_constants.FLOATINGIP_STATUS_ACTIVE + return lib_constants.FLOATINGIP_STATUS_ACTIVE def remove_external_gateway_ip(self, device, ip_cidr): device.delete_addr_and_conntrack_state(ip_cidr) @@ -311,7 +311,7 @@ class RouterInfo(object): fip_ip = fip['floating_ip_address'] ip_cidr = common_utils.ip_to_cidr(fip_ip) new_cidrs.add(ip_cidr) - fip_statuses[fip['id']] = l3_constants.FLOATINGIP_STATUS_ACTIVE + fip_statuses[fip['id']] = lib_constants.FLOATINGIP_STATUS_ACTIVE if ip_cidr not in existing_cidrs: fip_statuses[fip['id']] = self.add_floating_ip( fip, interface_name, device) @@ -346,7 +346,7 @@ class RouterInfo(object): for ip_addr in ex_gw_port['fixed_ips']: ex_gw_ip = ip_addr['ip_address'] addr = netaddr.IPAddress(ex_gw_ip) - if addr.version == l3_constants.IP_VERSION_4: + if addr.version == lib_constants.IP_VERSION_4: gw_cidrs.add(common_utils.ip_to_cidr(ex_gw_ip)) return gw_cidrs @@ -361,14 +361,14 @@ class RouterInfo(object): def put_fips_in_error_state(self): fip_statuses = {} - for fip in self.router.get(l3_constants.FLOATINGIP_KEY, []): - fip_statuses[fip['id']] = l3_constants.FLOATINGIP_STATUS_ERROR + for fip in self.router.get(lib_constants.FLOATINGIP_KEY, []): + fip_statuses[fip['id']] = lib_constants.FLOATINGIP_STATUS_ERROR return fip_statuses def delete(self, agent): self.router['gw_port'] = None - self.router[l3_constants.INTERFACE_KEY] = [] - self.router[l3_constants.FLOATINGIP_KEY] = [] + self.router[lib_constants.INTERFACE_KEY] = [] + self.router[lib_constants.FLOATINGIP_KEY] = [] self.process_delete(agent) self.disable_radvd() self.router_namespace.delete() @@ -487,7 +487,7 @@ class RouterInfo(object): def _process_internal_ports(self, pd): existing_port_ids = set(p['id'] for p in self.internal_ports) - internal_ports = self.router.get(l3_constants.INTERFACE_KEY, []) + internal_ports = self.router.get(lib_constants.INTERFACE_KEY, []) current_port_ids = set(p['id'] for p in internal_ports if p['admin_state_up']) @@ -643,8 +643,8 @@ class RouterInfo(object): device = ip_lib.IPDevice(interface_name, namespace=ns_name) current_gateways = set() - for ip_version in (l3_constants.IP_VERSION_4, - l3_constants.IP_VERSION_6): + for ip_version in (lib_constants.IP_VERSION_4, + lib_constants.IP_VERSION_6): gateway = device.route.get_gateway(ip_version=ip_version) if gateway and gateway.get('gateway'): current_gateways.add(gateway.get('gateway')) @@ -856,7 +856,7 @@ class RouterInfo(object): existing_floating_ips = self.floating_ips self.floating_ips = set(fip_statuses.keys()) for fip_id in existing_floating_ips - self.floating_ips: - fip_statuses[fip_id] = l3_constants.FLOATINGIP_STATUS_DOWN + fip_statuses[fip_id] = lib_constants.FLOATINGIP_STATUS_DOWN # filter out statuses that didn't change fip_statuses = {f: stat for f, stat in fip_statuses.items() if stat != FLOATINGIP_STATUS_NOCHANGE} @@ -915,8 +915,8 @@ class RouterInfo(object): 'PREROUTING', copy_address_scope_for_existing) def _get_port_devicename_scopemark(self, ports, name_generator): - devicename_scopemark = {l3_constants.IP_VERSION_4: dict(), - l3_constants.IP_VERSION_6: dict()} + devicename_scopemark = {lib_constants.IP_VERSION_4: dict(), + lib_constants.IP_VERSION_6: dict()} for p in ports: device_name = name_generator(p['id']) ip_cidrs = common_utils.fixed_ip_cidrs(p['fixed_ips']) @@ -930,7 +930,7 @@ class RouterInfo(object): def _get_address_scope_mark(self): # Prepare address scope iptables rule for internal ports - internal_ports = self.router.get(l3_constants.INTERFACE_KEY, []) + internal_ports = self.router.get(lib_constants.INTERFACE_KEY, []) ports_scopemark = self._get_port_devicename_scopemark( internal_ports, self.get_internal_device_name) @@ -939,8 +939,8 @@ class RouterInfo(object): if external_port: external_port_scopemark = self._get_port_devicename_scopemark( [external_port], self.get_external_device_name) - for ip_version in (l3_constants.IP_VERSION_4, - l3_constants.IP_VERSION_6): + for ip_version in (lib_constants.IP_VERSION_4, + lib_constants.IP_VERSION_6): ports_scopemark[ip_version].update( external_port_scopemark[ip_version]) return ports_scopemark @@ -953,13 +953,13 @@ class RouterInfo(object): external_port['id']) # Process address scope iptables rules - for ip_version in (l3_constants.IP_VERSION_4, - l3_constants.IP_VERSION_6): + for ip_version in (lib_constants.IP_VERSION_4, + lib_constants.IP_VERSION_6): scopemarks = ports_scopemark[ip_version] iptables = iptables_manager.get_tables(ip_version) iptables['mangle'].empty_chain('scope') iptables['filter'].empty_chain('scope') - dont_block_external = (ip_version == l3_constants.IP_VERSION_4 + dont_block_external = (ip_version == lib_constants.IP_VERSION_4 and self._snat_enabled and external_port) for device_name, mark in scopemarks.items(): # Add address scope iptables rule @@ -982,7 +982,7 @@ class RouterInfo(object): return scopes = external_port.get('address_scopes', {}) - return scopes.get(str(l3_constants.IP_VERSION_4)) + return scopes.get(str(lib_constants.IP_VERSION_4)) def process_external_port_address_scope_routing(self, iptables_manager): if not self._snat_enabled: diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index d36c24195a5..e5d7c4e7c0d 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -353,8 +353,8 @@ class Dnsmasq(DhcpLocalProcess): # static to preserve previous behavior addr_mode = getattr(subnet, 'ipv6_address_mode', None) ra_mode = getattr(subnet, 'ipv6_ra_mode', None) - if (addr_mode in [n_const.DHCPV6_STATEFUL, - n_const.DHCPV6_STATELESS] or + if (addr_mode in [constants.DHCPV6_STATEFUL, + constants.DHCPV6_STATELESS] or not addr_mode and not ra_mode): mode = 'static' @@ -510,7 +510,7 @@ class Dnsmasq(DhcpLocalProcess): fixed_ips, key=lambda fip: ((fip.subnet_id in v6_nets) and ( v6_nets[fip.subnet_id].ipv6_address_mode == ( - n_const.DHCPV6_STATELESS))), + constants.DHCPV6_STATELESS))), reverse=True) def _iter_hosts(self): @@ -545,11 +545,11 @@ class Dnsmasq(DhcpLocalProcess): no_opts = False if alloc.subnet_id in v6_nets: addr_mode = v6_nets[alloc.subnet_id].ipv6_address_mode - no_dhcp = addr_mode in (n_const.IPV6_SLAAC, - n_const.DHCPV6_STATELESS) + no_dhcp = addr_mode in (constants.IPV6_SLAAC, + constants.DHCPV6_STATELESS) # we don't setup anything for SLAAC. It doesn't make sense # to provide options for a client that won't use DHCP - no_opts = addr_mode == n_const.IPV6_SLAAC + no_opts = addr_mode == constants.IPV6_SLAAC # If dns_name attribute is supported by ports API, return the # dns_assignment generated by the Neutron server. Otherwise, @@ -770,7 +770,7 @@ class Dnsmasq(DhcpLocalProcess): addr_mode = getattr(subnet, 'ipv6_address_mode', None) if (not subnet.enable_dhcp or (subnet.ip_version == 6 and - addr_mode == n_const.IPV6_SLAAC)): + addr_mode == constants.IPV6_SLAAC)): continue if subnet.dns_nameservers: options.append( diff --git a/neutron/agent/linux/ip_lib.py b/neutron/agent/linux/ip_lib.py index 7be09c39177..469e6d3f03b 100644 --- a/neutron/agent/linux/ip_lib.py +++ b/neutron/agent/linux/ip_lib.py @@ -699,7 +699,7 @@ class IpRouteCommand(IpDeviceCommandBase): with excutils.save_and_reraise_exception() as ctx: if "Cannot find device" in str(rte): ctx.reraise = False - raise n_exc.DeviceNotFoundError(device_name=self.name) + raise exceptions.DeviceNotFoundError(device_name=self.name) def delete_gateway(self, gateway, table=None): ip_version = get_ip_version(gateway) diff --git a/neutron/agent/linux/ra.py b/neutron/agent/linux/ra.py index 304d344edbe..4c8c745d27e 100644 --- a/neutron/agent/linux/ra.py +++ b/neutron/agent/linux/ra.py @@ -17,6 +17,7 @@ from itertools import chain as iter_chain import jinja2 import netaddr +from neutron_lib import constants from oslo_config import cfg from oslo_log import log as logging import six @@ -24,7 +25,7 @@ import six from neutron._i18n import _ from neutron.agent.linux import external_process from neutron.agent.linux import utils -from neutron.common import constants +from neutron.common import constants as n_const from neutron.common import utils as common_utils @@ -53,7 +54,7 @@ CONFIG_TEMPLATE = jinja2.Template("""interface {{ interface_name }} MinRtrAdvInterval {{ min_rtr_adv_interval }}; MaxRtrAdvInterval {{ max_rtr_adv_interval }}; - {% if network_mtu >= constants.IPV6_MIN_MTU %} + {% if network_mtu >= n_const.IPV6_MIN_MTU %} AdvLinkMTU {{network_mtu}}; {% endif %} @@ -132,6 +133,7 @@ class DaemonMonitor(object): auto_config_prefixes=auto_config_prefixes, stateful_config_prefixes=stateful_config_prefixes, dns_servers=dns_servers[0:MAX_RDNSS_ENTRIES], + n_const=n_const, constants=constants, min_rtr_adv_interval=self._agent_conf.min_rtr_adv_interval, max_rtr_adv_interval=self._agent_conf.max_rtr_adv_interval, diff --git a/neutron/api/api_common.py b/neutron/api/api_common.py index 50d02c52681..087f0649577 100644 --- a/neutron/api/api_common.py +++ b/neutron/api/api_common.py @@ -28,7 +28,6 @@ from webob import exc from neutron._i18n import _, _LW from neutron.common import constants -from neutron.common import exceptions as n_exc from neutron import wsgi @@ -386,7 +385,7 @@ class NeutronController(object): def convert_exception_to_http_exc(e, faults, language): serializer = wsgi.JSONDictSerializer() - if isinstance(e, n_exc.MultipleExceptions): + if isinstance(e, exceptions.MultipleExceptions): converted_exceptions = [ convert_exception_to_http_exc(inner, faults, language) for inner in e.inner_exceptions] diff --git a/neutron/api/v2/attributes.py b/neutron/api/v2/attributes.py index d6a7776990f..9d1281484c6 100644 --- a/neutron/api/v2/attributes.py +++ b/neutron/api/v2/attributes.py @@ -24,7 +24,6 @@ import webob.exc from neutron._i18n import _ from neutron.common import _deprecate -from neutron.common import constants as n_const # Defining a constant to avoid repeating string literal in several modules @@ -280,12 +279,12 @@ RESOURCE_ATTRIBUTE_MAP = { 'is_visible': True}, 'ipv6_ra_mode': {'allow_post': True, 'allow_put': False, 'default': constants.ATTR_NOT_SPECIFIED, - 'validate': {'type:values': n_const.IPV6_MODES}, + 'validate': {'type:values': constants.IPV6_MODES}, 'is_visible': True}, 'ipv6_address_mode': {'allow_post': True, 'allow_put': False, 'default': constants.ATTR_NOT_SPECIFIED, 'validate': {'type:values': - n_const.IPV6_MODES}, + constants.IPV6_MODES}, 'is_visible': True}, SHARED: {'allow_post': False, 'allow_put': False, diff --git a/neutron/api/v2/router.py b/neutron/api/v2/router.py index 6389c834916..93b19f7de69 100644 --- a/neutron/api/v2/router.py +++ b/neutron/api/v2/router.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_service import wsgi as base_wsgi import routes as routes_mapper @@ -38,7 +39,7 @@ RESOURCES = {'network': 'networks', SUB_RESOURCES = {} COLLECTION_ACTIONS = ['index', 'create'] MEMBER_ACTIONS = ['show', 'update', 'delete'] -REQUIREMENTS = {'id': attributes.UUID_PATTERN, 'format': 'json'} +REQUIREMENTS = {'id': constants.UUID_PATTERN, 'format': 'json'} class Index(wsgi.Application): diff --git a/neutron/callbacks/exceptions.py b/neutron/callbacks/exceptions.py index f0049c5c811..3020def98a4 100644 --- a/neutron/callbacks/exceptions.py +++ b/neutron/callbacks/exceptions.py @@ -13,14 +13,13 @@ from neutron_lib import exceptions from neutron._i18n import _ -from neutron.common import exceptions as n_exc class Invalid(exceptions.NeutronException): message = _("The value '%(value)s' for %(element)s is not valid.") -class CallbackFailure(n_exc.MultipleExceptions): +class CallbackFailure(exceptions.MultipleExceptions): def __init__(self, errors): self.errors = errors diff --git a/neutron/common/constants.py b/neutron/common/constants.py index 960ce0b2135..2a6ae8acef8 100644 --- a/neutron/common/constants.py +++ b/neutron/common/constants.py @@ -135,8 +135,6 @@ DVR_FIP_LL_CIDR = '169.254.64.0/18' L3_HA_NET_CIDR = '169.254.192.0/18' METADATA_CIDR = '169.254.169.254/32' -DEVICE_OWNER_BAREMETAL_PREFIX = "baremetal:" - # Neutron-lib migration shim. This will wrap any constants that are moved # to that library in a deprecation warning, until they can be updated to # import directly from their new location. diff --git a/neutron/common/exceptions.py b/neutron/common/exceptions.py index 570c31e3438..203ec4e8a20 100644 --- a/neutron/common/exceptions.py +++ b/neutron/common/exceptions.py @@ -21,19 +21,6 @@ from neutron._i18n import _ from neutron.common import _deprecate -class MultipleExceptions(Exception): - """Container for multiple exceptions encountered. - - The API layer of Neutron will automatically unpack, translate, - filter, and combine the inner exceptions in any exception derived - from this class. - """ - - def __init__(self, exceptions, *args, **kwargs): - super(MultipleExceptions, self).__init__(*args, **kwargs) - self.inner_exceptions = exceptions - - class SubnetPoolNotFound(e.NotFound): message = _("Subnet pool %(subnetpool_id)s could not be found.") @@ -57,14 +44,6 @@ class NetworkQosBindingNotFound(e.NotFound): "could not be found.") -class PolicyInitError(e.NeutronException): - message = _("Failed to init policy %(policy)s because %(reason)s.") - - -class PolicyCheckError(e.NeutronException): - message = _("Failed to check policy %(policy)s because %(reason)s.") - - class PolicyRemoveAuthorizationError(e.NotAuthorized): message = _("Failed to remove provided policy %(policy_id)s " "because you are not authorized.") @@ -313,10 +292,6 @@ class SubnetPoolQuotaExceeded(e.OverQuota): message = _("Per-tenant subnet pool prefix quota exceeded.") -class DeviceNotFoundError(e.NeutronException): - message = _("Device '%(device_name)s' does not exist.") - - class NetworkSubnetPoolAffinityError(e.BadRequest): message = _("Subnets hosted on the same network must be allocated from " "the same subnet pool.") diff --git a/neutron/conf/agent/l3/config.py b/neutron/conf/agent/l3/config.py index 2de81d61c0f..4040e270c2c 100644 --- a/neutron/conf/agent/l3/config.py +++ b/neutron/conf/agent/l3/config.py @@ -14,11 +14,11 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib import constants from oslo_config import cfg from neutron._i18n import _ from neutron.agent.common import config -from neutron.common import constants OPTS = [ diff --git a/neutron/db/api.py b/neutron/db/api.py index 39df781cdfe..23efcbcdd4e 100644 --- a/neutron/db/api.py +++ b/neutron/db/api.py @@ -17,6 +17,7 @@ import contextlib from debtcollector import moves from debtcollector import removals +from neutron_lib import exceptions from oslo_config import cfg from oslo_db import api as oslo_db_api from oslo_db import exception as db_exc @@ -29,7 +30,6 @@ import sqlalchemy from sqlalchemy.orm import exc import traceback -from neutron.common import exceptions from neutron.common import profiler # noqa @@ -106,12 +106,12 @@ def _is_nested_instance(e, etypes): @contextlib.contextmanager -def exc_to_retry(exceptions): +def exc_to_retry(etypes): try: yield except Exception as e: with excutils.save_and_reraise_exception() as ctx: - if _is_nested_instance(e, exceptions): + if _is_nested_instance(e, etypes): ctx.reraise = False raise db_exc.RetryRequest(e) diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 2504808c7c4..b9a05ffd5e9 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -558,8 +558,8 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, "subnets.") raise exc.BadRequest(resource='subnets', msg=reason) - mode_list = [n_const.IPV6_SLAAC, - n_const.DHCPV6_STATELESS] + mode_list = [constants.IPV6_SLAAC, + constants.DHCPV6_STATELESS] ra_mode = subnet.get('ipv6_ra_mode') if ra_mode not in mode_list: diff --git a/neutron/db/external_net_db.py b/neutron/db/external_net_db.py index 6fee03235f9..e075e2e7db3 100644 --- a/neutron/db/external_net_db.py +++ b/neutron/db/external_net_db.py @@ -14,7 +14,7 @@ # under the License. from neutron_lib.api import validators -from neutron_lib import constants as l3_constants +from neutron_lib import constants as lib_constants from neutron_lib import exceptions as n_exc import sqlalchemy as sa from sqlalchemy import orm @@ -39,7 +39,7 @@ from neutron import manager from neutron.plugins.common import constants as service_constants -DEVICE_OWNER_ROUTER_GW = l3_constants.DEVICE_OWNER_ROUTER_GW +DEVICE_OWNER_ROUTER_GW = lib_constants.DEVICE_OWNER_ROUTER_GW class ExternalNetwork(model_base.BASEV2): diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py index c31f1c02347..e4f2d044854 100644 --- a/neutron/db/l3_db.py +++ b/neutron/db/l3_db.py @@ -18,7 +18,7 @@ import itertools from debtcollector import removals import netaddr from neutron_lib.api import validators -from neutron_lib import constants as l3_constants +from neutron_lib import constants as lib_constants from neutron_lib import exceptions as n_exc from oslo_log import log as logging from oslo_utils import excutils @@ -54,10 +54,10 @@ from neutron.plugins.common import utils as p_utils LOG = logging.getLogger(__name__) -DEVICE_OWNER_HA_REPLICATED_INT = l3_constants.DEVICE_OWNER_HA_REPLICATED_INT -DEVICE_OWNER_ROUTER_INTF = l3_constants.DEVICE_OWNER_ROUTER_INTF -DEVICE_OWNER_ROUTER_GW = l3_constants.DEVICE_OWNER_ROUTER_GW -DEVICE_OWNER_FLOATINGIP = l3_constants.DEVICE_OWNER_FLOATINGIP +DEVICE_OWNER_HA_REPLICATED_INT = lib_constants.DEVICE_OWNER_HA_REPLICATED_INT +DEVICE_OWNER_ROUTER_INTF = lib_constants.DEVICE_OWNER_ROUTER_INTF +DEVICE_OWNER_ROUTER_GW = lib_constants.DEVICE_OWNER_ROUTER_GW +DEVICE_OWNER_FLOATINGIP = lib_constants.DEVICE_OWNER_FLOATINGIP EXTERNAL_GW_INFO = l3.EXTERNAL_GW_INFO # Maps API field to DB column @@ -288,12 +288,12 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, def update_router(self, context, id, router): r = router['router'] - gw_info = r.pop(EXTERNAL_GW_INFO, l3_constants.ATTR_NOT_SPECIFIED) + gw_info = r.pop(EXTERNAL_GW_INFO, lib_constants.ATTR_NOT_SPECIFIED) # check whether router needs and can be rescheduled to the proper # l3 agent (associated with given external network); # do check before update in DB as an exception will be raised # in case no proper l3 agent found - if gw_info != l3_constants.ATTR_NOT_SPECIFIED: + if gw_info != lib_constants.ATTR_NOT_SPECIFIED: candidates = self._check_router_needs_rescheduling( context, id, gw_info) # Update the gateway outside of the DB update since it involves L2 @@ -341,7 +341,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, constants.L3_ROUTER_NAT) if (not utils.is_extension_supported( l3_plugin, - l3_constants.L3_AGENT_SCHEDULER_EXT_ALIAS) or + lib_constants.L3_AGENT_SCHEDULER_EXT_ALIAS) or l3_plugin.router_scheduler is None): # that might mean that we are dealing with non-agent-based # implementation of l3 services @@ -378,7 +378,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, # Port has no 'tenant-id', as it is hidden from user port_data = {'tenant_id': '', # intentionally not set 'network_id': network_id, - 'fixed_ips': ext_ips or l3_constants.ATTR_NOT_SPECIFIED, + 'fixed_ips': ext_ips or lib_constants.ATTR_NOT_SPECIFIED, 'device_id': router['id'], 'device_owner': DEVICE_OWNER_ROUTER_GW, 'admin_state_up': True, @@ -1018,11 +1018,11 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, RouterPort.router_id, models_v2.IPAllocation.ip_address).join( models_v2.Port, models_v2.IPAllocation).filter( models_v2.Port.network_id == internal_port['network_id'], - RouterPort.port_type.in_(l3_constants.ROUTER_INTERFACE_OWNERS), + RouterPort.port_type.in_(lib_constants.ROUTER_INTERFACE_OWNERS), models_v2.IPAllocation.subnet_id == internal_subnet['id'] ).join(gw_port, gw_port.device_id == RouterPort.router_id).filter( gw_port.network_id == external_network_id, - gw_port.device_owner == l3_constants.DEVICE_OWNER_ROUTER_GW + gw_port.device_owner == lib_constants.DEVICE_OWNER_ROUTER_GW ).distinct() first_router_id = None @@ -1171,7 +1171,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, gw_port = router.gw_port for fixed_ip in gw_port.fixed_ips: addr = netaddr.IPAddress(fixed_ip.ip_address) - if addr.version == l3_constants.IP_VERSION_4: + if addr.version == lib_constants.IP_VERSION_4: next_hop = fixed_ip.ip_address break args = {'fixed_ip_address': internal_ip_address, @@ -1192,7 +1192,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, return any(s.ip_version == 4 for s in net.subnets) def _create_floatingip(self, context, floatingip, - initial_status=l3_constants.FLOATINGIP_STATUS_ACTIVE): + initial_status=lib_constants.FLOATINGIP_STATUS_ACTIVE): fip = floatingip['floatingip'] fip_id = uuidutils.generate_uuid() @@ -1215,7 +1215,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, 'admin_state_up': True, 'device_id': fip_id, 'device_owner': DEVICE_OWNER_FLOATINGIP, - 'status': l3_constants.PORT_STATUS_NOTAPPLICABLE, + 'status': lib_constants.PORT_STATUS_NOTAPPLICABLE, 'name': ''} if fip.get('floating_ip_address'): port['fixed_ips'] = [ @@ -1268,7 +1268,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, return floatingip_dict def create_floatingip(self, context, floatingip, - initial_status=l3_constants.FLOATINGIP_STATUS_ACTIVE): + initial_status=lib_constants.FLOATINGIP_STATUS_ACTIVE): return self._create_floatingip(context, floatingip, initial_status) def _update_floatingip(self, context, id, floatingip): @@ -1606,8 +1606,8 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, port['subnets'] = [] port['extra_subnets'] = [] - port['address_scopes'] = {l3_constants.IP_VERSION_4: None, - l3_constants.IP_VERSION_6: None} + port['address_scopes'] = {lib_constants.IP_VERSION_4: None, + lib_constants.IP_VERSION_6: None} scopes = {} for subnet in subnets_by_network[port['network_id']]: @@ -1642,18 +1642,18 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, for floating_ip in floating_ips: router = routers_dict.get(floating_ip['router_id']) if router: - router_floatingips = router.get(l3_constants.FLOATINGIP_KEY, + router_floatingips = router.get(lib_constants.FLOATINGIP_KEY, []) router_floatingips.append(floating_ip) - router[l3_constants.FLOATINGIP_KEY] = router_floatingips + router[lib_constants.FLOATINGIP_KEY] = router_floatingips def _process_interfaces(self, routers_dict, interfaces): for interface in interfaces: router = routers_dict.get(interface['device_id']) if router: - router_interfaces = router.get(l3_constants.INTERFACE_KEY, []) + router_interfaces = router.get(lib_constants.INTERFACE_KEY, []) router_interfaces.append(interface) - router[l3_constants.INTERFACE_KEY] = router_interfaces + router[lib_constants.INTERFACE_KEY] = router_interfaces def _get_router_info_list(self, context, router_ids=None, active=None, device_owners=None): @@ -1780,7 +1780,7 @@ class L3_NAT_db_mixin(L3_NAT_dbonly_mixin, L3RpcNotifierMixin): return router_interface_info def create_floatingip(self, context, floatingip, - initial_status=l3_constants.FLOATINGIP_STATUS_ACTIVE): + initial_status=lib_constants.FLOATINGIP_STATUS_ACTIVE): floatingip_dict = super(L3_NAT_db_mixin, self).create_floatingip( context, floatingip, initial_status) router_id = floatingip_dict['router_id'] @@ -1852,7 +1852,7 @@ def _notify_subnet_gateway_ip_update(resource, event, trigger, **kwargs): subnet_id = kwargs['subnet_id'] query = context.session.query(models_v2.Port).filter_by( network_id=network_id, - device_owner=l3_constants.DEVICE_OWNER_ROUTER_GW) + device_owner=lib_constants.DEVICE_OWNER_ROUTER_GW) query = query.join(models_v2.Port.fixed_ips).filter( models_v2.IPAllocation.subnet_id == subnet_id) router_ids = set(port['device_id'] for port in query) diff --git a/neutron/db/migration/alembic_migrations/versions/newton/contract/a8b517cff8ab_add_routerport_bindings_for_ha.py b/neutron/db/migration/alembic_migrations/versions/newton/contract/a8b517cff8ab_add_routerport_bindings_for_ha.py index edc46c4c20e..eed0fdfb623 100644 --- a/neutron/db/migration/alembic_migrations/versions/newton/contract/a8b517cff8ab_add_routerport_bindings_for_ha.py +++ b/neutron/db/migration/alembic_migrations/versions/newton/contract/a8b517cff8ab_add_routerport_bindings_for_ha.py @@ -23,6 +23,7 @@ revision = 'a8b517cff8ab' down_revision = '7d9d8eeec6ad' from alembic import op +from neutron_lib import constants as lib_const import sqlalchemy as sa from neutron.common import constants @@ -57,11 +58,11 @@ def upgrade(): # as a result of Ifd3e007aaf2a2ed8123275aa3a9f540838e3c003 being # back-ported for router_port in session.query(router_ports).filter( - router_ports.c.port_type == constants.DEVICE_OWNER_ROUTER_HA_INTF): + router_ports.c.port_type == lib_const.DEVICE_OWNER_ROUTER_HA_INTF): router_port_tuples.discard((router_port.router_id, router_port.port_id)) new_records = [dict(router_id=router_id, port_id=port_id, - port_type=constants.DEVICE_OWNER_ROUTER_HA_INTF) + port_type=lib_const.DEVICE_OWNER_ROUTER_HA_INTF) for router_id, port_id in router_port_tuples] op.bulk_insert(router_ports, new_records) session.commit() diff --git a/neutron/db/migration/alembic_migrations/versions/newton/expand/030a959ceafa_uniq_routerports0port_id.py b/neutron/db/migration/alembic_migrations/versions/newton/expand/030a959ceafa_uniq_routerports0port_id.py index 9f562163c6f..c6751db6ff1 100644 --- a/neutron/db/migration/alembic_migrations/versions/newton/expand/030a959ceafa_uniq_routerports0port_id.py +++ b/neutron/db/migration/alembic_migrations/versions/newton/expand/030a959ceafa_uniq_routerports0port_id.py @@ -26,12 +26,11 @@ revision = '030a959ceafa' down_revision = '3d0e74aa7d37' from alembic import op +from neutron_lib import exceptions import sqlalchemy as sa from neutron._i18n import _ -from neutron.common import exceptions - routerports = sa.Table( 'routerports', sa.MetaData(), sa.Column('router_id', sa.String(36)), diff --git a/neutron/db/models_v2.py b/neutron/db/models_v2.py index a173c590959..29595f5eecc 100644 --- a/neutron/db/models_v2.py +++ b/neutron/db/models_v2.py @@ -213,11 +213,13 @@ class Subnet(model_base.HasStandardAttributes, model_base.BASEV2, ipv6_ra_mode = sa.Column(sa.Enum(constants.IPV6_SLAAC, constants.DHCPV6_STATEFUL, constants.DHCPV6_STATELESS, - name='ipv6_ra_modes'), nullable=True) + name='ipv6_ra_modes'), + nullable=True) ipv6_address_mode = sa.Column(sa.Enum(constants.IPV6_SLAAC, - constants.DHCPV6_STATEFUL, - constants.DHCPV6_STATELESS, - name='ipv6_address_modes'), nullable=True) + constants.DHCPV6_STATEFUL, + constants.DHCPV6_STATELESS, + name='ipv6_address_modes'), + nullable=True) # subnets don't have their own rbac_entries, they just inherit from # the network rbac entries rbac_entries = orm.relationship( diff --git a/neutron/notifiers/nova.py b/neutron/notifiers/nova.py index 20f40485982..22cd409c6fd 100644 --- a/neutron/notifiers/nova.py +++ b/neutron/notifiers/nova.py @@ -27,7 +27,6 @@ from neutron._i18n import _LE, _LI, _LW from neutron.callbacks import events from neutron.callbacks import registry from neutron.callbacks import resources -from neutron.common import constants as n_const from neutron import context from neutron import manager from neutron.notifiers import batch_notifier @@ -87,7 +86,7 @@ class Notifier(object): if (port['device_id'] and uuidutils.is_uuid_like(port['device_id']) and port['device_owner'].startswith(( constants.DEVICE_OWNER_COMPUTE_PREFIX, - n_const.DEVICE_OWNER_BAREMETAL_PREFIX))): + constants.DEVICE_OWNER_BAREMETAL_PREFIX))): return True except (KeyError, AttributeError): pass diff --git a/neutron/objects/common_types.py b/neutron/objects/common_types.py index c4777c8a8ed..c1c3e04be2d 100644 --- a/neutron/objects/common_types.py +++ b/neutron/objects/common_types.py @@ -14,13 +14,13 @@ import itertools import netaddr -from neutron_lib import constants as n_const +from neutron_lib import constants as lib_constants +from neutron_lib import exceptions from oslo_versionedobjects import fields as obj_fields import six from neutron._i18n import _ from neutron.common import constants -from neutron.common import exceptions class NeutronRangeConstrainedIntegerInvalidLimit(exceptions.NeutronException): @@ -29,7 +29,7 @@ class NeutronRangeConstrainedIntegerInvalidLimit(exceptions.NeutronException): class IPV6ModeEnumField(obj_fields.AutoTypedField): - AUTO_TYPE = obj_fields.Enum(valid_values=constants.IPV6_MODES) + AUTO_TYPE = obj_fields.Enum(valid_values=lib_constants.IPV6_MODES) class RangeConstrainedInteger(obj_fields.Integer): @@ -56,7 +56,7 @@ class IPNetworkPrefixLen(RangeConstrainedInteger): """IP network (CIDR) prefix length custom Enum""" def __init__(self, **kwargs): super(IPNetworkPrefixLen, self).__init__( - start=0, end=n_const.IPv6_BITS, + start=0, end=lib_constants.IPv6_BITS, **kwargs) @@ -139,8 +139,8 @@ class IpProtocolEnum(obj_fields.Enum): super(IpProtocolEnum, self).__init__( valid_values=list( itertools.chain( - n_const.IP_PROTOCOL_MAP.keys(), - [str(v) for v in n_const.IP_PROTOCOL_MAP.values()] + lib_constants.IP_PROTOCOL_MAP.keys(), + [str(v) for v in lib_constants.IP_PROTOCOL_MAP.values()] ) ), **kwargs) diff --git a/neutron/pecan_wsgi/hooks/policy_enforcement.py b/neutron/pecan_wsgi/hooks/policy_enforcement.py index 60e97f8a30f..a0ca98a3118 100644 --- a/neutron/pecan_wsgi/hooks/policy_enforcement.py +++ b/neutron/pecan_wsgi/hooks/policy_enforcement.py @@ -176,7 +176,7 @@ class PolicyHook(hooks.PecanHook): # This exception must be explicitly caught as the exception # translation hook won't be called if an error occurs in the # 'after' handler. - raise webob.exc.HTTPForbidden(e.message) + raise webob.exc.HTTPForbidden(str(e)) if is_single: resp = resp[0] 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 905d2aa8a26..4eedc5b76d2 100644 --- a/neutron/plugins/ml2/drivers/l2pop/rpc_manager/l2population_rpc.py +++ b/neutron/plugins/ml2/drivers/l2pop/rpc_manager/l2population_rpc.py @@ -239,7 +239,8 @@ class L2populationRpcCallBackTunnelMixin(L2populationRpcCallBackMixin): if local_vlan_map is not None: vlanmanager.deprecate_local_vlan_map_in_object( - "%s.get_agent_ports()" % self.__class__.__name__) + "%s.get_agent_ports()" % self.__class__.__name__, + stacklevel_extra=1) return get_lvm_from_mapping return get_lvm_from_manager diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/vlanmanager.py b/neutron/plugins/ml2/drivers/openvswitch/agent/vlanmanager.py index fd2a0fc1f52..d575358d733 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/vlanmanager.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/vlanmanager.py @@ -19,10 +19,11 @@ from neutron_lib import exceptions from neutron._i18n import _ -def deprecate_local_vlan_map_in_object(object_name): +def deprecate_local_vlan_map_in_object(object_name, stacklevel_extra=0): debtcollector.deprecate( "local_vlan_map argument for %s was deprecated." % object_name, - version="Newton", removal_version="Ocata") + version="Newton", removal_version="Ocata", + stacklevel=4 + stacklevel_extra) class VifIdNotFound(exceptions.NeutronException): diff --git a/neutron/policy.py b/neutron/policy.py index b413274bf95..adf7d68519f 100644 --- a/neutron/policy.py +++ b/neutron/policy.py @@ -17,7 +17,7 @@ import collections import re from neutron_lib import constants -from neutron_lib import exceptions as lib_exc +from neutron_lib import exceptions from oslo_config import cfg from oslo_db import exception as db_exc from oslo_log import log as logging @@ -29,7 +29,6 @@ import six from neutron._i18n import _, _LE, _LW from neutron.api.v2 import attributes from neutron.common import constants as const -from neutron.common import exceptions LOG = logging.getLogger(__name__) @@ -265,7 +264,7 @@ class OwnerCheck(policy.Check): target[parent_foreign_key], fields=[parent_field]) target[self.target_field] = data[parent_field] - except lib_exc.NotFound as e: + except exceptions.NotFound as e: # NOTE(kevinbenton): a NotFound exception can occur if a # list operation is happening at the same time as one of # the parents and its children being deleted. So we issue diff --git a/neutron/services/l3_router/service_providers/driver_controller.py b/neutron/services/l3_router/service_providers/driver_controller.py index 16230e75e0f..96ef0c4c544 100644 --- a/neutron/services/l3_router/service_providers/driver_controller.py +++ b/neutron/services/l3_router/service_providers/driver_controller.py @@ -13,6 +13,7 @@ # under the License. from neutron_lib import constants as lib_const +from neutron_lib import exceptions as lib_exc from oslo_config import cfg from oslo_log import log as logging @@ -20,7 +21,6 @@ from neutron._i18n import _ from neutron.callbacks import events from neutron.callbacks import registry from neutron.callbacks import resources -from neutron.common import exceptions as n_exc from neutron.db import servicetype_db as st_db from neutron import manager from neutron.plugins.common import constants @@ -110,7 +110,7 @@ class DriverController(object): # attributes via the API. try: _ensure_driver_supports_request(drv, router) - except n_exc.Invalid: + except lib_exc.Invalid: # the current driver does not support this request, we need to # migrate to a new provider. populate the distributed and ha # flags from the previous state if not in the update so we can @@ -120,7 +120,7 @@ class DriverController(object): # the flavor will make things inconsistent. We can probably # update the flavor automatically in the future. if old_router['flavor_id']: - raise n_exc.Invalid(_( + raise lib_exc.Invalid(_( "Changing the 'ha' and 'distributed' attributes on a " "router associated with a flavor is not supported.")) if 'distributed' not in router: @@ -202,7 +202,7 @@ class _LegacyPlusProviderConfiguration( self.add_provider({'service_type': constants.L3_ROUTER_NAT, 'name': name, 'driver': path, 'default': False}) - except n_exc.Invalid: + except lib_exc.Invalid: LOG.debug("Could not add L3 provider '%s', it may have " "already been explicitly defined.", name) @@ -244,6 +244,6 @@ def _ensure_driver_supports_request(drv, router_body): if flag not in [True, False]: continue # not specified in body if not getattr(drv, attr).is_compatible(flag): - raise n_exc.Invalid( + raise lib_exc.Invalid( _("Provider %(name)s does not support %(key)s=%(flag)s") % dict(name=drv.name, key=key, flag=flag)) diff --git a/neutron/services/provider_configuration.py b/neutron/services/provider_configuration.py index c355673b09a..4461a2c9564 100644 --- a/neutron/services/provider_configuration.py +++ b/neutron/services/provider_configuration.py @@ -13,7 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import debtcollector import importlib import itertools import os @@ -32,9 +31,7 @@ LOG = logging.getLogger(__name__) SERVICE_PROVIDERS = 'neutron.service_providers' -debtcollector.deprecate( - 'Moved serviceprovider_opts to %s' % prov_config.__name__, - version="newton", removal_version="ocata") +# TODO(HenryG): use MovedGlobals to deprecate this. serviceprovider_opts = prov_config.serviceprovider_opts prov_config.register_service_provider_opts() diff --git a/neutron/tests/common/helpers.py b/neutron/tests/common/helpers.py index 6cc0cdfe57b..21540516fc4 100644 --- a/neutron/tests/common/helpers.py +++ b/neutron/tests/common/helpers.py @@ -22,7 +22,6 @@ import six import testtools import neutron -from neutron.common import constants as n_const from neutron.common import topics from neutron import context from neutron.db import agents_db @@ -79,7 +78,7 @@ def _register_agent(agent, plugin=None): admin_context, agent['agent_type'], agent['host']) -def register_l3_agent(host=HOST, agent_mode=n_const.L3_AGENT_MODE_LEGACY, +def register_l3_agent(host=HOST, agent_mode=constants.L3_AGENT_MODE_LEGACY, internal_only=True, ext_net_id='', ext_bridge='', az=DEFAULT_AZ): agent = _get_l3_agent_dict(host, agent_mode, internal_only, ext_net_id, diff --git a/neutron/tests/common/l3_test_common.py b/neutron/tests/common/l3_test_common.py index aac5760d736..6f95972e5ad 100644 --- a/neutron/tests/common/l3_test_common.py +++ b/neutron/tests/common/l3_test_common.py @@ -15,7 +15,7 @@ import copy import netaddr -from neutron_lib import constants as l3_constants +from neutron_lib import constants as lib_constants from oslo_utils import uuidutils from six import moves @@ -33,7 +33,7 @@ def get_ha_interface(ip='169.254.192.1', mac='12:34:56:78:2b:5d'): subnet_id = _uuid() return {'admin_state_up': True, 'device_id': _uuid(), - 'device_owner': l3_constants.DEVICE_OWNER_ROUTER_HA_INTF, + 'device_owner': lib_constants.DEVICE_OWNER_ROUTER_HA_INTF, 'fixed_ips': [{'ip_address': ip, 'prefixlen': 18, 'subnet_id': subnet_id}], @@ -103,12 +103,12 @@ def prepare_router_data(ip_version=4, enable_snat=None, num_internal_ports=1, router = { 'id': router_id, 'distributed': False, - l3_constants.INTERFACE_KEY: [], + lib_constants.INTERFACE_KEY: [], 'routes': routes, 'gw_port': ex_gw_port} if enable_floating_ip: - router[l3_constants.FLOATINGIP_KEY] = [{ + router[lib_constants.FLOATINGIP_KEY] = [{ 'id': _uuid(), 'port_id': _uuid(), 'status': 'DOWN', @@ -120,7 +120,7 @@ def prepare_router_data(ip_version=4, enable_snat=None, num_internal_ports=1, if enable_ha: router['ha'] = True router['ha_vr_id'] = 1 - router[l3_constants.HA_INTERFACE_KEY] = (get_ha_interface()) + router[lib_constants.HA_INTERFACE_KEY] = (get_ha_interface()) if enable_snat is not None: router['enable_snat'] = enable_snat @@ -133,7 +133,7 @@ def get_subnet_id(port): def router_append_interface(router, count=1, ip_version=4, ra_mode=None, addr_mode=None, dual_stack=False): - interfaces = router[l3_constants.INTERFACE_KEY] + interfaces = router[lib_constants.INTERFACE_KEY] current = sum( [netaddr.IPNetwork(subnet['cidr']).version == ip_version for p in interfaces for subnet in p['subnets']]) @@ -203,7 +203,7 @@ def router_append_subnet(router, count=1, ip_version=4, else: raise ValueError("Invalid ip_version: %s" % ip_version) - interfaces = copy.deepcopy(router.get(l3_constants.INTERFACE_KEY, [])) + interfaces = copy.deepcopy(router.get(lib_constants.INTERFACE_KEY, [])) if interface_id: try: interface = next(i for i in interfaces @@ -248,11 +248,11 @@ def router_append_subnet(router, count=1, ip_version=4, 'fixed_ips': fixed_ips, 'subnets': subnets}) - router[l3_constants.INTERFACE_KEY] = interfaces + router[lib_constants.INTERFACE_KEY] = interfaces def router_append_pd_enabled_subnet(router, count=1): - interfaces = router[l3_constants.INTERFACE_KEY] + interfaces = router[lib_constants.INTERFACE_KEY] current = sum(netaddr.IPNetwork(subnet['cidr']).version == 6 for p in interfaces for subnet in p['subnets']) @@ -271,8 +271,8 @@ def router_append_pd_enabled_subnet(router, count=1): 'subnets': [{'id': subnet_id, 'cidr': n_const.PROVISIONAL_IPV6_PD_PREFIX, 'gateway_ip': '::1', - 'ipv6_ra_mode': n_const.IPV6_SLAAC, - 'subnetpool_id': l3_constants.IPV6_PD_POOL_ID}]} + 'ipv6_ra_mode': lib_constants.IPV6_SLAAC, + 'subnetpool_id': lib_constants.IPV6_PD_POOL_ID}]} interfaces.append(intf) pd_intfs.append(intf) mac_address.value += 1 diff --git a/neutron/tests/functional/agent/l3/framework.py b/neutron/tests/functional/agent/l3/framework.py index e790bf76a5a..754667cf77d 100644 --- a/neutron/tests/functional/agent/l3/framework.py +++ b/neutron/tests/functional/agent/l3/framework.py @@ -17,7 +17,7 @@ import functools import mock import netaddr -from neutron_lib import constants as l3_constants +from neutron_lib import constants from oslo_config import cfg from oslo_log import log as logging from oslo_utils import uuidutils @@ -29,7 +29,6 @@ from neutron.agent.l3 import agent as neutron_l3_agent from neutron.agent import l3_agent as l3_agent_main from neutron.agent.linux import external_process from neutron.agent.linux import ip_lib -from neutron.common import constants as n_const from neutron.common import utils as common_utils from neutron.conf import common as common_config from neutron.tests.common import l3_test_common @@ -123,13 +122,13 @@ class L3AgentTestFramework(base.BaseSudoTestCase): router_info = self.generate_router_info(enable_ha=ha) router = self.manage_router(self.agent, router_info) - port = net_helpers.get_free_namespace_port(l3_constants.PROTO_NAME_TCP, - router.ns_name) + port = net_helpers.get_free_namespace_port( + constants.PROTO_NAME_TCP, router.ns_name) client_address = '19.4.4.3' server_address = '35.4.0.4' def clean_fips(router): - router.router[l3_constants.FLOATINGIP_KEY] = [] + router.router[constants.FLOATINGIP_KEY] = [] clean_fips(router) self._add_fip(router, client_address, fixed_address=server_address) @@ -170,8 +169,8 @@ class L3AgentTestFramework(base.BaseSudoTestCase): # Assert that every defined FIP is updated via RPC expected_fips = set([ - (fip['id'], l3_constants.FLOATINGIP_STATUS_ACTIVE) for fip in - router.router[l3_constants.FLOATINGIP_KEY]]) + (fip['id'], constants.FLOATINGIP_STATUS_ACTIVE) for fip in + router.router[constants.FLOATINGIP_KEY]]) call = [args[0] for args in rpc.call_args_list][0] actual_fips = set( [(fip_id, status) for fip_id, status in call[2].items()]) @@ -188,7 +187,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase): def ha_router_dev_name_getter(not_used): return router.get_ha_device_name() self.assertTrue(self.device_exists_with_ips_and_mac( - router.router[l3_constants.HA_INTERFACE_KEY], + router.router[constants.HA_INTERFACE_KEY], ha_router_dev_name_getter, router.ns_name)) def _assert_gateway(self, router, v6_ext_gw_with_sub=True): @@ -227,7 +226,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase): router = self.manage_router(self.agent, router_info) # Add multiple-IPv6-prefix internal router port - slaac = n_const.IPV6_SLAAC + slaac = constants.IPV6_SLAAC slaac_mode = {'ra_mode': slaac, 'address_mode': slaac} subnet_modes = [slaac_mode] * 2 self._add_internal_interface_by_subnet(router.router, @@ -247,7 +246,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase): # not when it ends. Thus, we have to wait until keepalived finishes # configuring everything. We verify this by waiting until the last # device has an IP address. - device = router.router[l3_constants.INTERFACE_KEY][-1] + device = router.router[constants.INTERFACE_KEY][-1] device_exists = functools.partial( self.device_exists_with_ips_and_mac, device, @@ -308,7 +307,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase): 'fixed_ip_address': fixed_address, 'host': host, 'fixed_ip_address_scope': fixed_ip_address_scope} - router.router[l3_constants.FLOATINGIP_KEY].append(fip) + router.router[constants.FLOATINGIP_KEY].append(fip) def _add_internal_interface_by_subnet(self, router, count=1, ip_version=4, @@ -352,7 +351,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase): external_device_name = router.get_external_device_name( external_port['id']) external_device_cidr = self._port_first_ip_cidr(external_port) - internal_port = router.router[l3_constants.INTERFACE_KEY][0] + internal_port = router.router[constants.INTERFACE_KEY][0] int_port_ipv6 = ip_lib.get_ipv6_lladdr(internal_port['mac_address']) internal_device_name = router.get_internal_device_name( internal_port['id']) @@ -442,7 +441,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase): metadata_port_filter)) def _assert_internal_devices(self, router): - internal_devices = router.router[l3_constants.INTERFACE_KEY] + internal_devices = router.router[constants.INTERFACE_KEY] self.assertTrue(len(internal_devices)) for device in internal_devices: self.assertTrue(self.device_exists_with_ips_and_mac( @@ -481,7 +480,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase): assert_ovs_bridge_empty(self.agent.conf.external_network_bridge) def floating_ips_configured(self, router): - floating_ips = router.router[l3_constants.FLOATINGIP_KEY] + floating_ips = router.router[constants.FLOATINGIP_KEY] external_port = router.get_ex_gw_port() return len(floating_ips) and all( ip_lib.device_exists_with_ips_and_mac( diff --git a/neutron/tests/functional/agent/l3/test_dvr_router.py b/neutron/tests/functional/agent/l3/test_dvr_router.py index f2f4d49a31c..e9822fe1f17 100644 --- a/neutron/tests/functional/agent/l3/test_dvr_router.py +++ b/neutron/tests/functional/agent/l3/test_dvr_router.py @@ -18,7 +18,7 @@ import functools import mock import netaddr -from neutron_lib import constants as l3_constants +from neutron_lib import constants as lib_constants import testtools from neutron.agent.l3 import agent as neutron_l3_agent @@ -36,7 +36,7 @@ from neutron.tests.common import net_helpers from neutron.tests.functional.agent.l3 import framework -DEVICE_OWNER_COMPUTE = l3_constants.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' +DEVICE_OWNER_COMPUTE = lib_constants.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' class TestDvrRouter(framework.L3AgentTestFramework): @@ -112,7 +112,7 @@ class TestDvrRouter(framework.L3AgentTestFramework): 'gateway_ip': float_subnet['gateway_ip'], 'id': fixed_ip['subnet_id']}], 'network_id': external_gw_port['network_id'], - 'device_owner': l3_constants.DEVICE_OWNER_AGENT_GW, + 'device_owner': lib_constants.DEVICE_OWNER_AGENT_GW, 'mac_address': 'fa:16:3e:80:8f:89', portbindings.HOST_ID: self.agent.conf.host, 'fixed_ips': [{'subnet_id': fixed_ip['subnet_id'], @@ -239,7 +239,7 @@ class TestDvrRouter(framework.L3AgentTestFramework): # not when it ends. Thus, we have to wait until keepalived finishes # configuring everything. We verify this by waiting until the last # device has an IP address. - device = router.router[l3_constants.INTERFACE_KEY][-1] + device = router.router[lib_constants.INTERFACE_KEY][-1] device_exists = functools.partial( self.device_exists_with_ips_and_mac, device, @@ -298,7 +298,7 @@ class TestDvrRouter(framework.L3AgentTestFramework): num_internal_ports=2, enable_gw=enable_gw, **kwargs) - internal_ports = router.get(l3_constants.INTERFACE_KEY, []) + internal_ports = router.get(lib_constants.INTERFACE_KEY, []) router['distributed'] = True router['gw_port_host'] = agent.conf.host @@ -339,7 +339,7 @@ class TestDvrRouter(framework.L3AgentTestFramework): 'gateway_ip': float_subnet['gateway_ip'], 'id': fixed_ip['subnet_id']}], 'network_id': external_gw_port['network_id'], - 'device_owner': l3_constants.DEVICE_OWNER_AGENT_GW, + 'device_owner': lib_constants.DEVICE_OWNER_AGENT_GW, 'mac_address': 'fa:16:3e:80:8d:89', portbindings.HOST_ID: self.agent.conf.host, 'fixed_ips': [{'subnet_id': fixed_ip['subnet_id'], @@ -370,7 +370,7 @@ class TestDvrRouter(framework.L3AgentTestFramework): 'gateway_ip': snat_subnet['gateway_ip'], 'id': fixed_ip['subnet_id']}], 'network_id': port['network_id'], - 'device_owner': l3_constants.DEVICE_OWNER_ROUTER_SNAT, + 'device_owner': lib_constants.DEVICE_OWNER_ROUTER_SNAT, 'mac_address': 'fa:16:3e:80:8d:89', 'fixed_ips': [{'subnet_id': fixed_ip['subnet_id'], 'ip_address': snat_ip, @@ -457,7 +457,7 @@ class TestDvrRouter(framework.L3AgentTestFramework): # in the fip namespace: # Check that the fg- (floatingip_agent_gateway) # is created with the ip address of the external gateway port - floating_ips = router.router[l3_constants.FLOATINGIP_KEY] + floating_ips = router.router[lib_constants.FLOATINGIP_KEY] self.assertTrue(floating_ips) # We need to fetch the floatingip agent gateway port info # from the router_info @@ -504,7 +504,7 @@ class TestDvrRouter(framework.L3AgentTestFramework): self.assertTrue(self._namespace_exists(fip_ns)) restarted_agent = neutron_l3_agent.L3NATAgentWithStateReport( self.agent.host, self.agent.conf) - router1.router[l3_constants.FLOATINGIP_KEY] = [] + router1.router[lib_constants.FLOATINGIP_KEY] = [] self.manage_router(restarted_agent, router1.router) self._assert_dvr_snat_gateway(router1) self.assertTrue(self._namespace_exists(fip_ns)) @@ -513,7 +513,7 @@ class TestDvrRouter(framework.L3AgentTestFramework): self.agent.conf.agent_mode = 'dvr' router_info = self.generate_dvr_router_info() router = self.manage_router(self.agent, router_info) - floating_ips = router.router[l3_constants.FLOATINGIP_KEY] + floating_ips = router.router[lib_constants.FLOATINGIP_KEY] router_ns = router.ns_name fip_rule_prio_1 = self._get_fixed_ip_rule_priority( router_ns, floating_ips[0]['fixed_ip_address']) @@ -530,7 +530,7 @@ class TestDvrRouter(framework.L3AgentTestFramework): self.agent.conf.agent_mode = 'dvr' router_info = self.generate_dvr_router_info() router = self.manage_router(self.agent, router_info) - floating_ips = router.router[l3_constants.FLOATINGIP_KEY] + floating_ips = router.router[lib_constants.FLOATINGIP_KEY] router_ns = router.ns_name fixed_ip = floating_ips[0]['fixed_ip_address'] self.assertTrue(self._fixed_ip_rule_exists(router_ns, fixed_ip)) @@ -730,7 +730,7 @@ class TestDvrRouter(framework.L3AgentTestFramework): self.assertEqual(router1.snat_ports, snat_internal_port) # Now let us not pass INTERFACE_KEY, to emulate # the interface has been removed. - router1.router[l3_constants.INTERFACE_KEY] = [] + router1.router[lib_constants.INTERFACE_KEY] = [] # 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. @@ -923,20 +923,20 @@ class TestDvrRouter(framework.L3AgentTestFramework): internal_address_scope2, gw_address_scope=None): router_info = self.generate_dvr_router_info(enable_snat=True) address_scope1 = { - str(l3_constants.IP_VERSION_4): internal_address_scope1} + str(lib_constants.IP_VERSION_4): internal_address_scope1} address_scope2 = { - str(l3_constants.IP_VERSION_4): internal_address_scope2} + str(lib_constants.IP_VERSION_4): internal_address_scope2} if gw_address_scope: router_info['gw_port']['address_scopes'] = { - str(l3_constants.IP_VERSION_4): gw_address_scope} - router_info[l3_constants.INTERFACE_KEY][0]['address_scopes'] = ( + str(lib_constants.IP_VERSION_4): gw_address_scope} + router_info[lib_constants.INTERFACE_KEY][0]['address_scopes'] = ( address_scope1) - router_info[l3_constants.INTERFACE_KEY][1]['address_scopes'] = ( + router_info[lib_constants.INTERFACE_KEY][1]['address_scopes'] = ( address_scope2) # Renew the address scope router_info[n_const.SNAT_ROUTER_INTF_KEY] = [] self._add_snat_port_info_to_router( - router_info, router_info[l3_constants.INTERFACE_KEY]) + router_info, router_info[lib_constants.INTERFACE_KEY]) router = self.manage_router(self.agent, router_info) router_ip_cidr1 = self._port_first_ip_cidr(router.internal_ports[0]) @@ -983,7 +983,7 @@ class TestDvrRouter(framework.L3AgentTestFramework): (machine_same_scope, machine_diff_scope, router) = self._setup_address_scope('scope1', 'scope2', 'scope1') - router.router[l3_constants.FLOATINGIP_KEY] = [] + router.router[lib_constants.FLOATINGIP_KEY] = [] fip_same_scope = '19.4.4.10' self._add_fip(router, fip_same_scope, fixed_address=machine_same_scope.ip, diff --git a/neutron/tests/functional/agent/l3/test_ha_router.py b/neutron/tests/functional/agent/l3/test_ha_router.py index 379267c8a95..b5efeb8297a 100644 --- a/neutron/tests/functional/agent/l3/test_ha_router.py +++ b/neutron/tests/functional/agent/l3/test_ha_router.py @@ -16,14 +16,13 @@ import copy import mock -from neutron_lib import constants as l3_constants +from neutron_lib import constants import six import testtools 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.common import constants from neutron.common import ipv6_utils from neutron.common import utils as common_utils from neutron.tests.common import l3_test_common @@ -181,7 +180,7 @@ class L3HATestCase(framework.L3AgentTestFramework): common_utils.wait_until_true(lambda: router1.radvd.enabled) def _check_lla_status(router, expected): - internal_devices = router.router[l3_constants.INTERFACE_KEY] + internal_devices = router.router[constants.INTERFACE_KEY] for device in internal_devices: lladdr = ip_lib.get_ipv6_lladdr(device['mac_address']) exists = ip_lib.device_exists_with_ips_and_mac( @@ -210,7 +209,7 @@ class L3HATestCase(framework.L3AgentTestFramework): for ip_addr in ip_cidrs: self.assertIn(ip_addr, config) - interface_id = router.router[l3_constants.INTERFACE_KEY][0]['id'] + interface_id = router.router[constants.INTERFACE_KEY][0]['id'] slaac = constants.IPV6_SLAAC slaac_mode = {'ra_mode': slaac, 'address_mode': slaac} @@ -223,7 +222,7 @@ class L3HATestCase(framework.L3AgentTestFramework): # Verify that router internal interface is present and is configured # with IP address from both the subnets. - internal_iface = router.router[l3_constants.INTERFACE_KEY][0] + internal_iface = router.router[constants.INTERFACE_KEY][0] self.assertEqual(2, len(internal_iface['fixed_ips'])) self._assert_internal_devices(router) @@ -232,16 +231,16 @@ class L3HATestCase(framework.L3AgentTestFramework): # Remove one subnet from the router internal iface interfaces = copy.deepcopy(router.router.get( - l3_constants.INTERFACE_KEY, [])) + constants.INTERFACE_KEY, [])) fixed_ips, subnets = [], [] fixed_ips.append(interfaces[0]['fixed_ips'][0]) subnets.append(interfaces[0]['subnets'][0]) interfaces[0].update({'fixed_ips': fixed_ips, 'subnets': subnets}) - router.router[l3_constants.INTERFACE_KEY] = interfaces + router.router[constants.INTERFACE_KEY] = interfaces router.process(self.agent) # Verify that router internal interface has a single ipaddress - internal_iface = router.router[l3_constants.INTERFACE_KEY][0] + internal_iface = router.router[constants.INTERFACE_KEY][0] self.assertEqual(1, len(internal_iface['fixed_ips'])) self._assert_internal_devices(router) @@ -268,7 +267,7 @@ class L3HATestCase(framework.L3AgentTestFramework): common_utils.wait_until_true(lambda: router.ha_state == 'master') self._add_fip(router, '172.168.1.20', fixed_address='10.0.0.3') router.process(self.agent) - router.router[l3_constants.FLOATINGIP_KEY] = [] + router.router[constants.FLOATINGIP_KEY] = [] # The purpose of the test is to simply make sure no exception is raised # Because router.process will consume the FloatingIpSetupException, # call the configure_fip_addresses directly here @@ -302,7 +301,7 @@ class L3HATestFailover(framework.L3AgentTestFramework): router1 = self.manage_router(self.agent, router_info) router_info_2 = copy.deepcopy(router_info) - router_info_2[l3_constants.HA_INTERFACE_KEY] = ( + router_info_2[constants.HA_INTERFACE_KEY] = ( l3_test_common.get_ha_interface(ip='169.254.192.2', mac='22:22:22:22:22:22')) diff --git a/neutron/tests/functional/agent/l3/test_legacy_router.py b/neutron/tests/functional/agent/l3/test_legacy_router.py index 212aa2010a3..a991f4909ce 100644 --- a/neutron/tests/functional/agent/l3/test_legacy_router.py +++ b/neutron/tests/functional/agent/l3/test_legacy_router.py @@ -16,7 +16,7 @@ import copy import mock -from neutron_lib import constants as l3_constants +from neutron_lib import constants as lib_constants from neutron.agent.l3 import namespace_manager from neutron.agent.l3 import namespaces @@ -137,7 +137,7 @@ class L3AgentTestCase(framework.L3AgentTestFramework): gw_inf_name = router.get_external_device_name(gw_port['id']) gw_device = ip_lib.IPDevice(gw_inf_name, namespace=router.ns_name) router_ports = [gw_device] - for i_port in router_info.get(l3_constants.INTERFACE_KEY, []): + for i_port in router_info.get(lib_constants.INTERFACE_KEY, []): interface_name = router.get_internal_device_name(i_port['id']) router_ports.append( ip_lib.IPDevice(interface_name, namespace=router.ns_name)) @@ -265,7 +265,7 @@ class L3AgentTestCase(framework.L3AgentTestFramework): router_ip)).machines dst_fip = '19.4.4.10' - router.router[l3_constants.FLOATINGIP_KEY] = [] + router.router[lib_constants.FLOATINGIP_KEY] = [] self._add_fip(router, dst_fip, fixed_address=dst_machine.ip) router.process(self.agent) @@ -280,7 +280,7 @@ class L3AgentTestCase(framework.L3AgentTestFramework): src_machine, dst_machine, dst_fip = ( self._setup_fip_with_fixed_ip_from_same_subnet(enable_snat=True)) protocol_port = net_helpers.get_free_namespace_port( - l3_constants.PROTO_NAME_TCP, dst_machine.namespace) + lib_constants.PROTO_NAME_TCP, dst_machine.namespace) # client sends to fip netcat = net_helpers.NetcatTester( src_machine.namespace, dst_machine.namespace, @@ -304,15 +304,15 @@ class L3AgentTestCase(framework.L3AgentTestFramework): router_info = self.generate_router_info(enable_ha=False, num_internal_ports=2) address_scope1 = { - str(l3_constants.IP_VERSION_4): internal_address_scope1} + str(lib_constants.IP_VERSION_4): internal_address_scope1} address_scope2 = { - str(l3_constants.IP_VERSION_4): internal_address_scope2} + str(lib_constants.IP_VERSION_4): internal_address_scope2} if gw_address_scope: router_info['gw_port']['address_scopes'] = { - str(l3_constants.IP_VERSION_4): gw_address_scope} - router_info[l3_constants.INTERFACE_KEY][0]['address_scopes'] = ( + str(lib_constants.IP_VERSION_4): gw_address_scope} + router_info[lib_constants.INTERFACE_KEY][0]['address_scopes'] = ( address_scope1) - router_info[l3_constants.INTERFACE_KEY][1]['address_scopes'] = ( + router_info[lib_constants.INTERFACE_KEY][1]['address_scopes'] = ( address_scope2) router = self.manage_router(self.agent, router_info) @@ -356,7 +356,7 @@ class L3AgentTestCase(framework.L3AgentTestFramework): (machine_same_scope, machine_diff_scope, router) = self._setup_address_scope('scope1', 'scope2', 'scope1') - router.router[l3_constants.FLOATINGIP_KEY] = [] + router.router[lib_constants.FLOATINGIP_KEY] = [] fip_same_scope = '19.4.4.10' self._add_fip(router, fip_same_scope, fixed_address=machine_same_scope.ip, @@ -399,7 +399,7 @@ class L3AgentTestCase(framework.L3AgentTestFramework): (machine_same_scope, machine_diff_scope, router) = self._setup_address_scope('scope1', 'scope2', 'scope1') - router.router[l3_constants.FLOATINGIP_KEY] = [] + router.router[lib_constants.FLOATINGIP_KEY] = [] fip = '19.4.4.11' self._add_fip(router, fip, fixed_address=machine_diff_scope.ip, diff --git a/neutron/tests/functional/agent/test_dhcp_agent.py b/neutron/tests/functional/agent/test_dhcp_agent.py index 4334f4ffdee..d14a3e7384a 100644 --- a/neutron/tests/functional/agent/test_dhcp_agent.py +++ b/neutron/tests/functional/agent/test_dhcp_agent.py @@ -32,7 +32,6 @@ from neutron.agent.linux import external_process 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.common import utils as common_utils from neutron.tests.common import net_helpers from neutron.tests.functional.agent.linux import helpers @@ -112,7 +111,7 @@ class DHCPAgentOVSTestFramework(base.BaseSudoTestCase): "ipv6_ra_mode": None, "ipv6_address_mode": None}) if ip_version == 6: - sn_dict['ipv6_address_mode'] = constants.DHCPV6_STATEFUL + sn_dict['ipv6_address_mode'] = lib_const.DHCPV6_STATEFUL return sn_dict def create_port_dict(self, network_id, subnet_id, mac_address, diff --git a/neutron/tests/functional/scheduler/test_l3_agent_scheduler.py b/neutron/tests/functional/scheduler/test_l3_agent_scheduler.py index 45d3c67e22e..01523f0d107 100644 --- a/neutron/tests/functional/scheduler/test_l3_agent_scheduler.py +++ b/neutron/tests/functional/scheduler/test_l3_agent_scheduler.py @@ -16,12 +16,10 @@ import collections import random +from neutron_lib import constants +from oslo_utils import uuidutils import testscenarios -from oslo_utils import uuidutils - -from neutron.api.v2 import attributes -from neutron.common import constants from neutron import context from neutron.db import external_net_db from neutron.scheduler import l3_agent_scheduler @@ -613,9 +611,9 @@ class L3DVRSchedulerBaseTest(L3SchedulerBaseTest): 'enable_dhcp': False, 'gateway_ip': gw_ip, '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.adminContext, {'subnet': subnet}) 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 57e5e778f4a..2055bd153b0 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 @@ -15,7 +15,6 @@ import mock from neutron_lib 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 @@ -32,7 +31,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=n_const.L3_AGENT_MODE_DVR_SNAT) + agent_mode=constants.L3_AGENT_MODE_DVR_SNAT) def _create_router(self, distributed=True, ha=True): return (super(L3DvrHATestCase, self). @@ -136,7 +135,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=n_const.L3_AGENT_MODE_DVR) + host=host, agent_mode=constants.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 04af93e30cd..ea650287b10 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 @@ -16,7 +16,6 @@ import mock from neutron_lib import constants from neutron.api.rpc.handlers import l3_rpc -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 +31,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): def setUp(self): super(L3DvrTestCase, self).setUp() self.l3_agent = helpers.register_l3_agent( - agent_mode=n_const.L3_AGENT_MODE_DVR_SNAT) + agent_mode=constants.L3_AGENT_MODE_DVR_SNAT) def _create_router(self, distributed=True, ha=False): return (super(L3DvrTestCase, self). @@ -283,9 +282,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=n_const.L3_AGENT_MODE_DVR) + agent_mode=constants.L3_AGENT_MODE_DVR) helpers.register_l3_agent(host='host2', - agent_mode=n_const.L3_AGENT_MODE_DVR) + agent_mode=constants.L3_AGENT_MODE_DVR) # make net external ext_net_id = ext_subnet['subnet']['network_id'] @@ -456,7 +455,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): def test_allowed_addr_pairs_arp_update_for_port_with_original_owner(self): HOST1 = 'host1' helpers.register_l3_agent( - host=HOST1, agent_mode=n_const.L3_AGENT_MODE_DVR) + host=HOST1, agent_mode=constants.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', @@ -551,10 +550,10 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): def test_allowed_addr_pairs_delayed_fip_and_update_arp_entry(self): HOST1 = 'host1' helpers.register_l3_agent( - host=HOST1, agent_mode=n_const.L3_AGENT_MODE_DVR) + host=HOST1, agent_mode=constants.L3_AGENT_MODE_DVR) HOST2 = 'host2' helpers.register_l3_agent( - host=HOST2, agent_mode=n_const.L3_AGENT_MODE_DVR) + host=HOST2, agent_mode=constants.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', @@ -692,7 +691,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): def test_allowed_address_pairs_update_arp_entry(self): HOST1 = 'host1' helpers.register_l3_agent( - host=HOST1, agent_mode=n_const.L3_AGENT_MODE_DVR) + host=HOST1, agent_mode=constants.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', @@ -798,7 +797,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=n_const.L3_AGENT_MODE_DVR) + host=HOST1, agent_mode=constants.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', @@ -937,10 +936,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=n_const.L3_AGENT_MODE_DVR) + host=HOST1, agent_mode=constants.L3_AGENT_MODE_DVR) HOST2 = 'host2' helpers.register_l3_agent( - host=HOST2, agent_mode=n_const.L3_AGENT_MODE_DVR) + host=HOST2, agent_mode=constants.L3_AGENT_MODE_DVR) router = self._create_router() with self.subnet() as subnet: self.l3_plugin.add_router_interface( @@ -1036,7 +1035,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): HOST = 'host1' non_admin_tenant = 'tenant1' helpers.register_l3_agent( - host=HOST, agent_mode=n_const.L3_AGENT_MODE_DVR) + host=HOST, agent_mode=constants.L3_AGENT_MODE_DVR) router = self._create_router() with self.network(shared=True) as net,\ self.subnet(network=net) as subnet,\ @@ -1082,7 +1081,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): HOST1, HOST2 = 'host1', 'host2' for host in [HOST1, HOST2]: helpers.register_l3_agent( - host=host, agent_mode=n_const.L3_AGENT_MODE_DVR) + host=host, agent_mode=constants.L3_AGENT_MODE_DVR) router = self._create_router() arg_list = (portbindings.HOST_ID,) @@ -1153,7 +1152,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=n_const.L3_AGENT_MODE_DVR) + host=host, agent_mode=constants.L3_AGENT_MODE_DVR) router = self._create_router() arg_list = (portbindings.HOST_ID,) @@ -1494,7 +1493,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): def test_remove_router_interface(self): HOST1 = 'host1' helpers.register_l3_agent( - host=HOST1, agent_mode=n_const.L3_AGENT_MODE_DVR) + host=HOST1, agent_mode=constants.L3_AGENT_MODE_DVR) router = self._create_router() arg_list = (portbindings.HOST_ID,) with self.subnet() as subnet,\ diff --git a/neutron/tests/tools.py b/neutron/tests/tools.py index 52892e49fe3..e15b41d3f52 100644 --- a/neutron/tests/tools.py +++ b/neutron/tests/tools.py @@ -298,7 +298,7 @@ def reset_random_seed(): def get_random_ipv6_mode(): - return random.choice(n_const.IPV6_MODES) + return random.choice(constants.IPV6_MODES) import_modules_recursively = moves.moved_function( diff --git a/neutron/tests/unit/agent/l3/test_agent.py b/neutron/tests/unit/agent/l3/test_agent.py index 45b673eefb7..9879d3f1832 100644 --- a/neutron/tests/unit/agent/l3/test_agent.py +++ b/neutron/tests/unit/agent/l3/test_agent.py @@ -20,7 +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 constants as lib_constants from neutron_lib import exceptions as exc from oslo_config import cfg from oslo_log import log @@ -151,7 +151,7 @@ class BasicRouterOperationsFramework(base.BaseTestCase): 'id': subnet_id_1}], 'network_id': _uuid(), 'device_owner': - l3_constants.DEVICE_OWNER_ROUTER_SNAT, + lib_constants.DEVICE_OWNER_ROUTER_SNAT, 'mac_address': 'fa:16:3e:80:8d:80', 'fixed_ips': [{'subnet_id': subnet_id_1, 'ip_address': '152.2.0.13', @@ -162,7 +162,7 @@ class BasicRouterOperationsFramework(base.BaseTestCase): 'id': subnet_id_2}], 'network_id': _uuid(), 'device_owner': - l3_constants.DEVICE_OWNER_ROUTER_SNAT, + lib_constants.DEVICE_OWNER_ROUTER_SNAT, 'mac_address': 'fa:16:3e:80:8d:80', 'fixed_ips': [{'subnet_id': subnet_id_2, 'ip_address': '152.10.0.13', @@ -433,7 +433,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): 'floating_ip_address': '192.168.1.34', 'fixed_ip_address': '192.168.0.1', 'port_id': _uuid()}]} - router[l3_constants.FLOATINGIP_KEY] = fake_fip['floatingips'] + router[lib_constants.FLOATINGIP_KEY] = fake_fip['floatingips'] ri.external_gateway_added(ex_gw_port, interface_name) if not router.get('distributed'): self.assertEqual(1, self.mock_driver.plug.call_count) @@ -581,7 +581,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): 'floating_ip_address': '192.168.1.34', 'fixed_ip_address': '192.168.0.1', 'port_id': _uuid()}]} - router[l3_constants.FLOATINGIP_KEY] = fake_fip['floatingips'] + router[lib_constants.FLOATINGIP_KEY] = fake_fip['floatingips'] ri.external_gateway_updated(ex_gw_port, interface_name) self.assertEqual(1, self.mock_driver.plug.call_count) self.assertEqual(1, self.mock_driver.init_router_port.call_count) @@ -783,7 +783,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): def _verify_snat_mangle_rules(self, nat_rules, mangle_rules, router, negate=False): - interfaces = router[l3_constants.INTERFACE_KEY] + interfaces = router[lib_constants.INTERFACE_KEY] source_cidrs = [] for iface in interfaces: for subnet in iface['subnets']: @@ -830,9 +830,9 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): test_port = { 'mac_address': '00:12:23:34:45:56', 'fixed_ips': [{'subnet_id': l3_test_common.get_subnet_id( - router[l3_constants.INTERFACE_KEY][0]), + router[lib_constants.INTERFACE_KEY][0]), 'ip_address': '101.12.13.14'}]} - internal_ports = ri.router.get(l3_constants.INTERFACE_KEY, []) + internal_ports = ri.router.get(lib_constants.INTERFACE_KEY, []) # test valid case with mock.patch.object(ri, 'get_snat_interfaces') as get_interfaces: get_interfaces.return_value = [test_port] @@ -859,7 +859,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): router, **self.ri_kwargs) subnet_id = l3_test_common.get_subnet_id( - router[l3_constants.INTERFACE_KEY][0]) + router[lib_constants.INTERFACE_KEY][0]) ri.router['distributed'] = True ri.router['_snat_router_interfaces'] = [{ 'fixed_ips': [{'subnet_id': subnet_id, @@ -896,7 +896,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): fake_floatingips2 = copy.deepcopy(fake_floatingips1) fake_floatingips2['floatingips'][0]['fixed_ip_address'] = '7.7.7.8' - router[l3_constants.FLOATINGIP_KEY] = fake_floatingips2['floatingips'] + router[lib_constants.FLOATINGIP_KEY] = fake_floatingips2['floatingips'] ri.process(agent) ri.process_floating_ip_addresses.assert_called_with(mock.ANY) ri.process_floating_ip_addresses.reset_mock() @@ -921,7 +921,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): self.assertEqual(1, ri.external_gateway_updated.call_count) # remove just the floating ips - del router[l3_constants.FLOATINGIP_KEY] + del router[lib_constants.FLOATINGIP_KEY] ri.process(agent) ri.process_floating_ip_addresses.assert_called_with(mock.ANY) ri.process_floating_ip_addresses.reset_mock() @@ -929,7 +929,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): ri.process_floating_ip_nat_rules.reset_mock() # now no ports so state is torn down - del router[l3_constants.INTERFACE_KEY] + del router[lib_constants.INTERFACE_KEY] del router['gw_port'] ri.process(agent) self.assertEqual(1, self.send_adv_notif.call_count) @@ -946,14 +946,14 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): ex_gw_port = {'id': _uuid(), 'network_id': mock.sentinel.ext_net_id} ri.add_floating_ip = mock.Mock( - return_value=l3_constants.FLOATINGIP_STATUS_ACTIVE) + return_value=lib_constants.FLOATINGIP_STATUS_ACTIVE) with mock.patch.object(lla.LinkLocalAllocator, '_write'): if ri.router['distributed']: ri.fip_ns = agent.get_fip_ns(ex_gw_port['network_id']) ri.create_dvr_fip_interfaces(ex_gw_port) fip_statuses = ri.process_floating_ip_addresses( mock.sentinel.interface_name) - self.assertEqual({fip_id: l3_constants.FLOATINGIP_STATUS_ACTIVE}, + self.assertEqual({fip_id: lib_constants.FLOATINGIP_STATUS_ACTIVE}, fip_statuses) ri.add_floating_ip.assert_called_once_with( floating_ips[0], mock.sentinel.interface_name, device) @@ -984,7 +984,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): ) router = l3_test_common.prepare_router_data(enable_snat=True) - router[l3_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] + router[lib_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] router[n_const.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port router['distributed'] = True agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) @@ -1050,7 +1050,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): ) router = l3_test_common.prepare_router_data(enable_snat=True) - router[l3_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] + router[lib_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] router[n_const.FLOATINGIP_AGENT_INTF_KEY] = [] router['distributed'] = True agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) @@ -1095,7 +1095,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): ) router = l3_test_common.prepare_router_data(enable_snat=True) - router[l3_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] + router[lib_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] router[n_const.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port router['distributed'] = True agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) @@ -1146,7 +1146,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): ) router = l3_test_common.prepare_router_data(enable_snat=True) - router[l3_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] + router[lib_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] router[n_const.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port router['distributed'] = True agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) @@ -1182,7 +1182,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): 'host': HOSTNAME}]} router = l3_test_common.prepare_router_data(enable_snat=True) - router[l3_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] + router[lib_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri.iptables_manager.ipv4['nat'] = mock.MagicMock() @@ -1409,7 +1409,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=n_const.IPV6_SLAAC) + router, ra_mode=lib_constants.IPV6_SLAAC) self._assert_ri_process_enabled(ri) # Expect radvd configured with prefix radvd_config_str = self.utils_replace_file.call_args[0][1] @@ -1419,7 +1419,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=n_const.DHCPV6_STATEFUL) + router, ra_mode=lib_constants.DHCPV6_STATEFUL) self._assert_ri_process_enabled(ri) # Expect radvd configured with prefix radvd_config_str = self.utils_replace_file.call_args[0][1] @@ -1429,12 +1429,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': 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}]) + {'ra_mode': lib_constants.IPV6_SLAAC, + 'address_mode': lib_constants.IPV6_SLAAC}, + {'ra_mode': lib_constants.DHCPV6_STATELESS, + 'address_mode': lib_constants.DHCPV6_STATELESS}, + {'ra_mode': lib_constants.DHCPV6_STATEFUL, + 'address_mode': lib_constants.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 @@ -1454,8 +1454,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): l3_test_common.router_append_subnet( router, count=1, ip_version=6, ipv6_subnet_modes=[ - {'ra_mode': n_const.IPV6_SLAAC, - 'address_mode': n_const.IPV6_SLAAC}]) + {'ra_mode': lib_constants.IPV6_SLAAC, + 'address_mode': lib_constants.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() @@ -1468,13 +1468,13 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): self.external_process.reset_mock() self.utils_replace_file.reset_mock() # Add the second subnet on the same interface - interface_id = router[l3_constants.INTERFACE_KEY][1]['id'] + interface_id = router[lib_constants.INTERFACE_KEY][1]['id'] l3_test_common.router_append_subnet( router, count=1, ip_version=6, ipv6_subnet_modes=[ - {'ra_mode': n_const.IPV6_SLAAC, - 'address_mode': n_const.IPV6_SLAAC}], + {'ra_mode': lib_constants.IPV6_SLAAC, + 'address_mode': lib_constants.IPV6_SLAAC}], interface_id=interface_id) self._process_router_instance_for_agent(agent, ri, router) # radvd should have been enabled again and the interface @@ -1508,7 +1508,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): # Process with NAT ri.process(agent) # Add an interface and reprocess - del router[l3_constants.INTERFACE_KEY][1] + del router[lib_constants.INTERFACE_KEY][1] # Reassign the router object to RouterInfo ri.router = router ri.process(agent) @@ -1529,7 +1529,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): self.external_process.reset_mock() self.process_monitor.reset_mock() # Remove the IPv6 interface and reprocess - del router[l3_constants.INTERFACE_KEY][1] + del router[lib_constants.INTERFACE_KEY][1] self._process_router_instance_for_agent(agent, ri, router) self._assert_ri_process_disabled(ri) @@ -1542,8 +1542,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': n_const.IPV6_SLAAC, - 'address_mode': n_const.IPV6_SLAAC}] + ipv6_subnet_modes=([{'ra_mode': lib_constants.IPV6_SLAAC, + 'address_mode': lib_constants.IPV6_SLAAC}] * 2)) self._process_router_instance_for_agent(agent, ri, router) self._assert_ri_process_enabled(ri) @@ -1551,10 +1551,10 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): self.utils_replace_file.reset_mock() self.external_process.reset_mock() # Remove one subnet from the interface and reprocess - interfaces = copy.deepcopy(router[l3_constants.INTERFACE_KEY]) + interfaces = copy.deepcopy(router[lib_constants.INTERFACE_KEY]) del interfaces[1]['subnets'][0] del interfaces[1]['fixed_ips'][0] - router[l3_constants.INTERFACE_KEY] = interfaces + router[lib_constants.INTERFACE_KEY] = interfaces self._process_router_instance_for_agent(agent, ri, router) # Assert radvd was enabled again and that we only have one # prefix on the interface @@ -1578,7 +1578,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): internal_network_added.side_effect = RuntimeError self.assertRaises(RuntimeError, ri.process, agent) self.assertNotIn( - router[l3_constants.INTERFACE_KEY][0], ri.internal_ports) + router[lib_constants.INTERFACE_KEY][0], ri.internal_ports) # The unexpected exception has been fixed manually internal_network_added.side_effect = None @@ -1588,7 +1588,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): ri.process(agent) # We were able to add the port to ri.internal_ports self.assertIn( - router[l3_constants.INTERFACE_KEY][0], ri.internal_ports) + router[lib_constants.INTERFACE_KEY][0], ri.internal_ports) def test_process_router_internal_network_removed_unexpected_error(self): agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) @@ -1608,7 +1608,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): # The above port is set to down state, remove it. self.assertRaises(RuntimeError, ri.process, agent) self.assertIn( - router[l3_constants.INTERFACE_KEY][0], ri.internal_ports) + router[lib_constants.INTERFACE_KEY][0], ri.internal_ports) # The unexpected exception has been fixed manually internal_net_removed.side_effect = None @@ -1618,18 +1618,18 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): ri.process(agent) # We were able to remove the port from ri.internal_ports self.assertNotIn( - router[l3_constants.INTERFACE_KEY][0], ri.internal_ports) + router[lib_constants.INTERFACE_KEY][0], ri.internal_ports) def test_process_router_floatingip_nochange(self): agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) router = l3_test_common.prepare_router_data(num_internal_ports=1) fip1 = {'id': _uuid(), 'floating_ip_address': '8.8.8.8', 'fixed_ip_address': '7.7.7.7', 'status': 'ACTIVE', - 'port_id': router[l3_constants.INTERFACE_KEY][0]['id']} + 'port_id': router[lib_constants.INTERFACE_KEY][0]['id']} fip2 = copy.copy(fip1) fip2.update({'id': _uuid(), 'status': 'DOWN', 'floating_ip_address': '9.9.9.9'}) - router[l3_constants.FLOATINGIP_KEY] = [fip1, fip2] + router[lib_constants.FLOATINGIP_KEY] = [fip1, fip2] ri = legacy_router.LegacyRouter(router['id'], router, **self.ri_kwargs) @@ -1650,10 +1650,10 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): router = l3_test_common.prepare_router_data(num_internal_ports=1) fip1 = {'id': _uuid(), 'floating_ip_address': '8.8.8.8', 'fixed_ip_address': '7.7.7.7', 'status': 'ACTIVE', - 'port_id': router[l3_constants.INTERFACE_KEY][0]['id']} + 'port_id': router[lib_constants.INTERFACE_KEY][0]['id']} fip2 = copy.copy(fip1) fip2.update({'id': _uuid(), 'status': 'DOWN', }) - router[l3_constants.FLOATINGIP_KEY] = [fip1, fip2] + router[lib_constants.FLOATINGIP_KEY] = [fip1, fip2] ri = legacy_router.LegacyRouter(router['id'], router, **self.ri_kwargs) @@ -1676,12 +1676,12 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): 'update_floatingip_statuses') as mock_update_fip_status: fip_id = _uuid() router = l3_test_common.prepare_router_data(num_internal_ports=1) - router[l3_constants.FLOATINGIP_KEY] = [ + router[lib_constants.FLOATINGIP_KEY] = [ {'id': fip_id, 'floating_ip_address': '8.8.8.8', 'fixed_ip_address': '7.7.7.7', 'status': 'DOWN', - 'port_id': router[l3_constants.INTERFACE_KEY][0]['id']}] + 'port_id': router[lib_constants.INTERFACE_KEY][0]['id']}] ri = legacy_router.LegacyRouter(router['id'], router, @@ -1691,16 +1691,16 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): # Assess the call for putting the floating IP up was performed mock_update_fip_status.assert_called_once_with( mock.ANY, ri.router_id, - {fip_id: l3_constants.FLOATINGIP_STATUS_ACTIVE}) + {fip_id: lib_constants.FLOATINGIP_STATUS_ACTIVE}) mock_update_fip_status.reset_mock() # Process the router again, this time without floating IPs - router[l3_constants.FLOATINGIP_KEY] = [] + router[lib_constants.FLOATINGIP_KEY] = [] ri.router = router ri.process(agent) # Assess the call for putting the floating IP up was performed mock_update_fip_status.assert_called_once_with( mock.ANY, ri.router_id, - {fip_id: l3_constants.FLOATINGIP_STATUS_DOWN}) + {fip_id: lib_constants.FLOATINGIP_STATUS_DOWN}) def test_process_router_floatingip_exception(self): agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) @@ -1709,11 +1709,11 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): 'update_floatingip_statuses') as mock_update_fip_status: fip_id = _uuid() router = l3_test_common.prepare_router_data(num_internal_ports=1) - router[l3_constants.FLOATINGIP_KEY] = [ + router[lib_constants.FLOATINGIP_KEY] = [ {'id': fip_id, 'floating_ip_address': '8.8.8.8', 'fixed_ip_address': '7.7.7.7', - 'port_id': router[l3_constants.INTERFACE_KEY][0]['id']}] + 'port_id': router[lib_constants.INTERFACE_KEY][0]['id']}] ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri.process_floating_ip_addresses = mock.Mock( @@ -1724,7 +1724,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): # was performed mock_update_fip_status.assert_called_once_with( mock.ANY, ri.router_id, - {fip_id: l3_constants.FLOATINGIP_STATUS_ERROR}) + {fip_id: lib_constants.FLOATINGIP_STATUS_ERROR}) def test_process_external_iptables_exception(self): agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) @@ -1733,11 +1733,11 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): 'update_floatingip_statuses') as mock_update_fip_status: fip_id = _uuid() router = l3_test_common.prepare_router_data(num_internal_ports=1) - router[l3_constants.FLOATINGIP_KEY] = [ + router[lib_constants.FLOATINGIP_KEY] = [ {'id': fip_id, 'floating_ip_address': '8.8.8.8', 'fixed_ip_address': '7.7.7.7', - 'port_id': router[l3_constants.INTERFACE_KEY][0]['id']}] + 'port_id': router[lib_constants.INTERFACE_KEY][0]['id']}] ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri.iptables_manager._apply = mock.Mock(side_effect=Exception) @@ -1746,7 +1746,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): # was performed mock_update_fip_status.assert_called_once_with( mock.ANY, ri.router_id, - {fip_id: l3_constants.FLOATINGIP_STATUS_ERROR}) + {fip_id: lib_constants.FLOATINGIP_STATUS_ERROR}) self.assertEqual(1, ri.iptables_manager._apply.call_count) @@ -1829,7 +1829,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): num_internal_ports=1) ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) - internal_ports = ri.router.get(l3_constants.INTERFACE_KEY, []) + internal_ports = ri.router.get(lib_constants.INTERFACE_KEY, []) self.assertEqual(1, len(internal_ports)) internal_port = internal_ports[0] @@ -2360,8 +2360,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): def test_generate_radvd_mtu_conf(self): router = l3_test_common.prepare_router_data() - ipv6_subnet_modes = [{'ra_mode': n_const.IPV6_SLAAC, - 'address_mode': n_const.IPV6_SLAAC}] + ipv6_subnet_modes = [{'ra_mode': lib_constants.IPV6_SLAAC, + 'address_mode': lib_constants.IPV6_SLAAC}] network_mtu = '1446' ri = self._process_router_ipv6_subnet_added(router, ipv6_subnet_modes, @@ -2369,22 +2369,22 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): network_mtu) expected = "AdvLinkMTU 1446" ri.agent_conf.set_override('advertise_mtu', False) - ri.radvd._generate_radvd_conf(router[l3_constants.INTERFACE_KEY]) + ri.radvd._generate_radvd_conf(router[lib_constants.INTERFACE_KEY]) self.assertNotIn(expected, self.utils_replace_file.call_args[0][1]) # Verify that MTU is advertised when advertise_mtu is True ri.agent_conf.set_override('advertise_mtu', True) - ri.radvd._generate_radvd_conf(router[l3_constants.INTERFACE_KEY]) + ri.radvd._generate_radvd_conf(router[lib_constants.INTERFACE_KEY]) self.assertIn(expected, self.utils_replace_file.call_args[0][1]) def test_generate_radvd_conf_other_and_managed_flag(self): # expected = {ra_mode: (AdvOtherConfigFlag, AdvManagedFlag), ...} - expected = {n_const.IPV6_SLAAC: (False, False), - n_const.DHCPV6_STATELESS: (True, False), - n_const.DHCPV6_STATEFUL: (False, True)} + expected = {lib_constants.IPV6_SLAAC: (False, False), + lib_constants.DHCPV6_STATELESS: (True, False), + lib_constants.DHCPV6_STATEFUL: (False, True)} - modes = [n_const.IPV6_SLAAC, n_const.DHCPV6_STATELESS, - n_const.DHCPV6_STATEFUL] + modes = [lib_constants.IPV6_SLAAC, lib_constants.DHCPV6_STATELESS, + lib_constants.DHCPV6_STATEFUL] mode_combos = list(iter_chain(*[[list(combo) for combo in iter_combinations(modes, i)] for i in range(1, len(modes) + 1)])) @@ -2395,7 +2395,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): ri = self._process_router_ipv6_subnet_added(router, ipv6_subnet_modes) - ri.radvd._generate_radvd_conf(router[l3_constants.INTERFACE_KEY]) + ri.radvd._generate_radvd_conf(router[lib_constants.INTERFACE_KEY]) def assertFlag(flag): return (self.assertIn if flag else self.assertNotIn) @@ -2413,11 +2413,11 @@ 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': n_const.IPV6_SLAAC, - 'address_mode': n_const.IPV6_SLAAC}] + ipv6_subnet_modes = [{'ra_mode': lib_constants.IPV6_SLAAC, + 'address_mode': lib_constants.IPV6_SLAAC}] ri = self._process_router_ipv6_subnet_added(router, ipv6_subnet_modes) - ri.radvd._generate_radvd_conf(router[l3_constants.INTERFACE_KEY]) + ri.radvd._generate_radvd_conf(router[lib_constants.INTERFACE_KEY]) self.assertIn("MinRtrAdvInterval 22", self.utils_replace_file.call_args[0][1]) self.assertIn("MaxRtrAdvInterval 66", @@ -2425,13 +2425,13 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): def test_generate_radvd_rdnss_conf(self): router = l3_test_common.prepare_router_data() - ipv6_subnet_modes = [{'ra_mode': n_const.IPV6_SLAAC, - 'address_mode': n_const.IPV6_SLAAC}] + ipv6_subnet_modes = [{'ra_mode': lib_constants.IPV6_SLAAC, + 'address_mode': lib_constants.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, dns_nameservers=dns_list) - ri.radvd._generate_radvd_conf(router[l3_constants.INTERFACE_KEY]) + ri.radvd._generate_radvd_conf(router[lib_constants.INTERFACE_KEY]) # Verify that radvd configuration file includes RDNSS entries expected = "RDNSS " for dns in dns_list[0:ra.MAX_RDNSS_ENTRIES]: @@ -2512,7 +2512,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): expected_calls = [] for intf in intfs: # Remove the router interface - router[l3_constants.INTERFACE_KEY].remove(intf) + router[lib_constants.INTERFACE_KEY].remove(intf) requestor_id = self._pd_get_requestor_id(intf, router, ri) expected_calls += (self._pd_expected_call_external_process( requestor_id, ri, False)) 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 3742e122602..a34891a84ef 100644 --- a/neutron/tests/unit/agent/l3/test_dvr_local_router.py +++ b/neutron/tests/unit/agent/l3/test_dvr_local_router.py @@ -14,7 +14,7 @@ import mock import netaddr -from neutron_lib import constants as l3_constants +from neutron_lib import constants as lib_constants from oslo_config import cfg from oslo_log import log from oslo_utils import uuidutils @@ -125,7 +125,7 @@ class TestDvrRouterOperations(base.BaseTestCase): 'id': subnet_id_1}], 'network_id': _uuid(), 'device_owner': - l3_constants.DEVICE_OWNER_ROUTER_SNAT, + lib_constants.DEVICE_OWNER_ROUTER_SNAT, 'mac_address': 'fa:16:3e:80:8d:80', 'fixed_ips': [{'subnet_id': subnet_id_1, 'ip_address': '152.2.0.13', @@ -136,7 +136,7 @@ class TestDvrRouterOperations(base.BaseTestCase): 'id': subnet_id_2}], 'network_id': _uuid(), 'device_owner': - l3_constants.DEVICE_OWNER_ROUTER_SNAT, + lib_constants.DEVICE_OWNER_ROUTER_SNAT, 'mac_address': 'fa:16:3e:80:8d:80', 'fixed_ips': [{'subnet_id': subnet_id_2, 'ip_address': '152.10.0.13', @@ -320,7 +320,7 @@ class TestDvrRouterOperations(base.BaseTestCase): fip = {'floating_ip_address': ip} result = self._test_add_floating_ip(ri, fip, True) ri.floating_ip_added_dist.assert_called_once_with(fip, ip + '/32') - self.assertEqual(l3_constants.FLOATINGIP_STATUS_ACTIVE, result) + self.assertEqual(lib_constants.FLOATINGIP_STATUS_ACTIVE, result) @mock.patch.object(router_info.RouterInfo, 'remove_floating_ip') def test_remove_floating_ip(self, super_remove_floating_ip): @@ -375,10 +375,10 @@ class TestDvrRouterOperations(base.BaseTestCase): router['distributed'] = True ri = dvr_router.DvrLocalRouter( agent, HOSTNAME, router['id'], router, **self.ri_kwargs) - ports = ri.router.get(l3_constants.INTERFACE_KEY, []) + ports = ri.router.get(lib_constants.INTERFACE_KEY, []) subnet_id = l3_test_common.get_subnet_id(ports[0]) test_ports = [{'mac_address': '00:11:22:33:44:55', - 'device_owner': l3_constants.DEVICE_OWNER_DHCP, + 'device_owner': lib_constants.DEVICE_OWNER_DHCP, 'fixed_ips': [{'ip_address': '1.2.3.4', 'prefixlen': 24, 'subnet_id': subnet_id}]}] @@ -405,7 +405,7 @@ class TestDvrRouterOperations(base.BaseTestCase): router = l3_test_common.prepare_router_data(num_internal_ports=2) router['distributed'] = True subnet_id = l3_test_common.get_subnet_id( - router[l3_constants.INTERFACE_KEY][0]) + router[lib_constants.INTERFACE_KEY][0]) arp_table = {'ip_address': '1.7.23.11', 'mac_address': '00:11:22:33:44:55', 'subnet_id': subnet_id} @@ -421,7 +421,7 @@ class TestDvrRouterOperations(base.BaseTestCase): agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) router = l3_test_common.prepare_router_data(num_internal_ports=2) subnet_id = l3_test_common.get_subnet_id( - router[l3_constants.INTERFACE_KEY][0]) + router[lib_constants.INTERFACE_KEY][0]) arp_table = {'ip_address': '1.7.23.11', 'mac_address': '00:11:22:33:44:55', 'subnet_id': subnet_id} @@ -447,7 +447,7 @@ class TestDvrRouterOperations(base.BaseTestCase): ri = dvr_router.DvrLocalRouter( agent, HOSTNAME, router['id'], router, **self.ri_kwargs) subnet_id = l3_test_common.get_subnet_id( - ri.router[l3_constants.INTERFACE_KEY][0]) + ri.router[lib_constants.INTERFACE_KEY][0]) return ri, subnet_id def test__update_arp_entry_calls_arp_cache_with_no_device(self): @@ -487,7 +487,7 @@ class TestDvrRouterOperations(base.BaseTestCase): router = l3_test_common.prepare_router_data(num_internal_ports=2) router['distributed'] = True subnet_id = l3_test_common.get_subnet_id( - router[l3_constants.INTERFACE_KEY][0]) + router[lib_constants.INTERFACE_KEY][0]) arp_table = {'ip_address': '1.5.25.15', 'mac_address': '00:44:33:22:11:55', 'subnet_id': subnet_id} @@ -514,7 +514,7 @@ class TestDvrRouterOperations(base.BaseTestCase): 'gateway_ip': '20.0.0.1'}], 'id': _uuid(), portbindings.HOST_ID: 'myhost', - 'device_owner': l3_constants.DEVICE_OWNER_AGENT_GW, + 'device_owner': lib_constants.DEVICE_OWNER_AGENT_GW, 'network_id': fake_network_id, 'mac_address': 'ca:fe:de:ad:be:ef'}] ) @@ -545,7 +545,7 @@ class TestDvrRouterOperations(base.BaseTestCase): 'port_id': _uuid()}]} router = l3_test_common.prepare_router_data(enable_snat=True) - router[l3_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] + router[lib_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] router['distributed'] = True agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) ri = dvr_router.DvrLocalRouter(agent, diff --git a/neutron/tests/unit/agent/l3/test_legacy_router.py b/neutron/tests/unit/agent/l3/test_legacy_router.py index 3338c4bd84f..52df74ddd0f 100644 --- a/neutron/tests/unit/agent/l3/test_legacy_router.py +++ b/neutron/tests/unit/agent/l3/test_legacy_router.py @@ -13,7 +13,7 @@ # under the License. import mock -from neutron_lib import constants as l3_constants +from neutron_lib import constants as lib_constants from oslo_utils import uuidutils from neutron.agent.l3 import legacy_router @@ -78,9 +78,9 @@ class TestBasicRouterOperations(BasicRouterTestCaseFramework): ri.external_gateway_removed(ex_gw_port, "qg-fake-name") cidr_pri = '%s/%s' % (gw_ip_pri, v4_prefixlen) - cidr_sec = '%s/%s' % (gw_ip_sec, l3_constants.IPv4_BITS) + cidr_sec = '%s/%s' % (gw_ip_sec, lib_constants.IPv4_BITS) cidr_v6 = '%s/%s' % (gw_ip6_pri, v6_prefixlen) - cidr_v6_sec = '%s/%s' % (gw_ip6_sec, l3_constants.IPv6_BITS) + cidr_v6_sec = '%s/%s' % (gw_ip6_sec, lib_constants.IPv6_BITS) device.delete_addr_and_conntrack_state.assert_has_calls( [mock.call(cidr_pri), mock.call(cidr_sec), @@ -101,7 +101,7 @@ class TestAddFloatingIpWithMockGarp(BasicRouterTestCaseFramework): mock.sentinel.interface_name, ip, self.agent_conf) - self.assertEqual(l3_constants.FLOATINGIP_STATUS_ACTIVE, result) + self.assertEqual(lib_constants.FLOATINGIP_STATUS_ACTIVE, result) def test_add_floating_ip_error(self, send_ip_addr_adv_notif): ri = self._create_router() @@ -110,4 +110,4 @@ class TestAddFloatingIpWithMockGarp(BasicRouterTestCaseFramework): mock.sentinel.interface_name, mock.sentinel.device) self.assertFalse(ip_lib.send_ip_addr_adv_notif.called) - self.assertEqual(l3_constants.FLOATINGIP_STATUS_ERROR, result) + self.assertEqual(lib_constants.FLOATINGIP_STATUS_ERROR, result) diff --git a/neutron/tests/unit/agent/l3/test_router_info.py b/neutron/tests/unit/agent/l3/test_router_info.py index 69f51e449b5..ee05f2d7cda 100644 --- a/neutron/tests/unit/agent/l3/test_router_info.py +++ b/neutron/tests/unit/agent/l3/test_router_info.py @@ -11,7 +11,7 @@ # under the License. import mock -from neutron_lib import constants as l3_constants +from neutron_lib import constants as lib_constants from oslo_utils import uuidutils from neutron.agent.common import config as agent_config @@ -127,7 +127,7 @@ class TestRouterInfo(base.BaseTestCase): port = { 'id': _uuid(), 'fixed_ips': [{'ip_address': '172.9.9.9'}], - 'address_scopes': {l3_constants.IP_VERSION_4: '1234'} + 'address_scopes': {lib_constants.IP_VERSION_4: '1234'} } ipv4_mangle = ri.iptables_manager.ipv4['mangle'] = mock.MagicMock() ri.get_address_scope_mark_mask = mock.Mock(return_value='fake_mark') @@ -137,7 +137,7 @@ class TestRouterInfo(base.BaseTestCase): ri.process_floating_ip_address_scope_rules = mock.Mock() ri.iptables_manager._apply = mock.Mock() - ri.router[l3_constants.INTERFACE_KEY] = [port] + ri.router[lib_constants.INTERFACE_KEY] = [port] ri.process_address_scope() ipv4_mangle.add_rule.assert_called_once_with( @@ -338,8 +338,8 @@ class TestBasicRouterOperations(BasicRouterTestCaseFramework): statuses = ri.put_fips_in_error_state() - expected = [{mock.sentinel.id1: l3_constants.FLOATINGIP_STATUS_ERROR, - mock.sentinel.id2: l3_constants.FLOATINGIP_STATUS_ERROR}] + expected = [{mock.sentinel.id1: lib_constants.FLOATINGIP_STATUS_ERROR, + mock.sentinel.id2: lib_constants.FLOATINGIP_STATUS_ERROR}] self.assertNotEqual(expected, statuses) def test_configure_fip_addresses(self): @@ -372,7 +372,7 @@ class TestFloatingIpWithMockDevice(BasicRouterTestCaseFramework): 'id': fip_id, 'port_id': _uuid(), 'floating_ip_address': '15.1.2.3', 'fixed_ip_address': '192.168.0.2', - 'status': l3_constants.FLOATINGIP_STATUS_DOWN + 'status': lib_constants.FLOATINGIP_STATUS_DOWN } IPDevice.return_value = device = mock.Mock() @@ -382,7 +382,7 @@ class TestFloatingIpWithMockDevice(BasicRouterTestCaseFramework): fip_statuses = ri.process_floating_ip_addresses( mock.sentinel.interface_name) - self.assertEqual({fip_id: l3_constants.FLOATINGIP_STATUS_ACTIVE}, + self.assertEqual({fip_id: lib_constants.FLOATINGIP_STATUS_ACTIVE}, fip_statuses) self.assertFalse(device.addr.add.called) @@ -417,13 +417,13 @@ class TestFloatingIpWithMockDevice(BasicRouterTestCaseFramework): } ri = self._create_router() ri.add_floating_ip = mock.Mock( - return_value=l3_constants.FLOATINGIP_STATUS_ERROR) + return_value=lib_constants.FLOATINGIP_STATUS_ERROR) ri.get_floating_ips = mock.Mock(return_value=[fip]) fip_statuses = ri.process_floating_ip_addresses( mock.sentinel.interface_name) - self.assertEqual({fip_id: l3_constants.FLOATINGIP_STATUS_ERROR}, + self.assertEqual({fip_id: lib_constants.FLOATINGIP_STATUS_ERROR}, fip_statuses) # TODO(mrsmith): refactor for DVR cases diff --git a/neutron/tests/unit/agent/linux/test_dhcp.py b/neutron/tests/unit/agent/linux/test_dhcp.py index 915063b08c1..599c5e2b717 100644 --- a/neutron/tests/unit/agent/linux/test_dhcp.py +++ b/neutron/tests/unit/agent/linux/test_dhcp.py @@ -465,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 = n_const.DHCPV6_STATEFUL + self.ipv6_address_mode = constants.DHCPV6_STATEFUL class FakeV6SubnetSlaac(object): @@ -476,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 = n_const.IPV6_SLAAC + self.ipv6_address_mode = constants.IPV6_SLAAC self.ipv6_ra_mode = None @@ -489,7 +489,7 @@ class FakeV6SubnetStateless(object): self.enable_dhcp = True self.dns_nameservers = [] self.host_routes = [] - self.ipv6_address_mode = n_const.DHCPV6_STATELESS + self.ipv6_address_mode = constants.DHCPV6_STATELESS self.ipv6_ra_mode = None @@ -1064,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 == n_const.DHCPV6_STATEFUL): + or s.ipv6_address_mode == constants.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_ip_lib.py b/neutron/tests/unit/agent/linux/test_ip_lib.py index 3feca78d6b1..0b2217635df 100644 --- a/neutron/tests/unit/agent/linux/test_ip_lib.py +++ b/neutron/tests/unit/agent/linux/test_ip_lib.py @@ -15,11 +15,12 @@ import mock import netaddr +from neutron_lib import exceptions import testtools from neutron.agent.common import utils # noqa from neutron.agent.linux import ip_lib -from neutron.common import exceptions +from neutron.common import exceptions as n_exc from neutron.tests import base NETNS_SAMPLE = [ @@ -480,7 +481,7 @@ class TestIpWrapper(base.BaseTestCase): def test_add_vxlan_invalid_port_length(self): wrapper = ip_lib.IPWrapper() - self.assertRaises(exceptions.NetworkVxlanPortRangeError, + self.assertRaises(n_exc.NetworkVxlanPortRangeError, wrapper.add_vxlan, 'vxlan0', 'vni0', group='group0', dev='dev0', ttl='ttl0', tos='tos0', local='local0', proxy=True, diff --git a/neutron/tests/unit/agent/test_rpc.py b/neutron/tests/unit/agent/test_rpc.py index 9435b3ed85c..458ddfa78e1 100644 --- a/neutron/tests/unit/agent/test_rpc.py +++ b/neutron/tests/unit/agent/test_rpc.py @@ -25,7 +25,8 @@ from neutron.tests import base class AgentRPCPluginApi(base.BaseTestCase): def _test_rpc_call(self, method): agent = rpc.PluginApi('fake_topic') - ctxt = oslo_context.RequestContext('fake_user', 'fake_project') + ctxt = oslo_context.RequestContext(user='fake_user', + tenant='fake_project') expect_val = 'foo' with mock.patch.object(agent.client, 'call') as mock_call,\ mock.patch.object(agent.client, 'prepare') as mock_prepare: @@ -46,7 +47,8 @@ class AgentRPCPluginApi(base.BaseTestCase): def test_devices_details_list_unsupported(self): agent = rpc.PluginApi('fake_topic') - ctxt = oslo_context.RequestContext('fake_user', 'fake_project') + ctxt = oslo_context.RequestContext(user='fake_user', + tenant='fake_project') expect_val_get_device_details = 'foo' expect_val = [expect_val_get_device_details] with mock.patch.object(agent.client, 'call') as mock_call, \ @@ -75,7 +77,8 @@ class AgentPluginReportState(base.BaseTestCase): mock.patch.object(reportStateAPI.client, 'prepare' ) as mock_prepare: mock_prepare.return_value = reportStateAPI.client - ctxt = oslo_context.RequestContext('fake_user', 'fake_project') + ctxt = oslo_context.RequestContext(user='fake_user', + tenant='fake_project') reportStateAPI.report_state(ctxt, expected_agent_state, use_call=True) self.assertEqual(mock_call.call_args[0][0], ctxt) @@ -94,7 +97,8 @@ class AgentPluginReportState(base.BaseTestCase): mock.patch.object(reportStateAPI.client, 'prepare' ) as mock_prepare: mock_prepare.return_value = reportStateAPI.client - ctxt = oslo_context.RequestContext('fake_user', 'fake_project') + ctxt = oslo_context.RequestContext(user='fake_user', + tenant='fake_project') reportStateAPI.report_state(ctxt, expected_agent_state) self.assertEqual(mock_cast.call_args[0][0], ctxt) self.assertEqual(mock_cast.call_args[0][1], 'report_state') @@ -116,8 +120,8 @@ class AgentPluginReportState(base.BaseTestCase): mock.patch.object(reportStateAPI.client, 'prepare' ) as mock_prepare: mock_prepare.return_value = reportStateAPI.client - ctxt = oslo_context.RequestContext('fake_user', - 'fake_project') + ctxt = oslo_context.RequestContext(user='fake_user', + tenant='fake_project') reportStateAPI.report_state(ctxt, expected_agent_state) self.assertEqual(expected_time_str, mock_cast.call_args[1]['time']) diff --git a/neutron/tests/unit/agent/test_securitygroups_rpc.py b/neutron/tests/unit/agent/test_securitygroups_rpc.py index 37a261d79af..3a52f4c2c22 100644 --- a/neutron/tests/unit/agent/test_securitygroups_rpc.py +++ b/neutron/tests/unit/agent/test_securitygroups_rpc.py @@ -27,7 +27,6 @@ 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 n_const from neutron.common import ipv6_utils as ipv6 from neutron.common import rpc as n_rpc from neutron import context @@ -682,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=n_const.IPV6_SLAAC + ipv6_ra_mode=const.IPV6_SLAAC ) as subnet_v6,\ self.security_group() as sg1: sg1_id = sg1['security_group']['id'] @@ -750,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=n_const.IPV6_SLAAC + ipv6_ra_mode=const.IPV6_SLAAC ) as subnet_v6,\ self.security_group() as sg1: sg1_id = sg1['security_group']['id'] @@ -825,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=n_const.IPV6_SLAAC + ipv6_ra_mode=const.IPV6_SLAAC ) as subnet_v6,\ self.security_group() as sg1: sg1_id = sg1['security_group']['id'] @@ -893,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=n_const.IPV6_SLAAC + ipv6_ra_mode=const.IPV6_SLAAC ) as subnet_v6,\ self.security_group() as sg1: sg1_id = sg1['security_group']['id'] @@ -941,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=n_const.IPV6_SLAAC + ip_version=6, ipv6_ra_mode=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_l3_rpc.py b/neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py index 67eba74d415..6adb2af16bb 100644 --- a/neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py +++ b/neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py @@ -13,10 +13,10 @@ # 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 neutron.api.rpc.handlers import l3_rpc -from neutron.common import constants from neutron import context from neutron import manager from neutron.tests.unit.db import test_db_base_plugin_v2 diff --git a/neutron/tests/unit/api/test_api_common.py b/neutron/tests/unit/api/test_api_common.py index 4a2f90f36f6..446d0b5e4b4 100644 --- a/neutron/tests/unit/api/test_api_common.py +++ b/neutron/tests/unit/api/test_api_common.py @@ -20,7 +20,6 @@ from webob import exc from neutron.api import api_common as common from neutron.api.v2 import base as base_v2 -from neutron.common import exceptions as n_exc from neutron.tests import base @@ -98,8 +97,9 @@ class APICommonTestCase(base.BaseTestCase): params) def test_convert_exception_to_http_exc_multiple_different_codes(self): - e = n_exc.MultipleExceptions([exceptions.NetworkInUse(net_id='nid'), - exceptions.PortNotFound(port_id='pid')]) + e = exceptions.MultipleExceptions( + [exceptions.NetworkInUse(net_id='nid'), + exceptions.PortNotFound(port_id='pid')]) conv = common.convert_exception_to_http_exc(e, base_v2.FAULT_MAP, None) self.assertIsInstance(conv, exc.HTTPConflict) self.assertEqual( @@ -109,8 +109,9 @@ class APICommonTestCase(base.BaseTestCase): jsonutils.loads(conv.body)['NeutronError']['message']) def test_convert_exception_to_http_exc_multiple_same_codes(self): - e = n_exc.MultipleExceptions([exceptions.NetworkNotFound(net_id='nid'), - exceptions.PortNotFound(port_id='pid')]) + e = exceptions.MultipleExceptions( + [exceptions.NetworkNotFound(net_id='nid'), + exceptions.PortNotFound(port_id='pid')]) conv = common.convert_exception_to_http_exc(e, base_v2.FAULT_MAP, None) self.assertIsInstance(conv, exc.HTTPNotFound) self.assertEqual( @@ -118,7 +119,7 @@ class APICommonTestCase(base.BaseTestCase): jsonutils.loads(conv.body)['NeutronError']['message']) def test_convert_exception_to_http_exc_multiple_empty_inner(self): - e = n_exc.MultipleExceptions([]) + e = exceptions.MultipleExceptions([]) conv = common.convert_exception_to_http_exc(e, base_v2.FAULT_MAP, None) self.assertIsInstance(conv, exc.HTTPInternalServerError) diff --git a/neutron/tests/unit/common/test_ipv6_utils.py b/neutron/tests/unit/common/test_ipv6_utils.py index 4f891a14afe..fad579b2a34 100644 --- a/neutron/tests/unit/common/test_ipv6_utils.py +++ b/neutron/tests/unit/common/test_ipv6_utils.py @@ -15,8 +15,8 @@ import collections import mock +from neutron_lib import constants -from neutron.common import constants from neutron.common import ipv6_utils from neutron.tests import base from neutron.tests import tools diff --git a/neutron/tests/unit/db/test_api.py b/neutron/tests/unit/db/test_api.py index 6c51acf191c..7acab7abfea 100644 --- a/neutron/tests/unit/db/test_api.py +++ b/neutron/tests/unit/db/test_api.py @@ -13,6 +13,7 @@ # limitations under the License. import mock +from neutron_lib import exceptions from oslo_config import cfg from oslo_db import exception as db_exc import osprofiler @@ -20,7 +21,6 @@ import sqlalchemy from sqlalchemy.orm import exc import testtools -from neutron.common import exceptions from neutron.db import api as db_api from neutron.tests import base 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 a0e331e2047..654e466a9d4 100644 --- a/neutron/tests/unit/db/test_db_base_plugin_v2.py +++ b/neutron/tests/unit/db/test_db_base_plugin_v2.py @@ -1439,7 +1439,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=n_const.IPV6_SLAAC) as subnet: + ipv6_address_mode=constants.IPV6_SLAAC) as subnet: self.assertTrue( ipv6_utils.is_auto_address_subnet(subnet['subnet'])) self.check_update_port_mac(subnet=subnet) @@ -1656,7 +1656,7 @@ 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=n_const.IPV6_SLAAC, + ipv6_address_mode=constants.IPV6_SLAAC, gateway_ip=constants.ATTR_NOT_SPECIFIED) as subnet: with self.port(subnet=subnet) as port: ips = port['port']['fixed_ips'] @@ -1860,7 +1860,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s def test_create_port_invalid_fixed_ip_address_v6_pd_slaac(self): with self.network(name='net') as network: subnet = self._make_v6_subnet( - network, n_const.IPV6_SLAAC, ipv6_pd=True) + network, constants.IPV6_SLAAC, ipv6_pd=True) net_id = subnet['subnet']['network_id'] subnet_id = subnet['subnet']['id'] # update subnet with new prefix @@ -1878,7 +1878,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s def test_update_port_invalid_fixed_ip_address_v6_pd_slaac(self): with self.network(name='net') as network: subnet = self._make_v6_subnet( - network, n_const.IPV6_SLAAC, ipv6_pd=True) + network, constants.IPV6_SLAAC, ipv6_pd=True) net_id = subnet['subnet']['network_id'] subnet_id = subnet['subnet']['id'] # update subnet with new prefix @@ -1906,7 +1906,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s def test_update_port_invalid_subnet_v6_pd_slaac(self): with self.network(name='net') as network: subnet = self._make_v6_subnet( - network, n_const.IPV6_SLAAC, ipv6_pd=True) + network, constants.IPV6_SLAAC, ipv6_pd=True) subnet_id = subnet['subnet']['id'] # update subnet with new prefix prefix = '2001::/64' @@ -1934,7 +1934,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=n_const.IPV6_SLAAC) as subnet: + ipv6_address_mode=constants.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'] @@ -1946,7 +1946,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=n_const.IPV6_SLAAC) as subnet: + ipv6_address_mode=constants.IPV6_SLAAC) as subnet: kwargs = {"fixed_ips": [{'subnet_id': subnet['subnet']['id'], 'ip_address': 'fe80::1'}]} net_id = subnet['subnet']['network_id'] @@ -1962,7 +1962,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=n_const.IPV6_SLAAC) as subnet: + ipv6_address_mode=constants.IPV6_SLAAC) as subnet: with self.port(subnet, fixed_ips=[{'subnet_id': subnet['subnet']['id']}]) as port: @@ -1981,7 +1981,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=n_const.IPV6_SLAAC) as subnet2: + ipv6_address_mode=constants.IPV6_SLAAC) as subnet2: with self.port( subnet, fixed_ips=[{'subnet_id': subnet['subnet']['id']}, @@ -2010,7 +2010,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=n_const.IPV6_SLAAC): + ipv6_address_mode=constants.IPV6_SLAAC): subnet_ip_net = netaddr.IPNetwork(subnet_v4['subnet']['cidr']) # Create a router port without specifying fixed_ips port = self._make_port( @@ -2031,7 +2031,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, n_const.IPV6_SLAAC) + subnet = self._make_v6_subnet(network, constants.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), @@ -2048,7 +2048,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s with self.port(subnet=subnet, fixed_ips=fixed_ips) as port: port_fixed_ips = port['port']['fixed_ips'] self.assertEqual(1, len(port_fixed_ips)) - if addr_mode == n_const.IPV6_SLAAC: + if addr_mode == constants.IPV6_SLAAC: exp_ip_addr = self._calc_ipv6_addr_by_EUI64(port, subnet) self.assertEqual(exp_ip_addr, port_fixed_ips[0]['ip_address']) @@ -2057,15 +2057,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=n_const.IPV6_SLAAC) + addr_mode=constants.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=n_const.IPV6_SLAAC, ipv6_pd=True) + addr_mode=constants.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=n_const.DHCPV6_STATEFUL) + addr_mode=constants.DHCPV6_STATEFUL) def test_create_port_with_multiple_ipv4_and_ipv6_subnets(self): """Test port create with multiple IPv4, IPv6 DHCP/SLAAC subnets.""" @@ -2078,13 +2078,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': n_const.IPV6_SLAAC}, + 'ip_version': 6, 'ra_addr_mode': constants.IPV6_SLAAC}, {'gateway': 'fe81::1', 'cidr': 'fe81::/64', - 'ip_version': 6, 'ra_addr_mode': n_const.IPV6_SLAAC}, + 'ip_version': 6, 'ra_addr_mode': constants.IPV6_SLAAC}, {'gateway': 'fe82::1', 'cidr': 'fe82::/64', - 'ip_version': 6, 'ra_addr_mode': n_const.DHCPV6_STATEFUL}, + 'ip_version': 6, 'ra_addr_mode': constants.DHCPV6_STATEFUL}, {'gateway': 'fe83::1', 'cidr': 'fe83::/64', - 'ip_version': 6, 'ra_addr_mode': n_const.DHCPV6_STATEFUL}] + 'ip_version': 6, 'ra_addr_mode': constants.DHCPV6_STATEFUL}] subnets = {} for sub_dict in sub_dicts: subnet = self._make_subnet( @@ -2102,15 +2102,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, n_const.DHCPV6_STATEFUL: 0, - n_const.IPV6_SLAAC: 0} + addr_mode_count = {None: 0, constants.DHCPV6_STATEFUL: 0, + constants.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[n_const.DHCPV6_STATEFUL]) - self.assertEqual(2, addr_mode_count[n_const.IPV6_SLAAC]) + self.assertEqual(1, addr_mode_count[constants.DHCPV6_STATEFUL]) + self.assertEqual(2, addr_mode_count[constants.IPV6_SLAAC]) def test_delete_port_with_ipv6_slaac_address(self): """Test that a port with an IPv6 SLAAC address can be deleted.""" @@ -2118,7 +2118,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, n_const.IPV6_SLAAC) + self._make_v6_subnet(network, constants.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'])) @@ -2135,7 +2135,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, n_const.IPV6_SLAAC) + subnet_v6 = self._make_v6_subnet(network, constants.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'])) @@ -2159,7 +2159,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, n_const.IPV6_SLAAC) + subnet_v6 = self._make_v6_subnet(network, constants.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'])) @@ -2186,12 +2186,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=n_const.IPV6_SLAAC) + ipv6_ra_mode=constants.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=n_const.IPV6_SLAAC) + ipv6_ra_mode=constants.IPV6_SLAAC) port = self._make_port(self.fmt, network['network']['id']) port_mac = port['port']['mac_address'] cidr_1 = v6_subnet_1['subnet']['cidr'] @@ -3367,8 +3367,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=n_const.IPV6_SLAAC, - ipv6_address_mode=n_const.IPV6_SLAAC) + ipv6_ra_mode=constants.IPV6_SLAAC, + ipv6_address_mode=constants.IPV6_SLAAC) kwargs = {} if port_owner: kwargs['device_owner'] = port_owner @@ -3668,8 +3668,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=n_const.DHCPV6_STATEFUL, - ipv6_address_mode=n_const.DHCPV6_STATEFUL) + ipv6_ra_mode=constants.DHCPV6_STATEFUL, + ipv6_address_mode=constants.DHCPV6_STATEFUL) # Gateway is first IP in IPv6 DHCPv6 stateful subnet gateway = '2001::1' allocation_pools = [{'start': '2001::2', @@ -3679,15 +3679,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=n_const.DHCPV6_STATEFUL, - ipv6_address_mode=n_const.DHCPV6_STATEFUL) + ipv6_ra_mode=constants.DHCPV6_STATEFUL, + ipv6_address_mode=constants.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=n_const.IPV6_SLAAC, - ipv6_address_mode=n_const.IPV6_SLAAC) + ipv6_ra_mode=constants.IPV6_SLAAC, + ipv6_address_mode=constants.IPV6_SLAAC) @testtools.skipIf(tools.is_bsd(), 'bug/1484837') def test_create_subnet_ipv6_pd_gw_values(self): @@ -3701,8 +3701,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=n_const.DHCPV6_STATELESS, - ipv6_address_mode=n_const.DHCPV6_STATELESS) + ipv6_ra_mode=constants.DHCPV6_STATELESS, + ipv6_address_mode=constants.DHCPV6_STATELESS) # Gateway is first IP in IPv6 DHCPv6 Stateless subnet gateway = '::1' allocation_pools = [{'start': '::2', @@ -3712,15 +3712,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=n_const.DHCPV6_STATELESS, - ipv6_address_mode=n_const.DHCPV6_STATELESS) + ipv6_ra_mode=constants.DHCPV6_STATELESS, + ipv6_address_mode=constants.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=n_const.IPV6_SLAAC, - ipv6_address_mode=n_const.IPV6_SLAAC) + ipv6_ra_mode=constants.IPV6_SLAAC, + ipv6_address_mode=constants.IPV6_SLAAC) def test_create_subnet_gw_outside_cidr_returns_201(self): with self.network() as network: @@ -4058,7 +4058,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 n_const.IPV6_MODES: + for ra_mode in constants.IPV6_MODES: self._test_validate_subnet_ipv6_modes( ipv6_ra_mode=ra_mode) self._test_validate_subnet_ipv6_pd_modes( @@ -4066,7 +4066,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 n_const.IPV6_MODES: + for addr_mode in constants.IPV6_MODES: self._test_validate_subnet_ipv6_modes( ipv6_address_mode=addr_mode) self._test_validate_subnet_ipv6_pd_modes( @@ -4074,7 +4074,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 n_const.IPV6_MODES: + for ipv6_mode in constants.IPV6_MODES: self._test_validate_subnet_ipv6_modes( ipv6_ra_mode=ipv6_mode, ipv6_address_mode=ipv6_mode) @@ -4085,7 +4085,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( - n_const.IPV6_MODES, 2): + constants.IPV6_MODES, 2): self._test_validate_subnet_ipv6_modes( expect_success=not (ra_mode and addr_mode), ipv6_ra_mode=ra_mode, @@ -4101,8 +4101,8 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): subnet = self._test_create_subnet( gateway_ip=gateway_ip, cidr=cidr, ip_version=constants.IP_VERSION_6, - ipv6_ra_mode=n_const.DHCPV6_STATEFUL, - ipv6_address_mode=n_const.DHCPV6_STATEFUL) + ipv6_ra_mode=constants.DHCPV6_STATEFUL, + ipv6_address_mode=constants.DHCPV6_STATEFUL) self.assertEqual(constants.IP_VERSION_6, subnet['subnet']['ip_version']) self.assertEqual(gateway_ip, @@ -4119,8 +4119,8 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): self._test_create_subnet( gateway_ip=gateway_ip, cidr=cidr, ip_version=constants.IP_VERSION_6, - ipv6_ra_mode=n_const.DHCPV6_STATEFUL, - ipv6_address_mode=n_const.DHCPV6_STATEFUL) + ipv6_ra_mode=constants.DHCPV6_STATEFUL, + ipv6_address_mode=constants.DHCPV6_STATEFUL) self.assertEqual(webob.exc.HTTPClientError.code, ctx_manager.exception.code) @@ -4130,8 +4130,8 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): subnet = self._test_create_subnet( gateway_ip=gateway_ip, cidr=cidr, ip_version=constants.IP_VERSION_6, - ipv6_ra_mode=n_const.DHCPV6_STATEFUL, - ipv6_address_mode=n_const.DHCPV6_STATEFUL) + ipv6_ra_mode=constants.DHCPV6_STATEFUL, + ipv6_address_mode=constants.DHCPV6_STATEFUL) self.assertEqual(constants.IP_VERSION_6, subnet['subnet']['ip_version']) self.assertEqual(gateway_ip, @@ -4145,15 +4145,15 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): self._test_create_subnet( gateway_ip=gateway_ip, cidr=cidr, ip_version=6, - ipv6_ra_mode=n_const.IPV6_SLAAC, - ipv6_address_mode=n_const.IPV6_SLAAC) + ipv6_ra_mode=constants.IPV6_SLAAC, + ipv6_address_mode=constants.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 n_const.IPV6_MODES: + for mode in constants.IPV6_MODES: self._test_create_subnet(gateway_ip=gateway_ip, cidr=cidr, ip_version=6, enable_dhcp=False, @@ -4191,7 +4191,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=n_const.DHCPV6_STATEFUL) + ipv6_ra_mode=constants.DHCPV6_STATEFUL) self.assertEqual(webob.exc.HTTPClientError.code, ctx_manager.exception.code) @@ -4201,7 +4201,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): webob.exc.HTTPClientError) as ctx_manager: self._test_create_subnet( cidr=cidr, ip_version=4, - ipv6_address_mode=n_const.DHCPV6_STATEFUL) + ipv6_address_mode=constants.DHCPV6_STATEFUL) self.assertEqual(webob.exc.HTTPClientError.code, ctx_manager.exception.code) @@ -4258,30 +4258,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( - n_const.IPV6_SLAAC) + constants.IPV6_SLAAC) def test_create_subnet_dhcpv6_stateless_with_port_on_network(self): self._test_create_subnet_ipv6_auto_addr_with_port_on_network( - n_const.DHCPV6_STATELESS) + constants.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( - n_const.IPV6_SLAAC, + constants.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( - n_const.IPV6_SLAAC, + constants.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( - n_const.IPV6_SLAAC, + constants.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( - n_const.IPV6_SLAAC, insert_db_reference_error=True) + constants.IPV6_SLAAC, insert_db_reference_error=True) def test_update_subnet_no_gateway(self): with self.subnet() as subnet: @@ -4412,11 +4412,11 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): def test_subnet_update_ipv4_and_ipv6_pd_slaac_subnets(self): self._test_subnet_update_ipv4_and_ipv6_pd_subnets( - ra_addr_mode=n_const.IPV6_SLAAC) + ra_addr_mode=constants.IPV6_SLAAC) def test_subnet_update_ipv4_and_ipv6_pd_v6stateless_subnets(self): self._test_subnet_update_ipv4_and_ipv6_pd_subnets( - ra_addr_mode=n_const.DHCPV6_STATELESS) + ra_addr_mode=constants.DHCPV6_STATELESS) def test_update_subnet_shared_returns_400(self): with self.network(shared=True) as network: @@ -4543,10 +4543,10 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): def test_update_subnet_ipv6_attributes_fails(self): with self.subnet(ip_version=6, cidr='fe80::/64', - 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}} + 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}} req = self.new_update_request('subnets', data, subnet['subnet']['id']) res = req.get_response(self.api) @@ -4555,8 +4555,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=n_const.IPV6_SLAAC) as subnet: - data = {'subnet': {'ipv6_ra_mode': n_const.DHCPV6_STATEFUL}} + ipv6_ra_mode=constants.IPV6_SLAAC) as subnet: + data = {'subnet': {'ipv6_ra_mode': constants.DHCPV6_STATEFUL}} req = self.new_update_request('subnets', data, subnet['subnet']['id']) res = req.get_response(self.api) @@ -4565,8 +4565,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=n_const.IPV6_SLAAC) as subnet: - data = {'subnet': {'ipv6_address_mode': n_const.DHCPV6_STATEFUL}} + ipv6_address_mode=constants.IPV6_SLAAC) as subnet: + data = {'subnet': {'ipv6_address_mode': constants.DHCPV6_STATEFUL}} req = self.new_update_request('subnets', data, subnet['subnet']['id']) res = req.get_response(self.api) @@ -4575,8 +4575,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=n_const.IPV6_SLAAC, - ipv6_address_mode=n_const.IPV6_SLAAC) as subnet: + ipv6_ra_mode=constants.IPV6_SLAAC, + ipv6_address_mode=constants.IPV6_SLAAC) as subnet: data = {'subnet': {'enable_dhcp': False}} req = self.new_update_request('subnets', data, subnet['subnet']['id']) @@ -4588,7 +4588,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): with self.network() as network: with self.subnet(network=network) as subnet: data = {'subnet': {'ipv6_ra_mode': - n_const.DHCPV6_STATEFUL}} + constants.DHCPV6_STATEFUL}} req = self.new_update_request('subnets', data, subnet['subnet']['id']) res = req.get_response(self.api) @@ -4599,7 +4599,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): with self.network() as network: with self.subnet(network=network) as subnet: data = {'subnet': {'ipv6_address_mode': - n_const.DHCPV6_STATEFUL}} + constants.DHCPV6_STATEFUL}} req = self.new_update_request('subnets', data, subnet['subnet']['id']) res = req.get_response(self.api) diff --git a/neutron/tests/unit/db/test_ipam_backend_mixin.py b/neutron/tests/unit/db/test_ipam_backend_mixin.py index 52aab8f3ed7..b281a7f6352 100644 --- a/neutron/tests/unit/db/test_ipam_backend_mixin.py +++ b/neutron/tests/unit/db/test_ipam_backend_mixin.py @@ -18,7 +18,6 @@ import netaddr from neutron_lib import constants import webob.exc -from neutron.common import constants as n_const from neutron.db import db_base_plugin_v2 from neutron.db import ipam_backend_mixin from neutron.db import portbindings_db @@ -51,8 +50,8 @@ class TestIpamBackendMixin(base.BaseTestCase): return results def _mock_slaac_subnet_on(self): - slaac_subnet = {'ipv6_address_mode': n_const.IPV6_SLAAC, - 'ipv6_ra_mode': n_const.IPV6_SLAAC} + slaac_subnet = {'ipv6_address_mode': constants.IPV6_SLAAC, + 'ipv6_ra_mode': constants.IPV6_SLAAC} self.mixin._get_subnet = mock.Mock(return_value=slaac_subnet) def _mock_slaac_subnet_off(self): @@ -64,8 +63,8 @@ class TestIpamBackendMixin(base.BaseTestCase): """Mock incoming subnets as autoaddressed.""" def _get_subnet(context, subnet_id): if subnet_id in subnet_ids: - return {'ipv6_address_mode': n_const.IPV6_SLAAC, - 'ipv6_ra_mode': n_const.IPV6_SLAAC} + return {'ipv6_address_mode': constants.IPV6_SLAAC, + 'ipv6_ra_mode': constants.IPV6_SLAAC} else: return {'ipv6_address_mode': None, 'ipv6_ra_mode': None} @@ -135,8 +134,8 @@ class TestIpamBackendMixin(base.BaseTestCase): # mock to test auto address part pd_subnet = {'subnetpool_id': constants.IPV6_PD_POOL_ID, - 'ipv6_address_mode': n_const.IPV6_SLAAC, - 'ipv6_ra_mode': n_const.IPV6_SLAAC} + 'ipv6_address_mode': constants.IPV6_SLAAC, + 'ipv6_ra_mode': constants.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_pluggable_backend.py b/neutron/tests/unit/db/test_ipam_pluggable_backend.py index ffdcdcbcfb5..eb4e3ab3df3 100644 --- a/neutron/tests/unit/db/test_ipam_pluggable_backend.py +++ b/neutron/tests/unit/db/test_ipam_pluggable_backend.py @@ -359,8 +359,8 @@ class TestDbBasePluginIpam(test_db_base.NeutronDbPluginV2TestCase): 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=n_const.IPV6_SLAAC, - ipv6_address_mode=n_const.IPV6_SLAAC): + ipv6_ra_mode=constants.IPV6_SLAAC, + ipv6_address_mode=constants.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_hamode_db.py b/neutron/tests/unit/db/test_l3_hamode_db.py index f8a1cf501f9..049c308fbfb 100644 --- a/neutron/tests/unit/db/test_l3_hamode_db.py +++ b/neutron/tests/unit/db/test_l3_hamode_db.py @@ -65,7 +65,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', n_const.L3_AGENT_MODE_DVR_SNAT) + 'host_2', constants.L3_AGENT_MODE_DVR_SNAT) def _create_router(self, ha=True, tenant_id='tenant1', distributed=None, ctx=None, admin_state_up=True): @@ -839,7 +839,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', n_const.L3_AGENT_MODE_DVR) + helpers.register_l3_agent('host_3', constants.L3_AGENT_MODE_DVR) num_ha_candidates = self.plugin.get_number_of_agents_for_scheduling( self.admin_ctx) self.assertEqual(2, num_ha_candidates) @@ -852,7 +852,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', n_const.L3_AGENT_MODE_DVR_SNAT) + helpers.register_l3_agent('host_3', constants.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) @@ -1054,7 +1054,7 @@ class L3HAModeDbTestCase(L3HATestFramework): def test_ensure_host_set_on_ports_dvr_ha_binds_to_active(self): agent3 = helpers.register_l3_agent('host_3', - n_const.L3_AGENT_MODE_DVR_SNAT) + constants.L3_AGENT_MODE_DVR_SNAT) ext_net = self._create_network(self.core_plugin, self.admin_ctx, external=True) int_net = self._create_network(self.core_plugin, self.admin_ctx) diff --git a/neutron/tests/unit/extensions/test_dns.py b/neutron/tests/unit/extensions/test_dns.py index fde7f45e158..3005dd41055 100644 --- a/neutron/tests/unit/extensions/test_dns.py +++ b/neutron/tests/unit/extensions/test_dns.py @@ -15,10 +15,9 @@ import math import netaddr -from neutron_lib import constants as n_const +from neutron_lib import constants from oslo_config import cfg -from neutron.common import constants from neutron.common import utils from neutron import context from neutron.db import db_base_plugin_v2 @@ -92,7 +91,7 @@ class DnsExtensionTestCase(test_plugin.Ml2PluginV2TestCase): 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'] == n_const.DEVICE_OWNER_DHCP and + kwargs['device_owner'] == constants.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_l3.py b/neutron/tests/unit/extensions/test_l3.py index 17cbdd149b0..e47bc417427 100644 --- a/neutron/tests/unit/extensions/test_l3.py +++ b/neutron/tests/unit/extensions/test_l3.py @@ -19,7 +19,7 @@ import copy import mock import netaddr -from neutron_lib import constants as l3_constants +from neutron_lib import constants as lib_constants from neutron_lib import exceptions as n_exc from oslo_config import cfg from oslo_utils import importutils @@ -34,7 +34,6 @@ 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 n_const from neutron import context from neutron.db import common_db_mixin from neutron.db import db_base_plugin_v2 @@ -66,7 +65,7 @@ _uuid = uuidutils.generate_uuid _get_path = test_base._get_path -DEVICE_OWNER_COMPUTE = l3_constants.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' +DEVICE_OWNER_COMPUTE = lib_constants.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' class L3TestExtensionManager(object): @@ -322,7 +321,7 @@ class TestL3NatAgentSchedulingServicePlugin(TestL3NatServicePlugin, self.router_scheduler = importutils.import_object( cfg.CONF.router_scheduler_driver) self.agent_notifiers.update( - {l3_constants.AGENT_TYPE_L3: l3_rpc_agent_api.L3AgentNotifyAPI()}) + {lib_constants.AGENT_TYPE_L3: l3_rpc_agent_api.L3AgentNotifyAPI()}) class L3NatTestCaseMixin(object): @@ -932,8 +931,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=n_const.IPV6_SLAAC, - ipv6_address_mode=n_const.IPV6_SLAAC)) + ipv6_ra_mode=lib_constants.IPV6_SLAAC, + ipv6_address_mode=lib_constants.IPV6_SLAAC)) res3 = self._show('routers', r['router']['id']) fips = (res3['router']['external_gateway_info'] ['external_fixed_ips']) @@ -1015,9 +1014,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 = n_const.IPV6_SLAAC - stateful = n_const.DHCPV6_STATEFUL - stateless = n_const.DHCPV6_STATELESS + slaac = lib_constants.IPV6_SLAAC + stateful = lib_constants.DHCPV6_STATEFUL + stateless = lib_constants.DHCPV6_STATELESS use_cases = [{'msg': 'IPv6 Subnet Modes (slaac, none)', 'ra_mode': slaac, 'address_mode': None}, {'msg': 'IPv6 Subnet Modes (none, none)', @@ -1136,13 +1135,13 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): """ use_cases = [{'msg': 'IPv6 Subnet Modes (none, slaac)', 'ra_mode': None, - 'address_mode': n_const.IPV6_SLAAC}, + 'address_mode': lib_constants.IPV6_SLAAC}, {'msg': 'IPv6 Subnet Modes (none, dhcpv6-stateful)', 'ra_mode': None, - 'address_mode': n_const.DHCPV6_STATEFUL}, + 'address_mode': lib_constants.DHCPV6_STATEFUL}, {'msg': 'IPv6 Subnet Modes (none, dhcpv6-stateless)', 'ra_mode': None, - 'address_mode': n_const.DHCPV6_STATELESS}] + 'address_mode': lib_constants.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', @@ -1227,7 +1226,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): self.assertIn('port_id', body) self.assertEqual(p['port']['id'], body['port_id']) expected_port_update = { - 'device_owner': l3_constants.DEVICE_OWNER_ROUTER_INTF, + 'device_owner': lib_constants.DEVICE_OWNER_ROUTER_INTF, 'device_id': r['router']['id']} update_port.assert_any_call( mock.ANY, p['port']['id'], {'port': expected_port_update}) @@ -1292,7 +1291,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): port_id, device_id): self.assertNotIn('port_id', body) expected_port_update_before_update = { - 'device_owner': l3_constants.DEVICE_OWNER_ROUTER_INTF, + 'device_owner': lib_constants.DEVICE_OWNER_ROUTER_INTF, 'device_id': device_id} expected_port_update_after_fail = { 'device_owner': '', @@ -1431,7 +1430,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): with self.network() as network, self.router() as r: # Create a router port without ips p = self._make_port(self.fmt, network['network']['id'], - device_owner=l3_constants.DEVICE_OWNER_ROUTER_INTF) + device_owner=lib_constants.DEVICE_OWNER_ROUTER_INTF) err_code = exc.HTTPBadRequest.code self._router_interface_action('add', r['router']['id'], @@ -1567,18 +1566,18 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): self.subnet( cidr='2001:db8::/64', network=n, ip_version=6, - ipv6_ra_mode=n_const.IPV6_SLAAC, - ipv6_address_mode=n_const.IPV6_SLAAC)) as s3, ( + ipv6_ra_mode=lib_constants.IPV6_SLAAC, + ipv6_address_mode=lib_constants.IPV6_SLAAC)) as s3, ( self.subnet( cidr='2001:db8:1::/64', network=n, ip_version=6, - ipv6_ra_mode=n_const.DHCPV6_STATEFUL, - ipv6_address_mode=n_const.DHCPV6_STATEFUL)) as s4, ( + ipv6_ra_mode=lib_constants.DHCPV6_STATEFUL, + ipv6_address_mode=lib_constants.DHCPV6_STATEFUL)) as s4, ( self.subnet( cidr='2001:db8:2::/64', network=n, ip_version=6, - ipv6_ra_mode=n_const.DHCPV6_STATELESS, - ipv6_address_mode=n_const.DHCPV6_STATELESS)) as s5: + ipv6_ra_mode=lib_constants.DHCPV6_STATELESS, + ipv6_address_mode=lib_constants.DHCPV6_STATELESS)) as s5: self._set_net_external(n['network']['id']) self._add_external_gateway_to_router( r['router']['id'], @@ -1646,7 +1645,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): with self.network(tenant_id='tenant_a', set_context=True) as n: with self.subnet(network=n): - for device_owner in l3_constants.ROUTER_INTERFACE_OWNERS: + for device_owner in lib_constants.ROUTER_INTERFACE_OWNERS: self._create_port( self.fmt, n['network']['id'], tenant_id='tenant_a', @@ -1664,7 +1663,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): with self.network(tenant_id='tenant_a', set_context=True) as n: with self.subnet(network=n): - for device_owner in l3_constants.ROUTER_INTERFACE_OWNERS: + for device_owner in lib_constants.ROUTER_INTERFACE_OWNERS: port_res = self._create_port( self.fmt, n['network']['id'], tenant_id='tenant_a', @@ -2024,7 +2023,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): self.assertEqual(400, res.status_int) for p in self._list('ports')['ports']: if (p['device_owner'] == - l3_constants.DEVICE_OWNER_FLOATINGIP): + lib_constants.DEVICE_OWNER_FLOATINGIP): self.fail('garbage port is not deleted') def test_floatingip_with_assoc_fails(self): @@ -2032,7 +2031,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): 'neutron.db.l3_db.L3_NAT_dbonly_mixin._check_and_get_fip_assoc') def test_create_floatingip_with_assoc( - self, expected_status=l3_constants.FLOATINGIP_STATUS_ACTIVE): + self, expected_status=lib_constants.FLOATINGIP_STATUS_ACTIVE): with self.floatingip_with_assoc() as fip: body = self._show('floatingips', fip['floatingip']['id']) self.assertEqual(body['floatingip']['id'], @@ -2076,11 +2075,11 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): with self.floatingip_with_assoc(): port_body = self._list('ports', query_params='device_owner=network:floatingip')['ports'][0] - self.assertEqual(l3_constants.PORT_STATUS_NOTAPPLICABLE, + self.assertEqual(lib_constants.PORT_STATUS_NOTAPPLICABLE, port_body['status']) def test_floatingip_update( - self, expected_status=l3_constants.FLOATINGIP_STATUS_ACTIVE): + self, expected_status=lib_constants.FLOATINGIP_STATUS_ACTIVE): with self.port() as p: private_sub = {'subnet': {'id': p['port']['fixed_ips'][0]['subnet_id']}} @@ -2191,7 +2190,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): expected_code=exc.HTTPBadRequest.code) def test_floatingip_update_to_same_port_id_twice( - self, expected_status=l3_constants.FLOATINGIP_STATUS_ACTIVE): + self, expected_status=lib_constants.FLOATINGIP_STATUS_ACTIVE): with self.port() as p: private_sub = {'subnet': {'id': p['port']['fixed_ips'][0]['subnet_id']}} @@ -2388,7 +2387,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): found = False with self.floatingip_with_assoc(): for p in self._list('ports')['ports']: - if p['device_owner'] == l3_constants.DEVICE_OWNER_FLOATINGIP: + if p['device_owner'] == lib_constants.DEVICE_OWNER_FLOATINGIP: self._delete('ports', p['id'], expected_code=exc.HTTPConflict.code) found = True @@ -2699,7 +2698,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): ).filter( models_v2.Port.network_id == internal_port['network_id'], l3_db.RouterPort.port_type.in_( - l3_constants.ROUTER_INTERFACE_OWNERS + lib_constants.ROUTER_INTERFACE_OWNERS ), models_v2.IPAllocation.subnet_id == internal_subnet['id'] ).join( @@ -2738,7 +2737,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): found = False with self.floatingip_with_assoc(): for p in self._list('ports')['ports']: - if p['device_owner'] == l3_constants.DEVICE_OWNER_ROUTER_INTF: + if p['device_owner'] == lib_constants.DEVICE_OWNER_ROUTER_INTF: subnet_id = p['fixed_ips'][0]['subnet_id'] router_id = p['device_id'] self._router_interface_action( @@ -2752,7 +2751,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): found = False with self.floatingip_with_assoc(): for p in self._list('ports')['ports']: - if p['device_owner'] == l3_constants.DEVICE_OWNER_ROUTER_INTF: + if p['device_owner'] == lib_constants.DEVICE_OWNER_ROUTER_INTF: router_id = p['device_id'] self._router_interface_action( 'remove', router_id, None, p['id'], @@ -2784,12 +2783,12 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): def test_router_delete_ipv6_slaac_subnet_inuse_returns_409(self): with self.router() as r: - with self._ipv6_subnet(n_const.IPV6_SLAAC) as s: + with self._ipv6_subnet(lib_constants.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(n_const.DHCPV6_STATELESS) as s: + with self._ipv6_subnet(lib_constants.DHCPV6_STATELESS) as s: self._test_router_delete_subnet_inuse_returns_409(r, s) def test_delete_ext_net_with_disassociated_floating_ips(self): @@ -3067,7 +3066,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): allocation_pools=allocation_pools, cidr='120.0.0.0/24') as subnet: kwargs = { - 'device_owner': l3_constants.DEVICE_OWNER_ROUTER_GW, + 'device_owner': lib_constants.DEVICE_OWNER_ROUTER_GW, 'device_id': 'fake_device'} with self.port(subnet=subnet, **kwargs): data = {'subnet': {'gateway_ip': '120.0.0.2'}} @@ -3127,7 +3126,7 @@ class L3AgentDbTestCaseBase(L3NatTestCaseMixin): routers = self.plugin.get_sync_data( context.get_admin_context(), None) self.assertEqual(1, len(routers)) - interfaces = routers[0][l3_constants.INTERFACE_KEY] + interfaces = routers[0][lib_constants.INTERFACE_KEY] self.assertEqual(1, len(interfaces)) subnets = interfaces[0]['subnets'] self.assertEqual(1, len(subnets)) @@ -3189,7 +3188,8 @@ class L3AgentDbTestCaseBase(L3NatTestCaseMixin): self.core_plugin.update_port(ctx, p['port']['id'], port) routers = self.plugin.get_sync_data(ctx, None) self.assertEqual(1, len(routers)) - interfaces = routers[0].get(l3_constants.INTERFACE_KEY, []) + interfaces = routers[0].get(lib_constants.INTERFACE_KEY, + []) self.assertEqual(1, len(interfaces)) def test_l3_agent_routers_query_gateway(self): @@ -3215,7 +3215,7 @@ class L3AgentDbTestCaseBase(L3NatTestCaseMixin): routers = self.plugin.get_sync_data( context.get_admin_context(), [fip['floatingip']['router_id']]) self.assertEqual(1, len(routers)) - floatingips = routers[0][l3_constants.FLOATINGIP_KEY] + floatingips = routers[0][lib_constants.FLOATINGIP_KEY] self.assertEqual(1, len(floatingips)) self.assertEqual(floatingips[0]['id'], fip['floatingip']['id']) diff --git a/neutron/tests/unit/extensions/test_network_ip_availability.py b/neutron/tests/unit/extensions/test_network_ip_availability.py index 3a6ae2f8439..8e25e972d08 100644 --- a/neutron/tests/unit/extensions/test_network_ip_availability.py +++ b/neutron/tests/unit/extensions/test_network_ip_availability.py @@ -13,9 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +from neutron_lib import constants + import neutron.api.extensions as api_ext import neutron.common.config as config -import neutron.common.constants as constants import neutron.extensions import neutron.services.network_ip_availability.plugin as plugin_module import neutron.tests.unit.db.test_db_base_plugin_v2 as test_db_base_plugin_v2 diff --git a/neutron/tests/unit/hacking/test_checks.py b/neutron/tests/unit/hacking/test_checks.py index 88de02456e8..8ee3ecbd4d7 100644 --- a/neutron/tests/unit/hacking/test_checks.py +++ b/neutron/tests/unit/hacking/test_checks.py @@ -249,10 +249,10 @@ class HackingTestCase(base.BaseTestCase): 1, len(list(checks.check_assertempty(fail_code % (ec, ec), "neutron/tests/test_assert.py")))) self.assertEqual( - 0, len(list(checks.check_assertfalse(pass_code1 % (ec, ec), + 0, len(list(checks.check_asserttruefalse(pass_code1 % (ec, ec), "neutron/tests/test_assert.py")))) self.assertEqual( - 0, len(list(checks.check_assertfalse(pass_code2 % ec, + 0, len(list(checks.check_asserttruefalse(pass_code2 % ec, "neutron/tests/test_assert.py")))) def test_assertisinstance(self): diff --git a/neutron/tests/unit/notifiers/test_nova.py b/neutron/tests/unit/notifiers/test_nova.py index 4d1b4a86025..6bd0e03c718 100644 --- a/neutron/tests/unit/notifiers/test_nova.py +++ b/neutron/tests/unit/notifiers/test_nova.py @@ -22,13 +22,12 @@ from oslo_config import cfg from oslo_utils import uuidutils from sqlalchemy.orm import attributes as sql_attr -from neutron.common import constants from neutron.db import models_v2 from neutron.notifiers import nova from neutron.tests import base DEVICE_OWNER_COMPUTE = n_const.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' -DEVICE_OWNER_BAREMETAL = constants.DEVICE_OWNER_BAREMETAL_PREFIX + 'fake' +DEVICE_OWNER_BAREMETAL = n_const.DEVICE_OWNER_BAREMETAL_PREFIX + 'fake' class TestNovaNotify(base.BaseTestCase): diff --git a/neutron/tests/unit/objects/test_common_types.py b/neutron/tests/unit/objects/test_common_types.py index ccfcdc2ba13..7969304dd74 100644 --- a/neutron/tests/unit/objects/test_common_types.py +++ b/neutron/tests/unit/objects/test_common_types.py @@ -57,7 +57,7 @@ class IPV6ModeEnumFieldTest(test_base.BaseTestCase, TestField): super(IPV6ModeEnumFieldTest, self).setUp() self.field = common_types.IPV6ModeEnumField() self.coerce_good_values = [(mode, mode) - for mode in constants.IPV6_MODES] + for mode in const.IPV6_MODES] self.coerce_bad_values = ['6', 4, 'type', 'slaacc'] self.to_primitive_values = self.coerce_good_values self.from_primitive_values = self.coerce_good_values 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 c462f9c637f..f87505548e0 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 @@ -19,7 +19,6 @@ from neutron_lib import exceptions from oslo_serialization import jsonutils import testtools -from neutron.common import constants as n_const from neutron.common import topics from neutron import context from neutron.extensions import portbindings @@ -435,7 +434,7 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase): cidr='2001:db8::/64', ip_version=6, gateway_ip='fe80::1', - ipv6_address_mode=n_const.IPV6_SLAAC) as subnet2: + ipv6_address_mode=constants.IPV6_SLAAC) as subnet2: with self.port( subnet, fixed_ips=[{'subnet_id': subnet['subnet']['id']}, diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py index 2fe19ba6338..91b063f6a6d 100644 --- a/neutron/tests/unit/plugins/ml2/test_plugin.py +++ b/neutron/tests/unit/plugins/ml2/test_plugin.py @@ -32,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 as n_const from neutron.common import utils from neutron import context from neutron.db import agents_db @@ -2323,7 +2322,7 @@ class TestML2PluggableIPAM(test_ipam.UseIpamMixin, TestMl2SubnetsV2): with self.subnet(network=network, cidr='2001:100::0/64', ip_version=6, - ipv6_ra_mode=n_const.IPV6_SLAAC) as subnet: + ipv6_ra_mode=constants.IPV6_SLAAC) as subnet: with self.port(subnet=subnet) as port: with mock.patch(driver) as driver_mock: # Validate that deletion of SLAAC allocation happens diff --git a/neutron/tests/unit/plugins/ml2/test_rpc.py b/neutron/tests/unit/plugins/ml2/test_rpc.py index 9a040c2f1ca..266300d8e38 100644 --- a/neutron/tests/unit/plugins/ml2/test_rpc.py +++ b/neutron/tests/unit/plugins/ml2/test_rpc.py @@ -312,7 +312,8 @@ class RpcCallbacksTestCase(base.BaseTestCase): class RpcApiTestCase(base.BaseTestCase): def _test_rpc_api(self, rpcapi, topic, method, rpc_method, **kwargs): - ctxt = oslo_context.RequestContext('fake_user', 'fake_project') + ctxt = oslo_context.RequestContext(user='fake_user', + tenant='fake_project') expected_retval = 'foo' if rpc_method == 'call' else None expected_version = kwargs.pop('version', None) fanout = kwargs.pop('fanout', False) @@ -443,7 +444,8 @@ class RpcApiTestCase(base.BaseTestCase): def test_update_device_list_unsupported(self): rpcapi = agent_rpc.PluginApi(topics.PLUGIN) - ctxt = oslo_context.RequestContext('fake_user', 'fake_project') + ctxt = oslo_context.RequestContext(user='fake_user', + tenant='fake_project') devices_up = ['fake_device1', 'fake_device2'] devices_down = ['fake_device3', 'fake_device4'] expected_ret_val = {'devices_up': ['fake_device2'], @@ -485,7 +487,8 @@ class RpcApiTestCase(base.BaseTestCase): def test_get_devices_details_list_and_failed_devices_unsupported(self): rpcapi = agent_rpc.PluginApi(topics.PLUGIN) - ctxt = oslo_context.RequestContext('fake_user', 'fake_project') + ctxt = oslo_context.RequestContext(user='fake_user', + tenant='fake_project') devices = ['fake_device1', 'fake_device2'] dev2_details = {'device': 'fake_device2', 'network_id': 'net_id', 'port_id': 'port_id', 'admin_state_up': True} diff --git a/neutron/tests/unit/test_policy.py b/neutron/tests/unit/test_policy.py index 68602743cea..59b21cccae4 100644 --- a/neutron/tests/unit/test_policy.py +++ b/neutron/tests/unit/test_policy.py @@ -16,7 +16,7 @@ """Test of Policy Engine For Neutron""" import mock -from neutron_lib import constants as const +from neutron_lib import constants from neutron_lib import exceptions from oslo_db import exception as db_exc from oslo_policy import fixture as op_fixture @@ -27,7 +27,6 @@ from oslo_utils import importutils import neutron from neutron.api.v2 import attributes from neutron.common import constants as n_const -from neutron.common import exceptions as n_exc from neutron import context from neutron import manager from neutron import policy @@ -330,10 +329,10 @@ class NeutronPolicyTestCase(base.BaseTestCase): oslo_policy.PolicyNotAuthorized) def test_create_port_device_owner_regex(self): - blocked_values = (const.DEVICE_OWNER_NETWORK_PREFIX, + blocked_values = (constants.DEVICE_OWNER_NETWORK_PREFIX, 'network:abdef', - const.DEVICE_OWNER_DHCP, - const.DEVICE_OWNER_ROUTER_INTF) + constants.DEVICE_OWNER_DHCP, + constants.DEVICE_OWNER_ROUTER_INTF) for val in blocked_values: self._test_advsvc_action_on_attr( 'create', 'port', 'device_owner', val, @@ -570,7 +569,7 @@ class NeutronPolicyTestCase(base.BaseTestCase): def test_tenant_id_check_no_target_field_raises(self): # Try and add a bad rule self.assertRaises( - n_exc.PolicyInitError, + exceptions.PolicyInitError, oslo_policy.Rules.from_dict, {'test_policy': 'tenant_id:(wrong_stuff)'}) @@ -580,7 +579,7 @@ class NeutronPolicyTestCase(base.BaseTestCase): action = "create_network" target = {'tenant_id': 'fake'} self.fakepolicyinit() - self.assertRaises(n_exc.PolicyCheckError, + self.assertRaises(exceptions.PolicyCheckError, policy.enforce, self.context, action, target) @@ -653,7 +652,7 @@ class NeutronPolicyTestCase(base.BaseTestCase): attr, resource, target, action) self.assertFalse(result) - target = {attr: const.ATTR_NOT_SPECIFIED, 'tgt-tenant': 'tenantA'} + target = {attr: constants.ATTR_NOT_SPECIFIED, 'tgt-tenant': 'tenantA'} result = policy._is_attribute_explicitly_set( attr, resource, target, action) self.assertFalse(result)