Merge lp:~salgado/linaro-image-tools/fix-packaging-and-ensure-command into lp:linaro-image-tools/11.11

Proposed by Guilherme Salgado
Status: Merged
Merged at revision: 242
Proposed branch: lp:~salgado/linaro-image-tools/fix-packaging-and-ensure-command
Merge into: lp:linaro-image-tools/11.11
Diff against target: 234 lines (+67/-48)
6 files modified
debian/control (+5/-0)
linaro-media-create (+14/-11)
linaro_media_create/ensure_command.py (+0/-13)
linaro_media_create/hwpack.py (+2/-5)
linaro_media_create/tests/fixtures.py (+4/-0)
linaro_media_create/tests/test_media_create.py (+42/-19)
To merge this branch: bzr merge lp:~salgado/linaro-image-tools/fix-packaging-and-ensure-command
Reviewer Review Type Date Requested Status
Loïc Minier (community) Approve
Review via email: mp+46509@code.launchpad.net

Description of the change

- change Depends: to add some dependencies that were required in
   practice
 - add a couple qemu-kvm packages to Suggests: although we should add them to
   Depends: once they build successfully on Ubuntu/armel. Is this the correct
   approach or should we add them to Depends: now and render l-i-t
   uninstallable on armel until qemu-kvm builds there?
 - change ensure_command to figure out the package which provides the given
   command so that callsites don't need to specify that.

in a subsequent branch I'll change ensure_command to ask for confirmation
before installing anything

To post a comment you must log in.
Revision history for this message
Loïc Minier (lool) wrote :

Awesome, thanks

One question: why the qemu-kvm dep? I thought only qemu-kvm-extras-static was needed for qemu-arm-static?

I think you could make qemu-kvm-extras-static a Recommends (this reflects that it might not be needed in some combinations). It is a hard requirement on x86 arches right now and useless on arm right now, but it shouldn't be if linaro-image-tools was able to write any image architecture on any host. I think this is preferable to having an arch: any package just to repeat this hardcoding in the packaging.

review: Approve
Revision history for this message
Loïc Minier (lool) wrote :

Hmm also, filesystems should be Recommends and perhaps even Suggests in the case of btrfs.

Revision history for this message
Guilherme Salgado (salgado) wrote :

On Mon, 2011-01-17 at 18:13 +0000, Loïc Minier wrote:
> Review: Approve
> Awesome, thanks
>
> One question: why the qemu-kvm dep? I thought only qemu-kvm-extras-static was needed for qemu-arm-static?

qemu-kvm is needed because we use qemu-img to generate qemu images.

>
> I think you could make qemu-kvm-extras-static a Recommends (this reflects that it might not be needed in some combinations). It is a hard requirement on x86 arches right now and useless on arm right now, but it shouldn't be if linaro-image-tools was able to write any image architecture on any host. I think this is preferable to having an arch: any package just to repeat this hardcoding in the packaging.

Fair enough, I'll do that.

> Hmm also, filesystems should be Recommends and perhaps even Suggests
> in the case of btrfs.

I've added them to Depends: because at least one of them (e2fsprogs or
btrfs-tools) will be needed. Given that, does it make sense to have
them as Recommends/Suggests or should the one used by default
(e2fsprogs) be a hard dependency and btrfs-tools a suggestion?

Revision history for this message
Loïc Minier (lool) wrote :

In this case, you want:
Depends: e2fsprogs | btrfs-tools

Revision history for this message
Guilherme Salgado (salgado) wrote :

On Mon, 2011-01-17 at 19:26 +0000, Loïc Minier wrote:
> In this case, you want:
> Depends: e2fsprogs | btrfs-tools

I considered that, but it didn't seem like the right thing to do to me
given that if you happen to have btrfs-tools installed but not e2fsprogs
and try to run the tool with just the essential arguments, it will
either fail or (currently) install e2fsprogs automatically.

Revision history for this message
Loïc Minier (lool) wrote :

That's true, but it's not really distinguishable from the case where someone only wants to create btrfs images and doesn't want to install mkfs.extN.

