Merge lp:~milo/linaro-image-tools/hwpack-from-tarball into lp:linaro-image-tools/11.11

Proposed by Milo Casagrande
Status: Merged
Approved by: Georgy Redkozubov
Approved revision: 604
Merged at revision: 603
Proposed branch: lp:~milo/linaro-image-tools/hwpack-from-tarball
Merge into: lp:linaro-image-tools/11.11
Diff against target: 151 lines (+81/-9)
3 files modified
linaro-android-media-create (+18/-9)
linaro_image_tools/tests/test_utils.py (+45/-0)
linaro_image_tools/utils.py (+18/-0)
To merge this branch: bzr merge lp:~milo/linaro-image-tools/hwpack-from-tarball
Reviewer Review Type Date Requested Status
Georgy Redkozubov Approve
Review via email: mp+145583@code.launchpad.net

Description of the change

Reworked Vishal merge proposal adding tests.

Original one is here:

https://code.launchpad.net/~vishalbhoj/linaro-image-tools/hwpack-from-boottarball/+merge/144305

To post a comment you must log in.
Revision history for this message
Georgy Redkozubov (gesha) wrote :

Looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'linaro-android-media-create'
--- linaro-android-media-create 2012-12-28 13:09:56 +0000
+++ linaro-android-media-create 2013-01-30 11:36:23 +0000
@@ -42,6 +42,7 @@
42from linaro_image_tools.media_create import get_android_args_parser42from linaro_image_tools.media_create import get_android_args_parser
43from linaro_image_tools.utils import (43from linaro_image_tools.utils import (
44 additional_android_option_checks,44 additional_android_option_checks,
45 andorid_hwpack_in_boot_tarball,
45 ensure_command,46 ensure_command,
46 get_logger47 get_logger
47 )48 )
@@ -109,15 +110,6 @@
109 DATA_DISK = os.path.join(TMP_DIR, 'userdata-disc')110 DATA_DISK = os.path.join(TMP_DIR, 'userdata-disc')
110 SDCARD_DISK = os.path.join(TMP_DIR, 'sdcard-disc')111 SDCARD_DISK = os.path.join(TMP_DIR, 'sdcard-disc')
111112
112 board_config = get_board_config(args.dev)
113 if args.hwpack:
114 board_config.from_file(args.hwpack)
115 else:
116 logger.warning("No Android hwpack provided: default board values "
117 "will be used.")
118 board_config.add_boot_args(args.extra_boot_args)
119 board_config.add_boot_args_from_file(args.extra_boot_args_file)
120
121 if args.dev == 'iMX53':113 if args.dev == 'iMX53':
122 # XXX: remove this and the corresponding entry in android_board_configs114 # XXX: remove this and the corresponding entry in android_board_configs
123 logger.warning("DEPRECATION WARNING: iMX53 is deprecated, please "115 logger.warning("DEPRECATION WARNING: iMX53 is deprecated, please "
@@ -141,6 +133,23 @@
141 unpack_android_binary_tarball(args.system, SYSTEM_DIR)133 unpack_android_binary_tarball(args.system, SYSTEM_DIR)
142 unpack_android_binary_tarball(args.userdata, DATA_DIR)134 unpack_android_binary_tarball(args.userdata, DATA_DIR)
143135
136 board_config = get_board_config(args.dev)
137
138 hwpack_exists, config_file = andorid_hwpack_in_boot_tarball(BOOT_DIR)
139 if not args.hwpack and not hwpack_exists:
140 # No hwpack in the boot tarball nor provided on the command line.
141 logger.warning("No hwpack found in the boot tarball nor passed on "
142 "the command line. Default values will be used.")
143 elif not args.hwpack and hwpack_exists:
144 board_config.from_file(config_file)
145 elif args.hwpack:
146 logger.warning("Values from the hwpack provided on the command line "
147 "will be used.")
148 board_config.from_file(args.hwpack)
149
150 board_config.add_boot_args(args.extra_boot_args)
151 board_config.add_boot_args_from_file(args.extra_boot_args_file)
152
144 # Create partitions153 # Create partitions
145 boot_partition, system_partition, cache_partition, \154 boot_partition, system_partition, cache_partition, \
146 data_partition, sdcard_partition = setup_android_partitions( \155 data_partition, sdcard_partition = setup_android_partitions( \
147156
=== modified file 'linaro_image_tools/tests/test_utils.py'
--- linaro_image_tools/tests/test_utils.py 2012-06-13 14:55:34 +0000
+++ linaro_image_tools/tests/test_utils.py 2013-01-30 11:36:23 +0000
@@ -37,7 +37,9 @@
37 IncompatibleOptions,37 IncompatibleOptions,
38 InvalidHwpackFile,38 InvalidHwpackFile,
39 UnableToFindPackageProvidingCommand,39 UnableToFindPackageProvidingCommand,
40 additional_android_option_checks,
40 additional_option_checks,41 additional_option_checks,
42 andorid_hwpack_in_boot_tarball,
41 check_file_integrity_and_log_errors,43 check_file_integrity_and_log_errors,
42 ensure_command,44 ensure_command,
43 find_command,45 find_command,
@@ -335,6 +337,49 @@
335 sys.argv.remove("--mmc")337 sys.argv.remove("--mmc")
336338
337339
340class TestAndroidOptionChecks(TestCaseWithFixtures):
341
342 def test_hwpack_is_file(self):
343 class HwPacksArgs:
344 def __init__(self, hwpack):
345 self.hwpack = hwpack
346
347 try:
348 tmpdir = tempfile.mkdtemp()
349 self.assertRaises(InvalidHwpackFile,
350 additional_android_option_checks,
351 HwPacksArgs(tmpdir))
352 finally:
353 os.rmdir(tmpdir)
354
355 def test_android_hwpack_in_boot(self):
356 """Test presence of config file in boot directory."""
357 try:
358 tmpdir = tempfile.mkdtemp()
359 boot_dir = os.path.join(tmpdir, "boot")
360 os.mkdir(boot_dir)
361 config_file = os.path.join(boot_dir, "config")
362 expected = (True, config_file)
363 with open(config_file, "w"):
364 self.assertEqual(expected,
365 andorid_hwpack_in_boot_tarball(tmpdir))
366 finally:
367 os.unlink(config_file)
368 os.removedirs(boot_dir)
369
370 def test_android_hwpack_not_in_boot(self):
371 """Test missing config file."""
372 try:
373 tmpdir = tempfile.mkdtemp()
374 boot_dir = os.path.join(tmpdir, "boot")
375 os.mkdir(boot_dir)
376 config_file = os.path.join(boot_dir, "config")
377 expected = (False, config_file)
378 self.assertEqual(expected, andorid_hwpack_in_boot_tarball(tmpdir))
379 finally:
380 os.removedirs(boot_dir)
381
382
338class TestHwpackIsFile(TestCaseWithFixtures):383class TestHwpackIsFile(TestCaseWithFixtures):
339384
340 """Testing '--hwpack' option only allows regular files."""385 """Testing '--hwpack' option only allows regular files."""
341386
=== modified file 'linaro_image_tools/utils.py'
--- linaro_image_tools/utils.py 2012-12-05 14:54:29 +0000
+++ linaro_image_tools/utils.py 2013-01-30 11:36:23 +0000
@@ -30,6 +30,11 @@
3030
31DEFAULT_LOGGER_NAME = 'linaro_image_tools'31DEFAULT_LOGGER_NAME = 'linaro_image_tools'
3232
33# The boot path in the boot tarball.
34BOOT_DIR_IN_TARBALL = "boot"
35# The name of the hwpack file found in the boot tarball.
36HWPACK_NAME = "config"
37
3338
34# try_import was copied from python-testtools 0.9.12 and was originally39# try_import was copied from python-testtools 0.9.12 and was originally
35# licensed under a MIT-style license but relicensed under the GPL in Linaro40# licensed under a MIT-style license but relicensed under the GPL in Linaro
@@ -354,6 +359,19 @@
354 "--hwpack argument (%s) is not a regular file" % args.hwpack)359 "--hwpack argument (%s) is not a regular file" % args.hwpack)
355360
356361
362def andorid_hwpack_in_boot_tarball(boot_dir):
363 """Simple check for existence of a path.
364
365 Needed to make cli command testable in some way.
366 :param boot_dir: The path where the boot tarball has been extracted.
367 :type str
368 :return A tuple with a bool if the path exists, and the path to the config
369 file.
370 """
371 conf_file = os.path.join(boot_dir, BOOT_DIR_IN_TARBALL, HWPACK_NAME)
372 return os.path.exists(conf_file), conf_file
373
374
357def check_required_args(args):375def check_required_args(args):
358 """Check that the required args are passed."""376 """Check that the required args are passed."""
359 if args.dev is None:377 if args.dev is None:

Subscribers

People subscribed via source and target branches