diff --git a/oslo/messaging/_drivers/amqpdriver.py b/oslo/messaging/_drivers/amqpdriver.py index 1c51ab076..903f84826 100644 --- a/oslo/messaging/_drivers/amqpdriver.py +++ b/oslo/messaging/_drivers/amqpdriver.py @@ -291,21 +291,20 @@ class AMQPDriverBase(base.BaseDriver): self._waiter = None def _server_params_from_url(self, url): - if not url.hosts: - return None + sp = {} - sp = { - 'virtual_host': url.virtual_host, - } + if url.virtual_host is not None: + sp['virtual_host'] = url.virtual_host - # FIXME(markmc): support multiple hosts - host = url.hosts[0] + if url.hosts: + # FIXME(markmc): support multiple hosts + host = url.hosts[0] - sp['hostname'] = host.hostname - if host.port is not None: - sp['port'] = host.port - sp['username'] = host.username or '' - sp['password'] = host.password or '' + sp['hostname'] = host.hostname + if host.port is not None: + sp['port'] = host.port + sp['username'] = host.username or '' + sp['password'] = host.password or '' return sp diff --git a/tests/test_rabbit.py b/tests/test_rabbit.py index 240712ec2..fc753c1b4 100644 --- a/tests/test_rabbit.py +++ b/tests/test_rabbit.py @@ -48,14 +48,19 @@ class TestRabbitDriverLoad(test_utils.BaseTestCase): class TestRabbitTransportURL(test_utils.BaseTestCase): scenarios = [ - ('none', dict(url=None, expected=None)), - ('empty', dict(url='rabbit:///', expected=None)), + ('none', dict(url=None, expected={})), + ('empty', + dict(url='rabbit:///', + expected=dict(virtual_host=''))), ('localhost', dict(url='rabbit://localhost/', expected=dict(hostname='localhost', username='', password='', virtual_host=''))), + ('virtual_host', + dict(url='rabbit:///vhost', + expected=dict(virtual_host='vhost'))), ('no_creds', dict(url='rabbit://host/virtual_host', expected=dict(hostname='host',