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

Proposed by Thomi Richards
Status: Merged
Approved by: Thomi Richards
Approved revision: 14
Merged at revision: 12
Proposed branch: lp:~thomir-deactivatedaccount/core-image-publisher/build-cloud-image
Merge into: lp:core-image-publisher
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
Thomi Richards (community) Approve
Celso Providelo Pending
Kit Randel code Pending
Review via email: mp+254512@code.launchpad.net

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

Commit message

Work in progress to 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 : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal

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

Revision history for this message
Celso Providelo (cprov) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Celso Providelo (cprov) wrote : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal

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

Revision history for this message
Kit Randel (blr) wrote : Posted in a previous version of this proposal

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

review: Approve (code)
Revision history for this message
Ubuntu CI Bot (uci-bot) wrote : Posted in a previous version of this proposal
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) :
review: Approve
Revision history for this message
Ubuntu CI Bot (uci-bot) wrote :
Download full text (6.6 KiB)

The attempt to merge lp:~thomir/core-image-publisher/build-cloud-image into lp:core-image-publisher failed. Below is the output from the failed tests.

Using base prefix '/usr'
New python executable in /tmp/venv-core-image-publisherjgiynnkc/bin/python3
Also creating executable in /tmp/venv-core-image-publisherjgiynnkc/bin/python
Installing setuptools, pip...done.
Running virtualenv with interpreter /usr/bin/python3
Ignoring indexes: https://pypi.python.org/simple/
Downloading/unpacking kombu==3.0.24 (from -r requirements.txt (line 1))
Downloading/unpacking python-logstash==0.4.2 (from -r requirements.txt (line 2))
  Running setup.py (path:/tmp/venv-core-image-publisherjgiynnkc/build/python-logstash/setup.py) egg_info for package python-logstash

Downloading/unpacking anyjson>=0.3.3 (from kombu==3.0.24->-r requirements.txt (line 1))
  Running setup.py (path:/tmp/venv-core-image-publisherjgiynnkc/build/anyjson/setup.py) egg_info for package anyjson

Downloading/unpacking amqp>=1.4.5,<2.0 (from kombu==3.0.24->-r requirements.txt (line 1))
  Running setup.py (path:/tmp/venv-core-image-publisherjgiynnkc/build/amqp/setup.py) egg_info for package amqp

Installing collected packages: kombu, python-logstash, anyjson, amqp
  Running setup.py install for python-logstash

  Running setup.py install for anyjson
    Fixing build/lib/anyjson/__init__.py
    Skipping implicit fixer: buffer
    Skipping implicit fixer: idioms
    Skipping implicit fixer: set_literal
    Skipping implicit fixer: ws_comma
    Fixing build/lib/anyjson/__init__.py
    Skipping implicit fixer: buffer
    Skipping implicit fixer: idioms
    Skipping implicit fixer: set_literal
    Skipping implicit fixer: ws_comma

  Running setup.py install for amqp

Successfully installed kombu python-logstash anyjson amqp
Cleaning up...
Downloading/unpacking testtools==1.7.1 (from -r test_requirements.txt (line 1))
Downloading/unpacking python-mimeparse (from testtools==1.7.1->-r test_requirements.txt (line 1))
  Downloading python-mimeparse-0.1.4.tar.gz
  Running setup.py (path:/tmp/venv-core-image-publisherjgiynnkc/build/python-mimeparse/setup.py) egg_info for package python-mimeparse

Downloading/unpacking traceback2 (from testtools==1.7.1->-r test_requirements.txt (line 1))
  Downloading traceback2-1.4.0-py2.py3-none-any.whl
Downloading/unpacking unittest2>=1.0.0 (from testtools==1.7.1->-r test_requirements.txt (line 1))
Downloading/unpacking extras (from testtools==1.7.1->-r test_requirements.txt (line 1))
  Downloading extras-0.0.3.tar.gz
  Running setup.py (path:/tmp/venv-core-image-publisherjgiynnkc/build/extras/setup.py) egg_info for package extras

Downloading/unpacking linecache2 (from traceback2->testtools==1.7.1->-r test_requirements.txt (line 1))
  Downloading linecache2-1.0.0-py2.py3-none-any.whl
Downloading/unpacking six>=1.4 (from unittest2>=1.0.0->testtools==1.7.1->-r test_requirements.txt (line 1))
  Downloading six-1.9.0-py2.py3-none-any.whl
Downloading/unpacking argparse (from unittest2>=1.0.0->testtools==1.7.1->-r test_requirements.txt (line 1))
  Downloading argparse-1.3.0-py2.py3-none-any.whl
Installing collected packages: testtools, python...

Read more...

14. By Thomi Richards

Fix typo.

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 21:10:35 +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: