From 5b358f0c662cffbfece7e6aa61e10bffa14c95d9 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Fri, 3 May 2024 14:03:02 +0200 Subject: [PATCH] Clear VG UUID from PVs after removing the PV (#2278058) --- blivet/devices/lvm.py | 2 ++ tests/storage_tests/devices_test/lvm_test.py | 9 +++++++++ tests/unit_tests/devices_test/lvm_test.py | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/blivet/devices/lvm.py b/blivet/devices/lvm.py index db42328ac..661881ea9 100644 --- a/blivet/devices/lvm.py +++ b/blivet/devices/lvm.py @@ -667,6 +667,7 @@ def remove_hook(self, modparent=True): if modparent: for pv in self.pvs: pv.format.vg_name = None + pv.format.vg_uuid = None super(LVMVolumeGroupDevice, self).remove_hook(modparent=modparent) @@ -677,6 +678,7 @@ def add_hook(self, new=True): for pv in self.pvs: pv.format.vg_name = self.name + pv.format.vg_uuid = self.uuid def populate_ksdata(self, data): super(LVMVolumeGroupDevice, self).populate_ksdata(data) diff --git a/tests/storage_tests/devices_test/lvm_test.py b/tests/storage_tests/devices_test/lvm_test.py index d543d4596..f64af8943 100644 --- a/tests/storage_tests/devices_test/lvm_test.py +++ b/tests/storage_tests/devices_test/lvm_test.py @@ -81,6 +81,7 @@ def test_lvm_basic(self): self.assertIsNotNone(vg.format) self.assertIsNone(vg.format.type) self.assertEqual(pv.format.vg_name, vg.name) + self.assertEqual(pv.format.vg_uuid, vg.uuid) self.assertEqual(len(vg.parents), 1) self.assertEqual(vg.parents[0], pv) @@ -93,6 +94,13 @@ def test_lvm_basic(self): self.assertEqual(len(lv.parents), 1) self.assertEqual(lv.parents[0], vg) + self.storage.destroy_device(lv) + self.storage.destroy_device(vg) + + pv = self.storage.devicetree.get_device_by_path(self.vdevs[0] + "1") + self.assertIsNone(pv.format.vg_name) + self.assertIsNone(pv.format.vg_uuid) + def test_lvm_thin(self): disk = self.storage.devicetree.get_device_by_path(self.vdevs[0]) self.assertIsNotNone(disk) @@ -398,6 +406,7 @@ def test_lvm_pvs_add_remove(self): self.storage.devicetree.actions.add(ac) self.assertIsNone(pv1.format.vg_name) + self.assertIsNone(pv1.format.vg_uuid) # schedule also removing the lvmpv format from the PV ac = blivet.deviceaction.ActionDestroyFormat(pv1) diff --git a/tests/unit_tests/devices_test/lvm_test.py b/tests/unit_tests/devices_test/lvm_test.py index 26fcd7abb..ed30772fd 100644 --- a/tests/unit_tests/devices_test/lvm_test.py +++ b/tests/unit_tests/devices_test/lvm_test.py @@ -558,13 +558,14 @@ def test_add_remove_pv(self): size=Size("1024 MiB")) pv2 = StorageDevice("pv2", fmt=blivet.formats.get_format("lvmpv"), size=Size("1024 MiB")) - vg = LVMVolumeGroupDevice("testvg", parents=[pv1]) + vg = LVMVolumeGroupDevice("testvg", parents=[pv1], uuid="b0bf62ba-2a96-437e-8299-b0c5fffc43bb") vg._add_parent(pv2) self.assertEqual(pv2.format.vg_name, vg.name) vg._remove_parent(pv2) self.assertEqual(pv2.format.vg_name, None) + self.assertEqual(pv2.format.vg_uuid, None) def test_device_id(self): pv = StorageDevice("pv1", fmt=blivet.formats.get_format("lvmpv"),