Skip to content

Commit

Permalink
Merge pull request #1169 from vojtechtrefny/3.9-devel_lvmdevices-flag
Browse files Browse the repository at this point in the history
Add flag to control LVM devices file support
  • Loading branch information
vojtechtrefny authored Nov 22, 2023
2 parents 238c2c9 + 59e132b commit 793ec72
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions blivet/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions blivet/formats/lvmpv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions tests/unit_tests/formats_tests/lvmpv_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import unittest

from blivet.formats.lvmpv import LVMPhysicalVolume
from blivet.flags import flags


class LVMPVNodevTestCase(unittest.TestCase):
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions tests/unit_tests/formats_tests/methods_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 793ec72

Please sign in to comment.