[PATCH 2/5] The first format destroy action should obsolete any others.

David Lehman dlehman at redhat.com
Tue Sep 16 21:01:50 UTC 2014


The first one is the only one that knows that actual existing format it
needs to destroy.

The other rules for ActionDestroyFormat are preserved.

Fedora:
Related: rhbz#1121383

RHEL:
Related: rhbz#1075671
Related: rhbz#1085201
---
 blivet/deviceaction.py | 27 ++++++++++++++++++++-------
 tests/action_test.py   |  6 +++++-
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py
index db4c7a7..2057957 100644
--- a/blivet/deviceaction.py
+++ b/blivet/deviceaction.py
@@ -669,18 +669,31 @@ class ActionDestroyFormat(DeviceAction):
 
             Format destroy actions obsolete the following actions:
 
-            - format actions w/ lower id on same device, including self if
-              format does not exist
+            - non-destroy format actions w/ lower id on same device, including
+              self if format does not exist
+
+            - destroy format action w/ higher id on same device
 
             - format destroy action on a non-existent format shouldn't
               obsolete a format destroy action on an existing one
         """
-        return (self.device.id == action.device.id and
-                self.obj == action.obj and
-                (self.id > action.id or
-                 (self.id == action.id and not self.format.exists)) and
-                not (action.format.exists and not self.format.exists))
+        retval = False
+        same_device = self.device.id == action.device.id
+        format_action = self.obj == action.obj
+        if same_device and format_action:
+            if action.isDestroy:
+                if self.format.exists and not action.format.exists:
+                    retval = True
+                elif not self.format.exists and action.format.exists:
+                    retval = False
+                elif self.id == action.id and not self.format.exists:
+                    retval = True
+                else:
+                    retval = self.id < action.id
+            else:
+                retval = self.id > action.id
 
+        return retval
 
 class ActionResizeFormat(DeviceAction):
     """ An action representing the resizing of an existing filesystem.
diff --git a/tests/action_test.py b/tests/action_test.py
index fc96355..6e99a9f 100644
--- a/tests/action_test.py
+++ b/tests/action_test.py
@@ -413,13 +413,17 @@ class DeviceActionTestCase(StorageTestCase):
 
         # ActionDestroyFormat
         #
-        # - obsoletes all format actions w/ lower id on same device (including
+        # - obsoletes all format actions w/ higher id on same device (including
         #   self if format does not exist)
         destroy_format_1 = ActionDestroyFormat(sdc1)
         destroy_format_1.apply()
+        destroy_format_2 = ActionDestroyFormat(sdc1)
+        destroy_format_2.apply()
         self.assertEqual(destroy_format_1.obsoletes(create_format_1), True)
         self.assertEqual(destroy_format_1.obsoletes(resize_format_1), True)
         self.assertEqual(destroy_format_1.obsoletes(destroy_format_1), True)
+        self.assertEqual(destroy_format_2.obsoletes(destroy_format_1), False)
+        self.assertEqual(destroy_format_1.obsoletes(destroy_format_2), True)
 
         # ActionDestroyDevice
         #
-- 
1.9.3



More information about the anaconda-patches mailing list