diff --git a/pymongo/common.py b/pymongo/common.py index b8d2b0176..e2f4241eb 100644 --- a/pymongo/common.py +++ b/pymongo/common.py @@ -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 diff --git a/pymongo/topology_description.py b/pymongo/topology_description.py index 49d2b195d..6ba04971b 100644 --- a/pymongo/topology_description.py +++ b/pymongo/topology_description.py @@ -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 diff --git a/test/test_topology.py b/test/test_topology.py index 4dd19a8ea..5a4697f41 100644 --- a/test/test_topology.py +++ b/test/test_topology.py @@ -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')