[PATCH 4/6] Fix handling of clearing a partitioned disk and leaving it cleared.
David Lehman
dlehman at redhat.com
Fri May 2 17:03:41 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 | 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 0e12084..79e6c53 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -1510,9 +1510,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):
@@ -1721,6 +1729,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 26d9a4d..bc5a27a 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