From b29164198523591a69b234e869b7a1b94bd4f08e Mon Sep 17 00:00:00 2001 From: Peter Portante Date: Thu, 23 May 2013 16:34:24 -0400 Subject: 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 Reviewed-on: http://review.gluster.org/5080 Reviewed-by: Luis Pabon Tested-by: Luis Pabon --- gluster/swift/common/fs_utils.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'gluster/swift/common/fs_utils.py') 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) -- cgit