mirror of
https://git.launchpad.net/~ubuntu-release/britney/+git/britney2-ubuntu
synced 2025-05-16 13:01:29 +00:00
boottest - Add exception handling for manifest fetching
This commit is contained in:
parent
a729746fa8
commit
87ccbfd731
@ -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))
|
||||||
response = urllib.urlopen(url)
|
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
|
# 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,14 @@ 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_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):
|
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