[PATCH 4/6] Fix handling of clearing a partitioned disk and leaving it cleared.
Anne Mulhern
amulhern at redhat.com
Wed May 7 15:18:06 UTC 2014
----- Original Message -----
> From: "David Lehman" <dlehman at redhat.com>
> To: anaconda-patches at lists.fedorahosted.org
> Sent: Wednesday, May 7, 2014 9:52:58 AM
> Subject: Re: [PATCH 4/6] Fix handling of clearing a partitioned disk and leaving it cleared.
>
> On 05/07/2014 06:56 AM, Anne Mulhern wrote:
> >
> >
> >
> >
> > ----- Original Message -----
> >> From: "David Lehman" <dlehman at redhat.com>
> >> To: anaconda-patches at lists.fedorahosted.org
> >> Sent: Tuesday, May 6, 2014 3:44:30 PM
> >> Subject: [PATCH 4/6] 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 | 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
> >>
> >> _______________________________________________
> >> anaconda-patches mailing list
> >> anaconda-patches at lists.fedorahosted.org
> >> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> >>
> >
> > Is there a more precise way to express what isleaf() does? There is
> > already a notion of "depends" in the dependsOn() method, which can
> > also be found in devices.
>
> If it weren't for extended/logical partitions you could define a leaf as
> any device that is the parent of no other device. "A device which no
> other device depends on" is effectively the same idea, as you can see by
> the contents of the dependsOn method. They are two views on the same notion.
>
> David
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
>
Is it possible to say something as precise as:
device.isleaf() is True if and only if there is no other device in devicetree._hidden
+ devicetree.devices such that other.dependsOn(device) is True
?
- mulhern
More information about the anaconda-patches
mailing list