Remove some dead code
Used vulture utility to detect unused code in swiftonfile. https://pypi.python.org/pypi/vulture Change-Id: I045f5a96a48d2384718ad0f993540caa3a866309 Signed-off-by: Prashanth Pai <ppai@redhat.com>
This commit is contained in:
parent
b76c95dbcb
commit
eb7883dc23
@ -42,9 +42,7 @@ class PkgInfo(object):
|
||||
return '%s-dev' % (self.canonical_version,)
|
||||
|
||||
|
||||
###
|
||||
### Change the Package version here
|
||||
###
|
||||
# Change the Package version here
|
||||
_pkginfo = PkgInfo('2.1.0', '0', 'swiftonfile', False)
|
||||
__version__ = _pkginfo.pretty_version
|
||||
__canonical_version__ = _pkginfo.canonical_version
|
||||
|
@ -30,14 +30,6 @@ class FailureToMountError(SwiftOnFileFsException):
|
||||
pass
|
||||
|
||||
|
||||
class FileOrDirNotFoundError(SwiftOnFileFsException):
|
||||
pass
|
||||
|
||||
|
||||
class NotDirectoryError(SwiftOnFileFsException):
|
||||
pass
|
||||
|
||||
|
||||
class AlreadyExistsAsDir(SwiftOnFileFsException):
|
||||
pass
|
||||
|
||||
|
@ -25,36 +25,10 @@ from itertools import repeat
|
||||
import ctypes
|
||||
from eventlet import sleep
|
||||
from swift.common.utils import load_libc_function
|
||||
from swiftonfile.swift.common.exceptions import FileOrDirNotFoundError, \
|
||||
NotDirectoryError, SwiftOnFileSystemOSError
|
||||
from swiftonfile.swift.common.exceptions import SwiftOnFileSystemOSError
|
||||
from swift.common.exceptions import DiskFileNoSpace
|
||||
|
||||
|
||||
def do_exists(path):
|
||||
return os.path.exists(path)
|
||||
|
||||
|
||||
def do_touch(path):
|
||||
with open(path, 'a'):
|
||||
os.utime(path, None)
|
||||
|
||||
|
||||
def do_getctime(path):
|
||||
return os.path.getctime(path)
|
||||
|
||||
|
||||
def do_getmtime(path):
|
||||
return os.path.getmtime(path)
|
||||
|
||||
|
||||
def do_isdir(path):
|
||||
return os.path.isdir(path)
|
||||
|
||||
|
||||
def do_getsize(path):
|
||||
return os.path.getsize(path)
|
||||
|
||||
|
||||
def do_getxattr(path, key):
|
||||
return xattr.getxattr(path, key)
|
||||
|
||||
@ -142,33 +116,6 @@ def do_mkdir(path):
|
||||
os.mkdir(path)
|
||||
|
||||
|
||||
def do_listdir(path):
|
||||
try:
|
||||
buf = os.listdir(path)
|
||||
except OSError as err:
|
||||
raise SwiftOnFileSystemOSError(
|
||||
err.errno, '%s, os.listdir("%s")' % (err.strerror, path))
|
||||
return buf
|
||||
|
||||
|
||||
def dir_empty(path):
|
||||
"""
|
||||
Return true if directory is empty (or does not exist), false otherwise.
|
||||
|
||||
:param path: Directory path
|
||||
:returns: True/False
|
||||
"""
|
||||
try:
|
||||
files = do_listdir(path)
|
||||
return not files
|
||||
except SwiftOnFileSystemOSError as err:
|
||||
if err.errno == errno.ENOENT:
|
||||
raise FileOrDirNotFoundError()
|
||||
if err.errno == errno.ENOTDIR:
|
||||
raise NotDirectoryError()
|
||||
raise
|
||||
|
||||
|
||||
def do_rmdir(path):
|
||||
try:
|
||||
os.rmdir(path)
|
||||
@ -323,26 +270,6 @@ def do_lseek(fd, pos, how):
|
||||
err.errno, '%s, os.fsync("%s")' % (err.strerror, fd))
|
||||
|
||||
|
||||
def mkdirs(path):
|
||||
"""
|
||||
Ensures the path is a directory or makes it if not. Errors if the path
|
||||
exists but is a file or on permissions failure.
|
||||
|
||||
:param path: path to create
|
||||
"""
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError as err:
|
||||
if err.errno == errno.EEXIST and os.path.isdir(path):
|
||||
return
|
||||
elif err.errno in (errno.ENOSPC, errno.EDQUOT):
|
||||
do_log_rl("mkdirs(%s) failed: %s", path, err)
|
||||
raise DiskFileNoSpace()
|
||||
else:
|
||||
raise SwiftOnFileSystemOSError(
|
||||
err.errno, '%s, os.makedirs("%s")' % (err.strerror, path))
|
||||
|
||||
|
||||
def get_filename_from_fd(fd, verify=False):
|
||||
"""
|
||||
Given the file descriptor, this method attempts to get the filename as it
|
||||
|
@ -47,7 +47,6 @@ class CheckConstraintsMiddleware(object):
|
||||
def __init__(self, app, conf):
|
||||
self.app = app
|
||||
self.logger = get_logger(conf, log_route='constraints')
|
||||
self.swift_dir = conf.get('swift_dir', '/etc/swift')
|
||||
self.policies = conf.get('policies', '')
|
||||
|
||||
def __call__(self, env, start_response):
|
||||
|
@ -228,11 +228,6 @@ class DiskFileManager(SwiftDiskFileManager):
|
||||
:param conf: caller provided configuration object
|
||||
:param logger: caller provided logger
|
||||
"""
|
||||
def __init__(self, conf, logger):
|
||||
super(DiskFileManager, self).__init__(conf, logger)
|
||||
self.reseller_prefix = \
|
||||
conf.get('reseller_prefix', 'AUTH_').strip() # Not used, currently
|
||||
|
||||
def get_diskfile(self, device, partition, account, container, obj,
|
||||
policy_idx=0, **kwargs):
|
||||
dev_path = self.get_dev_path(device)
|
||||
@ -583,7 +578,6 @@ class DiskFile(object):
|
||||
self._uid = int(uid)
|
||||
self._gid = int(gid)
|
||||
self._is_dir = False
|
||||
self._logger = mgr.logger
|
||||
self._metadata = None
|
||||
self._fd = None
|
||||
# Don't store a value for data_file until we know it exists.
|
||||
@ -822,10 +816,6 @@ class DiskFile(object):
|
||||
" on subpath: %s" % (full_path, cur_path))
|
||||
child = stack.pop() if stack else None
|
||||
return True, newmd
|
||||
# Exists, but as a file
|
||||
#raise DiskFileError('DiskFile.put(): directory creation failed'
|
||||
# ' since the target, %s, already exists as'
|
||||
# ' a file' % df._data_file)
|
||||
|
||||
@contextmanager
|
||||
def create(self, size=None):
|
||||
|
@ -23,8 +23,7 @@ from mock import patch, Mock
|
||||
from time import sleep
|
||||
from tempfile import mkdtemp, mkstemp
|
||||
from swiftonfile.swift.common import fs_utils as fs
|
||||
from swiftonfile.swift.common.exceptions import NotDirectoryError, \
|
||||
FileOrDirNotFoundError, SwiftOnFileSystemOSError
|
||||
from swiftonfile.swift.common.exceptions import SwiftOnFileSystemOSError
|
||||
from swift.common.exceptions import DiskFileNoSpace
|
||||
|
||||
|
||||
@ -270,70 +269,6 @@ class TestFsUtils(unittest.TestCase):
|
||||
else:
|
||||
self.fail("Expected DiskFileNoSpace exception")
|
||||
|
||||
def test_mkdirs(self):
|
||||
try:
|
||||
subdir = os.path.join('/tmp', str(random.random()))
|
||||
path = os.path.join(subdir, str(random.random()))
|
||||
fs.mkdirs(path)
|
||||
assert os.path.exists(path)
|
||||
finally:
|
||||
shutil.rmtree(subdir)
|
||||
|
||||
def test_mkdirs_already_dir(self):
|
||||
tmpdir = mkdtemp()
|
||||
try:
|
||||
fs.mkdirs(tmpdir)
|
||||
except (SwiftOnFileSystemOSError, OSError):
|
||||
self.fail("Unexpected exception")
|
||||
else:
|
||||
pass
|
||||
finally:
|
||||
shutil.rmtree(tmpdir)
|
||||
|
||||
def test_mkdirs_existing_file(self):
|
||||
tmpdir = mkdtemp()
|
||||
fd, tmpfile = mkstemp(dir=tmpdir)
|
||||
try:
|
||||
fs.mkdirs(tmpfile)
|
||||
except OSError:
|
||||
pass
|
||||
else:
|
||||
self.fail("Expected SwiftOnFileSystemOSError exception")
|
||||
finally:
|
||||
os.close(fd)
|
||||
shutil.rmtree(tmpdir)
|
||||
|
||||
def test_mkdirs_existing_file_on_path(self):
|
||||
tmpdir = mkdtemp()
|
||||
fd, tmpfile = mkstemp(dir=tmpdir)
|
||||
try:
|
||||
fs.mkdirs(os.path.join(tmpfile, 'b'))
|
||||
except OSError:
|
||||
pass
|
||||
else:
|
||||
self.fail("Expected SwiftOnFileSystemOSError exception")
|
||||
finally:
|
||||
os.close(fd)
|
||||
shutil.rmtree(tmpdir)
|
||||
|
||||
def test_mkdirs_DiskFileNoSpace(self):
|
||||
|
||||
with patch('os.makedirs', mock_os_mkdir_makedirs_enospc):
|
||||
try:
|
||||
fs.mkdirs("blah")
|
||||
except DiskFileNoSpace:
|
||||
pass
|
||||
else:
|
||||
self.fail("Expected DiskFileNoSpace exception")
|
||||
|
||||
with patch('os.makedirs', mock_os_mkdir_makedirs_edquot):
|
||||
try:
|
||||
fs.mkdirs("blah")
|
||||
except DiskFileNoSpace:
|
||||
pass
|
||||
else:
|
||||
self.fail("Expected DiskFileNoSpace exception")
|
||||
|
||||
def test_do_mkdir(self):
|
||||
try:
|
||||
path = os.path.join('/tmp', str(random.random()))
|
||||
@ -369,26 +304,6 @@ class TestFsUtils(unittest.TestCase):
|
||||
else:
|
||||
self.fail("Expected OSError with errno.EDQUOT exception")
|
||||
|
||||
def test_do_listdir(self):
|
||||
tmpdir = mkdtemp()
|
||||
try:
|
||||
subdir = []
|
||||
for i in range(5):
|
||||
subdir.append(mkdtemp(dir=tmpdir).rsplit(os.path.sep, 1)[1])
|
||||
|
||||
assert subdir.sort() == fs.do_listdir(tmpdir).sort()
|
||||
finally:
|
||||
shutil.rmtree(tmpdir)
|
||||
|
||||
def test_do_listdir_err(self):
|
||||
try:
|
||||
path = os.path.join('/tmp', str(random.random()))
|
||||
fs.do_listdir(path)
|
||||
except SwiftOnFileSystemOSError:
|
||||
pass
|
||||
else:
|
||||
self.fail("SwiftOnFileSystemOSError expected")
|
||||
|
||||
def test_do_fstat(self):
|
||||
tmpdir = mkdtemp()
|
||||
try:
|
||||
@ -556,48 +471,6 @@ class TestFsUtils(unittest.TestCase):
|
||||
else:
|
||||
self.fail("SwiftOnFileSystemOSError expected")
|
||||
|
||||
def test_dir_empty(self):
|
||||
tmpdir = mkdtemp()
|
||||
try:
|
||||
subdir = mkdtemp(dir=tmpdir)
|
||||
assert not fs.dir_empty(tmpdir)
|
||||
assert fs.dir_empty(subdir)
|
||||
finally:
|
||||
shutil.rmtree(tmpdir)
|
||||
|
||||
def test_dir_empty_err(self):
|
||||
def _mock_os_listdir(path):
|
||||
raise OSError(13, "foo")
|
||||
|
||||
with patch("os.listdir", _mock_os_listdir):
|
||||
try:
|
||||
fs.dir_empty("/tmp")
|
||||
except SwiftOnFileSystemOSError:
|
||||
pass
|
||||
else:
|
||||
self.fail("SwiftOnFileSystemOSError exception expected")
|
||||
|
||||
def test_dir_empty_notfound(self):
|
||||
try:
|
||||
assert fs.dir_empty(os.path.join('/tmp', str(random.random())))
|
||||
except FileOrDirNotFoundError:
|
||||
pass
|
||||
else:
|
||||
self.fail("FileOrDirNotFoundError exception expected")
|
||||
|
||||
def test_dir_empty_notdir(self):
|
||||
fd, tmpfile = mkstemp()
|
||||
try:
|
||||
try:
|
||||
fs.dir_empty(tmpfile)
|
||||
except NotDirectoryError:
|
||||
pass
|
||||
else:
|
||||
self.fail("NotDirectoryError exception expected")
|
||||
finally:
|
||||
os.close(fd)
|
||||
os.unlink(tmpfile)
|
||||
|
||||
def test_do_rmdir(self):
|
||||
tmpdir = mkdtemp()
|
||||
try:
|
||||
|
@ -165,7 +165,6 @@ class TestDiskFile(unittest.TestCase):
|
||||
assert gdf._datadir == gdf._put_datadir
|
||||
assert gdf._data_file == os.path.join(self.td, "vol0", "ufo47", "bar", "z")
|
||||
assert gdf._is_dir is False
|
||||
assert gdf._logger == self.lg
|
||||
assert gdf._fd is None
|
||||
|
||||
def test_constructor_leadtrail_slash(self):
|
||||
|
Loading…
Reference in New Issue
Block a user