Change in vdsm[master]: directio: Keep line terminators in readlines()
nsoffer at redhat.com
nsoffer at redhat.com
Sun Mar 13 15:28:32 UTC 2016
Nir Soffer has uploaded a new change for review.
Change subject: directio: Keep line terminators in readlines()
......................................................................
directio: Keep line terminators in readlines()
Fix DirectFile.readlines() to keep line terminators as built-in file
object and io classes.
Change-Id: Id2d533b3811cfc7f642f6f0a081c61fe468946f3
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M lib/vdsm/storage/directio.py
M tests/storage_directio_test.py
2 files changed, 17 insertions(+), 11 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/01/54701/1
diff --git a/lib/vdsm/storage/directio.py b/lib/vdsm/storage/directio.py
index c9fc3ca..c80ed5f 100644
--- a/lib/vdsm/storage/directio.py
+++ b/lib/vdsm/storage/directio.py
@@ -91,7 +91,9 @@
return self._writable
def readlines(self):
- return self.readall().splitlines()
+ with self._readall() as buf:
+ buf.seek(0)
+ return buf.readlines()
def writelines(self, lines):
data = ''.join([l if l.endswith('\n') else l + '\n' for l in lines])
@@ -141,14 +143,8 @@
return ptr[:numRead]
def readall(self):
- buffsize = 1024
- res = io.BytesIO()
- with closing(res):
- while True:
- buff = self.read(buffsize)
- res.write(buff)
- if len(buff) < buffsize:
- return res.getvalue()
+ with self._readall() as buf:
+ return buf.getvalue()
def write(self, data):
length = len(data)
@@ -182,3 +178,15 @@
if not self.closed:
self.close()
+
+ def _readall(self):
+ """
+ Return a io.BytesIO with the entire file contents.
+ """
+ buffsize = 1024
+ buf = io.BytesIO()
+ while True:
+ chunk = self.read(buffsize)
+ buf.write(chunk)
+ if len(chunk) < buffsize:
+ return buf
diff --git a/tests/storage_directio_test.py b/tests/storage_directio_test.py
index 9ba379a..6744b9d 100644
--- a/tests/storage_directio_test.py
+++ b/tests/storage_directio_test.py
@@ -20,7 +20,6 @@
import io
-from testValidation import brokentest
from testlib import VdsmTestCase as TestCaseBase
from testlib import permutations, expandPermutations
from testlib import temporaryPath
@@ -75,7 +74,6 @@
with io.open(srcPath, "rb") as f:
self.assertEquals(f.read(), self.DATA)
- @brokentest("DirectFile does not keep line terminator")
def test_readlines(self):
with temporaryPath(data=self.DATA) as srcPath, \
directio.DirectFile(srcPath, "r") as direct_file, \
--
To view, visit https://gerrit.ovirt.org/54701
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id2d533b3811cfc7f642f6f0a081c61fe468946f3
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