File: config_http_booth.py

package info (click to toggle)
pcs 0.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,148 kB
  • sloc: python: 238,810; xml: 20,833; ruby: 13,203; makefile: 1,595; sh: 484
file content (108 lines) | stat: -rw-r--r-- 2,864 bytes parent folder | download | duplicates (2)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import base64
import json

from pcs_test.tools.command_env.mock_node_communicator import (
    place_multinode_call,
)


class BoothShortcuts:
    def __init__(self, calls):
        self.__calls = calls

    def send_config(
        self,
        booth_name,
        config,
        authfile=None,
        authfile_data=None,
        node_labels=None,
        communication_list=None,
        name="http.booth.send_config",
    ):
        data = {
            "config": {
                "name": "{}.conf".format(booth_name),
                "data": config,
            }
        }
        if authfile and authfile_data:
            data["authfile"] = {
                "name": authfile,
                "data": base64.b64encode(authfile_data).decode("utf-8"),
            }
        place_multinode_call(
            self.__calls,
            name,
            node_labels,
            communication_list,
            action="remote/booth_set_config",
            param_list=[("data_json", json.dumps(data))],
        )

    def get_config(
        self,
        booth_name,
        config_data=None,
        authfile=None,
        authfile_data=None,
        node_labels=None,
        communication_list=None,
        name="http.booth.get_config",
    ):
        place_multinode_call(
            self.__calls,
            name,
            node_labels,
            communication_list,
            action="remote/booth_get_config",
            param_list=[("name", booth_name)],
            output=json.dumps(
                {
                    "config": {
                        "data": config_data,
                    },
                    "authfile": {
                        "name": authfile,
                        "data": (
                            base64.b64encode(authfile_data).decode("utf-8")
                            if authfile_data
                            else None
                        ),
                    },
                }
            ),
        )

    def save_files(
        self,
        files_data,
        *,
        saved=(),
        existing=(),
        failed=(),
        rewrite_existing=False,
        node_labels=None,
        communication_list=None,
        name="http.booth.save_files",
    ):
        # pylint: disable=too-many-arguments
        param_list = [("data_json", json.dumps(files_data))]
        if rewrite_existing:
            param_list.append(("rewrite_existing", "1"))

        place_multinode_call(
            self.__calls,
            name,
            node_labels,
            communication_list,
            action="remote/booth_save_files",
            param_list=param_list,
            output=json.dumps(
                {
                    "saved": saved,
                    "existing": existing,
                    "failed": failed,
                }
            ),
        )