[PATCH 4/4] Fix a couple of problems with the examples.
Brian C. Lane
bcl at redhat.com
Sat Nov 16 01:46:03 UTC 2013
On Fri, Nov 15, 2013 at 08:39:50AM -0600, David Lehman wrote:
> 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
What do you think about adding something like a 'force=True' argument to
teardownAll instead. It would make it easier to document the behavior at
least.
I'm not too comfortable with embedding more behavior differences based on
the installer_mode flag but I'm also not sure what else we could do in
cases where the installer needs the error info and other users don't.
--
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)
More information about the anaconda-patches
mailing list