neil / rpms / python-blivet

Forked from rpms/python-blivet a year ago
Clone

Blame SOURCES/0015-ActionDestroyDevice-should-not-obsolete-ActionRemove.patch

2a10b1
From 950f51a4cc041fe1b8a98b17e4828857b7423e55 Mon Sep 17 00:00:00 2001
2a10b1
From: Vojtech Trefny <vtrefny@redhat.com>
2a10b1
Date: Wed, 13 Apr 2022 15:43:45 +0200
2a10b1
Subject: [PATCH] ActionDestroyDevice should not obsolete ActionRemoveMember
2a10b1
2a10b1
If we want to remove a PV from a VG and then remove the PV device,
2a10b1
the ActionDestroyDevice must not obsolete the ActionRemoveMember
2a10b1
action. Eventhough we are going to remove the device, we still
2a10b1
need to call "vgreduce" first.
2a10b1
2a10b1
Resolves: rhbz#2076958
2a10b1
---
2a10b1
 blivet/deviceaction.py | 10 +++++-----
2a10b1
 tests/action_test.py   |  7 +++++++
2a10b1
 2 files changed, 12 insertions(+), 5 deletions(-)
2a10b1
2a10b1
diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py
2a10b1
index 0458e4be..78e113bf 100644
2a10b1
--- a/blivet/deviceaction.py
2a10b1
+++ b/blivet/deviceaction.py
2a10b1
@@ -463,8 +463,8 @@ class ActionDestroyDevice(DeviceAction):
2a10b1
             - obsoletes all actions w/ lower id that act on the same device,
2a10b1
               including self, if device does not exist
2a10b1
 
2a10b1
-            - obsoletes all but ActionDestroyFormat actions w/ lower id on the
2a10b1
-              same device if device exists
2a10b1
+            - obsoletes all but ActionDestroyFormat and ActionRemoveMember actions
2a10b1
+              w/ lower id on the same device if device exists
2a10b1
 
2a10b1
             - obsoletes all actions that add a member to this action's
2a10b1
               (container) device
2a10b1
@@ -474,9 +474,9 @@ class ActionDestroyDevice(DeviceAction):
2a10b1
         if action.device.id == self.device.id:
2a10b1
             if self.id >= action.id and not self.device.exists:
2a10b1
                 rc = True
2a10b1
-            elif self.id > action.id and \
2a10b1
-                    self.device.exists and \
2a10b1
-                    not (action.is_destroy and action.is_format):
2a10b1
+            elif self.id > action.id and self.device.exists and \
2a10b1
+                    not ((action.is_destroy and action.is_format) or
2a10b1
+                         action.is_remove):
2a10b1
                 rc = True
2a10b1
             elif action.is_add and (action.device == self.device):
2a10b1
                 rc = True
2a10b1
diff --git a/tests/action_test.py b/tests/action_test.py
2a10b1
index 1e84c20b..b3608047 100644
2a10b1
--- a/tests/action_test.py
2a10b1
+++ b/tests/action_test.py
2a10b1
@@ -1198,6 +1198,13 @@ class DeviceActionTestCase(StorageTestCase):
2a10b1
         self.assertEqual(create_sdc2.requires(remove_sdc1), False)
2a10b1
         self.assertEqual(remove_sdc1.requires(create_sdc2), False)
2a10b1
 
2a10b1
+        # destroy sdc1, the ActionRemoveMember should not be obsoleted
2a10b1
+        sdc1.exists = True
2a10b1
+        destroy_sdc1 = ActionDestroyDevice(sdc1)
2a10b1
+        destroy_sdc1.apply()
2a10b1
+        self.assertFalse(destroy_sdc1.obsoletes(remove_sdc1))
2a10b1
+        self.assertTrue(destroy_sdc1.requires(remove_sdc1))
2a10b1
+
2a10b1
     def test_action_sorting(self, *args, **kwargs):
2a10b1
         """ Verify correct functioning of action sorting. """
2a10b1
 
2a10b1
-- 
2a10b1
2.35.3
2a10b1