Merge "use is_valid_port from oslo.utils"
This commit is contained in:
commit
81d3421fd3
|
@ -607,11 +607,6 @@ def is_uuid_like(val):
|
|||
return False
|
||||
|
||||
|
||||
def is_valid_port(port):
|
||||
"""Verify that port represents a valid port number."""
|
||||
return str(port).isdigit() and int(port) > 0 and int(port) <= 65535
|
||||
|
||||
|
||||
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
|
||||
|
@ -638,7 +633,7 @@ def parse_valid_host_port(host_port):
|
|||
except Exception:
|
||||
raise ValueError(_('Host and port "%s" is not valid.') % host_port)
|
||||
|
||||
if not is_valid_port(port):
|
||||
if not netutils.is_valid_port(port):
|
||||
raise ValueError(_('Port "%s" is not valid.') % port)
|
||||
|
||||
# First check for valid IPv6 and IPv4 addresses, then a generic
|
||||
|
|
|
@ -323,18 +323,6 @@ class TestUtils(test_utils.BaseTestCase):
|
|||
utils.validate_key_cert,
|
||||
keyfile, certfile)
|
||||
|
||||
def test_valid_port(self):
|
||||
valid_inputs = [1, '1', 2, '3', '5', 8, 13, 21,
|
||||
'80', '3246', '65535']
|
||||
for input_str in valid_inputs:
|
||||
self.assertTrue(utils.is_valid_port(input_str))
|
||||
|
||||
def test_valid_port_fail(self):
|
||||
invalid_inputs = ['-32768', '0', 0, '65536', 528491, '528491',
|
||||
'528.491', 'thirty-seven']
|
||||
for input_str in invalid_inputs:
|
||||
self.assertFalse(utils.is_valid_port(input_str))
|
||||
|
||||
def test_valid_hostname(self):
|
||||
valid_inputs = ['localhost',
|
||||
'glance04-a'
|
||||
|
|
Loading…
Reference in New Issue