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
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'
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
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
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):
from cinder import exception
from cinder.image import image_utils
from cinder import test
+from cinder import units
from cinder import utils
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'}
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()
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)
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
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."""
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)
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
'name': test_name,
'accountID': 25,
'sliceCount': 1,
- 'totalSize': 1048576 * 1024,
+ 'totalSize': 1 * units.GiB,
'enable512e': True,
'access': "readWrite",
'status': "active",
# 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)
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()
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'))
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'))
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
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