8000 deal with regression in pymongo 3.6.1 which needs auth for issuing bu… by abdulito · Pull Request #50 · mongolab/mongoctl · GitHub
[go: up one dir, main page]

Skip to content
8000
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions mongoctl/objects/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,34 @@ def read_current_mongo_version(self):

return None

###########################################################################
def get_server_build_info(self):
"""
issues a buildinfo command
"""
if self.is_online():
try:
return self.get_mongo_client().server_info()
except OperationFailure, ofe:
log_exception(ofe)
if "there are no users authenticated" in str(ofe):
# this is a pymongo 3.6.1 regression where the buildinfo command fails on non authenticated client
# fall-back to an authenticated client
admin_db = self.get_db("admin", no_auth=False)
return admin_db.command("buildinfo")
except Exception, e:
log_exception(e)

return None

###########################################################################
def get_mongodb_edition(self):

if self._mongodb_edition:
return self._mongodb_edition

79F9 if self.is_online():
server_info = self.get_mongo_client().server_info()
server_info = self.get_server_build_info()
if server_info:
if ("gitVersion" in server_info and
("subscription" in server_info["gitVersion"] or
"enterprise" in server_info["gitVersion"])):
Expand Down Expand Up @@ -739,7 +759,8 @@ def needs_to_auth(self, dbname):
result = False
except (RuntimeError,Exception), e:
log_exception(e)
result = "authorized" in str(e)
# updated for to handle auth failures from mongodb 3.6
result = "authorized" in str(e) or "there are no users authenticated" in str(e)

log_debug("needs_to_auth check for server '%s' on db '%s' : %s" %
(self.id, dbname, result))
Expand Down
0