Skip to content

Commit

Permalink
Change getLength() to prior getSize() method.
Browse files Browse the repository at this point in the history
Signed-off-by: Anne Mulhern <amulhern@redhat.com>
  • Loading branch information
mulkieran committed Apr 1, 2015
1 parent 010125d commit f663e1a
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 24 deletions.
4 changes: 2 additions & 2 deletions blivet/autopart.py
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion blivet/devices/disk.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion blivet/devices/luks.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion blivet/devices/md.py
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions blivet/devices/partition.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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. """
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion blivet/devices/storage.py
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions blivet/formats/disklabel.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions blivet/partitioning.py
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions 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@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
6 changes: 3 additions & 3 deletions tests/devices_test.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tests/storagetestcase.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit f663e1a

Please sign in to comment.