[blivet:master 15/16] Change Size so that it takes a single value parameter.
mulhern
amulhern at redhat.com
Thu May 1 13:08:52 UTC 2014
Update calls, remove SizeParamsError, and remove tests about SizeParamsError.
Signed-off-by: mulhern <amulhern at redhat.com>
---
blivet/__init__.py | 8 +-
blivet/devicefactory.py | 16 ++--
blivet/devicelibs/crypto.py | 2 +-
blivet/devicelibs/lvm.py | 20 ++---
blivet/devicelibs/mdraid.py | 10 +--
blivet/devicelibs/swap.py | 8 +-
blivet/devices.py | 32 ++++----
blivet/devicetree.py | 2 +-
blivet/errors.py | 3 -
blivet/formats/__init__.py | 4 +-
blivet/formats/biosboot.py | 4 +-
blivet/formats/disklabel.py | 6 +-
blivet/formats/fs.py | 48 ++++++------
blivet/formats/prepboot.py | 4 +-
blivet/formats/swap.py | 2 +-
blivet/partitioning.py | 32 ++++----
blivet/platform.py | 20 ++---
blivet/size.py | 59 +++++++-------
blivet/udev.py | 10 +--
blivet/util.py | 4 +-
tests/action_test.py | 146 +++++++++++++++++------------------
tests/devicefactory_test.py | 4 +-
tests/devicelibs_test/lvm_test.py | 38 ++++-----
tests/devicelibs_test/mdraid_test.py | 36 ++++-----
tests/devices_test.py | 114 +++++++++++++--------------
tests/size_test.py | 65 ++++++++--------
26 files changed, 342 insertions(+), 355 deletions(-)
diff --git a/blivet/__init__.py b/blivet/__init__.py
index 9f94300..7dfbd2a 100644
--- a/blivet/__init__.py
+++ b/blivet/__init__.py
@@ -899,11 +899,11 @@ class Blivet(object):
should_clear = self.shouldClear(disk, clearPartType=clearPartType,
clearPartDisks=[disk.name])
if should_clear:
- free[disk.name] = (disk.size, Size(bytes=0))
+ free[disk.name] = (disk.size, Size(0))
continue
- disk_free = Size(bytes=0)
- fs_free = Size(bytes=0)
+ disk_free = Size(0)
+ fs_free = Size(0)
if disk.partitioned:
disk_free = disk.format.free
for partition in [p for p in self.partitions if p.disk == disk]:
@@ -1641,7 +1641,7 @@ class Blivet(object):
if not swaps:
installed = util.total_memory()
- required = Size(spec="%s KiB" % isys.EARLY_SWAP_RAM)
+ required = Size("%s KiB" % isys.EARLY_SWAP_RAM)
if installed < required:
exns.append(
diff --git a/blivet/devicefactory.py b/blivet/devicefactory.py
index 30b8efb..c655a71 100644
--- a/blivet/devicefactory.py
+++ b/blivet/devicefactory.py
@@ -156,7 +156,7 @@ class DeviceFactory(object):
# PVs on each of the specified disks. No free space is maintained in
# new VGs by default.
factory = blivet.devicefactory.LVMFactory(_blivet,
- Size(spec="10000 MB"),
+ Size("10000 MB"),
disks,
fstype="xfs",
label="music",
@@ -169,7 +169,7 @@ class DeviceFactory(object):
# Now add another LV to the "data" VG, adjusting the size of a non-
# existent "data" VG so that it can contain the new LV.
factory = blivet.devicefactory.LVMFactory(_blivet,
- Size(spec="20000 MB"),
+ Size("20000 MB"),
disks,
fstype="xfs",
label="videos",
@@ -180,7 +180,7 @@ class DeviceFactory(object):
# Now change the size of the "music" LV and adjust the size of the
# "data" VG accordingly.
factory = blivet.devicefactory.LVMFactory(_blivet,
- Size(spec="15000 MB"),
+ Size("15000 MB"),
disks,
device=music_lv)
factory.configure()
@@ -815,7 +815,7 @@ class PartitionFactory(DeviceFactory):
if self.encrypted:
min_format_size += getFormat("luks").minSize
- return max(Size(spec="1MiB"), min_format_size)
+ return max(Size("1MiB"), min_format_size)
def _get_device_size(self):
""" Return the factory device size including container limitations. """
@@ -953,7 +953,7 @@ class PartitionSetFactory(PartitionFactory):
add_disks = self.disks
# drop any new disks that don't have free space
- min_free = min(Size(spec="500MiB"), self.parent_factory.size)
+ min_free = min(Size("500MiB"), self.parent_factory.size)
add_disks = [d for d in add_disks if d.partitioned and
d.format.free >= min_free]
@@ -1135,7 +1135,7 @@ class LVMFactory(DeviceFactory):
def _get_total_space(self):
""" Total disk space requirement for this device and its container. """
- size = Size(bytes=0)
+ size = Size(0)
if self.container and self.container.exists:
return size
@@ -1442,7 +1442,7 @@ class LVMThinPFactory(LVMFactory):
log.debug("requested size is %s", self.size)
size = self.size # projected size for the pool (not padded)
- free = Size(bytes=0)# total space within the vg that is available to us
+ free = Size(0)# total space within the vg that is available to us
if self.pool:
free += self.pool.freeSpace # pools are always auto-sized
# pool lv sizes go toward projected pool size and vg free space
@@ -1597,7 +1597,7 @@ class BTRFSFactory(DeviceFactory):
def _get_total_space(self):
""" Return the total space needed for the specified container. """
- size = Size(bytes=0)
+ size = Size(0)
if self.container and self.container.exists:
return size
diff --git a/blivet/devicelibs/crypto.py b/blivet/devicelibs/crypto.py
index dd2fcdf..da17b34 100644
--- a/blivet/devicelibs/crypto.py
+++ b/blivet/devicelibs/crypto.py
@@ -26,7 +26,7 @@ from pycryptsetup import CryptSetup
from ..errors import CryptoError
from ..size import Size
-LUKS_METADATA_SIZE = Size(spec="2 MiB")
+LUKS_METADATA_SIZE = Size("2 MiB")
# Keep the character set size a power of two to make sure all characters are
# equally likely
diff --git a/blivet/devicelibs/lvm.py b/blivet/devicelibs/lvm.py
index 2324db1..67fc1e5 100644
--- a/blivet/devicelibs/lvm.py
+++ b/blivet/devicelibs/lvm.py
@@ -35,14 +35,14 @@ from ..i18n import _
MAX_LV_SLOTS = 256
# some of lvm's defaults that we have no way to ask it for
-LVM_PE_START = Size(spec="1 MiB")
-LVM_PE_SIZE = Size(spec="4 MiB")
+LVM_PE_START = Size("1 MiB")
+LVM_PE_SIZE = Size("4 MiB")
# thinp constants
-LVM_THINP_MIN_METADATA_SIZE = Size(spec="2 MiB")
-LVM_THINP_MAX_METADATA_SIZE = Size(spec="16 GiB")
-LVM_THINP_MIN_CHUNK_SIZE = Size(spec="64 KiB")
-LVM_THINP_MAX_CHUNK_SIZE = Size(spec="1 GiB")
+LVM_THINP_MIN_METADATA_SIZE = Size("2 MiB")
+LVM_THINP_MAX_METADATA_SIZE = Size("16 GiB")
+LVM_THINP_MIN_CHUNK_SIZE = Size("64 KiB")
+LVM_THINP_MAX_CHUNK_SIZE = Size("1 GiB")
def has_lvm():
if util.find_program_in_path("lvm"):
@@ -119,8 +119,8 @@ def getPossiblePhysicalExtents():
"""
possiblePE = []
- curpe = Size(spec="1 KiB")
- while curpe <= Size(spec="16 GiB"):
+ curpe = Size("1 KiB")
+ while curpe <= Size("16 GiB"):
possiblePE.append(curpe)
curpe = curpe * 2
@@ -129,9 +129,9 @@ def getPossiblePhysicalExtents():
def getMaxLVSize():
""" Return the maximum size of a logical volume. """
if arch.getArch() in ("x86_64", "ppc64", "alpha", "ia64", "s390"): #64bit architectures
- return Size(spec="8 EiB")
+ return Size("8 EiB")
else:
- return Size(spec="16 TiB")
+ return Size("16 TiB")
def clampSize(size, pesize, roundup=None):
delta = size % pesize
diff --git a/blivet/devicelibs/mdraid.py b/blivet/devicelibs/mdraid.py
index 1077400..00364a3 100644
--- a/blivet/devicelibs/mdraid.py
+++ b/blivet/devicelibs/mdraid.py
@@ -31,8 +31,8 @@ import logging
log = logging.getLogger("blivet")
# these defaults were determined empirically
-MD_SUPERBLOCK_SIZE = Size(spec="2 MiB")
-MD_CHUNK_SIZE = Size(spec="512 KiB")
+MD_SUPERBLOCK_SIZE = Size("2 MiB")
+MD_CHUNK_SIZE = Size("512 KiB")
class MDRaidLevels(raid.RAIDLevels):
@classmethod
@@ -95,11 +95,11 @@ def get_raid_superblock_size(size, version=None):
# MDADM: operations, but limit this to 128Meg (0.1% of 10Gig)
# MDADM: which is plenty for efficient reshapes
# NOTE: In the mdadm code this is in 512b sectors. Converted to use MiB
- headroom = int(Size(spec="128 MiB"))
- while headroom << 10 > size and headroom > Size(spec="1 MiB"):
+ headroom = int(Size("128 MiB"))
+ while headroom << 10 > size and headroom > Size("1 MiB"):
headroom >>= 1
- headroom = Size(bytes=headroom)
+ headroom = Size(headroom)
log.info("Using %s superBlockSize", headroom)
return headroom
diff --git a/blivet/devicelibs/swap.py b/blivet/devicelibs/swap.py
index 2ba9e23..6cfe04f 100644
--- a/blivet/devicelibs/swap.py
+++ b/blivet/devicelibs/swap.py
@@ -137,10 +137,10 @@ def swapSuggestion(quiet=False, hibernation=False, disk_space=None):
if not quiet:
log.info("Detected %s of memory", mem)
- two_GiB = Size(spec="2GiB")
- four_GiB = Size(spec="4GiB")
- eight_GiB = Size(spec="8GiB")
- sixtyfour_GiB = Size(spec="64 GiB")
+ two_GiB = Size("2GiB")
+ four_GiB = Size("4GiB")
+ eight_GiB = Size("8GiB")
+ sixtyfour_GiB = Size("64 GiB")
#chart suggested in the discussion with other teams
if mem < two_GiB:
diff --git a/blivet/devices.py b/blivet/devices.py
index 7abf6c8..aa34e88 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -539,7 +539,7 @@ class StorageDevice(Device):
Device.__init__(self, name, parents=parents)
self._format = None
- self._size = Size(bytes=util.numeric_type(size))
+ self._size = Size(util.numeric_type(size))
self.major = util.numeric_type(major)
self.minor = util.numeric_type(minor)
self.sysfsPath = sysfsPath
@@ -569,7 +569,7 @@ class StorageDevice(Device):
sector_size = read_int_from_sys("%s/queue/logical_block_size"
% device_root)
size = read_int_from_sys("%s/size" % device_root)
- self._size = Size(bytes=(size * sector_size))
+ self._size = Size(size * sector_size)
def __str__(self):
exist = "existing"
@@ -958,7 +958,7 @@ class StorageDevice(Device):
"""
size = 0
if self.exists and self.partedDevice:
- size = Size(bytes=self.partedDevice.getLength(unit="B"))
+ size = Size(self.partedDevice.getLength(unit="B"))
elif self.exists:
size = self._size
return size
@@ -1179,7 +1179,7 @@ class PartitionDevice(StorageDevice):
"""
_type = "partition"
_resizable = True
- defaultSize = Size(spec="500MiB")
+ defaultSize = Size("500MiB")
def __init__(self, name, fmt=None,
size=None, grow=False, maxsize=None, start=None, end=None,
@@ -1297,7 +1297,7 @@ class PartitionDevice(StorageDevice):
self.req_name = name
self.req_partType = partType
self.req_primary = primary
- self.req_max_size = Size(bytes=util.numeric_type(maxsize))
+ self.req_max_size = Size(util.numeric_type(maxsize))
self.req_grow = grow
self.req_bootable = bootable
@@ -1582,7 +1582,7 @@ class PartitionDevice(StorageDevice):
if not self.exists:
return
- self._size = Size(bytes=self.partedPartition.getLength(unit="B"))
+ self._size = Size(self.partedPartition.getLength(unit="B"))
self._currentSize = self._size
self.targetSize = self._size
@@ -1600,7 +1600,7 @@ class PartitionDevice(StorageDevice):
device = self.partedPartition.geometry.device.path
# Erase 1MiB or to end of partition
- count = int(Size(spec="1 MiB") / bs)
+ count = int(Size("1 MiB") / bs)
count = min(count, part_len)
cmd = ["dd", "if=/dev/zero", "of=%s" % device, "bs=%s" % bs,
@@ -1644,7 +1644,7 @@ class PartitionDevice(StorageDevice):
DeviceFormat(device=self.path, exists=True).destroy()
StorageDevice._postCreate(self)
- self._currentSize = Size(bytes=self.partedPartition.getLength(unit="B"))
+ self._currentSize = Size(self.partedPartition.getLength(unit="B"))
def create(self):
""" Create the device. """
@@ -1693,7 +1693,7 @@ class PartitionDevice(StorageDevice):
end=geometry.end)
self.disk.format.commit()
- self._currentSize = Size(bytes=partition.getLength(unit="B"))
+ self._currentSize = Size(partition.getLength(unit="B"))
def _preDestroy(self):
StorageDevice._preDestroy(self)
@@ -1742,7 +1742,7 @@ class PartitionDevice(StorageDevice):
""" Get the device's size. """
size = self._size
if self.partedPartition:
- size = Size(bytes=self.partedPartition.getLength(unit="B"))
+ size = Size(self.partedPartition.getLength(unit="B"))
return size
def _setSize(self, newsize):
@@ -1764,7 +1764,7 @@ class PartitionDevice(StorageDevice):
if newsize > self.disk.size:
raise ValueError("partition size would exceed disk size")
- maxAvailableSize = Size(bytes=self.partedPartition.getMaxAvailableSize(unit="B"))
+ maxAvailableSize = Size(self.partedPartition.getMaxAvailableSize(unit="B"))
if newsize > maxAvailableSize:
raise ValueError("new size is greater than available space")
@@ -1813,7 +1813,7 @@ class PartitionDevice(StorageDevice):
pass
else:
if partition.type == parted.PARTITION_FREESPACE:
- maxPartSize = self.size + Size(bytes=partition.getLength(unit="B"))
+ maxPartSize = self.size + Size(partition.getLength(unit="B"))
maxFormatSize = self.format.maxSize
return min(maxFormatSize, maxPartSize) if maxFormatSize else maxPartSize
@@ -2305,7 +2305,7 @@ class LVMVolumeGroupDevice(ContainerDevice):
self.peCount = util.numeric_type(peCount)
self.peFree = util.numeric_type(peFree)
self.reserved_percent = 0
- self.reserved_space = Size(bytes=0)
+ self.reserved_space = Size(0)
# this will have to be covered by the 20% pad for non-existent pools
self.poolMetaData = 0
@@ -2880,7 +2880,7 @@ class LVMLogicalVolumeDevice(DMDevice):
# nothing more can be done, we don't know the VG's free space
return
- extent_size = Size(spec=vg_info["LVM2_VG_EXTENT_SIZE"] + "MiB")
+ extent_size = Size(vg_info["LVM2_VG_EXTENT_SIZE"] + "MiB")
extents_free = int(vg_info["LVM2_VG_FREE_COUNT"])
can_use = extent_size * extents_free
@@ -3305,7 +3305,7 @@ class MDRaidArrayDevice(ContainerDevice):
size = 0
log.debug("non-existent RAID %s size == %s", self.level, size)
else:
- size = Size(bytes=self.partedDevice.getLength(unit="B"))
+ size = Size(self.partedDevice.getLength(unit="B"))
log.debug("existing RAID %s size == %s", self.level, size)
return size
@@ -4024,7 +4024,7 @@ class FileDevice(StorageDevice):
fd = os.open(self.path, os.O_WRONLY|os.O_CREAT|os.O_TRUNC)
# all this fuss is so we write the zeros 1MiB at a time
zero = "\0"
- MiB = Size(spec="1 MiB")
+ MiB = Size("1 MiB")
count = int(self.size.convertTo(spec="MiB"))
rem = self.size % MiB
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index 142a8df..698f7fa 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -1441,7 +1441,7 @@ class DeviceTree(object):
self.addUdevDevice(lv_info)
raid = dict((n.replace("[", "").replace("]", ""),
- {"copies": 0, "log": Size(bytes=0), "meta": Size(bytes=0)})
+ {"copies": 0, "log": Size(0), "meta": Size(0)})
for n in lv_info.keys())
for lv in lv_info.values():
addLV(lv)
diff --git a/blivet/errors.py b/blivet/errors.py
index 1ce970b..e0e5871 100644
--- a/blivet/errors.py
+++ b/blivet/errors.py
@@ -180,9 +180,6 @@ class DasdFormatError(StorageError):
pass
# size
-class SizeParamsError(StorageError):
- pass
-
class SizePlacesError(StorageError):
pass
diff --git a/blivet/formats/__init__.py b/blivet/formats/__init__.py
index f052ef8..e4cee42 100644
--- a/blivet/formats/__init__.py
+++ b/blivet/formats/__init__.py
@@ -156,8 +156,8 @@ class DeviceFormat(ObjectID):
_packages = [] # required packages
_services = [] # required services
_resizable = False # can be resized
- _maxSize = Size(bytes=0) # maximum size
- _minSize = Size(bytes=0) # minimum size
+ _maxSize = Size(0) # maximum size
+ _minSize = Size(0) # minimum size
_dump = False
_check = False
_hidden = False # hide devices with this formatting?
diff --git a/blivet/formats/biosboot.py b/blivet/formats/biosboot.py
index 1688927..4d885f7 100644
--- a/blivet/formats/biosboot.py
+++ b/blivet/formats/biosboot.py
@@ -35,8 +35,8 @@ class BIOSBoot(DeviceFormat):
partedFlag = PARTITION_BIOS_GRUB
_formattable = True # can be formatted
_linuxNative = True # for clearpart
- _maxSize = Size(spec="2 MiB")
- _minSize = Size(spec="512 KiB")
+ _maxSize = Size("2 MiB")
+ _minSize = Size("512 KiB")
def __init__(self, *args, **kwargs):
"""
diff --git a/blivet/formats/disklabel.py b/blivet/formats/disklabel.py
index fe408dc..e06c39f 100644
--- a/blivet/formats/disklabel.py
+++ b/blivet/formats/disklabel.py
@@ -221,7 +221,7 @@ class DiskLabel(DeviceFormat):
size = self._size
if not size:
try:
- size = Size(bytes=self.partedDevice.getLength(unit="B"))
+ size = Size(self.partedDevice.getLength(unit="B"))
except Exception: # pylint: disable=broad-except
log_exception_info()
size = 0
@@ -417,7 +417,7 @@ class DiskLabel(DeviceFormat):
return int(open(path).readline().strip())
try:
- free = sum(Size(bytes=f.getLength(unit="B"))
+ free = sum(Size(f.getLength(unit="B"))
for f in self.partedDisk.getFreeSpacePartitions())
except Exception: # pylint: disable=broad-except
log_exception_info()
@@ -436,7 +436,7 @@ class DiskLabel(DeviceFormat):
partition_length = read_int_from_sys("%s/size" % partition_root)
used_sectors += partition_length
- free = Size(bytes=((disk_length - used_sectors) * sector_size))
+ free = Size((disk_length - used_sectors) * sector_size)
return free
diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index eb8e66a..8312bd4 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -106,7 +106,7 @@ class FS(DeviceFormat):
self.fsprofile = kwargs.get("fsprofile")
# filesystem size does not necessarily equal device size
- self._size = kwargs.get("size", Size(bytes=0))
+ self._size = kwargs.get("size", Size(0))
self._minInstanceSize = None # min size of this FS instance
self._mountpoint = None # the current mountpoint when mounted
@@ -311,7 +311,7 @@ class FS(DeviceFormat):
for value in values:
size *= value
- size = Size(bytes=size)
+ size = Size(size)
except Exception: # pylint: disable=broad-except
log_exception_info(log.error, "failed to obtain size of filesystem on %s", [self.device])
@@ -320,7 +320,7 @@ class FS(DeviceFormat):
@property
def currentSize(self):
""" The filesystem's current actual size. """
- size = Size(bytes=0)
+ size = Size(0)
if self.exists:
size = self._size
return size
@@ -878,8 +878,8 @@ class Ext2FS(FS):
_supported = True
_resizable = True
_linuxNative = True
- _maxSize = Size(spec="8 TiB")
- _minSize = Size(bytes=0)
+ _maxSize = Size("8 TiB")
+ _minSize = Size(0)
_defaultMountOptions = ["defaults"]
_defaultCheckOptions = ["-f", "-p", "-C", "0"]
_dump = True
@@ -949,7 +949,7 @@ class Ext2FS(FS):
minSize = minSize.strip()
if not minSize:
break
- size = Size(bytes=long(minSize) * blockSize)
+ size = Size(long(minSize) * blockSize)
break
if size is None:
@@ -993,7 +993,7 @@ class Ext3FS(Ext2FS):
# smaller than the default of 4096 bytes and therefore to make liars of us
# with regard to this maximum filesystem size, but if they're doing such
# things they should know the implications of their chosen block size.
- _maxSize = Size(spec="16 TiB")
+ _maxSize = Size("16 TiB")
@property
def needsFSCheck(self):
@@ -1024,7 +1024,7 @@ class FATFS(FS):
2: N_("Usage error.")}
_supported = True
_formattable = True
- _maxSize = Size(spec="1 TiB")
+ _maxSize = Size("1 TiB")
_packages = [ "dosfstools" ]
_defaultMountOptions = ["umask=0077", "shortname=winnt"]
# FIXME this should be fat32 in some cases
@@ -1046,7 +1046,7 @@ class EFIFS(FATFS):
_mountType = "vfat"
_modules = ["vfat"]
_name = N_("EFI System Partition")
- _minSize = Size(spec="50 MiB")
+ _minSize = Size("50 MiB")
@property
def supported(self):
@@ -1066,8 +1066,8 @@ class BTRFS(FS):
_maxLabelChars = 256
_supported = True
_packages = ["btrfs-progs"]
- _minSize = Size(spec="256 MiB")
- _maxSize = Size(spec="16 TiB")
+ _minSize = Size("256 MiB")
+ _maxSize = Size("16 TiB")
# FIXME parted needs to be taught about btrfs so that we can set the
# partition table type correctly for btrfs partitions
# partedSystem = fileSystemType["btrfs"]
@@ -1155,7 +1155,7 @@ class JFS(FS):
_labelfs = fslabeling.JFSLabeling()
_defaultFormatOptions = ["-q"]
_maxLabelChars = 16
- _maxSize = Size(spec="8 TiB")
+ _maxSize = Size("8 TiB")
_formattable = True
_linuxNative = True
_supported = False
@@ -1187,7 +1187,7 @@ class ReiserFS(FS):
_modules = ["reiserfs"]
_defaultFormatOptions = ["-f", "-f"]
_maxLabelChars = 16
- _maxSize = Size(spec="16 TiB")
+ _maxSize = Size("16 TiB")
_formattable = True
_linuxNative = True
_supported = False
@@ -1224,7 +1224,7 @@ class XFS(FS):
_labelfs = fslabeling.XFSLabeling()
_defaultFormatOptions = ["-f"]
_maxLabelChars = 16
- _maxSize = Size(spec="16 EiB")
+ _maxSize = Size("16 EiB")
_formattable = True
_linuxNative = True
_supported = True
@@ -1272,8 +1272,8 @@ class AppleBootstrapFS(HFS):
_type = "appleboot"
_mountType = "hfs"
_name = N_("Apple Bootstrap")
- _minSize = Size(spec="768 KiB")
- _maxSize = Size(spec="1 MiB")
+ _minSize = Size("768 KiB")
+ _maxSize = Size("1 MiB")
@property
def supported(self):
@@ -1292,8 +1292,8 @@ class HFSPlus(FS):
_packages = ["hfsplus-tools"]
_formattable = True
_mountType = "hfsplus"
- _minSize = Size(spec="1 MiB")
- _maxSize = Size(spec="2 TiB")
+ _minSize = Size("1 MiB")
+ _maxSize = Size("2 TiB")
_check = True
partedSystem = fileSystemType["hfs+"]
@@ -1322,8 +1322,8 @@ class NTFS(FS):
_labelfs = fslabeling.NTFSLabeling()
_fsck = "ntfsresize"
_resizable = True
- _minSize = Size(spec="1 MiB")
- _maxSize = Size(spec="16 TiB")
+ _minSize = Size("1 MiB")
+ _maxSize = Size("16 TiB")
_defaultMountOptions = ["defaults", "ro"]
_defaultCheckOptions = ["-c"]
_packages = ["ntfsprogs"]
@@ -1354,7 +1354,7 @@ class NTFS(FS):
continue
try:
# ntfsresize uses SI unit prefixes
- minSize = Size(spec="%d mb" % int(l.split(":")[1].strip()))
+ minSize = Size("%d mb" % int(l.split(":")[1].strip()))
except (IndexError, ValueError) as e:
minSize = None
log.warning("Unable to parse output for minimum size on %s: %s", self.device, e)
@@ -1519,9 +1519,9 @@ class TmpFS(NoDevFS):
# and 16EB on 64 bit systems
bits = arch.numBits()
if bits == 32:
- self._maxSize = Size(spec="16TiB")
+ self._maxSize = Size("16TiB")
elif bits == 64:
- self._maxSize = Size(spec="16EiB")
+ self._maxSize = Size("16EiB")
# if the architecture is other than 32 or 64 bit or unknown
# just use the default maxsize, which is 0, this disables
# resizing but other operations such as mounting should work fine
@@ -1596,7 +1596,7 @@ class TmpFS(NoDevFS):
# self._mountpoint is set to the full changeroot path once mounted,
# so even with changeroot, statvfs should still work fine.
st = os.statvfs(self._mountpoint)
- free_space = Size(bytes=st.f_bavail*st.f_frsize)
+ free_space = Size(st.f_bavail*st.f_frsize)
else:
# Free might be called even if the tmpfs mount has not been
# mounted yet, in this case just return the size set for the mount.
diff --git a/blivet/formats/prepboot.py b/blivet/formats/prepboot.py
index 9bb8c56..73b8cee 100644
--- a/blivet/formats/prepboot.py
+++ b/blivet/formats/prepboot.py
@@ -38,8 +38,8 @@ class PPCPRePBoot(DeviceFormat):
partedFlag = PARTITION_PREP
_formattable = True # can be formatted
_linuxNative = True # for clearpart
- _maxSize = Size(spec="10 MiB")
- _minSize = Size(spec="4 MiB")
+ _maxSize = Size("10 MiB")
+ _minSize = Size("4 MiB")
def __init__(self, *args, **kwargs):
"""
diff --git a/blivet/formats/swap.py b/blivet/formats/swap.py
index d7f5efb..5b1d0c5 100644
--- a/blivet/formats/swap.py
+++ b/blivet/formats/swap.py
@@ -43,7 +43,7 @@ class SwapSpace(DeviceFormat):
_linuxNative = True # for clearpart
#see rhbz#744129 for details
- _maxSize = Size(spec="128 GiB")
+ _maxSize = Size("128 GiB")
def __init__(self, *args, **kwargs):
"""
diff --git a/blivet/partitioning.py b/blivet/partitioning.py
index 78956bc..abf9ace 100644
--- a/blivet/partitioning.py
+++ b/blivet/partitioning.py
@@ -60,7 +60,7 @@ def _getCandidateDisks(storage):
part = part.nextPartition()
continue
- if Size(bytes=part.getLength(unit="B")) > PartitionDevice.defaultSize:
+ if Size(part.getLength(unit="B")) > PartitionDevice.defaultSize:
disks.append(disk)
break
@@ -132,9 +132,9 @@ def _schedulePartitions(storage, disks):
log.error("no free space on disks %s", [d.name for d in disks])
return
- free = Size(bytes=all_free[0].getLength(unit="B"))
+ free = Size(all_free[0].getLength(unit="B"))
if len(all_free) > 1:
- free += Size(bytes=all_free[1].getLength(unit="B"))
+ free += Size(all_free[1].getLength(unit="B"))
# The boot disk must be set at this point. See if any platform-specific
# stage1 device we might allocate already exists on the boot disk.
@@ -577,7 +577,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(bytes=free_geom.getLength(unit="B")))
+ Size(free_geom.getLength(unit="B")))
if start is not None and not free_geom.containsSector(start):
log.debug("free region does not contain requested start sector")
continue
@@ -594,8 +594,8 @@ def getBestFreeSpaceRegion(disk, part_type, req_size, start=None,
continue
if boot:
- max_boot = Size(spec="2 TiB")
- free_start = Size(bytes=(free_geom.start * disk.device.sectorSize))
+ max_boot = Size("2 TiB")
+ free_start = Size(free_geom.start * disk.device.sectorSize)
req_end = free_start + req_size
if req_end > max_boot:
log.debug("free range position would place boot req above %s",
@@ -604,8 +604,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(bytes=free_geom.getLength(unit="B")))
- free_size = Size(bytes=free_geom.getLength(unit="B"))
+ Size(free_geom.getLength(unit="B")))
+ free_size = Size(free_geom.getLength(unit="B"))
# For boot partitions, we want the first suitable region we find.
# For growable or extended partitions, we want the largest possible
@@ -637,7 +637,7 @@ def sectorsToSize(sectors, sectorSize):
:returns: the size
:rtype: :class:`~.size.Size`
"""
- return Size(bytes=(sectors * sectorSize))
+ return Size(sectors * sectorSize)
def sizeToSectors(size, sectorSize):
""" Convert size to length in sectors.
@@ -717,7 +717,7 @@ def addPartition(disklabel, free, part_type, size, start=None, end=None):
alignment unless a start sector is provided.
"""
- sectorSize = Size(bytes=disklabel.partedDevice.sectorSize)
+ sectorSize = Size(disklabel.partedDevice.sectorSize)
if start is not None:
if end is None:
end = start + sizeToSectors(size, sectorSize) - 1
@@ -1113,7 +1113,7 @@ def allocatePartitions(storage, disks, partitions, freespace):
# grow all growable requests
disk_growth = 0 # in sectors
- disk_sector_size = Size(bytes=disklabels[disk_path].partedDevice.sectorSize)
+ disk_sector_size = Size(disklabels[disk_path].partedDevice.sectorSize)
for chunk in chunks:
chunk.growRequests()
# record the growth for this layout
@@ -1162,7 +1162,7 @@ def allocatePartitions(storage, disks, partitions, freespace):
use_disk = _disk
log.debug("new free: %d-%d / %s", best.start,
best.end,
- Size(bytes=best.getLength(unit="B")))
+ Size(best.getLength(unit="B")))
log.debug("new free allows for %d sectors of growth", growth)
free = best
@@ -1204,7 +1204,7 @@ def allocatePartitions(storage, disks, partitions, freespace):
_part.req_start_sector, _part.req_end_sector)
log.debug("created partition %s of %s and added it to %s",
partition.getDeviceNodeName(),
- Size(bytes=partition.getLength(unit="B")),
+ Size(partition.getLength(unit="B")),
disklabel.device)
# this one sets the name
@@ -1265,7 +1265,7 @@ class PartitionRequest(Request):
super(PartitionRequest, self).__init__(partition)
self.base = partition.partedPartition.geometry.length # base sectors
- sector_size = Size(bytes=partition.partedPartition.disk.device.sectorSize)
+ sector_size = Size(partition.partedPartition.disk.device.sectorSize)
if partition.req_grow:
limits = filter(lambda l: l > 0,
@@ -1544,7 +1544,7 @@ class DiskChunk(Chunk):
"""
self.geometry = geometry # parted.Geometry
- self.sectorSize = Size(bytes=self.geometry.device.sectorSize)
+ self.sectorSize = Size(self.geometry.device.sectorSize)
self.path = self.geometry.device.path
super(DiskChunk, self).__init__(self.geometry.length, requests=requests)
@@ -1622,7 +1622,7 @@ class DiskChunk(Chunk):
# 2TB limit on bootable partitions, regardless of disklabel
if req.device.req_bootable:
- max_boot = sizeToSectors(Size(spec="2 TiB"), self.sectorSize)
+ max_boot = sizeToSectors(Size("2 TiB"), self.sectorSize)
limits.append(max_boot - req_end)
# request-specific maximum (see Request.__init__, above, for details)
diff --git a/blivet/platform.py b/blivet/platform.py
index 5315132..62eb9ac 100644
--- a/blivet/platform.py
+++ b/blivet/platform.py
@@ -129,7 +129,7 @@ class Platform(object):
def setDefaultPartitioning(self):
"""Return the default platform-specific partitioning information."""
- return [PartSpec(mountpoint="/boot", size=Size(spec="500MiB"),
+ return [PartSpec(mountpoint="/boot", size=Size("500MiB"),
weight=self.weight(mountpoint="/boot"))]
def weight(self, fstype=None, mountpoint=None):
@@ -167,7 +167,7 @@ class X86(Platform):
def setDefaultPartitioning(self):
"""Return the default platform-specific partitioning information."""
ret = Platform.setDefaultPartitioning(self)
- ret.append(PartSpec(fstype="biosboot", size=Size(spec="1MiB"),
+ ret.append(PartSpec(fstype="biosboot", size=Size("1MiB"),
weight=self.weight(fstype="biosboot")))
return ret
@@ -199,7 +199,7 @@ class EFI(Platform):
def setDefaultPartitioning(self):
ret = Platform.setDefaultPartitioning(self)
ret.append(PartSpec(mountpoint="/boot/efi", fstype="efi",
- size=Size(spec="20MiB"), maxSize=Size(spec="200MiB"),
+ size=Size("20MiB"), maxSize=Size("200MiB"),
grow=True, weight=self.weight(fstype="efi")))
return ret
@@ -221,7 +221,7 @@ class MacEFI(EFI):
def setDefaultPartitioning(self):
ret = Platform.setDefaultPartitioning(self)
ret.append(PartSpec(mountpoint="/boot/efi", fstype="macefi",
- size=Size(spec="20MiB"), maxSize=Size(spec="200MiB"),
+ size=Size("20MiB"), maxSize=Size("200MiB"),
grow=True, weight=self.weight(mountpoint="/boot/efi")))
return ret
@@ -238,7 +238,7 @@ class PPC(Platform):
class IPSeriesPPC(PPC):
_boot_stage1_format_types = ["prepboot"]
- _boot_stage1_max_end = Size(spec="4 GiB")
+ _boot_stage1_max_end = Size("4 GiB")
_boot_prep_description = N_("PReP Boot Partition")
_boot_descriptions = {"partition": _boot_prep_description}
_disklabel_types = ["msdos"]
@@ -248,7 +248,7 @@ class IPSeriesPPC(PPC):
def setDefaultPartitioning(self):
ret = PPC.setDefaultPartitioning(self)
- ret.append(PartSpec(fstype="prepboot", size=Size(spec="4MiB"),
+ ret.append(PartSpec(fstype="prepboot", size=Size("4MiB"),
weight=self.weight(fstype="prepboot")))
return ret
@@ -273,7 +273,7 @@ class NewWorldPPC(PPC):
def setDefaultPartitioning(self):
ret = Platform.setDefaultPartitioning(self)
- ret.append(PartSpec(fstype="appleboot", size=Size(spec="1MiB"),
+ ret.append(PartSpec(fstype="appleboot", size=Size("1MiB"),
weight=self.weight(fstype="appleboot")))
return ret
@@ -308,7 +308,7 @@ class S390(Platform):
def setDefaultPartitioning(self):
"""Return the default platform-specific partitioning information."""
- return [PartSpec(mountpoint="/boot", size=Size(spec="500MiB"),
+ return [PartSpec(mountpoint="/boot", size=Size("500MiB"),
weight=self.weight(mountpoint="/boot"), lv=True,
singlePV=True)]
@@ -357,11 +357,11 @@ class omapARM(ARM):
def setDefaultPartitioning(self):
"""Return the ARM-OMAP platform-specific partitioning information."""
ret = [PartSpec(mountpoint="/boot/uboot", fstype="vfat",
- size=Size(spec="20MiB"), maxSize=Size(spec="200MiB"),
+ size=Size("20MiB"), maxSize=Size("200MiB"),
grow=True,
weight=self.weight(fstype="vfat", mountpoint="/boot/uboot"))]
ret.append(PartSpec(mountpoint="/", fstype="ext4",
- size=Size(spec="2GiB"), maxSize=Size(spec="3GiB"),
+ size=Size("2GiB"), maxSize=Size("3GiB"),
weight=self.weight(mountpoint="/")))
return ret
diff --git a/blivet/size.py b/blivet/size.py
index 02ae536..a317ad3 100644
--- a/blivet/size.py
+++ b/blivet/size.py
@@ -28,7 +28,7 @@ from decimal import Decimal
from decimal import InvalidOperation
from decimal import ROUND_DOWN
-from .errors import SizeParamsError, SizePlacesError
+from .errors import SizePlacesError
from .i18n import _, P_, N_
# Container for size unit prefix information
@@ -181,39 +181,32 @@ class Size(Decimal):
decimal places.
"""
- def __new__(cls, bytes=None, spec=None):
- """ Initialize a new Size object. Must pass either bytes or spec,
- but not both. The bytes parameter is a numerical value for the size
- this object represents, in bytes. The spec parameter is a string
+ def __new__(cls, size):
+ """ Initialize a new Size object. Must pass a bytes or a spec value
+ for size. The bytes value is a numerical value for the size
+ this object represents, in bytes. The spec value is a string
specification of the size using any of the size specifiers in the
_decimalPrefixes or _binaryPrefixes lists combined with a 'b' or
'B'. For example, to specify 640 kilobytes, you could pass any of
- these parameters:
+ these spec parameters:
- spec="640kb"
- spec="640 kb"
- spec="640KB"
- spec="640 KB"
- spec="640 kilobytes"
+ "640kb"
+ "640 kb"
+ "640KB"
+ "640 KB"
+ "640 kilobytes"
- If you want to use spec to pass a bytes value, you can use the
- letter 'b' or 'B' or simply leave the specifier off and bytes
- will be assumed.
+ If you want to use a spec value to represent a bytes value,
+ you can use the letter 'b' or 'B' or omit the size specifier.
"""
- if bytes and spec:
- raise SizeParamsError("only specify one parameter")
-
- if bytes is not None:
- if isinstance(bytes, (int, long, float, Decimal)):
- value = Decimal(bytes)
- elif isinstance(bytes, Size):
- value = Decimal(bytes.convertTo("b"))
- else:
- raise ValueError("invalid value for bytes param")
- elif spec:
- value = _parseSpec(spec)
+ if isinstance(size, (unicode, str)):
+ value = _parseSpec(size)
+ elif isinstance(size, (int, long, float, Decimal)):
+ value = Decimal(size)
+ elif isinstance(size, Size):
+ value = Decimal(size.convertTo("b"))
else:
- raise SizeParamsError("missing bytes= or spec=")
+ raise ValueError("invalid value for size")
# drop any partial byte
value = value.to_integral_value(rounding=ROUND_DOWN)
@@ -228,14 +221,14 @@ class Size(Decimal):
return "Size('%s')" % self
def __deepcopy__(self, memo):
- return Size(bytes=self.convertTo(spec="b"))
+ return Size(self.convertTo(spec="b"))
def __add__(self, other, context=None):
- return Size(bytes=Decimal.__add__(self, other, context=context))
+ return Size(Decimal.__add__(self, other, context=context))
# needed to make sum() work with Size arguments
def __radd__(self, other, context=None):
- return Size(bytes=Decimal.__radd__(self, other, context=context))
+ return Size(Decimal.__radd__(self, other, context=context))
def __sub__(self, other, context=None):
# subtraction is implemented using __add__ and negation, so we'll
@@ -243,13 +236,13 @@ class Size(Decimal):
return Decimal.__sub__(self, other, context=context)
def __mul__(self, other, context=None):
- return Size(bytes=Decimal.__mul__(self, other, context=context))
+ return Size(Decimal.__mul__(self, other, context=context))
def __div__(self, other, context=None):
- return Size(bytes=Decimal.__div__(self, other, context=context))
+ return Size(Decimal.__div__(self, other, context=context))
def __mod__(self, other, context=None):
- return Size(bytes=Decimal.__mod__(self, other, context=context))
+ return Size(Decimal.__mod__(self, other, context=context))
def convertTo(self, spec="b"):
""" Return the size in the units indicated by the specifier. The
diff --git a/blivet/udev.py b/blivet/udev.py
index 95ec4ca..06e6806 100644
--- a/blivet/udev.py
+++ b/blivet/udev.py
@@ -396,15 +396,15 @@ def udev_device_get_vg_uuid(info):
def udev_device_get_vg_size(info):
# lvm's decmial precision is not configurable, so we tell it to use
# KB.
- return Size(spec="%s KiB" % info['LVM2_VG_SIZE'])
+ return Size("%s KiB" % info['LVM2_VG_SIZE'])
def udev_device_get_vg_free(info):
# lvm's decmial precision is not configurable, so we tell it to use
# KB.
- return Size(spec="%s KiB" % info['LVM2_VG_FREE'])
+ return Size("%s KiB" % info['LVM2_VG_FREE'])
def udev_device_get_vg_extent_size(info):
- return Size(spec="%s KiB" % info['LVM2_VG_EXTENT_SIZE'])
+ return Size("%s KiB" % info['LVM2_VG_EXTENT_SIZE'])
def udev_device_get_vg_extent_count(info):
return int(info['LVM2_VG_EXTENT_COUNT'])
@@ -416,7 +416,7 @@ def udev_device_get_vg_pv_count(info):
return int(info['LVM2_PV_COUNT'])
def udev_device_get_pv_pe_start(info):
- return Size(spec="%s KiB" % info['LVM2_PE_START'])
+ return Size("%s KiB" % info['LVM2_PE_START'])
def udev_device_get_lv_name(info):
return info['LVM2_LV_NAME']
@@ -425,7 +425,7 @@ def udev_device_get_lv_uuid(info):
return info['LVM2_LV_UUID']
def udev_device_get_lv_size(info):
- return Size(spec="%s KiB" % info['LVM2_LV_SIZE'])
+ return Size("%s KiB" % info['LVM2_LV_SIZE'])
def udev_device_get_lv_attr(info):
return info['LVM2_LV_ATTR']
diff --git a/blivet/util.py b/blivet/util.py
index d90b9e9..1fd5035 100644
--- a/blivet/util.py
+++ b/blivet/util.py
@@ -138,12 +138,12 @@ def total_memory():
lines = open("/proc/meminfo").readlines()
for line in lines:
if line.startswith("MemTotal:"):
- mem = Size(spec="%s KiB" % line.split()[1])
+ mem = Size("%s KiB" % line.split()[1])
# Because /proc/meminfo only gives us the MemTotal (total physical RAM
# minus the kernel binary code), we need to round this up. Assuming
# every machine has the total RAM MiB number divisible by 128. */
- bs = Size(spec="128MiB")
+ bs = Size("128MiB")
mem = (mem / bs + 1) * bs
return mem
diff --git a/tests/action_test.py b/tests/action_test.py
index 23bc129..2ca312e 100644
--- a/tests/action_test.py
+++ b/tests/action_test.py
@@ -36,7 +36,7 @@ class DeviceActionTestCase(StorageTestCase):
for name in ["sda", "sdb", "sdc", "sdd"]:
disk = self.newDevice(device_class=DiskDevice,
- name=name, size=Size(spec="100 GiB"))
+ name=name, size=Size("100 GiB"))
disk.format = self.newFormat("disklabel", path=disk.path,
exists=True)
self.storage.devicetree._addDevice(disk)
@@ -47,20 +47,20 @@ class DeviceActionTestCase(StorageTestCase):
sda1 = self.newDevice(device_class=PartitionDevice,
exists=True, name="sda1", parents=[sda],
- size=Size(spec="500 MiB"))
+ size=Size("500 MiB"))
sda1.format = self.newFormat("ext4", mountpoint="/boot",
device_instance=sda1,
device=sda1.path, exists=True)
self.storage.devicetree._addDevice(sda1)
sda2 = self.newDevice(device_class=PartitionDevice,
- size=Size(spec="99.5 GiB"), name="sda2",
+ size=Size("99.5 GiB"), name="sda2",
parents=[sda], exists=True)
sda2.format = self.newFormat("lvmpv", device=sda2.path, exists=True)
self.storage.devicetree._addDevice(sda2)
sdb1 = self.newDevice(device_class=PartitionDevice,
- size=Size(spec="99.999 GiB"), name="sdb1",
+ size=Size("99.999 GiB"), name="sdb1",
parents=[sdb], exists=True)
sdb1.format = self.newFormat("lvmpv", device=sdb1.path, exists=True)
self.storage.devicetree._addDevice(sdb1)
@@ -72,7 +72,7 @@ class DeviceActionTestCase(StorageTestCase):
lv_root = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_root", parents=[vg],
- size=Size(spec="160 GiB"), exists=True)
+ size=Size("160 GiB"), exists=True)
lv_root.format = self.newFormat("ext4", mountpoint="/",
device_instance=lv_root,
device=lv_root.path, exists=True)
@@ -80,7 +80,7 @@ class DeviceActionTestCase(StorageTestCase):
lv_swap = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_swap", parents=[vg],
- size=Size(spec="4000 MiB"), exists=True)
+ size=Size("4000 MiB"), exists=True)
lv_swap.format = self.newFormat("swap", device=lv_swap.path,
device_instance=lv_swap,
exists=True)
@@ -126,12 +126,12 @@ class DeviceActionTestCase(StorageTestCase):
self.assertNotEqual(sda, None, "failed to find disk 'sda'")
sda1 = self.newDevice(device_class=PartitionDevice,
- name="sda1", size=Size(spec="500 MiB"),
+ name="sda1", size=Size("500 MiB"),
parents=[sda])
self.scheduleCreateDevice(device=sda1)
sda2 = self.newDevice(device_class=PartitionDevice,
- name="sda2", size=Size(spec="100 GiB"),
+ name="sda2", size=Size("100 GiB"),
parents=[sda])
self.scheduleCreateDevice(device=sda2)
fmt = self.newFormat("lvmpv", device=sda2.path)
@@ -143,21 +143,21 @@ class DeviceActionTestCase(StorageTestCase):
lv_root = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_root", parents=[vg],
- size=Size(spec="60 GiB"))
+ size=Size("60 GiB"))
self.scheduleCreateDevice(device=lv_root)
fmt = self.newFormat("ext4", device=lv_root.path, mountpoint="/")
self.scheduleCreateFormat(device=lv_root, fmt=fmt)
lv_swap = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_swap", parents=[vg],
- size=Size(spec="4000 MiB"))
+ size=Size("4000 MiB"))
self.scheduleCreateDevice(device=lv_swap)
fmt = self.newFormat("swap", device=lv_swap.path)
self.scheduleCreateFormat(device=lv_swap, fmt=fmt)
sda3 = self.newDevice(device_class=PartitionDevice,
name="sda3", parents=[sda],
- size=Size(spec="40 GiB"))
+ size=Size("40 GiB"))
self.scheduleCreateDevice(device=sda3)
fmt = self.newFormat("mdmember", device=sda3.path)
self.scheduleCreateFormat(device=sda3, fmt=fmt)
@@ -167,7 +167,7 @@ class DeviceActionTestCase(StorageTestCase):
sdb1 = self.newDevice(device_class=PartitionDevice,
name="sdb1", parents=[sdb],
- size=Size(spec="40 GiB"))
+ size=Size("40 GiB"))
self.scheduleCreateDevice(device=sdb1)
fmt = self.newFormat("mdmember", device=sdb1.path,)
self.scheduleCreateFormat(device=sdb1, fmt=fmt)
@@ -191,11 +191,11 @@ class DeviceActionTestCase(StorageTestCase):
# XXX resizable depends on existence, so this is covered implicitly
sdd = self.storage.devicetree.getDeviceByName("sdd")
p = self.newDevice(device_class=PartitionDevice,
- name="sdd1", size=Size(spec="32 GiB"), parents=[sdd])
+ name="sdd1", size=Size("32 GiB"), parents=[sdd])
self.failUnlessRaises(ValueError,
ActionResizeDevice,
p,
- p.size + Size(spec="7232 MiB"))
+ p.size + Size("7232 MiB"))
# instantiation of device resize action for non-resizable device
# should fail
@@ -204,7 +204,7 @@ class DeviceActionTestCase(StorageTestCase):
self.failUnlessRaises(ValueError,
ActionResizeDevice,
vg,
- vg.size + Size(spec="32 MiB"))
+ vg.size + Size("32 MiB"))
# instantiation of format resize action for non-resizable format type
# should fail
@@ -213,7 +213,7 @@ class DeviceActionTestCase(StorageTestCase):
self.failUnlessRaises(ValueError,
ActionResizeFormat,
lv_swap,
- lv_swap.size + Size(spec="32 MiB"))
+ lv_swap.size + Size("32 MiB"))
# instantiation of format resize action for non-existent format
# should fail
@@ -223,7 +223,7 @@ class DeviceActionTestCase(StorageTestCase):
self.failUnlessRaises(ValueError,
ActionResizeFormat,
lv_root,
- lv_root.size - Size(spec="1000 MiB"))
+ lv_root.size - Size("1000 MiB"))
lv_root.format.exists = True
# instantiation of device create action for existing device should
@@ -274,7 +274,7 @@ class DeviceActionTestCase(StorageTestCase):
sdc = self.storage.devicetree.getDeviceByName("sdc")
self.assertNotEqual(sdc, None)
sdc1 = self.newDevice(device_class=PartitionDevice,
- name="sdc1", size=Size(spec="100 GiB"),
+ name="sdc1", size=Size("100 GiB"),
parents=[sdc], exists=True)
sdc1_format = self.newFormat("ext2", device=sdc1.path, mountpoint="/")
@@ -287,13 +287,13 @@ class DeviceActionTestCase(StorageTestCase):
sdc1_format.exists = True
resize_sdc1_format = ActionResizeFormat(sdc1,
- sdc1.size - Size(spec="10 GiB"))
+ sdc1.size - Size("10 GiB"))
resize_sdc1_format.apply()
self.failUnlessRaises(blivet.errors.DeviceTreeError,
self.storage.devicetree.registerAction,
resize_sdc1_format)
- resize_sdc1 = ActionResizeDevice(sdc1, sdc1.size - Size(spec="10 GiB"))
+ resize_sdc1 = ActionResizeDevice(sdc1, sdc1.size - Size("10 GiB"))
resize_sdc1.apply()
self.failUnlessRaises(blivet.errors.DeviceTreeError,
self.storage.devicetree.registerAction,
@@ -330,7 +330,7 @@ class DeviceActionTestCase(StorageTestCase):
sdd1 = self.storage.devicetree.getDeviceByName("sdd1")
self.assertEqual(sdd1, None)
sdd1 = self.newDevice(device_class=PartitionDevice,
- name="sdd1", size=Size(spec="100 GiB"),
+ name="sdd1", size=Size("100 GiB"),
parents=[sdd])
a = ActionCreateDevice(sdd1)
self.storage.devicetree.registerAction(a)
@@ -344,7 +344,7 @@ class DeviceActionTestCase(StorageTestCase):
self.assertNotEqual(sdc, None)
sdc1 = self.newDevice(device_class=PartitionDevice,
- name="sdc1", parents=[sdc], size=Size(spec="40 GiB"))
+ name="sdc1", parents=[sdc], size=Size("40 GiB"))
# ActionCreateDevice
#
@@ -376,9 +376,9 @@ class DeviceActionTestCase(StorageTestCase):
# device
sdc1.exists = True
sdc1.format.exists = True
- resize_format_1 = ActionResizeFormat(sdc1, sdc1.size - Size(spec="1000 MiB"))
+ resize_format_1 = ActionResizeFormat(sdc1, sdc1.size - Size("1000 MiB"))
resize_format_1.apply()
- resize_format_2 = ActionResizeFormat(sdc1, sdc1.size - Size(spec="5000 MiB"))
+ resize_format_2 = ActionResizeFormat(sdc1, sdc1.size - Size("5000 MiB"))
resize_format_2.apply()
self.assertEqual(resize_format_2.obsoletes(resize_format_1), True)
self.assertEqual(resize_format_1.obsoletes(resize_format_2), False)
@@ -401,10 +401,10 @@ class DeviceActionTestCase(StorageTestCase):
sdc1.exists = True
sdc1.format.exists = True
resize_device_1 = ActionResizeDevice(sdc1,
- sdc1.size + Size(spec="10 GiB"))
+ sdc1.size + Size("10 GiB"))
resize_device_1.apply()
resize_device_2 = ActionResizeDevice(sdc1,
- sdc1.size - Size(spec="10 GiB"))
+ sdc1.size - Size("10 GiB"))
resize_device_2.apply()
self.assertEqual(resize_device_2.obsoletes(resize_device_1), True)
self.assertEqual(resize_device_1.obsoletes(resize_device_2), False)
@@ -442,9 +442,9 @@ class DeviceActionTestCase(StorageTestCase):
sda1 = self.storage.devicetree.getDeviceByName("sda1")
self.assertNotEqual(sda1, None)
resize_sda1_format = ActionResizeFormat(sda1,
- sda1.size - Size(spec="50 MiB"))
+ sda1.size - Size("50 MiB"))
resize_sda1_format.apply()
- resize_sda1 = ActionResizeDevice(sda1, sda1.size - Size(spec="50 MiB"))
+ resize_sda1 = ActionResizeDevice(sda1, sda1.size - Size("50 MiB"))
resize_sda1.apply()
destroy_sda1_format = ActionDestroyFormat(sda1)
destroy_sda1_format.apply()
@@ -463,12 +463,12 @@ class DeviceActionTestCase(StorageTestCase):
self.assertNotEqual(sda, None, "failed to find disk 'sda'")
sda1 = self.newDevice(device_class=PartitionDevice,
- name="sda1", size=Size(spec="500 MiB"),
+ name="sda1", size=Size("500 MiB"),
parents=[sda])
self.scheduleCreateDevice(device=sda1)
sda2 = self.newDevice(device_class=PartitionDevice,
- name="sda2", size=Size(spec="100 GiB"),
+ name="sda2", size=Size("100 GiB"),
parents=[sda])
self.scheduleCreateDevice(device=sda2)
fmt = self.newFormat("lvmpv", device=sda2.path)
@@ -480,14 +480,14 @@ class DeviceActionTestCase(StorageTestCase):
lv_root = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_root", parents=[vg],
- size=Size(spec="60 GiB"))
+ size=Size("60 GiB"))
self.scheduleCreateDevice(device=lv_root)
fmt = self.newFormat("ext4", device=lv_root.path, mountpoint="/")
self.scheduleCreateFormat(device=lv_root, fmt=fmt)
lv_swap = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_swap", parents=[vg],
- size=Size(spec="4 GiB"))
+ size=Size("4 GiB"))
self.scheduleCreateDevice(device=lv_swap)
fmt = self.newFormat("swap", device=lv_swap.path)
self.scheduleCreateFormat(device=lv_swap, fmt=fmt)
@@ -496,7 +496,7 @@ class DeviceActionTestCase(StorageTestCase):
# which will test pruning. the whole mess should reduce to nothing
sda3 = self.newDevice(device_class=PartitionDevice,
name="sda3", parents=[sda],
- size=Size(spec="40 GiB"))
+ size=Size("40 GiB"))
self.scheduleCreateDevice(device=sda3)
fmt = self.newFormat("mdmember", device=sda3.path)
self.scheduleCreateFormat(device=sda3, fmt=fmt)
@@ -506,7 +506,7 @@ class DeviceActionTestCase(StorageTestCase):
sdb1 = self.newDevice(device_class=PartitionDevice,
name="sdb1", parents=[sdb],
- size=Size(spec="40 GiB"))
+ size=Size("40 GiB"))
self.scheduleCreateDevice(device=sdb1)
fmt = self.newFormat("mdmember", device=sdb1.path,)
self.scheduleCreateFormat(device=sdb1, fmt=fmt)
@@ -558,13 +558,13 @@ class DeviceActionTestCase(StorageTestCase):
# shrinks the device's format
lv_root = self.storage.devicetree.getDeviceByName("VolGroup-lv_root")
self.assertNotEqual(lv_root, None)
- lv_root.format._minInstanceSize = Size(spec="10 MiB")
+ lv_root.format._minInstanceSize = Size("10 MiB")
lv_root.format._targetSize = lv_root.format._minInstanceSize
shrink_format = ActionResizeFormat(lv_root,
- lv_root.size - Size(spec="5 GiB"))
+ lv_root.size - Size("5 GiB"))
shrink_format.apply()
shrink_device = ActionResizeDevice(lv_root,
- lv_root.size - Size(spec="5 GiB"))
+ lv_root.size - Size("5 GiB"))
shrink_device.apply()
self.assertEqual(shrink_device.requires(shrink_format), True)
self.assertEqual(shrink_format.requires(shrink_device), False)
@@ -576,10 +576,10 @@ class DeviceActionTestCase(StorageTestCase):
# grows the device
orig_size = lv_root.currentSize
grow_device = ActionResizeDevice(lv_root,
- orig_size + Size(spec="100 MiB"))
+ orig_size + Size("100 MiB"))
grow_device.apply()
grow_format = ActionResizeFormat(lv_root,
- orig_size + Size(spec="100 MiB"))
+ orig_size + Size("100 MiB"))
grow_format.apply()
self.assertEqual(grow_format.requires(grow_device), True)
self.assertEqual(grow_device.requires(grow_format), False)
@@ -589,20 +589,20 @@ class DeviceActionTestCase(StorageTestCase):
sda = self.storage.devicetree.getDeviceByName("sda")
sdb = self.storage.devicetree.getDeviceByName("sdb")
sda1 = self.newDevice(device_class=PartitionDevice, name="sda1",
- size=Size(spec="500 MiB"), parents=[sda])
+ size=Size("500 MiB"), parents=[sda])
sda1_format = self.newFormat("ext4", mountpoint="/boot",
device=sda1.path)
self.scheduleCreateDevice(device=sda1)
self.scheduleCreateFormat(device=sda1, fmt=sda1_format)
sda2 = self.newDevice(device_class=PartitionDevice, name="sda2",
- size=Size(spec="99.5 GiB"), parents=[sda])
+ size=Size("99.5 GiB"), parents=[sda])
sda2_format = self.newFormat("lvmpv", device=sda2.path)
self.scheduleCreateDevice(device=sda2)
self.scheduleCreateFormat(device=sda2, fmt=sda2_format)
sdb1 = self.newDevice(device_class=PartitionDevice, name="sdb1",
- size=Size(spec="100 GiB"), parents=[sdb])
+ size=Size("100 GiB"), parents=[sdb])
sdb1_format = self.newFormat("lvmpv", device=sdb1.path)
self.scheduleCreateDevice(device=sdb1)
self.scheduleCreateFormat(device=sdb1, fmt=sdb1_format)
@@ -613,14 +613,14 @@ class DeviceActionTestCase(StorageTestCase):
lv_root = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_root", parents=[vg],
- size=Size(spec="160 GiB"))
+ size=Size("160 GiB"))
self.scheduleCreateDevice(device=lv_root)
fmt = self.newFormat("ext4", device=lv_root.path, mountpoint="/")
self.scheduleCreateFormat(device=lv_root, fmt=fmt)
lv_swap = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_swap", parents=[vg],
- size=Size(spec="4 GiB"))
+ size=Size("4 GiB"))
self.scheduleCreateDevice(device=lv_swap)
fmt = self.newFormat("swap", device=lv_swap.path)
self.scheduleCreateFormat(device=lv_swap, fmt=fmt)
@@ -675,12 +675,12 @@ class DeviceActionTestCase(StorageTestCase):
self.assertNotEqual(sdc, None)
sdc1 = self.newDevice(device_class=PartitionDevice, name="sdc1",
- parents=[sdc], size=Size(spec="50 GiB"))
+ parents=[sdc], size=Size("50 GiB"))
create_sdc1 = self.scheduleCreateDevice(device=sdc1)
self.assertEqual(isinstance(create_sdc1, ActionCreateDevice), True)
sdc2 = self.newDevice(device_class=PartitionDevice, name="sdc2",
- parents=[sdc], size=Size(spec="50 GiB"))
+ parents=[sdc], size=Size("50 GiB"))
create_sdc2 = self.scheduleCreateDevice(device=sdc2)
self.assertEqual(isinstance(create_sdc2, ActionCreateDevice), True)
@@ -712,13 +712,13 @@ class DeviceActionTestCase(StorageTestCase):
self.assertNotEqual(sdd, None)
sdc1 = self.newDevice(device_class=PartitionDevice, name="sdc1",
- parents=[sdc], size=Size(spec="40 GiB"))
+ parents=[sdc], size=Size("40 GiB"))
self.scheduleCreateDevice(device=sdc1)
fmt = self.newFormat("mdmember", device=sdc1.path)
self.scheduleCreateFormat(device=sdc1, fmt=fmt)
sdd1 = self.newDevice(device_class=PartitionDevice, name="sdd1",
- parents=[sdd], size=Size(spec="40 GiB"))
+ parents=[sdd], size=Size("40 GiB"))
self.scheduleCreateDevice(device=sdd1)
fmt = self.newFormat("mdmember", device=sdd1.path,)
self.scheduleCreateFormat(device=sdd1, fmt=fmt)
@@ -749,11 +749,11 @@ class DeviceActionTestCase(StorageTestCase):
# numbered partition, eg: destroy sda2 before destroying sda1
self.destroyAllDevices(disks=["sdc", "sdd"])
sdc1 = self.newDevice(device_class=PartitionDevice, name="sdc1",
- parents=[sdc], size=Size(spec="50 GiB"))
+ parents=[sdc], size=Size("50 GiB"))
self.scheduleCreateDevice(device=sdc1)
sdc2 = self.newDevice(device_class=PartitionDevice, name="sdc2",
- parents=[sdc], size=Size(spec="40 GiB"))
+ parents=[sdc], size=Size("40 GiB"))
self.scheduleCreateDevice(device=sdc2)
destroy_sdc1 = self.scheduleDestroyDevice(device=sdc1)
@@ -768,7 +768,7 @@ class DeviceActionTestCase(StorageTestCase):
self.assertNotEqual(sdd, None)
sdc1 = self.newDevice(device_class=PartitionDevice, name="sdc1",
- parents=[sdc], size=Size(spec="50 GiB"))
+ parents=[sdc], size=Size("50 GiB"))
create_pv = self.scheduleCreateDevice(device=sdc1)
fmt = self.newFormat("lvmpv", device=sdc1.path)
create_pv_format = self.scheduleCreateFormat(device=sdc1, fmt=fmt)
@@ -778,7 +778,7 @@ class DeviceActionTestCase(StorageTestCase):
create_vg = self.scheduleCreateDevice(device=testvg)
testlv = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="testlv", parents=[testvg],
- size=Size(spec="30 GiB"))
+ size=Size("30 GiB"))
create_lv = self.scheduleCreateDevice(device=testlv)
fmt = self.newFormat("ext4", device=testlv.path)
create_lv_format = self.scheduleCreateFormat(device=testlv, fmt=fmt)
@@ -804,14 +804,14 @@ class DeviceActionTestCase(StorageTestCase):
self.destroyAllDevices(disks=["sdc", "sdd"])
sdc1 = self.newDevice(device_class=PartitionDevice, exists=True,
name="sdc1", parents=[sdc],
- size=Size(spec="50 GiB"))
+ size=Size("50 GiB"))
sdc1.format = self.newFormat("lvmpv", device=sdc1.path, exists=True,
device_instance=sdc1)
testvg = self.newDevice(device_class=LVMVolumeGroupDevice, exists=True,
name="testvg", parents=[sdc1],
- size=Size(spec="50 GiB"))
+ size=Size("50 GiB"))
testlv = self.newDevice(device_class=LVMLogicalVolumeDevice,
- exists=True, size=Size(spec="30 GiB"),
+ exists=True, size=Size("30 GiB"),
name="testlv", parents=[testvg])
testlv.format = self.newFormat("ext4", device=testlv.path,
exists=True, device_instance=testlv)
@@ -823,12 +823,12 @@ class DeviceActionTestCase(StorageTestCase):
sdc1.format._resizable = True # override lvmpv.resizable
sdc1.exists = True
sdc1.format.exists = True
- grow_pv = ActionResizeDevice(sdc1, sdc1.size + Size(spec="10 GiB"))
+ grow_pv = ActionResizeDevice(sdc1, sdc1.size + Size("10 GiB"))
grow_pv.apply()
- grow_lv = ActionResizeDevice(testlv, testlv.size + Size(spec="5 GiB"))
+ grow_lv = ActionResizeDevice(testlv, testlv.size + Size("5 GiB"))
grow_lv.apply()
grow_lv_format = ActionResizeFormat(testlv,
- testlv.size + Size(spec="5 GiB"))
+ testlv.size + Size("5 GiB"))
grow_lv_format.apply()
sdc1.exists = False
sdc1.format.exists = False
@@ -869,14 +869,14 @@ class DeviceActionTestCase(StorageTestCase):
# an action that resizes a device should require an action that
# shrinks a device that depends on the first action's device, eg:
# shrink LV before resizing VG or PV devices
- testlv.format._minInstanceSize = Size(spec="10 MiB")
+ testlv.format._minInstanceSize = Size("10 MiB")
testlv.format._targetSize = testlv.format._minInstanceSize
shrink_lv = ActionResizeDevice(testlv,
- testlv.size - Size(spec="10 GiB"))
+ testlv.size - Size("10 GiB"))
shrink_lv.apply()
sdc1.exists = True
sdc1.format.exists = True
- shrink_pv = ActionResizeDevice(sdc1, sdc1.size - Size(spec="5 GiB"))
+ shrink_pv = ActionResizeDevice(sdc1, sdc1.size - Size("5 GiB"))
shrink_pv.apply()
sdc1.exists = False
sdc1.format.exists = False
@@ -922,7 +922,7 @@ class DeviceActionTestCase(StorageTestCase):
# ActionCreateFormat
# an action that creates a format on a device should require an action
# that resizes the device that will contain the format
- grow_lv = ActionResizeDevice(testlv, testlv.size + Size(spec="1 GiB"))
+ grow_lv = ActionResizeDevice(testlv, testlv.size + Size("1 GiB"))
fmt = self.newFormat("msdos", device=testlv.path)
format_lv = ActionCreateFormat(testlv, fmt)
self.assertEqual(format_lv.requires(grow_lv), True)
@@ -945,7 +945,7 @@ class DeviceActionTestCase(StorageTestCase):
self.assertEqual(destroy_lv_format.requires(destroy_pv_format), False)
sdc2 = self.newDevice(device_class=PartitionDevice, name="sdc2",
- size=Size(spec="5 GiB"), parents=[sdc])
+ size=Size("5 GiB"), parents=[sdc])
create_sdc2 = self.scheduleCreateDevice(device=sdc2)
# create actions should always require destroy actions -- even for
@@ -961,11 +961,11 @@ class DeviceActionTestCase(StorageTestCase):
lv_root = self.storage.devicetree.getDeviceByName("VolGroup-lv_root")
# ActionResizeFormat
- lv_root.format._minInstanceSize = Size(spec="10 MiB")
+ lv_root.format._minInstanceSize = Size("10 MiB")
lv_root.format._size = lv_root.size
lv_root.format._targetSize = lv_root.size
original_format_size = lv_root.format.currentSize
- target_size = lv_root.size - Size(spec="1 GiB")
+ target_size = lv_root.size - Size("1 GiB")
action = ActionResizeFormat(lv_root, target_size)
self.assertEqual(lv_root.format.size, original_format_size)
action.apply()
@@ -1035,20 +1035,20 @@ class DeviceActionTestCase(StorageTestCase):
#
sda1 = self.newDevice(device_class=PartitionDevice,
exists=True, name="sda1", parents=[sda],
- size=Size(spec="500 MiB"))
+ size=Size("500 MiB"))
sda1.format = self.newFormat("ext4", mountpoint="/boot",
device_instance=sda1,
device=sda1.path, exists=True)
self.storage.devicetree._addDevice(sda1)
sda2 = self.newDevice(device_class=PartitionDevice,
- size=Size(spec="99.5 GiB"), name="sda2",
+ size=Size("99.5 GiB"), name="sda2",
parents=[sda], exists=True)
sda2.format = self.newFormat("lvmpv", device=sda2.path, exists=True)
self.storage.devicetree._addDevice(sda2)
sdb1 = self.newDevice(device_class=PartitionDevice,
- size=Size(spec="99.999 GiB"), name="sdb1",
+ size=Size("99.999 GiB"), name="sdb1",
parents=[sdb], exists=True)
sdb1.format = self.newFormat("lvmpv", device=sdb1.path, exists=True)
self.storage.devicetree._addDevice(sdb1)
@@ -1060,7 +1060,7 @@ class DeviceActionTestCase(StorageTestCase):
lv_root = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_root", parents=[vg],
- size=Size(spec="160 GiB"), exists=True)
+ size=Size("160 GiB"), exists=True)
lv_root.format = self.newFormat("ext4", mountpoint="/",
device_instance=lv_root,
device=lv_root.path, exists=True)
@@ -1068,7 +1068,7 @@ class DeviceActionTestCase(StorageTestCase):
lv_swap = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_swap", parents=[vg],
- size=Size(spec="4000 MiB"), exists=True)
+ size=Size("4000 MiB"), exists=True)
lv_swap.format = self.newFormat("swap", device=lv_swap.path,
device_instance=lv_swap,
exists=True)
@@ -1079,7 +1079,7 @@ class DeviceActionTestCase(StorageTestCase):
#
sdc = self.storage.devicetree.getDeviceByName("sdc")
sdc1 = self.newDevice(device_class=PartitionDevice, name="sdc1",
- size=Size(spec="50 GiB"), parents=[sdc])
+ size=Size("50 GiB"), parents=[sdc])
sdc1_format = self.newFormat("lvmpv", device=sdc1.path)
create_sdc1 = self.scheduleCreateDevice(device=sdc1)
create_sdc1_format = self.scheduleCreateFormat(device=sdc1,
@@ -1097,7 +1097,7 @@ class DeviceActionTestCase(StorageTestCase):
new_lv = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="newlv", parents=[vg],
- size=Size(spec="20 GiB"))
+ size=Size("20 GiB"))
create_new_lv = self.scheduleCreateDevice(device=new_lv)
new_lv_format = self.newFormat("xfs", device=new_lv.path)
create_new_lv_format = self.scheduleCreateFormat(device=new_lv,
@@ -1134,7 +1134,7 @@ class DeviceActionTestCase(StorageTestCase):
self.assertEqual(remove_sdb1.obsoletes(add_sdb1), True)
sdc2 = self.newDevice(device_class=PartitionDevice, name="sdc2",
- size=Size(spec="5 GiB"), parents=[sdc])
+ size=Size("5 GiB"), parents=[sdc])
create_sdc2 = self.scheduleCreateDevice(device=sdc2)
# destroy/resize/create sequencing does not apply to container actions
diff --git a/tests/devicefactory_test.py b/tests/devicefactory_test.py
index 6b06137..28fa079 100644
--- a/tests/devicefactory_test.py
+++ b/tests/devicefactory_test.py
@@ -18,11 +18,11 @@ class MDFactoryTestCase(unittest.TestCase):
self.b = blivet.Blivet()
self.factory1 = devicefactory.get_device_factory(self.b,
devicefactory.DEVICE_TYPE_MD,
- Size(spec="1 GiB"))
+ Size("1 GiB"))
self.factory2 = devicefactory.get_device_factory(self.b,
devicefactory.DEVICE_TYPE_MD,
- Size(spec="1 GiB"),
+ Size("1 GiB"),
raid_level=0)
def testMDFactory(self):
diff --git a/tests/devicelibs_test/lvm_test.py b/tests/devicelibs_test/lvm_test.py
index 5bbd259..ec82587 100755
--- a/tests/devicelibs_test/lvm_test.py
+++ b/tests/devicelibs_test/lvm_test.py
@@ -13,16 +13,16 @@ class LVMTestCase(unittest.TestCase):
def testGetPossiblePhysicalExtents(self):
# pass
self.assertEqual(lvm.getPossiblePhysicalExtents(),
- map(lambda power: Size(spec="%d KiB" % 2**power),
+ map(lambda power: Size("%d KiB" % 2**power),
xrange(0, 25)))
def testClampSize(self):
# pass
- self.assertEqual(lvm.clampSize(Size(spec="10 MiB"), Size(spec="4 MiB")),
- Size(spec="8 MiB"))
- self.assertEqual(lvm.clampSize(Size(spec="10 MiB"), Size(spec="4 MiB"),
+ self.assertEqual(lvm.clampSize(Size("10 MiB"), Size("4 MiB")),
+ Size("8 MiB"))
+ self.assertEqual(lvm.clampSize(Size("10 MiB"), Size("4 MiB"),
True),
- Size(spec="12 MiB"))
+ Size("12 MiB"))
# FIXME: Some of these tests expect behavior that is not entirely correct.
#
@@ -87,36 +87,36 @@ class LVMAsRootTestCase(baseclass.DevicelibsTestCase):
##
# pass
for dev in self._loopMap.values():
- self.assertEqual(lvm.pvresize(dev, Size(spec="50MiB")), None)
- self.assertEqual(lvm.pvresize(dev, Size(spec="100MiB")), None)
+ self.assertEqual(lvm.pvresize(dev, Size("50MiB")), None)
+ self.assertEqual(lvm.pvresize(dev, Size("100MiB")), None)
# fail
self.assertRaisesRegexp(LVMError,
"pvresize failed",
lvm.pvresize,
- "/not/existing/device", Size(spec="50MiB"))
+ "/not/existing/device", Size("50MiB"))
##
## vgcreate
##
# pass
- self.assertEqual(lvm.vgcreate(self._vg_name, [_LOOP_DEV0, _LOOP_DEV1], Size(spec="4MiB")), None)
+ self.assertEqual(lvm.vgcreate(self._vg_name, [_LOOP_DEV0, _LOOP_DEV1], Size("4MiB")), None)
# fail
self.assertRaisesRegexp(LVMError,
"vgcreate failed",
lvm.vgcreate,
- "another-vg", ["/not/existing/device"], Size(spec="4MiB"))
+ "another-vg", ["/not/existing/device"], Size("4MiB"))
# vg already exists
self.assertRaisesRegexp(LVMError,
"vgcreate failed",
lvm.vgcreate,
- self._vg_name, [_LOOP_DEV0], Size(spec="4MiB"))
+ self._vg_name, [_LOOP_DEV0], Size("4MiB"))
# pe size must be power of 2
self.assertRaisesRegexp(LVMError,
"vgcreate failed",
lvm.vgcreate,
- "another-vg", [_LOOP_DEV0], Size(spec="5MiB"))
+ "another-vg", [_LOOP_DEV0], Size("5MiB"))
##
## vgdeactivate
@@ -169,10 +169,10 @@ class LVMAsRootTestCase(baseclass.DevicelibsTestCase):
## lvcreate
##
# pass
- self.assertEqual(lvm.lvcreate(self._vg_name, self._lv_name, Size(spec="10MiB")), None)
+ self.assertEqual(lvm.lvcreate(self._vg_name, self._lv_name, Size("10MiB")), None)
# fail
- self.assertRaises(LVMError, lvm.lvcreate, "wrong-vg-name", "another-lv", Size(spec="10MiB"))
+ self.assertRaises(LVMError, lvm.lvcreate, "wrong-vg-name", "another-lv", Size("10MiB"))
##
## lvdeactivate
@@ -189,14 +189,14 @@ class LVMAsRootTestCase(baseclass.DevicelibsTestCase):
## lvresize
##
# pass
- self.assertEqual(lvm.lvresize(self._vg_name, self._lv_name, Size(spec="60MiB")), None)
+ self.assertEqual(lvm.lvresize(self._vg_name, self._lv_name, Size("60MiB")), None)
# fail
- self.assertRaises(LVMError, lvm.lvresize, self._vg_name, "wrong-lv-name", Size(spec="80MiB"))
- self.assertRaises(LVMError, lvm.lvresize, "wrong-vg-name", self._lv_name, Size(spec="80MiB"))
- self.assertRaises(LVMError, lvm.lvresize, "wrong-vg-name", "wrong-lv-name", Size(spec="80MiB"))
+ self.assertRaises(LVMError, lvm.lvresize, self._vg_name, "wrong-lv-name", Size("80MiB"))
+ self.assertRaises(LVMError, lvm.lvresize, "wrong-vg-name", self._lv_name, Size("80MiB"))
+ self.assertRaises(LVMError, lvm.lvresize, "wrong-vg-name", "wrong-lv-name", Size("80MiB"))
# changing to same size
- self.assertRaises(LVMError, lvm.lvresize, self._vg_name, self._lv_name, Size(spec="60MiB"))
+ self.assertRaises(LVMError, lvm.lvresize, self._vg_name, self._lv_name, Size("60MiB"))
##
## lvactivate
diff --git a/tests/devicelibs_test/mdraid_test.py b/tests/devicelibs_test/mdraid_test.py
index fbb6e43..8de5414 100755
--- a/tests/devicelibs_test/mdraid_test.py
+++ b/tests/devicelibs_test/mdraid_test.py
@@ -27,24 +27,24 @@ class MDRaidTestCase(unittest.TestCase):
##
## get_raid_superblock_size
##
- self.assertEqual(mdraid.get_raid_superblock_size(Size(spec="256 GiB")),
- Size(spec="128 MiB"))
- self.assertEqual(mdraid.get_raid_superblock_size(Size(spec="128 GiB")),
- Size(spec="128 MiB"))
- self.assertEqual(mdraid.get_raid_superblock_size(Size(spec="64 GiB")),
- Size(spec="64 MiB"))
- self.assertEqual(mdraid.get_raid_superblock_size(Size(spec="63 GiB")),
- Size(spec="32 MiB"))
- self.assertEqual(mdraid.get_raid_superblock_size(Size(spec="10 GiB")),
- Size(spec="8 MiB"))
- self.assertEqual(mdraid.get_raid_superblock_size(Size(spec="1 GiB")),
- Size(spec="1 MiB"))
- self.assertEqual(mdraid.get_raid_superblock_size(Size(spec="1023 MiB")),
- Size(spec="1 MiB"))
- self.assertEqual(mdraid.get_raid_superblock_size(Size(spec="512 MiB")),
- Size(spec="1 MiB"))
-
- self.assertEqual(mdraid.get_raid_superblock_size(Size(spec="257 MiB"),
+ self.assertEqual(mdraid.get_raid_superblock_size(Size("256 GiB")),
+ Size("128 MiB"))
+ self.assertEqual(mdraid.get_raid_superblock_size(Size("128 GiB")),
+ Size("128 MiB"))
+ self.assertEqual(mdraid.get_raid_superblock_size(Size("64 GiB")),
+ Size("64 MiB"))
+ self.assertEqual(mdraid.get_raid_superblock_size(Size("63 GiB")),
+ Size("32 MiB"))
+ self.assertEqual(mdraid.get_raid_superblock_size(Size("10 GiB")),
+ Size("8 MiB"))
+ self.assertEqual(mdraid.get_raid_superblock_size(Size("1 GiB")),
+ Size("1 MiB"))
+ self.assertEqual(mdraid.get_raid_superblock_size(Size("1023 MiB")),
+ Size("1 MiB"))
+ self.assertEqual(mdraid.get_raid_superblock_size(Size("512 MiB")),
+ Size("1 MiB"))
+
+ self.assertEqual(mdraid.get_raid_superblock_size(Size("257 MiB"),
version="version"),
mdraid.MD_SUPERBLOCK_SIZE)
diff --git a/tests/devices_test.py b/tests/devices_test.py
index ffeb78a..1ab8bb3 100644
--- a/tests/devices_test.py
+++ b/tests/devices_test.py
@@ -62,7 +62,7 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
def setUp(self):
self._state_functions = {
"createBitmap" : self.assertTrue,
- "currentSize" : lambda x, m: self.assertEqual(x, Size(bytes=0), m),
+ "currentSize" : lambda x, m: self.assertEqual(x, Size(0), m),
"description" : self.assertIsNotNone,
"devices" : lambda x, m: self.assertEqual(len(x), 0, m) and
self.assertIsInstance(x, ParentList, m),
@@ -73,7 +73,7 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
"isDisk" : self.assertFalse,
"level" : self.assertIsNone,
"major" : lambda x, m: self.assertEqual(x, 0, m),
- "maxSize" : lambda x, m: self.assertEqual(x, Size(bytes=0), m),
+ "maxSize" : lambda x, m: self.assertEqual(x, Size(0), m),
"mediaPresent" : self.assertFalse,
"metadataVersion" : lambda x, m: self.assertEqual(x, "default", m),
"minor" : lambda x, m: self.assertEqual(x, 0, m),
@@ -81,15 +81,15 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
self.assertIsInstance(x, ParentList, m),
"path" : lambda x, m: self.assertRegexpMatches(x, "^/dev", m),
"partitionable" : self.assertFalse,
- "rawArraySize" : lambda x, m: self.assertEqual(x, Size(bytes=0), m),
+ "rawArraySize" : lambda x, m: self.assertEqual(x, Size(0), m),
"resizable" : self.assertFalse,
- "size" : lambda x, m: self.assertEqual(x, Size(bytes=0), m),
+ "size" : lambda x, m: self.assertEqual(x, Size(0), m),
"smallestMember" : self.assertIsNone,
"spares" : lambda x, m: self.assertEqual(x, 0, m),
"status" : self.assertFalse,
- "superBlockSize" : lambda x, m: self.assertEqual(x, Size(spec="1 MiB"), m),
+ "superBlockSize" : lambda x, m: self.assertEqual(x, Size("1 MiB"), m),
"sysfsPath" : lambda x, m: self.assertEqual(x, "", m),
- "targetSize" : lambda x, m: self.assertEqual(x, Size(bytes=0), m),
+ "targetSize" : lambda x, m: self.assertEqual(x, Size(0), m),
"uuid" : self.assertIsNone,
"memberDevices" : lambda x, m: self.assertEqual(x, 0, m),
"totalDevices" : lambda x, m: self.assertEqual(x, 0, m),
@@ -118,7 +118,7 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
self.dev10 = MDRaidArrayDevice(
"dev10",
level="raid0",
- size=Size(spec="32 MiB"))
+ size=Size("32 MiB"))
self.dev11 = MDRaidArrayDevice(
"dev11",
@@ -129,7 +129,7 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
fmt=getFormat("mdmember")),
MDRaidArrayDevice("other", level="raid0",
fmt=getFormat("mdmember"))],
- size=Size(spec="32 MiB"),
+ size=Size("32 MiB"),
totalDevices=2)
self.dev12 = MDRaidArrayDevice(
@@ -138,11 +138,11 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
memberDevices=2,
parents=[
Mock(**{"type": "mdcontainer",
- "size": Size(spec="4 MiB"),
+ "size": Size("4 MiB"),
"format": getFormat("mdmember")}),
- Mock(**{"size": Size(spec="2 MiB"),
+ Mock(**{"size": Size("2 MiB"),
"format": getFormat("mdmember")})],
- size=Size(spec="32 MiB"),
+ size=Size("32 MiB"),
totalDevices=2)
self.dev13 = MDRaidArrayDevice(
@@ -150,11 +150,11 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
level=0,
memberDevices=3,
parents=[
- Mock(**{"size": Size(spec="4 MiB"),
+ Mock(**{"size": Size("4 MiB"),
"format": getFormat("mdmember")}),
- Mock(**{"size": Size(spec="2 MiB"),
+ Mock(**{"size": Size("2 MiB"),
"format": getFormat("mdmember")})],
- size=Size(spec="32 MiB"),
+ size=Size("32 MiB"),
totalDevices=3)
self.dev14 = MDRaidArrayDevice(
@@ -162,11 +162,11 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
level=4,
memberDevices=3,
parents=[
- Mock(**{"size": Size(spec="4 MiB"),
+ Mock(**{"size": Size("4 MiB"),
"format": getFormat("mdmember")}),
- Mock(**{"size": Size(spec="2 MiB"),
+ Mock(**{"size": Size("2 MiB"),
"format": getFormat("mdmember")}),
- Mock(**{"size": Size(spec="2 MiB"),
+ Mock(**{"size": Size("2 MiB"),
"format": getFormat("mdmember")})],
totalDevices=3)
@@ -175,11 +175,11 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
level=5,
memberDevices=3,
parents=[
- Mock(**{"size": Size(spec="4 MiB"),
+ Mock(**{"size": Size("4 MiB"),
"format": getFormat("mdmember")}),
- Mock(**{"size": Size(spec="2 MiB"),
+ Mock(**{"size": Size("2 MiB"),
"format": getFormat("mdmember")}),
- Mock(**{"size": Size(spec="2 MiB"),
+ Mock(**{"size": Size("2 MiB"),
"format": getFormat("mdmember")})],
totalDevices=3)
@@ -188,13 +188,13 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
level=6,
memberDevices=4,
parents=[
- Mock(**{"size": Size(spec="4 MiB"),
+ Mock(**{"size": Size("4 MiB"),
"format": getFormat("mdmember")}),
- Mock(**{"size": Size(spec="4 MiB"),
+ Mock(**{"size": Size("4 MiB"),
"format": getFormat("mdmember")}),
- Mock(**{"size": Size(spec="2 MiB"),
+ Mock(**{"size": Size("2 MiB"),
"format": getFormat("mdmember")}),
- Mock(**{"size": Size(spec="2 MiB"),
+ Mock(**{"size": Size("2 MiB"),
"format": getFormat("mdmember")})],
totalDevices=4)
@@ -203,13 +203,13 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
level=10,
memberDevices=4,
parents=[
- Mock(**{"size": Size(spec="4 MiB"),
+ Mock(**{"size": Size("4 MiB"),
"format": getFormat("mdmember")}),
- Mock(**{"size": Size(spec="4 MiB"),
+ Mock(**{"size": Size("4 MiB"),
"format": getFormat("mdmember")}),
- Mock(**{"size": Size(spec="2 MiB"),
+ Mock(**{"size": Size("2 MiB"),
"format": getFormat("mdmember")}),
- Mock(**{"size": Size(spec="2 MiB"),
+ Mock(**{"size": Size("2 MiB"),
"format": getFormat("mdmember")})],
totalDevices=4)
@@ -218,13 +218,13 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
level=10,
memberDevices=4,
parents=[
- Mock(**{"size": Size(spec="4 MiB"),
+ Mock(**{"size": Size("4 MiB"),
"format": getFormat("mdmember")}),
- Mock(**{"size": Size(spec="4 MiB"),
+ Mock(**{"size": Size("4 MiB"),
"format": getFormat("mdmember")}),
- Mock(**{"size": Size(spec="2 MiB"),
+ Mock(**{"size": Size("2 MiB"),
"format": getFormat("mdmember")}),
- Mock(**{"size": Size(spec="2 MiB"),
+ Mock(**{"size": Size("2 MiB"),
"format": getFormat("mdmember")})],
totalDevices=5)
@@ -286,7 +286,7 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
self.stateCheck(self.dev10,
createBitmap=self.assertFalse,
level=lambda x, m: self.assertEqual(x.number, 0, m),
- targetSize=lambda x, m: self.assertEqual(x, Size(spec="32 MiB"), m))
+ targetSize=lambda x, m: self.assertEqual(x, Size("32 MiB"), m))
self.stateCheck(self.dev11,
devices=lambda x, m: self.assertEqual(len(x), 2, m),
@@ -297,7 +297,7 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
parents=lambda x, m: self.assertNotEqual(x, [], m),
partitionable=self.assertTrue,
smallestMember=self.assertIsNotNone,
- targetSize=lambda x, m: self.assertEqual(x, Size(spec="32 MiB"), m),
+ targetSize=lambda x, m: self.assertEqual(x, Size("32 MiB"), m),
totalDevices=lambda x, m: self.assertEqual(x, 2, m),
type=lambda x, m: self.assertEqual(x, "mdbiosraidarray", m))
@@ -312,9 +312,9 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
memberDevices=lambda x, m: self.assertEqual(x, 2, m),
parents=lambda x, m: self.assertNotEqual(x, [], m),
partitionable=self.assertTrue,
- rawArraySize=lambda x, m: self.assertEqual(x, Size(spec="2 MiB"), m),
+ rawArraySize=lambda x, m: self.assertEqual(x, Size("2 MiB"), m),
smallestMember=self.assertIsNotNone,
- targetSize=lambda x, m: self.assertEqual(x, Size(spec="32 MiB"), m),
+ targetSize=lambda x, m: self.assertEqual(x, Size("32 MiB"), m),
totalDevices=lambda x, m: self.assertEqual(x, 2, m),
type = lambda x, m: self.assertEqual(x, "mdbiosraidarray", m))
@@ -324,10 +324,10 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
level=lambda x, m: self.assertEqual(x.number, 0, m),
memberDevices=lambda x, m: self.assertEqual(x, 3, m),
parents=lambda x, m: self.assertNotEqual(x, [], m),
- rawArraySize=lambda x, m: self.assertEqual(x, Size(spec="6 MiB"), m),
- size=lambda x, m: self.assertEqual(x, Size(spec="3 MiB"), m),
+ rawArraySize=lambda x, m: self.assertEqual(x, Size("6 MiB"), m),
+ size=lambda x, m: self.assertEqual(x, Size("3 MiB"), m),
smallestMember=self.assertIsNotNone,
- targetSize=lambda x, m: self.assertEqual(x, Size(spec="32 MiB"), m),
+ targetSize=lambda x, m: self.assertEqual(x, Size("32 MiB"), m),
totalDevices=lambda x, m: self.assertEqual(x, 3, m))
self.stateCheck(self.dev14,
@@ -335,8 +335,8 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
level=lambda x, m: self.assertEqual(x.number, 4, m),
memberDevices=lambda x, m: self.assertEqual(x, 3, m),
parents=lambda x, m: self.assertNotEqual(x, [], m),
- rawArraySize=lambda x, m: self.assertEqual(x, Size(spec="4 MiB"), m),
- size=lambda x, m: self.assertEqual(x, Size(spec="2 MiB"), m),
+ rawArraySize=lambda x, m: self.assertEqual(x, Size("4 MiB"), m),
+ size=lambda x, m: self.assertEqual(x, Size("2 MiB"), m),
smallestMember=self.assertIsNotNone,
totalDevices=lambda x, m: self.assertEqual(x, 3, m))
@@ -345,8 +345,8 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
level=lambda x, m: self.assertEqual(x.number, 5, m),
memberDevices=lambda x, m: self.assertEqual(x, 3, m),
parents=lambda x, m: self.assertNotEqual(x, [], m),
- rawArraySize=lambda x, m: self.assertEqual(x, Size(spec="4 MiB"), m),
- size=lambda x, m: self.assertEqual(x, Size(spec="2 MiB"), m),
+ rawArraySize=lambda x, m: self.assertEqual(x, Size("4 MiB"), m),
+ size=lambda x, m: self.assertEqual(x, Size("2 MiB"), m),
smallestMember=self.assertIsNotNone,
totalDevices=lambda x, m: self.assertEqual(x, 3, m))
@@ -355,8 +355,8 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
level=lambda x, m: self.assertEqual(x.number, 6, m),
memberDevices=lambda x, m: self.assertEqual(x, 4, m),
parents=lambda x, m: self.assertNotEqual(x, [], m),
- rawArraySize=lambda x, m: self.assertEqual(x, Size(spec="4 MiB"), m),
- size=lambda x, m: self.assertEqual(x, Size(spec="2 MiB"), m),
+ rawArraySize=lambda x, m: self.assertEqual(x, Size("4 MiB"), m),
+ size=lambda x, m: self.assertEqual(x, Size("2 MiB"), m),
smallestMember=self.assertIsNotNone,
totalDevices=lambda x, m: self.assertEqual(x, 4, m))
@@ -365,8 +365,8 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
level=lambda x, m: self.assertEqual(x.number, 10, m),
memberDevices=lambda x, m: self.assertEqual(x, 4, m),
parents=lambda x, m: self.assertNotEqual(x, [], m),
- rawArraySize=lambda x, m: self.assertEqual(x, Size(spec="4 MiB"), m),
- size=lambda x, m: self.assertEqual(x, Size(spec="2 MiB"), m),
+ rawArraySize=lambda x, m: self.assertEqual(x, Size("4 MiB"), m),
+ size=lambda x, m: self.assertEqual(x, Size("2 MiB"), m),
smallestMember=self.assertIsNotNone,
totalDevices=lambda x, m: self.assertEqual(x, 4, m))
@@ -375,8 +375,8 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
level=lambda x, m: self.assertEqual(x.number, 10, m),
memberDevices=lambda x, m: self.assertEqual(x, 4, m),
parents=lambda x, m: self.assertNotEqual(x, [], m),
- rawArraySize=lambda x, m: self.assertEqual(x, Size(spec="4 MiB"), m),
- size=lambda x, m: self.assertEqual(x, Size(spec="2 MiB"), m),
+ rawArraySize=lambda x, m: self.assertEqual(x, Size("4 MiB"), m),
+ size=lambda x, m: self.assertEqual(x, Size("2 MiB"), m),
smallestMember=self.assertIsNotNone,
spares=lambda x, m: self.assertEqual(x, 1, m),
totalDevices=lambda x, m: self.assertEqual(x, 5, m))
@@ -438,14 +438,14 @@ class BTRFSDeviceTestCase(DeviceStateTestCase):
def setUp(self):
self._state_functions = {
- "currentSize" : lambda x, m: self.assertEqual(x, Size(bytes=0), m),
+ "currentSize" : lambda x, m: self.assertEqual(x, Size(0), m),
"exists" : self.assertFalse,
"format" : self.assertIsNotNone,
"formatArgs" : lambda x, m: self.assertEqual(x, [], m),
"fstabSpec" : self.assertIsNotNone,
"isDisk" : self.assertFalse,
"major" : lambda x, m: self.assertEqual(x, 0, m),
- "maxSize" : lambda x, m: self.assertEqual(x, Size(bytes=0), m),
+ "maxSize" : lambda x, m: self.assertEqual(x, Size(0), m),
"mediaPresent" : self.assertTrue,
"minor" : lambda x, m: self.assertEqual(x, 0, m),
"parents" : lambda x, m: self.assertEqual(len(x), 0, m) and
@@ -453,10 +453,10 @@ class BTRFSDeviceTestCase(DeviceStateTestCase):
"partitionable" : self.assertFalse,
"path" : lambda x, m: self.assertRegexpMatches(x, "^/dev", m),
"resizable" : lambda x, m: self.assertFalse,
- "size" : lambda x, m: self.assertEqual(x, Size(bytes=0), m),
+ "size" : lambda x, m: self.assertEqual(x, Size(0), m),
"status" : self.assertFalse,
"sysfsPath" : lambda x, m: self.assertEqual(x, "", m),
- "targetSize" : lambda x, m: self.assertEqual(x, Size(bytes=0), m),
+ "targetSize" : lambda x, m: self.assertEqual(x, Size(0), m),
"type" : lambda x, m: self.assertEqual(x, "btrfs", m),
"uuid" : self.assertIsNone,
"vol_id" : lambda x, m: self.assertEqual(x, btrfs.MAIN_VOLUME_ID, m)}
@@ -469,7 +469,7 @@ class BTRFSDeviceTestCase(DeviceStateTestCase):
dev = StorageDevice("deva",
fmt=blivet.formats.getFormat("btrfs"),
- size=Size(spec="32 MiB"))
+ size=Size("32 MiB"))
self.dev3 = BTRFSVolumeDevice("dev3",
parents=[dev])
@@ -484,10 +484,10 @@ class BTRFSDeviceTestCase(DeviceStateTestCase):
type=lambda x, m: self.assertEqual(x, "btrfs volume", m))
self.stateCheck(self.dev3,
- currentSize=lambda x, m: self.assertEqual(x, Size(spec="32 MiB"), m),
- maxSize=lambda x, m: self.assertEqual(x, Size(spec="32 MiB"), m),
+ currentSize=lambda x, m: self.assertEqual(x, Size("32 MiB"), m),
+ maxSize=lambda x, m: self.assertEqual(x, Size("32 MiB"), m),
parents=lambda x, m: self.assertEqual(len(x), 1, m),
- size=lambda x, m: self.assertEqual(x, Size(spec="32 MiB"), m),
+ size=lambda x, m: self.assertEqual(x, Size("32 MiB"), m),
type=lambda x, m: self.assertEqual(x, "btrfs volume", m))
self.assertRaisesRegexp(ValueError,
diff --git a/tests/size_test.py b/tests/size_test.py
index 7029fdc..e05e3b5 100644
--- a/tests/size_test.py
+++ b/tests/size_test.py
@@ -23,18 +23,15 @@
import unittest
-from blivet.errors import SizeParamsError, SizePlacesError
+from blivet.errors import SizePlacesError
from blivet.size import Size, _prefixes
class SizeTestCase(unittest.TestCase):
def testExceptions(self):
- self.assertRaises(SizeParamsError, Size)
- self.assertRaises(SizeParamsError, Size, bytes=500, spec="45GB")
-
- zero = Size(bytes=0)
+ zero = Size(0)
self.assertEqual(zero, 0.0)
- s = Size(bytes=500)
+ s = Size(500)
self.assertRaises(SizePlacesError, s.humanReadable, places=-1)
self.assertEqual(s.humanReadable(places=0), "500 B")
@@ -42,23 +39,23 @@ class SizeTestCase(unittest.TestCase):
def _prefixTestHelper(self, numbytes, factor, prefix, abbr):
c = numbytes * factor
- s = Size(bytes=c)
+ s = Size(c)
self.assertEquals(s, c)
if prefix:
u = "%sbytes" % prefix
- s = Size(spec="%ld %s" % (numbytes, u))
+ s = Size("%ld %s" % (numbytes, u))
self.assertEquals(s, c)
self.assertEquals(s.convertTo(spec=u), numbytes)
if abbr:
u = "%sb" % abbr
- s = Size(spec="%ld %s" % (numbytes, u))
+ s = Size("%ld %s" % (numbytes, u))
self.assertEquals(s, c)
self.assertEquals(s.convertTo(spec=u), numbytes)
if not prefix and not abbr:
- s = Size(spec="%ld" % numbytes)
+ s = Size("%ld" % numbytes)
self.assertEquals(s, c)
self.assertEquals(s.convertTo(), numbytes)
@@ -70,46 +67,46 @@ class SizeTestCase(unittest.TestCase):
self._prefixTestHelper(numbytes, factor, prefix, abbr)
def testHumanReadable(self):
- s = Size(bytes=58929971L)
+ s = Size(58929971L)
self.assertEquals(s.humanReadable(), "56.2 MiB")
- s = Size(bytes=478360371L)
+ s = Size(478360371L)
self.assertEquals(s.humanReadable(), "456.2 MiB")
# humanReable output should be the same as input for big enough sizes
# and enough places and integer values
- s = Size(spec="12.68 TiB")
+ s = Size("12.68 TiB")
self.assertEquals(s.humanReadable(max_places=2), "12.68 TiB")
- s = Size(spec="26.55 MiB")
+ s = Size("26.55 MiB")
self.assertEquals(s.humanReadable(max_places=2), "26.55 MiB")
- s = Size(spec="300 MiB")
+ s = Size("300 MiB")
self.assertEquals(s.humanReadable(max_places=2), "300 MiB")
# smaller unit should be used for small sizes
- s = Size(spec="9.68 TiB")
+ s = Size("9.68 TiB")
self.assertEquals(s.humanReadable(max_places=2), "9912.32 GiB")
- s = Size(spec="4.29 MiB")
+ s = Size("4.29 MiB")
self.assertEquals(s.humanReadable(max_places=2), "4392.96 KiB")
- s = Size(spec="7.18 KiB")
+ s = Size("7.18 KiB")
self.assertEquals(s.humanReadable(max_places=2), "7352 B")
# rounding should work with max_places limitted
- s = Size(spec="12.687 TiB")
+ s = Size("12.687 TiB")
self.assertEquals(s.humanReadable(max_places=2), "12.69 TiB")
- s = Size(spec="23.7874 TiB")
+ s = Size("23.7874 TiB")
self.assertEquals(s.humanReadable(max_places=3), "23.787 TiB")
- s = Size(spec="12.6998 TiB")
+ s = Size("12.6998 TiB")
self.assertEquals(s.humanReadable(max_places=2), "12.7 TiB")
def testNegative(self):
- s = Size(spec="-500MiB")
+ s = Size("-500MiB")
self.assertEquals(s.humanReadable(), "-500 MiB")
self.assertEquals(s.convertTo(spec="b"), -524288000)
def testPartialBytes(self):
- self.assertEquals(Size(bytes=1024.6), Size(bytes=1024))
- self.assertEquals(Size(spec="%s KiB" % (1/1025.0,)), Size(bytes=0))
- self.assertEquals(Size(spec="%s KiB" % (1/1023.0,)), Size(bytes=1))
+ self.assertEquals(Size(1024.6), Size(1024))
+ self.assertEquals(Size("%s KiB" % (1/1025.0,)), Size(0))
+ self.assertEquals(Size("%s KiB" % (1/1023.0,)), Size(1))
def testTranslated(self):
import locale
@@ -125,31 +122,31 @@ class SizeTestCase(unittest.TestCase):
# you know, just in case
test_langs = ["es_ES.UTF-8", "kk_KZ.UTF-8", "ml_IN.UTF-8", "fa_IR.UTF-8"]
- s = Size(spec="56.19 MiB")
+ s = Size("56.19 MiB")
for lang in test_langs:
os.environ['LANG'] = lang
locale.setlocale(locale.LC_ALL, '')
# Check English parsing
- self.assertEquals(s, Size(spec="56.19 MiB"))
+ self.assertEquals(s, Size("56.19 MiB"))
# Check native parsing
- self.assertEquals(s, Size(spec="56.19 %s%s" % (_("Mi"), _("B"))))
+ self.assertEquals(s, Size("56.19 %s%s" % (_("Mi"), _("B"))))
# Check native parsing, all lowercase
- self.assertEquals(s, Size(spec=("56.19 %s%s" % (_("Mi"), _("B"))).lower()))
+ self.assertEquals(s, Size(("56.19 %s%s" % (_("Mi"), _("B"))).lower()))
# Check native parsing, all uppercase
- self.assertEquals(s, Size(spec=("56.19 %s%s" % (_("Mi"), _("B"))).upper()))
+ self.assertEquals(s, Size(("56.19 %s%s" % (_("Mi"), _("B"))).upper()))
# If the radix separator is not a period, repeat the tests with the
# native separator
radix = locale.nl_langinfo(locale.RADIXCHAR)
if radix != '.':
- self.assertEquals(s, Size(spec="56%s19 MiB" % radix))
- self.assertEquals(s, Size(spec="56%s19 %s%s" % (radix, _("Mi"), _("B"))))
- self.assertEquals(s, Size(spec=("56%s19 %s%s" % (radix, _("Mi"), _("B"))).lower()))
- self.assertEquals(s, Size(spec=("56%s19 %s%s" % (radix, _("Mi"), _("B"))).upper()))
+ self.assertEquals(s, Size("56%s19 MiB" % radix))
+ self.assertEquals(s, Size("56%s19 %s%s" % (radix, _("Mi"), _("B"))))
+ self.assertEquals(s, Size(("56%s19 %s%s" % (radix, _("Mi"), _("B"))).lower()))
+ self.assertEquals(s, Size(("56%s19 %s%s" % (radix, _("Mi"), _("B"))).upper()))
os.environ['LANG'] = saved_lang
locale.setlocale(locale.LC_ALL, '')
--
1.8.3.1
More information about the anaconda-patches
mailing list