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

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