[blivet][master] Make sure devices are always torn down in findExistingInstallations if requested

Vratislav Podzimek vpodzime at redhat.com
Wed Sep 9 10:44:19 UTC 2015


It's not that uncommon that findExistingInstallations() raises an
exception. Even in such case we need to tear all devices down if requested. Also
such exceptions should be just logged and not propagated as this function is a
"best-effort" one.

(port of commits bbe124c94772cb3313a05e9a00a663f75084be55 and
71f77ec0e7f657a3e9bffd03b859e845b2598eb7 from rhel7-branch merged together)

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 blivet/blivet.py    |  6 +-----
 blivet/osinstall.py | 19 ++++++++++++++++++-
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/blivet/blivet.py b/blivet/blivet.py
index f555ec2..f232f71 100644
--- a/blivet/blivet.py
+++ b/blivet/blivet.py
@@ -286,11 +286,7 @@ class Blivet(object):
 
         self.roots = []
         if flags.installer_mode:
-            try:
-                self.roots = findExistingInstallations(self.devicetree)
-            except Exception: # pylint: disable=broad-except
-                log_exception_info(log.info, "failure detecting existing installations")
-
+            self.roots = findExistingInstallations(self.devicetree)
             self.dumpState("initial")
 
         if not flags.installer_mode:
diff --git a/blivet/osinstall.py b/blivet/osinstall.py
index bb7c204..fb4e6f6 100644
--- a/blivet/osinstall.py
+++ b/blivet/osinstall.py
@@ -196,7 +196,24 @@ def parseFSTab(devicetree, chroot=None):
 
     return (mounts, swaps)
 
-def findExistingInstallations(devicetree):
+def findExistingInstallations(devicetree, teardown_all=True):
+    """Find existing GNU/Linux installations on devices from the devicetree.
+    :param devicetree: devicetree to find existing installations in
+    :type devicetree: :class:`~.devicetree.DeviceTree`
+    :param bool teardown_all: whether to tear down all devices in the
+                              devicetree in the end
+
+    """
+    try:
+        roots = _findExistingInstallations(devicetree)
+        return roots
+    except Exception: # pylint: disable=broad-except
+        log_exception_info(log.info, "failure detecting existing installations")
+    finally:
+        if teardown_all:
+            devicetree.teardownAll()
+
+def _findExistingInstallations(devicetree):
     if not os.path.exists(getTargetPhysicalRoot()):
         util.makedirs(getTargetPhysicalRoot())
 
-- 
2.1.0



More information about the anaconda-patches mailing list