From e55f419017200d0026ffb0fb8cfef19833347e4e Mon Sep 17 00:00:00 2001 From: Steve Kowalik Date: Thu, 5 Jul 2018 15:58:05 +1000 Subject: [PATCH] Remove transport aliases support To facilitate removing rpc_backend support, disentangle the aliases code by removing it to simplify the code and the tests. Aliases were first depreacted in 5.20.0 during Pike. Change-Id: I7d80cd050ce1eca2c6b6c38f0fac29d090b90bf3 Closes-Bug: #1424728 --- oslo_messaging/notify/notifier.py | 7 +-- oslo_messaging/tests/test_transport.py | 44 +++--------------- oslo_messaging/tests/test_urls.py | 62 +++++++------------------- oslo_messaging/transport.py | 38 ++++------------ 4 files changed, 33 insertions(+), 118 deletions(-) diff --git a/oslo_messaging/notify/notifier.py b/oslo_messaging/notify/notifier.py index 8bdb13caf..8696ee8de 100644 --- a/oslo_messaging/notify/notifier.py +++ b/oslo_messaging/notify/notifier.py @@ -140,8 +140,7 @@ class Driver(object): pass -def get_notification_transport(conf, url=None, - allowed_remote_exmods=None, aliases=None): +def get_notification_transport(conf, url=None, allowed_remote_exmods=None): """A factory method for Transport objects for notifications. This method should be used for notifications, in case notifications are @@ -164,15 +163,13 @@ def get_notification_transport(conf, url=None, transport will deserialize remote exceptions from :type allowed_remote_exmods: list - :param aliases: A map of transport alias to transport name - :type aliases: dict """ conf.register_opts(_notifier_opts, group='oslo_messaging_notifications') if url is None: url = conf.oslo_messaging_notifications.transport_url return msg_transport._get_transport( - conf, url, allowed_remote_exmods, aliases, + conf, url, allowed_remote_exmods, transport_cls=msg_transport.NotificationTransport) diff --git a/oslo_messaging/tests/test_transport.py b/oslo_messaging/tests/test_transport.py index 6e320645d..e1ad1d65e 100755 --- a/oslo_messaging/tests/test_transport.py +++ b/oslo_messaging/tests/test_transport.py @@ -53,63 +53,39 @@ class GetTransportTestCase(test_utils.BaseTestCase): scenarios = [ ('rpc_backend', dict(url=None, transport_url=None, rpc_backend='testbackend', - control_exchange=None, allowed=None, aliases=None, + control_exchange=None, allowed=None, expect=dict(backend='testbackend', exchange=None, url='testbackend:', allowed=[]))), ('transport_url', dict(url=None, transport_url='testtransport:', rpc_backend=None, - control_exchange=None, allowed=None, aliases=None, + control_exchange=None, allowed=None, expect=dict(backend='testtransport', exchange=None, url='testtransport:', allowed=[]))), ('url_param', dict(url='testtransport:', transport_url=None, rpc_backend=None, - control_exchange=None, allowed=None, aliases=None, + control_exchange=None, allowed=None, expect=dict(backend='testtransport', exchange=None, url='testtransport:', allowed=[]))), ('control_exchange', dict(url=None, transport_url=None, rpc_backend='testbackend', - control_exchange='testexchange', allowed=None, aliases=None, + control_exchange='testexchange', allowed=None, expect=dict(backend='testbackend', exchange='testexchange', url='testbackend:', allowed=[]))), ('allowed_remote_exmods', dict(url=None, transport_url=None, rpc_backend='testbackend', - control_exchange=None, allowed=['foo', 'bar'], aliases=None, + control_exchange=None, allowed=['foo', 'bar'], expect=dict(backend='testbackend', exchange=None, url='testbackend:', allowed=['foo', 'bar']))), - ('rpc_backend_aliased', - dict(url=None, transport_url=None, rpc_backend='testfoo', - control_exchange=None, allowed=None, - aliases=dict(testfoo='testbackend'), - expect=dict(backend='testbackend', - exchange=None, - url='testbackend:', - allowed=[]))), - ('transport_url_aliased', - dict(url=None, transport_url='testfoo:', rpc_backend=None, - control_exchange=None, allowed=None, - aliases=dict(testfoo='testtransport'), - expect=dict(backend='testtransport', - exchange=None, - url='testtransport:', - allowed=[]))), - ('url_param_aliased', - dict(url='testfoo:', transport_url=None, rpc_backend=None, - control_exchange=None, allowed=None, - aliases=dict(testfoo='testtransport'), - expect=dict(backend='testtransport', - exchange=None, - url='testtransport:', - allowed=[]))), ] @mock.patch('oslo_messaging.transport.LOG') @@ -133,18 +109,8 @@ class GetTransportTestCase(test_utils.BaseTestCase): kwargs = dict(url=self.url) if self.allowed is not None: kwargs['allowed_remote_exmods'] = self.allowed - if self.aliases is not None: - kwargs['aliases'] = self.aliases transport_ = oslo_messaging.get_transport(self.conf, **kwargs) - if self.aliases is not None: - self.assertEqual( - [mock.call('legacy "rpc_backend" is deprecated, ' - '"testfoo" must be replaced by ' - '"%s"' % self.aliases.get('testfoo'))], - fake_logger.warning.mock_calls - ) - self.assertIsNotNone(transport_) self.assertIs(transport_.conf, self.conf) self.assertIs(transport_._driver, drvr) diff --git a/oslo_messaging/tests/test_urls.py b/oslo_messaging/tests/test_urls.py index d722b8112..b3bdfca02 100644 --- a/oslo_messaging/tests/test_urls.py +++ b/oslo_messaging/tests/test_urls.py @@ -25,54 +25,51 @@ class TestParseURL(test_utils.BaseTestCase): scenarios = [ ('transport', - dict(url='foo:', aliases=None, - expect=dict(transport='foo'))), - ('transport_aliased', - dict(url='bar:', aliases=dict(bar='foo'), + dict(url='foo:', expect=dict(transport='foo'))), ('virtual_host_slash', - dict(url='foo:////', aliases=None, + dict(url='foo:////', expect=dict(transport='foo', virtual_host='/'))), ('virtual_host', - dict(url='foo:///bar', aliases=None, + dict(url='foo:///bar', expect=dict(transport='foo', virtual_host='bar'))), ('host', - dict(url='foo://host/bar', aliases=None, + dict(url='foo://host/bar', expect=dict(transport='foo', virtual_host='bar', hosts=[ dict(host='host'), ]))), ('ipv6_host', - dict(url='foo://[ffff::1]/bar', aliases=None, + dict(url='foo://[ffff::1]/bar', expect=dict(transport='foo', virtual_host='bar', hosts=[ dict(host='ffff::1'), ]))), ('port', - dict(url='foo://host:1234/bar', aliases=None, + dict(url='foo://host:1234/bar', expect=dict(transport='foo', virtual_host='bar', hosts=[ dict(host='host', port=1234), ]))), ('ipv6_port', - dict(url='foo://[ffff::1]:1234/bar', aliases=None, + dict(url='foo://[ffff::1]:1234/bar', expect=dict(transport='foo', virtual_host='bar', hosts=[ dict(host='ffff::1', port=1234), ]))), ('username', - dict(url='foo://u@host:1234/bar', aliases=None, + dict(url='foo://u@host:1234/bar', expect=dict(transport='foo', virtual_host='bar', hosts=[ dict(host='host', port=1234, username='u'), ]))), ('password', - dict(url='foo://u:p@host:1234/bar', aliases=None, + dict(url='foo://u:p@host:1234/bar', expect=dict(transport='foo', virtual_host='bar', hosts=[ @@ -80,14 +77,14 @@ class TestParseURL(test_utils.BaseTestCase): username='u', password='p'), ]))), ('creds_no_host', - dict(url='foo://u:p@/bar', aliases=None, + dict(url='foo://u:p@/bar', expect=dict(transport='foo', virtual_host='bar', hosts=[ dict(username='u', password='p'), ]))), ('multi_host', - dict(url='foo://u:p@host1:1234,host2:4321/bar', aliases=None, + dict(url='foo://u:p@host1:1234,host2:4321/bar', expect=dict(transport='foo', virtual_host='bar', hosts=[ @@ -96,7 +93,7 @@ class TestParseURL(test_utils.BaseTestCase): dict(host='host2', port=4321), ]))), ('multi_host_partial_creds', - dict(url='foo://u:p@host1,host2/bar', aliases=None, + dict(url='foo://u:p@host1,host2/bar', expect=dict(transport='foo', virtual_host='bar', hosts=[ @@ -104,7 +101,7 @@ class TestParseURL(test_utils.BaseTestCase): dict(host='host2'), ]))), ('multi_creds', - dict(url='foo://u1:p1@host1:1234,u2:p2@host2:4321/bar', aliases=None, + dict(url='foo://u1:p1@host1:1234,u2:p2@host2:4321/bar', expect=dict(transport='foo', virtual_host='bar', hosts=[ @@ -115,7 +112,6 @@ class TestParseURL(test_utils.BaseTestCase): ]))), ('multi_creds_ipv6', dict(url='foo://u1:p1@[ffff::1]:1234,u2:p2@[ffff::2]:4321/bar', - aliases=None, expect=dict(transport='foo', virtual_host='bar', hosts=[ @@ -125,7 +121,7 @@ class TestParseURL(test_utils.BaseTestCase): username='u2', password='p2'), ]))), ('quoting', - dict(url='foo://u%24:p%26@host:1234/%24', aliases=None, + dict(url='foo://u%24:p%26@host:1234/%24', expect=dict(transport='foo', virtual_host='$', hosts=[ @@ -137,8 +133,7 @@ class TestParseURL(test_utils.BaseTestCase): def test_parse_url(self): self.config(rpc_backend=None) - url = oslo_messaging.TransportURL.parse(self.conf, self.url, - self.aliases) + url = oslo_messaging.TransportURL.parse(self.conf, self.url) hosts = [] for host in self.expect.get('hosts', []): @@ -162,35 +157,18 @@ class TestFormatURL(test_utils.BaseTestCase): transport=None, virtual_host=None, hosts=[], - aliases=None, - expected='testbackend:///')), - ('rpc_backend_aliased', - dict(rpc_backend='testfoo', - transport=None, - virtual_host=None, - hosts=[], - aliases=dict(testfoo='testbackend'), expected='testbackend:///')), ('transport', dict(rpc_backend=None, transport='testtransport', virtual_host=None, hosts=[], - aliases=None, - expected='testtransport:///')), - ('transport_aliased', - dict(rpc_backend=None, - transport='testfoo', - virtual_host=None, - hosts=[], - aliases=dict(testfoo='testtransport'), expected='testtransport:///')), ('virtual_host', dict(rpc_backend=None, transport='testtransport', virtual_host='/vhost', hosts=[], - aliases=None, expected='testtransport:////vhost')), ('host', dict(rpc_backend=None, @@ -202,7 +180,6 @@ class TestFormatURL(test_utils.BaseTestCase): username='bob', password='secret'), ], - aliases=None, expected='testtransport://bob:secret@host:10//')), ('multi_host', dict(rpc_backend=None, @@ -218,7 +195,6 @@ class TestFormatURL(test_utils.BaseTestCase): username='b2', password='s2'), ], - aliases=None, expected='testtransport://b1:s1@h1:1000,b2:s2@h2:2000/')), ('quoting', dict(rpc_backend=None, @@ -230,7 +206,6 @@ class TestFormatURL(test_utils.BaseTestCase): username='b$', password='s&'), ], - aliases=None, expected='testtransport://b%24:s%26@host:10//%24')), ] @@ -244,10 +219,7 @@ class TestFormatURL(test_utils.BaseTestCase): host.get('username'), host.get('password'))) - url = oslo_messaging.TransportURL(self.conf, - self.transport, - self.virtual_host, - hosts, - self.aliases) + url = oslo_messaging.TransportURL(self.conf, self.transport, + self.virtual_host, hosts) self.assertEqual(self.expected, str(url)) diff --git a/oslo_messaging/transport.py b/oslo_messaging/transport.py index f416ee25f..267f3896f 100644 --- a/oslo_messaging/transport.py +++ b/oslo_messaging/transport.py @@ -195,13 +195,13 @@ class DriverLoadFailure(exceptions.MessagingException): self.ex = ex -def _get_transport(conf, url=None, allowed_remote_exmods=None, aliases=None, +def _get_transport(conf, url=None, allowed_remote_exmods=None, transport_cls=RPCTransport): allowed_remote_exmods = allowed_remote_exmods or [] conf.register_opts(_transport_opts) if not isinstance(url, TransportURL): - url = TransportURL.parse(conf, url, aliases) + url = TransportURL.parse(conf, url) kwargs = dict(default_exchange=conf.control_exchange, allowed_remote_exmods=allowed_remote_exmods) @@ -221,9 +221,7 @@ def _get_transport(conf, url=None, allowed_remote_exmods=None, aliases=None, @removals.remove( message='use get_rpc_transport or get_notification_transport' ) -@removals.removed_kwarg('aliases', - 'Parameter aliases is deprecated for removal.') -def get_transport(conf, url=None, allowed_remote_exmods=None, aliases=None): +def get_transport(conf, url=None, allowed_remote_exmods=None): """A factory method for Transport objects. This method will construct a Transport object from transport configuration @@ -250,11 +248,8 @@ def get_transport(conf, url=None, allowed_remote_exmods=None, aliases=None): transport will deserialize remote exceptions from :type allowed_remote_exmods: list - :param aliases: DEPRECATED: A map of transport alias to transport name - :type aliases: dict """ - return _get_transport(conf, url, - allowed_remote_exmods, aliases, + return _get_transport(conf, url, allowed_remote_exmods, transport_cls=RPCTransport) @@ -336,16 +331,12 @@ class TransportURL(object): :type virtual_host: str :param hosts: a list of TransportHost objects :type hosts: list - :param aliases: DEPRECATED: a map of transport alias to transport name - :type aliases: dict :param query: a dictionary of URL query parameters :type query: dict """ - @removals.removed_kwarg('aliases', - 'Parameter aliases is deprecated for removal.') def __init__(self, conf, transport=None, virtual_host=None, hosts=None, - aliases=None, query=None): + query=None): self.conf = conf self.conf.register_opts(_transport_opts) self._transport = transport @@ -354,10 +345,6 @@ class TransportURL(object): self.hosts = [] else: self.hosts = hosts - if aliases is None: - self.aliases = {} - else: - self.aliases = aliases if query is None: self.query = {} else: @@ -371,7 +358,7 @@ class TransportURL(object): transport = self.conf.rpc_backend else: transport = self._transport - final_transport = self.aliases.get(transport, transport) + final_transport = transport if not self._deprecation_logged and final_transport != transport: # NOTE(sileht): The first step is deprecate this one cycle. # To ensure deployer have updated they configuration during Ocata @@ -452,10 +439,8 @@ class TransportURL(object): return url - @removals.removed_kwarg('aliases', - 'Parameter aliases is deprecated for removal.') @classmethod - def parse(cls, conf, url=None, aliases=None): + def parse(cls, conf, url=None): """Parse a URL as defined by :py:class:`TransportURL` and return a TransportURL object. @@ -485,8 +470,6 @@ class TransportURL(object): :type conf: oslo.config.cfg.ConfigOpts :param url: The URL to parse :type url: str - :param aliases: A map of transport alias to transport name - :type aliases: dict :returns: A TransportURL """ @@ -494,7 +477,7 @@ class TransportURL(object): conf.register_opts(_transport_opts) url = url or conf.transport_url if not url: - return cls(conf) if aliases is None else cls(conf, aliases=aliases) + return cls(conf) if not isinstance(url, six.string_types): raise InvalidTransportURL(url, 'Wrong URL type') @@ -578,7 +561,4 @@ class TransportURL(object): {'hosts_with_credentials': hosts_with_credentials, 'hosts_without_credentials': hosts_without_credentials}) - if aliases is None: - return cls(conf, transport, virtual_host, hosts, query=query) - else: - return cls(conf, transport, virtual_host, hosts, aliases, query) + return cls(conf, transport, virtual_host, hosts, query)