Merge lp:~salgado/linaro-image-tools/port-install_hwpacks into lp:linaro-image-tools/11.11
- port-install_hwpacks
- Merge into trunk
Proposed by
Guilherme Salgado
Status: | Merged |
---|---|
Merged at revision: | 230 |
Proposed branch: | lp:~salgado/linaro-image-tools/port-install_hwpacks |
Merge into: | lp:linaro-image-tools/11.11 |
Diff against target: |
387 lines (+248/-71) 4 files modified
linaro-media-create (+2/-65) media_create/cmd_runner.py (+5/-6) media_create/hwpack.py (+120/-0) media_create/tests/test_media_create.py (+121/-0) |
To merge this branch: | bzr merge lp:~salgado/linaro-image-tools/port-install_hwpacks |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
James Westby (community) | Approve | ||
Review via email: mp+45264@code.launchpad.net |
Commit message
Description of the change
Port install_hwpacks to python
To post a comment you must log in.
Revision history for this message
Guilherme Salgado (salgado) wrote : | # |
Hi James,
Thanks for the review!
The reason why I went with atexit is that most of the functions here are
just setting things up in the chroot so that install_hwpack[s] can run,
and we want these things to be undone only after install_hwpack[s] has
finished. To achieve that using try/finally blocks I'd need to have
most of this code in a single function, which is not nice.
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 2011-01-05 15:52:33 +0000 | |||
3 | +++ linaro-media-create 2011-01-05 16:55:11 +0000 | |||
4 | @@ -269,66 +269,8 @@ | |||
5 | 269 | RFS_UUID=`uuidgen -r` | 269 | RFS_UUID=`uuidgen -r` |
6 | 270 | 270 | ||
7 | 271 | install_hwpacks () { | 271 | install_hwpacks () { |
68 | 272 | chroot=${DIR}/binary | 272 | python -m media_create.hwpack "${DIR}/binary" "$HWPACK_FORCE_YES" \ |
69 | 273 | # Make sure we unmount /proc in the chroot or else it can't be moved to the | 273 | "${HWPACK_FILES[@]}" |
10 | 274 | # rootfs. | ||
11 | 275 | |||
12 | 276 | LINARO_HWPACK_INSTALL=$(which linaro-hwpack-install) | ||
13 | 277 | |||
14 | 278 | sudo mv -f "${chroot}/etc/resolv.conf" ${TMP_DIR}/resolv.conf.orig | ||
15 | 279 | sudo cp /etc/resolv.conf "${chroot}/etc/resolv.conf" | ||
16 | 280 | |||
17 | 281 | sudo mv -f "${chroot}/etc/hosts" ${TMP_DIR}/hosts.orig | ||
18 | 282 | sudo cp /etc/hosts "${chroot}/etc/hosts" | ||
19 | 283 | |||
20 | 284 | local arch_is_arm=no | ||
21 | 285 | case `uname -m` in | ||
22 | 286 | arm*) | ||
23 | 287 | arch_is_arm=yes | ||
24 | 288 | ;; | ||
25 | 289 | *) | ||
26 | 290 | python -m media_create.ensure_command qemu-arm-static qemu-arm-static | ||
27 | 291 | python -m media_create.ensure_command qemu-img qemu-kvm | ||
28 | 292 | sudo cp /usr/bin/qemu-arm-static "${chroot}/usr/bin" | ||
29 | 293 | ;; | ||
30 | 294 | esac | ||
31 | 295 | sudo cp "$LINARO_HWPACK_INSTALL" "${chroot}/usr/bin" | ||
32 | 296 | |||
33 | 297 | # Actually install the hwpack. | ||
34 | 298 | sudo mount proc "${chroot}/proc" -t proc | ||
35 | 299 | cleanup_chroot() { | ||
36 | 300 | sudo umount -v "$chroot/proc" | ||
37 | 301 | } | ||
38 | 302 | |||
39 | 303 | for HWPACK_FILE in "${HWPACK_FILES[@]}"; do | ||
40 | 304 | |||
41 | 305 | sudo cp "$HWPACK_FILE" "$chroot" | ||
42 | 306 | echo "" | ||
43 | 307 | echo "---------------------------------------------------" | ||
44 | 308 | echo "Installing (apt-get) $HWPACK_FILE in target rootfs." | ||
45 | 309 | echo "" | ||
46 | 310 | if [ "$HWPACK_FORCE_YES" = "yes" ]; then | ||
47 | 311 | sudo LC_ALL=C chroot "$chroot" linaro-hwpack-install --force-yes /"$(basename "$HWPACK_FILE")" | ||
48 | 312 | else | ||
49 | 313 | sudo LC_ALL=C chroot "$chroot" linaro-hwpack-install /"$(basename "$HWPACK_FILE")" | ||
50 | 314 | fi | ||
51 | 315 | echo "---------------------------------------------------" | ||
52 | 316 | echo "" | ||
53 | 317 | sudo rm -f "${chroot}/$(basename "$HWPACK_FILE")" | ||
54 | 318 | |||
55 | 319 | done | ||
56 | 320 | |||
57 | 321 | # Revert some changes we did to the rootfs as we don't want them in the | ||
58 | 322 | # image. | ||
59 | 323 | sudo umount "${chroot}/proc" | ||
60 | 324 | cleanup_chroot() { :; } | ||
61 | 325 | |||
62 | 326 | sudo mv -f ${TMP_DIR}/resolv.conf.orig "${chroot}/etc/resolv.conf" | ||
63 | 327 | sudo mv -f ${TMP_DIR}/hosts.orig "${chroot}/etc/hosts" | ||
64 | 328 | if [ "arch_is_arm" = no ]; then | ||
65 | 329 | sudo rm -f "${chroot}/usr/bin/qemu-arm-static" | ||
66 | 330 | fi | ||
67 | 331 | sudo rm -f "${chroot}/usr/bin/linaro-hwpack-install" | ||
70 | 332 | } | 274 | } |
71 | 333 | 275 | ||
72 | 334 | unpack_binary_tarball() { | 276 | unpack_binary_tarball() { |
73 | @@ -444,10 +386,6 @@ | |||
74 | 444 | exit 2 | 386 | exit 2 |
75 | 445 | } | 387 | } |
76 | 446 | 388 | ||
77 | 447 | # Initially, no action is needed to clean up mounts in the chroot. | ||
78 | 448 | # install_hwpack will temporarily define this function when needed. | ||
79 | 449 | cleanup_chroot() { :; } | ||
80 | 450 | |||
81 | 451 | cleanup_handler() { | 389 | cleanup_handler() { |
82 | 452 | status=$? | 390 | status=$? |
83 | 453 | 391 | ||
84 | @@ -463,7 +401,6 @@ | |||
85 | 463 | echo "Performing cleanup..." | 401 | echo "Performing cleanup..." |
86 | 464 | echo | 402 | echo |
87 | 465 | 403 | ||
88 | 466 | cleanup_chroot | ||
89 | 467 | cleanup_sd | 404 | cleanup_sd |
90 | 468 | cleanup_mountpoints | 405 | cleanup_mountpoints |
91 | 469 | cleanup_tempfiles | 406 | cleanup_tempfiles |
92 | 470 | 407 | ||
93 | === modified file 'media_create/cmd_runner.py' | |||
94 | --- media_create/cmd_runner.py 2010-12-17 07:03:34 +0000 | |||
95 | +++ media_create/cmd_runner.py 2011-01-05 16:55:11 +0000 | |||
96 | @@ -26,10 +26,6 @@ | |||
97 | 26 | return Popen(args, stdin=stdin, stdout=stdout, stderr=stderr) | 26 | return Popen(args, stdin=stdin, stdout=stdout, stderr=stderr) |
98 | 27 | 27 | ||
99 | 28 | 28 | ||
100 | 29 | def get_extended_env(ext): | ||
101 | 30 | return os.environ.update(ext) | ||
102 | 31 | |||
103 | 32 | |||
104 | 33 | class Popen(subprocess.Popen): | 29 | class Popen(subprocess.Popen): |
105 | 34 | """A version of Popen which raises an error on non-zero returncode. | 30 | """A version of Popen which raises an error on non-zero returncode. |
106 | 35 | 31 | ||
107 | @@ -37,9 +33,12 @@ | |||
108 | 37 | SubcommandNonZeroReturnValue if it's non-zero. | 33 | SubcommandNonZeroReturnValue if it's non-zero. |
109 | 38 | """ | 34 | """ |
110 | 39 | 35 | ||
112 | 40 | def __init__(self, args, **kwargs): | 36 | def __init__(self, args, env=None, **kwargs): |
113 | 41 | self._my_args = args | 37 | self._my_args = args |
115 | 42 | super(Popen, self).__init__(args, **kwargs) | 38 | if env is None: |
116 | 39 | env = os.environ.copy() | ||
117 | 40 | env['LC_ALL'] = 'C' | ||
118 | 41 | super(Popen, self).__init__(args, env=env, **kwargs) | ||
119 | 43 | 42 | ||
120 | 44 | def wait(self): | 43 | def wait(self): |
121 | 45 | returncode = super(Popen, self).wait() | 44 | returncode = super(Popen, self).wait() |
122 | 46 | 45 | ||
123 | === added file 'media_create/hwpack.py' | |||
124 | --- media_create/hwpack.py 1970-01-01 00:00:00 +0000 | |||
125 | +++ media_create/hwpack.py 2011-01-05 16:55:11 +0000 | |||
126 | @@ -0,0 +1,120 @@ | |||
127 | 1 | import atexit | ||
128 | 2 | import os | ||
129 | 3 | import platform | ||
130 | 4 | import shutil | ||
131 | 5 | import sys | ||
132 | 6 | import tempfile | ||
133 | 7 | |||
134 | 8 | from media_create import cmd_runner | ||
135 | 9 | from media_create.ensure_command import ensure_command | ||
136 | 10 | |||
137 | 11 | |||
138 | 12 | def install_hwpacks(chroot_dir, tmp_dir, hwpack_force_yes, *hwpack_files): | ||
139 | 13 | """Install the given hwpacks onto the given chroot.""" | ||
140 | 14 | |||
141 | 15 | chroot_etc = os.path.join(chroot_dir, 'etc') | ||
142 | 16 | temporarily_overwrite_file_on_dir('/etc/resolv.conf', chroot_etc, tmp_dir) | ||
143 | 17 | temporarily_overwrite_file_on_dir('/etc/hosts', chroot_etc, tmp_dir) | ||
144 | 18 | |||
145 | 19 | if not platform.machine().startswith('arm'): | ||
146 | 20 | ensure_command('qemu-arm-static', 'qemu-arm-static') | ||
147 | 21 | ensure_command('qemu-img', 'qemu-kvm') | ||
148 | 22 | copy_file('/usr/bin/qemu-arm-static', | ||
149 | 23 | os.path.join(chroot_dir, 'usr', 'bin')) | ||
150 | 24 | |||
151 | 25 | # FIXME: This is an ugly hack to make sure we use the l-h-i script from | ||
152 | 26 | # the current development tree when possible. | ||
153 | 27 | here = os.path.dirname(__file__) | ||
154 | 28 | linaro_hwpack_install_path = os.path.join( | ||
155 | 29 | here, '..', 'linaro-hwpack-install') | ||
156 | 30 | if not os.path.exists(linaro_hwpack_install_path): | ||
157 | 31 | linaro_hwpack_install_path = '/usr/bin/linaro-hwpack-install' | ||
158 | 32 | copy_file(linaro_hwpack_install_path, | ||
159 | 33 | os.path.join(chroot_dir, 'usr', 'bin')) | ||
160 | 34 | |||
161 | 35 | mount_chroot_proc(chroot_dir) | ||
162 | 36 | |||
163 | 37 | for hwpack_file in hwpack_files: | ||
164 | 38 | install_hwpack(chroot_dir, hwpack_file, hwpack_force_yes) | ||
165 | 39 | |||
166 | 40 | |||
167 | 41 | def install_hwpack(chroot_dir, hwpack_file, hwpack_force_yes): | ||
168 | 42 | """Install an hwpack on the given chroot. | ||
169 | 43 | |||
170 | 44 | Copy the hwpack file to the chroot and run linaro-hwpack-install passing | ||
171 | 45 | that hwpack file to it. If hwpack_force_yes is True, also pass | ||
172 | 46 | --force-yes to linaro-hwpack-install. | ||
173 | 47 | """ | ||
174 | 48 | hwpack_basename = os.path.basename(hwpack_file) | ||
175 | 49 | copy_file(hwpack_file, chroot_dir) | ||
176 | 50 | print "-" * 60 | ||
177 | 51 | print "Installing (apt-get) %s in target rootfs." % hwpack_basename | ||
178 | 52 | args = ['chroot', chroot_dir, 'linaro-hwpack-install'] | ||
179 | 53 | if hwpack_force_yes: | ||
180 | 54 | args.append('--force-yes') | ||
181 | 55 | args.append('/%s' % hwpack_basename) | ||
182 | 56 | cmd_runner.run(args, as_root=True).wait() | ||
183 | 57 | print "-" * 60 | ||
184 | 58 | |||
185 | 59 | |||
186 | 60 | def mount_chroot_proc(chroot_dir): | ||
187 | 61 | """Mount a /proc filesystem on the given chroot. | ||
188 | 62 | |||
189 | 63 | Also register an atexit function to unmount that /proc filesystem. | ||
190 | 64 | """ | ||
191 | 65 | chroot_proc = os.path.join(chroot_dir, 'proc') | ||
192 | 66 | proc = cmd_runner.run( | ||
193 | 67 | ['mount', 'proc', chroot_proc, '-t', 'proc'], as_root=True) | ||
194 | 68 | proc.wait() | ||
195 | 69 | def umount_chroot_proc(): | ||
196 | 70 | cmd_runner.run(['umount', '-v', chroot_proc], as_root=True).wait() | ||
197 | 71 | atexit.register(umount_chroot_proc) | ||
198 | 72 | |||
199 | 73 | |||
200 | 74 | def copy_file(filepath, directory): | ||
201 | 75 | """Copy the given file to the given directory. | ||
202 | 76 | |||
203 | 77 | The copying of the file is done in a subprocess and run using sudo. | ||
204 | 78 | |||
205 | 79 | We also register an atexit function to remove the file from the given | ||
206 | 80 | directory. | ||
207 | 81 | """ | ||
208 | 82 | cmd_runner.run(['cp', filepath, directory], as_root=True).wait() | ||
209 | 83 | |||
210 | 84 | def undo(): | ||
211 | 85 | new_path = os.path.join(directory, os.path.basename(filepath)) | ||
212 | 86 | cmd_runner.run(['rm', '-f', new_path], as_root=True).wait() | ||
213 | 87 | atexit.register(undo) | ||
214 | 88 | |||
215 | 89 | |||
216 | 90 | def temporarily_overwrite_file_on_dir(filepath, directory, tmp_dir): | ||
217 | 91 | """Temporarily replace a file on the given directory. | ||
218 | 92 | |||
219 | 93 | We'll move the existing file on the given directory to a temp dir, then | ||
220 | 94 | copy over the given file to that directory and register an atexit function | ||
221 | 95 | to move the orig file back to the given directory. | ||
222 | 96 | """ | ||
223 | 97 | basename = os.path.basename(filepath) | ||
224 | 98 | path_to_orig = os.path.join(tmp_dir, basename) | ||
225 | 99 | # Move the existing file from the given directory to the temp dir. | ||
226 | 100 | cmd_runner.run( | ||
227 | 101 | ['mv', '-f', os.path.join(directory, basename), path_to_orig], | ||
228 | 102 | as_root=True).wait() | ||
229 | 103 | # Now copy the given file onto the given directory. | ||
230 | 104 | cmd_runner.run(['cp', filepath, directory], as_root=True).wait() | ||
231 | 105 | |||
232 | 106 | def undo(): | ||
233 | 107 | cmd_runner.run( | ||
234 | 108 | ['mv', '-f', path_to_orig, directory], as_root=True).wait() | ||
235 | 109 | atexit.register(undo) | ||
236 | 110 | |||
237 | 111 | |||
238 | 112 | if __name__ == '__main__': | ||
239 | 113 | tmp_dir = tempfile.mkdtemp() | ||
240 | 114 | atexit.register(shutil.rmtree, tmp_dir) | ||
241 | 115 | chroot_dir, hwpack_force_yes = sys.argv[1:3] | ||
242 | 116 | hwpack_force_yes = False | ||
243 | 117 | if hwpack_force_yes == "yes": | ||
244 | 118 | hwpack_force_yes = True | ||
245 | 119 | hwpacks = sys.argv[3:] | ||
246 | 120 | install_hwpacks(chroot_dir, tmp_dir, hwpack_force_yes, *hwpacks) | ||
247 | 0 | 121 | ||
248 | === modified file 'media_create/tests/test_media_create.py' | |||
249 | --- media_create/tests/test_media_create.py 2010-12-20 10:00:07 +0000 | |||
250 | +++ media_create/tests/test_media_create.py 2011-01-05 16:55:11 +0000 | |||
251 | @@ -1,4 +1,5 @@ | |||
252 | 1 | from contextlib import contextmanager | 1 | from contextlib import contextmanager |
253 | 2 | import atexit | ||
254 | 2 | import os | 3 | import os |
255 | 3 | import random | 4 | import random |
256 | 4 | import string | 5 | import string |
257 | @@ -17,6 +18,13 @@ | |||
258 | 17 | from media_create import partitions | 18 | from media_create import partitions |
259 | 18 | from media_create import rootfs | 19 | from media_create import rootfs |
260 | 19 | from media_create.boot_cmd import create_boot_cmd | 20 | from media_create.boot_cmd import create_boot_cmd |
261 | 21 | from media_create.hwpack import ( | ||
262 | 22 | copy_file, | ||
263 | 23 | install_hwpack, | ||
264 | 24 | install_hwpacks, | ||
265 | 25 | mount_chroot_proc, | ||
266 | 26 | temporarily_overwrite_file_on_dir, | ||
267 | 27 | ) | ||
268 | 20 | from media_create.partitions import ( | 28 | from media_create.partitions import ( |
269 | 21 | calculate_partition_size_and_offset, | 29 | calculate_partition_size_and_offset, |
270 | 22 | convert_size_to_bytes, | 30 | convert_size_to_bytes, |
271 | @@ -639,3 +647,116 @@ | |||
272 | 639 | def test_check_device_not_found(self): | 647 | def test_check_device_not_found(self): |
273 | 640 | self._mock_does_device_exist_false() | 648 | self._mock_does_device_exist_false() |
274 | 641 | self.assertFalse(check_device.check_device(None)) | 649 | self.assertFalse(check_device.check_device(None)) |
275 | 650 | |||
276 | 651 | |||
277 | 652 | class AtExitRegister(object): | ||
278 | 653 | funcs = None | ||
279 | 654 | def __call__(self, func, *args, **kwargs): | ||
280 | 655 | if self.funcs is None: | ||
281 | 656 | self.funcs = [] | ||
282 | 657 | self.funcs.append((func, args, kwargs)) | ||
283 | 658 | |||
284 | 659 | |||
285 | 660 | class TestInstallHWPack(TestCaseWithFixtures): | ||
286 | 661 | |||
287 | 662 | def test_temporarily_overwrite_file_on_dir(self): | ||
288 | 663 | fixture = self.useFixture(MockCmdRunnerPopenFixture()) | ||
289 | 664 | temporarily_overwrite_file_on_dir('/path/to/file', '/dir', '/tmp/dir') | ||
290 | 665 | self.assertEquals( | ||
291 | 666 | [['sudo', 'mv', '-f', '/dir/file', '/tmp/dir/file'], | ||
292 | 667 | ['sudo', 'cp', '/path/to/file', '/dir']], | ||
293 | 668 | fixture.mock.calls) | ||
294 | 669 | |||
295 | 670 | fixture.mock.calls = [] | ||
296 | 671 | self._run_registered_atexit_functions() | ||
297 | 672 | self.assertEquals( | ||
298 | 673 | [['sudo', 'mv', '-f', '/tmp/dir/file', '/dir']], | ||
299 | 674 | fixture.mock.calls) | ||
300 | 675 | |||
301 | 676 | def test_copy_file(self): | ||
302 | 677 | fixture = self.useFixture(MockCmdRunnerPopenFixture()) | ||
303 | 678 | copy_file('/path/to/file', '/dir') | ||
304 | 679 | self.assertEquals( | ||
305 | 680 | [['sudo', 'cp', '/path/to/file', '/dir']], | ||
306 | 681 | fixture.mock.calls) | ||
307 | 682 | |||
308 | 683 | fixture.mock.calls = [] | ||
309 | 684 | self._run_registered_atexit_functions() | ||
310 | 685 | self.assertEquals( | ||
311 | 686 | [['sudo', 'rm', '-f', '/dir/file']], fixture.mock.calls) | ||
312 | 687 | |||
313 | 688 | def test_mount_chroot_proc(self): | ||
314 | 689 | fixture = self.useFixture(MockCmdRunnerPopenFixture()) | ||
315 | 690 | mount_chroot_proc('chroot') | ||
316 | 691 | self.assertEquals( | ||
317 | 692 | [['sudo', 'mount', 'proc', 'chroot/proc', '-t', 'proc']], | ||
318 | 693 | fixture.mock.calls) | ||
319 | 694 | |||
320 | 695 | fixture.mock.calls = [] | ||
321 | 696 | self._run_registered_atexit_functions() | ||
322 | 697 | self.assertEquals( | ||
323 | 698 | [['sudo', 'umount', '-v', 'chroot/proc']], fixture.mock.calls) | ||
324 | 699 | |||
325 | 700 | def test_install_hwpack(self): | ||
326 | 701 | self.useFixture(MockSomethingFixture( | ||
327 | 702 | sys, 'stdout', open('/dev/null', 'w'))) | ||
328 | 703 | fixture = self.useFixture(MockCmdRunnerPopenFixture()) | ||
329 | 704 | force_yes = False | ||
330 | 705 | install_hwpack('chroot', 'hwpack.tgz', force_yes) | ||
331 | 706 | self.assertEquals( | ||
332 | 707 | [['sudo', 'cp', 'hwpack.tgz', 'chroot'], | ||
333 | 708 | ['sudo', 'chroot', 'chroot', 'linaro-hwpack-install', | ||
334 | 709 | '/hwpack.tgz']], | ||
335 | 710 | fixture.mock.calls) | ||
336 | 711 | |||
337 | 712 | fixture.mock.calls = [] | ||
338 | 713 | self._run_registered_atexit_functions() | ||
339 | 714 | self.assertEquals( | ||
340 | 715 | [['sudo', 'rm', '-f', 'chroot/hwpack.tgz']], fixture.mock.calls) | ||
341 | 716 | |||
342 | 717 | def test_install_hwpacks(self): | ||
343 | 718 | self.useFixture(MockSomethingFixture( | ||
344 | 719 | sys, 'stdout', open('/dev/null', 'w'))) | ||
345 | 720 | fixture = self.useFixture(MockCmdRunnerPopenFixture()) | ||
346 | 721 | force_yes = True | ||
347 | 722 | install_hwpacks( | ||
348 | 723 | 'chroot', '/tmp/dir', force_yes, 'hwpack1.tgz', 'hwpack2.tgz') | ||
349 | 724 | self.assertEquals( | ||
350 | 725 | [['sudo', 'mv', '-f', 'chroot/etc/resolv.conf', | ||
351 | 726 | '/tmp/dir/resolv.conf'], | ||
352 | 727 | ['sudo', 'cp', '/etc/resolv.conf', 'chroot/etc'], | ||
353 | 728 | ['sudo', 'mv', '-f', 'chroot/etc/hosts', '/tmp/dir/hosts'], | ||
354 | 729 | ['sudo', 'cp', '/etc/hosts', 'chroot/etc'], | ||
355 | 730 | ['sudo', 'cp', '/usr/bin/qemu-arm-static', 'chroot/usr/bin'], | ||
356 | 731 | ['sudo', 'cp', 'media_create/../linaro-hwpack-install', | ||
357 | 732 | 'chroot/usr/bin'], | ||
358 | 733 | ['sudo', 'mount', 'proc', 'chroot/proc', '-t', 'proc'], | ||
359 | 734 | ['sudo', 'cp', 'hwpack1.tgz', 'chroot'], | ||
360 | 735 | ['sudo', 'chroot', 'chroot', 'linaro-hwpack-install', | ||
361 | 736 | '--force-yes', '/hwpack1.tgz'], | ||
362 | 737 | ['sudo', 'cp', 'hwpack2.tgz', 'chroot'], | ||
363 | 738 | ['sudo', 'chroot', 'chroot', 'linaro-hwpack-install', | ||
364 | 739 | '--force-yes', '/hwpack2.tgz']], | ||
365 | 740 | fixture.mock.calls) | ||
366 | 741 | |||
367 | 742 | fixture.mock.calls = [] | ||
368 | 743 | self._run_registered_atexit_functions() | ||
369 | 744 | self.assertEquals( | ||
370 | 745 | [['sudo', 'mv', '-f', '/tmp/dir/resolv.conf', 'chroot/etc'], | ||
371 | 746 | ['sudo', 'mv', '-f', '/tmp/dir/hosts', 'chroot/etc'], | ||
372 | 747 | ['sudo', 'rm', '-f', 'chroot/usr/bin/qemu-arm-static'], | ||
373 | 748 | ['sudo', 'rm', '-f', 'chroot/usr/bin/linaro-hwpack-install'], | ||
374 | 749 | ['sudo', 'umount', '-v', 'chroot/proc'], | ||
375 | 750 | ['sudo', 'rm', '-f', 'chroot/hwpack1.tgz'], | ||
376 | 751 | ['sudo', 'rm', '-f', 'chroot/hwpack2.tgz']], | ||
377 | 752 | fixture.mock.calls) | ||
378 | 753 | |||
379 | 754 | def _run_registered_atexit_functions(self): | ||
380 | 755 | for func, args, kwargs in self.atexit_fixture.mock.funcs: | ||
381 | 756 | func(*args, **kwargs) | ||
382 | 757 | |||
383 | 758 | def setUp(self): | ||
384 | 759 | super(TestInstallHWPack, self).setUp() | ||
385 | 760 | self.atexit_fixture = self.useFixture(MockSomethingFixture( | ||
386 | 761 | atexit, 'register', AtExitRegister())) | ||
387 | 762 |
Looks good, thanks.
I'm interested in why you chose to use atexit rather than finally
blocks etc?
Thanks,
James