Change in vdsm[master]: fileUtils: Remove open_ex
nsoffer at redhat.com
nsoffer at redhat.com
Sat Mar 12 02:22:57 UTC 2016
Nir Soffer has uploaded a new change for review.
Change subject: fileUtils: Remove open_ex
......................................................................
fileUtils: Remove open_ex
We have only one user of this, and it can use DirectFile instead, making
the code more clear. We should avoid non-standard variants such as
open_ex.
Change-Id: Id5a26cdd857b845b7bbd58d302e231bb7d6c33e5
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M tests/fileUtilTests.py
M vdsm/storage/fileUtils.py
M vdsm/storage/remoteFileHandler.py
3 files changed, 11 insertions(+), 18 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/79/54679/1
diff --git a/tests/fileUtilTests.py b/tests/fileUtilTests.py
index 7420c5f..8c2622e 100644
--- a/tests/fileUtilTests.py
+++ b/tests/fileUtilTests.py
@@ -36,41 +36,42 @@
@permutations([[0], [512], [1024], [1024 + 512]])
def testRead(self, size):
with temporaryPath(data=self.DATA) as srcPath, \
- fileUtils.open_ex(srcPath, "dr") as f:
+ fileUtils.DirectFile(srcPath, "dr") as f:
self.assertEquals(f.read(size), self.DATA[:size])
@permutations([[512], [1024]])
def testSeekRead(self, offset):
with temporaryPath(data=self.DATA) as srcPath, \
- fileUtils.open_ex(srcPath, "dr") as f:
+ fileUtils.DirectFile(srcPath, "dr") as f:
f.seek(offset)
self.assertEquals(f.read(), self.DATA[offset:])
def testWrite(self):
- with temporaryPath() as srcPath, fileUtils.open_ex(srcPath, "dw") as f:
+ with temporaryPath() as srcPath, \
+ fileUtils.DirectFile(srcPath, "dw") as f:
f.write(self.DATA)
- with fileUtils.open_ex(srcPath, "r") as f:
+ with open(srcPath) as f:
self.assertEquals(f.read(), self.DATA)
def testSmallWrites(self):
with temporaryPath() as srcPath, \
- fileUtils.open_ex(srcPath, "dw") as f:
+ fileUtils.DirectFile(srcPath, "dw") as f:
f.write(self.DATA[:512])
f.write(self.DATA[512:])
- with fileUtils.open_ex(srcPath, "r") as f:
+ with open(srcPath) as f:
self.assertEquals(f.read(), self.DATA)
def testUpdateRead(self):
with temporaryPath() as srcPath, \
- fileUtils.open_ex(srcPath, "wd") as f:
+ fileUtils.DirectFile(srcPath, "wd") as f:
f.write(self.DATA[:512])
- with fileUtils.open_ex(srcPath, "r+d") as f:
+ with fileUtils.DirectFile(srcPath, "r+d") as f:
f.seek(512)
f.write(self.DATA[512:])
- with fileUtils.open_ex(srcPath, "r") as f:
+ with open(srcPath) as f:
self.assertEquals(f.read(), self.DATA)
diff --git a/vdsm/storage/fileUtils.py b/vdsm/storage/fileUtils.py
index 69aac2f..697b6ce 100644
--- a/vdsm/storage/fileUtils.py
+++ b/vdsm/storage/fileUtils.py
@@ -194,14 +194,6 @@
return True
-def open_ex(path, mode):
- # TODO: detect if on nfs to do this out of process
- if "d" in mode:
- return DirectFile(path, mode)
- else:
- return open(path, mode)
-
-
class DirectFile(object):
def __init__(self, path, mode):
if "d" not in mode:
diff --git a/vdsm/storage/remoteFileHandler.py b/vdsm/storage/remoteFileHandler.py
index e69ae8c..e858c81 100644
--- a/vdsm/storage/remoteFileHandler.py
+++ b/vdsm/storage/remoteFileHandler.py
@@ -334,7 +334,7 @@
def directReadLines(path):
- with fileUtils.open_ex(path, "dr") as f:
+ with fileUtils.DirectFile(path, "dr") as f:
return f.readlines()
--
To view, visit https://gerrit.ovirt.org/54679
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id5a26cdd857b845b7bbd58d302e231bb7d6c33e5
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