boottest - Add exception handling for manifest fetching

bzr-import-20160707
Joe Talbott 10 years ago
parent a729746fa8
commit 87ccbfd731

@ -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))
try:
response = urllib.urlopen(url)
except IOError as e:
print("W: [%s] - error connecting to %s" % (
time.asctime(), self.path))
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:

@ -89,6 +89,14 @@ class TestTouchManifest(unittest.TestCase):
self.assertEqual(1, len(manifest._manifest))
self.assertIn('foo', manifest)
def test_fetch_excpetion(self):
_p = mock.patch('urllib.urlopen')
mocked_urlopen = _p.start()
self.addCleanup(_p.stop)
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')

Loading…
Cancel
Save