Merge ~alexmurray/ubuntu-security-tools:umt-adt-better-url-handling into ubuntu-security-tools:master

Proposed by Alex Murray
Status: Merged
Merged at revision: d31813815c08775eb05487c4331f44d18bf51b7e
Proposed branch: ~alexmurray/ubuntu-security-tools:umt-adt-better-url-handling
Merge into: ubuntu-security-tools:master
Diff against target: 103 lines (+40/-33)
1 file modified
build-tools/umt (+40/-33)
Reviewer Review Type Date Requested Status
Steve Beattie Approve
Review via email: mp+407942@code.launchpad.net

Description of the change

Make the use of umt adt a bit easier as recommended by sbeattie.

To post a comment you must log in.
Revision history for this message
Alex Murray (alexmurray) wrote :

Rebased this ontop of a recent change by sbeattie in the same vein, plus a minor change to make the code more pythonic as well... any reviews would be great :)

Revision history for this message
Steve Beattie (sbeattie) wrote :

LGTM, and limited testing worked fine.

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/build-tools/umt b/build-tools/umt
2index 4ae47e4..40b5250 100755
3--- a/build-tools/umt
4+++ b/build-tools/umt
5@@ -1913,7 +1913,7 @@ def check_adt_results(excuses, package, version, html=False, only_regressions=Fa
6 else:
7 success(result_msg)
8 else:
9- err("No excuses data found for %s %s" % (package, version))
10+ raise ValueError("No excuses data found for %s %s" % (package, version))
11
12
13 # Usage, e.g: umt adt --only-regressions --html - shows only those had
14@@ -1943,50 +1943,57 @@ def cmd_adt():
15 parser.add_argument("--html", default=False, action='store_true',
16 help="saves a html output to ../adt and open it in a browser")
17 parser.add_argument("--url", default=None,
18- help="Specify the URL to the update_excuses.yaml to use. %%s can be used as a placeholder for the release name.")
19+ help="Specify the URL to the update_excuses.yaml to use or 'security-proposed' / 'ubuntu' as shorthard for the security-proposed PPA and the ubuntu archive respectively. %%s can be used as a placeholder for the release name. e.g. --url 'http://security-britney.internal/current/security_%%s_excuses.yaml'.")
20
21 (opt, args) = parser.parse_known_args()
22
23 # validate we know what PPA is
24 if release and release in valid_releases:
25+ urls = []
26 if opt.url is None:
27 # pick the first upload file
28 upload_files = glob.glob('./../source/*.upload')
29 if len(upload_files) == 0:
30- err("No upload file found. Please upload first to generate adt results or specify --url manually.")
31- sys.exit(1)
32- upload = parse_upload_file(upload_files[0])
33- ppa = list(upload['upload'].keys())[0]
34- if ppa not in adt_urls:
35- err("unable to map PPA %s to a known location for autopkgtest results." % ppa)
36- err("please specify the update_excuses URL manually via the --url argument.")
37- sys.exit(1)
38- excuses_url = adt_urls[ppa] % release
39+ warn("no upload file found.")
40+ else:
41+ upload = parse_upload_file(upload_files[0])
42+ ppa = list(upload['upload'].keys())[0]
43+ if ppa not in adt_urls:
44+ warn("unable to map upload destination '%s' to a known location for autopkgtest results." % ppa)
45+ else:
46+ urls = [adt_urls[ppa] % release]
47 else:
48 if opt.url in adt_urls:
49- excuses_url = adt_urls[opt.url] % release
50- elif "%s" in opt.url:
51- excuses_url = opt.url % release
52+ urls = [adt_urls[opt.url] % release]
53 else:
54- excuses_url = opt.url
55- prepare_dir(adt_dest, True)
56-
57- print("Getting {0} ...".format(excuses_url))
58- req = requests.get(excuses_url)
59- if not req.status_code == 200:
60- err("failed to get the excuses yaml page: %s" % req.url)
61- req.raise_for_status()
62- sys.exit(1)
63-
64- # handle decoding zstd compressed excuses
65- if excuses_url.endswith('xz'):
66- excuses_yaml = subprocess.check_output(["/usr/bin/xz", "-d", "-"],
67- input=req.content)
68- else:
69- excuses_yaml = req.content.decode()
70- excuses = yaml.safe_load(excuses_yaml)
71- check_adt_results(excuses, details["package"], details["version"],
72- opt.html, opt.only_regressions, opt.verbose)
73+ urls = [opt.url % release]
74+ # default to looking in all known locations
75+ if len(urls) == 0:
76+ warn("trying all known excuses...")
77+ urls = map(lambda s: s % release, adt_urls.values())
78+ for url in urls:
79+ prepare_dir(adt_dest, True)
80+
81+ print("Getting {0} ...".format(url))
82+ req = requests.get(url)
83+ if not req.status_code == 200:
84+ err("failed to get the excuses yaml page: %s" % req.url)
85+ # try next URL in the list
86+ continue
87+
88+ # handle decoding zstd compressed excuses
89+ if url.endswith('xz'):
90+ excuses_yaml = subprocess.check_output(["/usr/bin/xz", "-d", "-"],
91+ input=req.content)
92+ else:
93+ excuses_yaml = req.content.decode()
94+ excuses = yaml.safe_load(excuses_yaml)
95+ try:
96+ check_adt_results(excuses, details["package"], details["version"],
97+ opt.html, opt.only_regressions, opt.verbose)
98+ except ValueError as e:
99+ err(str(e))
100+ continue
101
102 else:
103 err("Not a valid release")

Subscribers

People subscribed via source and target branches