Merge "Fix bug with version_cap and target.version in RPCClient"

This commit is contained in:
Jenkins 2016-05-18 11:26:35 +00:00 committed by Gerrit Code Review
commit 46a98cf50e
3 changed files with 35 additions and 7 deletions

View File

@ -22,6 +22,12 @@ def version_is_compatible(imp_version, version):
:param imp_version: The version implemented
:param version: The version requested by an incoming message.
"""
if imp_version is None:
return True
if version is None:
return False
version_parts = version.split('.')
imp_version_parts = imp_version.split('.')
try:

View File

@ -123,12 +123,11 @@ class _BaseCallContext(object):
def can_send_version(self, version=_marker):
"""Check to see if a version is compatible with the version cap."""
version = self.target.version if version is self._marker else version
return (not self.version_cap or
utils.version_is_compatible(self.version_cap, version))
return utils.version_is_compatible(self.version_cap, version)
@classmethod
def _check_version(cls, version):
if version is not None and version is not cls._marker:
if version is not cls._marker:
# quick sanity check to make sure parsable version numbers are used
try:
utils.version_is_compatible(version, version)
@ -142,7 +141,6 @@ class _BaseCallContext(object):
msg = self._make_message(ctxt, method, kwargs)
msg_ctxt = self.serializer.serialize_context(ctxt)
if self.version_cap:
self._check_version_cap(msg.get('version'))
try:
@ -163,7 +161,6 @@ class _BaseCallContext(object):
if self.timeout is None:
timeout = self.conf.rpc_response_timeout
if self.version_cap:
self._check_version_cap(msg.get('version'))
try:

View File

@ -392,6 +392,14 @@ class TestVersionCap(test_utils.BaseTestCase):
dict(cap='2.0', prepare_cap=_notset,
version=None, prepare_version='1.0',
success=False)),
('ctor_cap_none_version_ok',
dict(cap=None, prepare_cap=_notset,
version='1.0', prepare_version=_notset,
success=True)),
('ctor_cap_version_none_fail',
dict(cap='1.0', prepare_cap=_notset,
version=None, prepare_version=_notset,
success=False)),
]
@classmethod
@ -492,6 +500,21 @@ class TestCanSendVersion(test_utils.BaseTestCase):
version=None, prepare_version='1.0',
can_send_version=_notset,
can_send=False)),
('ctor_cap_none_version_ok',
dict(cap=None, prepare_cap=_notset,
version='1.0', prepare_version=_notset,
can_send_version=_notset,
can_send=True)),
('ctor_cap_version_none_fail',
dict(cap='1.0', prepare_cap=_notset,
version=None, prepare_version=_notset,
can_send_version=_notset,
can_send=False)),
('ctor_cap_version_can_send_none_fail',
dict(cap='1.0', prepare_cap=_notset,
version='1.0', prepare_version=_notset,
can_send_version=None,
can_send=False)),
]
def test_version_cap(self):
@ -529,3 +552,5 @@ class TestCanSendVersion(test_utils.BaseTestCase):
client.prepare, version='5')
self.assertRaises(exceptions.MessagingException,
client.prepare, version='5.a')
self.assertRaises(exceptions.MessagingException,
client.prepare, version='5.5.a')