From 553ca6a6d94fc0c145c803e4480c0a322b6c295a Mon Sep 17 00:00:00 2001 From: David Lehman Date: Tue, 5 Aug 2014 12:06:22 -0500 Subject: [PATCH 11/18] 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 3128c89..f954963 100644 --- a/blivet/__init__.py +++ b/blivet/__init__.py @@ -793,35 +793,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 1a52801..0324eee 100644 --- a/blivet/devicetree.py +++ b/blivet/devicetree.py @@ -39,7 +39,7 @@ from .devices import MDRaidArrayDevice, MDBiosRaidArrayDevice from .devices import 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 @@ -470,6 +470,37 @@ class DeviceTree(object): self._removeDevice(devs_to_remove[0], force=True, modparent=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