diff mbox

boottool: Handle boot once logic differenly for Red Hat systems

Message ID 1286983065-16389-1-git-send-email-lmr@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lucas Meneghel Rodrigues Oct. 13, 2010, 3:17 p.m. UTC
None
diff mbox

Patch

diff --git a/client/common_lib/boottool.py b/client/common_lib/boottool.py
index f123f1c..3c1bd33 100644
--- a/client/common_lib/boottool.py
+++ b/client/common_lib/boottool.py
@@ -1,7 +1,8 @@ 
 # Copyright 2009 Google Inc. Released under the GPL v2
 
 import re
-
+from autotest_lib.client.bin import utils as client_utils
+import utils
 
 class boottool(object):
     """
@@ -267,11 +268,35 @@  class boottool(object):
         Sets a specific entry for the next boot, then falls back to the
         default kernel.
 
+        Apparently there is no standard to get it done in a distro agnostic
+        way, because even the same program, with similar versions behaves
+        differently from distro to distro. If for some reason this is not
+        working for your particular distro, you might have to implement some
+        custom logic on this method (I know is ugly, but it seems to be the
+        least intrusive option).
+
         @param kernel: title that identifies the entry to set for booting. If
                 evaluates to false, this becomes a no-op.
         """
+        vendor = client_utils.get_os_vendor()
         if title:
-            self._run_boottool('--boot-once', '--title=%s' % title)
+            if vendor in ['Red Hat', 'Fedora']:
+                try:
+                    title_index = int(title)
+                except ValueError:
+                    title_index = self._lookup(title)
+                g_cmd = ('echo "savedefault --default=%s --once" '
+                         '| grub --batch' % title_index)
+                utils.system(g_cmd)
+            else:
+                self._run_boottool('--boot-once', '--title=%s' % title)
+
+
+    def _lookup(self, title):
+        """
+        Finds the index of the given title.
+        """
+        return int(self._run_boottool('--lookup', '--title=%s' % title))
 
 
     def enable_xen_mode(self):
diff --git a/client/tools/boottool b/client/tools/boottool
index 4dafbab..93515ca 100755
--- a/client/tools/boottool
+++ b/client/tools/boottool
@@ -2425,6 +2425,7 @@  GetOptions(
            "force",
            "boot-once",
            "install",
+           "lookup",
 	   "module=s@", 
            "default",
            "help",
@@ -2533,7 +2534,10 @@  if (defined $params{'install'}) {
     $bootloader->read();
     $bootloader->set_default($params{'title'});
     $bootloader->write();
-  } 
+  }
+} elsif (defined $params{'lookup'} && defined $params{'title'}) {
+  $bootloader->read();
+  print $bootloader->_lookup($params{title});
 }
 
  
@@ -2554,6 +2558,7 @@  boottool [--bootloader-probe] [--arch-probe]
          [--remove-kernel=<#|title|start|end>] [--module=<module>]
          [--update-kernel=<#|title>] [--remove-args=<args>]
          [--info=<all|default|#>] [--default]
+         [--lookup] [--title]
          [--help] [--debug=<0..5>] [--set-default=<#>]
 
 =head1 DESCRIPTION
@@ -2641,6 +2646,11 @@  Also accepts 'start' or 'end'.
 Updates the bootloader to set the default boot entry to given given
 position or title.
 
+=item B<--lookup>=I<string>
+
+Returns the given index of position given by title. Has to be used with the
+option --title.
+
 =item B<--boot-once>
 
 Causes the bootloader to boot the kernel specified by --title just one