]> git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/ceph_fuse.py
405742891674357855c87a01b81977bda5b2d882
[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 :param ctx: Context
76 :param config: Configuration
77 """
78 log.info('Running ceph_fuse task...')
79
80 if config is None:
81 ids = misc.all_roles_of_type(ctx.cluster, 'client')
82 client_roles = [f'client.{id_}' for id_ in ids]
83 config = dict([r, dict()] for r in client_roles)
84 elif isinstance(config, list):
85 client_roles = config
86 config = dict([r, dict()] for r in client_roles)
87 elif isinstance(config, dict):
88 client_roles = filter(lambda x: 'client.' in x, config.keys())
89 else:
90 raise ValueError(f"Invalid config object: {config} ({config.__class__})")
91 log.info(f"config is {config}")
92
93 clients = list(misc.get_clients(ctx=ctx, roles=client_roles))
94 testdir = misc.get_testdir(ctx)
95 all_mounts = getattr(ctx, 'mounts', {})
96 mounted_by_me = {}
97 skipped = {}
98 remotes = set()
99
100 brxnet = config.get("brxnet", None)
101
102 # Construct any new FuseMount instances
103 overrides = ctx.config.get('overrides', {}).get('ceph-fuse', {})
104 top_overrides = dict(filter(lambda x: 'client.' not in x[0], overrides.items()))
105 for id_, remote in clients:
106 entity = f"client.{id_}"
107 client_config = config.get(entity)
108 if client_config is None:
109 client_config = {}
110 # top level overrides
111 for k, v in top_overrides.items():
112 if v is not None:
113 client_config[k] = v
114 # mount specific overrides
115 client_config_overrides = overrides.get(entity)
116 misc.deep_merge(client_config, client_config_overrides)
117 log.info(f"{entity} config is {client_config}")
118
119 remotes.add(remote)
120 auth_id = client_config.get("auth_id", id_)
121 cephfs_name = client_config.get("cephfs_name")
122
123 skip = client_config.get("skip", False)
124 if skip:
125 skipped[id_] = skip
126 continue
127
128 if id_ not in all_mounts:
129 fuse_mount = FuseMount(ctx=ctx, client_config=client_config,
130 test_dir=testdir, client_id=auth_id,
131 client_remote=remote, brxnet=brxnet,
132 cephfs_name=cephfs_name)
133 all_mounts[id_] = fuse_mount
134 else:
135 # Catch bad configs where someone has e.g. tried to use ceph-fuse and kcephfs for the same client
136 assert isinstance(all_mounts[id_], FuseMount)
137
138 if not config.get("disabled", False) and client_config.get('mounted', True):
139 mounted_by_me[id_] = {"config": client_config, "mount": all_mounts[id_]}
140
141 ctx.mounts = all_mounts
142
143 # Umount any pre-existing clients that we have not been asked to mount
144 for client_id in set(all_mounts.keys()) - set(mounted_by_me.keys()) - set(skipped.keys()):
145 mount = all_mounts[client_id]
146 if mount.is_mounted():
147 mount.umount_wait()
148
149 for remote in remotes:
150 FuseMount.cleanup_stale_netnses_and_bridge(remote)
151
152 # Mount any clients we have been asked to (default to mount all)
153 log.info('Mounting ceph-fuse clients...')
154 for info in mounted_by_me.values():
155 config = info["config"]
156 mount_x = info['mount']
157 if config.get("mount_path"):
158 mount_x.cephfs_mntpt = config.get("mount_path")
159 if config.get("mountpoint"):
160 mount_x.hostfs_mntpt = config.get("mountpoint")
161 mount_x.mount(createfs=False)
162
163 for info in mounted_by_me.values():
164 info["mount"].wait_until_mounted()
165
166 try:
167 yield all_mounts
168 finally:
169 log.info('Unmounting ceph-fuse clients...')
170
171 for info in mounted_by_me.values():
172 # Conditional because an inner context might have umounted it
173 mount = info["mount"]
174 if mount.is_mounted():
175 mount.umount_wait()
176 for remote in remotes:
177 FuseMount.cleanup_stale_netnses_and_bridge(remote)