]> git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/ceph_fuse.py
update ceph source to reef 18.1.2
[ceph.git] / ceph / qa / tasks / ceph_fuse.py
1 """
2 Ceph FUSE client task
3 """
4
5 import contextlib
6 import logging
7
8 from teuthology import misc
9 from tasks.cephfs.fuse_mount import FuseMount
10
11 log = logging.getLogger(__name__)
12
13
14 @contextlib.contextmanager
15 def task(ctx, config):
16 """
17 Mount/unmount a ``ceph-fuse`` client.
18
19 The config is optional and defaults to mounting on all clients. If
20 a config is given, it is expected to be a list of clients to do
21 this operation on. This lets you e.g. set up one client with
22 ``ceph-fuse`` and another with ``kclient``.
23
24 ``brxnet`` should be a Private IPv4 Address range, default range is
25 [192.168.0.0/16]
26
27 Example that mounts all clients::
28
29 tasks:
30 - ceph:
31 - ceph-fuse:
32 - interactive:
33 - brxnet: [192.168.0.0/16]
34
35 Example that uses both ``kclient` and ``ceph-fuse``::
36
37 tasks:
38 - ceph:
39 - ceph-fuse: [client.0]
40 - kclient: [client.1]
41 - interactive:
42
43 Example that enables valgrind:
44
45 tasks:
46 - ceph:
47 - ceph-fuse:
48 client.0:
49 valgrind: [--tool=memcheck, --leak-check=full, --show-reachable=yes]
50 - interactive:
51
52 Example that stops an already-mounted client:
53
54 ::
55
56 tasks:
57 - ceph:
58 - ceph-fuse: [client.0]
59 - ... do something that requires the FS mounted ...
60 - ceph-fuse:
61 client.0:
62 mounted: false
63 - ... do something that requires the FS unmounted ...
64
65 Example that adds more generous wait time for mount (for virtual machines):
66
67 tasks:
68 - ceph:
69 - ceph-fuse:
70 client.0:
71 mount_wait: 60 # default is 0, do not wait before checking /sys/
72 mount_timeout: 120 # default is 30, give up if /sys/ is not populated
73 - interactive:
74
75 Example that creates and mounts a subvol:
76
77 overrides:
78 ceph:
79 subvols:
80 create: 2
81 subvol_options: "--namespace-isolated --size 25000000000"
82 ceph-fuse:
83 client.0:
84 mount_subvol_num: 0
85 kclient:
86 client.1:
87 mount_subvol_num: 1
88
89 :param ctx: Context
90 :param config: Configuration
91 """
92 log.info('Running ceph_fuse task...')
93
94 if config is None:
95 ids = misc.all_roles_of_type(ctx.cluster, 'client')
96 client_roles = [f'client.{id_}' for id_ in ids]
97 config = dict([r, dict()] for r in client_roles)
98 elif isinstance(config, list):
99 client_roles = config
100 config = dict([r, dict()] for r in client_roles)
101 elif isinstance(config, dict):
102 client_roles = filter(lambda x: 'client.' in x, config.keys())
103 else:
104 raise ValueError(f"Invalid config object: {config} ({config.__class__})")
105 log.info(f"config is {config}")
106
107 clients = list(misc.get_clients(ctx=ctx, roles=client_roles))
108 testdir = misc.get_testdir(ctx)
109 all_mounts = getattr(ctx, 'mounts', {})
110 mounted_by_me = {}
111 skipped = {}
112 remotes = set()
113
114 brxnet = config.get("brxnet", None)
115
116 # Construct any new FuseMount instances
117 overrides = ctx.config.get('overrides', {}).get('ceph-fuse', {})
118 top_overrides = dict(filter(lambda x: 'client.' not in x[0], overrides.items()))
119 for id_, remote in clients:
120 entity = f"client.{id_}"
121 client_config = config.get(entity)
122 if client_config is None:
123 client_config = {}
124 # top level overrides
125 misc.deep_merge(client_config, top_overrides)
126 # mount specific overrides
127 client_config_overrides = overrides.get(entity)
128 misc.deep_merge(client_config, client_config_overrides)
129 log.info(f"{entity} config is {client_config}")
130
131 remotes.add(remote)
132 auth_id = client_config.get("auth_id", id_)
133 cephfs_name = client_config.get("cephfs_name")
134
135 skip = client_config.get("skip", False)
136 if skip:
137 skipped[id_] = skip
138 continue
139
140 if id_ not in all_mounts:
141 fuse_mount = FuseMount(ctx=ctx, client_config=client_config,
142 test_dir=testdir, client_id=auth_id,
143 client_remote=remote, brxnet=brxnet,
144 cephfs_name=cephfs_name)
145 all_mounts[id_] = fuse_mount
146 else:
147 # Catch bad configs where someone has e.g. tried to use ceph-fuse and kcephfs for the same client
148 assert isinstance(all_mounts[id_], FuseMount)
149
150 if not config.get("disabled", False) and client_config.get('mounted', True):
151 mounted_by_me[id_] = {"config": client_config, "mount": all_mounts[id_]}
152
153 ctx.mounts = all_mounts
154
155 # Umount any pre-existing clients that we have not been asked to mount
156 for client_id in set(all_mounts.keys()) - set(mounted_by_me.keys()) - set(skipped.keys()):
157 mount = all_mounts[client_id]
158 if mount.is_mounted():
159 mount.umount_wait()
160
161 for remote in remotes:
162 FuseMount.cleanup_stale_netnses_and_bridge(remote)
163
164 # Mount any clients we have been asked to (default to mount all)
165 log.info('Mounting ceph-fuse clients...')
166 for info in mounted_by_me.values():
167 config = info["config"]
168 mount_x = info['mount']
169 mount_x.mount(mntopts=config.get('mntopts', []), mntargs=config.get('mntargs', []))
170
171 for info in mounted_by_me.values():
172 info["mount"].wait_until_mounted()
173
174 try:
175 yield all_mounts
176 finally:
177 log.info('Unmounting ceph-fuse clients...')
178
179 for info in mounted_by_me.values():
180 # Conditional because an inner context might have umounted it
181 mount = info["mount"]
182 if mount.is_mounted():
183 mount.umount_wait()
184 for remote in remotes:
185 FuseMount.cleanup_stale_netnses_and_bridge(remote)