aboutsummaryrefslogtreecommitdiffstats
path: root/build/plugins/yabs_generate_conf.py
blob: ad416aaa0bc41b91815e12663d8acf63f0b2926a (plain) (blame)
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
from _common import sort_by_keywords


def get_or_default(kv, name, default):
    if name in kv:
        return kv[name][0]
    return default


def onyabs_generate_conf(unit, *args):
    flat, kv = sort_by_keywords({'MODE': 1, 'SCRIPT': 1, 'SRC': 1, 'TOOL': 1, 'CONF_DIR': 1, 'DEST': 1}, args)
    src = get_or_default(kv, 'SRC', 'yabs/server/phantom')
    mode = get_or_default(kv, 'MODE', 'production')

    script = src + "/" + get_or_default(kv, 'SCRIPT', 'mkconf.py')
    conf = src + "/" + get_or_default(kv, 'CONF_DIR', 'conf-tmpl')
    tool = src + "/" + get_or_default(kv, 'TOOL', 'yabs_conf')

    for name in flat:
        filename = "/".join([conf, name])
        unit.onpython(
            [
                script,
                "--cluster-conf-binary",
                tool,
                "--mode",
                mode,
                "--dest-dir",
                "${BINDIR}",
                filename,
                "IN",
                filename,
                "OUT_NOAUTO",
                "${BINDIR}/%s" % name,
                "TOOL",
                tool,
            ]
        )


def onyabs_generate_phantom_conf_patch(unit, *args):
    flat, kv = sort_by_keywords({'SRC': 1, 'DST': 1}, args)
    src = '${ARCADIA_BUILD_ROOT}/' + get_or_default(kv, 'SRC', 'yabs/server/phantom/conf')
    dst = '${ARCADIA_BUILD_ROOT}/' + get_or_default(kv, 'DST', 'yabs/server/phantom/conf-test')
    for f in flat:
        lhs = src + '/' + f
        rhs = dst + '/' + f
        unit.onpython(['mkdiff.py', lhs, rhs, 'IN', lhs, 'IN', rhs, 'STDOUT', f + ".patch"])


def onyabs_generate_phantom_conf_test_check(unit, *args):
    yabs_path = args[0]
    for name in args[1:]:
        unit.onpython(
            """
    build/scripts/wrapper.py mkcheckconf.sh ${{ARCADIA_BUILD_ROOT}}/{yabs_path}/phantom/conf-test/yabs-{role}.conf yabs-check-{role}.conf
    IN mkcheckconf.sh ${{ARCADIA_BUILD_ROOT}}/{yabs_path}/phantom/conf-test/yabs-{role}.conf
    OUT yabs-check-{role}.conf
""".format(
                yabs_path=yabs_path, role=name
            ).split()  # noqa
        )