[PATCH 4/4] Fix a couple of problems with the examples.

David Lehman dlehman at redhat.com
Fri Nov 15 14:39:50 UTC 2013


pvcreate/pvdestroy were failing if lvmetad wasn't running

DeviceTree.teardownAll doesn't do anything except in installer_mode.
This is probably wrong, but more importantly it prevented teardown
of the disk image stacks on exit, which leaves a mess.
---
 blivet/formats/lvmpv.py | 23 ++++++++++++++++++++---
 examples/common.py      |  3 +++
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/blivet/formats/lvmpv.py b/blivet/formats/lvmpv.py
index 4111ad0..d0d8226 100644
--- a/blivet/formats/lvmpv.py
+++ b/blivet/formats/lvmpv.py
@@ -27,6 +27,7 @@ from parted import PARTITION_LVM
 from ..errors import *
 from ..devicelibs import lvm
 from . import DeviceFormat, register_device_format
+from ..flags import flags
 
 import gettext
 _ = lambda x: gettext.ldgettext("blivet", x)
@@ -110,12 +111,23 @@ class LVMPhysicalVolume(DeviceFormat):
             # lvm has issues with persistence of metadata, so here comes the
             # hammer...
             DeviceFormat.destroy(self, *args, **kwargs)
-            lvm.pvscan(self.device)
+            try:
+                lvm.pvscan(self.device)
+            except LVMError as e:
+                log.error("%s", e)
+                if flags.installer_mode:
+                    raise
+
             lvm.pvcreate(self.device)
         except Exception:
             raise
         finally:
-            lvm.pvscan(self.device)
+            try:
+                lvm.pvscan(self.device)
+            except LVMError as e:
+                log.error("%s", e)
+                if flags.installer_mode:
+                    raise
 
         self.exists = True
         self.notifyKernel()
@@ -136,7 +148,12 @@ class LVMPhysicalVolume(DeviceFormat):
         except LVMError:
             DeviceFormat.destroy(self, *args, **kwargs)
         finally:
-            lvm.pvscan(self.device)
+            try:
+                lvm.pvscan(self.device)
+            except LVMError as e:
+                log.error("%s", e)
+                if flags.installer_mode:
+                    raise
 
         self.exists = False
         self.notifyKernel()
diff --git a/examples/common.py b/examples/common.py
index 467df98..93f813a 100644
--- a/examples/common.py
+++ b/examples/common.py
@@ -32,7 +32,10 @@ def create_sparse_file(b, name, size):
 
 def tear_down_disk_images(b):
     """ Tear down any disk image stacks. """
+    from blivet.flags import flags
+    flags.installer_mode = True
     b.devicetree.teardownAll()
+    flags.installer_mode = False
     for (name, path) in b.config.diskImages.items():
         dm_device = b.devicetree.getDeviceByName(name)
         if not dm_device:
-- 
1.8.1.4



More information about the anaconda-patches mailing list