Merge ~xnox/snappy-device-agents:compress-file-qcow2 into snappy-device-agents:master

Proposed by Dimitri John Ledkov
Status: Merged
Approved by: Chris Wayne
Approved revision: 6eee7c578ffc41c4e6325d8b7a8ed59677d00a3c
Merged at revision: 42bf53de34058c7c0b642c9c1ae5d1d2a4ba2c8b
Proposed branch: ~xnox/snappy-device-agents:compress-file-qcow2
Merge into: snappy-device-agents:master
Diff against target: 62 lines (+24/-2)
2 files modified
devices/muxpi/muxpi.py (+4/-1)
snappy_device_agents/__init__.py (+20/-1)
Reviewer Review Type Date Requested Status
Devices Certification Bot Needs Fixing
Paul Larson Approve
Review via email: mp+394647@code.launchpad.net

Commit message

compress_file: add support for QCOW2

This will allow deploying ubuntu-cpc QCOW2 cloud-images directly onto HiFive boards.

To post a comment you must log in.
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

qemu-utils package must be install where compress_file is executed.

Revision history for this message
Paul Larson (pwlars) wrote :

This seems to work ok after installing qemu-utils, thanks! However, I did try one of those images, and while it does seem to put the image on the sd card and boot it, it doesn't look like any network interface is detected other than loopback, so it never really finishes confirming that it's provisioned.

review: Approve
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

@pwlars Horay!

The lack of internets on that image is being fixed. It will need a new kernel upload.

The fact that it sort of, kind of, attempted to boot is perfect at this point!

Please land this if possible.

Revision history for this message
Dimitri John Ledkov (xnox) wrote :
Revision history for this message
Devices Certification Bot (ce-certification-qa) wrote :

The merge was fine but running tests failed.

Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /tmp/tmpgwmnM1/env/bin/python3
Also creating executable in /tmp/tmpgwmnM1/env/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
Collecting flake8==2.4.0
  Using cached flake8-2.4.0-py2.py3-none-any.whl (28 kB)
Collecting mccabe<0.4,>=0.2.1
  Using cached mccabe-0.3.1-py2.py3-none-any.whl (7.6 kB)
Collecting pep8<1.6,>=1.5.7
  Using cached pep8-1.5.7-py2.py3-none-any.whl (37 kB)
Collecting pyflakes<0.9,>=0.8.1
  Using cached pyflakes-0.8.1-py2.py3-none-any.whl (35 kB)
Installing collected packages: pyflakes, pep8, mccabe, flake8
Successfully installed flake8-2.4.0 mccabe-0.3.1 pep8-1.5.7 pyflakes-0.8.1
running flake8
snappy_device_agents/__init__.py:282:13: F841 local variable 'output' is assigned to but never used

review: Needs Fixing
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

fixed up.

Revision history for this message
Devices Certification Bot (ce-certification-qa) wrote :

The merge was fine but running tests failed.

Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /tmp/tmp168yxu/env/bin/python3
Also creating executable in /tmp/tmp168yxu/env/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
Collecting flake8==2.4.0
  Using cached flake8-2.4.0-py2.py3-none-any.whl (28 kB)
Collecting mccabe<0.4,>=0.2.1
  Using cached mccabe-0.3.1-py2.py3-none-any.whl (7.6 kB)
Collecting pep8<1.6,>=1.5.7
  Using cached pep8-1.5.7-py2.py3-none-any.whl (37 kB)
Collecting pyflakes<0.9,>=0.8.1
  Using cached pyflakes-0.8.1-py2.py3-none-any.whl (35 kB)
Installing collected packages: pyflakes, pep8, mccabe, flake8
Successfully installed flake8-2.4.0 mccabe-0.3.1 pep8-1.5.7 pyflakes-0.8.1
running flake8
snappy_device_agents/__init__.py:282:13: F841 local variable '_' is assigned to but never used

review: Needs Fixing
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

fixed up again.....

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/devices/muxpi/muxpi.py b/devices/muxpi/muxpi.py
2index a8ee667..5cf49f1 100644
3--- a/devices/muxpi/muxpi.py
4+++ b/devices/muxpi/muxpi.py
5@@ -39,7 +39,8 @@ class MuxPi:
6 IMAGE_PATH_IDS = {'writable/usr/bin/firefox': 'pi-desktop',
7 'writable/etc': 'ubuntu',
8 'writable/system-data': 'core',
9- 'ubuntu-seed/snaps': 'core20'}
10+ 'ubuntu-seed/snaps': 'core20',
11+ 'cloudimg-rootfs/etc/cloud/cloud.cfg': 'ubuntu-cpc'}
12
13 def __init__(self, config, job_data):
14 with open(config) as configfile:
15@@ -328,6 +329,8 @@ class MuxPi:
16 base = os.path.join(self.mount_point, 'writable')
17 if image_type == 'core':
18 base = os.path.join(base, 'system-data')
19+ if image_type == 'ubuntu-cpc':
20+ base = os.path.join(self.mount_point, 'cloudimg-rootfs')
21 ci_path = os.path.join(base, 'var/lib/cloud/seed/nocloud-net')
22 self._run_control('sudo mkdir -p {}'.format(ci_path))
23 write_cmd = "sudo bash -c \"echo '{}' > /{}/{}\""
24diff --git a/snappy_device_agents/__init__.py b/snappy_device_agents/__init__.py
25index 0455ccb..36844f7 100644
26--- a/snappy_device_agents/__init__.py
27+++ b/snappy_device_agents/__init__.py
28@@ -55,7 +55,9 @@ def filetype(filename):
29 magic_headers = {
30 b"\x1f\x8b\x08": "gz",
31 b"\x42\x5a\x68": "bz2",
32- b"\xfd\x37\x7a\x58\x5a\x00": "xz"}
33+ b"\xfd\x37\x7a\x58\x5a\x00": "xz",
34+ b"\x51\x46\x49\xfb": "qcow2",
35+ }
36 with open(filename, 'rb') as f:
37 filehead = f.read(1024)
38 filetype = "unknown"
39@@ -268,6 +270,23 @@ def compress_file(filename):
40 with lzma.open(compressed_filename, 'wb') as compressed_image:
41 with bz2.BZ2File(filename, 'rb') as old_compressed:
42 shutil.copyfileobj(old_compressed, compressed_image)
43+ elif filetype(filename) == 'qcow2':
44+ raw_filename = '{}.raw'.format(filename)
45+ try:
46+ # Remove the original file, unless we already did
47+ os.unlink(raw_filename)
48+ except FileNotFoundError:
49+ pass
50+ cmd = ['qemu-img', 'convert', '-O', 'raw', filename, raw_filename]
51+ try:
52+ subprocess.check_output(cmd, stderr=subprocess.STDOUT)
53+ except subprocess.CalledProcessError as e:
54+ logger.error('Image Conversion Output:\n %s', e.output)
55+ raise
56+ with open(raw_filename, 'rb') as uncompressed_image:
57+ with lzma.open(compressed_filename, 'wb') as compressed_image:
58+ shutil.copyfileobj(uncompressed_image, compressed_image)
59+ os.unlink(raw_filename)
60 else:
61 # filetype is 'unknown' so assumed to be raw image
62 with open(filename, 'rb') as uncompressed_image:

Subscribers

People subscribed via source and target branches