File: immutable_object_cache_thrash.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 (79 lines) | stat: -rw-r--r-- 2,473 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
73
74
75
76
77
78
79
"""
immutable object cache thrash task
"""
import contextlib
import logging

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

DEFAULT_KILL_DAEMON_TIME = 2
DEFAULT_DEAD_TIME = 30
DEFAULT_LIVE_TIME = 120

log = logging.getLogger(__name__)

@contextlib.contextmanager
def thrashes_immutable_object_cache_daemon(ctx, config):
    """
    thrashes immutable object cache daemon.
    It can test reconnection feature of RO cache when RO daemon crash
    TODO : replace sleep with better method.
    """
    log.info("thrashes immutable object cache daemon")

    # just thrash one rbd client.
    client, client_config = list(config.items())[0]
    (remote,) = ctx.cluster.only(client).remotes.keys()
    client_config = client_config if client_config is not None else dict()
    kill_daemon_time = client_config.get('kill_daemon_time', DEFAULT_KILL_DAEMON_TIME)
    dead_time = client_config.get('dead_time', DEFAULT_DEAD_TIME)
    live_time = client_config.get('live_time', DEFAULT_LIVE_TIME)

    for i in range(kill_daemon_time):
        log.info("ceph-immutable-object-cache crash....")
        remote.run(
            args=[
                'sudo', 'killall', '-s', '9', 'ceph-immutable-object-cache', run.Raw('||'), 'true',
                 ]
            )
        # librbd shoud normally run when ceph-immutable-object-cache
        remote.run(
            args=[
                'sleep', '{dead_time}'.format(dead_time=dead_time),
                 ]
            )
        # librbd should reconnect daemon
        log.info("startup ceph-immutable-object-cache")
        remote.run(
            args=[
                'ceph-immutable-object-cache', '-b',
                 ]
            )
        remote.run(
            args=[
                'sleep', '{live_time}'.format(live_time=live_time),
                 ]
            )
    try:
        yield
    finally:
        log.info("cleanup")

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

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

    with contextutil.nested(*managers):
        yield