From 2ec1fb7572d97a7c460e0198ddd1922b81ea1d21 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin <markmc@redhat.com> Date: Wed, 23 Oct 2013 07:25:27 +0100 Subject: [PATCH] Properly handle transport:///vhost URL Currently, if we are supplied with a transport URL with only the virtual host specified, we completely ignore it. Instead, the behaviour should be that we use that virtual host with the host, port and credentials from the config file. Change-Id: Ic97aa511ddf9bce69b1a5069d9f6468f4bd6dd4c --- oslo/messaging/_drivers/amqpdriver.py | 23 +++++++++++------------ tests/test_rabbit.py | 9 +++++++-- 2 files changed, 18 insertions(+), 14 deletions(-) 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 48f11dc9c..45eea6967 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',