Change in vdsm[master]: directio: Port to Python 3

nsoffer at redhat.com nsoffer at redhat.com
Sun Mar 13 15:28:31 UTC 2016


Nir Soffer has uploaded a new change for review.

Change subject: directio: Port to Python 3
......................................................................

directio: Port to Python 3

DirectFile is for binary io so it should return bytes instead of
strings, like io.FileIO, io.BufferedIOBase.

Replace StringIO.StringIO with io.BytesIO, and update the tests to use
bytes and io.open in binary mode, returning bytes.

Change-Id: Iad6f317df3efc70adb95063227c5e07513d34135
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M lib/vdsm/storage/directio.py
M tests/Makefile.am
M tests/storage_directio_test.py
3 files changed, 9 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/99/54699/1

diff --git a/lib/vdsm/storage/directio.py b/lib/vdsm/storage/directio.py
index f72a9f5..c9fc3ca 100644
--- a/lib/vdsm/storage/directio.py
+++ b/lib/vdsm/storage/directio.py
@@ -20,10 +20,10 @@
 from __future__ import absolute_import
 
 import ctypes
+import io
 import logging
 import os
 
-from StringIO import StringIO
 from contextlib import closing
 from contextlib import contextmanager
 
@@ -142,7 +142,7 @@
 
     def readall(self):
         buffsize = 1024
-        res = StringIO()
+        res = io.BytesIO()
         with closing(res):
             while True:
                 buff = self.read(buffsize)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c3b0690..fbcbd4c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -39,6 +39,7 @@
 	pthreadTests.py \
 	responseTests.py \
 	scheduleTests.py \
+	storage_directio_test.py \
 	vmStatsTests.py \
 	$(NULL)
 
diff --git a/tests/storage_directio_test.py b/tests/storage_directio_test.py
index 1f0822a..2feccef 100644
--- a/tests/storage_directio_test.py
+++ b/tests/storage_directio_test.py
@@ -18,6 +18,8 @@
 # Refer to the README and COPYING files for full details of the license
 #
 
+import io
+
 from testlib import VdsmTestCase as TestCaseBase
 from testlib import permutations, expandPermutations
 from testlib import temporaryPath
@@ -28,7 +30,7 @@
 @expandPermutations
 class TestDirectFile(TestCaseBase):
 
-    DATA = "a" * 512 + "b" * 512
+    DATA = b"a" * 512 + b"b" * 512
 
     @permutations([[0], [512], [1024], [1024 + 512]])
     def test_read(self, size):
@@ -47,7 +49,7 @@
         with temporaryPath() as srcPath, \
                 directio.DirectFile(srcPath, "w") as f:
             f.write(self.DATA)
-            with open(srcPath) as f:
+            with io.open(srcPath, "rb") as f:
                 self.assertEquals(f.read(), self.DATA)
 
     def test_small_writes(self):
@@ -56,7 +58,7 @@
             f.write(self.DATA[:512])
             f.write(self.DATA[512:])
 
-            with open(srcPath) as f:
+            with io.open(srcPath, "rb") as f:
                 self.assertEquals(f.read(), self.DATA)
 
     def test_update_and_read(self):
@@ -68,5 +70,5 @@
                 f.seek(512)
                 f.write(self.DATA[512:])
 
-            with open(srcPath) as f:
+            with io.open(srcPath, "rb") as f:
                 self.assertEquals(f.read(), self.DATA)


-- 
To view, visit https://gerrit.ovirt.org/54699
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iad6f317df3efc70adb95063227c5e07513d34135
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list