[PATCH 7/9] Make sorting by action type part of the action classes.

David Lehman dlehman at redhat.com
Thu Mar 20 17:14:11 UTC 2014


---
 blivet/deviceaction.py | 16 +++++++++-------
 blivet/devicetree.py   |  2 +-
 tests/action_test.py   | 21 +++++++++++++++++++++
 3 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py
index 569377a..089b3a7 100644
--- a/blivet/deviceaction.py
+++ b/blivet/deviceaction.py
@@ -252,7 +252,8 @@ class DeviceAction(util.ObjectID):
 
     def requires(self, action):
         """ Return True if self requires action. """
-        return False
+        return (not (self.isContainer or action.isContainer) and
+                self.type < action.type)
 
     def obsoletes(self, action):
         """ Return True is self obsoletes action.
@@ -293,7 +294,7 @@ class ActionCreateDevice(DeviceAction):
                   and this partition has a higher number
                 - the other action adds a member to this device's container
         """
-        rc = False
+        rc = super(ActionCreateDevice, self).requires(action)
         if self.device.dependsOn(action.device):
             rc = True
         elif (action.isCreate and action.isDevice and
@@ -349,7 +350,7 @@ class ActionDestroyDevice(DeviceAction):
                   and this partition has a lower number
                 - the other action removes this action's device from a container
         """
-        rc = False
+        rc = super(ActionDestroyDevice, self).requires(action)
         if action.device.dependsOn(self.device) and action.isDestroy:
             rc = True
         elif (action.isDestroy and action.isDevice and
@@ -449,7 +450,7 @@ class ActionResizeDevice(DeviceAction):
                 - the other action removes this action's device from a container
                 - the other action adds a member to this device's container
         """
-        retval = False
+        retval = super(ActionResizeDevice, self).requires(action)
         if action.isResize:
             if self.device.id == action.device.id and \
                self.dir == action.dir and \
@@ -532,7 +533,8 @@ class ActionCreateFormat(DeviceAction):
                 - the other action is a create or resize of this action's
                   device
         """
-        return ((self.device.dependsOn(action.device) and
+        return (super(ActionCreateFormat, self).requires(action) or
+                (self.device.dependsOn(action.device) and
                  not ((action.isDestroy and action.isDevice) or
                       action.isContainer)) or
                 (action.isDevice and (action.isCreate or action.isResize) and
@@ -588,7 +590,7 @@ class ActionDestroyFormat(DeviceAction):
                   and the other action is a destroy action
                 - the other action removes this action's device from a container
         """
-        retval = False
+        retval = super(ActionDestroyFormat, self).requires(action)
         if action.device.dependsOn(self.device) and action.isDestroy:
             retval = True
         elif (action.isRemove and action.device == self.device):
@@ -661,7 +663,7 @@ class ActionResizeFormat(DeviceAction):
                   action's device depends on
                 - the other action removes this action's device from a container
         """
-        retval = False
+        retval = super(ActionResizeFormat, self).requires(action)
         if action.isResize:
             if self.device.id == action.device.id and \
                self.dir == action.dir and \
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index 8f2be91..c18c375 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -190,7 +190,7 @@ class DeviceTree(object):
                     continue
 
                 # create edges based on both action type and dependencies.
-                if action.type > _action.type or _action.requires(action):
+                if _action.requires(action):
                     children.append(_action)
 
             for child in children:
diff --git a/tests/action_test.py b/tests/action_test.py
index e063fba..23d9f3c 100644
--- a/tests/action_test.py
+++ b/tests/action_test.py
@@ -914,6 +914,19 @@ class DeviceActionTestCase(StorageTestCase):
         self.assertEqual(destroy_pv_format.requires(destroy_lv_format), True)
         self.assertEqual(destroy_lv_format.requires(destroy_pv_format), False)
 
+        sdc2 = self.newDevice(device_class=PartitionDevice, name="sdc2",
+                              size=Size(spec="5 GiB"), parents=[sdc])
+        create_sdc2 = self.scheduleCreateDevice(device=sdc2)
+
+        # create actions should always require destroy actions -- even for
+        # unrelated devices -- since, after pruning, it should always be the
+        # case that destroy actions are processed before create actions (no
+        # create/destroy loops are allowed)
+        self.assertEqual(create_sdc2.requires(destroy_lv), True)
+
+        # similarly, create actions should also require resize actions
+        self.assertEqual(create_sdc2.requires(grow_lv), True)
+
     def testContainerActions(self):
         self.destroyAllDevices()
         sda = self.storage.devicetree.getDeviceByName("sda")
@@ -1010,6 +1023,14 @@ class DeviceActionTestCase(StorageTestCase):
         self.assertEqual(remove_sdc1.obsoletes(add_sdc1), True)
         self.assertEqual(add_sdc1.obsoletes(remove_sdc1), True)
 
+        sdc2 = self.newDevice(device_class=PartitionDevice, name="sdc2",
+                              size=Size(spec="5 GiB"), parents=[sdc])
+        create_sdc2 = self.scheduleCreateDevice(device=sdc2)
+
+        # destroy/resize/create sequencing does not apply to container actions
+        self.assertEqual(create_sdc2.requires(remove_sdc1), False)
+        self.assertEqual(remove_sdc1.requires(create_sdc2), False)
+
     def testActionSorting(self, *args, **kwargs):
         """ Verify correct functioning of action sorting. """
         pass
-- 
1.8.5.3



More information about the anaconda-patches mailing list