[rhel6-branch 13/30] Change getLength() to prior getSize() method.

mulkieran installerbot-noreply at redhat.com
Thu May 28 21:04:18 UTC 2015


From: Anne Mulhern <amulhern at redhat.com>

Signed-off-by: Anne Mulhern <amulhern at redhat.com>
---
 blivet/autopart.py              |  4 ++--
 blivet/devices/disk.py          |  2 +-
 blivet/devices/luks.py          |  2 +-
 blivet/devices/md.py            |  2 +-
 blivet/devices/partition.py     | 12 ++++++------
 blivet/devices/storage.py       |  2 +-
 blivet/formats/disklabel.py     |  4 ++--
 blivet/partitioning.py          | 10 +++++-----
 blivet/pykickstart_constants.py | 30 ++++++++++++++++++++++++++++++
 tests/devices_test.py           |  6 +++---
 tests/storagetestcase.py        |  4 ++--
 11 files changed, 54 insertions(+), 24 deletions(-)
 create mode 100644 blivet/pykickstart_constants.py

diff --git a/blivet/autopart.py b/blivet/autopart.py
index 316bba0..b7e4964 100644
--- a/blivet/autopart.py
+++ b/blivet/autopart.py
@@ -125,7 +125,7 @@ def _getCandidateDisks(storage):
                 part = part.nextPartition()
                 continue
 
-            if Size(part.getLength(unit="B")) > PartitionDevice.defaultSize:
+            if Size(part.getSize(unit="b")) > PartitionDevice.defaultSize:
                 disks.append(disk)
                 break
 
@@ -196,7 +196,7 @@ def _schedulePartitions(storage, disks, implicit_devices, min_luks_entropy=0):
     """
     # basis for requests with requiredSpace is the sum of the sizes of the
     # two largest free regions
-    all_free = (Size(reg.getLength(unit="B")) for reg in getFreeRegions(disks))
+    all_free = (Size(reg.getSize(unit="b")) for reg in getFreeRegions(disks))
     all_free = sorted(all_free, reverse=True)
     if not all_free:
         # this should never happen since we've already filtered the disks
diff --git a/blivet/devices/disk.py b/blivet/devices/disk.py
index f14638d..4130f20 100644
--- a/blivet/devices/disk.py
+++ b/blivet/devices/disk.py
@@ -104,7 +104,7 @@ def mediaPresent(self):
         # Some drivers (cpqarray <blegh>) make block device nodes for
         # controllers with no disks attached and then report a 0 size,
         # treat this as no media present
-        return Size(self.partedDevice.getLength(unit="B")) != Size(0)
+        return Size(self.partedDevice.getSize(unit="b")) != Size(0)
 
     @property
     def description(self):
diff --git a/blivet/devices/luks.py b/blivet/devices/luks.py
index f02cd28..1e998cc 100644
--- a/blivet/devices/luks.py
+++ b/blivet/devices/luks.py
@@ -66,7 +66,7 @@ def size(self):
         if not self.exists or not self.partedDevice:
             size = self.slave.size - crypto.LUKS_METADATA_SIZE
         else:
-            size = Size(self.partedDevice.getLength(unit="B"))
+            size = Size(self.partedDevice.getSize(unit="b"))
         return size
 
     def _postCreate(self):
diff --git a/blivet/devices/md.py b/blivet/devices/md.py
index 105ee1e..d8dc2f9 100644
--- a/blivet/devices/md.py
+++ b/blivet/devices/md.py
@@ -211,7 +211,7 @@ def size(self):
                 size = Size(0)
             log.debug("non-existent RAID %s size == %s", self.level, size)
         else:
-            size = Size(self.partedDevice.getLength(unit="B"))
+            size = Size(self.partedDevice.getSize(unit="b"))
             log.debug("existing RAID %s size == %s", self.level, size)
 
         return size
diff --git a/blivet/devices/partition.py b/blivet/devices/partition.py
index d77d9bf..ebc2c38 100644
--- a/blivet/devices/partition.py
+++ b/blivet/devices/partition.py
@@ -244,7 +244,7 @@ def alignTargetSize(self, newsize):
 
         (_constraint, geometry) = self._computeResize(self.partedPartition,
                                                       newsize=newsize)
-        return Size(geometry.getLength(unit="B"))
+        return Size(geometry.getSize(unit="b"))
 
     def _setTargetSize(self, newsize):
         if not isinstance(newsize, Size):
@@ -519,7 +519,7 @@ def probe(self):
         if not self.exists:
             return
 
-        self._size = Size(self.partedPartition.getLength(unit="B"))
+        self._size = Size(self.partedPartition.getSize(unit="b"))
         self._currentSize = self._size
         self.targetSize = self._size
 
@@ -582,7 +582,7 @@ def _postCreate(self):
             DeviceFormat(device=self.path, exists=True).destroy()
 
         StorageDevice._postCreate(self)
-        self._currentSize = Size(self.partedPartition.getLength(unit="B"))
+        self._currentSize = Size(self.partedPartition.getSize(unit="b"))
 
     def create(self):
         """ Create the device. """
@@ -651,7 +651,7 @@ def resize(self):
                                         end=geometry.end)
 
         self.disk.format.commit()
-        self._currentSize = Size(partition.getLength(unit="B"))
+        self._currentSize = Size(partition.getSize(unit="b"))
 
     def _preDestroy(self):
         StorageDevice._preDestroy(self)
@@ -700,7 +700,7 @@ def _getSize(self):
         """ Get the device's size. """
         size = self._size
         if self.partedPartition:
