Merge "IPv6 accepts first address only for routers"

This commit is contained in:
Zuul 2020-01-16 03:22:14 +00:00 committed by Gerrit Code Review
commit 8ad6bde44b
2 changed files with 33 additions and 7 deletions

View File

@ -27,7 +27,8 @@ def check_subnet_ip(cidr, ip_address, port_owner=''):
# NOTE(njohnston): In some cases the code cannot know the owner of the
# port. In these cases port_owner should an empty string, and we pass
# it through here.
return (port_owner in (constants.ROUTER_PORT_OWNERS + ('', )) and
return ((port_owner in (constants.ROUTER_PORT_OWNERS + ('', )) or
ip != net.network) and
ip in net)
else:
return ip != net.network and ip != net.broadcast and ip in net

View File

@ -14,6 +14,7 @@
# under the License.
import netaddr
from neutron_lib import constants
from neutron.ipam import utils
from neutron.tests import base
@ -31,13 +32,37 @@ class TestIpamUtils(base.BaseTestCase):
self.assertTrue(utils.check_subnet_ip('1.1.1.0/24', '1.1.1.1'))
self.assertTrue(utils.check_subnet_ip('1.1.1.0/24', '1.1.1.254'))
def test_check_subnet_ip_v6_network(self):
self.assertTrue(utils.check_subnet_ip('F111::0/64', 'F111::0'))
def test_check_subnet_ip_v6_owner_router_or_not_defined(self):
for port_owner in (constants.ROUTER_PORT_OWNERS + ('', )):
# IP address == network
self.assertTrue(utils.check_subnet_ip('F111::0/64', 'F111::0',
port_owner=port_owner))
# IP address == broadcast
self.assertTrue(utils.check_subnet_ip(
'F111::0/64', 'F111::FFFF:FFFF:FFFF:FFFF',
port_owner=port_owner))
# IP address in network
self.assertTrue(utils.check_subnet_ip('F111::0/64', 'F111::50',
port_owner=port_owner))
# IP address not in network
self.assertFalse(utils.check_subnet_ip('F111::0/64', 'F112::50',
port_owner=port_owner))
def test_check_subnet_ip_v6_valid(self):
self.assertTrue(utils.check_subnet_ip('F111::0/64', 'F111::1'))
self.assertTrue(utils.check_subnet_ip('F111::0/64',
'F111::FFFF:FFFF:FFFF:FFFF'))
def test_check_subnet_ip_v6_owner_not_router(self):
port_owner = 'nova:compute'
# IP address == network
self.assertFalse(utils.check_subnet_ip('F111::0/64', 'F111::0',
port_owner=port_owner))
# IP address == broadcast
self.assertTrue(utils.check_subnet_ip(
'F111::0/64', 'F111::FFFF:FFFF:FFFF:FFFF',
port_owner=port_owner))
# IP address in network
self.assertTrue(utils.check_subnet_ip('F111::0/64', 'F111::50',
port_owner=port_owner))
# IP address not in network
self.assertFalse(utils.check_subnet_ip('F111::0/64', 'F112::50',
port_owner=port_owner))
def test_generate_pools_v4_nogateway(self):
cidr = '192.168.0.0/24'