[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] tools/pygrub: Fix error handling if no valid partitions are found

If no partitions at all are found, pygrub never creates the name 'fs',
resulting in a NameError indicating the lack of fs, rather than a
RuntimeError explaining that no partitions were found.

Set fs to None right at the start, and use the pythonic idiom "if fs is None:"
to protect against otherwise valid values for fs which compare equal to

Reported-by: Sven KÃhler <sven.koehler@xxxxxxxxx>
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CC: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
CC: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>

 tools/pygrub/src/pygrub |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/pygrub/src/pygrub b/tools/pygrub/src/pygrub
index 54fecee..4c35f9d 100644
--- a/tools/pygrub/src/pygrub
+++ b/tools/pygrub/src/pygrub
@@ -747,7 +747,7 @@ if __name__ == "__main__":
     file = args[0]
+    fs = None
     output = None
     entry = None
     interactive = True
@@ -869,7 +869,7 @@ if __name__ == "__main__":
     # Did looping through partitions find us a kernel?
-    if not fs:
+    if fs is None:
         raise RuntimeError, "Unable to find partition containing kernel"
     bootcfg["kernel"] = copy_from_image(fs, chosencfg["kernel"], "kernel",

Xen-devel mailing list



Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.