]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
clean up numeric expressions in test
authorChang Bo Guo <guochbo@cn.ibm.com>
Tue, 29 Oct 2013 09:03:50 +0000 (02:03 -0700)
committerChang Bo Guo <guochbo@cn.ibm.com>
Wed, 30 Oct 2013 11:40:08 +0000 (04:40 -0700)
Replace numeric expressions with constants in tests
to make code more readable.

Change-Id: I42469cdbe3cafd36f8d9855c8284f885ffa7f465

13 files changed:
cinder/backup/drivers/swift.py
cinder/tests/test_gpfs.py
cinder/tests/test_image_utils.py
cinder/tests/test_nfs.py
cinder/tests/test_rbd.py
cinder/tests/test_scality.py
cinder/tests/test_sheepdog.py
cinder/tests/test_solidfire.py
cinder/tests/test_storwize_svc.py
cinder/tests/test_vmware_vmdk.py
cinder/volume/drivers/rbd.py
cinder/volume/drivers/sheepdog.py
cinder/volume/drivers/storwize_svc.py

index b243d32b750b5f0186befb3a0ee5deed31d32da7..655bc65260a5b40942ee623bd83c62993ada4222 100644 (file)
@@ -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'
index 316e182834fbe25b18dc2340557b998eee98c0f4..f6909a17ef29beaa7a9930002a38d67ebee5f28c 100644 (file)
@@ -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):
index 967aa38182049e09dcfc8e7389edc3f9a572ac48..174c263ab3d2f5e25cde77670ecb0162a7b01bf8 100644 (file)
@@ -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'}
 
index c221019021f1a26a9aae00117fbaacfb77dce745..993f35d17b0c188e1d0e09ccba7db8f107702206 100644 (file)
@@ -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()
index 72e176ec8cbc5f6776a8c7668ae85601cac165a7..33fc0630e9afe40b155e1769bb33ec2d00bca34a 100644 (file)
@@ -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)
index 97966c5ba00c7f5b86b56ecb246ffa92cde221e3..5c4c62d37d98a66da2723afa7c4e1d840d820538 100644 (file)
@@ -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."""
index 51428399d7ea7d3ac5c0305279a2db6f23ab91de..793579884adfb1ccd52c97b7576e0657ed3642d9 100644 (file)
@@ -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)
index 255a674bc40bfce30b9882e7fffed3bc0ad4a3ac..73e11793f61ce7aa410c30d22bf4dbbcee10af0f 100644 (file)
@@ -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",
index 8cc69155345105809cb65cb8eb37d0e975c0a2f3..24a219d211564552e2bd4b5bceafc52cf4286109 100644 (file)
@@ -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)
index ca4e5fd0fc214bf304cec7d374ec8bfe355f82c6..5846de2091888dbf56b502074790682ecf889c78 100644 (file)
@@ -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()
index ddcf16dcde07adee8d67c1571f6b842ed6899a84..0ab857c3ac07d90f78e5413d802066cf0dd9b42a 100644 (file)
@@ -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'))
index 57a8bfde355a5b3ba5f0fb04913c10ea9cb15494..1168a6086cacdb905cd5de5309732e6ebcf95697 100644 (file)
@@ -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'))
 
index 3026504d4f7d2b0a98f9134f3895b79c78f902c9..d03da19c576f18947209f4166460abac2bfb80f0 100644 (file)
@@ -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