From 916deb89e971a48a601623caf1de875580e3eeb5 Mon Sep 17 00:00:00 2001 From: David Lehman Date: Fri, 21 Feb 2014 16:37:59 -0600 Subject: [PATCH 04/13] Fix handling of clearing a partitioned disk and leaving it cleared. Until now it has always been the case that if you cleared a disks you were also creating a new disklabel on it. --- blivet/devices.py | 13 +++++++++++-- blivet/devicetree.py | 7 ++++--- tests/clearpart_test.py | 1 + tests/storagetestcase.py | 2 ++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/blivet/devices.py b/blivet/devices.py index 3d9c216..a712522 100644 --- a/blivet/devices.py +++ b/blivet/devices.py @@ -1505,9 +1505,17 @@ class PartitionDevice(StorageDevice): def isleaf(self): """ True if this device has no children. """ no_kids = super(PartitionDevice, self).isleaf + disklabel = None + if self.disk and self.partedPartition: + if self.disk.format.type == "disklabel" and \ + self.partedPartition in self.disk.format.partitions: + disklabel = self.disk.format + elif self.disk.originalFormat.type == "disklabel" and \ + self.partedPartition in self.disk.originalFormat.partitions: + disklabel = self.disk.originalFormat + extended_has_logical = (self.isExtended and - (self.disk and - self.disk.format.logicalPartitions)) + (disklabel and disklabel.logicalPartitions)) return (no_kids and not extended_has_logical) def _setFormat(self, format): @@ -1716,6 +1724,7 @@ class PartitionDevice(StorageDevice): raise if self.disk.format.exists and \ + self.disk.format.type == "disklabel" and \ self.disk.format.partedDisk != self.disk.originalFormat.partedDisk: # If the new/current disklabel is the same as the original one, we # have to duplicate the removal on the other copy of the DiskLabel. diff --git a/blivet/devicetree.py b/blivet/devicetree.py index 85c4ed0..b9a31bd 100644 --- a/blivet/devicetree.py +++ b/blivet/devicetree.py @@ -240,9 +240,10 @@ class DeviceTree(object): for device in self.devices: if device.partitioned: device.format.resetPartedDisk() - if device.originalFormat.type == "disklabel" and \ - device.originalFormat != device.format: - device.originalFormat.resetPartedDisk() + + if device.originalFormat.type == "disklabel" and \ + device.originalFormat != device.format: + device.originalFormat.resetPartedDisk() # Call preCommitFixup on all devices mpoints = [getattr(d.format, 'mountpoint', "") for d in self.devices] diff --git a/tests/clearpart_test.py b/tests/clearpart_test.py index ad55015..80d43ee 100644 --- a/tests/clearpart_test.py +++ b/tests/clearpart_test.py @@ -23,6 +23,7 @@ class ClearPartTestCase(unittest.TestCase): exists=True) sda.format._partedDisk = mock.Mock() sda.format._partedDevice = mock.Mock() + sda.format._partedDisk.configure_mock(partitions=[]) b.devicetree._addDevice(sda) # sda1 is a partition containing an existing ext4 filesystem diff --git a/tests/storagetestcase.py b/tests/storagetestcase.py index 86ba6d9..2097c80 100644 --- a/tests/storagetestcase.py +++ b/tests/storagetestcase.py @@ -122,6 +122,8 @@ class StorageTestCase(unittest.TestCase): if isinstance(format, blivet.formats.disklabel.DiskLabel): format._partedDevice = Mock() format._partedDisk = Mock() + attrs = {"partitions": []} + format._partedDisk.configure_mock(**attrs) format.exists = exists -- 1.9.0