Michal Novotny
2009-Mar-20 14:14 UTC
[Xen-devel] [PATCH] Make PyGrub run first entry in grub config when invalid default boot option provided
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> _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Jackson
2009-Mar-23 17:08 UTC
Re: [Xen-devel] [PATCH] Make PyGrub run first entry in grub config when invalid default boot option provided
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. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Michal Novotny
2009-Mar-24 09:21 UTC
Re: [Xen-devel] [PATCH] Make PyGrub run first entry in grub config when invalid default boot option provided
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. >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Jackson
2009-Mar-24 13:33 UTC
Re: [Xen-devel] [PATCH] Make PyGrub run first entry in grub config when invalid default boot option provided
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. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel