remove need for netaddr
The only reason netaddr was pulled in was for ip validation routines which exist in oslo.utils. Use those instead. Change-Id: Ic3beee7e8bfb2b2d16ecac9be6322fe2704c70bd
This commit is contained in:
parent
ca1db8577f
commit
b588479726
@ -35,7 +35,6 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import netaddr
|
|
||||||
from OpenSSL import crypto
|
from OpenSSL import crypto
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
@ -552,22 +551,6 @@ def is_valid_port(port):
|
|||||||
return str(port).isdigit() and int(port) > 0 and int(port) <= 65535
|
return str(port).isdigit() and int(port) > 0 and int(port) <= 65535
|
||||||
|
|
||||||
|
|
||||||
def is_valid_ipv4(address):
|
|
||||||
"""Verify that address represents a valid IPv4 address."""
|
|
||||||
try:
|
|
||||||
return netaddr.valid_ipv4(address)
|
|
||||||
except Exception:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def is_valid_ipv6(address):
|
|
||||||
"""Verify that address represents a valid IPv6 address."""
|
|
||||||
try:
|
|
||||||
return netaddr.valid_ipv6(address)
|
|
||||||
except Exception:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def is_valid_hostname(hostname):
|
def is_valid_hostname(hostname):
|
||||||
"""Verify whether a hostname (not an FQDN) is valid."""
|
"""Verify whether a hostname (not an FQDN) is valid."""
|
||||||
return re.match('^[a-zA-Z0-9-]+$', hostname) is not None
|
return re.match('^[a-zA-Z0-9-]+$', hostname) is not None
|
||||||
@ -602,7 +585,7 @@ def parse_valid_host_port(host_port):
|
|||||||
# should pass a very generic FQDN check. The FQDN check for letters at
|
# should pass a very generic FQDN check. The FQDN check for letters at
|
||||||
# the tail end will weed out any hilariously absurd IPv4 addresses.
|
# the tail end will weed out any hilariously absurd IPv4 addresses.
|
||||||
|
|
||||||
if not (is_valid_ipv6(host) or is_valid_ipv4(host) or
|
if not (netutils.is_valid_ipv6(host) or netutils.is_valid_ipv4(host) or
|
||||||
is_valid_hostname(host) or is_valid_fqdn(host)):
|
is_valid_hostname(host) or is_valid_fqdn(host)):
|
||||||
raise ValueError(_('Host "%s" is not valid.') % host)
|
raise ValueError(_('Host "%s" is not valid.') % host)
|
||||||
|
|
||||||
|
@ -285,57 +285,6 @@ class TestUtils(test_utils.BaseTestCase):
|
|||||||
for input_str in invalid_inputs:
|
for input_str in invalid_inputs:
|
||||||
self.assertFalse(utils.is_valid_port(input_str))
|
self.assertFalse(utils.is_valid_port(input_str))
|
||||||
|
|
||||||
def test_valid_ipv4(self):
|
|
||||||
valid_inputs = ['10.11.12.13',
|
|
||||||
'172.17.17.1']
|
|
||||||
for input_str in valid_inputs:
|
|
||||||
self.assertTrue(utils.is_valid_ipv4(input_str))
|
|
||||||
|
|
||||||
def test_valid_ipv4_fail(self):
|
|
||||||
invalid_pairs = ['',
|
|
||||||
'290.12.52.80',
|
|
||||||
'a.b.c.d',
|
|
||||||
u'\u2601',
|
|
||||||
u'\u2603:8080',
|
|
||||||
'fe80::1',
|
|
||||||
'[fe80::2]',
|
|
||||||
'<fe80::3>:5673',
|
|
||||||
'fe80:a:b:c:d:e:f:1:2:3:4',
|
|
||||||
'fe80:a:b:c:d:e:f:g',
|
|
||||||
'fe80::1:8080',
|
|
||||||
'[fe80:a:b:c:d:e:f:g]:9090',
|
|
||||||
'[a:b:s:u:r:d]:fe80']
|
|
||||||
|
|
||||||
for pair in invalid_pairs:
|
|
||||||
self.assertRaises(ValueError,
|
|
||||||
utils.parse_valid_host_port,
|
|
||||||
pair)
|
|
||||||
|
|
||||||
def test_valid_ipv6(self):
|
|
||||||
valid_inputs = ['fe80::1',
|
|
||||||
'fe80:0000:0000:0000:0000:0000:0000:0002',
|
|
||||||
'fe80:a:b:c:d:e:f:0',
|
|
||||||
'fe80::a:b:c:d',
|
|
||||||
'fe80::1:8080']
|
|
||||||
|
|
||||||
for input_str in valid_inputs:
|
|
||||||
self.assertTrue(utils.is_valid_ipv6(input_str))
|
|
||||||
|
|
||||||
def test_valid_ipv6_fail(self):
|
|
||||||
invalid_pairs = ['',
|
|
||||||
'[fe80::2]',
|
|
||||||
'<fe80::3>',
|
|
||||||
'fe80:::a',
|
|
||||||
'fe80:a:b:c:d:e:f:1:2:3:4',
|
|
||||||
'fe80:a:b:c:d:e:f:g',
|
|
||||||
'fe80::1:8080',
|
|
||||||
'i:n:s:a:n:i:t:y']
|
|
||||||
|
|
||||||
for pair in invalid_pairs:
|
|
||||||
self.assertRaises(ValueError,
|
|
||||||
utils.parse_valid_host_port,
|
|
||||||
pair)
|
|
||||||
|
|
||||||
def test_valid_hostname(self):
|
def test_valid_hostname(self):
|
||||||
valid_inputs = ['localhost',
|
valid_inputs = ['localhost',
|
||||||
'glance04-a'
|
'glance04-a'
|
||||||
|
@ -28,7 +28,6 @@ oslo.config>=1.6.0 # Apache-2.0
|
|||||||
oslo.concurrency>=0.3.0 # Apache-2.0
|
oslo.concurrency>=0.3.0 # Apache-2.0
|
||||||
oslo.utils>=1.2.0 # Apache-2.0
|
oslo.utils>=1.2.0 # Apache-2.0
|
||||||
stevedore>=1.1.0 # Apache-2.0
|
stevedore>=1.1.0 # Apache-2.0
|
||||||
netaddr>=0.7.12
|
|
||||||
keystonemiddleware>=1.0.0
|
keystonemiddleware>=1.0.0
|
||||||
WSME>=0.6
|
WSME>=0.6
|
||||||
# For openstack/common/lockutils
|
# For openstack/common/lockutils
|
||||||
|
2
tox.ini
2
tox.ini
@ -6,7 +6,7 @@ skipsdist = True
|
|||||||
[testenv]
|
[testenv]
|
||||||
setenv = VIRTUAL_ENV={envdir}
|
setenv = VIRTUAL_ENV={envdir}
|
||||||
usedevelop = True
|
usedevelop = True
|
||||||
install_command = pip install --allow-all-external --allow-insecure netaddr -U {opts} {packages}
|
install_command = pip install -U {opts} {packages}
|
||||||
deps = -r{toxinidir}/requirements.txt
|
deps = -r{toxinidir}/requirements.txt
|
||||||
-r{toxinidir}/test-requirements.txt
|
-r{toxinidir}/test-requirements.txt
|
||||||
commands = lockutils-wrapper python setup.py testr --slowest --testr-args='{posargs}'
|
commands = lockutils-wrapper python setup.py testr --slowest --testr-args='{posargs}'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user