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
1=== modified file 'debian/control'
2--- debian/control 2011-01-11 21:26:54 +0000
3+++ debian/control 2011-01-18 11:47:15 +0000
4@@ -18,8 +18,10 @@
5 Package: linaro-image-tools
6 Architecture: all
7 Depends: ${misc:Depends},
8+ util-linux,
9 parted,
10 uuid-runtime,
11+ dosfstools,
12 u-boot-tools | uboot-mkimage,
13 python,
14 python-hwpack (>= ${source:Version}),
15@@ -28,6 +30,9 @@
16 python-debian (>= 0.1.16ubuntu1),
17 python-linaro-media-create (>= ${source:Version}),
18 python-parted
19+Recommends: qemu-kvm-extras-static,
20+ qemu-kvm,
21+ btrfs-tools
22 Description: collection of tools to work with Linaro images
23 This package offers a set of tools for use with Linaro images.
24 .
25
26=== modified file 'linaro-media-create'
27--- linaro-media-create 2011-01-14 20:29:07 +0000
28+++ linaro-media-create 2011-01-18 11:47:15 +0000
29@@ -12,7 +12,6 @@
30 )
31 from linaro_media_create.check_device import (
32 confirm_device_selection_and_ensure_it_is_ready)
33-from linaro_media_create.ensure_command import ensure_command
34 from linaro_media_create.hwpack import install_hwpacks
35 from linaro_media_create.partitions import (
36 Media,
37@@ -21,6 +20,10 @@
38 from linaro_media_create.populate_boot import populate_boot
39 from linaro_media_create.rootfs import populate_rootfs
40 from linaro_media_create.unpack_binary_tarball import unpack_binary_tarball
41+from linaro_media_create.utils import (
42+ ensure_command,
43+ is_arm_host,
44+ )
45 from linaro_media_create import get_args_parser
46
47
48@@ -53,18 +56,16 @@
49 def ensure_required_commands(args):
50 """Ensure we have the commands that we know are going to be used."""
51 required_commands = [
52- ('sfdisk', 'util-linux'),
53- ('fdisk', 'util-linux'),
54- ('mkimage', 'uboot-mkimage'),
55- ('uuidgen', 'uuid-runtime'),
56- ('parted', 'parted'),
57- ]
58+ 'mkfs.vfat', 'sfdisk', 'fdisk', 'mkimage', 'uuidgen', 'parted']
59+ if not is_arm_host():
60+ required_commands.append('qemu-arm-static')
61+ required_commands.append('qemu-img')
62 if args.rootfs in ['ext2', 'ext3', 'ext4']:
63- required_commands.append(('mkfs.%s' % args.rootfs, 'e2fsprogs'))
64+ required_commands.append('mkfs.%s' % args.rootfs)
65 else:
66- required_commands.append(('mkfs.btrfs', 'btrfs-tools'))
67- for command, package in required_commands:
68- ensure_command(command, package)
69+ required_commands.append('mkfs.btrfs')
70+ for command in required_commands:
71+ ensure_command(command)
72
73
74 if __name__ == '__main__':
75@@ -72,6 +73,8 @@
76 args = parser.parse_args()
77 board_config = board_configs[args.board]
78
79+ ensure_required_commands(args)
80+
81 media = Media(args.device)
82 if media.is_block_device:
83 if not confirm_device_selection_and_ensure_it_is_ready(args.device):
84
85=== removed file 'linaro_media_create/ensure_command.py'
86--- linaro_media_create/ensure_command.py 2011-01-07 20:15:56 +0000
87+++ linaro_media_create/ensure_command.py 1970-01-01 00:00:00 +0000
88@@ -1,13 +0,0 @@
89-import os
90-import sys
91-
92-
93-def apt_get_install(command, package):
94- print ("Installing required command %s from package %s"
95- % (command, package))
96- os.system('sudo apt-get install %s' % package)
97-
98-
99-def ensure_command(command, package):
100- if os.system('which %s 2>/dev/null 1>/dev/null' % command) != 0:
101- apt_get_install(command, package)
102
103=== modified file 'linaro_media_create/hwpack.py'
104--- linaro_media_create/hwpack.py 2011-01-11 21:26:54 +0000
105+++ linaro_media_create/hwpack.py 2011-01-18 11:47:15 +0000
106@@ -1,8 +1,7 @@
107 import os
108-import platform
109
110 from linaro_media_create import cmd_runner
111-from linaro_media_create.ensure_command import ensure_command
112+from linaro_media_create.utils import is_arm_host
113
114
115 # It'd be nice if we could use atexit here, but all the things we need to undo
116@@ -17,9 +16,7 @@
117 temporarily_overwrite_file_on_dir('/etc/resolv.conf', chroot_etc, tmp_dir)
118 temporarily_overwrite_file_on_dir('/etc/hosts', chroot_etc, tmp_dir)
119
120- if not platform.machine().startswith('arm'):
121- ensure_command('qemu-arm-static', 'qemu-arm-static')
122- ensure_command('qemu-img', 'qemu-kvm')
123+ if not is_arm_host():
124 copy_file('/usr/bin/qemu-arm-static',
125 os.path.join(chroot_dir, 'usr', 'bin'))
126
127
128=== modified file 'linaro_media_create/tests/fixtures.py'
129--- linaro_media_create/tests/fixtures.py 2011-01-11 21:26:54 +0000
130+++ linaro_media_create/tests/fixtures.py 2011-01-18 11:47:15 +0000
131@@ -85,6 +85,10 @@
132 def wait(self):
133 return self.returncode
134
135+ @property
136+ def commands_executed(self):
137+ return [' '.join(args) for args in self.calls]
138+
139
140 class MockCmdRunnerPopenFixture(MockSomethingFixture):
141 """A test fixture which mocks cmd_runner.do_run with the given mock.
142
143=== modified file 'linaro_media_create/tests/test_media_create.py'
144--- linaro_media_create/tests/test_media_create.py 2011-01-18 10:16:45 +0000
145+++ linaro_media_create/tests/test_media_create.py 2011-01-18 11:47:15 +0000
146@@ -16,10 +16,10 @@
147 from linaro_media_create import (
148 check_device,
149 cmd_runner,
150- ensure_command,
151 boards,
152 partitions,
153 rootfs,
154+ utils,
155 )
156 from linaro_media_create.boards import (
157 board_configs,
158@@ -57,6 +57,11 @@
159 write_data_to_protected_file,
160 )
161 from linaro_media_create.unpack_binary_tarball import unpack_binary_tarball
162+from linaro_media_create.utils import (
163+ ensure_command,
164+ install_package_providing,
165+ UnableToFindPackageProvidingCommand,
166+ )
167
168 from linaro_media_create.tests.fixtures import (
169 CreateTempDirFixture,
170@@ -67,28 +72,46 @@
171 )
172
173
174-class TestEnsureCommand(TestCase):
175-
176- apt_get_called = False
177+class TestEnsureCommand(TestCaseWithFixtures):
178+
179+ install_pkg_providing_called = False
180+
181+ def setUp(self):
182+ super(TestEnsureCommand, self).setUp()
183+ self.useFixture(MockSomethingFixture(
184+ sys, 'stdout', open('/dev/null', 'w')))
185
186 def test_command_already_present(self):
187- with self.mock_apt_get_install():
188- ensure_command.ensure_command('apt-get', 'apt')
189- self.assertFalse(self.apt_get_called)
190+ self.mock_install_package_providing()
191+ ensure_command('apt-get')
192+ self.assertFalse(self.install_pkg_providing_called)
193
194 def test_command_not_present(self):
195- with self.mock_apt_get_install():
196- ensure_command.ensure_command('apt-get-two-o', 'apt-2')
197- self.assertTrue(self.apt_get_called)
198-
199- @contextmanager
200- def mock_apt_get_install(self):
201- def mock_apt_get_install(cmd, pkg):
202- self.apt_get_called = True
203- orig_func = ensure_command.apt_get_install
204- ensure_command.apt_get_install = mock_apt_get_install
205- yield
206- ensure_command.apt_get_install = orig_func
207+ self.mock_install_package_providing()
208+ ensure_command('apt-get-two-o')
209+ self.assertTrue(self.install_pkg_providing_called)
210+
211+ def mock_install_package_providing(self):
212+ def mock_func(command):
213+ self.install_pkg_providing_called = True
214+ self.useFixture(MockSomethingFixture(
215+ utils, 'install_package_providing', mock_func))
216+
217+
218+class TestInstallPackageProviding(TestCaseWithFixtures):
219+
220+ def test_found_package(self):
221+ fixture = self.useFixture(MockCmdRunnerPopenFixture())
222+ install_package_providing('mkfs.vfat')
223+ self.assertEqual(
224+ ['sudo apt-get install dosfstools'],
225+ fixture.mock.commands_executed)
226+
227+ def test_not_found_package(self):
228+ fixture = self.useFixture(MockCmdRunnerPopenFixture())
229+ self.assertRaises(
230+ UnableToFindPackageProvidingCommand,
231+ install_package_providing, 'mkfs.lean')
232
233
234 class TestGetBootCmd(TestCase):

Subscribers

People subscribed via source and target branches