[PATCH blivet/master 3/4] Add attribute 'flags.lvm_metadata_backup'

Anne Mulhern amulhern at redhat.com
Wed Sep 24 12:59:22 UTC 2014





----- Original Message -----
> From: "Will Woods" <wwoods at redhat.com>
> To: anaconda-patches at lists.fedorahosted.org
> Sent: Tuesday, September 23, 2014 6:14:02 PM
> Subject: [PATCH blivet/master 3/4] Add attribute 'flags.lvm_metadata_backup'
> 
> This adds a flag which - if set to False - will suppress the automatic
> backup of LVM metadata by adding the appropriate configuration options
> (backup.backup=0 and backup.archive=0) to all invocations of LVM.
> 
> It also adds a test case to ensure this actually works.
> ---
>  blivet/devicelibs/lvm.py          |  3 +++
>  blivet/flags.py                   |  4 ++++
>  tests/devicelibs_test/lvm_test.py | 30 +++++++++++++++++++++++++++++-
>  3 files changed, 36 insertions(+), 1 deletion(-)
> 
> diff --git a/blivet/devicelibs/lvm.py b/blivet/devicelibs/lvm.py
> index f1e14f3..f127a60 100644
> --- a/blivet/devicelibs/lvm.py
> +++ b/blivet/devicelibs/lvm.py
> @@ -32,6 +32,7 @@ from .. import util
>  from .. import arch
>  from ..errors import LVMError
>  from ..i18n import _
> +from ..flags import flags
>  
>  MAX_LV_SLOTS = 256
>  
> @@ -93,6 +94,8 @@ def _getConfigArgs(args):
>      config_string = " devices { %s } " % (devices_string) # strings can be
>      added
>      if cmd in READONLY_COMMANDS:
>          config_string += "global {locking_type=4} "
> +    if not flags.lvm_metadata_backup:
> +        config_string += "backup {backup=0 archive=0} "
>      if config_string:
>          config_args = ["--config", config_string]
>      return config_args
> diff --git a/blivet/flags.py b/blivet/flags.py
> index e293794..c89a114 100644
> --- a/blivet/flags.py
> +++ b/blivet/flags.py
> @@ -56,6 +56,10 @@ class Flags(object):
>  
>          self.multipath_friendly_names = True
>  
> +        # set to False to suppress the default LVM behavior of saving
> +        # backup metadata in /etc/lvm/{archive,backup}
> +        self.lvm_metadata_backup = True
> +
>          # whether to include nodev filesystems in the devicetree (only
>          # meaningful when flags.installer_mode is False)
>          self.include_nodev = False
> diff --git a/tests/devicelibs_test/lvm_test.py
> b/tests/devicelibs_test/lvm_test.py
> index 762ac1b..660e26f 100755
> --- a/tests/devicelibs_test/lvm_test.py
> +++ b/tests/devicelibs_test/lvm_test.py
> @@ -1,5 +1,5 @@
>  #!/usr/bin/python
> -import unittest
> +import unittest, glob


It has been our convention to put each import on a separate line. 


>  import blivet.devicelibs.lvm as lvm
>  from blivet.size import Size
> @@ -65,13 +65,41 @@ class
> LVMAsRootTestCaseBase(loopbackedtestcase.LoopBackedTestCase):
>  
>          super(LVMAsRootTestCaseBase, self).tearDown()
>  
> +class LVM_Metadata_Backup_TestCase(LVMAsRootTestCaseBase):
> +    def _list_backups(self):
> +        return set(glob.glob("/etc/lvm/archive/%s_*" % self._vg_name))
>  
> +    def setUp(self):
> +        super(LVM_Metadata_Backup_TestCase, self).setUp()
> +        self._old_backups = self._list_backups()
> +        for dev in self.loopDevices:
> +            lvm.pvcreate(dev)
> +
> +    def test_backup_enabled(self):
> +        lvm.flags.lvm_metadata_backup = True
> +        lvm.vgcreate(self._vg_name, self.loopDevices, Size("4MiB"))
> +
> +        current_backups = self._list_backups()
> +        self.assertTrue(current_backups.issuperset(self._old_backups),
> +                        "old backups disappeared??")
> +        self.assertTrue(current_backups.difference(self._old_backups),
> +                        "lvm_metadata_backup enabled but no backups
> created")
> +
> +    def test_backup_disabled(self):
> +        lvm.flags.lvm_metadata_backup = False
> +        lvm.vgcreate(self._vg_name, self.loopDevices, Size("4MiB"))
> +
> +        self.assertEqual(self._old_backups, self._list_backups(),
> +                         "lvm_metadata_backup disabled but backups created")
>  
>  class LVMAsRootTestCase(LVMAsRootTestCaseBase):
>      def testLVM(self):
>          _LOOP_DEV0 = self.loopDevices[0]
>          _LOOP_DEV1 = self.loopDevices[1]
>  
> +        # let's not create a bunch of junk on the host

One man's poison is another man's meat.

> +        lvm.flags.lvm_metadata_backup = False
> +
>          ##
>          ## pvcreate
>          ##
> --
> 1.9.3
> 
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> 

- mulhern


More information about the anaconda-patches mailing list