Fix transport url with empty port
When transport url is set to something like "amqp://hostname:/" it currently raise ValueError while any url parsing library (like urlparse) just ignore the port, and don't fail since this is a value url. This change make the transport url ignore empty port instead of raising ValueError. Change-Id: I04df76012e3b133eddbcf365363cd261d277e369
This commit is contained in:
parent
7f2299f7e9
commit
9d55749c05
@ -341,6 +341,7 @@ class TestTransportUrlCustomisation(test_utils.BaseTestCase):
|
|||||||
self.url2 = transport_url_parse("fake://vhost2?foo=bar")
|
self.url2 = transport_url_parse("fake://vhost2?foo=bar")
|
||||||
self.url3 = transport_url_parse("fake://vhost1?l=1&l=2&l=3")
|
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.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):
|
def test_hash(self):
|
||||||
urls = {}
|
urls = {}
|
||||||
@ -348,7 +349,8 @@ class TestTransportUrlCustomisation(test_utils.BaseTestCase):
|
|||||||
urls[self.url2] = self.url2
|
urls[self.url2] = self.url2
|
||||||
urls[self.url3] = self.url3
|
urls[self.url3] = self.url3
|
||||||
urls[self.url4] = self.url4
|
urls[self.url4] = self.url4
|
||||||
self.assertEqual(2, len(urls))
|
urls[self.url5] = self.url5
|
||||||
|
self.assertEqual(3, len(urls))
|
||||||
|
|
||||||
def test_eq(self):
|
def test_eq(self):
|
||||||
self.assertEqual(self.url1, self.url3)
|
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({'l': '1,2,3'}, self.url3.query)
|
||||||
self.assertEqual({'d': 'x:1,y:2,z:3'}, self.url4.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):
|
class TestTransportHostCustomisation(test_utils.BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -453,9 +453,13 @@ class TransportURL(object):
|
|||||||
# parses the port data
|
# parses the port data
|
||||||
port = None
|
port = None
|
||||||
if ':' in port_text:
|
if ':' in port_text:
|
||||||
port = int(port_text.split(':', 1)[1])
|
port = port_text.split(':', 1)[1]
|
||||||
elif ':' in hostname:
|
elif ':' in hostname:
|
||||||
hostname, port = hostname.split(':', 1)
|
hostname, port = hostname.split(':', 1)
|
||||||
|
|
||||||
|
if port == "":
|
||||||
|
port = None
|
||||||
|
if port is not None:
|
||||||
port = int(port)
|
port = int(port)
|
||||||
|
|
||||||
if username is None or password is None:
|
if username is None or password is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user