boottest - Fetch manifests dynamically but use cached manifests if the fetch fails

bzr-import-20160707
Joe Talbott 10 years ago
parent c340a46e7a
commit 2e5084ee79

@ -12,6 +12,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
import os import os
import urllib
from consts import BINARIES from consts import BINARIES
@ -36,9 +37,25 @@ class TouchManifest(object):
""" """
def __fetch_manifest(self, distribution, series):
url = "http://cdimage.ubuntu.com/{}/daily-preinstalled/" \
"pending/{}-preinstalled-touch-armhf.manifest".format(
distribution, series
)
response = urllib.urlopen(url)
# 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:
os.makedirs(os.path.dirname(self.path))
with open(self.path, 'w') as fp:
fp.write(response.read())
def __init__(self, distribution, series): def __init__(self, distribution, series):
self.path = 'boottest/images/{}/{}/manifest'.format( self.path = "boottest/images/{}/{}/manifest".format(
distribution, series) distribution, series)
self.__fetch_manifest(distribution, series)
self._manifest = self._load() self._manifest = self._load()
def _load(self): def _load(self):
@ -49,6 +66,9 @@ class TouchManifest(object):
with open(self.path) as fd: with open(self.path) as fd:
for line in fd.readlines(): for line in fd.readlines():
# skip headers and metadata
if 'DOCTYPE' in line:
continue
name, version = line.split() name, version = line.split()
name = name.split(':')[0] name = name.split(':')[0]
if name == 'click': if name == 'click':

@ -46,6 +46,23 @@ class TestTouchManifest(unittest.TestCase):
self.assertEqual([], manifest._manifest) self.assertEqual([], manifest._manifest)
self.assertNotIn('foo', manifest) self.assertNotIn('foo', manifest)
def test_fetch(self):
# Missing manifest file is fetched dynamically
manifest = TouchManifest('ubuntu-touch', 'vivid')
self.assertNotEqual([], manifest._manifest)
def test_fetch_fails(self):
distribution = 'fake'
series = 'fake'
manifest_dir = os.path.join(self.imagesdir, distribution, series)
manifest_lines = [
'foo:armhf 1~beta1',
]
create_manifest(manifest_dir, manifest_lines)
manifest = TouchManifest(distribution, series)
self.assertEqual(1, len(manifest._manifest))
self.assertIn('foo', 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…
Cancel
Save