[PATCH 4/6] Fix handling of clearing a partitioned disk and leaving it cleared.
David Lehman
dlehman at redhat.com
Tue May 6 19:44:30 UTC 2014
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 | 18 ++++++++++++++----
blivet/devicetree.py | 7 ++++---
tests/clearpart_test.py | 1 +
tests/storagetestcase.py | 2 ++
4 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/blivet/devices.py b/blivet/devices.py
index 0e12084..c130427 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -402,7 +402,7 @@ class Device(util.ObjectID):
@property
def isleaf(self):
- """ True if this device has no children. """
+ """ True if no other device depends on this one. """
return self.kids == 0
@property
@@ -1508,11 +1508,20 @@ class PartitionDevice(StorageDevice):
@property
def isleaf(self):
- """ True if this device has no children. """
+ """ True if no other device depends on this one. """
no_kids = super(PartitionDevice, self).isleaf
+ # it is possible that the disk that originally contained this partition
+ # no longer contains a disklabel, in which case we can assume that this
+ # device is a leaf
+ if self.disk and self.partedPartition and \
+ self.disk.format.type == "disklabel" and \
+ self.partedPartition in self.disk.format.partitions:
+ disklabel = self.disk.format
+ else:
+ disklabel = None
+
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):
@@ -1721,6 +1730,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 4df5f46..4398ab3 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 7673249..ba665f1 100644
--- a/tests/storagetestcase.py
+++ b/tests/storagetestcase.py
@@ -122,6 +122,8 @@ class StorageTestCase(unittest.TestCase):
if isinstance(fmt, blivet.formats.disklabel.DiskLabel):
fmt._partedDevice = Mock()
fmt._partedDisk = Mock()
+ attrs = {"partitions": []}
+ fmt._partedDisk.configure_mock(**attrs)
fmt.exists = exists
--
1.9.0
More information about the anaconda-patches
mailing list