summaryrefslogtreecommitdiffstats
path: root/gluster/swift/common/fs_utils.py
diff options
context:
space:
mode:
authorPeter Portante <peter.portante@redhat.com>2013-05-23 16:34:24 -0400
committerLuis Pabon <lpabon@redhat.com>2013-05-24 12:08:18 -0700
commitb29164198523591a69b234e869b7a1b94bd4f08e (patch)
tree04a3787ea446cdc42d282d5483ad21841c880f70 /gluster/swift/common/fs_utils.py
parent3ff44850b4b0151b55028d45c8c77a521c478b2c (diff)
Add DiskDir unit test skeleton and pep8 filter
The new DiskDir unit test skeleton is quite incomplete, but gets the DiskDir module on the board for modules covered, explicitly exposing the fact that we need to get test coverage. This is a first step. At the same time, we also update all the modules we have applying the fix for pep8 errors now run under tox. We can then add a Jenkins pre-commit job to fail on pep8 errors. This brings our code to parity with what they are doing in OpenStack Swift. Change-Id: Ia0565606512efda6e73f67bd00269177b89db858 Signed-off-by: Peter Portante <peter.portante@redhat.com> Reviewed-on: http://review.gluster.org/5080 Reviewed-by: Luis Pabon <lpabon@redhat.com> Tested-by: Luis Pabon <lpabon@redhat.com>
Diffstat (limited to 'gluster/swift/common/fs_utils.py')
-rw-r--r--gluster/swift/common/fs_utils.py30
1 files changed, 24 insertions, 6 deletions
diff --git a/gluster/swift/common/fs_utils.py b/gluster/swift/common/fs_utils.py
index 0613a26..de450a5 100644
--- a/gluster/swift/common/fs_utils.py
+++ b/gluster/swift/common/fs_utils.py
@@ -16,14 +16,16 @@
import logging
import os
import errno
-import os.path as os_path
+import os.path as os_path # noqa
from eventlet import tpool
from gluster.swift.common.exceptions import FileOrDirNotFoundError, \
NotDirectoryError
+
def do_walk(*args, **kwargs):
return os.walk(*args, **kwargs)
+
def do_write(fd, msg):
try:
cnt = os.write(fd, msg)
@@ -32,6 +34,7 @@ def do_write(fd, msg):
raise
return cnt
+
def do_mkdir(path):
try:
os.mkdir(path)
@@ -41,15 +44,18 @@ def do_mkdir(path):
raise
return True
+
def do_makedirs(path):
try:
os.makedirs(path)
except OSError as err:
if err.errno != errno.EEXIST:
- logging.exception("Makedirs failed on %s err: %s", path, err.strerror)
+ logging.exception("Makedirs failed on %s err: %s",
+ path, err.strerror)
raise
return True
+
def do_listdir(path):
try:
buf = os.listdir(path)
@@ -58,6 +64,7 @@ def do_listdir(path):
raise
return buf
+
def do_chown(path, uid, gid):
try:
os.chown(path, uid, gid)
@@ -66,6 +73,7 @@ def do_chown(path, uid, gid):
raise
return True
+
def do_stat(path):
try:
#Check for fd.
@@ -78,6 +86,7 @@ def do_stat(path):
raise
return buf
+
def do_open(path, mode):
if isinstance(mode, int):
try:
@@ -93,6 +102,7 @@ def do_open(path, mode):
raise
return fd
+
def do_close(fd):
#fd could be file or int type.
try:
@@ -105,16 +115,19 @@ def do_close(fd):
raise
return True
-def do_unlink(path, log = True):
+
+def do_unlink(path, log=True):
try:
os.unlink(path)
except OSError as err:
if err.errno != errno.ENOENT:
if log:
- logging.exception("Unlink failed on %s err: %s", path, err.strerror)
+ logging.exception("Unlink failed on %s err: %s",
+ path, err.strerror)
raise
return True
+
def do_rmdir(path):
try:
os.rmdir(path)
@@ -127,15 +140,17 @@ def do_rmdir(path):
res = True
return res
+
def do_rename(old_path, new_path):
try:
os.rename(old_path, new_path)
except OSError as err:
- logging.exception("Rename failed on %s to %s err: %s", old_path, new_path, \
- err.strerror)
+ logging.exception("Rename failed on %s to %s err: %s",
+ old_path, new_path, err.strerror)
raise
return True
+
def mkdirs(path):
"""
Ensures the path is a directory or makes it if not. Errors if the path
@@ -146,6 +161,7 @@ def mkdirs(path):
if not os.path.isdir(path):
do_makedirs(path)
+
def dir_empty(path):
"""
Return true if directory/container is empty.
@@ -159,6 +175,7 @@ def dir_empty(path):
raise FileOrDirNotFoundError()
raise NotDirectoryError()
+
def rmdirs(path):
if not os.path.isdir(path):
return False
@@ -170,6 +187,7 @@ def rmdirs(path):
return False
return True
+
def do_fsync(fd):
try:
tpool.execute(os.fsync, fd)