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