ceph/qa/tasks/ceph_fuse.py

156 lines
4.6 KiB
Python
Raw Normal View History

"""
Ceph FUSE client task
"""
2011-06-02 22:04:01 +00:00
import contextlib
import logging
from teuthology import misc as teuthology
from cephfs.fuse_mount import FuseMount
from tasks.cephfs.filesystem import Filesystem
2011-06-02 22:04:01 +00:00
log = logging.getLogger(__name__)
def get_client_configs(ctx, config):
"""
Get a map of the configuration for each FUSE client in the configuration by
combining the configuration of the current task with any global overrides.
:param ctx: Context instance
:param config: configuration for this task
:return: dict of client name to config or to None
"""
if config is None:
config = dict(('client.{id}'.format(id=id_), None)
for id_ in teuthology.all_roles_of_type(ctx.cluster, 'client'))
elif isinstance(config, list):
config = dict((name, None) for name in config)
overrides = ctx.config.get('overrides', {})
teuthology.deep_merge(config, overrides.get('ceph-fuse', {}))
return config
2011-06-02 22:04:01 +00:00
@contextlib.contextmanager
def task(ctx, config):
2011-06-06 21:22:49 +00:00
"""
Mount/unmount a ``ceph-fuse`` client.
2011-06-06 21:22:49 +00:00
The config is optional and defaults to mounting on all clients. If
a config is given, it is expected to be a list of clients to do
this operation on. This lets you e.g. set up one client with
``ceph-fuse`` and another with ``kclient``.
Example that mounts all clients::
tasks:
- ceph:
2012-02-20 15:12:53 +00:00
- ceph-fuse:
- interactive:
2012-02-20 15:12:53 +00:00
Example that uses both ``kclient` and ``ceph-fuse``::
2011-06-06 21:22:49 +00:00
tasks:
- ceph:
2012-02-20 15:12:53 +00:00
- ceph-fuse: [client.0]
- kclient: [client.1]
2011-06-06 21:22:49 +00:00
- interactive:
Example that enables valgrind:
tasks:
- ceph:
2012-02-20 15:12:53 +00:00
- ceph-fuse:
client.0:
valgrind: [--tool=memcheck, --leak-check=full, --show-reachable=yes]
- interactive:
Example that stops an already-mounted client:
::
tasks:
- ceph:
- ceph-fuse: [client.0]
- ... do something that requires the FS mounted ...
- ceph-fuse:
client.0:
mounted: false
- ... do something that requires the FS unmounted ...
Example that adds more generous wait time for mount (for virtual machines):
tasks:
- ceph:
- ceph-fuse:
client.0:
mount_wait: 60 # default is 0, do not wait before checking /sys/
mount_timeout: 120 # default is 30, give up if /sys/ is not populated
- interactive:
:param ctx: Context
:param config: Configuration
2011-06-06 21:22:49 +00:00
"""
log.info('Running ceph_fuse task...')
2011-06-02 22:04:01 +00:00
testdir = teuthology.get_testdir(ctx)
log.info("config is {}".format(str(config)))
config = get_client_configs(ctx, config)
log.info("new config is {}".format(str(config)))
# List clients we will configure mounts for, default is all clients
clients = list(teuthology.get_clients(ctx=ctx, roles=filter(lambda x: 'client.' in x, config.keys())))
all_mounts = getattr(ctx, 'mounts', {})
mounted_by_me = {}
skipped = {}
# Construct any new FuseMount instances
for id_, remote in clients:
client_config = config.get("client.%s" % id_)
if client_config is None:
client_config = {}
2011-06-02 22:04:01 +00:00
skip = client_config.get("skip", False)
if skip:
skipped[id_] = skip
continue
if id_ not in all_mounts:
fuse_mount = FuseMount(ctx, client_config, testdir, id_, remote)
all_mounts[id_] = fuse_mount
else:
# Catch bad configs where someone has e.g. tried to use ceph-fuse and kcephfs for the same client
assert isinstance(all_mounts[id_], FuseMount)
if not config.get("disabled", False) and client_config.get('mounted', True):
mounted_by_me[id_] = all_mounts[id_]
ctx.mounts = all_mounts
# Mount any clients we have been asked to (default to mount all)
log.info('Mounting ceph-fuse clients...')
for mount in mounted_by_me.values():
mount.mount()
for mount in mounted_by_me.values():
mount.wait_until_mounted()
2011-06-02 22:04:01 +00:00
# Umount any pre-existing clients that we have not been asked to mount
for client_id in set(all_mounts.keys()) - set(mounted_by_me.keys()) - set(skipped.keys()):
mount = all_mounts[client_id]
if mount.is_mounted():
mount.umount_wait()
2011-06-02 22:04:01 +00:00
try:
yield all_mounts
2011-06-02 22:04:01 +00:00
finally:
log.info('Unmounting ceph-fuse clients...')
for mount in mounted_by_me.values():
# Conditional because an inner context might have umounted it
if mount.is_mounted():
mount.umount_wait()