Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[browserperfdash-benchmark] Fix error logging from server after 251530@main #1989

Merged
merged 1 commit into from Jul 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -103,6 +103,15 @@ def _get_test_data_json_string(self, temp_result_file):
del temp_result_json['debugOutput']
return json.dumps(temp_result_json)

# urllib.request.urlopen always raises an exception when the http return code is not 200
# so this wraps the call to return the HTTPError object instead of raising the exception.
# The HTTPError object can be treated later as a http.client.HTTPResponse object.
def _send_post_request_data(self, post_url, post_data):
try:
return urllib.request.urlopen(post_url, post_data)
except urllib.error.HTTPError as e:
return e

def _upload_result(self):
upload_failed = False
for server in self._config_parser.sections():
Expand All @@ -111,14 +120,14 @@ def _upload_result(self):
post_data = urllib.parse.urlencode(self._result_data).encode('utf-8')
post_url = self._config_parser.get(server, 'post_url')
try:
post_request = urllib.request.urlopen(post_url, post_data)
post_request = self._send_post_request_data(post_url, post_data)
if post_request.getcode() == 200:
_log.info('Sucesfully uploaded results to server {server_name} for test {test_name} and browser {browser_name} version {browser_version}'.format(
server_name=server, test_name=self._result_data['test_id'], browser_name=self._result_data['browser_id'], browser_version=self._result_data['browser_version']))
else:
upload_failed = True
_log.error('The server {server_name} returned an error code: {http_error}'.format(server_name=server, http_error=post_request.getcode()))
_log.error('The error text from the server {server_name} was: "{error_text}"'.format(server_name=server, error_text=post_request.read()))
_log.error('The error text from the server {server_name} was: "{error_text}"'.format(server_name=server, error_text=post_request.read().decode('utf-8')))
except Exception as e:
upload_failed = True
_log.error('Exception while trying to upload results to server {server_name}'.format(server_name=server))
Expand Down