Merge lp:~cprov/snappy-proposed-image-builder/logging-extra into lp:snappy-proposed-image-builder

Proposed by Celso Providelo
Status: Merged
Approved by: Celso Providelo
Approved revision: 14
Merged at revision: 14
Proposed branch: lp:~cprov/snappy-proposed-image-builder/logging-extra
Merge into: lp:snappy-proposed-image-builder
Diff against target: 206 lines (+29/-25)
2 files modified
snappy_proposed_image_builder/__init__.py (+2/-1)
snappy_proposed_image_builder/worker.py (+27/-24)
To merge this branch: bzr merge lp:~cprov/snappy-proposed-image-builder/logging-extra
Reviewer Review Type Date Requested Status
Celso Providelo (community) Approve
Review via email: mp+261893@code.launchpad.net

Commit message

Using ExtraLogger to avoid passing 'extra' when logging and also setting HOME to the temporary dir when calling u-d-f (caches will be purged).

Description of the change

Using ExtraLogger to avoid passing 'extra' when logging and also setting HOME to the temporary dir when calling u-d-f (caches will be purged).

To post a comment you must log in.
Revision history for this message
Celso Providelo (cprov) wrote :

Self approving ...

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snappy_proposed_image_builder/__init__.py'
2--- snappy_proposed_image_builder/__init__.py 2015-05-27 19:13:29 +0000
3+++ snappy_proposed_image_builder/__init__.py 2015-06-13 01:58:46 +0000
4@@ -37,7 +37,8 @@
5
6
7 def read_config():
8- parser = argparse.ArgumentParser(description='Core image builder.')
9+ parser = argparse.ArgumentParser(
10+ description='Snappy-proposed image builder.')
11 parser.add_argument(
12 '-c',
13 '--conf',
14
15=== modified file 'snappy_proposed_image_builder/worker.py'
16--- snappy_proposed_image_builder/worker.py 2015-06-05 21:23:37 +0000
17+++ snappy_proposed_image_builder/worker.py 2015-06-13 01:58:46 +0000
18@@ -25,6 +25,7 @@
19 import tempfile
20
21 from uservice_utils.queue import MessageActions
22+from uservice_utils.logging import ExtraLogger
23
24 from snappy_proposed_image_builder.constants import LOGGING_EXTRA
25 from snappy_proposed_image_builder.cloud import get_glance_client
26@@ -34,6 +35,7 @@
27 )
28
29
30+logging.setLoggerClass(ExtraLogger)
31 logger = logging.getLogger(__name__)
32
33
34@@ -56,6 +58,8 @@
35 def __call__(self, payload):
36 extra = LOGGING_EXTRA.copy()
37 extra.update(payload)
38+ logger.set_extra_args(extra)
39+
40 try:
41 release = payload['release']
42 channel = payload['channel']
43@@ -67,7 +71,6 @@
44 "Unable to deserialize message payload - "
45 "rejecting message: %s",
46 e,
47- extra=extra
48 )
49 return MessageActions.Retry
50
51@@ -79,7 +82,7 @@
52 payload['device_version'] = device_version
53
54 with tempfile.TemporaryDirectory() as tmpdir:
55- logger.info("Beginning rootfs download.", extra=extra)
56+ logger.info("Beginning rootfs download.")
57 try:
58 rootfs_path = download_rootfs(
59 image_version,
60@@ -92,7 +95,6 @@
61 logger.error(
62 "Unable to download core image: %s",
63 e,
64- extra=extra
65 )
66 return MessageActions.Retry
67
68@@ -100,15 +102,17 @@
69 MAX_RETRIES = 3
70 count = MAX_RETRIES
71 while count > 0:
72- new_rootfs_path = add_proposed_packages(rootfs_path,
73- image_binaries,
74- source_version)
75+ new_rootfs_path = add_proposed_packages(
76+ rootfs_path,
77+ image_binaries,
78+ source_version,
79+ )
80 if new_rootfs_path is not None:
81 break
82
83 # try removing the rootfs as it sometimes is corrupted.
84 # XXX: find out why it's getting corrupted.
85- logger.info("Retrying rootfs download.", extra=extra)
86+ logger.info("Retrying rootfs download.")
87 os.remove(rootfs_path)
88 try:
89 rootfs_path = download_rootfs(
90@@ -122,7 +126,6 @@
91 logger.error(
92 "Unable to download core image: %s",
93 e,
94- extra=extra
95 )
96 return MessageActions.Retry
97
98@@ -150,10 +153,9 @@
99 logger.error(
100 "Unable to build the image: %s",
101 e,
102- extra=extra
103 )
104 return MessageActions.Retry
105- logger.info("Ubuntu Core image build OK.", extra=extra)
106+ logger.info("Ubuntu Core image build OK.")
107
108 try:
109 nova_image_path = convert_nova_image(image_path)
110@@ -161,29 +163,27 @@
111 logger.error(
112 "Unable to convert core image to qcow2 image: %s",
113 e,
114- extra=extra)
115+ )
116 return MessageActions.Retry
117- logger.info("Image converted to qcow2 OK.", extra=extra)
118+ logger.info("Image converted to qcow2 OK.")
119
120 try:
121- logger.info("Beginning image upload to glance...",
122- extra=extra)
123+ logger.info("Beginning image upload to glance...")
124 glance_image_id = upload_image_to_glance(
125 nova_image_path,
126- self._config
127+ self._config,
128 )
129 except Exception as e:
130 logger.error(
131 "Unable to upload image to glance: %s",
132 e,
133- extra=extra
134 )
135 return MessageActions.Retry
136- logger.info("Image uploaded to glance OK.", extra=extra)
137+ logger.info("Image uploaded to glance OK.")
138
139 payload['nova_image_id'] = glance_image_id
140 self.publish_results(payload)
141- logger.info("Processing completed.", extra=extra)
142+ logger.info("Processing completed.")
143 return MessageActions.Acknowledge
144
145
146@@ -255,7 +255,6 @@
147
148
149 def add_proposed_packages(rootfs_path, image_binaries, source_version):
150-
151 new_rootfs_path = rootfs_path.replace('.tar.xz', '-modified.tar.xz')
152
153 ROOTFS_BASE_DIR = 'system'
154@@ -367,6 +366,12 @@
155 def build_image(name, rootfs_path, release, channel, device, tmpdir):
156 """Download the ubuntu code image, return a path to it on disk."""
157 image_path = os.path.join(tmpdir, 'snappy-proposed-{}.img'.format(name))
158+ udf_env = {
159+ # u-d-f fills '~/.cache/ubuntuimages/' on downloads,
160+ # not particulary useful to us, unless we only have one
161+ # worker and perform testing retries.
162+ 'HOME': tmpdir,
163+ }
164 cmd = ['sudo',
165 ubuntu_device_flash,
166 '--revision', name,
167@@ -379,7 +384,7 @@
168 '--developer-mode',
169 '--cloud',
170 release]
171- check_call(cmd)
172+ check_call(cmd, env=udf_env)
173
174 cmd = ['sudo',
175 'rm',
176@@ -410,7 +415,6 @@
177 """
178 Upload the nova image to glance, returning the id of the image in glance.
179 """
180- extra = LOGGING_EXTRA.copy()
181 glance = get_glance_client(config)
182 image_name = os.path.basename(nova_image_path)
183 image = glance.images.create(
184@@ -419,13 +423,12 @@
185 disk_format='qcow2',
186 container_format='bare',
187 )
188- logger.info("Uploaded %s with ID %s.", image_name, image.id, extra=extra)
189+ logger.info("Uploaded %s with ID %s.", image_name, image.id)
190 return image.id
191
192
193 def _get_version_string_output(release, channel, device):
194 """Obtains a bytestring of the images info from the core image server"""
195- extra = LOGGING_EXTRA.copy()
196 cmd = [
197 ubuntu_device_flash,
198 'query',
199@@ -437,7 +440,7 @@
200 try:
201 latest_image_info = subprocess.check_output(cmd)
202 except subprocess.CalledProcessError as e:
203- logger.error(e, exc_info=True, extra=extra)
204+ logger.error(e, exc_info=True)
205 finally:
206 return latest_image_info
207

Subscribers

People subscribed via source and target branches