Merge lp:~lool/linaro-image-tools/mkfs-uuid into lp:linaro-image-tools/11.11

Proposed by Loïc Minier
Status: Merged
Merged at revision: 263
Proposed branch: lp:~lool/linaro-image-tools/mkfs-uuid
Merge into: lp:linaro-image-tools/11.11
Diff against target: 411 lines (+99/-50) (has conflicts)
7 files modified
debian/control (+0/-1)
linaro-media-create (+12/-6)
linaro_media_create/__init__.py (+1/-2)
linaro_media_create/boards.py (+5/-7)
linaro_media_create/partitions.py (+22/-4)
linaro_media_create/populate_boot.py (+5/-4)
linaro_media_create/tests/test_media_create.py (+54/-26)
Text conflict in linaro-media-create
To merge this branch: bzr merge lp:~lool/linaro-image-tools/mkfs-uuid
Reviewer Review Type Date Requested Status
James Westby (community) Approve
Review via email: mp+47487@code.launchpad.net

Description of the change

Tentative branch; only passed testsuite, didn't create btrfs image yet

Suggestions on testing get_uuid() welcome!

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

Looks good so far.

For a get_uuid() test I would use the subprocess mocking again to ensure that
it calls the correct thing. It would be testing that at multiple layers, but
I think that's just the price we have to pay here.

Thanks,

James

262. By Loïc Minier

Only lookup rootfs UUID when needed.

263. By Loïc Minier

Test that get_uuid() runs blkid correctly.

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

But ignoring the return value then -- ok; I guess otherwise I would have to introduce a new Popen mock which supports returning some pre-defined output in communicate().

I've pushed an additional test now, and a cleanup; I'll test the branch now with real images now.

Revision history for this message
James Westby (james-w) wrote :

On Wed, 26 Jan 2011 12:29:09 -0000, Loïc Minier <email address hidden> wrote:
> But ignoring the return value then -- ok; I guess otherwise I would
> have to introduce a new Popen mock which supports returning some
> pre-defined output in communicate().

I didn't realise that was missing. I assumed that you would be doing
that.

I don't think it's super critical, but would be nice to have.

Thanks,

James

264. By Loïc Minier

Use blkid -p to force probing and ignore the cache in this case since it's
useless; call blkid within sudo as it needs direct device access.

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

With the latest change to use blkid -p (and sudo and -c /dev/null), and with a workaround for the UDisk race issue (time.sleep(5) after creating the rootfs), things are working reliably and I can create an ext3 image and boot it in QEMU.

I tried creating a btrfs image, but I'm using an older hwpack has the latest one doesn't work in QEMU; it fails to insmod btrfs and then falls over. I did however confirm that the proper UUID is set in boot.scr, in etc/fstab, and matches the rootfs' UUID (I manually loop-mounted it to check).

Revision history for this message
James Westby (james-w) wrote :

Looks good, apart from the simple conflict.

Should blkid be added to required_commands?

Thanks,

James

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

