diff mbox

[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 603: Added support for Android hwpack in boot tarball, added tests.

Message ID 20130130121113.18980.63595.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Milo Casagrande Jan. 30, 2013, 12:11 p.m. UTC
Merge authors:
  Milo Casagrande (milo)
  vishal (vishalbhoj)
Related merge proposals:
  https://code.launchpad.net/~milo/linaro-image-tools/hwpack-from-tarball/+merge/145583
  proposed by: Milo Casagrande (milo)
  review: Approve - Georgy Redkozubov (gesha)
  https://code.launchpad.net/~vishalbhoj/linaro-image-tools/hwpack-from-boottarball/+merge/144305
  proposed by: vishal (vishalbhoj)
  review: Needs Fixing - Milo Casagrande (milo)
------------------------------------------------------------
revno: 603 [merge]
committer: Milo Casagrande <milo@ubuntu.com>
branch nick: trunk
timestamp: Wed 2013-01-30 13:10:59 +0100
message:
  Added support for Android hwpack in boot tarball, added tests.
modified:
  linaro-android-media-create
  linaro_image_tools/tests/test_utils.py
  linaro_image_tools/utils.py


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk

You are subscribed to branch lp:linaro-image-tools.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk/+edit-subscription
diff mbox

Patch

=== 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:28:51 +0000
@@ -42,6 +42,7 @@ 
 from linaro_image_tools.media_create import get_android_args_parser
 from linaro_image_tools.utils import (
     additional_android_option_checks,
+    andorid_hwpack_in_boot_tarball,
     ensure_command,
     get_logger
     )
@@ -109,15 +110,6 @@ 
     DATA_DISK = os.path.join(TMP_DIR, 'userdata-disc')
     SDCARD_DISK = os.path.join(TMP_DIR, 'sdcard-disc')
 
-    board_config = get_board_config(args.dev)
-    if args.hwpack:
-        board_config.from_file(args.hwpack)
-    else:
-        logger.warning("No Android hwpack provided: default board values "
-                       "will be used.")
-    board_config.add_boot_args(args.extra_boot_args)
-    board_config.add_boot_args_from_file(args.extra_boot_args_file)
-
     if args.dev == 'iMX53':
         # XXX: remove this and the corresponding entry in android_board_configs
         logger.warning("DEPRECATION WARNING: iMX53 is deprecated, please "
@@ -141,6 +133,23 @@ 
     unpack_android_binary_tarball(args.system, SYSTEM_DIR)
     unpack_android_binary_tarball(args.userdata, DATA_DIR)
 
+    board_config = get_board_config(args.dev)
+
+    hwpack_exists, config_file = andorid_hwpack_in_boot_tarball(BOOT_DIR)
+    if not args.hwpack and not hwpack_exists:
+        # No hwpack in the boot tarball nor provided on the command line.
+        logger.warning("No hwpack found in the boot tarball nor passed on "
+                       "the command line. Default values will be used.")
+    elif not args.hwpack and hwpack_exists:
+        board_config.from_file(config_file)
+    elif args.hwpack:
+        logger.warning("Values from the hwpack provided on the command line "
+                       "will be used.")
+        board_config.from_file(args.hwpack)
+
+    board_config.add_boot_args(args.extra_boot_args)
+    board_config.add_boot_args_from_file(args.extra_boot_args_file)
+
     # Create partitions
     boot_partition, system_partition, cache_partition, \
         data_partition, sdcard_partition = setup_android_partitions( \

=== 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:28:51 +0000
@@ -37,7 +37,9 @@ 
     IncompatibleOptions,
     InvalidHwpackFile,
     UnableToFindPackageProvidingCommand,
+    additional_android_option_checks,
     additional_option_checks,
+    andorid_hwpack_in_boot_tarball,
     check_file_integrity_and_log_errors,
     ensure_command,
     find_command,
@@ -335,6 +337,49 @@ 
         sys.argv.remove("--mmc")
 
 
+class TestAndroidOptionChecks(TestCaseWithFixtures):
+
+    def test_hwpack_is_file(self):
+        class HwPacksArgs:
+            def __init__(self, hwpack):
+                self.hwpack = hwpack
+
+        try:
+            tmpdir = tempfile.mkdtemp()
+            self.assertRaises(InvalidHwpackFile,
+                              additional_android_option_checks,
+                              HwPacksArgs(tmpdir))
+        finally:
+            os.rmdir(tmpdir)
+
+    def test_android_hwpack_in_boot(self):
+        """Test presence of config file in boot directory."""
+        try:
+            tmpdir = tempfile.mkdtemp()
+            boot_dir = os.path.join(tmpdir, "boot")
+            os.mkdir(boot_dir)
+            config_file = os.path.join(boot_dir, "config")
+            expected = (True, config_file)
+            with open(config_file, "w"):
+                self.assertEqual(expected,
+                                 andorid_hwpack_in_boot_tarball(tmpdir))
+        finally:
+            os.unlink(config_file)
+            os.removedirs(boot_dir)
+
+    def test_android_hwpack_not_in_boot(self):
+        """Test missing config file."""
+        try:
+            tmpdir = tempfile.mkdtemp()
+            boot_dir = os.path.join(tmpdir, "boot")
+            os.mkdir(boot_dir)
+            config_file = os.path.join(boot_dir, "config")
+            expected = (False, config_file)
+            self.assertEqual(expected, andorid_hwpack_in_boot_tarball(tmpdir))
+        finally:
+            os.removedirs(boot_dir)
+
+
 class TestHwpackIsFile(TestCaseWithFixtures):
 
     """Testing '--hwpack' option only allows regular files."""

=== 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:28:51 +0000
@@ -30,6 +30,11 @@ 
 
 DEFAULT_LOGGER_NAME = 'linaro_image_tools'
 
+# The boot path in the boot tarball.
+BOOT_DIR_IN_TARBALL = "boot"
+# The name of the hwpack file found in the boot tarball.
+HWPACK_NAME = "config"
+
 
 # try_import was copied from python-testtools 0.9.12 and was originally
 # licensed under a MIT-style license but relicensed under the GPL in Linaro
@@ -354,6 +359,19 @@ 
                 "--hwpack argument (%s) is not a regular file" % args.hwpack)
 
 
+def andorid_hwpack_in_boot_tarball(boot_dir):
+    """Simple check for existence of a path.
+
+    Needed to make cli command testable in some way.
+    :param boot_dir: The path where the boot tarball has been extracted.
+    :type str
+    :return A tuple with a bool if the path exists, and the path to the config
+            file.
+    """
+    conf_file = os.path.join(boot_dir, BOOT_DIR_IN_TARBALL, HWPACK_NAME)
+    return os.path.exists(conf_file), conf_file
+
+
 def check_required_args(args):
     """Check that the required args are passed."""
     if args.dev is None: