Use utils.ismount in place of os.path.ismount

See comments from: https://review.openstack.org/55991

Change-Id: Ibb4153702b3dc4c60f66abb11cd3fa1953449827
Signed-off-by: Peter Portante <peter.portante@redhat.com>
This commit is contained in:
Peter Portante 2013-11-13 11:16:59 -05:00
parent 8255810e7d
commit b1f51d00cd
11 changed files with 27 additions and 32 deletions

View File

@ -28,7 +28,8 @@ from swift.account.backend import AccountBroker
from swift.common.direct_client import ClientException, \
direct_delete_container, direct_delete_object, direct_get_container
from swift.common.ring import Ring
from swift.common.utils import get_logger, whataremyips, config_true_value
from swift.common.utils import get_logger, whataremyips, ismount, \
config_true_value
from swift.common.daemon import Daemon
@ -120,7 +121,7 @@ class AccountReaper(Daemon):
begin = time()
try:
for device in os.listdir(self.devices):
if self.mount_check and not os.path.ismount(
if self.mount_check and not ismount(
os.path.join(self.devices, device)):
self.logger.increment('errors')
self.logger.debug(

View File

@ -32,7 +32,7 @@ import swift.common.db
from swift.common.direct_client import quote
from swift.common.utils import get_logger, whataremyips, storage_directory, \
renamer, mkdirs, lock_parent_directory, config_true_value, \
unlink_older_than, dump_recon_cache, rsync_ip
unlink_older_than, dump_recon_cache, rsync_ip, ismount
from swift.common import ring
from swift.common.http import HTTP_NOT_FOUND, HTTP_INSUFFICIENT_STORAGE
from swift.common.bufferedhttp import BufferedHTTPConnection
@ -529,7 +529,7 @@ class Replicator(Daemon):
for node in self.ring.devs:
if (node and node['replication_ip'] in ips and
node['replication_port'] == self.port):
if self.mount_check and not os.path.ismount(
if self.mount_check and not ismount(
os.path.join(self.root, node['device'])):
self.logger.warn(
_('Skipping %(device)s as it is not mounted') % node)
@ -580,8 +580,7 @@ class ReplicatorRpc(object):
return HTTPBadRequest(body='Invalid object type')
op = args.pop(0)
drive, partition, hsh = replicate_args
if self.mount_check and \
not os.path.ismount(os.path.join(self.root, drive)):
if self.mount_check and not ismount(os.path.join(self.root, drive)):
return Response(status='507 %s is not mounted' % drive)
db_file = os.path.join(self.root, drive,
storage_directory(self.datadir, partition, hsh),

View File

@ -1511,8 +1511,7 @@ def audit_location_generator(devices, datadir, suffix='',
# randomize devices in case of process restart before sweep completed
shuffle(device_dir)
for device in device_dir:
if mount_check and not \
os.path.ismount(os.path.join(devices, device)):
if mount_check and not ismount(os.path.join(devices, device)):
if logger:
logger.debug(
_('Skipping %s as it is not mounted'), device)

View File

@ -30,7 +30,8 @@ from swift.container.server import DATADIR
from swift.common.bufferedhttp import http_connect
from swift.common.exceptions import ConnectionTimeout
from swift.common.ring import Ring
from swift.common.utils import get_logger, config_true_value, dump_recon_cache
from swift.common.utils import get_logger, config_true_value, ismount, \
dump_recon_cache
from swift.common.daemon import Daemon
from swift.common.http import is_success, HTTP_INTERNAL_SERVER_ERROR
@ -79,7 +80,7 @@ class ContainerUpdater(Daemon):
paths = []
for device in os.listdir(self.devices):
dev_path = os.path.join(self.devices, device)
if self.mount_check and not os.path.ismount(dev_path):
if self.mount_check and not ismount(dev_path):
self.logger.warn(_('%s is not mounted'), device)
continue
con_path = os.path.join(dev_path, DATADIR)

View File

@ -53,7 +53,7 @@ from swift.common.constraints import check_mount
from swift.common.utils import mkdirs, normalize_timestamp, \
storage_directory, hash_path, renamer, fallocate, fsync, \
fdatasync, drop_buffer_cache, ThreadPool, lock_path, write_pickle, \
config_true_value, listdir, split_path
config_true_value, listdir, split_path, ismount
from swift.common.exceptions import DiskFileQuarantined, DiskFileNotExist, \
DiskFileCollision, DiskFileNoSpace, DiskFileDeviceUnavailable, \
DiskFileDeleted, DiskFileError, DiskFileNotOpen, PathNotDir
@ -324,7 +324,7 @@ def object_audit_location_generator(devices, mount_check=True, logger=None):
shuffle(device_dirs)
for device in device_dirs:
if mount_check and not \
os.path.ismount(os.path.join(devices, device)):
ismount(os.path.join(devices, device)):
if logger:
logger.debug(
_('Skipping %s as it is not mounted'), device)

View File

@ -29,7 +29,7 @@ from eventlet.support.greenlets import GreenletExit
from swift.common.ring import Ring
from swift.common.utils import whataremyips, unlink_older_than, \
compute_eta, get_logger, dump_recon_cache, \
compute_eta, get_logger, dump_recon_cache, ismount, \
rsync_ip, mkdirs, config_true_value, list_from_csv, get_hub, \
tpool_reraise, config_auto_int_value
from swift.common.bufferedhttp import http_connect
@ -407,7 +407,7 @@ class ObjectReplicator(Daemon):
dev_path = join(self.devices_dir, local_dev['device'])
obj_path = join(dev_path, 'objects')
tmp_path = join(dev_path, 'tmp')
if self.mount_check and not os.path.ismount(dev_path):
if self.mount_check and not ismount(dev_path):
self.logger.warn(_('%s is not mounted'), local_dev['device'])
continue
unlink_older_than(tmp_path, time.time() - self.reclaim_age)
@ -475,7 +475,7 @@ class ObjectReplicator(Daemon):
job['partition'] not in override_partitions:
continue
dev_path = join(self.devices_dir, job['device'])
if self.mount_check and not os.path.ismount(dev_path):
if self.mount_check and not ismount(dev_path):
self.logger.warn(_('%s is not mounted'), job['device'])
continue
if not self.check_ring():

View File

@ -27,7 +27,7 @@ from swift.common.bufferedhttp import http_connect
from swift.common.exceptions import ConnectionTimeout
from swift.common.ring import Ring
from swift.common.utils import get_logger, renamer, write_pickle, \
dump_recon_cache, config_true_value
dump_recon_cache, config_true_value, ismount
from swift.common.daemon import Daemon
from swift.obj.diskfile import ASYNCDIR
from swift.common.http import is_success, HTTP_NOT_FOUND, \
@ -72,7 +72,7 @@ class ObjectUpdater(Daemon):
self.get_container_ring().get_nodes('')
for device in os.listdir(self.devices):
if self.mount_check and not \
os.path.ismount(os.path.join(self.devices, device)):
ismount(os.path.join(self.devices, device)):
self.logger.increment('errors')
self.logger.warn(
_('Skipping %s as it is not mounted'), device)
@ -115,7 +115,7 @@ class ObjectUpdater(Daemon):
self.failures = 0
for device in os.listdir(self.devices):
if self.mount_check and \
not os.path.ismount(os.path.join(self.devices, device)):
ismount(os.path.join(self.devices, device)):
self.logger.increment('errors')
self.logger.warn(
_('Skipping %s as it is not mounted'), device)

View File

@ -24,7 +24,7 @@ from time import sleep, time
from swiftclient import get_auth, head_account
from swift.common.ring import Ring
from swift.common.utils import readconf
from swift.common.utils import readconf, ismount
from test.probe import CHECK_SERVER_TIMEOUT, VALIDATE_RSYNC
@ -154,7 +154,7 @@ def get_ring(server, force_validate=None):
for device in os.listdir(conf['devices']):
if device == dev['device']:
full_path = path.realpath(path.join(conf['devices'], device))
assert path.ismount(full_path), \
assert ismount(full_path), \
'device %s in %s was not mounted (%s)' % (
device, conf['devices'], full_path)
break

View File

@ -448,13 +448,13 @@ class TestReaper(unittest.TestCase):
devices = prepare_data_dir()
r = init_reaper(devices)
with patch('swift.account.reaper.os.path.ismount', lambda x: True):
with patch('swift.account.reaper.ismount', lambda x: True):
with patch(
'swift.account.reaper.AccountReaper.reap_device') as foo:
r.run_once()
self.assertEqual(foo.called, 1)
with patch('swift.account.reaper.os.path.ismount', lambda x: False):
with patch('swift.account.reaper.ismount', lambda x: False):
with patch(
'swift.account.reaper.AccountReaper.reap_device') as foo:
r.run_once()

View File

@ -166,15 +166,10 @@ class TestDatabaseBroker(unittest.TestCase):
with broker.get() as conn:
conn.execute('SELECT * FROM outgoing_sync')
conn.execute('SELECT * FROM incoming_sync')
def my_ismount(*a, **kw):
return True
with patch('os.path.ismount', my_ismount):
broker = DatabaseBroker(os.path.join(self.testdir, '1.db'))
broker._initialize = stub
self.assertRaises(DatabaseAlreadyExists,
broker.initialize, normalize_timestamp('1'))
broker = DatabaseBroker(os.path.join(self.testdir, '1.db'))
broker._initialize = stub
self.assertRaises(DatabaseAlreadyExists,
broker.initialize, normalize_timestamp('1'))
def test_delete_db(self):
def init_stub(conn, put_timestamp):

View File

@ -414,7 +414,7 @@ class TestObjectAuditLocationGenerator(unittest.TestCase):
def mock_ismount(path):
return path.endswith('sdp')
with mock.patch('os.path.ismount', mock_ismount):
with mock.patch('swift.obj.diskfile.ismount', mock_ismount):
with temptree([]) as tmpdir:
os.makedirs(os.path.join(tmpdir, "sdp", "objects",
"2607", "df3",