Merge lp:~salgado/linaro-image-tools/drop-udisks-when-not-strictly-necessary into lp:linaro-image-tools/11.11

Proposed by Guilherme Salgado
Status: Merged
Merged at revision: 262
Proposed branch: lp:~salgado/linaro-image-tools/drop-udisks-when-not-strictly-necessary
Merge into: lp:linaro-image-tools/11.11
Diff against target: 148 lines (+17/-46)
3 files modified
linaro_media_create/boards.py (+2/-0)
linaro_media_create/partitions.py (+7/-29)
linaro_media_create/tests/test_media_create.py (+8/-17)
To merge this branch: bzr merge lp:~salgado/linaro-image-tools/drop-udisks-when-not-strictly-necessary
Reviewer Review Type Date Requested Status
James Westby (community) Approve
Review via email: mp+47537@code.launchpad.net

Description of the change

Use the board's mmc_part_offset (instead of the media's partition count) to figure out the boot/root partition numbers

This is a nice simplification that allows us to get rid of a udisks callsite as a side effect

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

Looks good to me.

Thanks,

James

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/boards.py'
2--- linaro_media_create/boards.py 2011-01-25 20:04:45 +0000
3+++ linaro_media_create/boards.py 2011-01-26 15:22:54 +0000
4@@ -134,6 +134,7 @@
5 'earlyprintk fixrtc nocompcache vram=12M '
6 'omapfb.mode=dvi:1280x720MR-16@60')
7
8+
9 class OveroConfig(OmapConfig):
10 uboot_flavor = 'omap3_overo'
11 extra_serial_opts = 'console=tty0 console=ttyO2,115200n8'
12@@ -145,6 +146,7 @@
13 extra_boot_args_options = (
14 'earlyprintk')
15
16+
17 class PandaConfig(OmapConfig):
18 uboot_flavor = 'omap4_panda'
19 extra_serial_opts = 'console=tty0 console=ttyO2,115200n8'
20
21=== modified file 'linaro_media_create/partitions.py'
22--- linaro_media_create/partitions.py 2011-01-25 20:04:45 +0000
23+++ linaro_media_create/partitions.py 2011-01-26 15:22:54 +0000
24@@ -52,7 +52,8 @@
25 board_config, media, HEADS, SECTORS, cylinders)
26
27 if media.is_block_device:
28- bootfs, rootfs = get_boot_and_root_partitions_for_media(media)
29+ bootfs, rootfs = get_boot_and_root_partitions_for_media(
30+ media, board_config)
31 else:
32 bootfs, rootfs = get_boot_and_root_loopback_devices(media.path)
33
34@@ -151,34 +152,21 @@
35 return vfat_size, vfat_offset, linux_size, linux_offset
36
37
38-def get_boot_and_root_partitions_for_media(media):
39+def get_boot_and_root_partitions_for_media(media, board_config):
40 """Return the device files for the boot and root partitions of media.
41
42- If the given media has 2 partitions, the first is boot and the second is
43- root. If there are 3 partitions, the second is boot and third is root.
44-
45- If there are any other number of partitions, ValueError is raised.
46+ For boot we use partition number 1 plus the board's defined partition
47+ offset and for root we use partition number 2 plus the board's offset.
48
49 This function must only be used for block devices.
50 """
51 assert media.is_block_device, (
52 "This function must only be used for block devices")
53
54- partition_count = _get_partition_count(media)
55-
56- if partition_count == 2:
57- partition_offset = 0
58- elif partition_count == 3:
59- partition_offset = 1
60- else:
61- raise ValueError(
62- "Unexpected number of partitions on %s: %d" % (
63- media.path, partition_count))
64-
65 boot_partition = _get_device_file_for_partition_number(
66- media.path, 1 + partition_offset)
67+ media.path, 1 + board_config.mmc_part_offset)
68 root_partition = _get_device_file_for_partition_number(
69- media.path, 2 + partition_offset)
70+ media.path, 2 + board_config.mmc_part_offset)
71 assert boot_partition is not None and root_partition is not None, (
72 "Could not find boot/root partition for %s" % media.path)
73 return boot_partition, root_partition
74@@ -203,16 +191,6 @@
75 return None
76
77
78-def _get_partition_count(media):
79- """Return the number of partitions on the given media."""
80- # We could do the same easily using python-parted but it requires root
81- # rights to read block devices, so we use UDisks here.
82- device_path = _get_udisks_device_path(media.path)
83- device = dbus.SystemBus().get_object(UDISKS, device_path)
84- return device.Get(
85- device_path, 'PartitionTableCount', dbus_interface=DBUS_PROPERTIES)
86-
87-
88 def _get_udisks_device_path(device):
89 """Return the UDisks path for the given device."""
90 bus = dbus.SystemBus()
91
92=== modified file 'linaro_media_create/tests/test_media_create.py'
93--- linaro_media_create/tests/test_media_create.py 2011-01-25 20:04:45 +0000
94+++ linaro_media_create/tests/test_media_create.py 2011-01-26 15:22:54 +0000
95@@ -560,36 +560,29 @@
96 [129024L, 32256L, 10321920L, 161280L],
97 [vfat_size, vfat_offset, linux_size, linux_offset])
98
99- def test_get_boot_and_root_partitions_for_media_with_2_partitions(self):
100- self.useFixture(MockSomethingFixture(
101- partitions, '_get_partition_count', lambda media: 2))
102- tempfile = self._create_qemu_img_with_partitions(',1,0x0C,*\n,,,-')
103+ def test_get_boot_and_root_partitions_for_media_beagle(self):
104 self.useFixture(MockSomethingFixture(
105 partitions, '_get_device_file_for_partition_number',
106 lambda dev, partition: '%s%d' % (tempfile, partition)))
107+ tempfile = self.createTempFileAsFixture()
108 media = Media(tempfile)
109- # Pretend the image file is a block device, or else
110- # get_boot_and_root_partitions_for_media will choke.
111 media.is_block_device = True
112 self.assertEqual(
113 ("%s%d" % (tempfile, 1), "%s%d" % (tempfile, 2)),
114- get_boot_and_root_partitions_for_media(media))
115+ get_boot_and_root_partitions_for_media(
116+ media, board_configs['beagle']))
117
118- def test_get_boot_and_root_partitions_for_media_with_3_partitions(self):
119- self.useFixture(MockSomethingFixture(
120- partitions, '_get_partition_count', lambda media: 3))
121- tempfile = self._create_qemu_img_with_partitions(
122- ',1,0xDA\n,1,0x0C,*\n,,,-')
123+ def test_get_boot_and_root_partitions_for_media_mx51evk(self):
124 self.useFixture(MockSomethingFixture(
125 partitions, '_get_device_file_for_partition_number',
126 lambda dev, partition: '%s%d' % (tempfile, partition)))
127+ tempfile = self.createTempFileAsFixture()
128 media = Media(tempfile)
129- # Pretend the image file is a block device, or else
130- # get_boot_and_root_partitions_for_media will choke.
131 media.is_block_device = True
132 self.assertEqual(
133 ("%s%d" % (tempfile, 2), "%s%d" % (tempfile, 3)),
134- get_boot_and_root_partitions_for_media(media))
135+ get_boot_and_root_partitions_for_media(
136+ media, board_configs['mx51evk']))
137
138 def _create_qemu_img_with_partitions(self, sfdisk_commands):
139 tempfile = self.createTempFileAsFixture()
140@@ -681,8 +674,6 @@
141 def test_setup_partitions_for_block_device(self):
142 self.useFixture(MockSomethingFixture(
143 sys, 'stdout', open('/dev/null', 'w')))
144- self.useFixture(MockSomethingFixture(
145- partitions, '_get_partition_count', lambda media: 2))
146 # Pretend the partitions are mounted.
147 self.useFixture(MockSomethingFixture(
148 partitions, 'is_partition_mounted', lambda part: True))

Subscribers

People subscribed via source and target branches