diff options
author | Eugene Kirpichov <ekirpichov@gmail.com> | 2012-09-07 22:56:34 +0000 |
---|---|---|
committer | Eugene Kirpichov <ekirpichov@gmail.com> | 2012-09-11 17:50:43 +0000 |
commit | 879470b99c0f8f42d50f955defaf43ab47b704cc (patch) | |
tree | 0410ba26dc28ef3c72915bddae48aa0c104c06da /tests | |
parent | 1071b9da480d25e7cee556d7f9b483f8ac258ffb (diff) | |
download | oslo-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.py | 17 |
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)) |