]>
Commit | Line | Data |
---|---|---|
f91f0fd5 TL |
1 | """ |
2 | immutable object cache task | |
3 | """ | |
4 | import contextlib | |
5 | import logging | |
6 | ||
7 | from teuthology import misc as teuthology | |
8 | from teuthology import contextutil | |
9 | from teuthology.orchestra import run | |
10 | ||
11 | log = logging.getLogger(__name__) | |
12 | ||
13 | @contextlib.contextmanager | |
14 | def immutable_object_cache(ctx, config): | |
15 | """ | |
16 | setup and cleanup immutable object cache | |
17 | """ | |
18 | log.info("start immutable object cache daemon") | |
19 | for client, client_config in config.items(): | |
20 | (remote,) = ctx.cluster.only(client).remotes.keys() | |
21 | # make sure that there is one immutable object cache daemon on the same node. | |
22 | remote.run( | |
23 | args=[ | |
24 | 'sudo', 'killall', '-s', '9', 'ceph-immutable-object-cache', run.Raw('||'), 'true', | |
25 | ] | |
26 | ) | |
27 | remote.run( | |
28 | args=[ | |
29 | 'ceph-immutable-object-cache', '-b', | |
30 | ] | |
31 | ) | |
32 | try: | |
33 | yield | |
34 | finally: | |
f67539c2 | 35 | log.info("check and cleanup immutable object cache") |
f91f0fd5 TL |
36 | for client, client_config in config.items(): |
37 | client_config = client_config if client_config is not None else dict() | |
38 | (remote,) = ctx.cluster.only(client).remotes.keys() | |
f67539c2 TL |
39 | cache_path = client_config.get('immutable object cache path', '/tmp/ceph-immutable-object-cache') |
40 | ls_command = '"$(ls {} )"'.format(cache_path) | |
41 | remote.run( | |
42 | args=[ | |
43 | 'test', '-n', run.Raw(ls_command), | |
44 | ] | |
45 | ) | |
f91f0fd5 TL |
46 | remote.run( |
47 | args=[ | |
48 | 'sudo', 'killall', '-s', '9', 'ceph-immutable-object-cache', run.Raw('||'), 'true', | |
49 | ] | |
50 | ) | |
f91f0fd5 TL |
51 | remote.run( |
52 | args=[ | |
53 | 'sudo', 'rm', '-rf', cache_path, run.Raw('||'), 'true', | |
54 | ] | |
55 | ) | |
56 | ||
57 | @contextlib.contextmanager | |
58 | def task(ctx, config): | |
59 | """ | |
60 | This is task for start immutable_object_cache. | |
61 | """ | |
62 | assert isinstance(config, dict), \ | |
63 | "task immutable_object_cache only supports a dictionary for configuration" | |
64 | ||
65 | managers = [] | |
66 | config = teuthology.replace_all_with_clients(ctx.cluster, config) | |
67 | managers.append( | |
68 | lambda: immutable_object_cache(ctx=ctx, config=config) | |
69 | ) | |
70 | ||
71 | with contextutil.nested(*managers): | |
72 | yield |