2013-10-12 08:28:27 +00:00
|
|
|
"""
|
|
|
|
Mount/unmount a ``kernel`` client.
|
|
|
|
"""
|
2011-06-16 01:07:18 +00:00
|
|
|
import contextlib
|
|
|
|
import logging
|
|
|
|
|
2014-10-28 17:06:56 +00:00
|
|
|
from teuthology.misc import deep_merge
|
2017-02-01 00:25:44 +00:00
|
|
|
from teuthology.orchestra.run import CommandFailedError
|
2014-07-02 15:43:16 +00:00
|
|
|
from teuthology import misc
|
2017-02-01 00:25:44 +00:00
|
|
|
from teuthology.contextutil import MaxWhileTries
|
2014-08-07 14:24:59 +00:00
|
|
|
from cephfs.kernel_mount import KernelMount
|
2011-06-16 01:07:18 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def task(ctx, config):
|
|
|
|
"""
|
|
|
|
Mount/unmount a ``kernel`` client.
|
|
|
|
|
2011-06-16 23:07:59 +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
|
2011-09-23 15:57:18 +00:00
|
|
|
``ceph-fuse`` and another with ``kclient``.
|
2011-06-16 01:07:18 +00:00
|
|
|
|
2011-06-16 23:51:57 +00:00
|
|
|
Example that mounts all clients::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- kclient:
|
|
|
|
- interactive:
|
|
|
|
|
2012-10-09 00:08:41 +00:00
|
|
|
Example that uses both ``kclient` and ``ceph-fuse``::
|
2011-06-16 23:51:57 +00:00
|
|
|
|
2011-06-16 01:07:18 +00:00
|
|
|
tasks:
|
|
|
|
- ceph:
|
2012-10-09 00:08:41 +00:00
|
|
|
- ceph-fuse: [client.0]
|
2011-06-16 01:07:18 +00:00
|
|
|
- kclient: [client.1]
|
|
|
|
- interactive:
|
2013-10-12 08:28:27 +00:00
|
|
|
|
2014-10-28 17:06:56 +00:00
|
|
|
|
|
|
|
Pass a dictionary instead of lists to specify per-client config:
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
-kclient:
|
|
|
|
client.0:
|
|
|
|
debug: true
|
|
|
|
|
2013-10-12 08:28:27 +00:00
|
|
|
:param ctx: Context
|
|
|
|
:param config: Configuration
|
2011-06-16 01:07:18 +00:00
|
|
|
"""
|
|
|
|
log.info('Mounting kernel clients...')
|
2014-10-28 17:06:56 +00:00
|
|
|
assert config is None or isinstance(config, list) or isinstance(config, dict), \
|
2011-06-16 23:07:59 +00:00
|
|
|
"task kclient got invalid config"
|
2011-06-16 01:07:18 +00:00
|
|
|
|
2011-06-16 23:07:59 +00:00
|
|
|
if config is None:
|
|
|
|
config = ['client.{id}'.format(id=id_)
|
2014-07-02 15:43:16 +00:00
|
|
|
for id_ in misc.all_roles_of_type(ctx.cluster, 'client')]
|
2014-10-28 17:06:56 +00:00
|
|
|
|
|
|
|
if isinstance(config, list):
|
|
|
|
client_roles = config
|
|
|
|
config = dict([r, dict()] for r in client_roles)
|
|
|
|
elif isinstance(config, dict):
|
2016-12-02 00:27:27 +00:00
|
|
|
client_roles = filter(lambda x: 'client.' in x, config.keys())
|
2014-10-28 17:06:56 +00:00
|
|
|
else:
|
|
|
|
raise ValueError("Invalid config object: {0} ({1})".format(config, config.__class__))
|
|
|
|
|
|
|
|
# config has been converted to a dict by this point
|
|
|
|
overrides = ctx.config.get('overrides', {})
|
|
|
|
deep_merge(config, overrides.get('kclient', {}))
|
|
|
|
|
|
|
|
clients = list(misc.get_clients(ctx=ctx, roles=client_roles))
|
2011-06-16 23:07:59 +00:00
|
|
|
|
2014-07-02 15:43:16 +00:00
|
|
|
test_dir = misc.get_testdir(ctx)
|
2013-01-23 20:37:39 +00:00
|
|
|
|
2014-07-02 15:43:16 +00:00
|
|
|
# Assemble mon addresses
|
|
|
|
remotes_and_roles = ctx.cluster.remotes.items()
|
|
|
|
roles = [roles for (remote_, roles) in remotes_and_roles]
|
2014-07-14 12:36:21 +00:00
|
|
|
ips = [remote_.ssh.get_transport().getpeername()[0]
|
|
|
|
for (remote_, _) in remotes_and_roles]
|
2014-07-02 15:43:16 +00:00
|
|
|
mons = misc.get_mons(roles, ips).values()
|
2011-08-04 22:03:05 +00:00
|
|
|
|
2014-07-02 15:43:16 +00:00
|
|
|
mounts = {}
|
|
|
|
for id_, remote in clients:
|
2016-12-02 00:27:27 +00:00
|
|
|
client_config = config.get("client.%s" % id_)
|
|
|
|
if client_config is None:
|
|
|
|
client_config = {}
|
|
|
|
|
|
|
|
if config.get("disabled", False) or not client_config.get('mounted', True):
|
|
|
|
continue
|
|
|
|
|
2014-09-15 22:41:34 +00:00
|
|
|
kernel_mount = KernelMount(
|
|
|
|
mons,
|
|
|
|
test_dir,
|
|
|
|
id_,
|
|
|
|
remote,
|
|
|
|
ctx.teuthology_config.get('ipmi_user', None),
|
|
|
|
ctx.teuthology_config.get('ipmi_password', None),
|
|
|
|
ctx.teuthology_config.get('ipmi_domain', None)
|
|
|
|
)
|
|
|
|
|
2014-07-02 15:43:16 +00:00
|
|
|
mounts[id_] = kernel_mount
|
2011-06-16 01:07:18 +00:00
|
|
|
|
2014-10-28 17:06:56 +00:00
|
|
|
if client_config.get('debug', False):
|
|
|
|
remote.run(args=["sudo", "bash", "-c", "echo 'module ceph +p' > /sys/kernel/debug/dynamic_debug/control"])
|
|
|
|
remote.run(args=["sudo", "bash", "-c", "echo 'module libceph +p' > /sys/kernel/debug/dynamic_debug/control"])
|
|
|
|
|
2014-07-02 15:43:16 +00:00
|
|
|
kernel_mount.mount()
|
2011-06-16 01:07:18 +00:00
|
|
|
|
2017-01-25 12:23:37 +00:00
|
|
|
|
|
|
|
def umount_all():
|
|
|
|
log.info('Unmounting kernel clients...')
|
|
|
|
|
|
|
|
forced = False
|
|
|
|
for mount in mounts.values():
|
|
|
|
if mount.is_mounted():
|
|
|
|
try:
|
|
|
|
mount.umount()
|
2017-02-01 00:25:44 +00:00
|
|
|
except (CommandFailedError, MaxWhileTries):
|
2017-01-25 12:23:37 +00:00
|
|
|
log.warn("Ordinary umount failed, forcing...")
|
|
|
|
forced = True
|
|
|
|
mount.umount_wait(force=True)
|
|
|
|
|
|
|
|
return forced
|
|
|
|
|
2014-07-02 15:43:16 +00:00
|
|
|
ctx.mounts = mounts
|
2011-06-16 01:07:18 +00:00
|
|
|
try:
|
2014-07-02 15:43:16 +00:00
|
|
|
yield mounts
|
2017-01-25 12:23:37 +00:00
|
|
|
except:
|
|
|
|
umount_all() # ignore forced retval, we are already in error handling
|
2011-06-16 01:07:18 +00:00
|
|
|
finally:
|
2017-01-25 12:23:37 +00:00
|
|
|
|
|
|
|
forced = umount_all()
|
|
|
|
if forced:
|
|
|
|
# The context managers within the kclient manager worked (i.e.
|
|
|
|
# the test workload passed) but for some reason we couldn't
|
|
|
|
# umount, so turn this into a test failure.
|
|
|
|
raise RuntimeError("Kernel mounts did not umount cleanly")
|