diff --git a/blivet/flags.py b/blivet/flags.py index e1f2279b2..66edf01ca 100644 --- a/blivet/flags.py +++ b/blivet/flags.py @@ -71,6 +71,9 @@ def __init__(self): # backup metadata in /etc/lvm/{archive,backup} self.lvm_metadata_backup = True + # set to False to not write new LVM PVs to /etc/lvm/devices/system.devices + self.lvm_devices_file = True + # whether to include nodev filesystems in the devicetree self.include_nodev = False diff --git a/blivet/formats/lvmpv.py b/blivet/formats/lvmpv.py index b72ea519e..142e37b82 100644 --- a/blivet/formats/lvmpv.py +++ b/blivet/formats/lvmpv.py @@ -37,6 +37,7 @@ from . import DeviceFormat, register_device_format from .. import udev from ..static_data.lvm_info import pvs_info, vgs_info +from ..flags import flags import logging log = logging.getLogger("blivet") @@ -136,6 +137,10 @@ def lvmdevices_add(self, force=True): self.device, lvm.LVM_DEVICES_FILE) return + if not flags.lvm_devices_file: + log.debug("Not adding %s to devices file: 'lvm_devices_file' flag is set to False", self.device) + return + try: blockdev.lvm.devices_add(self.device) except blockdev.LVMError as e: diff --git a/tests/unit_tests/formats_tests/lvmpv_test.py b/tests/unit_tests/formats_tests/lvmpv_test.py index 6490c7d48..2d22d2f1d 100644 --- a/tests/unit_tests/formats_tests/lvmpv_test.py +++ b/tests/unit_tests/formats_tests/lvmpv_test.py @@ -8,6 +8,7 @@ import unittest from blivet.formats.lvmpv import LVMPhysicalVolume +from blivet.flags import flags class LVMPVNodevTestCase(unittest.TestCase): @@ -71,3 +72,18 @@ def test_lvm_devices(self): fmt._create() mock["blockdev"].lvm.devices_add.assert_not_called() + + with self.patches() as mock: + # LVM devices file enabled and devices file exists + # but flag set to false -> devices_add should not be called + mock["lvm"].HAVE_LVMDEVICES = True + mock["os"].path.exists.return_value = True + mock["vgs_info"].cache = {} + flags.lvm_devices_file = False + + fmt._create() + + mock["blockdev"].lvm.devices_add.assert_not_called() + + # reset the flag back + flags.lvm_devices_file = True diff --git a/tests/unit_tests/formats_tests/methods_test.py b/tests/unit_tests/formats_tests/methods_test.py index f9e2aebf7..48d0a35c3 100644 --- a/tests/unit_tests/formats_tests/methods_test.py +++ b/tests/unit_tests/formats_tests/methods_test.py @@ -388,6 +388,7 @@ class LVMPhysicalVolumeMethodsTestCase(FormatMethodsTestCase): def set_patches(self): super(LVMPhysicalVolumeMethodsTestCase, self).set_patches() self.patchers["blockdev"] = patch("blivet.formats.lvmpv.blockdev") + self.patchers["vgs_info"] = patch("blivet.formats.lvmpv.vgs_info") def _test_destroy_backend(self): self.format.exists = True