Merge lp:~fginther/britney/add-vivid-manifest into lp:~canonical-ci-engineering/britney/enable-vivid-boottest

Proposed by Francis Ginther
Status: Merged
Approved by: Francis Ginther
Approved revision: 436
Merged at revision: 435
Proposed branch: lp:~fginther/britney/add-vivid-manifest
Merge into: lp:~canonical-ci-engineering/britney/enable-vivid-boottest
Diff against target: 98 lines (+43/-26)
2 files modified
boottest.py (+35/-24)
tests/test_boottest.py (+8/-2)
To merge this branch: bzr merge lp:~fginther/britney/add-vivid-manifest
Reviewer Review Type Date Requested Status
Celso Providelo (community) Approve
Review via email: mp+261212@code.launchpad.net

Commit message

Use a list of url formats for downloading the appropriate touch image manifest for a given release.

Description of the change

Use a list of url formats for downloading the appropriate touch image manifest for a given release.

To post a comment you must log in.
436. By Francis Ginther

Refactor the __fetch_manifest() code so that the a successful response is immediately handled and we don't end up with an undefined 'response' on an exception. Also update the tests to return two mocked reponses to match the size of the url_list.

Revision history for this message
Celso Providelo (cprov) wrote :

Francis,

Looks good, whichever URL exists will update manifest, if they both fail the manifest on disk will remain intact.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'boottest.py'
2--- boottest.py 2015-02-11 14:45:20 +0000
3+++ boottest.py 2015-06-05 16:09:01 +0000
4@@ -69,32 +69,43 @@
5 self._manifest = self._load()
6
7 def __fetch_manifest(self, project, series):
8- url = "http://cdimage.ubuntu.com/{}/daily-preinstalled/" \
9- "pending/{}-preinstalled-touch-armhf.manifest".format(
10- project, series
11- )
12+ # There are two url formats that may lead to the proper manifest
13+ # file. The first form is for series that have been released,
14+ # the second form is for the current development series.
15+ # Only one of these is expected to exist for any given series.
16+ url_list = [
17+ "http://cdimage.ubuntu.com/{}/{}/daily-preinstalled/pending/" \
18+ "{}-preinstalled-touch-armhf.manifest".format(
19+ project, series, series),
20+ "http://cdimage.ubuntu.com/{}/daily-preinstalled/pending/" \
21+ "{}-preinstalled-touch-armhf.manifest".format(
22+ project, series),
23+ ]
24+
25 success = False
26- if self.verbose:
27- print(
28- "I: [%s] - Fetching manifest from %s" % (
29- time.asctime(), url))
30- print("I: [%s] - saving it to %s" % (time.asctime(), self.path))
31- try:
32- response = urllib.urlopen(url)
33- except IOError as e:
34- print("W: [%s] - error connecting to %s: %s" % (
35- time.asctime(), self.path, e))
36- return success # failure
37+ for url in url_list:
38+ if self.verbose:
39+ print("I: [%s] - Fetching manifest from %s" %
40+ (time.asctime(), url))
41+ print("I: [%s] - saving it to %s" %
42+ (time.asctime(), self.path))
43+ try:
44+ response = urllib.urlopen(url)
45+ if response.code == 200:
46+ # Only [re]create the manifest file if one was successfully
47+ # downloaded. This allows for an existing image to be used
48+ # if the download fails.
49+ path_dir = os.path.dirname(self.path)
50+ if not os.path.exists(path_dir):
51+ os.makedirs(path_dir)
52+ with open(self.path, 'w') as fp:
53+ fp.write(response.read())
54+ success = True
55+ break
56
57- # Only [re]create the manifest file if one was successfully downloaded
58- # this allows for an existing image to be used if the download fails.
59- if response.code == 200:
60- path_dir = os.path.dirname(self.path)
61- if not os.path.exists(path_dir):
62- os.makedirs(path_dir)
63- with open(self.path, 'w') as fp:
64- fp.write(response.read())
65- success = True
66+ except IOError as e:
67+ print("W: [%s] - error connecting to %s: %s" % (
68+ time.asctime(), self.path, e))
69
70 return success
71
72
73=== modified file 'tests/test_boottest.py'
74--- tests/test_boottest.py 2015-02-20 16:28:47 +0000
75+++ tests/test_boottest.py 2015-06-05 16:09:01 +0000
76@@ -49,7 +49,10 @@
77 self.addCleanup(shutil.rmtree, self.path)
78 _p = mock.patch('urllib.urlopen')
79 self.mocked_urlopen = _p.start()
80- self.mocked_urlopen.side_effect = [FakeResponse(code=404),]
81+ self.mocked_urlopen.side_effect = [
82+ FakeResponse(code=404),
83+ FakeResponse(code=404),
84+ ]
85 self.addCleanup(_p.stop)
86 self.fetch_retries_orig = boottest.FETCH_RETRIES
87 def restore_fetch_retries():
88@@ -90,7 +93,10 @@
89 self.assertIn('foo', manifest)
90
91 def test_fetch_exception(self):
92- self.mocked_urlopen.side_effect = [IOError("connection refused")]
93+ self.mocked_urlopen.side_effect = [
94+ IOError("connection refused"),
95+ IOError("connection refused"),
96+ ]
97 manifest = boottest.TouchManifest('not-real', 'not-real')
98 self.assertEqual(0, len(manifest._manifest))
99

Subscribers

People subscribed via source and target branches