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
1=== modified file 'Makefile'
2--- Makefile 2015-11-10 17:24:36 +0000
3+++ Makefile 2015-11-10 19:41:00 +0000
4@@ -1,6 +1,8 @@
5 TOP := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
6 CWD := $(shell pwd)
7 PYTHON ?= python3
8+CURTIN_VMTEST_IMAGE_SYNC ?= False
9+export CURTIN_VMTEST_IMAGE_SYNC
10
11 build:
12
13@@ -30,7 +32,7 @@
14
15 # By default don't sync images when running all tests.
16 vmtest:
17- CURTIN_VMTEST_IMAGE_SYNC=False nosetests3 $(noseopts) tests/vmtests
18+ nosetests3 $(noseopts) tests/vmtests
19
20 vmtest-deps:
21 @$(CWD)/tools/vmtest-system-setup
22
23=== modified file 'tests/vmtests/__init__.py'
24--- tests/vmtests/__init__.py 2015-11-10 17:24:36 +0000
25+++ tests/vmtests/__init__.py 2015-11-10 19:41:00 +0000
26@@ -15,12 +15,13 @@
27
28 from .helpers import check_call
29
30-IMAGE_SRC_URL = (
31+IMAGE_SRC_URL = os.environ.get(
32+ 'IMAGE_SRC_URL',
33 "http://maas.ubuntu.com/images/ephemeral-v2/daily/streams/v1/index.sjson")
34+
35 IMAGE_DIR = os.environ.get("IMAGE_DIR", "/srv/images")
36 DEFAULT_SSTREAM_OPTS = [
37- '--max=1',
38- '--keyring=/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg']
39+ '--max=1', '--keyring=/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg']
40 DEFAULT_FILTERS = ['arch=amd64', 'item_name=root-image.gz']
41
42
43@@ -73,7 +74,17 @@
44
45 def sync_images(self, filters=DEFAULT_FILTERS):
46 """Sync MAAS images from source_url simplestreams."""
47- cmd = ['sstream-mirror'] + DEFAULT_SSTREAM_OPTS + [
48+ try:
49+ out = subprocess.check_output(
50+ ['sstream-mirror', '--help'], stderr=subprocess.STDOUT)
51+ if isinstance(out, bytes):
52+ out = out.decode()
53+ if '--progress' in out:
54+ progress = ['--progress']
55+ except subprocess.CalledProcessError:
56+ progress = []
57+
58+ cmd = ['sstream-mirror'] + DEFAULT_SSTREAM_OPTS + progress + [
59 self.source_url, self.base_dir] + filters
60 logger.debug('Syncing images {}'.format(cmd))
61 out = subprocess.check_output(cmd)
62@@ -81,15 +92,14 @@
63
64 def get_image(self, release, arch, filters=None):
65 """Return local path for root image, kernel and initrd."""
66- if not filters:
67- filters = (
68- 'release={release} krel={release} arch={arch}'.format(
69- release=release, arch=arch))
70+ if filters is None:
71+ filters = [
72+ 'release=%s' % release, 'krel=%s' % release, 'arch=%s' % arch]
73 # Query local sstream for compressed root image.
74 logger.debug(
75- 'Query simplestreams for root image: ' + filters)
76+ 'Query simplestreams for root image: %s', filters)
77 cmd = ['sstream-query'] + DEFAULT_SSTREAM_OPTS + [
78- self.url, 'item_name=root-image.gz' ] + filters.split()
79+ self.url, 'item_name=root-image.gz'] + filters
80 logger.debug(" ".join(cmd))
81 out = subprocess.check_output(cmd)
82 logger.debug(out)
83@@ -97,7 +107,7 @@
84 # If there's output, ImageStore.sync decides if images should be
85 # synced or not.
86 if not out or self.sync:
87- self.sync_images(filters=filters.split())
88+ self.sync_images(filters=filters)
89 out = subprocess.check_output(cmd)
90 sstream_data = ast.literal_eval(bytes.decode(out))
91 root_image_gz = urllib.parse.urlsplit(sstream_data['item_url']).path
92@@ -107,7 +117,7 @@
93 with open(root_image_gz, "rb") as fp:
94 checksum = hashlib.sha256(fp.read()).hexdigest()
95 if checksum != sstream_data['sha256']:
96- self.sync_images(filters=filters.split())
97+ self.sync_images(filters=filters)
98 out = subprocess.check_output(cmd)
99 sstream_data = ast.literal_eval(bytes.decode(out))
100 root_image_gz = urllib.parse.urlsplit(
101@@ -119,8 +129,8 @@
102 initrd_path = os.path.join(image_dir, 'root-image-initrd')
103 # Check if we need to unpack things from the compressed image.
104 if (not os.path.exists(root_image_path) or
105- not os.path.exists(kernel_path) or
106- not os.path.exists(initrd_path)):
107+ not os.path.exists(kernel_path) or
108+ not os.path.exists(initrd_path)):
109 self.convert_image(root_image_gz)
110 return (root_image_path, kernel_path, initrd_path)
111
112@@ -171,7 +181,7 @@
113 stdout=DEVNULL, stderr=subprocess.STDOUT)
114
115 def __del__(self):
116- if (os.getenv('CURTIN_VMTEST_KEEP_DATA', "false") != "true"):
117+ if get_env_var_bool('CURTIN_VMTEST_KEEP_DATA', False):
118 # remove tempdir
119 shutil.rmtree(self.tmpdir)
120
121@@ -187,7 +197,7 @@
122 # get boot img
123 image_store = ImageStore(IMAGE_SRC_URL, IMAGE_DIR)
124 # Disable sync if env var is set.
125- if os.getenv('CURTIN_VMTEST_IMAGE_SYNC', False):
126+ if get_env_var_bool('CURTIN_VMTEST_IMAGE_SYNC', False):
127 logger.debug("Images not synced.")
128 image_store.sync = False
129 (boot_img, boot_kernel, boot_initrd) = image_store.get_image(
130@@ -472,3 +482,18 @@
131 logger.debug('Cloud config archive content (pre-json):' + part)
132 parts.append({'content': part, 'type': 'text/x-shellscript'})
133 return '#cloud-config-archive\n' + json.dumps(parts, indent=1)
134+
135+
136+def get_env_var_bool(envname, default=False):
137+ """get a boolean environment variable.
138+
139+ If environment variable is not set, use default.
140+ False values are case insensitive 'false', '0', ''."""
141+ if not isinstance(default, bool):
142+ raise ValueError("default '%s' for '%s' is not a boolean" %
143+ (default, envname))
144+ val = os.environ.get(envname)
145+ if val is None:
146+ return default
147+
148+ return val.lower() not in ("false", "0", "")
149
150=== modified file 'tools/vmtest-system-setup'
151--- tools/vmtest-system-setup 2015-09-21 16:19:01 +0000
152+++ tools/vmtest-system-setup 2015-11-10 19:41:00 +0000
153@@ -5,6 +5,10 @@
154 fail() { [ $# -eq 0 ] || error "$@"; exit 2; }
155
156 rel="$(lsb_release -sc)"
157+case "$(uname -m)" in
158+ i?86|x86_64) qemu="qemu-system-x86";;
159+ ppc*) qemu="qemu-system-ppc";;
160+esac
161 DEPS=(
162 cloud-image-utils
163 make
164@@ -12,6 +16,7 @@
165 python3-nose
166 python3-yaml
167 simplestreams
168+ $qemu
169 ubuntu-cloudimage-keyring
170 )
171

Subscribers

People subscribed via source and target branches

to all changes: