Merge "Verify that version in 'prepare' is valid"
This commit is contained in:
commit
0969bfcd89
@ -166,6 +166,14 @@ class _CallContext(object):
|
|||||||
version=_marker, server=_marker, fanout=_marker,
|
version=_marker, server=_marker, fanout=_marker,
|
||||||
timeout=_marker, version_cap=_marker, retry=_marker):
|
timeout=_marker, version_cap=_marker, retry=_marker):
|
||||||
"""Prepare a method invocation context. See RPCClient.prepare()."""
|
"""Prepare a method invocation context. See RPCClient.prepare()."""
|
||||||
|
if version is not None and version is not cls._marker:
|
||||||
|
# quick sanity check to make sure parsable version numbers are used
|
||||||
|
try:
|
||||||
|
utils.version_is_compatible(version, version)
|
||||||
|
except (IndexError, ValueError):
|
||||||
|
raise exceptions.MessagingException(
|
||||||
|
"Version must contain a major and minor integer. Got %s"
|
||||||
|
% version)
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
exchange=exchange,
|
exchange=exchange,
|
||||||
topic=topic,
|
topic=topic,
|
||||||
|
@ -122,21 +122,21 @@ class TestCastToTarget(test_utils.BaseTestCase):
|
|||||||
prepare=dict(namespace='testnamespace'),
|
prepare=dict(namespace='testnamespace'),
|
||||||
expect=dict(namespace='testnamespace'))),
|
expect=dict(namespace='testnamespace'))),
|
||||||
('ctor_version',
|
('ctor_version',
|
||||||
dict(ctor=dict(version='testversion'),
|
dict(ctor=dict(version='1.1'),
|
||||||
prepare={},
|
prepare={},
|
||||||
expect=dict(version='testversion'))),
|
expect=dict(version='1.1'))),
|
||||||
('prepare_version',
|
('prepare_version',
|
||||||
dict(ctor={},
|
dict(ctor={},
|
||||||
prepare=dict(version='testversion'),
|
prepare=dict(version='1.1'),
|
||||||
expect=dict(version='testversion'))),
|
expect=dict(version='1.1'))),
|
||||||
('prepare_version_none',
|
('prepare_version_none',
|
||||||
dict(ctor=dict(version='testversion'),
|
dict(ctor=dict(version='1.1'),
|
||||||
prepare=dict(version=None),
|
prepare=dict(version=None),
|
||||||
expect={})),
|
expect={})),
|
||||||
('both_version',
|
('both_version',
|
||||||
dict(ctor=dict(version='ctorversion'),
|
dict(ctor=dict(version='ctorversion'),
|
||||||
prepare=dict(version='testversion'),
|
prepare=dict(version='1.1'),
|
||||||
expect=dict(version='testversion'))),
|
expect=dict(version='1.1'))),
|
||||||
('ctor_server',
|
('ctor_server',
|
||||||
dict(ctor=dict(server='testserver'),
|
dict(ctor=dict(server='testserver'),
|
||||||
prepare={},
|
prepare={},
|
||||||
@ -517,3 +517,12 @@ class TestCanSendVersion(test_utils.BaseTestCase):
|
|||||||
can_send = client.can_send_version()
|
can_send = client.can_send_version()
|
||||||
|
|
||||||
self.assertEqual(self.can_send, can_send)
|
self.assertEqual(self.can_send, can_send)
|
||||||
|
|
||||||
|
def test_invalid_version_type(self):
|
||||||
|
target = oslo_messaging.Target(topic='sometopic')
|
||||||
|
transport = _FakeTransport(self.conf)
|
||||||
|
client = oslo_messaging.RPCClient(transport, target)
|
||||||
|
self.assertRaises(exceptions.MessagingException,
|
||||||
|
client.prepare, version='5')
|
||||||
|
self.assertRaises(exceptions.MessagingException,
|
||||||
|
client.prepare, version='5.a')
|
||||||
|
@ -122,21 +122,21 @@ class TestCastToTarget(test_utils.BaseTestCase):
|
|||||||
prepare=dict(namespace='testnamespace'),
|
prepare=dict(namespace='testnamespace'),
|
||||||
expect=dict(namespace='testnamespace'))),
|
expect=dict(namespace='testnamespace'))),
|
||||||
('ctor_version',
|
('ctor_version',
|
||||||
dict(ctor=dict(version='testversion'),
|
dict(ctor=dict(version='1.1'),
|
||||||
prepare={},
|
prepare={},
|
||||||
expect=dict(version='testversion'))),
|
expect=dict(version='1.1'))),
|
||||||
('prepare_version',
|
('prepare_version',
|
||||||
dict(ctor={},
|
dict(ctor={},
|
||||||
prepare=dict(version='testversion'),
|
prepare=dict(version='1.1'),
|
||||||
expect=dict(version='testversion'))),
|
expect=dict(version='1.1'))),
|
||||||
('prepare_version_none',
|
('prepare_version_none',
|
||||||
dict(ctor=dict(version='testversion'),
|
dict(ctor=dict(version='1.1'),
|
||||||
prepare=dict(version=None),
|
prepare=dict(version=None),
|
||||||
expect={})),
|
expect={})),
|
||||||
('both_version',
|
('both_version',
|
||||||
dict(ctor=dict(version='ctorversion'),
|
dict(ctor=dict(version='ctorversion'),
|
||||||
prepare=dict(version='testversion'),
|
prepare=dict(version='1.1'),
|
||||||
expect=dict(version='testversion'))),
|
expect=dict(version='1.1'))),
|
||||||
('ctor_server',
|
('ctor_server',
|
||||||
dict(ctor=dict(server='testserver'),
|
dict(ctor=dict(server='testserver'),
|
||||||
prepare={},
|
prepare={},
|
||||||
|
Loading…
Reference in New Issue
Block a user