summaryrefslogtreecommitdiffstats
path: root/test/unit/common/test_utils.py
diff options
context:
space:
mode:
authorPeter Portante <peter.portante@redhat.com>2013-05-28 06:29:22 -0400
committerLuis Pabon <lpabon@redhat.com>2013-06-03 14:01:29 -0700
commita574805398d9bf28be6f357e26a2ba299a5b90e1 (patch)
tree1207d03d0419d14d99204b8313d95b991d73df8b /test/unit/common/test_utils.py
parent3c0cdd74ec1d8df3e452a6653f20bad6252b971c (diff)
Bring initial DiskDir module coverage to 97%.
This is quite ugly. Sorry. We ported a set of test from OpenStack Swift's test/unit/commont/test_db.py, the testAccountBroker and testContainerBroker, but because of the divergent nature of the current attempt UFO (Unified File and Object) implementation, it was not possible to use the interface calls directly. Instead, we are using these tests to make sure most of the code paths are exercised, and to define much of the expected behavior. Further refactoring, unit tests and functional test work will help us bring the code base and these tests closer to the originals in upstream OpenStack Swift (as of Havana). Change-Id: I095bb03619de6e7e1378b5252913e39b1ea8bf27 Signed-off-by: Peter Portante <peter.portante@redhat.com> Reviewed-on: http://review.gluster.org/5135 Reviewed-by: Luis Pabon <lpabon@redhat.com> Tested-by: Luis Pabon <lpabon@redhat.com>
Diffstat (limited to 'test/unit/common/test_utils.py')
-rw-r--r--test/unit/common/test_utils.py47
1 files changed, 43 insertions, 4 deletions
diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py
index 0f6dba3..06f1a46 100644
--- a/test/unit/common/test_utils.py
+++ b/test/unit/common/test_utils.py
@@ -38,9 +38,11 @@ _xattr_set_err = {}
_xattr_get_err = {}
_xattr_rem_err = {}
+
def _xkey(path, key):
return "%s:%s" % (path, key)
+
def _setxattr(path, key, value, *args, **kwargs):
_xattr_op_cnt['set'] += 1
xkey = _xkey(path, key)
@@ -51,6 +53,7 @@ def _setxattr(path, key, value, *args, **kwargs):
global _xattrs
_xattrs[xkey] = value
+
def _getxattr(path, key, *args, **kwargs):
_xattr_op_cnt['get'] += 1
xkey = _xkey(path, key)
@@ -67,6 +70,7 @@ def _getxattr(path, key, *args, **kwargs):
raise e
return ret_val
+
def _removexattr(path, key, *args, **kwargs):
_xattr_op_cnt['remove'] += 1
xkey = _xkey(path, key)
@@ -82,6 +86,7 @@ def _removexattr(path, key, *args, **kwargs):
e.errno = errno.ENODATA
raise e
+
def _initxattr():
global _xattrs
_xattrs = {}
@@ -102,6 +107,7 @@ def _initxattr():
xattr.getxattr = _getxattr
xattr.removexattr = _removexattr
+
def _destroyxattr():
# Restore the current methods just in case
global _xattr_set; xattr.setxattr = _xattr_set
@@ -789,6 +795,40 @@ class TestUtils(unittest.TestCase):
cd = utils._get_container_details_from_fs(td)
assert cd.bytes_used == 0, repr(cd.bytes_used)
+ # Should not include the directories
+ assert cd.object_count == 5, repr(cd.object_count)
+ assert set(cd.obj_list) == set(['file1', 'file3', 'file2',
+ 'dir1/file1', 'dir1/file2'
+ ]), repr(cd.obj_list)
+
+ full_dir1 = os.path.join(td, 'dir1')
+ full_dir2 = os.path.join(td, 'dir2')
+ full_dir3 = os.path.join(td, 'dir3')
+ exp_dir_dict = { td: os.path.getmtime(td),
+ full_dir1: os.path.getmtime(full_dir1),
+ full_dir2: os.path.getmtime(full_dir2),
+ full_dir3: os.path.getmtime(full_dir3),
+ }
+ for d,m in cd.dir_list:
+ assert d in exp_dir_dict
+ assert exp_dir_dict[d] == m
+ finally:
+ os.chdir(orig_cwd)
+ shutil.rmtree(td)
+
+ def test_get_container_details_from_fs_ufo(self):
+ orig_cwd = os.getcwd()
+ __obj_only = Glusterfs.OBJECT_ONLY
+ td = tempfile.mkdtemp()
+ try:
+ tf = tarfile.open("common/data/container_tree.tar.bz2", "r:bz2")
+ os.chdir(td)
+ tf.extractall()
+
+ Glusterfs.OBJECT_ONLY = False
+
+ cd = utils._get_container_details_from_fs(td)
+ assert cd.bytes_used == 0, repr(cd.bytes_used)
assert cd.object_count == 8, repr(cd.object_count)
assert set(cd.obj_list) == set(['file1', 'file3', 'file2',
'dir3', 'dir1', 'dir2',
@@ -809,24 +849,23 @@ class TestUtils(unittest.TestCase):
finally:
os.chdir(orig_cwd)
shutil.rmtree(td)
-
+ Glusterfs.OBJECT_ONLY = __obj_only
def test_get_container_details_from_fs_do_getsize_true(self):
orig_cwd = os.getcwd()
+ __do_getsize = Glusterfs._do_getsize
td = tempfile.mkdtemp()
try:
tf = tarfile.open("common/data/container_tree.tar.bz2", "r:bz2")
os.chdir(td)
tf.extractall()
- __do_getsize = Glusterfs._do_getsize
Glusterfs._do_getsize = True
cd = utils._get_container_details_from_fs(td)
assert cd.bytes_used == 30, repr(cd.bytes_used)
- assert cd.object_count == 8, repr(cd.object_count)
+ assert cd.object_count == 5, repr(cd.object_count)
assert set(cd.obj_list) == set(['file1', 'file3', 'file2',
- 'dir3', 'dir1', 'dir2',
'dir1/file1', 'dir1/file2'
]), repr(cd.obj_list)