From 6d1aaa134cfe9f075afa0816048e29984bf92b69 Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Thu, 3 Nov 2016 13:58:40 -0700 Subject: [PATCH 1/2] Handle unformatted/corrupted partition tables, see SWL-3246 - handle more pyparted exceptions - properly clobber the disk signature --- .../src/python/onl/install/BaseInstall.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py b/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py index bb60b0b7..45da8857 100644 --- a/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py @@ -21,6 +21,14 @@ from InstallUtils import ProcMountsParser import onl.YamlUtils from onl.sysconfig import sysconfig +try: + PartedException = parted._ped.PartedException + DiskException = parted._ped.DiskException +except AttributeError: + import _ped + PartedException = _ped.PartedException + DiskException = _ped.DiskException + class Base: class installmeta: @@ -686,11 +694,17 @@ class UbootInstaller(SubprocessMixin, Base): return 0 self.log.warn("disk %s has wrong label %s", self.device, self.partedDisk.type) - except Exception as ex: + except (DiskException, PartedException) as ex: self.log.error("cannot get partition table from %s: %s", self.device, str(ex)) + except Exception as ex: + self.log.exception("cannot get partition table from %s: %s", + self.device) - self.log.info("creating msdos label on %s") + self.log.info("clobbering disk label on %s", self.device) + self.partedDevice.clobber() + + self.log.info("creating msdos label on %s", self.device) self.partedDisk = parted.freshDisk(self.partedDevice, 'msdos') return 0 From a676d8ed2cbc450dadadf62d0696d03c66163868 Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Fri, 4 Nov 2016 12:53:48 -0700 Subject: [PATCH 2/2] Fixed exception handler and log message --- .../vendor-config-onl/src/python/onl/install/BaseInstall.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py b/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py index 45da8857..ec65e5e2 100644 --- a/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py @@ -697,8 +697,8 @@ class UbootInstaller(SubprocessMixin, Base): except (DiskException, PartedException) as ex: self.log.error("cannot get partition table from %s: %s", self.device, str(ex)) - except Exception as ex: - self.log.exception("cannot get partition table from %s: %s", + except Exception: + self.log.exception("cannot get partition table from %s", self.device) self.log.info("clobbering disk label on %s", self.device)