summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEugene Kirpichov <ekirpichov@gmail.com>2012-09-07 22:56:34 +0000
committerEugene Kirpichov <ekirpichov@gmail.com>2012-09-11 17:50:43 +0000
commit879470b99c0f8f42d50f955defaf43ab47b704cc (patch)
tree0410ba26dc28ef3c72915bddae48aa0c104c06da /tests
parent1071b9da480d25e7cee556d7f9b483f8ac258ffb (diff)
downloadoslo-879470b99c0f8f42d50f955defaf43ab47b704cc.tar.gz
oslo-879470b99c0f8f42d50f955defaf43ab47b704cc.tar.xz
oslo-879470b99c0f8f42d50f955defaf43ab47b704cc.zip
Added a method for parsing host:port pairs.
The method works correctly with ipv6. An alternative way would be to use urlparse, but urlparse only works correctly starting with Python 2.7, so to be compatible, we have to reimplement this part. The method will be used for parsing Glance API server addresses, RabbitMQ addresses and perhaps other things. Change-Id: Ie5014891c6abcd80681a370d5dd94cb0406f7f61
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_utils.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
index 135f49d..25280f9 100644
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -80,3 +80,20 @@ class UtilsTest(unittest.TestCase):
# running code.
def test_execute_unknown_kwargs(self):
self.assertRaises(exception.Error, utils.execute, hozer=True)
+
+ def test_parse_host_port(self):
+ self.assertEqual(('server01', 80),
+ utils.parse_host_port('server01:80'))
+ self.assertEqual(('server01', None),
+ utils.parse_host_port('server01'))
+ self.assertEqual(('server01', 1234),
+ utils.parse_host_port('server01', default_port=1234))
+ self.assertEqual(('::1', 80),
+ utils.parse_host_port('[::1]:80'))
+ self.assertEqual(('::1', None),
+ utils.parse_host_port('[::1]'))
+ self.assertEqual(('::1', 1234),
+ utils.parse_host_port('[::1]', default_port=1234))
+ self.assertEqual(('2001:db8:85a3::8a2e:370:7334', 1234),
+ utils.parse_host_port('2001:db8:85a3::8a2e:370:7334',
+ default_port=1234))