]> git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/ceph_fuse.py
update sources to ceph Nautilus 14.2.1
[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 as teuthology
9 from cephfs.fuse_mount import FuseMount
10 from tasks.cephfs.filesystem import Filesystem
11
12 log = logging.getLogger(__name__)
13
14
15 def get_client_configs(ctx, config):
16 """
17 Get a map of the configuration for each FUSE client in the configuration by
18 combining the configuration of the current task with any global overrides.
19
20 :param ctx: Context instance
21 :param config: configuration for this task
22 :return: dict of client name to config or to None
23 """
24 if config is None:
25 config = dict(('client.{id}'.format(id=id_), None)
26 for id_ in teuthology.all_roles_of_type(ctx.cluster, 'client'))
27 elif isinstance(config, list):
28 config = dict((name, None) for name in config)
29
30 overrides = ctx.config.get('overrides', {})
31 teuthology.deep_merge(config, overrides.get('ceph-fuse', {}))
32
33 return config
34
35
36 @contextlib.contextmanager
37 def task(ctx, config):
38 """
39 Mount/unmount a ``ceph-fuse`` client.
40
41 The config is optional and defaults to mounting on all clients. If
42 a config is given, it is expected to be a list of clients to do
43 this operation on. This lets you e.g. set up one client with
44 ``ceph-fuse`` and another with ``kclient``.
45
46 Example that mounts all clients::
47
48 tasks:
49 - ceph:
50 - ceph-fuse:
51 - interactive:
52
53 Example that uses both ``kclient` and ``ceph-fuse``::
54
55 tasks:
56 - ceph:
57 - ceph-fuse: [client.0]
58 - kclient: [client.1]
59 - interactive:
60
61 Example that enables valgrind:
62
63 tasks:
64 - ceph:
65 - ceph-fuse:
66 client.0:
67 valgrind: [--tool=memcheck, --leak-check=full, --show-reachable=yes]
68 - interactive:
69
70 Example that stops an already-mounted client:
71
72 ::
73
74 tasks:
75 - ceph:
76 - ceph-fuse: [client.0]
77 - ... do something that requires the FS mounted ...
78 - ceph-fuse:
79 client.0:
80 mounted: false
81 - ... do something that requires the FS unmounted ...
82
83 Example that adds more generous wait time for mount (for virtual machines):
84
85 tasks:
86 - ceph:
87 - ceph-fuse:
88 client.0:
89 mount_wait: 60 # default is 0, do not wait before checking /sys/
90 mount_timeout: 120 # default is 30, give up if /sys/ is not populated
91 - interactive:
92
93 :param ctx: Context
94 :param config: Configuration
95 """
96 log.info('Running ceph_fuse task...')
97
98 testdir = teuthology.get_testdir(ctx)
99 log.info("config is {}".format(str(config)))
100 config = get_client_configs(ctx, config)
101 log.info("new config is {}".format(str(config)))
102
103 # List clients we will configure mounts for, default is all clients
104 clients = list(teuthology.get_clients(ctx=ctx, roles=filter(lambda x: 'client.' in x, config.keys())))
105
106 all_mounts = getattr(ctx, 'mounts', {})
107 mounted_by_me = {}
108 skipped = {}
109
110 # Construct any new FuseMount instances
111 for id_, remote in clients:
112 client_config = config.get("client.%s" % id_)
113 if client_config is None:
114 client_config = {}
115
116 skip = client_config.get("skip", False)
117 if skip:
118 skipped[id_] = skip
119 continue
120
121 if id_ not in all_mounts:
122 fuse_mount = FuseMount(ctx, client_config, testdir, id_, remote)
123 all_mounts[id_] = fuse_mount
124 else:
125 # Catch bad configs where someone has e.g. tried to use ceph-fuse and kcephfs for the same client
126 assert isinstance(all_mounts[id_], FuseMount)
127
128 if not config.get("disabled", False) and client_config.get('mounted', True):
129 mounted_by_me[id_] = all_mounts[id_]
130
131 ctx.mounts = all_mounts
132
133 # Mount any clients we have been asked to (default to mount all)
134 log.info('Mounting ceph-fuse clients...')
135 for mount in mounted_by_me.values():
136 mount.mount()
137
138 for mount in mounted_by_me.values():
139 mount.wait_until_mounted()
140
141 # Umount any pre-existing clients that we have not been asked to mount
142 for client_id in set(all_mounts.keys()) - set(mounted_by_me.keys()) - set(skipped.keys()):
143 mount = all_mounts[client_id]
144 if mount.is_mounted():
145 mount.umount_wait()
146
147 try:
148 yield all_mounts
149 finally:
150 log.info('Unmounting ceph-fuse clients...')
151
152 for mount in mounted_by_me.values():
153 # Conditional because an inner context might have umounted it
154 if mount.is_mounted():
155 mount.umount_wait()