summaryrefslogtreecommitdiffstats
path: root/ufo
diff options
context:
space:
mode:
authorMohammed Junaid <junaid@redhat.com>2013-02-10 02:10:25 +0530
committerPeter Portante <peter.portante@redhat.com>2013-04-29 16:35:57 -0400
commitd6c287ab8cdc9b8f4a5c7f03ec0661c9155defd9 (patch)
tree8650047450d1df8eaf4c6f82e26cc434eca36040 /ufo
parent55389b74c7a50d162ef95e07a562575e78e9b888 (diff)
object-storage: Fixing the errors and warnings in unittest.
Change-Id: Id22c968aefd82c4b62445b3ecc93cbabc2b35ffc BUG: 887301 Signed-off-by: Mohammed Junaid <junaid@redhat.com> Reviewed-on: http://review.gluster.org/4394 Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com> Reviewed-by: Peter Portante <pportant@redhat.com> Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'ufo')
-rw-r--r--ufo/test/unit/common/test_diskfile.py36
1 files changed, 34 insertions, 2 deletions
diff --git a/ufo/test/unit/common/test_diskfile.py b/ufo/test/unit/common/test_diskfile.py
index fb0dc3e..85d539a 100644
--- a/ufo/test/unit/common/test_diskfile.py
+++ b/ufo/test/unit/common/test_diskfile.py
@@ -66,6 +66,21 @@ def _mock_do_unlink(f):
raise ose
+def _mock_do_unlink_eacces_err(f):
+ ose = OSError()
+ ose.errno = errno.EACCES
+ raise ose
+
+def _mock_getsize_eaccess_err(f):
+ ose = OSError()
+ ose.errno = errno.EACCES
+ raise ose
+
+def _mock_do_rmdir_eacces_err(f):
+ ose = OSError()
+ ose.errno = errno.EACCES
+ raise ose
+
class MockRenamerCalled(Exception):
pass
@@ -654,13 +669,16 @@ class TestDiskFile(unittest.TestCase):
os.chmod(the_path, stats.st_mode & (~stat.S_IWUSR))
# Handle the case do_unlink() raises an OSError
+ __os_unlink = os.unlink
+ os.unlink = _mock_do_unlink_eacces_err
try:
gdf.unlinkold(normalize_timestamp(later))
except OSError as e:
- assert e.errno != errno.ENOENT
+ assert e.errno == errno.EACCES
else:
self.fail("Excepted an OSError when unlinking file")
finally:
+ os.unlink = __os_unlink
os.chmod(the_path, stats.st_mode)
assert os.path.isdir(gdf.datadir)
@@ -699,11 +717,14 @@ class TestDiskFile(unittest.TestCase):
stats = os.stat(gdf.datadir)
os.chmod(gdf.datadir, 0)
+ __os_rmdir = os.rmdir
+ os.rmdir = _mock_do_rmdir_eacces_err
try:
later = float(gdf.metadata['X-Timestamp']) + 1
gdf.unlinkold(normalize_timestamp(later))
finally:
os.chmod(gdf.datadir, stats.st_mode)
+ os.rmdir = __os_rmdir
assert os.path.isdir(gdf.datadir)
assert os.path.isdir(gdf.data_file)
finally:
@@ -795,13 +816,16 @@ class TestDiskFile(unittest.TestCase):
assert not gdf._is_dir
stats = os.stat(the_path)
os.chmod(the_path, 0)
+ __os_path_getsize = os.path.getsize
+ os.path.getsize = _mock_getsize_eaccess_err
try:
s = gdf.get_data_file_size()
except OSError as err:
- assert err.errno != errno.ENOENT
+ assert err.errno == errno.EACCES
else:
self.fail("Expected OSError exception")
finally:
+ os.path.getsize = __os_path_getsize
os.chmod(the_path, stats.st_mode)
finally:
shutil.rmtree(td)
@@ -873,7 +897,15 @@ class TestDiskFile(unittest.TestCase):
assert os.path.basename(saved_tmppath)[:3] == '.z.'
assert os.path.exists(saved_tmppath)
os.write(fd, "123")
+ # At the end of previous with block a close on fd is called.
+ # Calling os.close on the same fd will raise an OSError
+ # exception and we must catch it.
+ try:
os.close(fd)
+ except OSError as err:
+ pass
+ else:
+ self.fail("Exception expected")
assert not os.path.exists(saved_tmppath)
finally:
shutil.rmtree(td)