diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 547: fix support for boot_options in master.py

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

Commit Message

Andy Doan Jan. 29, 2013, 4:25 a.m. UTC
Merge authors:
  Andy Doan (doanac)
Related merge proposals:
  https://code.launchpad.net/~doanac/lava-dispatcher/boot-cmds/+merge/145282
  proposed by: Andy Doan (doanac)
------------------------------------------------------------
revno: 547 [merge]
committer: Andy Doan <andy.doan@linaro.org>
branch nick: lava-dispatcher
timestamp: Mon 2013-01-28 22:23:19 -0600
message:
  fix support for boot_options in master.py
  
  this is a regression from past functionality when code was merged
  to boot_options.py. Its still a confusing hack, but we'll fix for
  real another day.
modified:
  lava_dispatcher/device/boot_options.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/device/boot_options.py'
--- lava_dispatcher/device/boot_options.py	2012-11-14 19:37:35 +0000
+++ lava_dispatcher/device/boot_options.py	2013-01-29 04:23:19 +0000
@@ -25,7 +25,7 @@ 
     """
     Parses items from a config ini section into an options object.
     """
-    def __init__(self, section, items):
+    def __init__(self, section, items, defval):
         self.name = section
         self.value = None
         self.allowed = None
@@ -35,8 +35,9 @@ 
             elif item[0] == 'allowed':
                 self.allowed = [x.strip() for x in item[1].split(',')]
             else:
-                logging.warn('section(%s) contains unknown item: %s' %
-                    (section, item))
+                logging.warn('section(%s) contains unknown item: %s', section, item)
+        if defval:
+            self.value = defval
 
     def valid(self, option):
         if self.allowed:
@@ -45,34 +46,45 @@ 
         return True
 
 
-def as_dict(target):
+def as_dict(target, defaults={}):
+    """
+    converts the boot_options stanza for a device into a dictionary of
+    key value pairs for the option and its value
+
+    defaults - in some cases you need to override a default value specified
+    in the device's config. For example for boot_options with master.py, the
+    default for boot_cmds is boot_cmds. However, we really need to look at
+    the deployment_data's boot_cmds for the default so that booting
+    something like android will work.
+    """
     options = {}
     for opt in target.config.boot_options:
         if opt in target.config.cp.sections():
-            options[opt] = BootOption(opt, target.config.cp.items(opt))
+            defval = defaults.get(opt, None)
+            options[opt] = BootOption(opt, target.config.cp.items(opt), defval)
         else:
-            logging.warn('no boot option config section for: %s' % opt)
+            logging.warn('no boot option config section for: %s', opt)
 
     for opt in target.boot_options:
         keyval = opt.split('=')
         if len(keyval) != 2:
-            logging.warn("Invalid boot option format: %s" % opt)
+            logging.warn("Invalid boot option format: %s", opt)
         elif keyval[0] not in options:
-            logging.warn("Invalid boot option: %s" % keyval[0])
+            logging.warn("Invalid boot option: %s", keyval[0])
         elif not options[keyval[0]].valid(keyval[1]):
-            logging.warn("Invalid boot option value: %s" % opt)
+            logging.warn("Invalid boot option value: %s", opt)
         else:
             options[keyval[0]].value = keyval[1]
 
     return options
 
 
-def as_string(target, join_pattern):
+def as_string(target, join_pattern, defaults={}):
     """
     pulls the options into a string via the join_pattern. The join pattern
     can be something like "%s=%s"
     """
-    options = as_dict(target)
+    options = as_dict(target, defaults)
 
     cmd = ''
     for option in options.values():

=== modified file 'lava_dispatcher/device/master.py'
--- lava_dispatcher/device/master.py	2013-01-16 23:27:28 +0000
+++ lava_dispatcher/device/master.py	2013-01-28 23:43:30 +0000
@@ -405,15 +405,17 @@ 
 
     def _enter_uboot(self):
         if self.proc.expect(self.config.interrupt_boot_prompt) != 0:
-            raise Exception("Faile to enter uboot")
+            raise Exception("Failed to enter uboot")
         self.proc.sendline(self.config.interrupt_boot_command)
 
     def _boot_linaro_image(self):
         boot_cmds = self.deployment_data['boot_cmds']
-        options = boot_options.as_dict(self)
+
+        options = boot_options.as_dict(self, defaults={'boot_cmds': boot_cmds})
         if 'boot_cmds' in options:
             boot_cmds = options['boot_cmds'].value
 
+        logging.info('boot_cmds attribute: %s', boot_cmds)
         boot_cmds = getattr(self.config, boot_cmds)
         self._boot(string_to_list(boot_cmds.encode('ascii')))