For selection of boottest candidates, use a list of url formats for downloading the appropriate touch image manifest for a given release.

bzr-import-20160707
Francis Ginther 10 years ago
commit 9e238f7406

@ -69,32 +69,43 @@ class TouchManifest(object):
self._manifest = self._load() self._manifest = self._load()
def __fetch_manifest(self, project, series): def __fetch_manifest(self, project, series):
url = "http://cdimage.ubuntu.com/{}/daily-preinstalled/" \ # There are two url formats that may lead to the proper manifest
"pending/{}-preinstalled-touch-armhf.manifest".format( # file. The first form is for series that have been released,
project, series # the second form is for the current development series.
) # Only one of these is expected to exist for any given series.
url_list = [
"http://cdimage.ubuntu.com/{}/{}/daily-preinstalled/pending/" \
"{}-preinstalled-touch-armhf.manifest".format(
project, series, series),
"http://cdimage.ubuntu.com/{}/daily-preinstalled/pending/" \
"{}-preinstalled-touch-armhf.manifest".format(
project, series),
]
success = False success = False
if self.verbose: for url in url_list:
print( if self.verbose:
"I: [%s] - Fetching manifest from %s" % ( print("I: [%s] - Fetching manifest from %s" %
time.asctime(), url)) (time.asctime(), url))
print("I: [%s] - saving it to %s" % (time.asctime(), self.path)) print("I: [%s] - saving it to %s" %
try: (time.asctime(), self.path))
response = urllib.urlopen(url) try:
except IOError as e: response = urllib.urlopen(url)
print("W: [%s] - error connecting to %s: %s" % ( if response.code == 200:
time.asctime(), self.path, e)) # Only [re]create the manifest file if one was successfully
return success # failure # downloaded. This allows for an existing image to be used
# if the download fails.
# Only [re]create the manifest file if one was successfully downloaded path_dir = os.path.dirname(self.path)
# this allows for an existing image to be used if the download fails. if not os.path.exists(path_dir):
if response.code == 200: os.makedirs(path_dir)
path_dir = os.path.dirname(self.path) with open(self.path, 'w') as fp:
if not os.path.exists(path_dir): fp.write(response.read())
os.makedirs(path_dir) success = True
with open(self.path, 'w') as fp: break
fp.write(response.read())
success = True except IOError as e:
print("W: [%s] - error connecting to %s: %s" % (
time.asctime(), self.path, e))
return success return success

@ -49,7 +49,10 @@ class TestTouchManifest(unittest.TestCase):
self.addCleanup(shutil.rmtree, self.path) self.addCleanup(shutil.rmtree, self.path)
_p = mock.patch('urllib.urlopen') _p = mock.patch('urllib.urlopen')
self.mocked_urlopen = _p.start() self.mocked_urlopen = _p.start()
self.mocked_urlopen.side_effect = [FakeResponse(code=404),] self.mocked_urlopen.side_effect = [
FakeResponse(code=404),
FakeResponse(code=404),
]
self.addCleanup(_p.stop) self.addCleanup(_p.stop)
self.fetch_retries_orig = boottest.FETCH_RETRIES self.fetch_retries_orig = boottest.FETCH_RETRIES
def restore_fetch_retries(): def restore_fetch_retries():
@ -90,7 +93,10 @@ class TestTouchManifest(unittest.TestCase):
self.assertIn('foo', manifest) self.assertIn('foo', manifest)
def test_fetch_exception(self): def test_fetch_exception(self):
self.mocked_urlopen.side_effect = [IOError("connection refused")] self.mocked_urlopen.side_effect = [
IOError("connection refused"),
IOError("connection refused"),
]
manifest = boottest.TouchManifest('not-real', 'not-real') manifest = boottest.TouchManifest('not-real', 'not-real')
self.assertEqual(0, len(manifest._manifest)) self.assertEqual(0, len(manifest._manifest))

Loading…
Cancel
Save