mirror of
https://git.launchpad.net/~ubuntu-release/britney/+git/britney2-ubuntu
synced 2025-06-03 22:01:35 +00:00
boottest - Add exception handling for manifest fetching
This commit is contained in:
commit
f9cfb6e49c
@ -79,7 +79,13 @@ class TouchManifest(object):
|
|||||||
"I: [%s] - Fetching manifest from %s" % (
|
"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" % (time.asctime(), self.path))
|
||||||
|
try:
|
||||||
response = urllib.urlopen(url)
|
response = urllib.urlopen(url)
|
||||||
|
except IOError as e:
|
||||||
|
print("W: [%s] - error connecting to %s: %s" % (
|
||||||
|
time.asctime(), self.path, e))
|
||||||
|
return success # failure
|
||||||
|
|
||||||
# Only [re]create the manifest file if one was successfully downloaded
|
# Only [re]create the manifest file if one was successfully downloaded
|
||||||
# this allows for an existing image to be used if the download fails.
|
# this allows for an existing image to be used if the download fails.
|
||||||
if response.code == 200:
|
if response.code == 200:
|
||||||
|
@ -89,6 +89,11 @@ class TestTouchManifest(unittest.TestCase):
|
|||||||
self.assertEqual(1, len(manifest._manifest))
|
self.assertEqual(1, len(manifest._manifest))
|
||||||
self.assertIn('foo', manifest)
|
self.assertIn('foo', manifest)
|
||||||
|
|
||||||
|
def test_fetch_exception(self):
|
||||||
|
self.mocked_urlopen.side_effect = [IOError("connection refused")]
|
||||||
|
manifest = boottest.TouchManifest('not-real', 'not-real')
|
||||||
|
self.assertEqual(0, len(manifest._manifest))
|
||||||
|
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
# Existing manifest file allows callsites to properly check presence.
|
# Existing manifest file allows callsites to properly check presence.
|
||||||
manifest_dir = os.path.join(self.imagesdir, 'ubuntu/vivid')
|
manifest_dir = os.path.join(self.imagesdir, 'ubuntu/vivid')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user