I was actually wrong earlier; we shouldn't test for e2fsprogs as it's Essential: yes, which means it can be omitted from deps as it's always installed, so our whole discussion is moot :-)

Let's just list either Recommends: btrfs-tools or Suggests: btrfs-tools :-)

Revision history for this message
Guilherme Salgado (salgado) wrote :

I somehow forgot to bzr add the new utils.py file I created in this branch, so it didn't show up in the diff when the mp was created. Here it is, though: http://bazaar.launchpad.net/~salgado/linaro-image-tools/fix-packaging-and-ensure-command/revision/242

Revision history for this message
Loïc Minier (lool) wrote :

utils.py looks good; thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2011-01-11 21:26:54 +0000
+++ debian/control 2011-01-18 11:47:15 +0000
@@ -18,8 +18,10 @@
18Package: linaro-image-tools18Package: linaro-image-tools
19Architecture: all19Architecture: all
20Depends: ${misc:Depends},20Depends: ${misc:Depends},
21 util-linux,
21 parted,22 parted,
22 uuid-runtime,23 uuid-runtime,
24 dosfstools,
23 u-boot-tools | uboot-mkimage,25 u-boot-tools | uboot-mkimage,
24 python,26 python,
25 python-hwpack (>= ${source:Version}),27 python-hwpack (>= ${source:Version}),
@@ -28,6 +30,9 @@
28 python-debian (>= 0.1.16ubuntu1),30 python-debian (>= 0.1.16ubuntu1),
29 python-linaro-media-create (>= ${source:Version}),31 python-linaro-media-create (>= ${source:Version}),
30 python-parted32 python-parted
33Recommends: qemu-kvm-extras-static,
34 qemu-kvm,
35 btrfs-tools
31Description: collection of tools to work with Linaro images36Description: collection of tools to work with Linaro images
32 This package offers a set of tools for use with Linaro images.37 This package offers a set of tools for use with Linaro images.
33 .38 .
3439
=== modified file 'linaro-media-create'
--- linaro-media-create 2011-01-14 20:29:07 +0000
+++ linaro-media-create 2011-01-18 11:47:15 +0000
@@ -12,7 +12,6 @@
12 )12 )
13from linaro_media_create.check_device import (13from linaro_media_create.check_device import (
14 confirm_device_selection_and_ensure_it_is_ready)14 confirm_device_selection_and_ensure_it_is_ready)
15from linaro_media_create.ensure_command import ensure_command
16from linaro_media_create.hwpack import install_hwpacks15from linaro_media_create.hwpack import install_hwpacks
17from linaro_media_create.partitions import (16from linaro_media_create.partitions import (
18 Media,17 Media,
@@ -21,6 +20,10 @@
21from linaro_media_create.populate_boot import populate_boot20from linaro_media_create.populate_boot import populate_boot
22from linaro_media_create.rootfs import populate_rootfs21from linaro_media_create.rootfs import populate_rootfs
23from linaro_media_create.unpack_binary_tarball import unpack_binary_tarball22from linaro_media_create.unpack_binary_tarball import unpack_binary_tarball
23from linaro_media_create.utils import (
24 ensure_command,
25 is_arm_host,
26 )
24from linaro_media_create import get_args_parser27from linaro_media_create import get_args_parser
2528
2629
@@ -53,18 +56,16 @@
53def ensure_required_commands(args):56def ensure_required_commands(args):
54 """Ensure we have the commands that we know are going to be used."""57 """Ensure we have the commands that we know are going to be used."""
55 required_commands = [58 required_commands = [
56 ('sfdisk', 'util-linux'),59 'mkfs.vfat', 'sfdisk', 'fdisk', 'mkimage', 'uuidgen', 'parted']
57 ('fdisk', 'util-linux'),60 if not is_arm_host():
58 ('mkimage', 'uboot-mkimage'),61 required_commands.append('qemu-arm-static')
59 ('uuidgen', 'uuid-runtime'),62 required_commands.append('qemu-img')
60 ('parted', 'parted'),
61 ]
62 if args.rootfs in ['ext2', 'ext3', 'ext4']:63 if args.rootfs in ['ext2', 'ext3', 'ext4']:
63 required_commands.append(('mkfs.%s' % args.rootfs, 'e2fsprogs'))64 required_commands.append('mkfs.%s' % args.rootfs)
64 else:65 else:
65 required_commands.append(('mkfs.btrfs', 'btrfs-tools'))66 required_commands.append('mkfs.btrfs')
66 for command, package in required_commands:67 for command in required_commands:
67 ensure_command(command, package)68 ensure_command(command)
6869
6970
70if __name__ == '__main__':71if __name__ == '__main__':
@@ -72,6 +73,8 @@
72 args = parser.parse_args()73 args = parser.parse_args()
73 board_config = board_configs[args.board]74 board_config = board_configs[args.board]
7475
76 ensure_required_commands(args)
77
75 media = Media(args.device)78 media = Media(args.device)
76 if media.is_block_device:79 if media.is_block_device:
77 if not confirm_device_selection_and_ensure_it_is_ready(args.device):80 if not confirm_device_selection_and_ensure_it_is_ready(args.device):
7881
=== removed file 'linaro_media_create/ensure_command.py'
--- linaro_media_create/ensure_command.py 2011-01-07 20:15:56 +0000
+++ linaro_media_create/ensure_command.py 1970-01-01 00:00:00 +0000
@@ -1,13 +0,0 @@
1import os
2import sys
3
4
5def apt_get_install(command, package):
6 print ("Installing required command %s from package %s"
7 % (command, package))
8 os.system('sudo apt-get install %s' % package)
9
10
11def ensure_command(command, package):
12 if os.system('which %s 2>/dev/null 1>/dev/null' % command) != 0:
13 apt_get_install(command, package)
140
=== modified file 'linaro_media_create/hwpack.py'
--- linaro_media_create/hwpack.py 2011-01-11 21:26:54 +0000
+++ linaro_media_create/hwpack.py 2011-01-18 11:47:15 +0000
@@ -1,8 +1,7 @@
1import os1import os
2import platform
32
4from linaro_media_create import cmd_runner3from linaro_media_create import cmd_runner
5from linaro_media_create.ensure_command import ensure_command4from linaro_media_create.utils import is_arm_host
65
76
8# It'd be nice if we could use atexit here, but all the things we need to undo7# It'd be nice if we could use atexit here, but all the things we need to undo
@@ -17,9 +16,7 @@
17 temporarily_overwrite_file_on_dir('/etc/resolv.conf', chroot_etc, tmp_dir)16 temporarily_overwrite_file_on_dir('/etc/resolv.conf', chroot_etc, tmp_dir)
18 temporarily_overwrite_file_on_dir('/etc/hosts', chroot_etc, tmp_dir)17 temporarily_overwrite_file_on_dir('/etc/hosts', chroot_etc, tmp_dir)
1918
20 if not platform.machine().startswith('arm'):19 if not is_arm_host():
21 ensure_command('qemu-arm-static', 'qemu-arm-static')
22 ensure_command('qemu-img', 'qemu-kvm')
23 copy_file('/usr/bin/qemu-arm-static',20 copy_file('/usr/bin/qemu-arm-static',
24 os.path.join(chroot_dir, 'usr', 'bin'))21 os.path.join(chroot_dir, 'usr', 'bin'))
2522
2623
=== modified file 'linaro_media_create/tests/fixtures.py'
--- linaro_media_create/tests/fixtures.py 2011-01-11 21:26:54 +0000
+++ linaro_media_create/tests/fixtures.py 2011-01-18 11:47:15 +0000
@@ -85,6 +85,10 @@
85 def wait(self):85 def wait(self):
86 return self.returncode86 return self.returncode
8787
88 @property
89 def commands_executed(self):
90 return [' '.join(args) for args in self.calls]
91
8892
89class MockCmdRunnerPopenFixture(MockSomethingFixture):93class MockCmdRunnerPopenFixture(MockSomethingFixture):
90 """A test fixture which mocks cmd_runner.do_run with the given mock.94 """A test fixture which mocks cmd_runner.do_run with the given mock.
9195
=== modified file 'linaro_media_create/tests/test_media_create.py'
--- linaro_media_create/tests/test_media_create.py 2011-01-18 10:16:45 +0000
+++ linaro_media_create/tests/test_media_create.py 2011-01-18 11:47:15 +0000
@@ -16,10 +16,10 @@
16from linaro_media_create import (16from linaro_media_create import (
17 check_device,17 check_device,
18 cmd_runner,18 cmd_runner,
19 ensure_command,
20 boards,19 boards,
21 partitions,20 partitions,
22 rootfs,21 rootfs,
22 utils,
23 )23 )
24from linaro_media_create.boards import (24from linaro_media_create.boards import (
25 board_configs,25 board_configs,
@@ -57,6 +57,11 @@
57 write_data_to_protected_file,57 write_data_to_protected_file,
58 )58 )
59from linaro_media_create.unpack_binary_tarball import unpack_binary_tarball59from linaro_media_create.unpack_binary_tarball import unpack_binary_tarball
60from linaro_media_create.utils import (
61 ensure_command,
62 install_package_providing,
63 UnableToFindPackageProvidingCommand,
64 )
6065
61from linaro_media_create.tests.fixtures import (66from linaro_media_create.tests.fixtures import (
62 CreateTempDirFixture,67 CreateTempDirFixture,
@@ -67,28 +72,46 @@
67 )72 )
6873
6974
70class TestEnsureCommand(TestCase):75class TestEnsureCommand(TestCaseWithFixtures):
7176
72 apt_get_called = False77 install_pkg_providing_called = False
78
79 def setUp(self):
80 super(TestEnsureCommand, self).setUp()
81 self.useFixture(MockSomethingFixture(
82 sys, 'stdout', open('/dev/null', 'w')))
7383
74 def test_command_already_present(self):84 def test_command_already_present(self):
75 with self.mock_apt_get_install():85 self.mock_install_package_providing()
76 ensure_command.ensure_command('apt-get', 'apt')86 ensure_command('apt-get')
77 self.assertFalse(self.apt_get_called)87 self.assertFalse(self.install_pkg_providing_called)
7888
79 def test_command_not_present(self):89 def test_command_not_present(self):
80 with self.mock_apt_get_install():90 self.mock_install_package_providing()
81 ensure_command.ensure_command('apt-get-two-o', 'apt-2')91 ensure_command('apt-get-two-o')
82 self.assertTrue(self.apt_get_called)92 self.assertTrue(self.install_pkg_providing_called)
8393
84 @contextmanager94 def mock_install_package_providing(self):
85 def mock_apt_get_install(self):95 def mock_func(command):
86 def mock_apt_get_install(cmd, pkg):96 self.install_pkg_providing_called = True
87 self.apt_get_called = True97 self.useFixture(MockSomethingFixture(
88 orig_func = ensure_command.apt_get_install98 utils, 'install_package_providing', mock_func))
89 ensure_command.apt_get_install = mock_apt_get_install99
90 yield100
91 ensure_command.apt_get_install = orig_func101class TestInstallPackageProviding(TestCaseWithFixtures):
102
103 def test_found_package(self):
104 fixture = self.useFixture(MockCmdRunnerPopenFixture())
105 install_package_providing('mkfs.vfat')
106 self.assertEqual(
107 ['sudo apt-get install dosfstools'],
108 fixture.mock.commands_executed)
109
110 def test_not_found_package(self):
111 fixture = self.useFixture(MockCmdRunnerPopenFixture())
112 self.assertRaises(
113 UnableToFindPackageProvidingCommand,
114 install_package_providing, 'mkfs.lean')
92115
93116
94class TestGetBootCmd(TestCase):117class TestGetBootCmd(TestCase):

Subscribers

People subscribed via source and target branches