From 7b458073cefac296f41c11ffacb0f18785f127d8 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Mon, 3 Sep 2012 22:11:59 -0400 Subject: [PATCH] Remove dependencies for netaddr. Updates cinder utils.py to remove the parse_server_string and is_valid_cidr functions. These functions aren't in use and are the only reason we need the netaddr dependency. Updates pip-requires to drop the netaddr dependency. Also removes the unit tests for removed functions. Change-Id: I521ae60b758324069fb1ffa1701b1f9deb780f65 --- cinder/tests/test_utils.py | 23 ---------------- cinder/utils.py | 55 -------------------------------------- tools/pip-requires | 1 - 3 files changed, 79 deletions(-) diff --git a/cinder/tests/test_utils.py b/cinder/tests/test_utils.py index ee9779670..92be797b8 100644 --- a/cinder/tests/test_utils.py +++ b/cinder/tests/test_utils.py @@ -273,29 +273,6 @@ class GetFromPathTestCase(test.TestCase): class GenericUtilsTestCase(test.TestCase): - def test_parse_server_string(self): - result = utils.parse_server_string('::1') - self.assertEqual(('::1', ''), result) - result = utils.parse_server_string('[::1]:8773') - self.assertEqual(('::1', '8773'), result) - result = utils.parse_server_string('2001:db8::192.168.1.1') - self.assertEqual(('2001:db8::192.168.1.1', ''), result) - result = utils.parse_server_string('[2001:db8::192.168.1.1]:8773') - self.assertEqual(('2001:db8::192.168.1.1', '8773'), result) - result = utils.parse_server_string('192.168.1.1') - self.assertEqual(('192.168.1.1', ''), result) - result = utils.parse_server_string('192.168.1.2:8773') - self.assertEqual(('192.168.1.2', '8773'), result) - result = utils.parse_server_string('192.168.1.3') - self.assertEqual(('192.168.1.3', ''), result) - result = utils.parse_server_string('www.example.com:8443') - self.assertEqual(('www.example.com', '8443'), result) - result = utils.parse_server_string('www.example.com') - self.assertEqual(('www.example.com', ''), result) - # error case - result = utils.parse_server_string('www.exa:mple.com:8443') - self.assertEqual(('', ''), result) - def test_hostname_unicode_sanitization(self): hostname = u"\u7684.test.example.com" self.assertEqual("test.example.com", diff --git a/cinder/utils.py b/cinder/utils.py index 04e4854c3..5f896a3af 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -46,7 +46,6 @@ from xml.sax import saxutils from eventlet import event from eventlet import greenthread from eventlet.green import subprocess -import netaddr from cinder.common import deprecated from cinder import exception @@ -713,36 +712,6 @@ def check_isinstance(obj, cls): return cls() # Ugly PyLint hack -def parse_server_string(server_str): - """ - Parses the given server_string and returns a list of host and port. - If it's not a combination of host part and port, the port element - is a null string. If the input is invalid expression, return a null - list. - """ - try: - # First of all, exclude pure IPv6 address (w/o port). - if netaddr.valid_ipv6(server_str): - return (server_str, '') - - # Next, check if this is IPv6 address with a port number combination. - if server_str.find("]:") != -1: - (address, port) = server_str.replace('[', '', 1).split(']:') - return (address, port) - - # Third, check if this is a combination of an address and a port - if server_str.find(':') == -1: - return (server_str, '') - - # This must be a combination of an address and a port - (address, port) = server_str.split(':') - return (address, port) - - except Exception: - LOG.debug(_('Invalid server_string: %s'), server_str) - return ('', '') - - def gen_uuid(): return uuid.uuid4() @@ -786,30 +755,6 @@ def is_valid_ipv4(address): return True -def is_valid_cidr(address): - """Check if the provided ipv4 or ipv6 address is a valid - CIDR address or not""" - try: - # Validate the correct CIDR Address - netaddr.IPNetwork(address) - except netaddr.core.AddrFormatError: - return False - except UnboundLocalError: - # NOTE(MotoKen): work around bug in netaddr 0.7.5 (see detail in - # https://github.com/drkjam/netaddr/issues/2) - return False - - # Prior validation partially verify /xx part - # Verify it here - ip_segment = address.split('/') - - if (len(ip_segment) <= 1 or - ip_segment[1] == ''): - return False - - return True - - def monkey_patch(): """ If the Flags.monkey_patch set as True, this function patches a decorator diff --git a/tools/pip-requires b/tools/pip-requires index 5422ef04f..34538e3cf 100644 --- a/tools/pip-requires +++ b/tools/pip-requires @@ -13,7 +13,6 @@ greenlet>=0.3.1 PasteDeploy==1.5.0 paste sqlalchemy-migrate>=0.7.2 -netaddr suds==0.4 paramiko Babel>=0.9.6 -- 2.45.2