-            size = Size(self.partedPartition.getLength(unit="B"))
+            size = Size(self.partedPartition.getSize(unit="b"))
         return size
 
     def _setSize(self, newsize):
@@ -778,7 +778,7 @@ def _unalignedMaxPartSize(self):
             pass
         else:
             if partition.type == parted.PARTITION_FREESPACE:
-                maxPartSize += Size(partition.getLength(unit="B"))
+                maxPartSize += Size(partition.getSize(unit="b"))
 
         return maxPartSize
 
diff --git a/blivet/devices/storage.py b/blivet/devices/storage.py
index 311df3e..c05a709 100644
--- a/blivet/devices/storage.py
+++ b/blivet/devices/storage.py
@@ -594,7 +594,7 @@ def currentSize(self):
         """
         size = Size(0)
         if self.exists and self.partedDevice:
-            size = Size(self.partedDevice.getLength(unit="B"))
+            size = Size(self.partedDevice.getSize(unit="b"))
         elif self.exists:
             size = self._size
         return size
diff --git a/blivet/formats/disklabel.py b/blivet/formats/disklabel.py
index 3d0c91b..e724c7f 100644
--- a/blivet/formats/disklabel.py
+++ b/blivet/formats/disklabel.py
@@ -206,7 +206,7 @@ def size(self):
         size = self._size
         if not size:
             try:
-                size = Size(self.partedDevice.getLength(unit="B"))
+                size = Size(self.partedDevice.getSize(unit="b"))
             except Exception: # pylint: disable=broad-except
                 log_exception_info()
                 size = Size(0)
@@ -383,7 +383,7 @@ def endAlignment(self):
 
     @property
     def free(self):
-        return sum((Size(f.getLength(unit="B")) for f in self.partedDisk.getFreeSpacePartitions()), Size(0))
+        return sum((Size(f.getSize(unit="b")) for f in self.partedDisk.getFreeSpacePartitions()), Size(0))
 
     @property
     def magicPartitionNumber(self):
diff --git a/blivet/partitioning.py b/blivet/partitioning.py
index 17da6e0..a08ad92 100644
--- a/blivet/partitioning.py
+++ b/blivet/partitioning.py
@@ -201,7 +201,7 @@ def getBestFreeSpaceRegion(disk, part_type, req_size, start=None,
 
     for free_geom in disk.getFreeSpaceRegions():
         log.debug("checking %d-%d (%s)", free_geom.start, free_geom.end,
-                                         Size(free_geom.getLength(unit="B")))
+                                         Size(free_geom.getSize(unit="b")))
         if start is not None and not free_geom.containsSector(start):
             log.debug("free region does not contain requested start sector")
             continue
@@ -228,8 +228,8 @@ def getBestFreeSpaceRegion(disk, part_type, req_size, start=None,
 
         log.debug("current free range is %d-%d (%s)", free_geom.start,
                                                       free_geom.end,
-                                                      Size(free_geom.getLength(unit="B")))
-        free_size = Size(free_geom.getLength(unit="B"))
+                                                      Size(free_geom.getSize(unit="b")))
+        free_size = Size(free_geom.getSize(unit="b"))
 
         # For boot partitions, we want the first suitable region we find.
         # For growable or extended partitions, we want the largest possible
@@ -801,7 +801,7 @@ def allocatePartitions(storage, disks, partitions, freespace):
                     use_disk = _disk
                     log.debug("new free: %d-%d / %s", best.start,
                                                       best.end,
-                                                      Size(best.getLength(unit="B")))
+                                                      Size(best.getSize(unit="b")))
                     log.debug("new free allows for %d sectors of growth", growth)
                     free = best
 
@@ -847,7 +847,7 @@ def allocatePartitions(storage, disks, partitions, freespace):
 
         log.debug("created partition %s of %s and added it to %s",
                 partition.getDeviceNodeName(),
-                Size(partition.getLength(unit="B")),
+                Size(partition.getSize(unit="b")),
                 disklabel.device)
 
         # this one sets the name
diff --git a/blivet/pykickstart_constants.py b/blivet/pykickstart_constants.py
new file mode 100644
index 0000000..3ab7a41
--- /dev/null
+++ b/blivet/pykickstart_constants.py
@@ -0,0 +1,30 @@
+# pykickstart_constants.py
+# Constants defined in pykickstart package but used in blivet.
+#
+# Copyright (C) 2010  Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# the GNU General Public License v.2, or (at your option) any later version.
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY expressed or implied, including the implied warranties of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+# Public License for more details.  You should have received a copy of the
+# GNU General Public License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
+# source code or documentation are not subject to the GNU General Public
+# License and may only be used or replicated with the express permission of
+# Red Hat, Inc.
+#
+# Red Hat Author(s): Anne Mulhern <amulhern at redhat.com>
+
+CLEARPART_TYPE_LINUX = 0
+CLEARPART_TYPE_ALL = 1
+CLEARPART_TYPE_NONE = 2
+CLEARPART_TYPE_LIST = 3
+
+AUTOPART_TYPE_PLAIN = 0
+AUTOPART_TYPE_BTRFS = 1
+AUTOPART_TYPE_LVM = 2
+AUTOPART_TYPE_LVM_THINP = 3
diff --git a/tests/devices_test.py b/tests/devices_test.py
index 96516eb..da80636 100644
--- a/tests/devices_test.py
+++ b/tests/devices_test.py
@@ -850,7 +850,7 @@ def testTargetSize(self):
             disk.format.addPartition(start, end)
             partition = disk.format.partedDisk.getPartitionBySector(start)
             self.assertNotEqual(partition, None)
-            self.assertEqual(orig_size, Size(partition.getLength(unit='B')))
+            self.assertEqual(orig_size, Size(partition.getSize(unit='b')))
 
             device = PartitionDevice(os.path.basename(partition.path),
                                      size=orig_size)
@@ -902,14 +902,14 @@ def testTargetSize(self):
             device.targetSize = new_target
             self.assertEqual(device.targetSize, new_target)
             self.assertEqual(device.size, new_target)
-            parted_size = Size(device.partedPartition.getLength(unit='B'))
+            parted_size = Size(device.partedPartition.getSize(unit='b'))
             self.assertEqual(parted_size, device.targetSize)
 
             # reset target size to original size
             device.targetSize = orig_size
             self.assertEqual(device.targetSize, orig_size)
             self.assertEqual(device.size, orig_size)
-            parted_size = Size(device.partedPartition.getLength(unit='B'))
+            parted_size = Size(device.partedPartition.getSize(unit='b'))
             self.assertEqual(parted_size, device.targetSize)
 
     def testMinMaxSizeAlignment(self):
diff --git a/tests/storagetestcase.py b/tests/storagetestcase.py
index b01a104..6d6d6e7 100644
--- a/tests/storagetestcase.py
+++ b/tests/storagetestcase.py
@@ -59,7 +59,7 @@ def partition_probe(device):
             else:
                 part_mock = Mock()
 
-            attrs = {"getLength.return_value": int(device._size),
+            attrs = {"getSize.return_value": int(device._size),
                      "getDeviceNodeName.return_value": device.name,
                      "type": parted.PARTITION_NORMAL}
             part_mock.configure_mock(**attrs)
@@ -96,7 +96,7 @@ def newDevice(self, *args, **kwargs):
         if exists:
             # set up mock parted.Device w/ correct size
             device._partedDevice = Mock()
-            device._partedDevice.getLength = Mock(return_value=int(device._size.convertTo(B)))
+            device._partedDevice.getSize = Mock(return_value=int(device._size.convertTo(B)))
             device._partedDevice.sectorSize = 512
 
         if isinstance(device, blivet.devices.PartitionDevice):


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/f663e1a5ad3b8e5982360d9eff0121c0d37b236d


More information about the anaconda-patches mailing list