Merge lp:~salgado/linaro-image-tools/prepare-partitions into lp:linaro-image-tools/11.11

Proposed by Guilherme Salgado
Status: Merged
Merged at revision: 205
Proposed branch: lp:~salgado/linaro-image-tools/prepare-partitions
Merge into: lp:linaro-image-tools/11.11
Diff against target: 198 lines (+60/-43)
4 files modified
linaro-media-create (+2/-30)
media_create/partitions.py (+35/-7)
media_create/tests/test_media_create.py (+18/-4)
tests/integration.txt (+5/-2)
To merge this branch: bzr merge lp:~salgado/linaro-image-tools/prepare-partitions
Reviewer Review Type Date Requested Status
James Westby (community) Approve
Review via email: mp+44044@code.launchpad.net

Description of the change

Port prepare_partitions to python.

To post a comment you must log in.
Revision history for this message
Guilherme Salgado (salgado) wrote :

I may not be around when this is reviewed either, so if my dear reviewer is happy with it, please go ahead and land it. Otherwise I'll do so when I'm back.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'linaro-media-create'
2--- linaro-media-create 2010-12-16 20:27:05 +0000
3+++ linaro-media-create 2010-12-17 13:31:53 +0000
4@@ -424,42 +424,14 @@
5 setup_partitions() {
6 boot_and_root_devices=$(python -m media_create.partitions \
7 "$DEVIMAGE" "${DEVICE-$IMAGE_FILE}" "$FAT_SIZE" "$IMAGE_SIZE" \
8- "$SHOULD_CREATE_PARTITIONS")
9+ "$BOOT_LABEL" "$RFS_LABEL" "$RFS" "$RFS_UUID" \
10+ "$SHOULD_CREATE_PARTITIONS" "$BOOTFS_STEP" "$ROOTFS_STEP")
11 eval $boot_and_root_devices
12
13 if [ "${IMAGE_FILE}" ]; then
14 register_loopback "$BOOTFS"
15 register_loopback "$ROOTFS"
16 fi
17-
18- prepare_partitions
19-}
20-
21-prepare_partitions() {
22-
23- if [ "$BOOTFS_STEP" ]; then
24- echo ""
25- echo "Formating Boot Partition"
26- echo ""
27- if [ -z "$BOOTFS" ]; then
28- echo "Partition $BOOTFS does not exist"
29- exit 2
30- else
31- sudo mkfs.vfat -F ${FAT_SIZE} ${BOOTFS} -n ${BOOT_LABEL}
32- fi
33- fi
34-
35- if [ "$ROOTFS_STEP" ]; then
36- echo ""
37- echo "Formating ${RFS} Partition"
38- echo ""
39- if [ -z "$ROOTFS" ]; then
40- echo "Partition $ROOTFS does not exist"
41- exit 2
42- else
43- sudo mkfs.${RFS} -U "$RFS_UUID" ${ROOTFS} -L ${RFS_LABEL}
44- fi
45- fi
46 }
47
48 populate_boot() {
49
50=== modified file 'media_create/partitions.py'
51--- media_create/partitions.py 2010-12-14 14:14:06 +0000
52+++ media_create/partitions.py 2010-12-17 13:31:53 +0000
53@@ -22,7 +22,9 @@
54 # small enough that there's not much benefit in doing that, but if it grows we
55 # might want to do it.
56 def setup_partitions(board, media, fat_size, image_size,
57- should_create_partitions):
58+ bootfs_label, rootfs_label, rootfs_type, rootfs_uuid,
59+ should_create_partitions, should_format_bootfs,
60+ should_format_rootfs):
61 """Make sure the given device is partitioned to boot the given board.
62
63 :param board: The board's name, as a string.
64@@ -48,9 +50,26 @@
65 create_partitions(board, media, fat_size, HEADS, SECTORS, cylinders)
66
67 if media.is_block_device:
68- return get_boot_and_root_partitions_for_media(media)
69+ bootfs, rootfs = get_boot_and_root_partitions_for_media(media)
70 else:
71- return get_boot_and_root_loopback_devices(media.path)
72+ bootfs, rootfs = get_boot_and_root_loopback_devices(media.path)
73+
74+ if should_format_bootfs:
75+ print "\nFormating boot partition\n"
76+ proc = cmd_runner.run(
77+ ['mkfs.vfat', '-F', str(fat_size), bootfs, '-n', bootfs_label],
78+ as_root=True)
79+ proc.wait()
80+
81+ if should_format_rootfs:
82+ print "\nFormating root partition\n"
83+ mkfs = 'mkfs.%s' % rootfs_type
84+ proc = cmd_runner.run(
85+ [mkfs, '-U', rootfs_uuid, rootfs, '-L', rootfs_label],
86+ as_root=True)
87+ proc.wait()
88+
89+ return bootfs, rootfs
90
91
92 def get_boot_and_root_loopback_devices(image_file):
93@@ -71,7 +90,7 @@
94 stdout=subprocess.PIPE, as_root=True)
95 root_device, _ = proc.communicate()
96
97- return boot_device, root_device
98+ return boot_device.strip(), root_device.strip()
99
100
101 def calculate_partition_size_and_offset(image_file):
102@@ -248,9 +267,18 @@
103
104
105 if __name__ == "__main__":
106- board, device, fat_size, image_size, should_create_partitions = (
107- sys.argv[1:])
108+ (board, device, fat_size, image_size, bootfs_label, rootfs_label,
109+ rootfs_type, rootfs_uuid, should_create_partitions, bootfs_step,
110+ rootfs_step) = sys.argv[1:]
111 fat_size = int(fat_size)
112+ should_format_bootfs = True
113+ should_format_rootfs = True
114+ if bootfs_step == "":
115+ should_format_bootfs = False
116+ if rootfs_step == "":
117+ should_format_rootfs = False
118 boot, root = setup_partitions(
119- board, Media(device), fat_size, image_size, should_create_partitions)
120+ board, Media(device), fat_size, image_size, bootfs_label,
121+ rootfs_label, rootfs_type, rootfs_uuid, should_create_partitions,
122+ should_format_bootfs, should_format_rootfs)
123 print "BOOTFS=%s ROOTFS=%s" % (boot, root)
124
125=== modified file 'media_create/tests/test_media_create.py'
126--- media_create/tests/test_media_create.py 2010-12-14 14:14:06 +0000
127+++ media_create/tests/test_media_create.py 2010-12-17 13:31:53 +0000
128@@ -428,7 +428,12 @@
129 # already setup image file.
130 tempfile = self._create_qemu_img_with_partitions(',1,0x0C,*\n,,,-')
131 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
132- setup_partitions('beagle', Media(tempfile), 32, '2G', 'yes')
133+ self.useFixture(MockSomethingFixture(
134+ sys, 'stdout', open('/dev/null', 'w')))
135+ uuid = '2e82008e-1af3-4699-8521-3bf5bac1e67a'
136+ bootfs, rootfs = setup_partitions(
137+ 'beagle', Media(tempfile), 32, '2G', 'boot', 'root', 'ext3',
138+ uuid, 'yes', 'format-bootfs', 'format-rootfs')
139 self.assertEqual(
140 # This is the call that would create the image file.
141 [['qemu-img', 'create', '-f', 'raw', tempfile, '2G'],
142@@ -442,20 +447,29 @@
143 ['sudo', 'losetup', '-f', '--show', tempfile, '--offset',
144 '32256', '--sizelimit', '129024'],
145 ['sudo', 'losetup', '-f', '--show', tempfile, '--offset',
146- '161280', '--sizelimit', '10321920']],
147+ '161280', '--sizelimit', '10321920'],
148+ ['sudo', 'mkfs.vfat', '-F', '32', bootfs, '-n', 'boot'],
149+ ['sudo', 'mkfs.ext3', '-U', uuid, rootfs, '-L', 'root']],
150 popen_fixture.mock.calls)
151
152 def test_setup_partitions_for_block_device(self):
153 self.useFixture(MockSomethingFixture(
154+ sys, 'stdout', open('/dev/null', 'w')))
155+ self.useFixture(MockSomethingFixture(
156 partitions, '_get_partition_count', lambda media: 2))
157 tempfile = self._create_qemu_img_with_partitions(',1,0x0C,*\n,,,-')
158 media = Media(tempfile)
159 # Pretend our tempfile is a block device.
160 media.is_block_device = True
161 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
162- setup_partitions('beagle', media, 32, '2G', 'yes')
163+ uuid = '2e82008e-1af3-4699-8521-3bf5bac1e67a'
164+ bootfs, rootfs = setup_partitions(
165+ 'beagle', media, 32, '2G', 'boot', 'root', 'ext3',
166+ uuid, 'yes', 'format-bootfs', 'format-rootfs')
167 self.assertEqual(
168 [['sudo', 'parted', '-s', tempfile, 'mklabel', 'msdos'],
169 ['sudo', 'sfdisk', '-D', '-H', '255', '-S', '63', tempfile],
170- ['sync']],
171+ ['sync'],
172+ ['sudo', 'mkfs.vfat', '-F', '32', bootfs, '-n', 'boot'],
173+ ['sudo', 'mkfs.ext3', '-U', uuid, rootfs, '-L', 'root']],
174 popen_fixture.mock.calls)
175
176=== modified file 'tests/integration.txt'
177--- tests/integration.txt 2010-12-14 13:30:32 +0000
178+++ tests/integration.txt 2010-12-17 13:31:53 +0000
179@@ -11,14 +11,17 @@
180
181 # Partition (for real!) /dev/sdb for a beagle board and return the devices
182 # for the boot and root partitions.
183- >>> python -m media_create.partitions beagle /dev/sdb 32 2G yes
184+ >>> python -m media_create.partitions beagle /dev/sdb 32 2G boot root ext3
185+ ... 2e82008e-1af3-4699-8521-3bf5bac1e67a yes format-bootfs format-rootfs
186 Checking that no-one is using this disk right now
187 ...
188 BOOTFS=/dev/sdb1 ROOTFS=/dev/sdb2
189
190 # Partition /tmp/beagle.img for a beagle board and return the loopback
191 # devices for the boot and root partitions.
192- >>> python -m media_create.partitions beagle /tmp/beagle.img 32 2G yes
193+ >>> python -m media_create.partitions beagle /tmp/beagle.img 32 2G boot
194+ ... root ext3 2e82008e-1af3-4699-8521-3bf5bac1e67a yes
195+ ... format-bootfs format-rootfs
196 Warning: /tmp/beagle.img is not a block device
197 ...
198 BOOTFS=/dev/loop0

Subscribers

People subscribed via source and target branches