Merge lp:~smoser/curtin/simplestreams into lp:~matsubara/curtin/simplestreams

Proposed by Scott Moser
Status: Merged
Merged at revision: 290
Proposed branch: lp:~smoser/curtin/simplestreams
Merge into: lp:~matsubara/curtin/simplestreams
Diff against target: 170 lines (+49/-17)
3 files modified
Makefile (+3/-1)
tests/vmtests/__init__.py (+41/-16)
tools/vmtest-system-setup (+5/-0)
To merge this branch: bzr merge lp:~smoser/curtin/simplestreams
Reviewer Review Type Date Requested Status
Diogo Matsubara Approve
Review via email: mp+277173@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

A few cleanups. A few added features.

Revision history for this message
Diogo Matsubara (matsubara) wrote :

Changes looks good to me. Thanks for the patch. I'll incorporate them into my branch.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Makefile'
--- Makefile 2015-11-10 17:24:36 +0000
+++ Makefile 2015-11-10 19:41:00 +0000
@@ -1,6 +1,8 @@
1TOP := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))1TOP := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
2CWD := $(shell pwd)2CWD := $(shell pwd)
3PYTHON ?= python33PYTHON ?= python3
4CURTIN_VMTEST_IMAGE_SYNC ?= False
5export CURTIN_VMTEST_IMAGE_SYNC
46
5build:7build:
68
@@ -30,7 +32,7 @@
3032
31# By default don't sync images when running all tests.33# By default don't sync images when running all tests.
32vmtest:34vmtest:
33 CURTIN_VMTEST_IMAGE_SYNC=False nosetests3 $(noseopts) tests/vmtests35 nosetests3 $(noseopts) tests/vmtests
3436
35vmtest-deps:37vmtest-deps:
36 @$(CWD)/tools/vmtest-system-setup38 @$(CWD)/tools/vmtest-system-setup
3739
=== modified file 'tests/vmtests/__init__.py'
--- tests/vmtests/__init__.py 2015-11-10 17:24:36 +0000
+++ tests/vmtests/__init__.py 2015-11-10 19:41:00 +0000
@@ -15,12 +15,13 @@
1515
16from .helpers import check_call16from .helpers import check_call
1717
18IMAGE_SRC_URL = (18IMAGE_SRC_URL = os.environ.get(
19 'IMAGE_SRC_URL',
19 "http://maas.ubuntu.com/images/ephemeral-v2/daily/streams/v1/index.sjson")20 "http://maas.ubuntu.com/images/ephemeral-v2/daily/streams/v1/index.sjson")
21
20IMAGE_DIR = os.environ.get("IMAGE_DIR", "/srv/images")22IMAGE_DIR = os.environ.get("IMAGE_DIR", "/srv/images")
21DEFAULT_SSTREAM_OPTS = [23DEFAULT_SSTREAM_OPTS = [
22 '--max=1',24 '--max=1', '--keyring=/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg']
23 '--keyring=/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg']
24DEFAULT_FILTERS = ['arch=amd64', 'item_name=root-image.gz']25DEFAULT_FILTERS = ['arch=amd64', 'item_name=root-image.gz']
2526
2627
@@ -73,7 +74,17 @@
7374
74 def sync_images(self, filters=DEFAULT_FILTERS):75 def sync_images(self, filters=DEFAULT_FILTERS):
75 """Sync MAAS images from source_url simplestreams."""76 """Sync MAAS images from source_url simplestreams."""
76 cmd = ['sstream-mirror'] + DEFAULT_SSTREAM_OPTS + [77 try:
78 out = subprocess.check_output(
79 ['sstream-mirror', '--help'], stderr=subprocess.STDOUT)
80 if isinstance(out, bytes):
81 out = out.decode()
82 if '--progress' in out:
83 progress = ['--progress']
84 except subprocess.CalledProcessError:
85 progress = []
86
87 cmd = ['sstream-mirror'] + DEFAULT_SSTREAM_OPTS + progress + [
77 self.source_url, self.base_dir] + filters88 self.source_url, self.base_dir] + filters
78 logger.debug('Syncing images {}'.format(cmd))89 logger.debug('Syncing images {}'.format(cmd))
79 out = subprocess.check_output(cmd)90 out = subprocess.check_output(cmd)
@@ -81,15 +92,14 @@
8192
82 def get_image(self, release, arch, filters=None):93 def get_image(self, release, arch, filters=None):
83 """Return local path for root image, kernel and initrd."""94 """Return local path for root image, kernel and initrd."""
84 if not filters:95 if filters is None:
85 filters = (96 filters = [
86 'release={release} krel={release} arch={arch}'.format(97 'release=%s' % release, 'krel=%s' % release, 'arch=%s' % arch]
87 release=release, arch=arch))
88 # Query local sstream for compressed root image.98 # Query local sstream for compressed root image.
89 logger.debug(99 logger.debug(
90 'Query simplestreams for root image: ' + filters)100 'Query simplestreams for root image: %s', filters)
91 cmd = ['sstream-query'] + DEFAULT_SSTREAM_OPTS + [101 cmd = ['sstream-query'] + DEFAULT_SSTREAM_OPTS + [
92 self.url, 'item_name=root-image.gz' ] + filters.split()102 self.url, 'item_name=root-image.gz'] + filters
93 logger.debug(" ".join(cmd))103 logger.debug(" ".join(cmd))
94 out = subprocess.check_output(cmd)104 out = subprocess.check_output(cmd)
95 logger.debug(out)105 logger.debug(out)
@@ -97,7 +107,7 @@
97 # If there's output, ImageStore.sync decides if images should be107 # If there's output, ImageStore.sync decides if images should be
98 # synced or not.108 # synced or not.
99 if not out or self.sync:109 if not out or self.sync:
100 self.sync_images(filters=filters.split())110 self.sync_images(filters=filters)
101 out = subprocess.check_output(cmd)111 out = subprocess.check_output(cmd)
102 sstream_data = ast.literal_eval(bytes.decode(out))112 sstream_data = ast.literal_eval(bytes.decode(out))
103 root_image_gz = urllib.parse.urlsplit(sstream_data['item_url']).path113 root_image_gz = urllib.parse.urlsplit(sstream_data['item_url']).path
@@ -107,7 +117,7 @@
107 with open(root_image_gz, "rb") as fp:117 with open(root_image_gz, "rb") as fp:
108 checksum = hashlib.sha256(fp.read()).hexdigest()118 checksum = hashlib.sha256(fp.read()).hexdigest()
109 if checksum != sstream_data['sha256']:119 if checksum != sstream_data['sha256']:
110 self.sync_images(filters=filters.split())120 self.sync_images(filters=filters)
111 out = subprocess.check_output(cmd)121 out = subprocess.check_output(cmd)
112 sstream_data = ast.literal_eval(bytes.decode(out))122 sstream_data = ast.literal_eval(bytes.decode(out))
113 root_image_gz = urllib.parse.urlsplit(123 root_image_gz = urllib.parse.urlsplit(
@@ -119,8 +129,8 @@
119 initrd_path = os.path.join(image_dir, 'root-image-initrd')129 initrd_path = os.path.join(image_dir, 'root-image-initrd')
120 # Check if we need to unpack things from the compressed image.130 # Check if we need to unpack things from the compressed image.
121 if (not os.path.exists(root_image_path) or131 if (not os.path.exists(root_image_path) or
122 not os.path.exists(kernel_path) or132 not os.path.exists(kernel_path) or
123 not os.path.exists(initrd_path)):133 not os.path.exists(initrd_path)):
124 self.convert_image(root_image_gz)134 self.convert_image(root_image_gz)
125 return (root_image_path, kernel_path, initrd_path)135 return (root_image_path, kernel_path, initrd_path)
126136
@@ -171,7 +181,7 @@
171 stdout=DEVNULL, stderr=subprocess.STDOUT)181 stdout=DEVNULL, stderr=subprocess.STDOUT)
172182
173 def __del__(self):183 def __del__(self):
174 if (os.getenv('CURTIN_VMTEST_KEEP_DATA', "false") != "true"):184 if get_env_var_bool('CURTIN_VMTEST_KEEP_DATA', False):
175 # remove tempdir185 # remove tempdir
176 shutil.rmtree(self.tmpdir)186 shutil.rmtree(self.tmpdir)
177187
@@ -187,7 +197,7 @@
187 # get boot img197 # get boot img
188 image_store = ImageStore(IMAGE_SRC_URL, IMAGE_DIR)198 image_store = ImageStore(IMAGE_SRC_URL, IMAGE_DIR)
189 # Disable sync if env var is set.199 # Disable sync if env var is set.
190 if os.getenv('CURTIN_VMTEST_IMAGE_SYNC', False):200 if get_env_var_bool('CURTIN_VMTEST_IMAGE_SYNC', False):
191 logger.debug("Images not synced.")201 logger.debug("Images not synced.")
192 image_store.sync = False202 image_store.sync = False
193 (boot_img, boot_kernel, boot_initrd) = image_store.get_image(203 (boot_img, boot_kernel, boot_initrd) = image_store.get_image(
@@ -472,3 +482,18 @@
472 logger.debug('Cloud config archive content (pre-json):' + part)482 logger.debug('Cloud config archive content (pre-json):' + part)
473 parts.append({'content': part, 'type': 'text/x-shellscript'})483 parts.append({'content': part, 'type': 'text/x-shellscript'})
474 return '#cloud-config-archive\n' + json.dumps(parts, indent=1)484 return '#cloud-config-archive\n' + json.dumps(parts, indent=1)
485
486
487def get_env_var_bool(envname, default=False):
488 """get a boolean environment variable.
489
490 If environment variable is not set, use default.
491 False values are case insensitive 'false', '0', ''."""
492 if not isinstance(default, bool):
493 raise ValueError("default '%s' for '%s' is not a boolean" %
494 (default, envname))
495 val = os.environ.get(envname)
496 if val is None:
497 return default
498
499 return val.lower() not in ("false", "0", "")
475500
=== modified file 'tools/vmtest-system-setup'
--- tools/vmtest-system-setup 2015-09-21 16:19:01 +0000
+++ tools/vmtest-system-setup 2015-11-10 19:41:00 +0000
@@ -5,6 +5,10 @@
5fail() { [ $# -eq 0 ] || error "$@"; exit 2; }5fail() { [ $# -eq 0 ] || error "$@"; exit 2; }
66
7rel="$(lsb_release -sc)"7rel="$(lsb_release -sc)"
8case "$(uname -m)" in
9 i?86|x86_64) qemu="qemu-system-x86";;
10 ppc*) qemu="qemu-system-ppc";;
11esac
8DEPS=(12DEPS=(
9 cloud-image-utils13 cloud-image-utils
10 make14 make
@@ -12,6 +16,7 @@
12 python3-nose16 python3-nose
13 python3-yaml17 python3-yaml
14 simplestreams18 simplestreams
19 $qemu
15 ubuntu-cloudimage-keyring20 ubuntu-cloudimage-keyring
16)21)
1722

Subscribers

People subscribed via source and target branches

to all changes: