]> git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/kclient.py
bump version to 18.2.2-pve1
[ceph.git] / ceph / qa / tasks / kclient.py
1 """
2 Mount/unmount a ``kernel`` client.
3 """
4 import contextlib
5 import logging
6
7 from teuthology.misc import deep_merge
8 from teuthology.exceptions import CommandFailedError
9 from teuthology import misc
10 from teuthology.contextutil import MaxWhileTries
11 from tasks.cephfs.kernel_mount import KernelMount
12
13 log = logging.getLogger(__name__)
14
15 @contextlib.contextmanager
16 def task(ctx, config):
17 """
18 Mount/unmount a ``kernel`` client.
19
20 The config is optional and defaults to mounting on all clients. If
21 a config is given, it is expected to be a list of clients to do
22 this operation on. This lets you e.g. set up one client with
23 ``ceph-fuse`` and another with ``kclient``.
24
25 ``brxnet`` should be a Private IPv4 Address range, default range is
26 [192.168.0.0/16]
27
28 Example that mounts all clients::
29
30 tasks:
31 - ceph:
32 - kclient:
33 - interactive:
34 - brxnet: [192.168.0.0/16]
35
36 Example that uses both ``kclient` and ``ceph-fuse``::
37
38 tasks:
39 - ceph:
40 - ceph-fuse: [client.0]
41 - kclient: [client.1]
42 - interactive:
43
44
45 Pass a dictionary instead of lists to specify per-client config:
46
47 tasks:
48 -kclient:
49 client.0:
50 debug: true
51 mntopts: ["nowsync"]
52
53 :param ctx: Context
54 :param config: Configuration
55 """
56 log.info('Mounting kernel clients...')
57
58 if config is None:
59 ids = misc.all_roles_of_type(ctx.cluster, 'client')
60 client_roles = [f'client.{id_}' for id_ in ids]
61 config = dict([r, dict()] for r in client_roles)
62 elif isinstance(config, list):
63 client_roles = config
64 config = dict([r, dict()] for r in client_roles)
65 elif isinstance(config, dict):
66 client_roles = filter(lambda x: 'client.' in x, config.keys())
67 else:
68 raise ValueError(f"Invalid config object: {config} ({config.__class__})")
69 log.info(f"config is {config}")
70
71 clients = list(misc.get_clients(ctx=ctx, roles=client_roles))
72
73 test_dir = misc.get_testdir(ctx)
74
75 for id_, remote in clients:
76 KernelMount.cleanup_stale_netnses_and_bridge(remote)
77
78 mounts = {}
79 overrides = ctx.config.get('overrides', {}).get('kclient', {})
80 top_overrides = dict(filter(lambda x: 'client.' not in x[0], overrides.items()))
81 for id_, remote in clients:
82 entity = f"client.{id_}"
83 client_config = config.get(entity)
84 if client_config is None:
85 client_config = {}
86 # top level overrides
87 deep_merge(client_config, top_overrides)
88 # mount specific overrides
89 client_config_overrides = overrides.get(entity)
90 deep_merge(client_config, client_config_overrides)
91 log.info(f"{entity} config is {client_config}")
92
93 cephfs_name = client_config.get("cephfs_name")
94 if config.get("disabled", False) or not client_config.get('mounted', True):
95 continue
96
97 kernel_mount = KernelMount(
98 ctx=ctx,
99 test_dir=test_dir,
100 client_id=id_,
101 client_remote=remote,
102 brxnet=ctx.teuthology_config.get('brxnet', None),
103 client_config=client_config,
104 cephfs_name=cephfs_name)
105
106 mounts[id_] = kernel_mount
107
108 if client_config.get('debug', False):
109 remote.run(args=["sudo", "bash", "-c", "echo 'module ceph +p' > /sys/kernel/debug/dynamic_debug/control"])
110 remote.run(args=["sudo", "bash", "-c", "echo 'module libceph +p' > /sys/kernel/debug/dynamic_debug/control"])
111
112 kernel_mount.mount(mntopts=client_config.get('mntopts', []))
113
114 def umount_all():
115 log.info('Unmounting kernel clients...')
116
117 forced = False
118 for mount in mounts.values():
119 if mount.is_mounted():
120 try:
121 mount.umount()
122 except (CommandFailedError, MaxWhileTries):
123 log.warning("Ordinary umount failed, forcing...")
124 forced = True
125 mount.umount_wait(force=True)
126
127 for id_, remote in clients:
128 KernelMount.cleanup_stale_netnses_and_bridge(remote)
129
130 return forced
131
132 ctx.mounts = mounts
133 try:
134 yield mounts
135 except:
136 umount_all() # ignore forced retval, we are already in error handling
137 finally:
138
139 forced = umount_all()
140 if forced:
141 # The context managers within the kclient manager worked (i.e.
142 # the test workload passed) but for some reason we couldn't
143 # umount, so turn this into a test failure.
144 raise RuntimeError("Kernel mounts did not umount cleanly")