diff --git a/neutron/common/constants.py b/neutron/common/constants.py index 20a20470ad0..9c346f6c115 100644 --- a/neutron/common/constants.py +++ b/neutron/common/constants.py @@ -131,9 +131,6 @@ VALID_ETHERTYPES = (lib_constants.IPv4, lib_constants.IPv6) IP_ALLOWED_VERSIONS = [lib_constants.IP_VERSION_4, lib_constants.IP_VERSION_6] -IPV4_MAX_PREFIXLEN = 32 -IPV6_MAX_PREFIXLEN = 128 - # Some components communicate using private address ranges, define # them all here. These address ranges should not cause any issues # even if they overlap since they are used in disjoint namespaces, diff --git a/neutron/objects/common_types.py b/neutron/objects/common_types.py index 4e79223446e..804ddc2f7fc 100644 --- a/neutron/objects/common_types.py +++ b/neutron/objects/common_types.py @@ -54,7 +54,7 @@ class IPNetworkPrefixLen(RangeConstrainedInteger): """IP network (CIDR) prefix length custom Enum""" def __init__(self, **kwargs): super(IPNetworkPrefixLen, self).__init__( - start=0, end=constants.IPV6_MAX_PREFIXLEN, + start=0, end=n_const.IPv6_BITS, **kwargs) diff --git a/neutron/services/externaldns/drivers/designate/driver.py b/neutron/services/externaldns/drivers/designate/driver.py index f9248cb406c..89d11cdd84f 100644 --- a/neutron/services/externaldns/drivers/designate/driver.py +++ b/neutron/services/externaldns/drivers/designate/driver.py @@ -20,6 +20,7 @@ from designateclient.v2 import client as d_client from keystoneclient.auth.identity.generic import password from keystoneclient.auth import token_endpoint from keystoneclient import session +from neutron_lib import constants from oslo_config import cfg from oslo_log import log @@ -175,8 +176,10 @@ class Designate(driver.ExternalDNSService): def _get_bytes_or_nybles_to_skip(self, in_addr_name): if 'in-addr.arpa' in in_addr_name: - return int((32 - CONF.designate.ipv4_ptr_zone_prefix_size) / 8) - return int((128 - CONF.designate.ipv6_ptr_zone_prefix_size) / 4) + return int((constants.IPv4_BITS - + CONF.designate.ipv4_ptr_zone_prefix_size) / 8) + return int((constants.IPv6_BITS - + CONF.designate.ipv6_ptr_zone_prefix_size) / 4) def delete_record_set(self, context, dns_domain, dns_name, records): designate, designate_admin = get_clients(context) diff --git a/neutron/tests/tempest/api/test_network_ip_availability.py b/neutron/tests/tempest/api/test_network_ip_availability.py index f84e14e9963..74395ea69fe 100644 --- a/neutron/tests/tempest/api/test_network_ip_availability.py +++ b/neutron/tests/tempest/api/test_network_ip_availability.py @@ -99,9 +99,11 @@ class NetworksIpAvailabilityTest(base.BaseAdminNetworkTest): def calc_total_ips(prefix, ip_version): # will calculate total ips after removing reserved. if ip_version == lib_constants.IP_VERSION_4: - total_ips = 2 ** (32 - prefix) - DEFAULT_IP4_RESERVED + total_ips = 2 ** (lib_constants.IPv4_BITS + - prefix) - DEFAULT_IP4_RESERVED elif ip_version == lib_constants.IP_VERSION_6: - total_ips = 2 ** (128 - prefix) - DEFAULT_IP6_RESERVED + total_ips = 2 ** (lib_constants.IPv6_BITS + - prefix) - DEFAULT_IP6_RESERVED return total_ips diff --git a/neutron/tests/tools.py b/neutron/tests/tools.py index 15760a40579..3d2a4c56c02 100644 --- a/neutron/tests/tools.py +++ b/neutron/tests/tools.py @@ -25,12 +25,13 @@ import warnings import fixtures import mock import netaddr +from neutron_lib import constants import six import unittest2 import neutron from neutron.api.v2 import attributes -from neutron.common import constants +from neutron.common import constants as n_const from neutron.common import ipv6_utils @@ -233,14 +234,14 @@ def get_random_integer(range_begin=0, range_end=1000): def get_random_prefixlen(version=4): - maxlen = constants.IPV4_MAX_PREFIXLEN + maxlen = constants.IPv4_BITS if version == 6: - maxlen = constants.IPV6_MAX_PREFIXLEN + maxlen = constants.IPv6_BITS return random.randint(0, maxlen) def get_random_ip_version(): - return random.choice(constants.IP_ALLOWED_VERSIONS) + return random.choice(n_const.IP_ALLOWED_VERSIONS) def get_random_cidr(version=4): @@ -302,4 +303,4 @@ def reset_random_seed(): def get_random_ipv6_mode(): - return random.choice(constants.IPV6_MODES) + return random.choice(n_const.IPV6_MODES) diff --git a/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py b/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py index c3e1e8fed88..364ebfe15e8 100644 --- a/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py +++ b/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py @@ -15,6 +15,7 @@ import mock import netaddr +from neutron_lib import constants from neutron import context from neutron.db import dns_db @@ -235,8 +236,10 @@ class DNSIntegrationTestCase(test_plugin.Ml2PluginV2TestCase): def _get_bytes_or_nybles_to_skip(self, in_addr_name): if 'in-addr.arpa' in in_addr_name: return (( - 32 - config.cfg.CONF.designate.ipv4_ptr_zone_prefix_size) / 8) - return (128 - config.cfg.CONF.designate.ipv6_ptr_zone_prefix_size) / 4 + constants.IPv4_BITS - + config.cfg.CONF.designate.ipv4_ptr_zone_prefix_size) / 8) + return (constants.IPv6_BITS - + config.cfg.CONF.designate.ipv6_ptr_zone_prefix_size) / 4 def test_create_port(self, *mocks): config.cfg.CONF.set_override('dns_domain', DNSDOMAIN)