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
|
2019-12-16 01:50:09 +00:00
|
|
|
from tasks.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
|
|
|
|
2020-03-03 13:31:29 +00:00
|
|
|
``brxnet`` should be a Private IPv4 Address range, default range is
|
|
|
|
[192.168.0.0/16]
|
|
|
|
|
2011-06-16 23:51:57 +00:00
|
|
|
Example that mounts all clients::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- kclient:
|
|
|
|
- interactive:
|
2020-03-03 13:31:29 +00:00
|
|
|
- brxnet: [192.168.0.0/16]
|
2011-06-16 23:51:57 +00:00
|
|
|
|
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
|
|
|
|
2020-05-28 04:58:13 +00:00
|
|
|
for id_, remote in clients:
|
|
|
|
KernelMount.cleanup_stale_netnses_and_bridge(remote)
|
|
|
|
|
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(
|
2018-07-12 13:25:53 +00:00
|
|
|
ctx,
|
2014-09-15 22:41:34 +00:00
|
|
|
test_dir,
|
|
|
|
id_,
|
|
|
|
remote,
|
2020-03-03 13:31:29 +00:00
|
|
|
ctx.teuthology_config.get('brxnet', None),
|
2014-09-15 22:41:34 +00:00
|
|
|
)
|
|
|
|
|
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):
|
2020-05-13 23:16:17 +00:00
|
|
|
log.warning("Ordinary umount failed, forcing...")
|
2017-01-25 12:23:37 +00:00
|
|
|
forced = True
|
|
|
|
mount.umount_wait(force=True)
|
|
|
|
|
2020-07-06 12:27:34 +00:00
|
|
|
for id_, remote in clients:
|
|
|
|
KernelMount.cleanup_stale_netnses_and_bridge(remote)
|
|
|
|
|
2017-01-25 12:23:37 +00:00
|
|
|
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")
|