I am not sure what we keep in required_commands these days; in the case of Debian/Ubuntu it's guaranteed to be there

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-19 18:53:01 +0000
3+++ debian/control 2011-01-26 15:52:07 +0000
4@@ -22,7 +22,6 @@
5 Architecture: all
6 Depends: ${misc:Depends},
7 parted,
8- uuid-runtime,
9 dosfstools,
10 u-boot-tools | uboot-mkimage,
11 python,
12
13=== modified file 'linaro-media-create'
14--- linaro-media-create 2011-01-26 12:10:14 +0000
15+++ linaro-media-create 2011-01-26 15:52:07 +0000
16@@ -8,7 +8,6 @@
17
18 from linaro_media_create.boards import (
19 board_configs,
20- ROOTFS_UUID,
21 )
22 from linaro_media_create.check_device import (
23 confirm_device_selection_and_ensure_it_is_ready)
24@@ -16,6 +15,7 @@
25 from linaro_media_create.partitions import (
26 Media,
27 setup_partitions,
28+ get_uuid,
29 )
30 from linaro_media_create.populate_boot import populate_boot
31 from linaro_media_create.rootfs import populate_rootfs
32@@ -59,7 +59,11 @@
33 def ensure_required_commands(args):
34 """Ensure we have the commands that we know are going to be used."""
35 required_commands = [
36+<<<<<<< TREE
37 'mkfs.vfat', 'sfdisk', 'mkimage', 'uuidgen', 'parted']
38+=======
39+ 'mkfs.vfat', 'sfdisk', 'fdisk', 'mkimage', 'parted']
40+>>>>>>> MERGE-SOURCE
41 if not is_arm_host():
42 required_commands.append('qemu-arm-static')
43 required_commands.append('qemu-img')
44@@ -105,20 +109,22 @@
45
46 boot_partition, root_partition = setup_partitions(
47 board_config, media, args.image_size, args.boot_label, args.rfs_label,
48- args.rootfs, ROOTFS_UUID, args.should_create_partitions,
49- args.should_format_bootfs, args.should_format_rootfs)
50+ args.rootfs, args.should_create_partitions, args.should_format_bootfs,
51+ args.should_format_rootfs)
52+
53+ rootfs_uuid = get_uuid(root_partition)
54
55 if args.should_format_bootfs:
56 populate_boot(
57- board_config, ROOTFS_DIR, boot_partition, BOOT_DISK, args.device,
58- args.is_live, args.is_lowmem, args.consoles)
59+ board_config, ROOTFS_DIR, rootfs_uuid, boot_partition, BOOT_DISK,
60+ args.device, args.is_live, args.is_lowmem, args.consoles)
61
62 if args.should_format_rootfs:
63 create_swap = False
64 if args.swap_file is not None:
65 create_swap = True
66 populate_rootfs(ROOTFS_DIR, ROOT_DISK, root_partition, args.rootfs,
67- ROOTFS_UUID, create_swap, str(args.swap_file),
68+ rootfs_uuid, create_swap, str(args.swap_file),
69 board_config.mmc_part_offset)
70
71 print "Done creating Linaro image on %s" % args.device
72
73=== modified file 'linaro_media_create/__init__.py'
74--- linaro_media_create/__init__.py 2011-01-12 21:54:55 +0000
75+++ linaro_media_create/__init__.py 2011-01-26 15:52:07 +0000
76@@ -52,8 +52,7 @@
77 group.add_argument(
78 '--live', dest='is_live', action='store_true',
79 help=('Create boot command for casper/live images; if this is not '
80- 'provided a UUID for the rootfs is generated and used as the '
81- 'root= option'))
82+ 'provided the UUID for the rootfs is used as the root= option'))
83 group.add_argument(
84 '--live-256m', dest='is_lowmem', action=Live256MegsAction,
85 help=('Create boot command for casper/live images; adds '
86
87=== modified file 'linaro_media_create/boards.py'
88--- linaro_media_create/boards.py 2011-01-25 20:04:45 +0000
89+++ linaro_media_create/boards.py 2011-01-26 15:52:07 +0000
90@@ -9,12 +9,9 @@
91 import glob
92 import os
93 import tempfile
94-import uuid
95
96 from linaro_media_create import cmd_runner
97
98-ROOTFS_UUID = str(uuid.uuid4())
99-
100
101 class BoardConfig(object):
102 """The configuration used when building an image for a board."""
103@@ -48,7 +45,7 @@
104 return ',9,%s,*\n,,,-' % partition_type
105
106 @classmethod
107- def _get_boot_cmd(cls, is_live, is_lowmem, consoles):
108+ def _get_boot_cmd(cls, is_live, is_lowmem, consoles, rootfs_uuid):
109 """Get the boot command for this board.
110
111 In general subclasses should not have to override this.
112@@ -69,7 +66,7 @@
113 serial_opts += ' %s' % cls.extra_serial_opts
114
115 lowmem_opt = ''
116- boot_snippet = 'root=UUID=%s' % ROOTFS_UUID
117+ boot_snippet = 'root=UUID=%s' % rootfs_uuid
118 if is_live:
119 serial_opts += ' %s' % cls.live_serial_opts
120 boot_snippet = 'boot=casper'
121@@ -91,8 +88,9 @@
122
123 @classmethod
124 def make_boot_files(cls, uboot_parts_dir, is_live, is_lowmem, consoles,
125- root_dir, boot_dir, boot_script, boot_device_or_file):
126- boot_cmd = cls._get_boot_cmd(is_live, is_lowmem, consoles)
127+ root_dir, rootfs_uuid, boot_dir, boot_script,
128+ boot_device_or_file):
129+ boot_cmd = cls._get_boot_cmd(is_live, is_lowmem, consoles, rootfs_uuid)
130 cls._make_boot_files(
131 uboot_parts_dir, boot_cmd, root_dir, boot_dir, boot_script,
132 boot_device_or_file)
133
134=== modified file 'linaro_media_create/partitions.py'
135--- linaro_media_create/partitions.py 2011-01-25 20:04:45 +0000
136+++ linaro_media_create/partitions.py 2011-01-26 15:52:07 +0000
137@@ -1,5 +1,6 @@
138 import atexit
139 import glob
140+import re
141 import subprocess
142 import time
143
144@@ -25,9 +26,8 @@
145 # small enough that there's not much benefit in doing that, but if it grows we
146 # might want to do it.
147 def setup_partitions(board_config, media, image_size, bootfs_label,
148- rootfs_label, rootfs_type, rootfs_uuid,
149- should_create_partitions, should_format_bootfs,
150- should_format_rootfs):
151+ rootfs_label, rootfs_type, should_create_partitions,
152+ should_format_bootfs, should_format_rootfs):
153 """Make sure the given device is partitioned to boot the given board.
154
155 :param board_config: A BoardConfig class.
156@@ -73,13 +73,31 @@
157 mkfs = 'mkfs.%s' % rootfs_type
158 ensure_partition_is_not_mounted(rootfs)
159 proc = cmd_runner.run(
160- [mkfs, '-U', rootfs_uuid, rootfs, '-L', rootfs_label],
161+ [mkfs, rootfs, '-L', rootfs_label],
162 as_root=True)
163 proc.wait()
164
165 return bootfs, rootfs
166
167
168+def get_uuid(partition):
169+ """Find UUID of the given partition."""
170+ proc = cmd_runner.run(
171+ ['blkid', '-o', 'udev', '-p', '-c', '/dev/null', partition],
172+ as_root=True,
173+ stdout=subprocess.PIPE)
174+ blkid_output, _ = proc.communicate()
175+ return _parse_blkid_output(blkid_output)
176+
177+
178+def _parse_blkid_output(output):
179+ for line in output.splitlines():
180+ uuid_match = re.match("ID_FS_UUID=(.*)", line)
181+ if uuid_match:
182+ return uuid_match.group(1)
183+ return None
184+
185+
186 def ensure_partition_is_not_mounted(partition):
187 """Ensure the given partition is not mounted, umounting if necessary."""
188 if is_partition_mounted(partition):
189
190=== modified file 'linaro_media_create/populate_boot.py'
191--- linaro_media_create/populate_boot.py 2011-01-13 00:00:49 +0000
192+++ linaro_media_create/populate_boot.py 2011-01-26 15:52:07 +0000
193@@ -4,8 +4,9 @@
194 from linaro_media_create import cmd_runner
195
196
197-def populate_boot(board_config, chroot_dir, boot_partition, boot_disk,
198- boot_device_or_file, is_live, is_lowmem, consoles):
199+def populate_boot(board_config, chroot_dir, rootfs_uuid, boot_partition,
200+ boot_disk, boot_device_or_file, is_live, is_lowmem,
201+ consoles):
202
203 parts_dir = 'boot'
204 if is_live:
205@@ -33,8 +34,8 @@
206 boot_script_name=board_config.boot_script))
207
208 board_config.make_boot_files(
209- uboot_parts_dir, is_live, is_lowmem, consoles, chroot_dir, boot_disk,
210- boot_script, boot_device_or_file)
211+ uboot_parts_dir, is_live, is_lowmem, consoles, chroot_dir, rootfs_uuid,
212+ boot_disk, boot_script, boot_device_or_file)
213
214 cmd_runner.run(['sync']).wait()
215 try:
216
217=== modified file 'linaro_media_create/tests/test_media_create.py'
218--- linaro_media_create/tests/test_media_create.py 2011-01-25 20:04:45 +0000
219+++ linaro_media_create/tests/test_media_create.py 2011-01-26 15:52:07 +0000
220@@ -27,7 +27,6 @@
221 make_boot_script,
222 make_uImage,
223 make_uInitrd,
224- ROOTFS_UUID,
225 _get_file_matching,
226 _get_mlo_file,
227 _run_mkimage,
228@@ -50,6 +49,8 @@
229 Media,
230 run_sfdisk_commands,
231 setup_partitions,
232+ get_uuid,
233+ _parse_blkid_output,
234 )
235 from linaro_media_create.rootfs import (
236 create_flash_kernel_config,
237@@ -172,7 +173,7 @@
238 linaro_media_create.boards, name, mock_func_creator(name)))
239
240 def make_boot_files(self, config):
241- config.make_boot_files('', False, False, [], '', '', '', '')
242+ config.make_boot_files('', False, False, [], '', '', '', '', '')
243
244 def test_vexpress_steps(self):
245 config = linaro_media_create.boards.VexpressConfig
246@@ -235,71 +236,76 @@
247
248 def test_vexpress(self):
249 boot_cmd = board_configs['vexpress']._get_boot_cmd(
250- is_live=False, is_lowmem=False, consoles=None)
251+ is_live=False, is_lowmem=False, consoles=None,
252+ rootfs_uuid="deadbeef")
253 expected = (
254 "setenv bootcmd 'fatload mmc 0:1 0x60008000 uImage; fatload mmc "
255 "0:1 0x81000000 uInitrd; bootm 0x60008000 0x81000000'\nsetenv "
256 "bootargs ' console=tty0 console=ttyAMA0,38400n8 "
257- "root=UUID=%s rootwait ro'\nboot" % ROOTFS_UUID)
258+ "root=UUID=deadbeef rootwait ro'\nboot")
259 self.assertEqual(expected, boot_cmd)
260
261 def test_mx51evk(self):
262 boot_cmd = board_configs['mx51evk']._get_boot_cmd(
263- is_live=False, is_lowmem=False, consoles=None)
264+ is_live=False, is_lowmem=False, consoles=None,
265+ rootfs_uuid="deadbeef")
266 expected = (
267 "setenv bootcmd 'fatload mmc 0:2 0x90000000 uImage; fatload mmc "
268 "0:2 0x90800000 uInitrd; bootm 0x90000000 0x90800000'\nsetenv "
269 "bootargs ' console=tty0 console=ttymxc0,115200n8 "
270- "root=UUID=%s rootwait ro'\nboot" % ROOTFS_UUID)
271+ "root=UUID=deadbeef rootwait ro'\nboot")
272 self.assertEqual(expected, boot_cmd)
273
274 def test_ux500(self):
275 boot_cmd = board_configs['ux500']._get_boot_cmd(
276- is_live=False, is_lowmem=False, consoles=None)
277+ is_live=False, is_lowmem=False, consoles=None,
278+ rootfs_uuid="deadbeef")
279 expected = (
280 "setenv bootcmd 'fatload mmc 1:1 0x00100000 uImage; fatload mmc "
281 "1:1 0x08000000 uInitrd; bootm 0x00100000 0x08000000'\nsetenv "
282 "bootargs ' console=tty0 console=ttyAMA2,115200n8 "
283- "root=UUID=%s rootwait ro earlyprintk rootdelay=1 fixrtc "
284+ "root=UUID=deadbeef rootwait ro earlyprintk rootdelay=1 fixrtc "
285 "nocompcache mem=96M@0 mem_modem=32M@96M mem=44M@128M "
286 "pmem=22M@172M mem=30M@194M mem_mali=32M@224M "
287- "pmem_hwb=54M@256M hwmem=48M@302M mem=152M@360M'\nboot"
288- % ROOTFS_UUID)
289+ "pmem_hwb=54M@256M hwmem=48M@302M mem=152M@360M'\nboot")
290 self.assertEqual(expected, boot_cmd)
291
292 def test_panda(self):
293 boot_cmd = board_configs['panda']._get_boot_cmd(
294- is_live=False, is_lowmem=False, consoles=None)
295+ is_live=False, is_lowmem=False, consoles=None,
296+ rootfs_uuid="deadbeef")
297 expected = (
298 "setenv bootcmd 'fatload mmc 0:1 0x80200000 uImage; fatload mmc "
299 "0:1 0x81600000 uInitrd; bootm 0x80200000 0x81600000'\nsetenv "
300 "bootargs ' console=tty0 console=ttyO2,115200n8 "
301- "root=UUID=%s rootwait ro earlyprintk fixrtc nocompcache "
302+ "root=UUID=deadbeef rootwait ro earlyprintk fixrtc nocompcache "
303 "vram=32M omapfb.vram=0:8M mem=463M "
304- "ip=none'\nboot" % ROOTFS_UUID)
305+ "ip=none'\nboot")
306 self.assertEqual(expected, boot_cmd)
307
308 def test_beagle(self):
309 boot_cmd = board_configs['beagle']._get_boot_cmd(
310- is_live=False, is_lowmem=False, consoles=None)
311+ is_live=False, is_lowmem=False, consoles=None,
312+ rootfs_uuid="deadbeef")
313 expected = (
314 "setenv bootcmd 'fatload mmc 0:1 0x80000000 uImage; "
315 "fatload mmc 0:1 0x81600000 uInitrd; bootm 0x80000000 "
316 "0x81600000'\nsetenv bootargs ' console=tty0 "
317- "console=ttyO2,115200n8 root=UUID=%s rootwait ro earlyprintk "
318- "fixrtc nocompcache vram=12M "
319- "omapfb.mode=dvi:1280x720MR-16@60'\nboot" % ROOTFS_UUID)
320+ "console=ttyO2,115200n8 root=UUID=deadbeef rootwait ro "
321+ "earlyprintk fixrtc nocompcache vram=12M "
322+ "omapfb.mode=dvi:1280x720MR-16@60'\nboot")
323 self.assertEqual(expected, boot_cmd)
324
325 def test_overo(self):
326 boot_cmd = board_configs['overo']._get_boot_cmd(
327- is_live=False, is_lowmem=False, consoles=None)
328+ is_live=False, is_lowmem=False, consoles=None,
329+ rootfs_uuid="deadbeef")
330 expected = (
331 "setenv bootcmd 'fatload mmc 0:1 0x80000000 uImage; "
332 "fatload mmc 0:1 0x81600000 uInitrd; bootm 0x80000000 "
333 "0x81600000'\nsetenv bootargs ' console=tty0 "
334- "console=ttyO2,115200n8 root=UUID=%s rootwait ro earlyprintk'"
335- "\nboot" % ROOTFS_UUID)
336+ "console=ttyO2,115200n8 root=UUID=deadbeef rootwait ro "
337+ "earlyprintk'\nboot")
338 self.assertEqual(expected, boot_cmd)
339
340 class TestUnpackBinaryTarball(TestCaseWithFixtures):
341@@ -321,6 +327,30 @@
342 self.assertEqual(rc, 0)
343
344
345+class TestGetUuid(TestCaseWithFixtures):
346+
347+ def setUp(self):
348+ super(TestGetUuid, self).setUp()
349+
350+ def test_get_uuid(self):
351+ fixture = MockCmdRunnerPopenFixture()
352+ self.useFixture(fixture)
353+ get_uuid("/dev/rootfs")
354+ self.assertEquals(
355+ [[
356+ "sudo", "blkid", "-o", "udev", "-p", "-c", "/dev/null",
357+ "/dev/rootfs"]],
358+ fixture.mock.calls)
359+
360+ def test_parse_blkid_output(self):
361+ output = (
362+ "ID_FS_UUID=67d641db-ea7d-4acf-9f46-5f1f8275dce2\n"
363+ "ID_FS_UUID_ENC=67d641db-ea7d-4acf-9f46-5f1f8275dce2\n"
364+ "ID_FS_TYPE=ext4\n")
365+ uuid = _parse_blkid_output(output)
366+ self.assertEquals("67d641db-ea7d-4acf-9f46-5f1f8275dce2", uuid)
367+
368+
369 class TestCmdRunner(TestCaseWithFixtures):
370
371 def test_run(self):
372@@ -662,10 +692,9 @@
373 self.useFixture(MockSomethingFixture(
374 partitions, 'get_boot_and_root_loopback_devices',
375 lambda image: ('/dev/loop99', '/dev/loop98')))
376- uuid = '2e82008e-1af3-4699-8521-3bf5bac1e67a'
377 bootfs_dev, rootfs_dev = setup_partitions(
378 board_configs['beagle'], Media(tempfile), '2G', 'boot',
379- 'root', 'ext3', uuid, True, True, True)
380+ 'root', 'ext3', True, True, True)
381 self.assertEqual(
382 # This is the call that would create the image file.
383 [['qemu-img', 'create', '-f', 'raw', tempfile, '2G'],
384@@ -675,7 +704,7 @@
385 # Make sure changes are written to disk.
386 ['sync'],
387 ['sudo', 'mkfs.vfat', '-F', '32', bootfs_dev, '-n', 'boot'],
388- ['sudo', 'mkfs.ext3', '-U', uuid, rootfs_dev, '-L', 'root']],
389+ ['sudo', 'mkfs.ext3', rootfs_dev, '-L', 'root']],
390 popen_fixture.mock.calls)
391
392 def test_setup_partitions_for_block_device(self):
393@@ -694,10 +723,9 @@
394 # Pretend our tempfile is a block device.
395 media.is_block_device = True
396 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
397- uuid = '2e82008e-1af3-4699-8521-3bf5bac1e67a'
398 bootfs_dev, rootfs_dev = setup_partitions(
399 board_configs['beagle'], media, '2G', 'boot', 'root', 'ext3',
400- uuid, True, True, True)
401+ True, True, True)
402 self.assertEqual(
403 [['sudo', 'parted', '-s', tempfile, 'mklabel', 'msdos'],
404 ['sudo', 'sfdisk', '-D', '-H', '255', '-S', '63', tempfile],
405@@ -707,7 +735,7 @@
406 ['sudo', 'umount', bootfs_dev],
407 ['sudo', 'mkfs.vfat', '-F', '32', bootfs_dev, '-n', 'boot'],
408 ['sudo', 'umount', rootfs_dev],
409- ['sudo', 'mkfs.ext3', '-U', uuid, rootfs_dev, '-L', 'root']],
410+ ['sudo', 'mkfs.ext3', rootfs_dev, '-L', 'root']],
411 popen_fixture.mock.calls)
412
413

Subscribers

People subscribed via source and target branches