diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 585: Untangle boot commands from lava dispatcher. See BP:

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

Commit Message

Senthil Kumaran April 22, 2013, 12:06 p.m. UTC
Merge authors:
  Senthil Kumaran S (stylesen)
Related merge proposals:
  https://code.launchpad.net/~stylesen/lava-dispatcher/untangle-boot-cmds/+merge/158274
  proposed by: Senthil Kumaran S (stylesen)
  review: Needs Fixing - Antonio Terceiro (terceiro)
------------------------------------------------------------
revno: 585 [merge]
committer: Senthil Kumaran <senthil.kumaran@linaro.org>
branch nick: trunk
timestamp: Mon 2013-04-22 17:35:02 +0530
message:
  Untangle boot commands from lava dispatcher. See BP:
  https://blueprints.launchpad.net/lava-dispatcher/+spec/untangle-boot-commands-from-dispatcher
modified:
  lava_dispatcher/config.py
  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
diff mbox

Patch

=== modified file 'lava_dispatcher/config.py'
--- lava_dispatcher/config.py	2013-04-08 13:29:48 +0000
+++ lava_dispatcher/config.py	2013-04-22 09:39:22 +0000
@@ -71,6 +71,7 @@ 
     possible_partitions_files = schema.ListOption(default=["init.partitions.rc",
                                                            "fstab.partitions",
                                                            "init.rc"])
+    boot_files = schema.ListOption(default=['boot.txt', 'uEnv.txt'])
     # see doc/sdmux.rst for details
     sdmux_id = schema.StringOption()
     sdmux_version = schema.StringOption(default="unknown")

=== modified file 'lava_dispatcher/device/master.py'
--- lava_dispatcher/device/master.py	2013-04-16 02:59:05 +0000
+++ lava_dispatcher/device/master.py	2013-04-22 09:39:22 +0000
@@ -23,6 +23,7 @@ 
 import logging
 import os
 import time
+import re
 
 import pexpect
 
@@ -171,6 +172,41 @@ 
                 logging.exception("Deployment failed")
                 raise CriticalError("Deployment failed")
 
+    def _rewrite_partition_number(self, matchobj):
+        """ Returns the partition number after rewriting it to n+2.
+        """
+        partition = int(matchobj.group('partition')) + 2
+        return matchobj.group(0)[:2] + ':' + 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
+        root=LABEL=testrootfs instead of root=UUID=ab34-...
+        """
+        boot_cmds = re.sub(
+            r"root=UUID=\S+", "root=LABEL=testrootfs", boot_cmds, re.MULTILINE)
+        pattern = "\s+\d+:(?P<partition>\d+)\s+"
+        boot_cmds = re.sub(
+            pattern, self._rewrite_partition_number, boot_cmds, re.MULTILINE)
+        
+        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:
+            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
+
     def _format_testpartition(self, runner, fstype):
         logging.info("Format testboot and testrootfs partitions")
         runner.run('umount /dev/disk/by-label/testrootfs', failok=True)
@@ -421,8 +457,15 @@ 
             boot_cmds = options['boot_cmds'].value
 
         logging.info('boot_cmds attribute: %s', boot_cmds)
-        boot_cmds = self.config.cp.get('__main__', boot_cmds)
-        self._boot(string_to_list(boot_cmds.encode('ascii')))
+
+        # Check if we have already got some values from image's boot file.
+        if self.deployment_data.get('boot_cmds_dynamic'):
+            boot_cmds = self.deployment_data['boot_cmds_dynamic']
+        else:
+            boot_cmds = self.config.cp.get('__main__', boot_cmds)
+            boot_cmds = string_to_list(boot_cmds.encode('ascii'))
+
+        self._boot(boot_cmds)
 
     def _boot(self, boot_cmds):
         try: