Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not remove PVs from devices file if disabled or doesn't exists #1333

Open
wants to merge 1 commit into
base: rhel10-branch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions blivet/formats/lvmpv.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ def lvmdevices_remove(self):
if not lvm.HAVE_LVMDEVICES:
raise PhysicalVolumeError("LVM devices file feature is not supported")

if not os.path.exists(lvm.LVM_DEVICES_FILE):
log.debug("Not removing %s from devices file: %s doesn't exist",
self.device, lvm.LVM_DEVICES_FILE)
return

if not flags.lvm_devices_file:
log.debug("Not removing %s from devices file: 'lvm_devices_file' flag is set to False",
self.device)
return

try:
blockdev.lvm.devices_delete(self.device)
except blockdev.LVMError as e:
Expand Down
28 changes: 28 additions & 0 deletions tests/unit_tests/formats_tests/lvmpv_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def test_lvm_devices(self):

mock["blockdev"].lvm.devices_add.assert_not_called()

# LVM devices file not enabled/supported -> devices_delete should not be called
fmt._destroy()

mock["blockdev"].lvm.devices_delete.assert_not_called()

with self.patches() as mock:
# LVM devices file enabled and devices file exists -> devices_add should be called
mock["lvm"].HAVE_LVMDEVICES = True
Expand All @@ -47,6 +52,11 @@ def test_lvm_devices(self):

mock["blockdev"].lvm.devices_add.assert_called_with("/dev/test")

# LVM devices file enabled and devices file exists -> devices_delete should be called
fmt._destroy()

mock["blockdev"].lvm.devices_delete.assert_called_with("/dev/test")

with self.patches() as mock:
# LVM devices file enabled and devices file doesn't exist
# and no existing VGs present -> devices_add should be called
Expand All @@ -58,6 +68,12 @@ def test_lvm_devices(self):

mock["blockdev"].lvm.devices_add.assert_called_with("/dev/test")

# LVM devices file enabled but devices file doesn't exist
# -> devices_delete should not be called
fmt._destroy()

mock["blockdev"].lvm.devices_delete.assert_not_called()

with self.patches() as mock:
# LVM devices file enabled and devices file doesn't exist
# and existing VGs present -> devices_add should not be called
Expand All @@ -69,6 +85,12 @@ def test_lvm_devices(self):

mock["blockdev"].lvm.devices_add.assert_not_called()

# LVM devices file enabled but devices file doesn't exist
# -> devices_delete should not be called
fmt._destroy()

mock["blockdev"].lvm.devices_delete.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
Expand All @@ -81,5 +103,11 @@ def test_lvm_devices(self):

mock["blockdev"].lvm.devices_add.assert_not_called()

# LVM devices file enabled and devices file exists
# but flag set to false -> devices_delete should not be called
fmt._destroy()

mock["blockdev"].lvm.devices_delete.assert_not_called()

# reset the flag back
flags.lvm_devices_file = True