oslo.messaging/tests/test_transport.py

368 lines
14 KiB
Python
Raw Normal View History

2013-06-09 14:46:40 +01:00
# Copyright 2013 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import fixtures
import six
from six.moves import mox
2013-06-09 14:46:40 +01:00
from stevedore import driver
import testscenarios
2013-06-09 14:46:40 +01:00
from oslo.config import cfg
from oslo import messaging
from oslo.messaging import transport
from oslo_messaging.tests import utils as test_utils
from oslo_messaging import transport as private_transport
2013-06-09 14:46:40 +01:00
load_tests = testscenarios.load_tests_apply_scenarios
2013-06-09 14:46:40 +01:00
class _FakeDriver(object):
def __init__(self, conf):
self.conf = conf
def send(self, *args, **kwargs):
pass
def send_notification(self, *args, **kwargs):
pass
2013-06-09 14:46:40 +01:00
def listen(self, target):
pass
class _FakeManager(object):
def __init__(self, driver):
self.driver = driver
class GetTransportTestCase(test_utils.BaseTestCase):
scenarios = [
('rpc_backend',
dict(url=None, transport_url=None, rpc_backend='testbackend',
control_exchange=None, allowed=None, aliases=None,
2013-06-09 14:46:40 +01:00
expect=dict(backend='testbackend',
exchange=None,
Add a TransportURL class to the public API Nova's cells/rpc_driver.py has some code which allows user of the REST API to update elements of a cell's transport URL (say, the host name of the message broker) stored in the database. To achieve this, it has a parse_transport_url() method which breaks the URL into its constituent parts and an unparse_transport_url() which re-forms it again after updating some of its parts. This is all fine and, since it's fairly specialized, it wouldn't be a big deal to leave this code in Nova for now ... except the unparse method looks at CONF.rpc_backend to know what scheme to use in the returned URL if now backend was specified. oslo.messaging registers the rpc_backend option, but the ability to reference any option registered by the library should not be relied upon by users of the library. Imagine, for instance, if we renamed the option in future (with backwards compat for old configurations), then this would mean API breakage. So, long story short - an API along these lines makes some sense, but especially since not having it would mean we'd need to add some way to query the name of the transport driver. In this commit, we add a simple new TransportURL class: >>> url = messaging.TransportURL.parse(cfg.CONF, 'foo:///') >>> str(url), url ('foo:///', <TransportURL transport='foo'>) >>> url.hosts.append(messaging.TransportHost(hostname='localhost')) >>> str(url), url ('foo://localhost/', <TransportURL transport='foo', hosts=[<TransportHost hostname='localhost'>]>) >>> url.transport = None >>> str(url), url ('kombu://localhost/', <TransportURL transport='kombu', hosts=[<TransportHost hostname='localhost'>]>) >>> cfg.CONF.set_override('rpc_backend', 'bar') >>> str(url), url ('bar://localhost/', <TransportURL transport='bar', hosts=[<TransportHost hostname='localhost'>]>) The TransportURL.parse() method equates to parse_transport_url() and TransportURL.__str__() equates to unparse_transport(). The transport drivers are also updated to take a TransportURL as a required argument, which simplifies the handling of transport URLs in the drivers. Change-Id: Ic04173476329858e4a2c2d2707e9d4aeb212d127
2013-08-12 17:16:44 +01:00
url='testbackend:',
allowed=[]))),
2013-06-09 14:46:40 +01:00
('transport_url',
dict(url=None, transport_url='testtransport:', rpc_backend=None,
control_exchange=None, allowed=None, aliases=None,
2013-06-09 14:46:40 +01:00
expect=dict(backend='testtransport',
exchange=None,
url='testtransport:',
allowed=[]))),
2013-06-09 14:46:40 +01:00
('url_param',
dict(url='testtransport:', transport_url=None, rpc_backend=None,
control_exchange=None, allowed=None, aliases=None,
2013-06-09 14:46:40 +01:00
expect=dict(backend='testtransport',
exchange=None,
url='testtransport:',
allowed=[]))),
Add a TransportURL class to the public API Nova's cells/rpc_driver.py has some code which allows user of the REST API to update elements of a cell's transport URL (say, the host name of the message broker) stored in the database. To achieve this, it has a parse_transport_url() method which breaks the URL into its constituent parts and an unparse_transport_url() which re-forms it again after updating some of its parts. This is all fine and, since it's fairly specialized, it wouldn't be a big deal to leave this code in Nova for now ... except the unparse method looks at CONF.rpc_backend to know what scheme to use in the returned URL if now backend was specified. oslo.messaging registers the rpc_backend option, but the ability to reference any option registered by the library should not be relied upon by users of the library. Imagine, for instance, if we renamed the option in future (with backwards compat for old configurations), then this would mean API breakage. So, long story short - an API along these lines makes some sense, but especially since not having it would mean we'd need to add some way to query the name of the transport driver. In this commit, we add a simple new TransportURL class: >>> url = messaging.TransportURL.parse(cfg.CONF, 'foo:///') >>> str(url), url ('foo:///', <TransportURL transport='foo'>) >>> url.hosts.append(messaging.TransportHost(hostname='localhost')) >>> str(url), url ('foo://localhost/', <TransportURL transport='foo', hosts=[<TransportHost hostname='localhost'>]>) >>> url.transport = None >>> str(url), url ('kombu://localhost/', <TransportURL transport='kombu', hosts=[<TransportHost hostname='localhost'>]>) >>> cfg.CONF.set_override('rpc_backend', 'bar') >>> str(url), url ('bar://localhost/', <TransportURL transport='bar', hosts=[<TransportHost hostname='localhost'>]>) The TransportURL.parse() method equates to parse_transport_url() and TransportURL.__str__() equates to unparse_transport(). The transport drivers are also updated to take a TransportURL as a required argument, which simplifies the handling of transport URLs in the drivers. Change-Id: Ic04173476329858e4a2c2d2707e9d4aeb212d127
2013-08-12 17:16:44 +01:00
('control_exchange',
dict(url=None, transport_url=None, rpc_backend='testbackend',
control_exchange='testexchange', allowed=None, aliases=None,
Add a TransportURL class to the public API Nova's cells/rpc_driver.py has some code which allows user of the REST API to update elements of a cell's transport URL (say, the host name of the message broker) stored in the database. To achieve this, it has a parse_transport_url() method which breaks the URL into its constituent parts and an unparse_transport_url() which re-forms it again after updating some of its parts. This is all fine and, since it's fairly specialized, it wouldn't be a big deal to leave this code in Nova for now ... except the unparse method looks at CONF.rpc_backend to know what scheme to use in the returned URL if now backend was specified. oslo.messaging registers the rpc_backend option, but the ability to reference any option registered by the library should not be relied upon by users of the library. Imagine, for instance, if we renamed the option in future (with backwards compat for old configurations), then this would mean API breakage. So, long story short - an API along these lines makes some sense, but especially since not having it would mean we'd need to add some way to query the name of the transport driver. In this commit, we add a simple new TransportURL class: >>> url = messaging.TransportURL.parse(cfg.CONF, 'foo:///') >>> str(url), url ('foo:///', <TransportURL transport='foo'>) >>> url.hosts.append(messaging.TransportHost(hostname='localhost')) >>> str(url), url ('foo://localhost/', <TransportURL transport='foo', hosts=[<TransportHost hostname='localhost'>]>) >>> url.transport = None >>> str(url), url ('kombu://localhost/', <TransportURL transport='kombu', hosts=[<TransportHost hostname='localhost'>]>) >>> cfg.CONF.set_override('rpc_backend', 'bar') >>> str(url), url ('bar://localhost/', <TransportURL transport='bar', hosts=[<TransportHost hostname='localhost'>]>) The TransportURL.parse() method equates to parse_transport_url() and TransportURL.__str__() equates to unparse_transport(). The transport drivers are also updated to take a TransportURL as a required argument, which simplifies the handling of transport URLs in the drivers. Change-Id: Ic04173476329858e4a2c2d2707e9d4aeb212d127
2013-08-12 17:16:44 +01:00
expect=dict(backend='testbackend',
exchange='testexchange',
url='testbackend:',
allowed=[]))),
('allowed_remote_exmods',
Add a TransportURL class to the public API Nova's cells/rpc_driver.py has some code which allows user of the REST API to update elements of a cell's transport URL (say, the host name of the message broker) stored in the database. To achieve this, it has a parse_transport_url() method which breaks the URL into its constituent parts and an unparse_transport_url() which re-forms it again after updating some of its parts. This is all fine and, since it's fairly specialized, it wouldn't be a big deal to leave this code in Nova for now ... except the unparse method looks at CONF.rpc_backend to know what scheme to use in the returned URL if now backend was specified. oslo.messaging registers the rpc_backend option, but the ability to reference any option registered by the library should not be relied upon by users of the library. Imagine, for instance, if we renamed the option in future (with backwards compat for old configurations), then this would mean API breakage. So, long story short - an API along these lines makes some sense, but especially since not having it would mean we'd need to add some way to query the name of the transport driver. In this commit, we add a simple new TransportURL class: >>> url = messaging.TransportURL.parse(cfg.CONF, 'foo:///') >>> str(url), url ('foo:///', <TransportURL transport='foo'>) >>> url.hosts.append(messaging.TransportHost(hostname='localhost')) >>> str(url), url ('foo://localhost/', <TransportURL transport='foo', hosts=[<TransportHost hostname='localhost'>]>) >>> url.transport = None >>> str(url), url ('kombu://localhost/', <TransportURL transport='kombu', hosts=[<TransportHost hostname='localhost'>]>) >>> cfg.CONF.set_override('rpc_backend', 'bar') >>> str(url), url ('bar://localhost/', <TransportURL transport='bar', hosts=[<TransportHost hostname='localhost'>]>) The TransportURL.parse() method equates to parse_transport_url() and TransportURL.__str__() equates to unparse_transport(). The transport drivers are also updated to take a TransportURL as a required argument, which simplifies the handling of transport URLs in the drivers. Change-Id: Ic04173476329858e4a2c2d2707e9d4aeb212d127
2013-08-12 17:16:44 +01:00
dict(url=None, transport_url=None, rpc_backend='testbackend',
control_exchange=None, allowed=['foo', 'bar'], aliases=None,
Add a TransportURL class to the public API Nova's cells/rpc_driver.py has some code which allows user of the REST API to update elements of a cell's transport URL (say, the host name of the message broker) stored in the database. To achieve this, it has a parse_transport_url() method which breaks the URL into its constituent parts and an unparse_transport_url() which re-forms it again after updating some of its parts. This is all fine and, since it's fairly specialized, it wouldn't be a big deal to leave this code in Nova for now ... except the unparse method looks at CONF.rpc_backend to know what scheme to use in the returned URL if now backend was specified. oslo.messaging registers the rpc_backend option, but the ability to reference any option registered by the library should not be relied upon by users of the library. Imagine, for instance, if we renamed the option in future (with backwards compat for old configurations), then this would mean API breakage. So, long story short - an API along these lines makes some sense, but especially since not having it would mean we'd need to add some way to query the name of the transport driver. In this commit, we add a simple new TransportURL class: >>> url = messaging.TransportURL.parse(cfg.CONF, 'foo:///') >>> str(url), url ('foo:///', <TransportURL transport='foo'>) >>> url.hosts.append(messaging.TransportHost(hostname='localhost')) >>> str(url), url ('foo://localhost/', <TransportURL transport='foo', hosts=[<TransportHost hostname='localhost'>]>) >>> url.transport = None >>> str(url), url ('kombu://localhost/', <TransportURL transport='kombu', hosts=[<TransportHost hostname='localhost'>]>) >>> cfg.CONF.set_override('rpc_backend', 'bar') >>> str(url), url ('bar://localhost/', <TransportURL transport='bar', hosts=[<TransportHost hostname='localhost'>]>) The TransportURL.parse() method equates to parse_transport_url() and TransportURL.__str__() equates to unparse_transport(). The transport drivers are also updated to take a TransportURL as a required argument, which simplifies the handling of transport URLs in the drivers. Change-Id: Ic04173476329858e4a2c2d2707e9d4aeb212d127
2013-08-12 17:16:44 +01:00
expect=dict(backend='testbackend',
exchange=None,
Add a TransportURL class to the public API Nova's cells/rpc_driver.py has some code which allows user of the REST API to update elements of a cell's transport URL (say, the host name of the message broker) stored in the database. To achieve this, it has a parse_transport_url() method which breaks the URL into its constituent parts and an unparse_transport_url() which re-forms it again after updating some of its parts. This is all fine and, since it's fairly specialized, it wouldn't be a big deal to leave this code in Nova for now ... except the unparse method looks at CONF.rpc_backend to know what scheme to use in the returned URL if now backend was specified. oslo.messaging registers the rpc_backend option, but the ability to reference any option registered by the library should not be relied upon by users of the library. Imagine, for instance, if we renamed the option in future (with backwards compat for old configurations), then this would mean API breakage. So, long story short - an API along these lines makes some sense, but especially since not having it would mean we'd need to add some way to query the name of the transport driver. In this commit, we add a simple new TransportURL class: >>> url = messaging.TransportURL.parse(cfg.CONF, 'foo:///') >>> str(url), url ('foo:///', <TransportURL transport='foo'>) >>> url.hosts.append(messaging.TransportHost(hostname='localhost')) >>> str(url), url ('foo://localhost/', <TransportURL transport='foo', hosts=[<TransportHost hostname='localhost'>]>) >>> url.transport = None >>> str(url), url ('kombu://localhost/', <TransportURL transport='kombu', hosts=[<TransportHost hostname='localhost'>]>) >>> cfg.CONF.set_override('rpc_backend', 'bar') >>> str(url), url ('bar://localhost/', <TransportURL transport='bar', hosts=[<TransportHost hostname='localhost'>]>) The TransportURL.parse() method equates to parse_transport_url() and TransportURL.__str__() equates to unparse_transport(). The transport drivers are also updated to take a TransportURL as a required argument, which simplifies the handling of transport URLs in the drivers. Change-Id: Ic04173476329858e4a2c2d2707e9d4aeb212d127
2013-08-12 17:16:44 +01:00
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=[]))),
2013-06-09 14:46:40 +01:00
]
def test_get_transport(self):
2013-06-09 14:46:40 +01:00
self.config(rpc_backend=self.rpc_backend,
control_exchange=self.control_exchange,
transport_url=self.transport_url)
self.mox.StubOutWithMock(driver, 'DriverManager')
Add a TransportURL class to the public API Nova's cells/rpc_driver.py has some code which allows user of the REST API to update elements of a cell's transport URL (say, the host name of the message broker) stored in the database. To achieve this, it has a parse_transport_url() method which breaks the URL into its constituent parts and an unparse_transport_url() which re-forms it again after updating some of its parts. This is all fine and, since it's fairly specialized, it wouldn't be a big deal to leave this code in Nova for now ... except the unparse method looks at CONF.rpc_backend to know what scheme to use in the returned URL if now backend was specified. oslo.messaging registers the rpc_backend option, but the ability to reference any option registered by the library should not be relied upon by users of the library. Imagine, for instance, if we renamed the option in future (with backwards compat for old configurations), then this would mean API breakage. So, long story short - an API along these lines makes some sense, but especially since not having it would mean we'd need to add some way to query the name of the transport driver. In this commit, we add a simple new TransportURL class: >>> url = messaging.TransportURL.parse(cfg.CONF, 'foo:///') >>> str(url), url ('foo:///', <TransportURL transport='foo'>) >>> url.hosts.append(messaging.TransportHost(hostname='localhost')) >>> str(url), url ('foo://localhost/', <TransportURL transport='foo', hosts=[<TransportHost hostname='localhost'>]>) >>> url.transport = None >>> str(url), url ('kombu://localhost/', <TransportURL transport='kombu', hosts=[<TransportHost hostname='localhost'>]>) >>> cfg.CONF.set_override('rpc_backend', 'bar') >>> str(url), url ('bar://localhost/', <TransportURL transport='bar', hosts=[<TransportHost hostname='localhost'>]>) The TransportURL.parse() method equates to parse_transport_url() and TransportURL.__str__() equates to unparse_transport(). The transport drivers are also updated to take a TransportURL as a required argument, which simplifies the handling of transport URLs in the drivers. Change-Id: Ic04173476329858e4a2c2d2707e9d4aeb212d127
2013-08-12 17:16:44 +01:00
invoke_args = [self.conf,
messaging.TransportURL.parse(self.conf,
self.expect['url'])]
invoke_kwds = dict(default_exchange=self.expect['exchange'],
allowed_remote_exmods=self.expect['allowed'])
2013-06-09 14:46:40 +01:00
drvr = _FakeDriver(self.conf)
driver.DriverManager('oslo.messaging.drivers',
2013-06-09 14:46:40 +01:00
self.expect['backend'],
invoke_on_load=True,
invoke_args=invoke_args,
invoke_kwds=invoke_kwds).\
AndReturn(_FakeManager(drvr))
self.mox.ReplayAll()
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_ = messaging.get_transport(self.conf, **kwargs)
2013-06-09 14:46:40 +01:00
self.assertIsNotNone(transport_)
self.assertIs(transport_.conf, self.conf)
self.assertIs(transport_._driver, drvr)
2013-06-09 14:46:40 +01:00
class GetTransportSadPathTestCase(test_utils.BaseTestCase):
scenarios = [
('invalid_transport_url',
dict(url=None, transport_url='invalid', rpc_backend=None,
ex=dict(cls=messaging.InvalidTransportURL,
msg_contains='No scheme specified',
url='invalid'))),
('invalid_url_param',
dict(url='invalid', transport_url=None, rpc_backend=None,
ex=dict(cls=messaging.InvalidTransportURL,
msg_contains='No scheme specified',
url='invalid'))),
('driver_load_failure',
dict(url=None, transport_url=None, rpc_backend='testbackend',
ex=dict(cls=messaging.DriverLoadFailure,
msg_contains='Failed to load',
driver='testbackend'))),
]
def test_get_transport_sad(self):
2013-06-09 14:46:40 +01:00
self.config(rpc_backend=self.rpc_backend,
transport_url=self.transport_url)
if self.rpc_backend:
2013-06-09 14:46:40 +01:00
self.mox.StubOutWithMock(driver, 'DriverManager')
Add a TransportURL class to the public API Nova's cells/rpc_driver.py has some code which allows user of the REST API to update elements of a cell's transport URL (say, the host name of the message broker) stored in the database. To achieve this, it has a parse_transport_url() method which breaks the URL into its constituent parts and an unparse_transport_url() which re-forms it again after updating some of its parts. This is all fine and, since it's fairly specialized, it wouldn't be a big deal to leave this code in Nova for now ... except the unparse method looks at CONF.rpc_backend to know what scheme to use in the returned URL if now backend was specified. oslo.messaging registers the rpc_backend option, but the ability to reference any option registered by the library should not be relied upon by users of the library. Imagine, for instance, if we renamed the option in future (with backwards compat for old configurations), then this would mean API breakage. So, long story short - an API along these lines makes some sense, but especially since not having it would mean we'd need to add some way to query the name of the transport driver. In this commit, we add a simple new TransportURL class: >>> url = messaging.TransportURL.parse(cfg.CONF, 'foo:///') >>> str(url), url ('foo:///', <TransportURL transport='foo'>) >>> url.hosts.append(messaging.TransportHost(hostname='localhost')) >>> str(url), url ('foo://localhost/', <TransportURL transport='foo', hosts=[<TransportHost hostname='localhost'>]>) >>> url.transport = None >>> str(url), url ('kombu://localhost/', <TransportURL transport='kombu', hosts=[<TransportHost hostname='localhost'>]>) >>> cfg.CONF.set_override('rpc_backend', 'bar') >>> str(url), url ('bar://localhost/', <TransportURL transport='bar', hosts=[<TransportHost hostname='localhost'>]>) The TransportURL.parse() method equates to parse_transport_url() and TransportURL.__str__() equates to unparse_transport(). The transport drivers are also updated to take a TransportURL as a required argument, which simplifies the handling of transport URLs in the drivers. Change-Id: Ic04173476329858e4a2c2d2707e9d4aeb212d127
2013-08-12 17:16:44 +01:00
invoke_args = [self.conf,
messaging.TransportURL.parse(self.conf,
self.url)]
invoke_kwds = dict(default_exchange='openstack',
allowed_remote_exmods=[])
2013-06-09 14:46:40 +01:00
driver.DriverManager('oslo.messaging.drivers',
self.rpc_backend,
2013-06-09 14:46:40 +01:00
invoke_on_load=True,
invoke_args=invoke_args,
invoke_kwds=invoke_kwds).\
AndRaise(RuntimeError())
self.mox.ReplayAll()
try:
messaging.get_transport(self.conf, url=self.url)
self.assertFalse(True)
except Exception as ex:
ex_cls = self.ex.pop('cls')
ex_msg_contains = self.ex.pop('msg_contains')
self.assertIsInstance(ex, messaging.MessagingException)
self.assertIsInstance(ex, ex_cls)
self.assertIn(ex_msg_contains, six.text_type(ex))
2013-06-09 14:46:40 +01:00
for k, v in self.ex.items():
self.assertTrue(hasattr(ex, k))
self.assertEqual(v, str(getattr(ex, k)))
2013-06-09 14:46:40 +01:00
# FIXME(markmc): this could be used elsewhere
class _SetDefaultsFixture(fixtures.Fixture):
def __init__(self, set_defaults, opts, *names):
super(_SetDefaultsFixture, self).__init__()
self.set_defaults = set_defaults
self.opts = opts
self.names = names
def setUp(self):
super(_SetDefaultsFixture, self).setUp()
# FIXME(markmc): this comes from Id5c1f3ba
def first(seq, default=None, key=None):
if key is None:
key = bool
return next(six.moves.filter(key, seq), default)
2013-06-09 14:46:40 +01:00
def default(opts, name):
return first(opts, key=lambda o: o.name == name).default
orig_defaults = {}
for n in self.names:
orig_defaults[n] = default(self.opts, n)
def restore_defaults():
self.set_defaults(**orig_defaults)
self.addCleanup(restore_defaults)
class TestSetDefaults(test_utils.BaseTestCase):
def setUp(self):
super(TestSetDefaults, self).setUp(conf=cfg.ConfigOpts())
self.useFixture(_SetDefaultsFixture(messaging.set_transport_defaults,
private_transport._transport_opts,
2013-06-09 14:46:40 +01:00
'control_exchange'))
def test_set_default_control_exchange(self):
messaging.set_transport_defaults(control_exchange='foo')
2013-06-09 14:46:40 +01:00
self.mox.StubOutWithMock(driver, 'DriverManager')
invoke_kwds = mox.ContainsKeyValue('default_exchange', 'foo')
driver.DriverManager(mox.IgnoreArg(),
mox.IgnoreArg(),
invoke_on_load=mox.IgnoreArg(),
invoke_args=mox.IgnoreArg(),
invoke_kwds=invoke_kwds).\
AndReturn(_FakeManager(_FakeDriver(self.conf)))
self.mox.ReplayAll()
messaging.get_transport(self.conf)
class TestTransportMethodArgs(test_utils.BaseTestCase):
_target = messaging.Target(topic='topic', server='server')
2013-06-09 14:46:40 +01:00
def test_send_defaults(self):
t = transport.Transport(_FakeDriver(cfg.CONF))
self.mox.StubOutWithMock(t._driver, 'send')
t._driver.send(self._target, 'ctxt', 'message',
2013-06-09 14:46:40 +01:00
wait_for_reply=None,
timeout=None, retry=None)
2013-06-09 14:46:40 +01:00
self.mox.ReplayAll()
t._send(self._target, 'ctxt', 'message')
2013-06-09 14:46:40 +01:00
def test_send_all_args(self):
t = transport.Transport(_FakeDriver(cfg.CONF))
self.mox.StubOutWithMock(t._driver, 'send')
t._driver.send(self._target, 'ctxt', 'message',
2013-06-09 14:46:40 +01:00
wait_for_reply='wait_for_reply',
timeout='timeout', retry='retry')
2013-06-09 14:46:40 +01:00
self.mox.ReplayAll()
t._send(self._target, 'ctxt', 'message',
2013-06-09 14:46:40 +01:00
wait_for_reply='wait_for_reply',
timeout='timeout', retry='retry')
def test_send_notification(self):
t = transport.Transport(_FakeDriver(cfg.CONF))
self.mox.StubOutWithMock(t._driver, 'send_notification')
t._driver.send_notification(self._target, 'ctxt', 'message', 1.0,
retry=None)
self.mox.ReplayAll()
t._send_notification(self._target, 'ctxt', 'message', version=1.0)
2013-06-09 14:46:40 +01:00
def test_send_notification_all_args(self):
t = transport.Transport(_FakeDriver(cfg.CONF))
self.mox.StubOutWithMock(t._driver, 'send_notification')
t._driver.send_notification(self._target, 'ctxt', 'message', 1.0,
retry=5)
self.mox.ReplayAll()
t._send_notification(self._target, 'ctxt', 'message', version=1.0,
retry=5)
2013-06-09 14:46:40 +01:00
def test_listen(self):
t = transport.Transport(_FakeDriver(cfg.CONF))
self.mox.StubOutWithMock(t._driver, 'listen')
t._driver.listen(self._target)
2013-06-09 14:46:40 +01:00
self.mox.ReplayAll()
t._listen(self._target)
class TestTransportUrlCustomisation(test_utils.BaseTestCase):
def setUp(self):
super(TestTransportUrlCustomisation, self).setUp()
self.url1 = transport.TransportURL.parse(self.conf, "fake://vhost1")
self.url2 = transport.TransportURL.parse(self.conf, "fake://vhost2")
self.url3 = transport.TransportURL.parse(self.conf, "fake://vhost1")
def test_hash(self):
urls = {}
urls[self.url1] = self.url1
urls[self.url2] = self.url2
urls[self.url3] = self.url3
self.assertEqual(2, len(urls))
def test_eq(self):
self.assertEqual(self.url1, self.url3)
self.assertNotEqual(self.url1, self.url2)
class TestTransportHostCustomisation(test_utils.BaseTestCase):
def setUp(self):
super(TestTransportHostCustomisation, self).setUp()
self.host1 = transport.TransportHost("host1", 5662, "user", "pass")
self.host2 = transport.TransportHost("host1", 5662, "user", "pass")
self.host3 = transport.TransportHost("host1", 5663, "user", "pass")
self.host4 = transport.TransportHost("host1", 5662, "user2", "pass")
self.host5 = transport.TransportHost("host1", 5662, "user", "pass2")
self.host6 = transport.TransportHost("host2", 5662, "user", "pass")
def test_hash(self):
hosts = {}
hosts[self.host1] = self.host1
hosts[self.host2] = self.host2
hosts[self.host3] = self.host3
hosts[self.host4] = self.host4
hosts[self.host5] = self.host5
hosts[self.host6] = self.host6
self.assertEqual(5, len(hosts))
def test_eq(self):
self.assertEqual(self.host1, self.host2)
self.assertNotEqual(self.host1, self.host3)
self.assertNotEqual(self.host1, self.host4)
self.assertNotEqual(self.host1, self.host5)
self.assertNotEqual(self.host1, self.host6)