Merge "Remove some dead code"
This commit is contained in:
commit
486668b880
@ -42,9 +42,7 @@ class PkgInfo(object):
|
|||||||
return '%s-dev' % (self.canonical_version,)
|
return '%s-dev' % (self.canonical_version,)
|
||||||
|
|
||||||
|
|
||||||
###
|
# Change the Package version here
|
||||||
### Change the Package version here
|
|
||||||
###
|
|
||||||
_pkginfo = PkgInfo('2.1.0', '0', 'swiftonfile', False)
|
_pkginfo = PkgInfo('2.1.0', '0', 'swiftonfile', False)
|
||||||
__version__ = _pkginfo.pretty_version
|
__version__ = _pkginfo.pretty_version
|
||||||
__canonical_version__ = _pkginfo.canonical_version
|
__canonical_version__ = _pkginfo.canonical_version
|
||||||
|
@ -30,14 +30,6 @@ class FailureToMountError(SwiftOnFileFsException):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class FileOrDirNotFoundError(SwiftOnFileFsException):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class NotDirectoryError(SwiftOnFileFsException):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class AlreadyExistsAsDir(SwiftOnFileFsException):
|
class AlreadyExistsAsDir(SwiftOnFileFsException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -25,36 +25,10 @@ from itertools import repeat
|
|||||||
import ctypes
|
import ctypes
|
||||||
from eventlet import sleep
|
from eventlet import sleep
|
||||||
from swift.common.utils import load_libc_function
|
from swift.common.utils import load_libc_function
|
||||||
from swiftonfile.swift.common.exceptions import FileOrDirNotFoundError, \
|
from swiftonfile.swift.common.exceptions import SwiftOnFileSystemOSError
|
||||||
NotDirectoryError, SwiftOnFileSystemOSError
|
|
||||||
from swift.common.exceptions import DiskFileNoSpace
|
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):
|
def do_getxattr(path, key):
|
||||||
return xattr.getxattr(path, key)
|
return xattr.getxattr(path, key)
|
||||||
|
|
||||||
@ -142,33 +116,6 @@ def do_mkdir(path):
|
|||||||
os.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):
|
def do_rmdir(path):
|
||||||
try:
|
try:
|
||||||
os.rmdir(path)
|
os.rmdir(path)
|
||||||
@ -323,26 +270,6 @@ def do_lseek(fd, pos, how):
|
|||||||
err.errno, '%s, os.fsync("%s")' % (err.strerror, fd))
|
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):
|
def get_filename_from_fd(fd, verify=False):
|
||||||
"""
|
"""
|
||||||
Given the file descriptor, this method attempts to get the filename as it
|
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):
|
def __init__(self, app, conf):
|
||||||
self.app = app
|
self.app = app
|
||||||
self.logger = get_logger(conf, log_route='constraints')
|
self.logger = get_logger(conf, log_route='constraints')
|
||||||
self.swift_dir = conf.get('swift_dir', '/etc/swift')
|
|
||||||
self.policies = conf.get('policies', '')
|
self.policies = conf.get('policies', '')
|
||||||
|
|
||||||
def __call__(self, env, start_response):
|
def __call__(self, env, start_response):
|
||||||
|
@ -228,11 +228,6 @@ class DiskFileManager(SwiftDiskFileManager):
|
|||||||
:param conf: caller provided configuration object
|
:param conf: caller provided configuration object
|
||||||
:param logger: caller provided logger
|
: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,
|
def get_diskfile(self, device, partition, account, container, obj,
|
||||||
policy_idx=0, **kwargs):
|
policy_idx=0, **kwargs):
|
||||||
dev_path = self.get_dev_path(device)
|
dev_path = self.get_dev_path(device)
|
||||||
@ -583,7 +578,6 @@ class DiskFile(object):
|
|||||||
self._uid = int(uid)
|
self._uid = int(uid)
|
||||||
self._gid = int(gid)
|
self._gid = int(gid)
|
||||||
self._is_dir = False
|
self._is_dir = False
|
||||||
self._logger = mgr.logger
|
|
||||||
self._metadata = None
|
self._metadata = None
|
||||||
self._fd = None
|
self._fd = None
|
||||||
# Don't store a value for data_file until we know it exists.
|
# 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))
|
" on subpath: %s" % (full_path, cur_path))
|
||||||
child = stack.pop() if stack else None
|
child = stack.pop() if stack else None
|
||||||
return True, newmd
|
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
|
@contextmanager
|
||||||
def create(self, size=None):
|
def create(self, size=None):
|
||||||
|
@ -23,8 +23,7 @@ from mock import patch, Mock
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
from tempfile import mkdtemp, mkstemp
|
from tempfile import mkdtemp, mkstemp
|
||||||
from swiftonfile.swift.common import fs_utils as fs
|
from swiftonfile.swift.common import fs_utils as fs
|
||||||
from swiftonfile.swift.common.exceptions import NotDirectoryError, \
|
from swiftonfile.swift.common.exceptions import SwiftOnFileSystemOSError
|
||||||
FileOrDirNotFoundError, SwiftOnFileSystemOSError
|
|
||||||
from swift.common.exceptions import DiskFileNoSpace
|
from swift.common.exceptions import DiskFileNoSpace
|
||||||
|
|
||||||
|
|
||||||
@ -270,70 +269,6 @@ class TestFsUtils(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
self.fail("Expected DiskFileNoSpace exception")
|
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):
|
def test_do_mkdir(self):
|
||||||
try:
|
try:
|
||||||
path = os.path.join('/tmp', str(random.random()))
|
path = os.path.join('/tmp', str(random.random()))
|
||||||
@ -369,26 +304,6 @@ class TestFsUtils(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
self.fail("Expected OSError with errno.EDQUOT exception")
|
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):
|
def test_do_fstat(self):
|
||||||
tmpdir = mkdtemp()
|
tmpdir = mkdtemp()
|
||||||
try:
|
try:
|
||||||
@ -556,48 +471,6 @@ class TestFsUtils(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
self.fail("SwiftOnFileSystemOSError expected")
|
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):
|
def test_do_rmdir(self):
|
||||||
tmpdir = mkdtemp()
|
tmpdir = mkdtemp()
|
||||||
try:
|
try:
|
||||||
|
@ -165,7 +165,6 @@ class TestDiskFile(unittest.TestCase):
|
|||||||
assert gdf._datadir == gdf._put_datadir
|
assert gdf._datadir == gdf._put_datadir
|
||||||
assert gdf._data_file == os.path.join(self.td, "vol0", "ufo47", "bar", "z")
|
assert gdf._data_file == os.path.join(self.td, "vol0", "ufo47", "bar", "z")
|
||||||
assert gdf._is_dir is False
|
assert gdf._is_dir is False
|
||||||
assert gdf._logger == self.lg
|
|
||||||
assert gdf._fd is None
|
assert gdf._fd is None
|
||||||
|
|
||||||
def test_constructor_leadtrail_slash(self):
|
def test_constructor_leadtrail_slash(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user