Blame SOURCES/0016-Correctly-set-vg_name-after-adding-removing-a-PV-fro.patch

5b80eb
From a9cb01f948fa5371b3e6f9282e7af81aec5cb1a8 Mon Sep 17 00:00:00 2001
5b80eb
From: Vojtech Trefny <vtrefny@redhat.com>
5b80eb
Date: Mon, 2 May 2022 15:30:16 +0200
5b80eb
Subject: [PATCH] Correctly set vg_name after adding/removing a PV from a VG
5b80eb
5b80eb
Without setting the LVMPhysicalVolume.vg_name argument to None
5b80eb
after removing the PV from its VG, the PV is still considered
5b80eb
active and cannot be removed.
5b80eb
5b80eb
Resolves: rhbz#2081276
5b80eb
---
5b80eb
 blivet/devices/lvm.py          |  3 +++
5b80eb
 tests/devices_test/lvm_test.py | 13 +++++++++++++
5b80eb
 2 files changed, 16 insertions(+)
5b80eb
5b80eb
diff --git a/blivet/devices/lvm.py b/blivet/devices/lvm.py
5b80eb
index c61eeb4b..7c78c813 100644
5b80eb
--- a/blivet/devices/lvm.py
5b80eb
+++ b/blivet/devices/lvm.py
5b80eb
@@ -385,6 +385,8 @@ class LVMVolumeGroupDevice(ContainerDevice):
5b80eb
         if not parent.format.exists:
5b80eb
             parent.format.free = self._get_pv_usable_space(parent)
5b80eb
 
5b80eb
+        parent.format.vg_name = self.name
5b80eb
+
5b80eb
     def _remove_parent(self, parent):
5b80eb
         # XXX It would be nice to raise an exception if removing this member
5b80eb
         #     would not leave enough space, but the devicefactory relies on it
5b80eb
@@ -395,6 +397,7 @@ class LVMVolumeGroupDevice(ContainerDevice):
5b80eb
         super(LVMVolumeGroupDevice, self)._remove_parent(parent)
5b80eb
         parent.format.free = None
5b80eb
         parent.format.container_uuid = None
5b80eb
+        parent.format.vg_name = None
5b80eb
 
5b80eb
     # We can't rely on lvm to tell us about our size, free space, &c
5b80eb
     # since we could have modifications queued, unless the VG and all of
5b80eb
diff --git a/tests/devices_test/lvm_test.py b/tests/devices_test/lvm_test.py
5b80eb
index 336c5b99..c349f003 100644
5b80eb
--- a/tests/devices_test/lvm_test.py
5b80eb
+++ b/tests/devices_test/lvm_test.py
5b80eb
@@ -453,6 +453,19 @@ class LVMDeviceTest(unittest.TestCase):
5b80eb
         pool.autoset_md_size(enforced=True)
5b80eb
         self.assertEqual(pool.chunk_size, Size("128 KiB"))
5b80eb
 
5b80eb
+    def test_add_remove_pv(self):
5b80eb
+        pv1 = StorageDevice("pv1", fmt=blivet.formats.get_format("lvmpv"),
5b80eb
+                            size=Size("1024 MiB"))
5b80eb
+        pv2 = StorageDevice("pv2", fmt=blivet.formats.get_format("lvmpv"),
5b80eb
+                            size=Size("1024 MiB"))
5b80eb
+        vg = LVMVolumeGroupDevice("testvg", parents=[pv1])
5b80eb
+
5b80eb
+        vg._add_parent(pv2)
5b80eb
+        self.assertEqual(pv2.format.vg_name, vg.name)
5b80eb
+
5b80eb
+        vg._remove_parent(pv2)
5b80eb
+        self.assertEqual(pv2.format.vg_name, None)
5b80eb
+
5b80eb
 
5b80eb
 class TypeSpecificCallsTest(unittest.TestCase):
5b80eb
     def test_type_specific_calls(self):
5b80eb
-- 
5b80eb
2.35.3
5b80eb