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, \ from swift.common.direct_client import ClientException, \
direct_delete_container, direct_delete_object, direct_get_container direct_delete_container, direct_delete_object, direct_get_container
from swift.common.ring import Ring 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 from swift.common.daemon import Daemon
@ -120,7 +121,7 @@ class AccountReaper(Daemon):
begin = time() begin = time()
try: try:
for device in os.listdir(self.devices): 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)): os.path.join(self.devices, device)):
self.logger.increment('errors') self.logger.increment('errors')
self.logger.debug( self.logger.debug(

View File

@ -32,7 +32,7 @@ import swift.common.db
from swift.common.direct_client import quote from swift.common.direct_client import quote
from swift.common.utils import get_logger, whataremyips, storage_directory, \ from swift.common.utils import get_logger, whataremyips, storage_directory, \
renamer, mkdirs, lock_parent_directory, config_true_value, \ 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 import ring
from swift.common.http import HTTP_NOT_FOUND, HTTP_INSUFFICIENT_STORAGE from swift.common.http import HTTP_NOT_FOUND, HTTP_INSUFFICIENT_STORAGE
from swift.common.bufferedhttp import BufferedHTTPConnection from swift.common.bufferedhttp import BufferedHTTPConnection
@ -529,7 +529,7 @@ class Replicator(Daemon):
for node in self.ring.devs: for node in self.ring.devs:
if (node and node['replication_ip'] in ips and if (node and node['replication_ip'] in ips and
node['replication_port'] == self.port): 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'])): os.path.join(self.root, node['device'])):
self.logger.warn( self.logger.warn(
_('Skipping %(device)s as it is not mounted') % node) _('Skipping %(device)s as it is not mounted') % node)
@ -580,8 +580,7 @@ class ReplicatorRpc(object):
return HTTPBadRequest(body='Invalid object type') return HTTPBadRequest(body='Invalid object type')
op = args.pop(0) op = args.pop(0)
drive, partition, hsh = replicate_args drive, partition, hsh = replicate_args
if self.mount_check and \ if self.mount_check and not ismount(os.path.join(self.root, drive)):
not os.path.ismount(os.path.join(self.root, drive)):
return Response(status='507 %s is not mounted' % drive) return Response(status='507 %s is not mounted' % drive)
db_file = os.path.join(self.root, drive, db_file = os.path.join(self.root, drive,
storage_directory(self.datadir, partition, hsh), 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 # randomize devices in case of process restart before sweep completed
shuffle(device_dir) shuffle(device_dir)
for device in device_dir: for device in device_dir:
if mount_check and not \ if mount_check and not ismount(os.path.join(devices, device)):
os.path.ismount(os.path.join(devices, device)):
if logger: if logger:
logger.debug( logger.debug(
_('Skipping %s as it is not mounted'), device) _('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.bufferedhttp import http_connect
from swift.common.exceptions import ConnectionTimeout from swift.common.exceptions import ConnectionTimeout
from swift.common.ring import Ring 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.daemon import Daemon
from swift.common.http import is_success, HTTP_INTERNAL_SERVER_ERROR from swift.common.http import is_success, HTTP_INTERNAL_SERVER_ERROR
@ -79,7 +80,7 @@ class ContainerUpdater(Daemon):
paths = [] paths = []
for device in os.listdir(self.devices): for device in os.listdir(self.devices):
dev_path = os.path.join(self.devices, device) 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) self.logger.warn(_('%s is not mounted'), device)
continue continue
con_path = os.path.join(dev_path, DATADIR) 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, \ from swift.common.utils import mkdirs, normalize_timestamp, \
storage_directory, hash_path, renamer, fallocate, fsync, \ storage_directory, hash_path, renamer, fallocate, fsync, \
fdatasync, drop_buffer_cache, ThreadPool, lock_path, write_pickle, \ 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, \ from swift.common.exceptions import DiskFileQuarantined, DiskFileNotExist, \
DiskFileCollision, DiskFileNoSpace, DiskFileDeviceUnavailable, \ DiskFileCollision, DiskFileNoSpace, DiskFileDeviceUnavailable, \
DiskFileDeleted, DiskFileError, DiskFileNotOpen, PathNotDir DiskFileDeleted, DiskFileError, DiskFileNotOpen, PathNotDir
@ -324,7 +324,7 @@ def object_audit_location_generator(devices, mount_check=True, logger=None):
shuffle(device_dirs) shuffle(device_dirs)
for device in device_dirs: for device in device_dirs:
if mount_check and not \ if mount_check and not \
os.path.ismount(os.path.join(devices, device)): ismount(os.path.join(devices, device)):
if logger: if logger:
logger.debug( logger.debug(
_('Skipping %s as it is not mounted'), device) _('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.ring import Ring
from swift.common.utils import whataremyips, unlink_older_than, \ 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, \ rsync_ip, mkdirs, config_true_value, list_from_csv, get_hub, \
tpool_reraise, config_auto_int_value tpool_reraise, config_auto_int_value
from swift.common.bufferedhttp import http_connect from swift.common.bufferedhttp import http_connect
@ -407,7 +407,7 @@ class ObjectReplicator(Daemon):
dev_path = join(self.devices_dir, local_dev['device']) dev_path = join(self.devices_dir, local_dev['device'])
obj_path = join(dev_path, 'objects') obj_path = join(dev_path, 'objects')
tmp_path = join(dev_path, 'tmp') 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']) self.logger.warn(_('%s is not mounted'), local_dev['device'])
continue continue
unlink_older_than(tmp_path, time.time() - self.reclaim_age) unlink_older_than(tmp_path, time.time() - self.reclaim_age)
@ -475,7 +475,7 @@ class ObjectReplicator(Daemon):
job['partition'] not in override_partitions: job['partition'] not in override_partitions:
continue continue
dev_path = join(self.devices_dir, job['device']) 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']) self.logger.warn(_('%s is not mounted'), job['device'])
continue continue
if not self.check_ring(): 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.exceptions import ConnectionTimeout
from swift.common.ring import Ring from swift.common.ring import Ring
from swift.common.utils import get_logger, renamer, write_pickle, \ 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.common.daemon import Daemon
from swift.obj.diskfile import ASYNCDIR from swift.obj.diskfile import ASYNCDIR
from swift.common.http import is_success, HTTP_NOT_FOUND, \ from swift.common.http import is_success, HTTP_NOT_FOUND, \
@ -72,7 +72,7 @@ class ObjectUpdater(Daemon):
self.get_container_ring().get_nodes('') self.get_container_ring().get_nodes('')
for device in os.listdir(self.devices): for device in os.listdir(self.devices):
if self.mount_check and not \ 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.increment('errors')
self.logger.warn( self.logger.warn(
_('Skipping %s as it is not mounted'), device) _('Skipping %s as it is not mounted'), device)
@ -115,7 +115,7 @@ class ObjectUpdater(Daemon):
self.failures = 0 self.failures = 0
for device in os.listdir(self.devices): for device in os.listdir(self.devices):
if self.mount_check and \ 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.increment('errors')
self.logger.warn( self.logger.warn(
_('Skipping %s as it is not mounted'), device) _('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 swiftclient import get_auth, head_account
from swift.common.ring import Ring 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 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']): for device in os.listdir(conf['devices']):
if device == dev['device']: if device == dev['device']:
full_path = path.realpath(path.join(conf['devices'], 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 %s in %s was not mounted (%s)' % (
device, conf['devices'], full_path) device, conf['devices'], full_path)
break break

View File

@ -448,13 +448,13 @@ class TestReaper(unittest.TestCase):
devices = prepare_data_dir() devices = prepare_data_dir()
r = init_reaper(devices) 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( with patch(
'swift.account.reaper.AccountReaper.reap_device') as foo: 'swift.account.reaper.AccountReaper.reap_device') as foo:
r.run_once() r.run_once()
self.assertEqual(foo.called, 1) 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( with patch(
'swift.account.reaper.AccountReaper.reap_device') as foo: 'swift.account.reaper.AccountReaper.reap_device') as foo:
r.run_once() r.run_once()

View File

@ -166,11 +166,6 @@ class TestDatabaseBroker(unittest.TestCase):
with broker.get() as conn: with broker.get() as conn:
conn.execute('SELECT * FROM outgoing_sync') conn.execute('SELECT * FROM outgoing_sync')
conn.execute('SELECT * FROM incoming_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 = DatabaseBroker(os.path.join(self.testdir, '1.db'))
broker._initialize = stub broker._initialize = stub
self.assertRaises(DatabaseAlreadyExists, self.assertRaises(DatabaseAlreadyExists,

View File

@ -414,7 +414,7 @@ class TestObjectAuditLocationGenerator(unittest.TestCase):
def mock_ismount(path): def mock_ismount(path):
return path.endswith('sdp') 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: with temptree([]) as tmpdir:
os.makedirs(os.path.join(tmpdir, "sdp", "objects", os.makedirs(os.path.join(tmpdir, "sdp", "objects",
"2607", "df3", "2607", "df3",