From ad36b6948ca2e7bc3d333d6aa29fd47f4a7d573f Mon Sep 17 00:00:00 2001 From: Ji-Wei Date: Mon, 19 Sep 2016 16:28:51 +0800 Subject: [PATCH] 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 --- cinder/tests/unit/volume/drivers/test_remotefs.py | 7 +++++++ cinder/volume/drivers/remotefs.py | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cinder/tests/unit/volume/drivers/test_remotefs.py b/cinder/tests/unit/volume/drivers/test_remotefs.py index 03c403640d0..739cd8015ab 100644 --- a/cinder/tests/unit/volume/drivers/test_remotefs.py +++ b/cinder/tests/unit/volume/drivers/test_remotefs.py @@ -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) diff --git a/cinder/volume/drivers/remotefs.py b/cinder/volume/drivers/remotefs.py index 0160b0a4d84..6fb527ce50d 100644 --- a/cinder/volume/drivers/remotefs.py +++ b/cinder/volume/drivers/remotefs.py @@ -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,