diff --git a/oslo_messaging/tests/test_transport.py b/oslo_messaging/tests/test_transport.py index 01ead7e08..ee969cf69 100644 --- a/oslo_messaging/tests/test_transport.py +++ b/oslo_messaging/tests/test_transport.py @@ -341,6 +341,7 @@ class TestTransportUrlCustomisation(test_utils.BaseTestCase): self.url2 = transport_url_parse("fake://vhost2?foo=bar") self.url3 = transport_url_parse("fake://vhost1?l=1&l=2&l=3") self.url4 = transport_url_parse("fake://vhost2?d=x:1&d=y:2&d=z:3") + self.url5 = transport_url_parse("fake://noport:/?") def test_hash(self): urls = {} @@ -348,7 +349,8 @@ class TestTransportUrlCustomisation(test_utils.BaseTestCase): urls[self.url2] = self.url2 urls[self.url3] = self.url3 urls[self.url4] = self.url4 - self.assertEqual(2, len(urls)) + urls[self.url5] = self.url5 + self.assertEqual(3, len(urls)) def test_eq(self): self.assertEqual(self.url1, self.url3) @@ -361,6 +363,9 @@ class TestTransportUrlCustomisation(test_utils.BaseTestCase): self.assertEqual({'l': '1,2,3'}, self.url3.query) self.assertEqual({'d': 'x:1,y:2,z:3'}, self.url4.query) + def test_noport(self): + self.assertIsNone(self.url5.hosts[0].port) + class TestTransportHostCustomisation(test_utils.BaseTestCase): def setUp(self): diff --git a/oslo_messaging/transport.py b/oslo_messaging/transport.py index b7408201d..93f3f478b 100644 --- a/oslo_messaging/transport.py +++ b/oslo_messaging/transport.py @@ -453,9 +453,13 @@ class TransportURL(object): # parses the port data port = None if ':' in port_text: - port = int(port_text.split(':', 1)[1]) + port = port_text.split(':', 1)[1] elif ':' in hostname: hostname, port = hostname.split(':', 1) + + if port == "": + port = None + if port is not None: port = int(port) if username is None or password is None: