diff --git a/oslo_messaging/rpc/client.py b/oslo_messaging/rpc/client.py index 3b05785a2..04992288f 100644 --- a/oslo_messaging/rpc/client.py +++ b/oslo_messaging/rpc/client.py @@ -166,6 +166,14 @@ class _CallContext(object): version=_marker, server=_marker, fanout=_marker, timeout=_marker, version_cap=_marker, retry=_marker): """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( exchange=exchange, topic=topic, diff --git a/oslo_messaging/tests/rpc/test_client.py b/oslo_messaging/tests/rpc/test_client.py index e163a9297..c5b7364d8 100644 --- a/oslo_messaging/tests/rpc/test_client.py +++ b/oslo_messaging/tests/rpc/test_client.py @@ -122,21 +122,21 @@ class TestCastToTarget(test_utils.BaseTestCase): prepare=dict(namespace='testnamespace'), expect=dict(namespace='testnamespace'))), ('ctor_version', - dict(ctor=dict(version='testversion'), + dict(ctor=dict(version='1.1'), prepare={}, - expect=dict(version='testversion'))), + expect=dict(version='1.1'))), ('prepare_version', dict(ctor={}, - prepare=dict(version='testversion'), - expect=dict(version='testversion'))), + prepare=dict(version='1.1'), + expect=dict(version='1.1'))), ('prepare_version_none', - dict(ctor=dict(version='testversion'), + dict(ctor=dict(version='1.1'), prepare=dict(version=None), expect={})), ('both_version', dict(ctor=dict(version='ctorversion'), - prepare=dict(version='testversion'), - expect=dict(version='testversion'))), + prepare=dict(version='1.1'), + expect=dict(version='1.1'))), ('ctor_server', dict(ctor=dict(server='testserver'), prepare={}, @@ -517,3 +517,12 @@ class TestCanSendVersion(test_utils.BaseTestCase): can_send = client.can_send_version() 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') diff --git a/tests/rpc/test_client.py b/tests/rpc/test_client.py index 65c4f6752..d4a9c241b 100644 --- a/tests/rpc/test_client.py +++ b/tests/rpc/test_client.py @@ -122,21 +122,21 @@ class TestCastToTarget(test_utils.BaseTestCase): prepare=dict(namespace='testnamespace'), expect=dict(namespace='testnamespace'))), ('ctor_version', - dict(ctor=dict(version='testversion'), + dict(ctor=dict(version='1.1'), prepare={}, - expect=dict(version='testversion'))), + expect=dict(version='1.1'))), ('prepare_version', dict(ctor={}, - prepare=dict(version='testversion'), - expect=dict(version='testversion'))), + prepare=dict(version='1.1'), + expect=dict(version='1.1'))), ('prepare_version_none', - dict(ctor=dict(version='testversion'), + dict(ctor=dict(version='1.1'), prepare=dict(version=None), expect={})), ('both_version', dict(ctor=dict(version='ctorversion'), - prepare=dict(version='testversion'), - expect=dict(version='testversion'))), + prepare=dict(version='1.1'), + expect=dict(version='1.1'))), ('ctor_server', dict(ctor=dict(server='testserver'), prepare={},