koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 1 | import time |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 2 | import json |
kdanylov aka koder | 736e5c1 | 2017-05-07 17:27:14 +0300 | [diff] [blame^] | 3 | import copy |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 4 | import logging |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 5 | from concurrent.futures import Future |
| 6 | from typing import List, Dict, Tuple, Optional, Union, cast |
koder aka kdanilov | 88407ff | 2015-05-26 15:35:57 +0300 | [diff] [blame] | 7 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 8 | from . import utils, ssh_utils, hw_info |
| 9 | from .config import ConfigBlock |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 10 | from .node import setup_rpc, connect |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 11 | from .node_interfaces import NodeInfo, IRPCNode |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 12 | from .stage import Stage, StepOrder |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 13 | from .sensors import collect_sensors_data |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 14 | from .suits.all_suits import all_suits |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 15 | from .test_run_class import TestRun |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 16 | from .utils import StopTestError |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame] | 17 | from .result_classes import SuiteConfig |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 18 | from .hlstorage import ResultStorage |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame] | 19 | |
koder aka kdanilov | 57ce4db | 2015-04-25 21:25:51 +0300 | [diff] [blame] | 20 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 21 | logger = logging.getLogger("wally") |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 22 | |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 23 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 24 | class ConnectStage(Stage): |
| 25 | """Connect to nodes stage""" |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 26 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 27 | priority = StepOrder.CONNECT |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 28 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 29 | def run(self, ctx: TestRun) -> None: |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 30 | with ctx.get_pool() as pool: |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 31 | logger.info("Connecting to %s nodes", len(ctx.nodes_info)) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 32 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 33 | def connect_ext(node_info: NodeInfo) -> Tuple[bool, Union[IRPCNode, NodeInfo]]: |
| 34 | try: |
| 35 | ssh_node = connect(node_info, conn_timeout=ctx.config.connect_timeout) |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 36 | |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 37 | return True, setup_rpc(ssh_node, |
| 38 | ctx.rpc_code, |
| 39 | ctx.default_rpc_plugins, |
| 40 | log_level=ctx.config.rpc_log_level) |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 41 | except Exception as exc: |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 42 | logger.exception("During connect to %s: %s", node_info, exc) |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 43 | return False, node_info |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 44 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 45 | failed_testnodes = [] # type: List[NodeInfo] |
| 46 | failed_nodes = [] # type: List[NodeInfo] |
| 47 | ctx.nodes = [] |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 48 | |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 49 | for ok, node in pool.map(connect_ext, ctx.nodes_info.values()): |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 50 | if not ok: |
| 51 | node = cast(NodeInfo, node) |
| 52 | if 'testnode' in node.roles: |
| 53 | failed_testnodes.append(node) |
| 54 | else: |
| 55 | failed_nodes.append(node) |
| 56 | else: |
| 57 | ctx.nodes.append(cast(IRPCNode, node)) |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 58 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 59 | if failed_nodes: |
| 60 | msg = "Node(s) {} would be excluded - can't connect" |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 61 | logger.warning(msg.format(", ".join(map(str, failed_nodes)))) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 62 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 63 | if failed_testnodes: |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 64 | msg = "Can't start RPC on testnode(s) " + ",".join(map(str, failed_testnodes)) |
koder aka kdanilov | c368eb6 | 2015-04-28 18:22:01 +0300 | [diff] [blame] | 65 | logger.error(msg) |
| 66 | raise utils.StopTestError(msg) |
| 67 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 68 | if not failed_nodes: |
| 69 | logger.info("All nodes connected successfully") |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 70 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 71 | def cleanup(self, ctx: TestRun) -> None: |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 72 | if ctx.config.get("download_rpc_logs", False): |
| 73 | for node in ctx.nodes: |
| 74 | if node.rpc_log_file is not None: |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 75 | nid = node.node_id |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame] | 76 | path = "rpc_logs/{}.txt".format(nid) |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 77 | node.conn.server.flush_logs() |
| 78 | log = node.get_file_content(node.rpc_log_file) |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 79 | if path in ctx.storage: |
koder aka kdanilov | ffaf48d | 2016-12-27 02:25:29 +0200 | [diff] [blame] | 80 | ctx.storage.append_raw(log, path) |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 81 | else: |
koder aka kdanilov | ffaf48d | 2016-12-27 02:25:29 +0200 | [diff] [blame] | 82 | ctx.storage.put_raw(log, path) |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 83 | logger.debug("RPC log from node {} stored into storage::{}".format(nid, path)) |
| 84 | |
| 85 | with ctx.get_pool() as pool: |
| 86 | list(pool.map(lambda node: node.disconnect(stop=True), ctx.nodes)) |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 87 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 88 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 89 | class CollectInfoStage(Stage): |
| 90 | """Collect node info""" |
koder aka kdanilov | 3d2bc4f | 2016-11-12 18:31:18 +0200 | [diff] [blame] | 91 | |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 92 | priority = StepOrder.START_SENSORS - 2 |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 93 | config_block = 'collect_info' |
| 94 | |
| 95 | def run(self, ctx: TestRun) -> None: |
| 96 | if not ctx.config.collect_info: |
| 97 | return |
| 98 | |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 99 | futures = {} # type: Dict[Tuple[str, str], Future] |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 100 | |
| 101 | with ctx.get_pool() as pool: |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 102 | # can't make next RPC request until finish with previous |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 103 | for node in ctx.nodes: |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 104 | nid = node.node_id |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 105 | hw_info_path = "hw_info/{}".format(nid) |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 106 | if hw_info_path not in ctx.storage: |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 107 | futures[(hw_info_path, nid)] = pool.submit(hw_info.get_hw_info, node) |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 108 | |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 109 | for (path, nid), future in futures.items(): |
| 110 | try: |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 111 | ctx.storage.put(future.result(), path) |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 112 | except Exception: |
| 113 | logger.exception("During collecting hardware info from %s", nid) |
| 114 | raise utils.StopTestError() |
| 115 | |
| 116 | futures.clear() |
| 117 | for node in ctx.nodes: |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 118 | nid = node.node_id |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 119 | sw_info_path = "sw_info/{}".format(nid) |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 120 | if sw_info_path not in ctx.storage: |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 121 | futures[(sw_info_path, nid)] = pool.submit(hw_info.get_sw_info, node) |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 122 | |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 123 | for (path, nid), future in futures.items(): |
| 124 | try: |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 125 | ctx.storage.put(future.result(), path) |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 126 | except Exception: |
| 127 | logger.exception("During collecting software info from %s", nid) |
| 128 | raise utils.StopTestError() |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 129 | |
| 130 | |
| 131 | class ExplicitNodesStage(Stage): |
| 132 | """add explicit nodes""" |
| 133 | |
| 134 | priority = StepOrder.DISCOVER |
| 135 | config_block = 'nodes' |
| 136 | |
| 137 | def run(self, ctx: TestRun) -> None: |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 138 | if 'all_nodes' in ctx.storage: |
| 139 | logger.info("Skip explicid nodes filling, as all_nodes all ready in storage") |
| 140 | return |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 141 | |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 142 | for url, roles in ctx.config.get('nodes', {}).raw().items(): |
kdanylov aka koder | 150b219 | 2017-04-01 16:53:01 +0300 | [diff] [blame] | 143 | ctx.merge_node(ssh_utils.parse_ssh_uri(url), set(role.strip() for role in roles.split(","))) |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 144 | logger.debug("Add node %s with roles %s", url, roles) |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 145 | |
| 146 | |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 147 | class SleepStage(Stage): |
| 148 | """Save nodes list to file""" |
| 149 | |
| 150 | priority = StepOrder.TEST |
| 151 | config_block = 'sleep' |
| 152 | |
| 153 | def run(self, ctx: TestRun) -> None: |
| 154 | logger.debug("Will sleep for %r seconds", ctx.config.sleep) |
| 155 | time.sleep(ctx.config.sleep) |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 156 | |
| 157 | |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 158 | class PrepareNodes(Stage): |
| 159 | priority = StepOrder.START_SENSORS - 1 |
| 160 | |
| 161 | def __init__(self): |
| 162 | Stage.__init__(self) |
| 163 | self.nodeepscrub_updated = False |
| 164 | self.noscrub_updated = False |
| 165 | |
| 166 | def run(self, ctx: TestRun) -> None: |
| 167 | ceph_sett = ctx.config.get('ceph_settings', "").split() |
| 168 | if ceph_sett: |
| 169 | for node in ctx.nodes: |
| 170 | if "ceph-mon" in node.info.roles or "ceph-osd" in node.info.roles: |
| 171 | state = json.loads(node.run("ceph health --format json"))["summary"]["summary"] |
| 172 | if 'noscrub' in ceph_sett: |
| 173 | if 'noscrub' in state: |
| 174 | logger.debug("noscrub already set on cluster") |
| 175 | else: |
| 176 | logger.info("Applying noscrub settings to ceph cluster") |
| 177 | node.run("ceph osd set noscrub") |
| 178 | self.noscrub_updated = True |
| 179 | |
| 180 | if 'nodeepscrub' in ceph_sett: |
| 181 | if 'nodeepscrub' in state: |
| 182 | logger.debug("noscrub already set on cluster") |
| 183 | else: |
| 184 | logger.info("Applying noscrub settings to ceph cluster") |
| 185 | node.run("ceph osd set noscrub") |
| 186 | self.nodeepscrub_updated = True |
| 187 | break |
| 188 | |
| 189 | def cleanup(self, ctx: TestRun) -> None: |
| 190 | if self.nodeepscrub_updated or self.noscrub_updated: |
| 191 | for node in ctx.nodes: |
| 192 | if "ceph-mon" in node.info.roles or "ceph-osd" in node.info.roles : |
| 193 | if self.noscrub_updated: |
| 194 | logger.info("Reverting noscrub setting for ceph cluster") |
| 195 | node.run("ceph osd unset noscrub") |
| 196 | self.noscrub_updated = False |
| 197 | |
| 198 | if self.nodeepscrub_updated: |
| 199 | logger.info("Reverting noscrub setting for ceph cluster") |
| 200 | node.run("ceph osd unset nodeepscrub") |
| 201 | self.nodeepscrub_updated = False |
| 202 | |
| 203 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 204 | class RunTestsStage(Stage): |
| 205 | |
| 206 | priority = StepOrder.TEST |
| 207 | config_block = 'tests' |
| 208 | |
| 209 | def run(self, ctx: TestRun) -> None: |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 210 | if ctx.config.no_tests: |
| 211 | logger.info("Skiping tests, as 'no_tests' config settings is True") |
| 212 | return |
koder aka kdanilov | 3d2bc4f | 2016-11-12 18:31:18 +0200 | [diff] [blame] | 213 | |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 214 | for suite_idx, test_suite in enumerate(ctx.config.get('tests', [])): |
| 215 | test_nodes = [node for node in ctx.nodes if 'testnode' in node.info.roles] |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 216 | |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 217 | if not test_nodes: |
| 218 | logger.error("No test nodes found") |
| 219 | raise StopTestError() |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 220 | |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 221 | if len(test_suite) != 1: |
| 222 | logger.error("Test suite %s contain more than one test. Put each test in separated group", suite_idx) |
| 223 | raise StopTestError() |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 224 | |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 225 | name, params = list(test_suite.items())[0] |
| 226 | vm_count = params.get('node_limit', None) # type: Optional[int] |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 227 | |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 228 | # select test nodes |
| 229 | if vm_count is None: |
| 230 | curr_test_nodes = test_nodes |
| 231 | else: |
| 232 | curr_test_nodes = test_nodes[:vm_count] |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 233 | |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 234 | if not curr_test_nodes: |
| 235 | logger.error("No nodes found for test, skipping it.") |
| 236 | continue |
| 237 | |
kdanylov aka koder | 150b219 | 2017-04-01 16:53:01 +0300 | [diff] [blame] | 238 | if name not in all_suits: |
| 239 | logger.error("Test suite %r not found. Only suits [%s] available", name, ", ".join(all_suits)) |
| 240 | raise StopTestError() |
| 241 | |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 242 | test_cls = all_suits[name] |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 243 | remote_dir = ctx.config.default_test_local_folder.format(name=name, uuid=ctx.config.run_uuid) |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame] | 244 | suite = SuiteConfig(test_cls.name, |
| 245 | params=params, |
| 246 | run_uuid=ctx.config.run_uuid, |
| 247 | nodes=test_nodes, |
| 248 | remote_dir=remote_dir, |
| 249 | idx=suite_idx, |
| 250 | keep_raw_files=ctx.config.keep_raw_files) |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 251 | |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 252 | test_cls(storage=ResultStorage(ctx.storage), |
| 253 | suite=suite, |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 254 | on_idle=lambda: collect_sensors_data(ctx, False)).run() |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 255 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 256 | @classmethod |
| 257 | def validate_config(cls, cfg: ConfigBlock) -> None: |
| 258 | pass |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 259 | |
| 260 | |
kdanylov aka koder | 736e5c1 | 2017-05-07 17:27:14 +0300 | [diff] [blame^] | 261 | class SaveNodesStage(Stage): |
| 262 | """Save nodes list to file""" |
| 263 | nodes_path = 'all_nodes' |
| 264 | params_path = 'all_nodes_params.js' |
| 265 | priority = StepOrder.UPDATE_NODES_INFO + 1 |
| 266 | |
| 267 | def run(self, ctx: TestRun) -> None: |
| 268 | infos = list(ctx.nodes_info.values()) |
| 269 | params = {node.node_id: node.params for node in infos} |
| 270 | ninfos = [copy.copy(node) for node in infos] |
| 271 | for node in ninfos: |
| 272 | node.params = "in {!r} file".format(self.params_path) |
| 273 | ctx.storage.put_list(ninfos, self.nodes_path) |
| 274 | ctx.storage.put_raw(json.dumps(params).encode('utf8'), self.params_path) |
| 275 | |
| 276 | |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 277 | class LoadStoredNodesStage(Stage): |
| 278 | priority = StepOrder.DISCOVER |
| 279 | |
| 280 | def run(self, ctx: TestRun) -> None: |
kdanylov aka koder | 736e5c1 | 2017-05-07 17:27:14 +0300 | [diff] [blame^] | 281 | if SaveNodesStage.nodes_path in ctx.storage: |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 282 | if ctx.nodes_info: |
| 283 | logger.error("Internal error: Some nodes already stored in " + |
| 284 | "nodes_info before LoadStoredNodesStage stage") |
| 285 | raise StopTestError() |
kdanylov aka koder | 736e5c1 | 2017-05-07 17:27:14 +0300 | [diff] [blame^] | 286 | |
| 287 | nodes = {node.node_id: node for node in ctx.storage.load_list(NodeInfo, SaveNodesStage.nodes_path)} |
| 288 | |
| 289 | if SaveNodesStage.params_path in ctx.storage: |
| 290 | params = json.loads(ctx.storage.get_raw(SaveNodesStage.params_path).decode('utf8')) |
| 291 | for node_id, node in nodes.items(): |
| 292 | node.params = params.get(node_id, {}) |
| 293 | |
| 294 | ctx.nodes_info = nodes |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 295 | logger.info("%s nodes loaded from database", len(ctx.nodes_info)) |