]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Port ceph driver to Python 3
authorVictor Stinner <vstinner@redhat.com>
Wed, 7 Oct 2015 16:07:38 +0000 (18:07 +0200)
committerVictor Stinner <vstinner@redhat.com>
Thu, 8 Oct 2015 20:45:53 +0000 (22:45 +0200)
* Replace xrange() with range(). cinder/volume/utils.py uses
  "from six.moves import range", so "range" is xrange on Python 2.
* Replace '' with b'' for image content to get a bytes string on
  Python 3.

Note: _transfer_data() of cinder.volume.utils is tested by
test_backup_ceph which is already run on Python 3, but the test only
failed with python3 run with -bb. This bug is now fixed.

Partial-Implements: blueprint cinder-python3
Change-Id: Ib69b9ee4669d3b627747c754b1bda1994f0ed2a5

cinder/backup/drivers/ceph.py
cinder/tests/unit/test_rbd.py
cinder/volume/drivers/rbd.py
cinder/volume/utils.py

index e197eb3fa727a56be84e73cd279aaefb8dc1a3b1..26d6f7c1a9be07914a3a2577c431cd6a9f025a51 100644 (file)
@@ -310,7 +310,7 @@ class CephBackupDriver(driver.BackupDriver):
             data = src.read(self.chunk_size)
             # If we have reach end of source, discard any extraneous bytes from
             # destination volume if trim is enabled and stop writing.
-            if data == '':
+            if data == b'':
                 if CONF.restore_discard_excess_bytes:
                     self._discard_bytes(dest, dest.tell(),
                                         length - dest.tell())
@@ -334,7 +334,7 @@ class CephBackupDriver(driver.BackupDriver):
         if rem:
             LOG.debug("Transferring remaining %s bytes", rem)
             data = src.read(rem)
-            if data == '':
+            if data == b'':
                 if CONF.restore_discard_excess_bytes:
                     self._discard_bytes(dest, dest.tell(), rem)
             else:
index a3d2b68e1d4eb51c7d041be0889ba34ec491372a..bb60f4aa81cda77c9803d5066ec8f04c846b1637 100644 (file)
@@ -966,7 +966,7 @@ class RBDImageIOWrapperTestCase(test.TestCase):
         self.meta.image.size = mock.Mock()
         self.mock_rbd_wrapper = driver.RBDImageIOWrapper(self.meta)
         self.data_length = 1024
-        self.full_data = 'abcd' * 256
+        self.full_data = b'abcd' * 256
 
     def test_init(self):
         self.assertEqual(self.mock_rbd_wrapper._rbd_meta, self.meta)
@@ -1001,7 +1001,7 @@ class RBDImageIOWrapperTestCase(test.TestCase):
         self.assertEqual(self.full_data, data)
 
         data = self.mock_rbd_wrapper.read()
-        self.assertEqual('', data)
+        self.assertEqual(b'', data)
 
         self.mock_rbd_wrapper.seek(0)
         data = self.mock_rbd_wrapper.read()
index e5eefe8fcfb3ca89e41d6176540a732fc43527d5..b3be6e1cba84c1ca0ef07b0df4a3c887e3419d15 100644 (file)
@@ -142,7 +142,7 @@ class RBDImageIOWrapper(io.RawIOBase):
         # length (they just return nothing) but rbd images do so we need to
         # return empty string if we have reached the end of the image.
         if (offset >= total):
-            return ''
+            return b''
 
         if length is None:
             length = total
index 621296b43a9367d1aefaca9c8037b5b2875545b8..9e1e2c72fbdf5e8b178b9032ba495e02547a810e 100644 (file)
@@ -377,13 +377,13 @@ def _transfer_data(src, dest, length, chunk_size):
     LOG.debug("%(chunks)s chunks of %(bytes)s bytes to be transferred.",
               {'chunks': chunks, 'bytes': chunk_size})
 
-    for chunk in xrange(0, chunks):
+    for chunk in range(0, chunks):
         before = time.time()
         data = tpool.execute(src.read, min(chunk_size, remaining_length))
 
         # If we have reached end of source, discard any extraneous bytes from
         # destination volume if trim is enabled and stop writing.
-        if data == '':
+        if data == b'':
             break
 
         tpool.execute(dest.write, data)