From b58847972663fc76b9cbcae205f7fffbe4a4a64d Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Tue, 13 Jan 2015 17:48:39 -0500 Subject: [PATCH] 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 --- glance/common/utils.py | 19 +--------- glance/tests/unit/common/test_utils.py | 51 -------------------------- requirements.txt | 1 - tox.ini | 2 +- 4 files changed, 2 insertions(+), 71 deletions(-) diff --git a/glance/common/utils.py b/glance/common/utils.py index 9e8ced280b..a80becac25 100644 --- a/glance/common/utils.py +++ b/glance/common/utils.py @@ -35,7 +35,6 @@ import subprocess import sys import uuid -import netaddr from OpenSSL import crypto from oslo.config import cfg 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 -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): """Verify whether a hostname (not an FQDN) is valid.""" 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 # 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)): raise ValueError(_('Host "%s" is not valid.') % host) diff --git a/glance/tests/unit/common/test_utils.py b/glance/tests/unit/common/test_utils.py index 59b4da5720..1875d62fe8 100644 --- a/glance/tests/unit/common/test_utils.py +++ b/glance/tests/unit/common/test_utils.py @@ -285,57 +285,6 @@ class TestUtils(test_utils.BaseTestCase): for input_str in invalid_inputs: 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]', - ':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:::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): valid_inputs = ['localhost', 'glance04-a' diff --git a/requirements.txt b/requirements.txt index 9cdab3ce8b..e9d542cb4e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -28,7 +28,6 @@ oslo.config>=1.6.0 # Apache-2.0 oslo.concurrency>=0.3.0 # Apache-2.0 oslo.utils>=1.2.0 # Apache-2.0 stevedore>=1.1.0 # Apache-2.0 -netaddr>=0.7.12 keystonemiddleware>=1.0.0 WSME>=0.6 # For openstack/common/lockutils diff --git a/tox.ini b/tox.ini index 834b3b11a7..80d45cfdcf 100644 --- a/tox.ini +++ b/tox.ini @@ -6,7 +6,7 @@ skipsdist = True [testenv] setenv = VIRTUAL_ENV={envdir} 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 -r{toxinidir}/test-requirements.txt commands = lockutils-wrapper python setup.py testr --slowest --testr-args='{posargs}'