Make divisible py3 compatible in remotefs driver
the code: import platform print('Python', platform.python_version()) print('3 / 2 =', 3 / 2) print('3 // 2 =', 3 // 2) print('3 / 2.0 =', 3 / 2.0) print('3 // 2.0 =', 3 // 2.0) in py2 ('Python', '2.7.10') ('3 / 2 =', 1) ('3 // 2 =', 1) ('3 / 2.0 =', 1.5) ('3 // 2.0 =', 1.0) in py3 Python 3.4.3+ 3 / 2 = 1.5 3 // 2 = 1 3 / 2.0 = 1.5 3 // 2.0 = 1.0 So it need to modify the code to adapt to this difference. Change-Id: I6811f849ffcd2aaa4a6fefc8ce864097b447cf5f Closes-Bug: #1596139
This commit is contained in:
parent
c240eafa0a
commit
ad36b6948c
@ -466,3 +466,10 @@ class RemoteFsSnapDriverTestCase(test.TestCase):
|
||||
mock_copy_volume_from_snapshot.assert_called_once_with(
|
||||
snap_ref, volume_ref, volume['size'])
|
||||
self.assertTrue(mock_delete_snapshot.called)
|
||||
|
||||
def test_create_regular_file(self):
|
||||
self._driver._create_regular_file('/path', 1)
|
||||
self._driver._execute.assert_called_once_with('dd', 'if=/dev/zero',
|
||||
'of=/path', 'bs=1M',
|
||||
'count=1024',
|
||||
run_as_root=True)
|
||||
|
@ -336,7 +336,7 @@ class RemoteFSDriver(driver.LocalVD, driver.TransferVD, driver.BaseVD):
|
||||
"""Creates a regular file of given size in GiB."""
|
||||
|
||||
block_size_mb = 1
|
||||
block_count = size * units.Gi / (block_size_mb * units.Mi)
|
||||
block_count = size * units.Gi // (block_size_mb * units.Mi)
|
||||
|
||||
self._execute('dd', 'if=/dev/zero', 'of=%s' % path,
|
||||
'bs=%dM' % block_size_mb,
|
||||
@ -421,7 +421,7 @@ class RemoteFSDriver(driver.LocalVD, driver.TransferVD, driver.BaseVD):
|
||||
|
||||
data = image_utils.qemu_img_info(self.local_path(volume),
|
||||
run_as_root=run_as_root)
|
||||
virt_size = data.virtual_size / units.Gi
|
||||
virt_size = data.virtual_size // units.Gi
|
||||
if virt_size != volume.size:
|
||||
raise exception.ImageUnacceptable(
|
||||
image_id=image_id,
|
||||
|
Loading…
x
Reference in New Issue
Block a user