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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
import json
import pprint
from pcs_test.tools.command_env.config_http_booth import BoothShortcuts
from pcs_test.tools.command_env.config_http_corosync import CorosyncShortcuts
from pcs_test.tools.command_env.config_http_files import FilesShortcuts
from pcs_test.tools.command_env.config_http_host import HostShortcuts
from pcs_test.tools.command_env.config_http_pcmk import PcmkShortcuts
from pcs_test.tools.command_env.config_http_pcs_cfgsync import (
PcsCfgsyncShortcuts,
)
from pcs_test.tools.command_env.config_http_sbd import SbdShortcuts
from pcs_test.tools.command_env.config_http_scsi import ScsiShortcuts
from pcs_test.tools.command_env.config_http_status import StatusShortcuts
from pcs_test.tools.command_env.mock_node_communicator import (
place_communication,
place_multinode_call,
place_requests,
place_responses,
)
def _mutual_exclusive(param_names, **kwargs):
entered = {
key: value
for key, value in kwargs.items()
if key in param_names and value is not None
}
if len(entered) != 1:
raise AssertionError(
"Exactly one of '{0}' must be specified, \nwas specified:\n{1}".format(
"', '".join(param_names),
pprint.pformat(entered) if entered else " nothing",
)
)
class HttpConfig:
# pylint: disable=too-many-instance-attributes
def __init__(self, call_collection, wrap_helper):
self.__calls = call_collection
self.booth = wrap_helper(BoothShortcuts(self.__calls))
self.corosync = wrap_helper(CorosyncShortcuts(self.__calls))
self.files = wrap_helper(FilesShortcuts(self.__calls))
self.host = wrap_helper(HostShortcuts(self.__calls))
self.pcmk = wrap_helper(PcmkShortcuts(self.__calls))
self.pcs_cfgsync = wrap_helper(PcsCfgsyncShortcuts(self.__calls))
self.sbd = wrap_helper(SbdShortcuts(self.__calls))
self.scsi = wrap_helper(ScsiShortcuts(self.__calls))
self.status = wrap_helper(StatusShortcuts(self.__calls))
def add_communication(self, name, communication_list, **kwargs):
"""
Create a generic call for network communication.
string name -- key of the call
list of dict communication_list -- see
pcs_test.tools.command_env.mock_node_communicator.create_communication
**kwargs -- see
pcs_test.tools.command_env.mock_node_communicator.create_communication
"""
place_communication(self.__calls, name, communication_list, **kwargs)
def add_requests(self, request_list, name):
place_requests(self.__calls, name, request_list)
def start_loop(self, response_list, name):
place_responses(self.__calls, name, response_list)
def put_file(
self,
communication_list,
name="http.common.put_file",
results=None,
files=None,
**kwargs,
):
"""
Example:
config.http.put_file(
communication_list=[dict(label="node")],
files={
"pacemaker_remote authkey": {
"type": "pcmk_remote_authkey",
"data": base64.b64encode(pcmk_authkey_content),
"rewrite_existing": True
}
},
results={
"pacemaker_remote authkey": {
"code": "written",
"message": "",
}
}
)
"""
_mutual_exclusive(["output", "results"], results=results, **kwargs)
_mutual_exclusive(["files", "param_list"], files=files, **kwargs)
if results:
kwargs["output"] = json.dumps({"files": results})
if files:
kwargs["param_list"] = [("data_json", json.dumps(files))]
self.place_multinode_call(
name,
communication_list=communication_list,
action="remote/put_file",
**kwargs,
)
def remove_file(
self,
communication_list,
name="http.common.remove_file",
results=None,
files=None,
**kwargs,
):
"""
Example:
config.http.remove_file(
communication_list=[dict(label="node")],
files={
"pacemaker_remote authkey": {
"type": "pcmk_remote_authkey",
}
},
results={
"pacemaker_remote authkey": {
"code": "deleted",
"message": "",
}
}
)
"""
_mutual_exclusive(["output", "results"], results=results, **kwargs)
_mutual_exclusive(["files", "param_list"], files=files, **kwargs)
if results:
kwargs["output"] = json.dumps({"files": results})
if files:
kwargs["param_list"] = [("data_json", json.dumps(files))]
self.place_multinode_call(
name,
communication_list=communication_list,
action="remote/remove_file",
**kwargs,
)
def manage_services(
self,
communication_list,
name="http.common.manage_services",
results=None,
action_map=None,
**kwargs,
):
"""
Example:
config.http.manage_services(
communication_list=[dict(label=label)],
action_map={
"pacemaker_remote enable": {
"type": "service_command",
"service": "pacemaker_remote",
"command": "enable",
},
"pacemaker_remote start": {
"type": "service_command",
"service": "pacemaker_remote",
"command": "start",
},
},
results={
"pacemaker_remote enable": {
"code": "success",
"message": "",
},
"pacemaker_remote start": {
"code": "success",
"message": "",
}
}
)
"""
_mutual_exclusive(["output", "results"], results=results, **kwargs)
_mutual_exclusive(
["action_map", "param_list"], action_map=action_map, **kwargs
)
if results:
kwargs["output"] = json.dumps({"actions": results})
if action_map:
kwargs["param_list"] = [("data_json", json.dumps(action_map))]
self.place_multinode_call(
name,
communication_list=communication_list,
action="remote/manage_services",
**kwargs,
)
def place_multinode_call(self, *args, **kwargs):
place_multinode_call(self.__calls, *args, **kwargs)
|