Merge lp:~thomir-deactivatedaccount/core-image-publisher/build-cloud-image into lp:core-image-publisher

Proposed by Thomi Richards
Status: Superseded
Proposed branch: lp:~thomir-deactivatedaccount/core-image-publisher/build-cloud-image
Merge into: lp:core-image-publisher
Prerequisite: lp:~pwlars/core-image-publisher/fix-logger
Diff against target: 84 lines (+48/-7)
1 file modified
core_image_publisher/worker.py (+48/-7)
To merge this branch: bzr merge lp:~thomir-deactivatedaccount/core-image-publisher/build-cloud-image
Reviewer Review Type Date Requested Status
Kit Randel (community) code Approve
Celso Providelo (community) Needs Fixing
Review via email: mp+254354@code.launchpad.net

This proposal supersedes a proposal from 2015-03-27.

This proposal has been superseded by a proposal from 2015-03-29.

Commit message

Add support for building and converting the cloud image.

Description of the change

Work in progress to add support for building and converting the cloud image

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote : Posted in a previous version of this proposal

Happy to land once you fix the one note I made in the diff.

Revision history for this message
Celso Providelo (cprov) wrote :

As we discussed on IRC, this code will not work in production until the charm gets extended to grant sudo NOPASSWD powers to the worker user ('core-worker', IRC).

I don't necessarily want to block code changes due to production missing features, but I will only feel comfortable approving this changes if someone is already assigned to do the charm work. Otherwise it will get lost ...

review: Needs Information
Revision history for this message
Para Siva (psivaa) wrote :

One question inline. But that could be postponed for another MP.

Revision history for this message
Celso Providelo (cprov) :
review: Approve
Revision history for this message
Celso Providelo (cprov) wrote :

Actually, u-d-f call needs a tweak (shell=True) and better check if qemu-img call is in the same situation.

review: Needs Fixing
Revision history for this message
Celso Providelo (cprov) wrote :

Thomi,

Ignore my comments about u-d-f calls requiring shell, but double check kombu docs about reject vs. requeue behaviour. I think psivaa is right, according to docs, we should call requeue() not reject().

review: Needs Fixing
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Yeah, I agree - changed them all to requeue() calls instead.

Revision history for this message
Kit Randel (blr) wrote :

Looks fine, although I may be lacking some context. :)

review: Approve (code)
Revision history for this message
Ubuntu CI Bot (uci-bot) wrote :
14. By Thomi Richards

Fix typo.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'core_image_publisher/worker.py'
2--- core_image_publisher/worker.py 2015-03-27 04:47:12 +0000
3+++ core_image_publisher/worker.py 2015-03-29 20:04:52 +0000
4@@ -18,6 +18,9 @@
5 """Business logic or the service lives here."""
6
7 import logging
8+import os
9+import subprocess
10+import tempfile
11 from core_image_publisher.queue import enqueue_message
12
13 logger = logging.getLogger(__name__)
14@@ -36,25 +39,63 @@
15 e,
16 extra=payload
17 )
18- message.reject()
19+ message.requeue()
20 return
21
22- image_path = download_image(image_name, channel, device)
23- nova_image_path = convert_nova_image(image_path)
24- glance_image_name = upload_image_to_glance(nova_image_path)
25+ with tempfile.TemporaryDirectory as tmpdir:
26+ try:
27+ image_path = download_image(image_name, channel, device, tmpdir)
28+ except subprocess.CalledProcessError as e:
29+ logger.error("Unable to download core image: %s", e, extra=payload)
30+ message.requeue()
31+ return
32+ try:
33+ nova_image_path = convert_nova_image(image_path)
34+ except subprocess.CalledProcessError as e:
35+ logger.error("Unable to convert core image to qcow2 image: %s", e,
36+ extra=payload)
37+ message.requeue()
38+ return
39+ glance_image_name = upload_image_to_glance(nova_image_path)
40
41 payload['nova_image'] = glance_image_name
42 enqueue_message(payload)
43 message.ack()
44
45
46-def download_image(name, channel, device):
47+def download_image(name, channel, device, tmpdir):
48 """Download the ubuntu code image, return a path to it on disk."""
49+ image_path = os.path.join(tmpdir, 'core-{}.img'.format(name))
50+ cmd = ['sudo',
51+ 'ubuntu-device-flash',
52+ '--revision', name,
53+ 'core',
54+ '--device' generic_amd64,
55+ '--channel', channel,
56+ '--size', '3',
57+ '-o', image_path,
58+ '--developer-mode',
59+ '--cloud']
60+ subprocess.check_call(cmd)
61+ return image_path
62
63
64 def convert_nova_image(image_path):
65- """Convert a core image to a nova image, return path to the converted image."""
66+ """
67+ Convert a core image to a nova image, return path to the converted image.
68+ """
69+ converted_image_path = '{}-cloud.img'.format(image_path.strip('.img'))
70+ cmd = ['qemu-img',
71+ 'convert',
72+ '-f', 'raw',
73+ '-O', 'qcow2',
74+ image_path,
75+ converted_image_path]
76+ subprocess.check_call(cmd)
77+ return converted_image_path
78
79
80 def upload_image_to_glance(nova_image_path):
81- """Upload the nova image to glance, returning the name of the image in glance."""
82+ """
83+ Upload the nova image to glance, returning the name of the image in glance.
84+ """

Subscribers

People subscribed via source and target branches

to all changes: