From b1f51d00cde51a77aacbe41401cde0b3b9e35719 Mon Sep 17 00:00:00 2001 From: Peter Portante Date: Wed, 13 Nov 2013 11:16:59 -0500 Subject: [PATCH] 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 --- swift/account/reaper.py | 5 +++-- swift/common/db_replicator.py | 7 +++---- swift/common/utils.py | 3 +-- swift/container/updater.py | 5 +++-- swift/obj/diskfile.py | 4 ++-- swift/obj/replicator.py | 6 +++--- swift/obj/updater.py | 6 +++--- test/probe/common.py | 4 ++-- test/unit/account/test_reaper.py | 4 ++-- test/unit/common/test_db.py | 13 ++++--------- test/unit/obj/test_diskfile.py | 2 +- 11 files changed, 27 insertions(+), 32 deletions(-) diff --git a/swift/account/reaper.py b/swift/account/reaper.py index 544dcb52..ff39f075 100644 --- a/swift/account/reaper.py +++ b/swift/account/reaper.py @@ -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( diff --git a/swift/common/db_replicator.py b/swift/common/db_replicator.py index 3481cba4..0ba8877f 100644 --- a/swift/common/db_replicator.py +++ b/swift/common/db_replicator.py @@ -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), diff --git a/swift/common/utils.py b/swift/common/utils.py index c52d682f..6456e418 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -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) diff --git a/swift/container/updater.py b/swift/container/updater.py index 96c35a0c..4c8d8f77 100644 --- a/swift/container/updater.py +++ b/swift/container/updater.py @@ -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) diff --git a/swift/obj/diskfile.py b/swift/obj/diskfile.py index d1944607..09c7d2f5 100644 --- a/swift/obj/diskfile.py +++ b/swift/obj/diskfile.py @@ -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) diff --git a/swift/obj/replicator.py b/swift/obj/replicator.py index 01b7a29b..9da5b843 100644 --- a/swift/obj/replicator.py +++ b/swift/obj/replicator.py @@ -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(): diff --git a/swift/obj/updater.py b/swift/obj/updater.py index af4eab4d..1592088c 100644 --- a/swift/obj/updater.py +++ b/swift/obj/updater.py @@ -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) diff --git a/test/probe/common.py b/test/probe/common.py index 4a23f80b..9c0f3bd9 100644 --- a/test/probe/common.py +++ b/test/probe/common.py @@ -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 diff --git a/test/unit/account/test_reaper.py b/test/unit/account/test_reaper.py index ee0700eb..10438218 100644 --- a/test/unit/account/test_reaper.py +++ b/test/unit/account/test_reaper.py @@ -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() diff --git a/test/unit/common/test_db.py b/test/unit/common/test_db.py index d944c30a..9af8e971 100644 --- a/test/unit/common/test_db.py +++ b/test/unit/common/test_db.py @@ -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): diff --git a/test/unit/obj/test_diskfile.py b/test/unit/obj/test_diskfile.py index e5275691..cf99530b 100644 --- a/test/unit/obj/test_diskfile.py +++ b/test/unit/obj/test_diskfile.py @@ -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",