boottest - Add exception handling for manifest fetching

This commit is contained in:
Joe Talbott 2015-02-05 18:17:08 -05:00
commit f9cfb6e49c
2 changed files with 12 additions and 1 deletions

View File

@ -79,7 +79,13 @@ class TouchManifest(object):
"I: [%s] - Fetching manifest from %s" % (
time.asctime(), url))
print("I: [%s] - saving it to %s" % (time.asctime(), self.path))
response = urllib.urlopen(url)
try:
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
# this allows for an existing image to be used if the download fails.
if response.code == 200:

View File

@ -89,6 +89,11 @@ class TestTouchManifest(unittest.TestCase):
self.assertEqual(1, len(manifest._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):
# Existing manifest file allows callsites to properly check presence.
manifest_dir = os.path.join(self.imagesdir, 'ubuntu/vivid')