From patchwork Wed Oct 13 15:17:45 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 250831 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9DFHvdC009028 for ; Wed, 13 Oct 2010 15:17:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753757Ab0JMPRy (ORCPT ); Wed, 13 Oct 2010 11:17:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52054 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753401Ab0JMPRy (ORCPT ); Wed, 13 Oct 2010 11:17:54 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9DFHpPW017374 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 13 Oct 2010 11:17:51 -0400 Received: from freedom.redhat.com (vpn-8-89.rdu.redhat.com [10.11.8.89]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o9DFHmHa030348; Wed, 13 Oct 2010 11:17:49 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, jadmanski@google.com, Lucas Meneghel Rodrigues Subject: [PATCH] boottool: Handle boot once logic differenly for Red Hat systems Date: Wed, 13 Oct 2010 12:17:45 -0300 Message-Id: <1286983065-16389-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Wed, 13 Oct 2010 15:17:57 +0000 (UTC) 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=] [--update-kernel=<#|title>] [--remove-args=] [--info=] [--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 + +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