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