Catch parted returning None as the searched partition
authorEvgeni Golov <evgeni@grml.org>
Mon, 28 Sep 2015 15:37:06 +0000 (17:37 +0200)
committerMichael Prokop <mika@grml.org>
Mon, 28 Sep 2015 16:08:02 +0000 (18:08 +0200)
Certain USB devices aren't handled correctly by
python-parted. As soon as the USB devices are
filled/rewritten with zeros (dd if=/dev/zero of=/dev/sdX)
they are recognized properly. The underlying issue
couldn't be identified yet, but since we know what
we get let's just fall back to the old boot device
detection and print an according warning message.

Thanks: to mika and Haudegen for debugging
Closes: #766964

grml2usb

index cb841c5..2f63ce1 100755 (executable)
--- a/grml2usb
+++ b/grml2usb
@@ -134,6 +134,12 @@ if not os.path.isdir(GRML2USB_BASE):
     GRML2USB_BASE = os.path.dirname(os.path.realpath(__file__))
 
 
     GRML2USB_BASE = os.path.dirname(os.path.realpath(__file__))
 
 
+class HodorException(Exception):
+    """Throw exception if the exact error is not known and not fatal.
+
+    @Exception: message"""
+
+
 class CriticalException(Exception):
     """Throw critical exception if the exact error is not known but fatal.
 
 class CriticalException(Exception):
     """Throw critical exception if the exact error is not known but fatal.
 
@@ -356,9 +362,13 @@ def check_boot_flag(device):
     try:
         import parted
         part = get_partition_for_path(device)
     try:
         import parted
         part = get_partition_for_path(device)
+        if part is None:
+            raise HodorException("parted could not find partition")
         if part.getFlag(parted.PARTITION_BOOT):
             logging.debug("bootflag is enabled on %s" % device)
             return
         if part.getFlag(parted.PARTITION_BOOT):
             logging.debug("bootflag is enabled on %s" % device)
             return
+    except HodorException, e:
+        logging.info("%s, falling back to old bootflag detection", e)
     except ImportError, e:
         logging.debug("could not import parted, falling back to old bootflag detection")
 
     except ImportError, e:
         logging.debug("could not import parted, falling back to old bootflag detection")