diff options
author | Mark McLoughlin <markmc@redhat.com> | 2013-08-12 06:03:25 +0100 |
---|---|---|
committer | Mark McLoughlin <markmc@redhat.com> | 2013-08-12 06:09:48 +0100 |
commit | 9cc66e1e018dcaad6d94a6382fa0743a040901a0 (patch) | |
tree | fc8123d490611f9c5e566f2d1f02ff7a4d7924ee | |
parent | a7d7eb660e1e8d5bb0f849956737b5cf3ddb4139 (diff) | |
download | oslo-messaging-9cc66e1e018dcaad6d94a6382fa0743a040901a0.tar.gz |
Kill ability to specify exchange in transport URL
My original thinking was that if you're using the exchange name to
separate two instances of the applications (so their queues don't
collide) then the exchange name is pretty key to transport
configuration. In fact, it's really a virtual host that you'd use for
this (at least in the case of rabbit and qpid).
Also, Nova's cells code has already moved ahead with the assumption that
the path specifies a virtual host, so it'd only make sense to deviate
from that if there was a really good reason to.
Change-Id: Ic8b5dc3538b6b17afec524047acc2efa76366377
-rw-r--r-- | oslo/messaging/_drivers/amqpdriver.py | 3 | ||||
-rw-r--r-- | oslo/messaging/_drivers/impl_fake.py | 3 | ||||
-rw-r--r-- | oslo/messaging/_urls.py | 35 | ||||
-rw-r--r-- | oslo/messaging/transport.py | 2 | ||||
-rw-r--r-- | tests/test_urls.py | 67 |
5 files changed, 22 insertions, 88 deletions
diff --git a/oslo/messaging/_drivers/amqpdriver.py b/oslo/messaging/_drivers/amqpdriver.py index b20a61c..089601f 100644 --- a/oslo/messaging/_drivers/amqpdriver.py +++ b/oslo/messaging/_drivers/amqpdriver.py @@ -24,7 +24,6 @@ from oslo import messaging from oslo.messaging._drivers import amqp as rpc_amqp from oslo.messaging._drivers import base from oslo.messaging._drivers import common as rpc_common -from oslo.messaging import _urls as urls LOG = logging.getLogger(__name__) @@ -248,7 +247,7 @@ class AMQPDriverBase(base.BaseDriver): super(AMQPDriverBase, self).__init__(conf, url, default_exchange, allowed_remote_exmods) - self._default_exchange = urls.exchange_from_url(url, default_exchange) + self._default_exchange = default_exchange # FIXME(markmc): temp hack if self._default_exchange: diff --git a/oslo/messaging/_drivers/impl_fake.py b/oslo/messaging/_drivers/impl_fake.py index 42ddd86..6998262 100644 --- a/oslo/messaging/_drivers/impl_fake.py +++ b/oslo/messaging/_drivers/impl_fake.py @@ -22,7 +22,6 @@ import time from oslo import messaging from oslo.messaging._drivers import base -from oslo.messaging import _urls as urls class FakeIncomingMessage(base.IncomingMessage): @@ -92,7 +91,7 @@ class FakeDriver(base.BaseDriver): super(FakeDriver, self).__init__(conf, url, default_exchange, allowed_remote_exmods=[]) - self._default_exchange = urls.exchange_from_url(url, default_exchange) + self._default_exchange = default_exchange self._exchanges_lock = threading.Lock() self._exchanges = {} diff --git a/oslo/messaging/_urls.py b/oslo/messaging/_urls.py index 1574262..b7c865c 100644 --- a/oslo/messaging/_urls.py +++ b/oslo/messaging/_urls.py @@ -16,17 +16,17 @@ import urlparse -def parse_url(url, default_exchange=None): +def parse_url(url): """Parse an url. Assuming a URL takes the form of: - transport://user:pass@host1:port[,hostN:portN]/exchange[?opt=val] + transport://user:pass@host1:port[,hostN:portN]/virtual_host[?opt=val] then parse the URL and return a dictionary with the following structure: { - 'exchange': 'exchange' + 'virtual_host': 'virtual_host', 'transport': 'transport', 'hosts': [{'username': 'username', 'password': 'password' @@ -62,12 +62,10 @@ def parse_url(url, default_exchange=None): :param url: The URL to parse :type url: str - :param default_exchange: what to return if no exchange found in URL - :type default_exchange: str :returns: A dictionary with the parsed data """ if not url: - return dict(exchange=default_exchange) + return None # NOTE(flaper87): Not PY3K compliant if not isinstance(url, basestring): @@ -77,12 +75,10 @@ def parse_url(url, default_exchange=None): parsed = dict(transport=url.scheme) - exchange = None + virtual_host = None if url.path.startswith('/'): - exchange = url.path[1:].split('/')[0] - if not exchange: - exchange = default_exchange - parsed["exchange"] = exchange + virtual_host = url.path[1:] + parsed["virtual_host"] = virtual_host # NOTE(flaper87): Parse netloc. hosts = [] @@ -113,20 +109,3 @@ def parse_url(url, default_exchange=None): parsed['parameters'] = parameters return parsed - - -def exchange_from_url(url, default_exchange=None): - """Parse an exchange name from a URL. - - Assuming a URL takes the form of: - - transport:///myexchange - - then parse the URL and return the exchange name. - - :param url: the URL to parse - :type url: str - :param default_exchange: what to return if no exchange found in URL - :type default_exchange: str - """ - return parse_url(url, default_exchange)['exchange'] diff --git a/oslo/messaging/transport.py b/oslo/messaging/transport.py index 87572f5..14e425f 100644 --- a/oslo/messaging/transport.py +++ b/oslo/messaging/transport.py @@ -134,7 +134,7 @@ def get_transport(conf, url=None, allowed_remote_exmods=[]): An example transport URL might be:: - rabbit://me:passwd@host:5672/myexchange + rabbit://me:passwd@host:5672/virtual_host :param conf: the user configuration :type conf: cfg.ConfigOpts diff --git a/tests/test_urls.py b/tests/test_urls.py index 2bb8a0c..3e0439f 100644 --- a/tests/test_urls.py +++ b/tests/test_urls.py @@ -22,69 +22,31 @@ from tests import utils as test_utils load_tests = testscenarios.load_tests_apply_scenarios -class TestExchangeFromURL(test_utils.BaseTestCase): - - _notset = object() - - scenarios = [ - ('none_url_no_default', - dict(url=None, default=_notset, expect=None)), - ('empty_url_no_default', - dict(url='', default=_notset, expect=None)), - ('empty_url_none_default', - dict(url='foo:///', default=None, expect=None)), - ('empty_url_with_default', - dict(url='foo:///', default='bar', expect='bar')), - ('url_with_no_default', - dict(url='foo:///bar', default=_notset, expect='bar')), - ('url_with_none_default', - dict(url='foo:///bar', default=None, expect='bar')), - ('url_with_none_default', - dict(url='foo:///bar', default='blaa', expect='bar')), - ('multipart_url', - dict(url='foo:///bar/blaa', default=None, expect='bar')), - ('invalid_url', - dict(url='hooha', default='blaa', expect='blaa')), - ] - - def test_exchange_from_url(self): - kwargs = {} - if self.default is not self._notset: - kwargs['default_exchange'] = self.default - - self.assertEqual(urls.exchange_from_url(self.url, **kwargs), - self.expect) - - class TestParseURL(test_utils.BaseTestCase): scenarios = [ ('transport', dict(url='foo:', - default_exchange=None, expect=dict(transport='foo', - exchange=None, + virtual_host=None, hosts=[], parameters={}))), - ('default_exchange', - dict(url='foo:///bar', - default_exchange='bar', + ('virtual_host_slash', + dict(url='foo:////', expect=dict(transport='foo', - exchange='bar', + virtual_host='/', hosts=[], parameters={}))), - ('exchange', + ('virtual_host', dict(url='foo:///bar', - default_exchange=None, expect=dict(transport='foo', - exchange='bar', + virtual_host='bar', hosts=[], parameters={}))), ('host', dict(url='foo://host/bar', - default_exchange=None, expect=dict(transport='foo', - exchange='bar', + virtual_host='bar', hosts=[ dict(host='host', username='', @@ -93,9 +55,8 @@ class TestParseURL(test_utils.BaseTestCase): parameters={}))), ('port', dict(url='foo://host:1234/bar', - default_exchange=None, expect=dict(transport='foo', - exchange='bar', + virtual_host='bar', hosts=[ dict(host='host:1234', username='', @@ -104,9 +65,8 @@ class TestParseURL(test_utils.BaseTestCase): parameters={}))), ('username', dict(url='foo://u@host:1234/bar', - default_exchange=None, expect=dict(transport='foo', - exchange='bar', + virtual_host='bar', hosts=[ dict(host='host:1234', username='u', @@ -115,9 +75,8 @@ class TestParseURL(test_utils.BaseTestCase): parameters={}))), ('password', dict(url='foo://u:p@host:1234/bar', - default_exchange=None, expect=dict(transport='foo', - exchange='bar', + virtual_host='bar', hosts=[ dict(host='host:1234', username='u', @@ -126,9 +85,8 @@ class TestParseURL(test_utils.BaseTestCase): parameters={}))), ('multi_host', dict(url='foo://u:p@host1:1234,host2:4321/bar', - default_exchange=None, expect=dict(transport='foo', - exchange='bar', + virtual_host='bar', hosts=[ dict(host='host1:1234', username='u', @@ -140,9 +98,8 @@ class TestParseURL(test_utils.BaseTestCase): parameters={}))), ('multi_creds', dict(url='foo://u1:p1@host1:1234,u2:p2@host2:4321/bar', - default_exchange=None, expect=dict(transport='foo', - exchange='bar', + virtual_host='bar', hosts=[ dict(host='host1:1234', username='u1', |