Remove do_mkdir and simplify mkdirs

Change-Id: I2e629533bceafb341ced5b1b3f2436448293e03f
Signed-off-by: Luis Pabon <lpabon@redhat.com>
Reviewed-on: http://review.gluster.org/5304
Reviewed-by: Peter Portante <pportant@redhat.com>
Tested-by: Peter Portante <pportant@redhat.com>
This commit is contained in:
Luis Pabon 2013-07-09 15:41:43 -04:00 committed by Peter Portante
parent 9282f7095e
commit 3f72ae45a3
2 changed files with 11 additions and 44 deletions

View File

@ -35,27 +35,6 @@ def do_write(fd, msg):
return cnt
def do_mkdir(path):
try:
os.mkdir(path)
except OSError as err:
if err.errno != errno.EEXIST:
logging.exception("Mkdir failed on %s err: %s", path, err.strerror)
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)
raise
return True
def do_listdir(path):
try:
buf = os.listdir(path)
@ -155,7 +134,14 @@ def mkdirs(path):
:param path: path to create
"""
if not os.path.isdir(path):
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)
raise
return True
def dir_empty(path):

View File

@ -116,32 +116,13 @@ class TestFsUtils(unittest.TestCase):
os.close(fd)
os.remove(tmpfile)
def test_do_mkdir(self):
try:
path = os.path.join('/tmp', str(random.random()))
fs.do_mkdir(path)
assert os.path.exists(path)
assert 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()))
fs.do_mkdir(path)
except OSError:
pass
else:
self.fail("OSError expected")
def test_do_makedirs(self):
def test_mkdirs(self):
try:
subdir = os.path.join('/tmp', str(random.random()))
path = os.path.join(subdir, str(random.random()))
fs.do_makedirs(path)
fs.mkdirs(path)
assert os.path.exists(path)
assert fs.do_makedirs(path)
assert fs.mkdirs(path)
finally:
shutil.rmtree(subdir)