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
1=== modified file 'linaro-android-media-create'
2--- linaro-android-media-create 2012-12-28 13:09:56 +0000
3+++ linaro-android-media-create 2013-01-30 11:36:23 +0000
4@@ -42,6 +42,7 @@
5 from linaro_image_tools.media_create import get_android_args_parser
6 from linaro_image_tools.utils import (
7 additional_android_option_checks,
8+ andorid_hwpack_in_boot_tarball,
9 ensure_command,
10 get_logger
11 )
12@@ -109,15 +110,6 @@
13 DATA_DISK = os.path.join(TMP_DIR, 'userdata-disc')
14 SDCARD_DISK = os.path.join(TMP_DIR, 'sdcard-disc')
15
16- board_config = get_board_config(args.dev)
17- if args.hwpack:
18- board_config.from_file(args.hwpack)
19- else:
20- logger.warning("No Android hwpack provided: default board values "
21- "will be used.")
22- board_config.add_boot_args(args.extra_boot_args)
23- board_config.add_boot_args_from_file(args.extra_boot_args_file)
24-
25 if args.dev == 'iMX53':
26 # XXX: remove this and the corresponding entry in android_board_configs
27 logger.warning("DEPRECATION WARNING: iMX53 is deprecated, please "
28@@ -141,6 +133,23 @@
29 unpack_android_binary_tarball(args.system, SYSTEM_DIR)
30 unpack_android_binary_tarball(args.userdata, DATA_DIR)
31
32+ board_config = get_board_config(args.dev)
33+
34+ hwpack_exists, config_file = andorid_hwpack_in_boot_tarball(BOOT_DIR)
35+ if not args.hwpack and not hwpack_exists:
36+ # No hwpack in the boot tarball nor provided on the command line.
37+ logger.warning("No hwpack found in the boot tarball nor passed on "
38+ "the command line. Default values will be used.")
39+ elif not args.hwpack and hwpack_exists:
40+ board_config.from_file(config_file)
41+ elif args.hwpack:
42+ logger.warning("Values from the hwpack provided on the command line "
43+ "will be used.")
44+ board_config.from_file(args.hwpack)
45+
46+ board_config.add_boot_args(args.extra_boot_args)
47+ board_config.add_boot_args_from_file(args.extra_boot_args_file)
48+
49 # Create partitions
50 boot_partition, system_partition, cache_partition, \
51 data_partition, sdcard_partition = setup_android_partitions( \
52
53=== modified file 'linaro_image_tools/tests/test_utils.py'
54--- linaro_image_tools/tests/test_utils.py 2012-06-13 14:55:34 +0000
55+++ linaro_image_tools/tests/test_utils.py 2013-01-30 11:36:23 +0000
56@@ -37,7 +37,9 @@
57 IncompatibleOptions,
58 InvalidHwpackFile,
59 UnableToFindPackageProvidingCommand,
60+ additional_android_option_checks,
61 additional_option_checks,
62+ andorid_hwpack_in_boot_tarball,
63 check_file_integrity_and_log_errors,
64 ensure_command,
65 find_command,
66@@ -335,6 +337,49 @@
67 sys.argv.remove("--mmc")
68
69
70+class TestAndroidOptionChecks(TestCaseWithFixtures):
71+
72+ def test_hwpack_is_file(self):
73+ class HwPacksArgs:
74+ def __init__(self, hwpack):
75+ self.hwpack = hwpack
76+
77+ try:
78+ tmpdir = tempfile.mkdtemp()
79+ self.assertRaises(InvalidHwpackFile,
80+ additional_android_option_checks,
81+ HwPacksArgs(tmpdir))
82+ finally:
83+ os.rmdir(tmpdir)
84+
85+ def test_android_hwpack_in_boot(self):
86+ """Test presence of config file in boot directory."""
87+ try:
88+ tmpdir = tempfile.mkdtemp()
89+ boot_dir = os.path.join(tmpdir, "boot")
90+ os.mkdir(boot_dir)
91+ config_file = os.path.join(boot_dir, "config")
92+ expected = (True, config_file)
93+ with open(config_file, "w"):
94+ self.assertEqual(expected,
95+ andorid_hwpack_in_boot_tarball(tmpdir))
96+ finally:
97+ os.unlink(config_file)
98+ os.removedirs(boot_dir)
99+
100+ def test_android_hwpack_not_in_boot(self):
101+ """Test missing config file."""
102+ try:
103+ tmpdir = tempfile.mkdtemp()
104+ boot_dir = os.path.join(tmpdir, "boot")
105+ os.mkdir(boot_dir)
106+ config_file = os.path.join(boot_dir, "config")
107+ expected = (False, config_file)
108+ self.assertEqual(expected, andorid_hwpack_in_boot_tarball(tmpdir))
109+ finally:
110+ os.removedirs(boot_dir)
111+
112+
113 class TestHwpackIsFile(TestCaseWithFixtures):
114
115 """Testing '--hwpack' option only allows regular files."""
116
117=== modified file 'linaro_image_tools/utils.py'
118--- linaro_image_tools/utils.py 2012-12-05 14:54:29 +0000
119+++ linaro_image_tools/utils.py 2013-01-30 11:36:23 +0000
120@@ -30,6 +30,11 @@
121
122 DEFAULT_LOGGER_NAME = 'linaro_image_tools'
123
124+# The boot path in the boot tarball.
125+BOOT_DIR_IN_TARBALL = "boot"
126+# The name of the hwpack file found in the boot tarball.
127+HWPACK_NAME = "config"
128+
129
130 # try_import was copied from python-testtools 0.9.12 and was originally
131 # licensed under a MIT-style license but relicensed under the GPL in Linaro
132@@ -354,6 +359,19 @@
133 "--hwpack argument (%s) is not a regular file" % args.hwpack)
134
135
136+def andorid_hwpack_in_boot_tarball(boot_dir):
137+ """Simple check for existence of a path.
138+
139+ Needed to make cli command testable in some way.
140+ :param boot_dir: The path where the boot tarball has been extracted.
141+ :type str
142+ :return A tuple with a bool if the path exists, and the path to the config
143+ file.
144+ """
145+ conf_file = os.path.join(boot_dir, BOOT_DIR_IN_TARBALL, HWPACK_NAME)
146+ return os.path.exists(conf_file), conf_file
147+
148+
149 def check_required_args(args):
150 """Check that the required args are passed."""
151 if args.dev is None:

Subscribers

People subscribed via source and target branches