mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
Revert "SERVER-27627 use requests instead of urllib2 in resmoke.py"
This reverts commit 14f16f384a
.
This commit is contained in:
parent
a70ed6af85
commit
973b8b9da3
@ -5,6 +5,7 @@ Defines handlers for communicating with a buildlogger server.
|
||||
from __future__ import absolute_import
|
||||
|
||||
import functools
|
||||
import urllib2
|
||||
|
||||
from . import handlers
|
||||
from . import loggers
|
||||
@ -16,6 +17,7 @@ APPEND_GLOBAL_LOGS_ENDPOINT = "/build/%(build_id)s"
|
||||
CREATE_TEST_ENDPOINT = "/build/%(build_id)s/test"
|
||||
APPEND_TEST_LOGS_ENDPOINT = "/build/%(build_id)s/test/%(test_id)s"
|
||||
|
||||
_BUILDLOGGER_REALM = "buildlogs"
|
||||
_BUILDLOGGER_CONFIG = "mci.buildlogger"
|
||||
|
||||
_SEND_AFTER_LINES = 2000
|
||||
@ -35,6 +37,20 @@ def _log_on_error(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except urllib2.HTTPError as err:
|
||||
sb = [] # String builder.
|
||||
sb.append("HTTP Error %s: %s" % (err.code, err.msg))
|
||||
sb.append("POST %s" % (err.filename))
|
||||
|
||||
for name in err.hdrs:
|
||||
value = err.hdrs[name]
|
||||
sb.append(" %s: %s" % (name, value))
|
||||
|
||||
# Try to read the response back from the server.
|
||||
if hasattr(err, "read"):
|
||||
sb.append(err.read())
|
||||
|
||||
loggers._BUILDLOGGER_FALLBACK.exception("\n".join(sb))
|
||||
except:
|
||||
loggers._BUILDLOGGER_FALLBACK.exception("Encountered an error.")
|
||||
return None
|
||||
@ -78,6 +94,7 @@ def new_build_id(config):
|
||||
build_num = int(config["build_num"])
|
||||
|
||||
handler = handlers.HTTPHandler(
|
||||
realm=_BUILDLOGGER_REALM,
|
||||
url_root=_config.BUILDLOGGER_URL,
|
||||
username=username,
|
||||
password=password)
|
||||
@ -100,6 +117,7 @@ def new_test_id(build_id, build_config, test_filename, test_command):
|
||||
return None
|
||||
|
||||
handler = handlers.HTTPHandler(
|
||||
realm=_BUILDLOGGER_REALM,
|
||||
url_root=_config.BUILDLOGGER_URL,
|
||||
username=build_config["username"],
|
||||
password=build_config["password"])
|
||||
@ -136,7 +154,8 @@ class _BaseBuildloggerHandler(handlers.BufferedHandler):
|
||||
username = build_config["username"]
|
||||
password = build_config["password"]
|
||||
|
||||
self.http_handler = handlers.HTTPHandler(_config.BUILDLOGGER_URL,
|
||||
self.http_handler = handlers.HTTPHandler(_BUILDLOGGER_REALM,
|
||||
_config.BUILDLOGGER_URL,
|
||||
username,
|
||||
password)
|
||||
|
||||
|
@ -8,16 +8,13 @@ from __future__ import absolute_import
|
||||
import json
|
||||
import logging
|
||||
import threading
|
||||
|
||||
import requests
|
||||
import requests.auth
|
||||
import urllib2
|
||||
|
||||
from .. import utils
|
||||
from ..utils import timer
|
||||
|
||||
_TIMEOUT_SECS = 10
|
||||
|
||||
|
||||
class BufferedHandler(logging.Handler):
|
||||
"""
|
||||
A handler class that buffers logging records in memory. Whenever
|
||||
@ -144,15 +141,21 @@ class HTTPHandler(object):
|
||||
A class which sends data to a web server using POST requests.
|
||||
"""
|
||||
|
||||
def __init__(self, url_root, username, password):
|
||||
def __init__(self, realm, url_root, username, password):
|
||||
"""
|
||||
Initializes the handler with the necessary authentication
|
||||
Initializes the handler with the necessary authenticaton
|
||||
credentials.
|
||||
"""
|
||||
|
||||
self.auth_handler = requests.auth.HTTPBasicAuth(username, password)
|
||||
auth_handler = urllib2.HTTPBasicAuthHandler()
|
||||
auth_handler.add_password(
|
||||
realm=realm,
|
||||
uri=url_root,
|
||||
user=username,
|
||||
passwd=password)
|
||||
|
||||
self.url_root = url_root
|
||||
self.url_opener = urllib2.build_opener(auth_handler, urllib2.HTTPErrorProcessor())
|
||||
|
||||
def _make_url(self, endpoint):
|
||||
return "%s/%s/" % (self.url_root.rstrip("/"), endpoint.strip("/"))
|
||||
@ -173,18 +176,14 @@ class HTTPHandler(object):
|
||||
headers["Content-Type"] = "application/json; charset=utf-8"
|
||||
|
||||
url = self._make_url(endpoint)
|
||||
request = urllib2.Request(url=url, data=data, headers=headers)
|
||||
|
||||
response = requests.post(url, data=data, headers=headers, timeout=timeout_secs,
|
||||
auth=self.auth_handler)
|
||||
response = self.url_opener.open(request, timeout=timeout_secs)
|
||||
headers = response.info()
|
||||
|
||||
response.raise_for_status()
|
||||
content_type = headers.gettype()
|
||||
if content_type == "application/json":
|
||||
encoding = headers.getparam("charset") or "utf-8"
|
||||
return json.load(response, encoding=encoding)
|
||||
|
||||
if not response.encoding:
|
||||
response.encoding = "utf-8"
|
||||
|
||||
headers = response.headers
|
||||
|
||||
if headers["Content-Type"].startswith("application/json"):
|
||||
return response.json()
|
||||
|
||||
return response.text
|
||||
return response.read()
|
||||
|
@ -1,5 +1,4 @@
|
||||
pymongo >= 3.0
|
||||
pypiwin32 == 219 ; sys_platform == "win32"
|
||||
PyYAML == 3.11
|
||||
requests >= 2.0.0
|
||||
subprocess32 >= 3.2.7 ; os_name == "posix" and python_version < "3"
|
||||
|
Loading…
Reference in New Issue
Block a user