Merge lp:~raharper/curtin/sync-images-convert into lp:~curtin-dev/curtin/trunk

Proposed by Ryan Harper
Status: Merged
Merged at revision: 337
Proposed branch: lp:~raharper/curtin/sync-images-convert
Merge into: lp:~curtin-dev/curtin/trunk
Diff against target: 98 lines (+38/-7)
2 files modified
tests/vmtests/__init__.py (+29/-5)
tools/vmtest-sync-images (+9/-2)
To merge this branch: bzr merge lp:~raharper/curtin/sync-images-convert
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
curtin developers Pending
Review via email: mp+282021@code.launchpad.net

Description of the change

sync-images: auto-convert and prune images

make sync-images will now ensure we invoke convert_image() as needed on each one and we now have a default of 1 image to keep around. This number is controlled by an environment variable, IMAGES_TO_KEEP.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
341. By Ryan Harper

sstream-mirror use IMAGES_TO_KEEP for --max

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
342. By Ryan Harper

convert IMAGES_TO_KEEP to int

343. By Ryan Harper

Only use --max for mirror, query needs max=1

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
344. By Ryan Harper

max can't be in the default or mirror gets it twice

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/vmtests/__init__.py'
2--- tests/vmtests/__init__.py 2015-12-18 20:25:09 +0000
3+++ tests/vmtests/__init__.py 2016-01-08 17:11:34 +0000
4@@ -25,9 +25,15 @@
5 "http://maas.ubuntu.com/images/ephemeral-v2/daily/streams/v1/index.sjson")
6
7 IMAGE_DIR = os.environ.get("IMAGE_DIR", "/srv/images")
8+try:
9+ IMAGES_TO_KEEP = int(os.environ.get("IMAGES_TO_KEEP", 1))
10+except ValueError:
11+ raise ValueError("IMAGES_TO_KEEP in environment was not an integer")
12+
13 DEFAULT_SSTREAM_OPTS = [
14- '--max=1', '--keyring=/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg']
15-DEFAULT_FILTERS = ['arch=amd64', 'item_name=root-image.gz']
16+ '--keyring=/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg']
17+DEFAULT_ARCH = 'amd64'
18+DEFAULT_FILTERS = ['arch=%s' % DEFAULT_ARCH, 'item_name=root-image.gz']
19
20 DEVNULL = open(os.devnull, 'w')
21 KEEP_DATA = {"pass": "none", "fail": "all"}
22@@ -47,6 +53,11 @@
23 pass
24
25
26+def remove_dir(dirpath):
27+ if os.path.exists(dirpath):
28+ shutil.rmtree(dirpath)
29+
30+
31 def _topdir():
32 global _TOPDIR
33 if _TOPDIR:
34@@ -172,12 +183,25 @@
35 # then the real sstream-mirror call below will also fail.
36 pass
37
38- cmd = ['sstream-mirror'] + DEFAULT_SSTREAM_OPTS + progress + [
39- self.source_url, self.base_dir] + filters
40+ cmd = (['sstream-mirror'] + DEFAULT_SSTREAM_OPTS + progress + [
41+ '--max=%s' % IMAGES_TO_KEEP, self.source_url, self.base_dir] +
42+ filters)
43 logger.info('Syncing images {}'.format(cmd))
44 out = subprocess.check_output(cmd)
45 logger.debug(out)
46
47+ def prune_images(self, release, arch, filters=None):
48+ image_dir = os.path.join(self.base_dir, release, arch)
49+ release_dirs = sorted(os.listdir(image_dir))
50+ logger.info('Pruning release={} keep={}'.format(release,
51+ IMAGES_TO_KEEP))
52+ if len(release_dirs) > IMAGES_TO_KEEP:
53+ to_remove = release_dirs[0:-IMAGES_TO_KEEP]
54+ logger.info('Removing {} images'.format(len(to_remove)))
55+ for d in to_remove:
56+ fullpath = os.path.join(image_dir, d)
57+ remove_dir(fullpath)
58+
59 def get_image(self, release, arch, filters=None):
60 """Return local path for root image, kernel and initrd, tarball."""
61 if filters is None:
62@@ -187,7 +211,7 @@
63 logger.info(
64 'Query simplestreams for root image: %s', filters)
65 cmd = ['sstream-query'] + DEFAULT_SSTREAM_OPTS + [
66- self.url, 'item_name=root-image.gz'] + filters
67+ '--max=1', self.url, 'item_name=root-image.gz'] + filters
68 logger.debug(" ".join(cmd))
69 out = subprocess.check_output(cmd)
70 logger.debug(out)
71
72=== modified file 'tools/vmtest-sync-images'
73--- tools/vmtest-sync-images 2015-11-05 19:44:39 +0000
74+++ tools/vmtest-sync-images 2016-01-08 17:11:34 +0000
75@@ -8,14 +8,21 @@
76 sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
77
78 from tests.vmtests import (
79- ImageStore, IMAGE_DIR, IMAGE_SRC_URL, DEFAULT_FILTERS)
80+ ImageStore, IMAGE_DIR, IMAGE_SRC_URL, DEFAULT_FILTERS, DEFAULT_ARCH)
81 from tests.vmtests.helpers import find_releases
82
83
84 if __name__ == '__main__':
85 # Instantiate the ImageStore object.
86 store = ImageStore(IMAGE_SRC_URL, IMAGE_DIR)
87- release_filter = 'release~{}'.format('|'.join(find_releases()))
88+ releases = find_releases()
89+ release_filter = 'release~{}'.format('|'.join(releases))
90 DEFAULT_FILTERS.append(release_filter)
91 # Sync images.
92 store.sync_images(filters=DEFAULT_FILTERS)
93+ # Drop old images and convert new images.
94+ for release in releases:
95+ store.prune_images(release, DEFAULT_ARCH)
96+ store.get_image(release, DEFAULT_ARCH)
97+
98+

Subscribers

People subscribed via source and target branches