PYTHON-1409 - Improve server compatibility error messages

This commit is contained in:
Bernie Hackett 2017-11-13 15:03:47 -08:00
parent 49cee292cc
commit b878ed60ca
3 changed files with 40 additions and 8 deletions

View File

@ -48,6 +48,7 @@ MAX_WIRE_VERSION = 0
MAX_WRITE_BATCH_SIZE = 1000
# What this version of PyMongo supports.
MIN_SUPPORTED_SERVER_VERSION = "2.6"
MIN_SUPPORTED_WIRE_VERSION = 2
MAX_SUPPORTED_WIRE_VERSION = 5

View File

@ -76,15 +76,21 @@ class TopologyDescription(object):
s.max_wire_version is not None
and s.max_wire_version < common.MIN_SUPPORTED_WIRE_VERSION)
if server_too_new or server_too_old:
if server_too_new:
self._incompatible_err = (
"Server at %s:%d "
"uses wire protocol versions %d through %d, "
"but PyMongo only supports %d through %d"
"Server at %s:%d requires wire version %d, but this "
"version of PyMongo only supports up to %d."
% (s.address[0], s.address[1],
s.min_wire_version, s.max_wire_version,
s.min_wire_version, common.MAX_SUPPORTED_WIRE_VERSION))
elif server_too_old:
self._incompatible_err = (
"Server at %s:%d reports wire version %d, but this "
"version of PyMongo requires at least %d (MongoDB %s)."
% (s.address[0], s.address[1],
s.max_wire_version,
common.MIN_SUPPORTED_WIRE_VERSION,
common.MAX_SUPPORTED_WIRE_VERSION))
common.MIN_SUPPORTED_SERVER_VERSION))
break

View File

@ -567,8 +567,33 @@ class TestMultiServerTopology(TopologyTest):
t.select_servers(any_server_selector)
except ConfigurationError as e:
# Error message should say which server failed and why.
self.assertTrue('a:27017' in str(e))
self.assertTrue('wire protocol versions 11 through 12' in str(e))
self.assertEqual(
str(e),
"Server at a:27017 requires wire version 11, but this version "
"of PyMongo only supports up to %d."
% (common.MAX_SUPPORTED_WIRE_VERSION,))
else:
self.fail('No error with incompatible wire version')
# Incompatible.
got_ismaster(t, address, {
'ok': 1,
'ismaster': True,
'setName': 'rs',
'hosts': ['a'],
'minWireVersion': 0,
'maxWireVersion': 0})
try:
t.select_servers(any_server_selector)
except ConfigurationError as e:
# Error message should say which server failed and why.
self.assertEqual(
str(e),
"Server at a:27017 reports wire version 0, but this version "
"of PyMongo requires at least %d (MongoDB %s)."
% (common.MIN_SUPPORTED_WIRE_VERSION,
common.MIN_SUPPORTED_SERVER_VERSION))
else:
self.fail('No error with incompatible wire version')