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