Merge ~pitti/autopkgtest-cloud/+git/fixes:master into autopkgtest-cloud:master

Proposed by Martin Pitt
Status: Merged
Merged at revision: 0e11dba8da790617ce033c3131d0972561164f02
Proposed branch: ~pitti/autopkgtest-cloud/+git/fixes:master
Merge into: autopkgtest-cloud:master
Diff against target: 29 lines (+9/-2)
1 file modified
tools/retry-github-test (+9/-2)
Reviewer Review Type Date Requested Status
Iain Lane Approve
Review via email: mp+330743@code.launchpad.net

Description of the change

Fix error messages for retry-github-test. This will turn a relatively useless and verbose

$ retry-gh-systemd-test 6790 fakearch fakerelease
Traceback (most recent call last):
  File "/home/martin/ubuntu/autopkgtest-cloud/tools/retry-github-test", line 32, in <module>
    with urllib.request.urlopen(req) as f:
  File "/usr/lib64/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib64/python3.6/urllib/request.py", line 532, in open
    response = meth(req, response)
  File "/usr/lib64/python3.6/urllib/request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib64/python3.6/urllib/request.py", line 570, in error
    return self._call_chain(*args)
  File "/usr/lib64/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/usr/lib64/python3.6/urllib/request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: BAD REQUEST

into a more useful

$ retry-gh-systemd-test 6790 fakearch fakerelease
Request failed with code 400: BAD REQUEST
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Autopkgtest Test Request</title>
</head>
<body>
<p>You submitted an invalid request: Unknown release fakerelease</p>
</body>
</html>

To post a comment you must log in.
Revision history for this message
Iain Lane (laney) wrote :

Thanks Martin! I've merged it and deployed - feel free to give it a try.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/tools/retry-github-test b/tools/retry-github-test
2index 92f043a..e47ecc2 100755
3--- a/tools/retry-github-test
4+++ b/tools/retry-github-test
5@@ -2,9 +2,11 @@
6 '''Retry a GitHub PR test request to autopkgtest.ubuntu.com'''
7
8 import os
9+import sys
10 import hmac
11 import json
12 import urllib.request
13+import urllib.error
14 import argparse
15
16 p = argparse.ArgumentParser(description='Retry a GitHub PR test request to autopkgtest.ubuntu.com')
17@@ -29,5 +31,10 @@ payload_sig = hmac.new(args.secret_file.read().strip(), payload, 'sha1').hexdige
18 req = urllib.request.Request(args.test_url, data=payload,
19 headers={'X-Hub-Signature': 'sha1=' + payload_sig,
20 'Content-Type': 'application/json'})
21-with urllib.request.urlopen(req) as f:
22- print(f.read().decode())
23+try:
24+ with urllib.request.urlopen(req) as f:
25+ print(f.read().decode())
26+except urllib.error.HTTPError as e:
27+ sys.stderr.write('Request failed with code %i: %s' % (e.code, e.msg))
28+ sys.stderr.write(e.fp.read().decode('UTF-8', 'replace'))
29+ sys.exit(1)

Subscribers

People subscribed via source and target branches