Support uncompressed ipv6 address and abbreviated ipv4 address
Now neutron supports zero-compressed ipv6 address like '2001:db8::10:10:10:0/120' and unabbreviated ipv4 address like '10.0.0.0/24'. This path will make neutron also support uncompressed ipv6 address and abbreviated ipv4 address. for example: 1, uncompressed ipv6 address like 'fe80:0:0:0:0:0:0:0/128' 2, ipv6 address with multiple consecutive zero like '2001:0db8:0:0:1::1/128' or '2001::0:1:0:0:1100/120' 3, abbreviated ipv4 address like '10/24' Change-Id: I755e38ea11c139e15488ec60e7d5682a244ab114 Closes-Bug: #1240790
This commit is contained in:
parent
3a7dad7c5d
commit
d4127c622d
@ -267,11 +267,10 @@ def _validate_subnet(data, valid_values=None):
|
|||||||
msg = None
|
msg = None
|
||||||
try:
|
try:
|
||||||
net = netaddr.IPNetwork(_validate_no_whitespace(data))
|
net = netaddr.IPNetwork(_validate_no_whitespace(data))
|
||||||
cidr = str(net.cidr)
|
if ('/' not in data or net.network != net.ip):
|
||||||
if (cidr != data):
|
|
||||||
msg = _("'%(data)s' isn't a recognized IP subnet cidr,"
|
msg = _("'%(data)s' isn't a recognized IP subnet cidr,"
|
||||||
" '%(cidr)s' is recommended") % {"data": data,
|
" '%(cidr)s' is recommended") % {"data": data,
|
||||||
"cidr": cidr}
|
"cidr": net.cidr}
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -397,6 +397,36 @@ class TestAttributes(base.BaseTestCase):
|
|||||||
None)
|
None)
|
||||||
self.assertIsNone(msg)
|
self.assertIsNone(msg)
|
||||||
|
|
||||||
|
# Valid - uncompressed ipv6 address
|
||||||
|
cidr = "fe80:0:0:0:0:0:0:0/128"
|
||||||
|
msg = attributes._validate_subnet(cidr,
|
||||||
|
None)
|
||||||
|
self.assertIsNone(msg)
|
||||||
|
|
||||||
|
# Valid - ipv6 address with multiple consecutive zero
|
||||||
|
cidr = "2001:0db8:0:0:1::1/128"
|
||||||
|
msg = attributes._validate_subnet(cidr,
|
||||||
|
None)
|
||||||
|
self.assertIsNone(msg)
|
||||||
|
|
||||||
|
# Valid - ipv6 address with multiple consecutive zero
|
||||||
|
cidr = "2001:0db8::1:0:0:1/128"
|
||||||
|
msg = attributes._validate_subnet(cidr,
|
||||||
|
None)
|
||||||
|
self.assertIsNone(msg)
|
||||||
|
|
||||||
|
# Valid - ipv6 address with multiple consecutive zero
|
||||||
|
cidr = "2001::0:1:0:0:1100/120"
|
||||||
|
msg = attributes._validate_subnet(cidr,
|
||||||
|
None)
|
||||||
|
self.assertIsNone(msg)
|
||||||
|
|
||||||
|
# Valid - abbreviated ipv4 address
|
||||||
|
cidr = "10/24"
|
||||||
|
msg = attributes._validate_subnet(cidr,
|
||||||
|
None)
|
||||||
|
self.assertIsNone(msg)
|
||||||
|
|
||||||
# Invalid - IPv4 missing mask
|
# Invalid - IPv4 missing mask
|
||||||
cidr = "10.0.2.0"
|
cidr = "10.0.2.0"
|
||||||
msg = attributes._validate_subnet(cidr,
|
msg = attributes._validate_subnet(cidr,
|
||||||
|
@ -531,10 +531,7 @@ class TestFirewallAttributeValidators(base.BaseTestCase):
|
|||||||
# Valid - IPv6 with final octets
|
# Valid - IPv6 with final octets
|
||||||
cidr = "fe80::0/24"
|
cidr = "fe80::0/24"
|
||||||
msg = firewall._validate_ip_or_subnet_or_none(cidr, None)
|
msg = firewall._validate_ip_or_subnet_or_none(cidr, None)
|
||||||
self.assertEqual(msg, ("'%s' is not a valid IP address and "
|
self.assertIsNone(msg)
|
||||||
"'%s' isn't a recognized IP subnet cidr,"
|
|
||||||
" 'fe80::/24' is recommended") % (cidr,
|
|
||||||
cidr))
|
|
||||||
|
|
||||||
cidr = "fe80::"
|
cidr = "fe80::"
|
||||||
msg = firewall._validate_ip_or_subnet_or_none(cidr, None)
|
msg = firewall._validate_ip_or_subnet_or_none(cidr, None)
|
||||||
|
Loading…
Reference in New Issue
Block a user