* [PATCH] Make PyGrub run first entry in grub config when invalid default boot option provided
@ 2009-03-20 14:14 Michal Novotny
2009-03-23 17:08 ` Ian Jackson
0 siblings, 1 reply; 4+ messages in thread
From: Michal Novotny @ 2009-03-20 14:14 UTC (permalink / raw)
To: xen-devel
[-- Attachment #1: Type: text/plain, Size: 410 bytes --]
Hello everybody,
I have created a patch for pygrub and I am sending it as an attachment.
This patch mainly solves the issue of invalid default boot option in
VM's configuration. If the entry doesn't exist, it doesn't exit with
IndexError python exception but it uses first entry there to boot up the
machine - same way like standard (real) grub does...
Signed-off-by: Michal Novotny <minovotn@redhat.com>
[-- Attachment #2: xen-pygrub-invalid-default-configuration.patch --]
[-- Type: text/plain, Size: 532 bytes --]
diff -r e1562a36094e tools/pygrub/src/pygrub
--- a/tools/pygrub/src/pygrub Thu Mar 19 17:04:06 2009 +0000
+++ b/tools/pygrub/src/pygrub Fri Mar 20 15:09:31 2009 +0100
@@ -530,7 +530,11 @@
print "No kernel image selected!"
sys.exit(1)
- img = g.cf.images[sel]
+ try:
+ img = g.cf.images[sel]
+ except:
+ log.debug("PyGrub: Default selection is not valid, using first boot configuration...")
+ img = g.cf.images[0]
grubcfg = { "kernel": None, "ramdisk": None, "args": None }
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Make PyGrub run first entry in grub config when invalid default boot option provided
2009-03-20 14:14 [PATCH] Make PyGrub run first entry in grub config when invalid default boot option provided Michal Novotny
@ 2009-03-23 17:08 ` Ian Jackson
2009-03-24 9:21 ` Michal Novotny
0 siblings, 1 reply; 4+ messages in thread
From: Ian Jackson @ 2009-03-23 17:08 UTC (permalink / raw)
To: Michal Novotny; +Cc: xen-devel
Michal Novotny writes ("[Xen-devel] [PATCH] Make PyGrub run first entry in grub config when invalid default boot option provided"):
> - img = g.cf.images[sel]
> + try:
> + img = g.cf.images[sel]
> + except:
It is not correct to do this on all exceptions. (This is a common
mistake in Python.) I assume that in your error case the images array
doesn't have the relevant entry and that your code should read:
+ img = g.cf.images[sel]
+ except KeyError:
Ian.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Make PyGrub run first entry in grub config when invalid default boot option provided
2009-03-23 17:08 ` Ian Jackson
@ 2009-03-24 9:21 ` Michal Novotny
2009-03-24 13:33 ` Ian Jackson
0 siblings, 1 reply; 4+ messages in thread
From: Michal Novotny @ 2009-03-24 9:21 UTC (permalink / raw)
To: Ian Jackson; +Cc: xen-devel
[-- Attachment #1: Type: text/plain, Size: 823 bytes --]
Hi,
thanks for advice. Here's new and corrected version of the patch. Well,
the error here is IndexError, when an error occurs so the IndexError is
catched and not KeyError. I have also tried it with KeyError but it was
not working so IndexError is catched here.
Michal
Ian Jackson wrote:
> Michal Novotny writes ("[Xen-devel] [PATCH] Make PyGrub run first entry in grub config when invalid default boot option provided"):
>
>> - img = g.cf.images[sel]
>> + try:
>> + img = g.cf.images[sel]
>> + except:
>>
>
> It is not correct to do this on all exceptions. (This is a common
> mistake in Python.) I assume that in your error case the images array
> doesn't have the relevant entry and that your code should read:
> + img = g.cf.images[sel]
> + except KeyError:
>
> Ian.
>
[-- Attachment #2: xen-pygrub-invalid-default-configuration.patch --]
[-- Type: text/plain, Size: 449 bytes --]
diff -r e1562a36094e tools/pygrub/src/pygrub
--- a/tools/pygrub/src/pygrub Thu Mar 19 17:04:06 2009 +0000
+++ b/tools/pygrub/src/pygrub Fri Mar 20 15:09:31 2009 +0100
@@ -530,7 +530,11 @@
print "No kernel image selected!"
sys.exit(1)
- img = g.cf.images[sel]
+ try:
+ img = g.cf.images[sel]
+ except IndexError:
+ img = g.cf.images[0]
+
grubcfg = { "kernel": None, "ramdisk": None, "args": None }
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Make PyGrub run first entry in grub config when invalid default boot option provided
2009-03-24 9:21 ` Michal Novotny
@ 2009-03-24 13:33 ` Ian Jackson
0 siblings, 0 replies; 4+ messages in thread
From: Ian Jackson @ 2009-03-24 13:33 UTC (permalink / raw)
To: Michal Novotny; +Cc: xen-devel@lists.xensource.com
Michal Novotny writes ("Re: [Xen-devel] [PATCH] Make PyGrub run first entry in grub config when invalid default boot option provided"):
> thanks for advice. Here's new and corrected version of the patch. Well,
> the error here is IndexError, when an error occurs so the IndexError is
> catched and not KeyError. I have also tried it with KeyError but it was
> not working so IndexError is catched here.
Err, yes, I didn't double-check with the docs or the rest of the
code. Your version is very likely correct.
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Ian.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-03-24 13:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-20 14:14 [PATCH] Make PyGrub run first entry in grub config when invalid default boot option provided Michal Novotny
2009-03-23 17:08 ` Ian Jackson
2009-03-24 9:21 ` Michal Novotny
2009-03-24 13:33 ` Ian Jackson
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.