]> git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/fs.py
4b47e754bfa2460e81651685f065bb423dc0cd32
[ceph.git] / ceph / qa / tasks / fs.py
1 """
2 CephFS sub-tasks.
3 """
4
5 import logging
6 import re
7
8 from tasks.cephfs.filesystem import Filesystem
9
10 log = logging.getLogger(__name__)
11
12 def clients_evicted(ctx, config):
13 """
14 Check clients are evicted, unmount (cleanup) if so.
15 """
16
17 if config is None:
18 config = {}
19 assert isinstance(config, dict), \
20 'task only accepts a dict for configuration'
21
22 clients = config.get('clients')
23
24 if clients is None:
25 clients = {("client."+client_id): True for client_id in ctx.mounts}
26
27 log.info("clients is {}".format(str(clients)))
28
29 fs = Filesystem(ctx)
30 status = fs.status()
31
32 has_session = set()
33 mounts = {}
34 for client in clients:
35 client_id = re.match("^client.([0-9]+)$", client).groups(1)[0]
36 mounts[client] = ctx.mounts.get(client_id)
37
38 for rank in fs.get_ranks(status=status):
39 ls = fs.rank_asok(['session', 'ls'], rank=rank['rank'], status=status)
40 for session in ls:
41 for client, evicted in clients.viewitems():
42 mount = mounts.get(client)
43 if mount is not None:
44 global_id = mount.get_global_id()
45 if session['id'] == global_id:
46 if evicted:
47 raise RuntimeError("client still has session: {}".format(str(session)))
48 else:
49 log.info("client {} has a session with MDS {}.{}".format(client, fs.id, rank['rank']))
50 has_session.add(client)
51
52 no_session = set(clients) - has_session
53 should_assert = False
54 for client, evicted in clients.viewitems():
55 mount = mounts.get(client)
56 if mount is not None:
57 if evicted:
58 log.info("confirming client {} is blacklisted".format(client))
59 assert mount.is_blacklisted()
60 elif client in no_session:
61 log.info("client {} should not be evicted but has no session with an MDS".format(client))
62 mount.is_blacklisted() # for debugging
63 should_assert = True
64 if should_assert:
65 raise RuntimeError("some clients which should not be evicted have no session with an MDS?")