File: immutable_object_cache.py

package info (click to toggle)
ceph 18.2.7%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,186,140 kB
  • sloc: cpp: 6,278,388; ansic: 3,507,431; python: 372,964; asm: 216,381; java: 133,450; sh: 125,043; xml: 39,398; ruby: 32,026; makefile: 29,004; javascript: 23,994; cs: 18,980; perl: 9,708; sql: 7,833; lisp: 5,920; pascal: 3,109; ada: 1,681; yacc: 478; awk: 188; f90: 55; php: 1
file content (72 lines) | stat: -rw-r--r-- 2,333 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
immutable object cache task
"""
import contextlib
import logging

from teuthology import misc as teuthology
from teuthology import contextutil
from teuthology.orchestra import run

log = logging.getLogger(__name__)

@contextlib.contextmanager
def immutable_object_cache(ctx, config):
    """
    setup and cleanup immutable object cache
    """
    log.info("start immutable object cache daemon")
    for client, client_config in config.items():
        (remote,) = ctx.cluster.only(client).remotes.keys()
        # make sure that there is one immutable object cache daemon on the same node.
        remote.run(
            args=[
                'sudo', 'killall', '-s', '9', 'ceph-immutable-object-cache', run.Raw('||'), 'true',
                ]
            )
        remote.run(
            args=[
                'ceph-immutable-object-cache', '-b',
                ]
            )
    try:
        yield
    finally:
        log.info("check and cleanup immutable object cache")
        for client, client_config in config.items():
            client_config = client_config if client_config is not None else dict()
            (remote,) = ctx.cluster.only(client).remotes.keys()
            cache_path = client_config.get('immutable object cache path', '/tmp/ceph-immutable-object-cache')
            ls_command = '"$(ls {} )"'.format(cache_path)
            remote.run(
                args=[
                    'test', '-n', run.Raw(ls_command),
                    ]
                )
            remote.run(
                args=[
                    'sudo', 'killall', '-s', '9', 'ceph-immutable-object-cache', run.Raw('||'), 'true',
                    ]
                )
            remote.run(
                args=[
                    'sudo', 'rm', '-rf', cache_path, run.Raw('||'), 'true',
                    ]
                )

@contextlib.contextmanager
def task(ctx, config):
    """
    This is task for start immutable_object_cache.
    """
    assert isinstance(config, dict), \
           "task immutable_object_cache only supports a dictionary for configuration"

    managers = []
    config = teuthology.replace_all_with_clients(ctx.cluster, config)
    managers.append(
        lambda: immutable_object_cache(ctx=ctx, config=config)
        )

    with contextutil.nested(*managers):
        yield