From 29d1c47b5e14a70cbb5f4e766cd5330c5dbad21b Mon Sep 17 00:00:00 2001
From: David Lehman <dlehman@redhat.com>
Date: Tue, 5 Aug 2014 12:06:22 -0500
Subject: [PATCH 02/14] Move recursiveRemove from Blivet to DeviceTree.

---
 blivet/__init__.py   | 31 ++-----------------------------
 blivet/devicetree.py | 33 ++++++++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 30 deletions(-)

diff --git a/blivet/__init__.py b/blivet/__init__.py
index eb55f66..aaf4d6f 100644
--- a/blivet/__init__.py
+++ b/blivet/__init__.py
@@ -781,35 +781,8 @@ class Blivet(object):
         return True
 
     def recursiveRemove(self, device):
-        """ Remove a device after removing its dependent devices.
-
-            If the device is not a leaf, all of its dependents are removed
-            recursively until it is a leaf device. At that point the device is
-            removed, unless it is a disk. If the device is a disk, its
-            formatting is removed by no attempt is made to actually remove the
-            disk device.
-        """
-        log.debug("removing %s", device.name)
-        devices = self.deviceDeps(device)
-
-        # this isn't strictly necessary, but it makes the action list easier to
-        # read when removing logical partitions because of the automatic
-        # renumbering that happens if you remove them in ascending numerical
-        # order
-        devices.reverse()
-
-        while devices:
-            log.debug("devices to remove: %s", [d.name for d in devices])
-            leaves = [d for d in devices if d.isleaf]
-            log.debug("leaves to remove: %s", [d.name for d in leaves])
-            for leaf in leaves:
-                self.destroyDevice(leaf)
-                devices.remove(leaf)
-
-        if device.isDisk:
-            self.devicetree.registerAction(ActionDestroyFormat(device))
-        else:
-            self.destroyDevice(device)
+        """ Remove a device after removing its dependent devices. """
+        self.devicetree.recursiveRemove(device)
 
     def clearPartitions(self):
         """ Clear partitions and dependent devices from disks. """
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index 12cde24..b10bbd6 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -37,7 +37,7 @@ from .devices import LVMSnapShotDevice, LVMThinSnapShotDevice
 from .devices import MDRaidArrayDevice, MultipathDevice, NoDevice, OpticalDevice
 from .devices import PartitionDevice, ZFCPDiskDevice, iScsiDiskDevice
 from .devices import devicePathToName
-from .deviceaction import ActionCreateDevice, ActionDestroyDevice, action_type_from_string, action_object_from_string
+from .deviceaction import ActionCreateDevice, ActionDestroyDevice, ActionDestroyFormat, action_type_from_string, action_object_from_string
 from . import formats
 from .formats import getFormat
 from .formats.fs import nodev_filesystems
@@ -474,6 +474,37 @@ class DeviceTree(object):
                 self._removeDevice(devs_to_remove[0], force=True, moddisk=False)
                 break
 
+    def recursiveRemove(self, device):
+        """ Remove a device after removing its dependent devices.
+
+            If the device is not a leaf, all of its dependents are removed
+            recursively until it is a leaf device. At that point the device is
+            removed, unless it is a disk. If the device is a disk, its
+            formatting is removed by no attempt is made to actually remove the
+            disk device.
+        """
+        log.debug("removing %s", device.name)
+        devices = self.getDependentDevices(device)
+
+        # this isn't strictly necessary, but it makes the action list easier to
+        # read when removing logical partitions because of the automatic
+        # renumbering that happens if you remove them in ascending numerical
+        # order
+        devices.reverse()
+
+        while devices:
+            log.debug("devices to remove: %s", [d.name for d in devices])
+            leaves = [d for d in devices if d.isleaf]
+            log.debug("leaves to remove: %s", [d.name for d in leaves])
+            for leaf in leaves:
+                self.registerAction(ActionDestroyFormat(leaf))
+                self.registerAction(ActionDestroyDevice(leaf))
+                devices.remove(leaf)
+
+        self.registerAction(ActionDestroyFormat(device))
+        if not device.isDisk:
+            self.registerAction(ActionDestroyDevice(device))
+
     def registerAction(self, action):
         """ Register an action to be performed at a later time.
 
-- 
1.9.3

