[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 592: Fix bug #1174179 - Obtain test boot partition from config.

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

Commit Message

Senthil Kumaran April 30, 2013, 12:31 p.m.
Merge authors:
  Senthil Kumaran S (stylesen)
Related merge proposals:
  https://code.launchpad.net/~stylesen/lava-dispatcher/fix-bug-1174179/+merge/161584
  proposed by: Senthil Kumaran S (stylesen)
  review: Approve - Dave Pigott (dpigott)
------------------------------------------------------------
revno: 592 [merge]
committer: Senthil Kumaran <senthil.kumaran@linaro.org>
branch nick: trunk
timestamp: Tue 2013-04-30 17:59:48 +0530
message:
  Fix bug #1174179 - Obtain test boot partition from config.
modified:
  lava_dispatcher/config.py
  lava_dispatcher/default-config/lava-dispatcher/device-defaults.conf
  lava_dispatcher/device/master.py


--
lp:lava-dispatcher
https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk

You are subscribed to branch lp:lava-dispatcher.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk/+edit-subscription

Patch

=== modified file 'lava_dispatcher/config.py'
--- lava_dispatcher/config.py	2013-04-23 10:47:45 +0000
+++ lava_dispatcher/config.py	2013-04-29 10:31:06 +0000
@@ -72,6 +72,8 @@ 
                                                            "fstab.partitions",
                                                            "init.rc"])
     boot_files = schema.ListOption(default=['boot.txt', 'uEnv.txt'])
+    boot_device = schema.IntOption(fatal=True)
+    testboot_offset = schema.IntOption(fatal=True)
     # see doc/sdmux.rst for details
     sdmux_id = schema.StringOption()
     sdmux_version = schema.StringOption(default="unknown")

=== modified file 'lava_dispatcher/default-config/lava-dispatcher/device-defaults.conf'
--- lava_dispatcher/default-config/lava-dispatcher/device-defaults.conf	2012-11-30 01:54:29 +0000
+++ lava_dispatcher/default-config/lava-dispatcher/device-defaults.conf	2013-04-29 10:31:06 +0000
@@ -122,3 +122,12 @@ 
 
 # how long the disablesuspend script should take to complete
 #disablesuspend_timeout = 240
+
+# This is the actual boot device for test images. Can be overridden in device
+# specific config file.
+boot_device = 0
+
+# The test boot offset that should be added to the boot partition for data
+# obtained from boot.txt or uEnv.txt and others. Can be overridden in device
+# specific config file.
+testboot_offset = 2

=== modified file 'lava_dispatcher/device/master.py'
--- lava_dispatcher/device/master.py	2013-04-25 11:36:15 +0000
+++ lava_dispatcher/device/master.py	2013-04-30 11:45:15 +0000
@@ -50,6 +50,8 @@ 
     mk_targz,
     string_to_list,
     rmtree,
+    mkdtemp,
+    extract_targz,
 )
 from lava_dispatcher.client.lmc_utils import (
     generate_image,
@@ -106,6 +108,7 @@ 
         image_file = generate_image(self, hwpack, rfs, self.scratch_dir, bootloader)
         (boot_tgz, root_tgz, data) = self._generate_tarballs(image_file)
 
+        self._read_boot_cmds(boot_tgz=boot_tgz)
         self._deploy_tarballs(boot_tgz, root_tgz)
 
     def deploy_android(self, boot, system, userdata):
@@ -153,6 +156,7 @@ 
             image_file = download_image(image, self.context, self.scratch_dir)
             (boot_tgz, root_tgz, data) = self._generate_tarballs(image_file)
 
+        self._read_boot_cmds(boot_tgz=boot_tgz)
         self._deploy_tarballs(boot_tgz, root_tgz)
 
     def _deploy_tarballs(self, boot_tgz, root_tgz):
@@ -173,16 +177,19 @@ 
                 raise CriticalError("Deployment failed")
 
     def _rewrite_partition_number(self, matchobj):
-        """ Returns the partition number after rewriting it to n+2.
+        """ Returns the partition number after rewriting it to
+        n + testboot_offset.
         """
-        partition = int(matchobj.group('partition')) + 2
-        return matchobj.group(0)[:2] + ':' + str(partition) + ' '
+        boot_device = str(self.config.boot_device)
+        testboot_offset = self.config.testboot_offset
+        partition = int(matchobj.group('partition')) + testboot_offset
+        return ' ' + boot_device + ':' + str(partition) + ' '
 
     def _rewrite_boot_cmds(self, boot_cmds):
         """
         Returns boot_cmds list after rewriting things such as:
         
-        * partition number from n to n+2
+        * partition number from n to n + testboot_offset
         * root=LABEL=testrootfs instead of root=UUID=ab34-...
         """
         boot_cmds = re.sub(
@@ -194,19 +201,39 @@ 
         
         return boot_cmds.split('\n')
 
-    def _customize_linux(self, image):
-        super(MasterImageTarget, self)._customize_linux(image)
-        boot_part = self.config.boot_part
-
-        # Read boot related file from the boot partition of image.
-        with image_partition_mounted(image, boot_part) as mnt:
+    def _read_boot_cmds(self, image=None, boot_tgz=None):
+        boot_file_path = None
+
+        # If we have already obtained boot commands dynamically, then return.
+        if self.deployment_data.get('boot_cmds_dynamic', False):
+            logging.debug("We already have boot commands in place.")
+            return
+
+        if image:
+            boot_part = self.config.boot_part
+            # Read boot related file from the boot partition of image.
+            with image_partition_mounted(image, boot_part) as mnt:
+                for boot_file in self.config.boot_files:
+                    boot_path = os.path.join(mnt, boot_file)
+                    if os.path.exists(boot_path):
+                        boot_file_path = boot_path
+                        break
+
+        elif boot_tgz:
+            tmp_dir = mkdtemp()
+            extracted_files = extract_targz(boot_tgz, tmp_dir)
             for boot_file in self.config.boot_files:
-                boot_path = os.path.join(mnt, boot_file)
-                if os.path.exists(boot_path):
-                    with open(boot_path, 'r') as f:
-                        boot_cmds = self._rewrite_boot_cmds(f.read())
-                        self.deployment_data['boot_cmds_dynamic'] = boot_cmds
-                    break
+                for file_path in extracted_files:
+                    if boot_file == os.path.basename(file_path):
+                        boot_file_path = file_path
+                        break
+
+        if boot_file_path and os.path.exists(boot_file_path):
+            with open(boot_file_path, 'r') as f:
+                boot_cmds = self._rewrite_boot_cmds(f.read())
+                self.deployment_data['boot_cmds_dynamic'] = boot_cmds
+        else:
+            logging.debug("Unable to read boot commands dynamically.")
 
     def _format_testpartition(self, runner, fstype):
         logging.info("Format testboot and testrootfs partitions")
@@ -218,6 +245,7 @@ 
 
     def _generate_tarballs(self, image_file):
         self._customize_linux(image_file)
+        self._read_boot_cmds(image=image_file)
         boot_tgz = os.path.join(self.scratch_dir, "boot.tgz")
         root_tgz = os.path.join(self.scratch_dir, "root.tgz")
         try: