summaryrefslogtreecommitdiffstats
path: root/ufo/gluster/swift/common/fs_utils.py
diff options
context:
space:
mode:
authorPeter Portante <peter.portante@redhat.com>2012-12-07 16:39:37 -0500
committerVijay Bellur <vbellur@redhat.com>2012-12-17 06:10:54 -0800
commit47e21afaaf192b03db69d8f204b3e33e5f9596cf (patch)
treeb3973cddf521e9dfa9b9defa55511ef3605aaae4 /ufo/gluster/swift/common/fs_utils.py
parent5267406e5bcd8847bfe9565ee8d5ce13eeedd8cc (diff)
object-storage: Initial unittest of DiskFile class
If we had this ahead of time, we could have avoided the errors that were encountered leading to the fix-account-mapping fix (see http://review.gluster.org/4222). This represents 100% coverage of the DiskFile module, but the coverage report says otherwise, unfortunately. That is because the put() method invokes eventlets during the test run, and coverage is not able to accurately track the coverage lines properly. If one comments out the "tpool.execute()" line in DiskFile.put() the coverage report then reports 100% for the DiskFile module. Additionally, we changed DiskFile.put() in four ways that should not change its behavior: 1. Comments were added to explain various code paths and mark potential issues / fixes 2. It no longer returns a boolean value, matching the behavior of swift.obj.server.DiskFile.put() 3. It no longer logs a message when it detects a directory that already exists, instead is raises an exception We believe this is okay because we cannot find a code path that would lead to his condition. As a result, it makes it easier to test all the code paths in that routine. 4. It no longer logs a message when create_dir_object() fails, since create_dir_object() raises an exception on failure only We also modified create_dir_object() to not return a boolean as a result of the above behavior. Note that by implementing these tests up to this point we found three code paths that would have failed if encountered due to missing imports. We also made changes to the DiskFile module to make it a bit easier to test, also eliminating an extra stat system call when deleting directory objects. Change-Id: I3286de83c1ec7c5e8d6cab9354e1c4397cee7497 BUG: 870589 Signed-off-by: Peter Portante <peter.portante@redhat.com> Reviewed-on: http://review.gluster.org/4284 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Mohammed Junaid <junaid@redhat.com>
Diffstat (limited to 'ufo/gluster/swift/common/fs_utils.py')
-rw-r--r--ufo/gluster/swift/common/fs_utils.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/ufo/gluster/swift/common/fs_utils.py b/ufo/gluster/swift/common/fs_utils.py
index 7f5292c2bf1..88368c78c9e 100644
--- a/ufo/gluster/swift/common/fs_utils.py
+++ b/ufo/gluster/swift/common/fs_utils.py
@@ -101,7 +101,10 @@ def do_rmdir(path):
logging.exception("Rmdir failed on %s err: %s", path, str(err))
if err.errno != errno.ENOENT:
raise
- return True
+ res = False
+ else:
+ res = True
+ return res
def do_rename(old_path, new_path):
try:
@@ -149,8 +152,8 @@ def dir_empty(path):
return True
def rmdirs(path):
- if os.path.isdir(path) and dir_empty(path):
- do_rmdir(path)
- else:
- logging.error("rmdirs failed dir may not be empty or not valid dir")
+ if not os.path.isdir(path) or not dir_empty(path):
+ logging.error("rmdirs failed: %s may not be empty or not valid dir", path)
return False
+
+ return do_rmdir(path)