Merge ~ubuntu-release/britney/+git/britney2-ubuntu:wip/httplib2 into ~ubuntu-release/britney/+git/britney2-ubuntu:master

Proposed by Iain Lane
Status: Rejected
Rejected by: Iain Lane
Proposed branch: ~ubuntu-release/britney/+git/britney2-ubuntu:wip/httplib2
Merge into: ~ubuntu-release/britney/+git/britney2-ubuntu:master
Diff against target: 93 lines (+23/-33)
1 file modified
britney2/policies/autopkgtest.py (+23/-33)
Reviewer Review Type Date Requested Status
Iain Lane Disapprove
Review via email: mp+381098@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Iain Lane (laney) wrote :

Nah, I'll make this use requests, stand by!

review: Disapprove

Unmerged commits

acb2bda... by Iain Lane

autopkgtest: Re-use the HTTP connection between requests to swift

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/britney2/policies/autopkgtest.py b/britney2/policies/autopkgtest.py
2index 669d4a9..77ae90f 100644
3--- a/britney2/policies/autopkgtest.py
4+++ b/britney2/policies/autopkgtest.py
5@@ -24,7 +24,7 @@ import io
6 import re
7 import sys
8 import urllib.parse
9-from urllib.request import urlopen
10+import httplib2
11
12 import apt_pkg
13 import amqplib.client_0_8 as amqp
14@@ -84,6 +84,8 @@ class AutopkgtestPolicy(BasePolicy):
15 else:
16 self.results_cache_file = os.path.join(self.test_state_dir, 'results.cache')
17
18+ self.http = httplib2.Http(timeout=30)
19+
20 try:
21 self.options.adt_ppas = self.options.adt_ppas.strip().split()
22 except AttributeError:
23@@ -484,29 +486,22 @@ class AutopkgtestPolicy(BasePolicy):
24 # request new results from swift
25 url = os.path.join(swift_url, self.swift_container)
26 url += '?' + urllib.parse.urlencode(query)
27- try:
28- f = urlopen(url, timeout=30)
29- if f.getcode() == 200:
30- result_paths = f.read().decode().strip().splitlines()
31- elif f.getcode() == 204: # No content
32- result_paths = []
33- else:
34- # we should not ever end up here as we expect a HTTPError in
35- # other cases; e. g. 3XX is something that tells us to adjust
36- # our URLS, so fail hard on those
37- raise NotImplementedError('fetch_swift_results(%s): cannot handle HTTP code %i' %
38- (url, f.getcode()))
39- f.close()
40- except IOError as e:
41+
42+ (resp, content) = self.http.request(url, 'GET')
43+ if resp.status == 200:
44+ result_paths = content.decode().strip().splitlines()
45+ elif resp.status == 204: # No content
46+ result_paths = []
47+ elif resp.status == 401:
48 # 401 "Unauthorized" is swift's way of saying "container does not exist"
49- if hasattr(e, 'code') and e.code == 401:
50- self.log('fetch_swift_results: %s does not exist yet or is inaccessible' % url)
51- return
52+ self.log('fetch_swift_results: %s does not exist yet or is inaccessible' % url)
53+ return
54+ else:
55 # Other status codes are usually a transient
56 # network/infrastructure failure. Ignoring this can lead to
57 # re-requesting tests which we already have results for, so
58 # fail hard on this and let the next run retry.
59- self.log('FATAL: Failure to fetch swift results from %s: %s' % (url, str(e)), 'E')
60+ self.log('FATAL: Failure to fetch swift results from %s: got error code %s' % (url, f.status))
61 sys.exit(1)
62
63 for p in result_paths:
64@@ -520,20 +515,15 @@ class AutopkgtestPolicy(BasePolicy):
65
66 Remove matching pending_tests entries.
67 '''
68- try:
69- f = urlopen(url, timeout=30)
70- if f.getcode() == 200:
71- tar_bytes = io.BytesIO(f.read())
72- f.close()
73- else:
74- raise NotImplementedError('fetch_one_result(%s): cannot handle HTTP code %i' %
75- (url, f.getcode()))
76- except IOError as e:
77- self.log('Failure to fetch %s: %s' % (url, str(e)), 'E')
78- # we tolerate "not found" (something went wrong on uploading the
79- # result), but other things indicate infrastructure problems
80- if hasattr(e, 'code') and e.code == 404:
81- return
82+ (resp, content) = self.http.request(url, 'GET')
83+ if resp.status == 200:
84+ tar_bytes = io.BytesIO(content)
85+ # we tolerate "not found" (something went wrong on uploading the
86+ # result), but other things indicate infrastructure problems
87+ elif resp.status == 404:
88+ return
89+ else:
90+ self.log('Failure to fetch %s: error code %s' % (url, resp.status))
91 sys.exit(1)
92
93 try:

Subscribers

People subscribed via source and target branches