Merge lp:~salgado/linaro-image-tools/port-create_partitions into lp:linaro-image-tools/11.11
- port-create_partitions
- Merge into trunk
Proposed by
Guilherme Salgado
Status: | Merged |
---|---|
Merged at revision: | 188 |
Proposed branch: | lp:~salgado/linaro-image-tools/port-create_partitions |
Merge into: | lp:linaro-image-tools/11.11 |
Diff against target: |
377 lines (+199/-56) 5 files modified
hwpack/testing.py (+9/-0) linaro-media-create (+3/-34) media_create/create_partitions.py (+87/-0) media_create/tests/fixtures.py (+28/-9) media_create/tests/test_media_create.py (+72/-13) |
To merge this branch: | bzr merge lp:~salgado/linaro-image-tools/port-create_partitions |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
James Westby (community) | Approve | ||
Review via email: mp+43105@code.launchpad.net |
Commit message
Description of the change
Port most of create_partitions to python
To post a comment you must log in.
- 180. By Guilherme Salgado
-
merge trunk
Revision history for this message
Guilherme Salgado (salgado) wrote : | # |
I can now use cmd_runner.Popen() here and avoid the duplication. I'll do so after I land that branch.
The board-specific code is going away soon indeed.
Thanks a lot for the review.
- 181. By Guilherme Salgado
-
merge trunk
- 182. By Guilherme Salgado
-
Use the new cmd_runner.Popen instead of subprocess.Popen
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'hwpack/testing.py' | |||
2 | --- hwpack/testing.py 2010-12-08 00:34:09 +0000 | |||
3 | +++ hwpack/testing.py 2010-12-09 20:01:29 +0000 | |||
4 | @@ -161,6 +161,15 @@ | |||
5 | 161 | fixture.setUp() | 161 | fixture.setUp() |
6 | 162 | return fixture | 162 | return fixture |
7 | 163 | 163 | ||
8 | 164 | def createTempFileAsFixture(self, prefix='tmp'): | ||
9 | 165 | """Create a temp file and make sure it is removed on tearDown. | ||
10 | 166 | |||
11 | 167 | :return: The filename of the file created. | ||
12 | 168 | """ | ||
13 | 169 | _, filename = tempfile.mkstemp(prefix=prefix) | ||
14 | 170 | self.addCleanup(os.unlink, filename) | ||
15 | 171 | return filename | ||
16 | 172 | |||
17 | 164 | 173 | ||
18 | 165 | class ConfigFileFixture(object): | 174 | class ConfigFileFixture(object): |
19 | 166 | 175 | ||
20 | 167 | 176 | ||
21 | === modified file 'linaro-media-create' | |||
22 | --- linaro-media-create 2010-12-03 18:55:10 +0000 | |||
23 | +++ linaro-media-create 2010-12-09 20:01:29 +0000 | |||
24 | @@ -438,40 +438,8 @@ | |||
25 | 438 | } | 438 | } |
26 | 439 | 439 | ||
27 | 440 | create_partitions() { | 440 | create_partitions() { |
62 | 441 | if [ "${DEVICE}" ]; then | 441 | python -m media_create.create_partitions "${DEVIMAGE}" \ |
63 | 442 | sudo parted -s ${DEVICE} mklabel msdos | 442 | "${DEVICE-$IMAGE_FILE}" "$FAT_SIZE" "$HEADS" "$SECTORS" "$CYLINDER_ARG" |
30 | 443 | fi | ||
31 | 444 | |||
32 | 445 | if [ "${IMAGE_FILE}" ]; then | ||
33 | 446 | partdev=${IMAGE_FILE} | ||
34 | 447 | else | ||
35 | 448 | partdev=${DEVICE} | ||
36 | 449 | fi | ||
37 | 450 | |||
38 | 451 | if [ "$FAT_SIZE" = "32" ]; then | ||
39 | 452 | PARTITION_TYPE="0x0C" | ||
40 | 453 | else | ||
41 | 454 | PARTITION_TYPE="0x0E" | ||
42 | 455 | fi | ||
43 | 456 | |||
44 | 457 | # Create: | ||
45 | 458 | # - on mx51evk, a one cylinder partition for fixed-offset bootloader data at | ||
46 | 459 | # the beginning of the image (size is one cylinder, so 8224768 bytes with | ||
47 | 460 | # the first sector for MBR), | ||
48 | 461 | # - a VFAT or FAT16 partition of 9 cylinders (74027520 bytes, ~70 MiB) | ||
49 | 462 | # and a linux partition of the rest | ||
50 | 463 | # - a Linux type rootfs for the rest of the space | ||
51 | 464 | ( | ||
52 | 465 | if [ "$DEVIMAGE" = mx51evk ]; then | ||
53 | 466 | cat <<EOF | ||
54 | 467 | ,1,0xDA | ||
55 | 468 | EOF | ||
56 | 469 | fi | ||
57 | 470 | cat <<EOF | ||
58 | 471 | ,9,$PARTITION_TYPE,* | ||
59 | 472 | ,,,- | ||
60 | 473 | EOF | ||
61 | 474 | ) | sudo sfdisk -D -H $HEADS -S $SECTORS $CYLINDER_ARG $partdev | ||
64 | 475 | 443 | ||
65 | 476 | if [ "${IMAGE_FILE}" ]; then | 444 | if [ "${IMAGE_FILE}" ]; then |
66 | 477 | VFATOFFSET=$(($(LC_ALL=C fdisk -l -u "$IMAGE_FILE" | grep FAT | awk '{print $3}')*512)) | 445 | VFATOFFSET=$(($(LC_ALL=C fdisk -l -u "$IMAGE_FILE" | grep FAT | awk '{print $3}')*512)) |
67 | @@ -628,6 +596,7 @@ | |||
68 | 628 | fi | 596 | fi |
69 | 629 | } | 597 | } |
70 | 630 | 598 | ||
71 | 599 | # XXX: Apparently there's no need to run qemu-img as root. | ||
72 | 631 | setup_image() { | 600 | setup_image() { |
73 | 632 | sudo qemu-img create -f raw "$IMAGE_FILE" $IMAGE_SIZE | 601 | sudo qemu-img create -f raw "$IMAGE_FILE" $IMAGE_SIZE |
74 | 633 | } | 602 | } |
75 | 634 | 603 | ||
76 | === added file 'media_create/create_partitions.py' | |||
77 | --- media_create/create_partitions.py 1970-01-01 00:00:00 +0000 | |||
78 | +++ media_create/create_partitions.py 2010-12-09 20:01:29 +0000 | |||
79 | @@ -0,0 +1,87 @@ | |||
80 | 1 | import subprocess | ||
81 | 2 | import sys | ||
82 | 3 | |||
83 | 4 | from media_create import cmd_runner | ||
84 | 5 | |||
85 | 6 | |||
86 | 7 | def run_sfdisk_commands(commands, heads, sectors, cylinders_arg, device, | ||
87 | 8 | as_root=True): | ||
88 | 9 | """Run the given commands under sfdisk. | ||
89 | 10 | |||
90 | 11 | :param commands: A string of sfdisk commands; each on a separate line. | ||
91 | 12 | :return: A 2-tuple containing the subprocess' stdout and stderr. | ||
92 | 13 | """ | ||
93 | 14 | args = ['sfdisk', | ||
94 | 15 | '-D', | ||
95 | 16 | '-H', str(heads), | ||
96 | 17 | '-S', str(sectors)] | ||
97 | 18 | if cylinders_arg: | ||
98 | 19 | args.append(cylinders_arg) | ||
99 | 20 | args.append(device) | ||
100 | 21 | # XXX: There's some stuff duplicated here from cmd_runner.run() but I | ||
101 | 22 | # don't see an easy way to consolidate them as a single function, so I'll | ||
102 | 23 | # leave it for later. | ||
103 | 24 | if as_root: | ||
104 | 25 | args = args[:] | ||
105 | 26 | args.insert(0, 'sudo') | ||
106 | 27 | proc = cmd_runner.Popen( | ||
107 | 28 | args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, | ||
108 | 29 | stderr=subprocess.PIPE) | ||
109 | 30 | return proc.communicate("%s\n" % commands) | ||
110 | 31 | |||
111 | 32 | |||
112 | 33 | def create_partitions(board, device, fat_size, heads, sectors, cylinders_arg): | ||
113 | 34 | """Partition the given device according to the board requirements. | ||
114 | 35 | |||
115 | 36 | :param board: A string with the board type (e.g. beagle, panda, etc) | ||
116 | 37 | :param device: A string containing the path to the device to partition. | ||
117 | 38 | :param fat_size: The type of FATs used in the boot partition (16 or 32). | ||
118 | 39 | :param heads: Number of heads to use in the disk geometry of | ||
119 | 40 | partitions. | ||
120 | 41 | :param sectors: Number of sectors to use in the disk geometry of | ||
121 | 42 | partitions. | ||
122 | 43 | :param cylinders_arg: A string of the form "-C NN" containing the number | ||
123 | 44 | of cylinders to use in the disk geometry of partitions. | ||
124 | 45 | """ | ||
125 | 46 | stdout = [] | ||
126 | 47 | stderr = [] | ||
127 | 48 | is_block_device = device.startswith('/dev/') | ||
128 | 49 | if is_block_device: | ||
129 | 50 | # Overwrite any existing partition tables with a fresh one. | ||
130 | 51 | cmd_runner.run( | ||
131 | 52 | ['parted', '-s', device, 'mklabel', 'msdos'], as_root=True) | ||
132 | 53 | |||
133 | 54 | if fat_size == 32: | ||
134 | 55 | partition_type = '0x0C' | ||
135 | 56 | else: | ||
136 | 57 | partition_type = '0x0E' | ||
137 | 58 | |||
138 | 59 | if board == 'mx51evk': | ||
139 | 60 | # Create a one cylinder partition for fixed-offset bootloader data at | ||
140 | 61 | # the beginning of the image (size is one cylinder, so 8224768 bytes | ||
141 | 62 | # with the first sector for MBR). | ||
142 | 63 | out, err = run_sfdisk_commands( | ||
143 | 64 | ',1,0xDA', heads, sectors, cylinders_arg, device) | ||
144 | 65 | stdout.append(out) | ||
145 | 66 | stderr.append(err) | ||
146 | 67 | |||
147 | 68 | # Create a VFAT or FAT16 partition of 9 cylinders (74027520 bytes, ~70 | ||
148 | 69 | # MiB), followed by a Linux-type partition containing the rest of the free | ||
149 | 70 | # space. | ||
150 | 71 | sfdisk_cmd = ',9,%s,*\n,,,-' % partition_type | ||
151 | 72 | out, err = run_sfdisk_commands( | ||
152 | 73 | sfdisk_cmd, heads, sectors, cylinders_arg, device) | ||
153 | 74 | stdout.append(out) | ||
154 | 75 | stderr.append(err) | ||
155 | 76 | return "\n".join(stdout), "\n".join(stderr) | ||
156 | 77 | |||
157 | 78 | |||
158 | 79 | if __name__ == "__main__": | ||
159 | 80 | board, device, fat_size, heads, sectors, cylinders_arg = sys.argv[1:] | ||
160 | 81 | fat_size = int(fat_size) | ||
161 | 82 | heads = int(heads) | ||
162 | 83 | sectors = int(sectors) | ||
163 | 84 | stdout, stderr = create_partitions( | ||
164 | 85 | board, device, fat_size, heads, sectors, cylinders_arg) | ||
165 | 86 | print stdout | ||
166 | 87 | print stderr | ||
167 | 0 | 88 | ||
168 | === modified file 'media_create/tests/fixtures.py' | |||
169 | --- media_create/tests/fixtures.py 2010-12-09 19:17:14 +0000 | |||
170 | +++ media_create/tests/fixtures.py 2010-12-09 20:01:29 +0000 | |||
171 | @@ -3,6 +3,7 @@ | |||
172 | 3 | import subprocess | 3 | import subprocess |
173 | 4 | import tempfile | 4 | import tempfile |
174 | 5 | 5 | ||
175 | 6 | from media_create import create_partitions | ||
176 | 6 | from media_create import cmd_runner | 7 | from media_create import cmd_runner |
177 | 7 | 8 | ||
178 | 8 | 9 | ||
179 | @@ -62,17 +63,11 @@ | |||
180 | 62 | setattr(self.obj, self.attr_name, self.orig_attr) | 63 | setattr(self.obj, self.attr_name, self.orig_attr) |
181 | 63 | 64 | ||
182 | 64 | 65 | ||
185 | 65 | class MockDoRun(object): | 66 | class MockCmdRunnerPopen(object): |
186 | 66 | """A mock for do_run() which just stores the args given to it.""" | 67 | """A mock for cmd_runner.Popen() which stores the args given to it.""" |
187 | 67 | args = None | 68 | args = None |
188 | 68 | def __call__(self, args, **kwargs): | 69 | def __call__(self, args, **kwargs): |
189 | 69 | self.args = args | 70 | self.args = args |
190 | 70 | return 0 | ||
191 | 71 | |||
192 | 72 | |||
193 | 73 | class MockCmdRunnerPopen(object): | ||
194 | 74 | def __call__(self, args, **kwargs): | ||
195 | 75 | self.args = args | ||
196 | 76 | self.returncode = 0 | 71 | self.returncode = 0 |
197 | 77 | return self | 72 | return self |
198 | 78 | 73 | ||
199 | @@ -83,7 +78,7 @@ | |||
200 | 83 | class MockCmdRunnerPopenFixture(MockSomethingFixture): | 78 | class MockCmdRunnerPopenFixture(MockSomethingFixture): |
201 | 84 | """A test fixture which mocks cmd_runner.do_run with the given mock. | 79 | """A test fixture which mocks cmd_runner.do_run with the given mock. |
202 | 85 | 80 | ||
204 | 86 | If no mock is given, MockDoRun is used. | 81 | If no mock is given, a MockCmdRunnerPopen instance is used. |
205 | 87 | """ | 82 | """ |
206 | 88 | 83 | ||
207 | 89 | def __init__(self, mock=None): | 84 | def __init__(self, mock=None): |
208 | @@ -104,3 +99,27 @@ | |||
209 | 104 | 99 | ||
210 | 105 | def tearDown(self): | 100 | def tearDown(self): |
211 | 106 | os.chdir(self.orig_cwd) | 101 | os.chdir(self.orig_cwd) |
212 | 102 | |||
213 | 103 | |||
214 | 104 | class MockCallableWithPositionalArgs(object): | ||
215 | 105 | """A callable mock which just stores the positional args given to it. | ||
216 | 106 | |||
217 | 107 | Every time an instance of this is "called", it will append a tuple | ||
218 | 108 | containing the positional arguments given to it to self.calls. | ||
219 | 109 | """ | ||
220 | 110 | calls = None | ||
221 | 111 | return_value = None | ||
222 | 112 | def __call__(self, *args): | ||
223 | 113 | if self.calls is None: | ||
224 | 114 | self.calls = [] | ||
225 | 115 | self.calls.append(args) | ||
226 | 116 | return self.return_value | ||
227 | 117 | |||
228 | 118 | |||
229 | 119 | class MockRunSfdiskCommandsFixture(MockSomethingFixture): | ||
230 | 120 | |||
231 | 121 | def __init__(self): | ||
232 | 122 | mock = MockCallableWithPositionalArgs() | ||
233 | 123 | mock.return_value = ('', '') | ||
234 | 124 | super(MockRunSfdiskCommandsFixture, self).__init__( | ||
235 | 125 | create_partitions, 'run_sfdisk_commands', mock) | ||
236 | 107 | 126 | ||
237 | === modified file 'media_create/tests/test_media_create.py' | |||
238 | --- media_create/tests/test_media_create.py 2010-12-09 19:17:14 +0000 | |||
239 | +++ media_create/tests/test_media_create.py 2010-12-09 20:01:29 +0000 | |||
240 | @@ -4,17 +4,19 @@ | |||
241 | 4 | import string | 4 | import string |
242 | 5 | import subprocess | 5 | import subprocess |
243 | 6 | import sys | 6 | import sys |
244 | 7 | import tempfile | ||
245 | 8 | 7 | ||
246 | 9 | from testtools import TestCase | 8 | from testtools import TestCase |
247 | 10 | 9 | ||
248 | 11 | from hwpack.testing import TestCaseWithFixtures | 10 | from hwpack.testing import TestCaseWithFixtures |
249 | 12 | 11 | ||
250 | 13 | from media_create.boot_cmd import create_boot_cmd | ||
251 | 14 | from media_create import cmd_runner | 12 | from media_create import cmd_runner |
252 | 15 | from media_create import ensure_command | 13 | from media_create import ensure_command |
253 | 16 | |||
254 | 17 | from media_create import populate_boot | 14 | from media_create import populate_boot |
255 | 15 | from media_create.boot_cmd import create_boot_cmd | ||
256 | 16 | from media_create.create_partitions import ( | ||
257 | 17 | create_partitions, | ||
258 | 18 | run_sfdisk_commands, | ||
259 | 19 | ) | ||
260 | 18 | from media_create.populate_boot import ( | 20 | from media_create.populate_boot import ( |
261 | 19 | make_boot_script, | 21 | make_boot_script, |
262 | 20 | make_uImage, | 22 | make_uImage, |
263 | @@ -31,6 +33,7 @@ | |||
264 | 31 | CreateTarballFixture, | 33 | CreateTarballFixture, |
265 | 32 | MockCmdRunnerPopenFixture, | 34 | MockCmdRunnerPopenFixture, |
266 | 33 | MockSomethingFixture, | 35 | MockSomethingFixture, |
267 | 36 | MockRunSfdiskCommandsFixture, | ||
268 | 34 | ) | 37 | ) |
269 | 35 | 38 | ||
270 | 36 | 39 | ||
271 | @@ -202,7 +205,7 @@ | |||
272 | 202 | def test_get_file_matching(self): | 205 | def test_get_file_matching(self): |
273 | 203 | prefix = ''.join( | 206 | prefix = ''.join( |
274 | 204 | random.choice(string.ascii_lowercase) for x in range(5)) | 207 | random.choice(string.ascii_lowercase) for x in range(5)) |
276 | 205 | file1 = self._create_temp_file_as_fixture(prefix) | 208 | file1 = self.createTempFileAsFixture(prefix) |
277 | 206 | directory = os.path.dirname(file1) | 209 | directory = os.path.dirname(file1) |
278 | 207 | self.assertEqual( | 210 | self.assertEqual( |
279 | 208 | file1, _get_file_matching('%s/%s*' % (directory, prefix))) | 211 | file1, _get_file_matching('%s/%s*' % (directory, prefix))) |
280 | @@ -210,8 +213,8 @@ | |||
281 | 210 | def test_get_file_matching_too_many_files_found(self): | 213 | def test_get_file_matching_too_many_files_found(self): |
282 | 211 | prefix = ''.join( | 214 | prefix = ''.join( |
283 | 212 | random.choice(string.ascii_lowercase) for x in range(5)) | 215 | random.choice(string.ascii_lowercase) for x in range(5)) |
286 | 213 | file1 = self._create_temp_file_as_fixture(prefix) | 216 | file1 = self.createTempFileAsFixture(prefix) |
287 | 214 | file2 = self._create_temp_file_as_fixture(prefix) | 217 | file2 = self.createTempFileAsFixture(prefix) |
288 | 215 | directory = os.path.dirname(file1) | 218 | directory = os.path.dirname(file1) |
289 | 216 | self.assertRaises( | 219 | self.assertRaises( |
290 | 217 | ValueError, _get_file_matching, '%s/%s*' % (directory, prefix)) | 220 | ValueError, _get_file_matching, '%s/%s*' % (directory, prefix)) |
291 | @@ -222,23 +225,79 @@ | |||
292 | 222 | 225 | ||
293 | 223 | def test_run_mkimage(self): | 226 | def test_run_mkimage(self): |
294 | 224 | # Create a fake boot script. | 227 | # Create a fake boot script. |
296 | 225 | filename = self._create_temp_file_as_fixture() | 228 | filename = self.createTempFileAsFixture() |
297 | 226 | f = open(filename, 'w') | 229 | f = open(filename, 'w') |
298 | 227 | f.write("setenv bootcmd 'fatload mmc 0:1 0x80000000 uImage;\nboot") | 230 | f.write("setenv bootcmd 'fatload mmc 0:1 0x80000000 uImage;\nboot") |
299 | 228 | f.close() | 231 | f.close() |
300 | 229 | 232 | ||
302 | 230 | img = self._create_temp_file_as_fixture() | 233 | img = self.createTempFileAsFixture() |
303 | 231 | # Use that fake boot script to create a boot loader using mkimage. | 234 | # Use that fake boot script to create a boot loader using mkimage. |
304 | 232 | # Send stdout to file as mkimage will print to stdout and we don't | 235 | # Send stdout to file as mkimage will print to stdout and we don't |
305 | 233 | # want that. | 236 | # want that. |
306 | 234 | retval = _run_mkimage( | 237 | retval = _run_mkimage( |
307 | 235 | 'script', '0', '0', 'boot script', filename, img, | 238 | 'script', '0', '0', 'boot script', filename, img, |
309 | 236 | stdout=open(self._create_temp_file_as_fixture(), 'w'), | 239 | stdout=open(self.createTempFileAsFixture(), 'w'), |
310 | 237 | as_root=False) | 240 | as_root=False) |
311 | 238 | 241 | ||
312 | 239 | self.assertEqual(0, retval) | 242 | self.assertEqual(0, retval) |
313 | 240 | 243 | ||
318 | 241 | def _create_temp_file_as_fixture(self, prefix='tmp'): | 244 | |
319 | 242 | _, filename = tempfile.mkstemp(prefix=prefix) | 245 | class TestCreatePartitions(TestCaseWithFixtures): |
320 | 243 | self.addCleanup(os.unlink, filename) | 246 | |
321 | 244 | return filename | 247 | def test_create_partitions_for_mx51evk(self): |
322 | 248 | # For this board we create a one cylinder partition at the beginning. | ||
323 | 249 | popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) | ||
324 | 250 | sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture()) | ||
325 | 251 | |||
326 | 252 | create_partitions('mx51evk', '/dev/sdz', 32, 255, 63, '') | ||
327 | 253 | |||
328 | 254 | self.assertEqual( | ||
329 | 255 | ['sudo', 'parted', '-s', '/dev/sdz', 'mklabel', 'msdos'], | ||
330 | 256 | popen_fixture.mock.args) | ||
331 | 257 | self.assertEqual( | ||
332 | 258 | [(',1,0xDA', 255, 63, '', '/dev/sdz'), | ||
333 | 259 | (',9,0x0C,*\n,,,-', 255, 63, '', '/dev/sdz')], | ||
334 | 260 | sfdisk_fixture.mock.calls) | ||
335 | 261 | |||
336 | 262 | def test_create_partitions_for_beagle(self): | ||
337 | 263 | popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) | ||
338 | 264 | sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture()) | ||
339 | 265 | |||
340 | 266 | create_partitions('beagle', '/dev/sdz', 32, 255, 63, '') | ||
341 | 267 | |||
342 | 268 | self.assertEqual( | ||
343 | 269 | ['sudo', 'parted', '-s', '/dev/sdz', 'mklabel', 'msdos'], | ||
344 | 270 | popen_fixture.mock.args) | ||
345 | 271 | self.assertEqual( | ||
346 | 272 | [(',9,0x0C,*\n,,,-', 255, 63, '', '/dev/sdz')], | ||
347 | 273 | sfdisk_fixture.mock.calls) | ||
348 | 274 | |||
349 | 275 | def test_create_partitions_with_img_file(self): | ||
350 | 276 | popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) | ||
351 | 277 | sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture()) | ||
352 | 278 | |||
353 | 279 | tempfile = self.createTempFileAsFixture() | ||
354 | 280 | create_partitions('beagle', tempfile, 32, 255, 63, '') | ||
355 | 281 | |||
356 | 282 | # popen() was not called as there's no existing partition table for | ||
357 | 283 | # us to overwrite on the image file. | ||
358 | 284 | self.assertEqual(None, popen_fixture.mock.args) | ||
359 | 285 | |||
360 | 286 | self.assertEqual( | ||
361 | 287 | [(',9,0x0C,*\n,,,-', 255, 63, '', tempfile)], | ||
362 | 288 | sfdisk_fixture.mock.calls) | ||
363 | 289 | |||
364 | 290 | def test_run_sfdisk_commands(self): | ||
365 | 291 | tempfile = self.createTempFileAsFixture() | ||
366 | 292 | cmd_runner.run(['qemu-img', 'create', '-f', 'raw', tempfile, '10M'], | ||
367 | 293 | stdout=subprocess.PIPE) | ||
368 | 294 | stdout, stderr = run_sfdisk_commands( | ||
369 | 295 | ',1,0xDA', 5, 63, '', tempfile, as_root=False) | ||
370 | 296 | self.assertIn('Successfully wrote the new partition table', stdout) | ||
371 | 297 | |||
372 | 298 | def test_run_sfdisk_commands_raises_on_non_zero_returncode(self): | ||
373 | 299 | tempfile = self.createTempFileAsFixture() | ||
374 | 300 | self.assertRaises( | ||
375 | 301 | cmd_runner.SubcommandNonZeroReturnValue, | ||
376 | 302 | run_sfdisk_commands, | ||
377 | 303 | ',1,0xDA', 5, 63, '', tempfile, as_root=False) |
Hi,
Looks fine. I agree sharing more code with do_run would be nice.
The board-specific code in their isn't that nice, but I presume you
are deferring removing that for now?
Thanks,
James