From b00a99673233b8fe0a93c6f9095b435cb2569330 Mon Sep 17 00:00:00 2001 From: Thiago da Silva Date: Wed, 26 Mar 2014 14:57:55 -0400 Subject: removing exception handling in do_mkdir This change is being made to allow callers to handle any exception thrown by os.mkdir. This function is currently never called anywhere in the code. It was introduced as part of the first commit to this project but it was never used. This patch (http://review.gluster.org/#/c/5304/) removed the early version of this function, and this patch (http://review.gluster.org/#/c/5305/) added it back with new exception handling. Change-Id: I71325660cb47594b0804da3da21920e26d2055f2 Signed-off-by: Thiago da Silva Reviewed-on: http://review.gluster.org/7350 Reviewed-by: Prashanth Pai Reviewed-by: Chetan Risbud Tested-by: Chetan Risbud --- gluster/swift/common/fs_utils.py | 12 +----------- test/unit/common/test_fs_utils.py | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/gluster/swift/common/fs_utils.py b/gluster/swift/common/fs_utils.py index 03c5a77..a93fa6b 100644 --- a/gluster/swift/common/fs_utils.py +++ b/gluster/swift/common/fs_utils.py @@ -105,17 +105,7 @@ def do_ismount(path): def do_mkdir(path): - try: - os.mkdir(path) - except OSError as err: - if err.errno == errno.EEXIST: - logging.warn("fs_utils: os.mkdir - path %s already exists", path) - elif err.errno in (errno.ENOSPC, errno.EDQUOT): - do_log_rl("do_mkdir(%s) failed: %s", path, err) - raise DiskFileNoSpace() - else: - raise GlusterFileSystemOSError( - err.errno, '%s, os.mkdir("%s")' % (err.strerror, path)) + os.mkdir(path) def do_listdir(path): diff --git a/test/unit/common/test_fs_utils.py b/test/unit/common/test_fs_utils.py index dbf052f..46e7ffc 100644 --- a/test/unit/common/test_fs_utils.py +++ b/test/unit/common/test_fs_utils.py @@ -348,36 +348,36 @@ class TestFsUtils(unittest.TestCase): try: path = os.path.join('/tmp', str(random.random())) fs.do_mkdir(path) - assert os.path.exists(path) - assert fs.do_mkdir(path) is None + self.assertTrue(os.path.exists(path)) + self.assertRaises(OSError, fs.do_mkdir, path) finally: os.rmdir(path) def test_do_mkdir_err(self): try: - path = os.path.join('/tmp', str(random.random()), str(random.random())) + path = os.path.join('/tmp', str(random.random()), + str(random.random())) fs.do_mkdir(path) - except GlusterFileSystemOSError: - pass + except OSError as err: + self.assertEqual(err.errno, errno.ENOENT) else: - self.fail("GlusterFileSystemOSError expected") + self.fail("OSError with errno.ENOENT expected") with patch('os.mkdir', mock_os_mkdir_makedirs_enospc): try: fs.do_mkdir("blah") - except DiskFileNoSpace: - pass + except OSError as err: + self.assertEqual(err.errno, errno.ENOSPC) else: - self.fail("Expected DiskFileNoSpace exception") + self.fail("Expected OSError with errno.ENOSPC exception") with patch('os.mkdir', mock_os_mkdir_makedirs_edquot): try: fs.do_mkdir("blah") - except DiskFileNoSpace: - pass + except OSError as err: + self.assertEqual(err.errno, errno.EDQUOT) else: - self.fail("Expected DiskFileNoSpace exception") - + self.fail("Expected OSError with errno.EDQUOT exception") def test_do_listdir(self): tmpdir = mkdtemp() -- cgit