clean up numeric expressions in test
Replace numeric expressions with constants in tests to make code more readable. Change-Id: I42469cdbe3cafd36f8d9855c8284f885ffa7f465
This commit is contained in:
parent
75bcf70ed4
commit
f709c9d3db
@ -44,6 +44,7 @@ from cinder.backup.driver import BackupDriver
|
||||
from cinder import exception
|
||||
from cinder.openstack.common import log as logging
|
||||
from cinder.openstack.common import timeutils
|
||||
from cinder import units
|
||||
from swiftclient import client as swift
|
||||
|
||||
|
||||
@ -242,7 +243,7 @@ class SwiftBackupDriver(BackupDriver):
|
||||
backup['service_metadata'] = object_prefix
|
||||
self.db.backup_update(self.context, backup_id, {'service_metadata':
|
||||
object_prefix})
|
||||
volume_size_bytes = volume['size'] * 1024 * 1024 * 1024
|
||||
volume_size_bytes = volume['size'] * units.GiB
|
||||
availability_zone = self.az
|
||||
LOG.debug(_('starting backup of volume: %(volume_id)s to swift,'
|
||||
' volume size: %(volume_size_bytes)d, swift object names'
|
||||
|
@ -28,6 +28,7 @@ from cinder.openstack.common import log as logging
|
||||
from cinder.openstack.common import processutils
|
||||
from cinder import test
|
||||
from cinder.tests import utils as test_utils
|
||||
from cinder import units
|
||||
from cinder import utils
|
||||
from cinder.volume import configuration as conf
|
||||
from cinder.volume.drivers.gpfs import GPFSDriver
|
||||
@ -434,7 +435,7 @@ class GPFSDriverTestCase(test.TestCase):
|
||||
return False
|
||||
|
||||
def _fake_get_available_capacity(self, path):
|
||||
fake_avail = 80 * 1024 * 1024 * 1024
|
||||
fake_avail = 80 * units.GiB
|
||||
fake_size = 2 * fake_avail
|
||||
return fake_avail, fake_size
|
||||
|
||||
@ -485,14 +486,14 @@ class GPFSDriverTestCase(test.TestCase):
|
||||
data = FakeQemuImgInfo()
|
||||
data.file_format = 'qcow2'
|
||||
data.backing_file = None
|
||||
data.virtual_size = 1024 * 1024 * 1024
|
||||
data.virtual_size = 1 * units.GiB
|
||||
return data
|
||||
|
||||
def _fake_qemu_raw_image_info(self, path):
|
||||
data = FakeQemuImgInfo()
|
||||
data.file_format = 'raw'
|
||||
data.backing_file = None
|
||||
data.virtual_size = 1024 * 1024 * 1024
|
||||
data.virtual_size = 1 * units.GiB
|
||||
return data
|
||||
|
||||
def _fake_qemu_image_resize(self, path, size):
|
||||
|
@ -25,6 +25,7 @@ from cinder import context
|
||||
from cinder import exception
|
||||
from cinder.image import image_utils
|
||||
from cinder import test
|
||||
from cinder import units
|
||||
from cinder import utils
|
||||
|
||||
|
||||
@ -37,7 +38,7 @@ class FakeImageService:
|
||||
data.write(self._imagedata.get(image_id, ''))
|
||||
|
||||
def show(self, context, image_id):
|
||||
return {'size': 2 * 1024 * 1024 * 1024,
|
||||
return {'size': 2 * units.GiB,
|
||||
'disk_format': 'qcow2',
|
||||
'container_format': 'bare'}
|
||||
|
||||
|
@ -182,7 +182,7 @@ class NfsDriverTestCase(test.TestCase):
|
||||
|
||||
mox.StubOutWithMock(image_utils, 'qemu_img_info')
|
||||
data = mox_lib.MockAnything()
|
||||
data.virtual_size = 1024 ** 3
|
||||
data.virtual_size = 1 * units.GiB
|
||||
image_utils.qemu_img_info(TEST_IMG_SOURCE).AndReturn(data)
|
||||
|
||||
mox.ReplayAll()
|
||||
|
@ -116,7 +116,7 @@ class RBDTestCase(test.TestCase):
|
||||
self.rbd.RBD_FEATURE_LAYERING = 1
|
||||
_mock_rbd = self.mox.CreateMockAnything()
|
||||
self.rbd.RBD().AndReturn(_mock_rbd)
|
||||
_mock_rbd.create(mox.IgnoreArg(), str(name), size * 1024 ** 3,
|
||||
_mock_rbd.create(mox.IgnoreArg(), str(name), size * units.GiB,
|
||||
old_format=False,
|
||||
features=self.rbd.RBD_FEATURE_LAYERING)
|
||||
mock_client.__exit__(None, None, None).AndReturn(None)
|
||||
|
@ -27,6 +27,7 @@ from cinder import context
|
||||
from cinder import exception
|
||||
from cinder.image import image_utils
|
||||
from cinder import test
|
||||
from cinder import units
|
||||
from cinder import utils
|
||||
from cinder.volume.drivers import scality
|
||||
|
||||
@ -181,7 +182,7 @@ class ScalityDriverTestCase(test.TestCase):
|
||||
self.TEST_VOLNAME))
|
||||
self.assertTrue(os.path.isfile(self.TEST_VOLPATH))
|
||||
self.assertEqual(os.stat(self.TEST_VOLPATH).st_size,
|
||||
100 * 1024 * 1024)
|
||||
100 * units.MiB)
|
||||
|
||||
def test_delete_volume(self):
|
||||
"""Expected behaviour for delete_volume."""
|
||||
|
@ -71,8 +71,8 @@ class SheepdogTestCase(test.TestCase):
|
||||
vendor_name='Open Source',
|
||||
dirver_version=self.driver.VERSION,
|
||||
storage_protocol='sheepdog',
|
||||
total_capacity_gb=float(107287605248) / (1024 ** 3),
|
||||
free_capacity_gb=float(107287605248 - 3623897354) / (1024 ** 3),
|
||||
total_capacity_gb=float(107287605248) / units.GiB,
|
||||
free_capacity_gb=float(107287605248 - 3623897354) / units.GiB,
|
||||
reserved_percentage=0,
|
||||
QoS_support=False)
|
||||
actual = self.driver.get_volume_stats(True)
|
||||
|
@ -21,6 +21,7 @@ from cinder import exception
|
||||
from cinder.openstack.common import log as logging
|
||||
from cinder.openstack.common import timeutils
|
||||
from cinder import test
|
||||
from cinder import units
|
||||
from cinder.volume import configuration as conf
|
||||
from cinder.volume.drivers.solidfire import SolidFireDriver
|
||||
|
||||
@ -112,7 +113,7 @@ class SolidFireVolumeTestCase(test.TestCase):
|
||||
'name': test_name,
|
||||
'accountID': 25,
|
||||
'sliceCount': 1,
|
||||
'totalSize': 1048576 * 1024,
|
||||
'totalSize': 1 * units.GiB,
|
||||
'enable512e': True,
|
||||
'access': "readWrite",
|
||||
'status': "active",
|
||||
|
@ -1739,7 +1739,7 @@ class StorwizeSVCDriverTestCase(test.TestCase):
|
||||
|
||||
# Make sure volume attributes are as they should be
|
||||
attributes = self.driver._get_vdisk_attributes(volume['name'])
|
||||
attr_size = float(attributes['capacity']) / (1024 ** 3) # bytes to GB
|
||||
attr_size = float(attributes['capacity']) / units.GiB # bytes to GB
|
||||
self.assertEqual(attr_size, float(volume['size']))
|
||||
pool = self.driver.configuration.local_conf.storwize_svc_volpool_name
|
||||
self.assertEqual(attributes['mdisk_grp_name'], pool)
|
||||
|
@ -1320,7 +1320,7 @@ class VMwareEsxVmdkDriverTestCase(test.TestCase):
|
||||
image_id = 'image-id'
|
||||
image_meta = FakeObject()
|
||||
image_meta['disk_format'] = 'vmdk'
|
||||
image_meta['size'] = 1024 * 1024
|
||||
image_meta['size'] = 1 * units.MiB
|
||||
image_service = m.CreateMock(glance.GlanceImageService)
|
||||
image_service.show(mox.IgnoreArg(), image_id).AndReturn(image_meta)
|
||||
volume = FakeObject()
|
||||
|
@ -339,8 +339,8 @@ class RBDDriver(driver.VolumeDriver):
|
||||
try:
|
||||
with RADOSClient(self) as client:
|
||||
new_stats = client.cluster.get_cluster_stats()
|
||||
stats['total_capacity_gb'] = new_stats['kb'] / 1024 ** 2
|
||||
stats['free_capacity_gb'] = new_stats['kb_avail'] / 1024 ** 2
|
||||
stats['total_capacity_gb'] = new_stats['kb'] / units.MiB
|
||||
stats['free_capacity_gb'] = new_stats['kb_avail'] / units.MiB
|
||||
except self.rados.Error:
|
||||
# just log and return unknown capacities
|
||||
LOG.exception(_('error refreshing volume stats'))
|
||||
|
@ -172,8 +172,8 @@ class SheepdogDriver(driver.VolumeDriver):
|
||||
m = self.stats_pattern.match(stdout)
|
||||
total = float(m.group(1))
|
||||
used = float(m.group(2))
|
||||
stats['total_capacity_gb'] = total / (1024 ** 3)
|
||||
stats['free_capacity_gb'] = (total - used) / (1024 ** 3)
|
||||
stats['total_capacity_gb'] = total / units.GiB
|
||||
stats['free_capacity_gb'] = (total - used) / units.GiB
|
||||
except processutils.ProcessExecutionError:
|
||||
LOG.exception(_('error refreshing volume stats'))
|
||||
|
||||
|
@ -54,6 +54,7 @@ from cinder.openstack.common import log as logging
|
||||
from cinder.openstack.common import loopingcall
|
||||
from cinder.openstack.common import processutils
|
||||
from cinder.openstack.common import strutils
|
||||
from cinder import units
|
||||
from cinder import utils
|
||||
from cinder.volume.drivers.san import san
|
||||
from cinder.volume import volume_types
|
||||
@ -1562,9 +1563,9 @@ class StorwizeSVCDriver(san.SanDriver):
|
||||
raise exception.VolumeBackendAPIException(data=exception_message)
|
||||
|
||||
data['total_capacity_gb'] = (float(attributes['capacity']) /
|
||||
(1024 ** 3))
|
||||
units.GiB)
|
||||
data['free_capacity_gb'] = (float(attributes['free_capacity']) /
|
||||
(1024 ** 3))
|
||||
units.GiB)
|
||||
data['easytier_support'] = attributes['easy_tier'] in ['on', 'auto']
|
||||
data['compression_support'] = self._compression_enabled
|
||||
data['extent_size'] = self._extent_size
|
||||
|
Loading…
Reference in New Issue
Block a user