gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 1 | import os |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 2 | import re |
koder aka kdanilov | 57ce4db | 2015-04-25 21:25:51 +0300 | [diff] [blame] | 3 | import time |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 4 | import logging |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 5 | import functools |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 6 | import contextlib |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 7 | import collections |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 8 | |
koder aka kdanilov | 88407ff | 2015-05-26 15:35:57 +0300 | [diff] [blame] | 9 | from yaml import load as _yaml_load |
| 10 | |
| 11 | try: |
| 12 | from yaml import CLoader |
| 13 | yaml_load = functools.partial(_yaml_load, Loader=CLoader) |
| 14 | except ImportError: |
| 15 | yaml_load = _yaml_load |
| 16 | |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 17 | from concurrent.futures import ThreadPoolExecutor |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 18 | |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 19 | from wally.hw_info import get_hw_info |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 20 | from wally.config import get_test_files |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 21 | from wally.discover import discover, Node |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 22 | from wally import pretty_yaml, utils, report, ssh_utils, start_vms |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 23 | from wally.sensors_utils import with_sensors_util, sensors_info_util |
| 24 | |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 25 | from wally.suits.mysql import MysqlTest |
| 26 | from wally.suits.itest import TestConfig |
| 27 | from wally.suits.io.fio import IOPerfTest |
| 28 | from wally.suits.postgres import PgBenchTest |
| 29 | |
| 30 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 31 | TOOL_TYPE_MAPPER = { |
| 32 | "io": IOPerfTest, |
| 33 | "pgbench": PgBenchTest, |
| 34 | "mysql": MysqlTest, |
| 35 | } |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame] | 36 | |
koder aka kdanilov | 57ce4db | 2015-04-25 21:25:51 +0300 | [diff] [blame] | 37 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 38 | logger = logging.getLogger("wally") |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 39 | |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 40 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 41 | def connect_all(nodes, spawned_node=False): |
| 42 | """ |
| 43 | Connect to all nodes, log errors |
| 44 | nodes:[Node] - list of nodes |
| 45 | spawned_node:bool - whenever nodes is newly spawned VM |
| 46 | """ |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 47 | |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 48 | logger.info("Connecting to nodes") |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 49 | |
| 50 | conn_timeout = 240 if spawned_node else 30 |
| 51 | |
| 52 | def connect_ext(conn_url): |
| 53 | try: |
| 54 | return ssh_utils.connect(conn_url, conn_timeout=conn_timeout) |
| 55 | except Exception as exc: |
| 56 | logger.error("During connect to {0}: {1!s}".format(conn_url, exc)) |
| 57 | return None |
| 58 | |
| 59 | urls = [] |
| 60 | ssh_pref = "ssh://" |
| 61 | |
| 62 | for node in nodes: |
| 63 | if node.conn_url == 'local': |
| 64 | urls.append(node.conn_url) |
| 65 | elif node.conn_url.startswith(ssh_pref): |
| 66 | urls.append(node.conn_url[len(ssh_pref):]) |
| 67 | else: |
| 68 | msg = "Unknown url type {0}".format(node.conn_url) |
| 69 | logger.error(msg) |
| 70 | raise utils.StopTestError(msg) |
| 71 | |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 72 | with ThreadPoolExecutor(32) as pool: |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 73 | for node, conn in zip(nodes, pool.map(connect_ext, urls)): |
| 74 | node.connection = conn |
| 75 | |
| 76 | failed_testnodes = [] |
| 77 | failed_nodes = [] |
| 78 | |
| 79 | for node in nodes: |
| 80 | if node.connection is None: |
| 81 | if 'testnode' in node.roles: |
| 82 | failed_testnodes.append(node.get_conn_id()) |
| 83 | else: |
| 84 | failed_nodes.append(node.get_conn_id()) |
| 85 | |
| 86 | if failed_nodes != []: |
| 87 | msg = "Node(s) {0} would be excluded - can't connect" |
| 88 | logger.warning(msg.format(",".join(failed_nodes))) |
| 89 | |
| 90 | if failed_testnodes != []: |
| 91 | msg = "Can't connect to testnode(s) " + ",".join(failed_testnodes) |
| 92 | logger.error(msg) |
| 93 | raise utils.StopTestError(msg) |
| 94 | |
| 95 | if len(failed_nodes) == 0: |
| 96 | logger.info("All nodes connected successfully") |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 97 | |
| 98 | |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 99 | def collect_hw_info_stage(cfg, ctx): |
| 100 | if os.path.exists(cfg['hwreport_fname']): |
| 101 | msg = "{0} already exists. Skip hw info" |
| 102 | logger.info(msg.format(cfg['hwreport_fname'])) |
| 103 | return |
| 104 | |
| 105 | with ThreadPoolExecutor(32) as pool: |
| 106 | connections = (node.connection for node in ctx.nodes) |
| 107 | ctx.hw_info.extend(pool.map(get_hw_info, connections)) |
| 108 | |
| 109 | with open(cfg['hwreport_fname'], 'w') as hwfd: |
| 110 | for node, info in zip(ctx.nodes, ctx.hw_info): |
| 111 | hwfd.write("-" * 60 + "\n") |
| 112 | hwfd.write("Roles : " + ", ".join(node.roles) + "\n") |
| 113 | hwfd.write(str(info) + "\n") |
| 114 | hwfd.write("-" * 60 + "\n\n") |
| 115 | |
| 116 | if info.hostname is not None: |
| 117 | fname = os.path.join( |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 118 | cfg.hwinfo_directory, |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 119 | info.hostname + "_lshw.xml") |
| 120 | |
| 121 | with open(fname, "w") as fd: |
| 122 | fd.write(info.raw) |
| 123 | logger.info("Hardware report stored in " + cfg['hwreport_fname']) |
| 124 | logger.debug("Raw hardware info in " + cfg['hwinfo_directory'] + " folder") |
| 125 | |
| 126 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 127 | @contextlib.contextmanager |
| 128 | def suspend_vm_nodes_ctx(unused_nodes): |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 129 | pausable_nodes_ids = [node.os_vm_id for node in unused_nodes |
| 130 | if node.os_vm_id is not None] |
| 131 | non_pausable = len(unused_nodes) - len(pausable_nodes_ids) |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 132 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 133 | if 0 != non_pausable: |
| 134 | logger.warning("Can't pause {0} nodes".format( |
| 135 | non_pausable)) |
| 136 | |
| 137 | if len(pausable_nodes_ids) != 0: |
| 138 | logger.debug("Try to pause {0} unused nodes".format( |
| 139 | len(pausable_nodes_ids))) |
| 140 | start_vms.pause(pausable_nodes_ids) |
| 141 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 142 | try: |
| 143 | yield pausable_nodes_ids |
| 144 | finally: |
| 145 | if len(pausable_nodes_ids) != 0: |
| 146 | logger.debug("Unpausing {0} nodes".format( |
| 147 | len(pausable_nodes_ids))) |
| 148 | start_vms.unpause(pausable_nodes_ids) |
| 149 | |
| 150 | |
| 151 | def generate_result_dir_name(results, name, params): |
| 152 | # make a directory for results |
| 153 | all_tests_dirs = os.listdir(results) |
| 154 | |
| 155 | if 'name' in params: |
| 156 | dir_name = "{0}_{1}".format(name, params['name']) |
| 157 | else: |
| 158 | for idx in range(len(all_tests_dirs) + 1): |
| 159 | dir_name = "{0}_{1}".format(name, idx) |
| 160 | if dir_name not in all_tests_dirs: |
| 161 | break |
| 162 | else: |
| 163 | raise utils.StopTestError("Can't select directory for test results") |
| 164 | |
| 165 | return os.path.join(results, dir_name) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 166 | |
| 167 | |
| 168 | def run_tests(cfg, test_block, nodes): |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 169 | """ |
| 170 | Run test from test block |
| 171 | """ |
| 172 | test_nodes = [node for node in nodes if 'testnode' in node.roles] |
| 173 | not_test_nodes = [node for node in nodes if 'testnode' not in node.roles] |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 174 | |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 175 | if len(test_nodes) == 0: |
| 176 | logger.error("No test nodes found") |
| 177 | return |
| 178 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 179 | for name, params in test_block.items(): |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 180 | results = [] |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 181 | |
| 182 | # iterate over all node counts |
| 183 | limit = params.get('node_limit', len(test_nodes)) |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 184 | if isinstance(limit, (int, long)): |
| 185 | vm_limits = [limit] |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 186 | else: |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 187 | list_or_tpl = isinstance(limit, (tuple, list)) |
| 188 | all_ints = list_or_tpl and all(isinstance(climit, (int, long)) |
| 189 | for climit in limit) |
| 190 | if not all_ints: |
| 191 | msg = "'node_limit' parameter ion config should" + \ |
| 192 | "be either int or list if integers, not {0!r}".format(limit) |
| 193 | raise ValueError(msg) |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 194 | vm_limits = limit |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 195 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 196 | for vm_count in vm_limits: |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 197 | # select test nodes |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 198 | if vm_count == 'all': |
| 199 | curr_test_nodes = test_nodes |
| 200 | unused_nodes = [] |
| 201 | else: |
| 202 | curr_test_nodes = test_nodes[:vm_count] |
| 203 | unused_nodes = test_nodes[vm_count:] |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 204 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 205 | if 0 == len(curr_test_nodes): |
| 206 | continue |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 207 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 208 | results_path = generate_result_dir_name(cfg.results_storage, name, params) |
| 209 | utils.mkdirs_if_unxists(results_path) |
koder aka kdanilov | fd2cfa5 | 2015-05-20 03:17:42 +0300 | [diff] [blame] | 210 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 211 | # suspend all unused virtual nodes |
| 212 | if cfg.settings.get('suspend_unused_vms', True): |
| 213 | suspend_ctx = suspend_vm_nodes_ctx(unused_nodes) |
koder aka kdanilov | fd2cfa5 | 2015-05-20 03:17:42 +0300 | [diff] [blame] | 214 | else: |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 215 | suspend_ctx = utils.empty_ctx() |
koder aka kdanilov | fd2cfa5 | 2015-05-20 03:17:42 +0300 | [diff] [blame] | 216 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 217 | with suspend_ctx: |
| 218 | resumable_nodes_ids = [node.os_vm_id for node in curr_test_nodes |
| 219 | if node.os_vm_id is not None] |
koder aka kdanilov | fd2cfa5 | 2015-05-20 03:17:42 +0300 | [diff] [blame] | 220 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 221 | if len(resumable_nodes_ids) != 0: |
| 222 | logger.debug("Check and unpause {0} nodes".format( |
| 223 | len(resumable_nodes_ids))) |
| 224 | start_vms.unpause(resumable_nodes_ids) |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 225 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 226 | sens_nodes = curr_test_nodes + not_test_nodes |
| 227 | with sensors_info_util(cfg, sens_nodes) as sensor_data: |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 228 | test_cls = TOOL_TYPE_MAPPER[name] |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 229 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 230 | remote_dir = cfg.default_test_local_folder.format(name=name) |
| 231 | |
| 232 | test_cfg = TestConfig(test_cls.__name__, |
| 233 | params=params, |
| 234 | test_uuid=cfg.run_uuid, |
| 235 | nodes=test_nodes, |
| 236 | log_directory=results_path, |
| 237 | remote_dir=remote_dir) |
| 238 | |
| 239 | t_start = time.time() |
| 240 | res = test_cls(test_cfg).run() |
| 241 | t_end = time.time() |
| 242 | |
| 243 | # save sensor data |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 244 | if sensor_data is not None: |
| 245 | fname = "{0}_{1}.csv".format(int(t_start), int(t_end)) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 246 | fpath = os.path.join(cfg.sensor_storage, fname) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 247 | |
| 248 | with open(fpath, "w") as fd: |
| 249 | fd.write("\n\n".join(sensor_data)) |
| 250 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 251 | results.append(res) |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 252 | |
| 253 | yield name, results |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 254 | |
| 255 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 256 | def connect_stage(cfg, ctx): |
| 257 | ctx.clear_calls_stack.append(disconnect_stage) |
| 258 | connect_all(ctx.nodes) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 259 | ctx.nodes = [node for node in ctx.nodes if node.connection is not None] |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 260 | |
| 261 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 262 | def discover_stage(cfg, ctx): |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 263 | """ |
| 264 | discover clusters and nodes stage |
| 265 | """ |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 266 | if cfg.get('discover') is not None: |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 267 | discover_objs = [i.strip() for i in cfg.discover.strip().split(",")] |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 268 | |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 269 | nodes = discover(ctx, |
| 270 | discover_objs, |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 271 | cfg.clouds, |
| 272 | cfg.results_storage, |
| 273 | not cfg.dont_discover_nodes) |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 274 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 275 | ctx.nodes.extend(nodes) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 276 | |
| 277 | for url, roles in cfg.get('explicit_nodes', {}).items(): |
| 278 | ctx.nodes.append(Node(url, roles.split(","))) |
| 279 | |
| 280 | |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 281 | def save_nodes_stage(cfg, ctx): |
| 282 | cluster = {} |
| 283 | for node in ctx.nodes: |
| 284 | roles = node.roles[:] |
| 285 | if 'testnode' in roles: |
| 286 | roles.remove('testnode') |
| 287 | |
| 288 | if len(roles) != 0: |
| 289 | cluster[node.conn_url] = roles |
| 290 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 291 | with open(cfg.nodes_report_file, "w") as fd: |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 292 | fd.write(pretty_yaml.dumps(cluster)) |
| 293 | |
| 294 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 295 | def reuse_vms_stage(cfg, ctx): |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 296 | vms_patterns = cfg.get('clouds', {}).get('openstack', {}).get('vms', []) |
| 297 | private_key_path = get_vm_keypair(cfg)['keypair_file_private'] |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 298 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 299 | for creds in vms_patterns: |
| 300 | user_name, vm_name_pattern = creds.split("@", 1) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 301 | msg = "Vm like {0} lookup failed".format(vm_name_pattern) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 302 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 303 | with utils.log_error(msg): |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 304 | msg = "Looking for vm with name like {0}".format(vm_name_pattern) |
| 305 | logger.debug(msg) |
| 306 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 307 | if not start_vms.is_connected(): |
| 308 | os_creds = get_OS_credentials(cfg, ctx) |
| 309 | else: |
| 310 | os_creds = {} |
| 311 | |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 312 | conn = start_vms.nova_connect(**os_creds) |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 313 | for ip, vm_id in start_vms.find_vms(conn, vm_name_pattern): |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 314 | conn_url = "ssh://{user}@{ip}::{key}".format(user=user_name, |
| 315 | ip=ip, |
| 316 | key=private_key_path) |
| 317 | node = Node(conn_url, ['testnode']) |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 318 | node.os_vm_id = vm_id |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 319 | ctx.nodes.append(node) |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 320 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 321 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 322 | def get_OS_credentials(cfg, ctx): |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 323 | creds = None |
koder aka kdanilov | fd2cfa5 | 2015-05-20 03:17:42 +0300 | [diff] [blame] | 324 | tenant = None |
| 325 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 326 | if 'openstack' in cfg.clouds: |
| 327 | os_cfg = cfg.clouds['openstack'] |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 328 | if 'OPENRC' in os_cfg: |
| 329 | logger.info("Using OS credentials from " + os_cfg['OPENRC']) |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 330 | user, passwd, tenant, auth_url = utils.get_creds_openrc(os_cfg['OPENRC']) |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 331 | elif 'ENV' in os_cfg: |
| 332 | logger.info("Using OS credentials from shell environment") |
| 333 | user, passwd, tenant, auth_url = start_vms.ostack_get_creds() |
koder aka kdanilov | fd2cfa5 | 2015-05-20 03:17:42 +0300 | [diff] [blame] | 334 | elif 'OS_TENANT_NAME' in os_cfg: |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 335 | logger.info("Using predefined credentials") |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 336 | tenant = os_cfg['OS_TENANT_NAME'].strip() |
| 337 | user = os_cfg['OS_USERNAME'].strip() |
| 338 | passwd = os_cfg['OS_PASSWORD'].strip() |
| 339 | auth_url = os_cfg['OS_AUTH_URL'].strip() |
| 340 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 341 | if tenant is None and 'fuel' in cfg.clouds and \ |
| 342 | 'openstack_env' in cfg.clouds['fuel'] and \ |
koder aka kdanilov | 88407ff | 2015-05-26 15:35:57 +0300 | [diff] [blame] | 343 | ctx.fuel_openstack_creds is not None: |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 344 | logger.info("Using fuel creds") |
| 345 | creds = ctx.fuel_openstack_creds |
koder aka kdanilov | fd2cfa5 | 2015-05-20 03:17:42 +0300 | [diff] [blame] | 346 | elif tenant is None: |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 347 | logger.error("Can't found OS credentials") |
| 348 | raise utils.StopTestError("Can't found OS credentials", None) |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 349 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 350 | if creds is None: |
| 351 | creds = {'name': user, |
| 352 | 'passwd': passwd, |
| 353 | 'tenant': tenant, |
| 354 | 'auth_url': auth_url} |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 355 | |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 356 | logger.debug("OS_CREDS: user={name} tenant={tenant} auth_url={auth_url}".format(**creds)) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 357 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 358 | return creds |
koder aka kdanilov | 4e9f3ed | 2015-04-14 11:26:12 +0300 | [diff] [blame] | 359 | |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 360 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 361 | def get_vm_keypair(cfg): |
| 362 | res = {} |
| 363 | for field, ext in (('keypair_file_private', 'pem'), |
| 364 | ('keypair_file_public', 'pub')): |
| 365 | fpath = cfg.vm_configs.get(field) |
| 366 | |
| 367 | if fpath is None: |
| 368 | fpath = cfg.vm_configs['keypair_name'] + "." + ext |
| 369 | |
| 370 | if os.path.isabs(fpath): |
| 371 | res[field] = fpath |
| 372 | else: |
| 373 | res[field] = os.path.join(cfg.config_folder, fpath) |
| 374 | return res |
| 375 | |
| 376 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 377 | @contextlib.contextmanager |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 378 | def create_vms_ctx(ctx, cfg, config, already_has_count=0): |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 379 | if config['count'].startswith('='): |
| 380 | count = int(config['count'][1:]) |
| 381 | if count <= already_has_count: |
| 382 | logger.debug("Not need new vms") |
| 383 | yield [] |
| 384 | return |
| 385 | |
| 386 | params = cfg.vm_configs[config['cfg_name']].copy() |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 387 | os_nodes_ids = [] |
| 388 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 389 | if not start_vms.is_connected(): |
| 390 | os_creds = get_OS_credentials(cfg, ctx) |
| 391 | else: |
| 392 | os_creds = {} |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 393 | |
| 394 | nova = start_vms.nova_connect(**os_creds) |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 395 | |
koder aka kdanilov | c368eb6 | 2015-04-28 18:22:01 +0300 | [diff] [blame] | 396 | params.update(config) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 397 | params.update(get_vm_keypair(cfg)) |
koder aka kdanilov | fd2cfa5 | 2015-05-20 03:17:42 +0300 | [diff] [blame] | 398 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 399 | params['group_name'] = cfg.run_uuid |
| 400 | params['keypair_name'] = cfg.vm_configs['keypair_name'] |
koder aka kdanilov | c368eb6 | 2015-04-28 18:22:01 +0300 | [diff] [blame] | 401 | |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 402 | if not config.get('skip_preparation', False): |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 403 | logger.info("Preparing openstack") |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 404 | start_vms.prepare_os_subpr(nova, params=params, **os_creds) |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 405 | |
| 406 | new_nodes = [] |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 407 | old_nodes = ctx.nodes[:] |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 408 | try: |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 409 | for new_node, node_id in start_vms.launch_vms(params, already_has_count): |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 410 | new_node.roles.append('testnode') |
| 411 | ctx.nodes.append(new_node) |
| 412 | os_nodes_ids.append(node_id) |
| 413 | new_nodes.append(new_node) |
| 414 | |
| 415 | store_nodes_in_log(cfg, os_nodes_ids) |
| 416 | ctx.openstack_nodes_ids = os_nodes_ids |
| 417 | |
| 418 | yield new_nodes |
| 419 | |
| 420 | finally: |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 421 | if not cfg.keep_vm: |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 422 | shut_down_vms_stage(cfg, ctx) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 423 | ctx.nodes = old_nodes |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 424 | |
| 425 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 426 | def run_tests_stage(cfg, ctx): |
koder aka kdanilov | fd2cfa5 | 2015-05-20 03:17:42 +0300 | [diff] [blame] | 427 | ctx.results = collections.defaultdict(lambda: []) |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 428 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 429 | for group in cfg.get('tests', []): |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 430 | |
koder aka kdanilov | 170936a | 2015-06-27 22:51:17 +0300 | [diff] [blame] | 431 | if len(group.items()) != 1: |
| 432 | msg = "Items in tests section should have len == 1" |
| 433 | logger.error(msg) |
| 434 | raise utils.StopTestError(msg) |
| 435 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 436 | key, config = group.items()[0] |
| 437 | |
| 438 | if 'start_test_nodes' == key: |
koder aka kdanilov | c368eb6 | 2015-04-28 18:22:01 +0300 | [diff] [blame] | 439 | if 'openstack' not in config: |
| 440 | msg = "No openstack block in config - can't spawn vm's" |
| 441 | logger.error(msg) |
| 442 | raise utils.StopTestError(msg) |
| 443 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 444 | num_test_nodes = 0 |
| 445 | for node in ctx.nodes: |
| 446 | if 'testnode' in node.roles: |
| 447 | num_test_nodes += 1 |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 448 | |
| 449 | vm_ctx = create_vms_ctx(ctx, cfg, config['openstack'], |
| 450 | num_test_nodes) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 451 | tests = config.get('tests', []) |
| 452 | else: |
| 453 | vm_ctx = utils.empty_ctx([]) |
| 454 | tests = [group] |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 455 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 456 | if cfg.get('sensors') is None: |
| 457 | sensor_ctx = utils.empty_ctx() |
| 458 | else: |
| 459 | sensor_ctx = with_sensors_util(cfg.get('sensors'), ctx.nodes) |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 460 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 461 | with vm_ctx as new_nodes: |
| 462 | if len(new_nodes) != 0: |
| 463 | connect_all(new_nodes, True) |
| 464 | |
| 465 | if not cfg.no_tests: |
| 466 | for test_group in tests: |
| 467 | with sensor_ctx: |
koder aka kdanilov | fd2cfa5 | 2015-05-20 03:17:42 +0300 | [diff] [blame] | 468 | for tp, res in run_tests(cfg, test_group, ctx.nodes): |
| 469 | ctx.results[tp].extend(res) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 470 | |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 471 | |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 472 | def shut_down_vms_stage(cfg, ctx): |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 473 | vm_ids_fname = cfg.vm_ids_fname |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 474 | if ctx.openstack_nodes_ids is None: |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 475 | nodes_ids = open(vm_ids_fname).read().split() |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 476 | else: |
| 477 | nodes_ids = ctx.openstack_nodes_ids |
| 478 | |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 479 | if len(nodes_ids) != 0: |
| 480 | logger.info("Removing nodes") |
| 481 | start_vms.clear_nodes(nodes_ids) |
| 482 | logger.info("Nodes has been removed") |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 483 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 484 | if os.path.exists(vm_ids_fname): |
| 485 | os.remove(vm_ids_fname) |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 486 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 487 | |
| 488 | def store_nodes_in_log(cfg, nodes_ids): |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 489 | with open(cfg.vm_ids_fname, 'w') as fd: |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 490 | fd.write("\n".join(nodes_ids)) |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 491 | |
| 492 | |
| 493 | def clear_enviroment(cfg, ctx): |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 494 | if os.path.exists(cfg.vm_ids_fname): |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 495 | shut_down_vms_stage(cfg, ctx) |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 496 | |
| 497 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 498 | def disconnect_stage(cfg, ctx): |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 499 | ssh_utils.close_all_sessions() |
| 500 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 501 | for node in ctx.nodes: |
| 502 | if node.connection is not None: |
| 503 | node.connection.close() |
| 504 | |
| 505 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 506 | def store_raw_results_stage(cfg, ctx): |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 507 | if os.path.exists(cfg.raw_results): |
| 508 | cont = yaml_load(open(cfg.raw_results).read()) |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 509 | else: |
| 510 | cont = [] |
| 511 | |
koder aka kdanilov | fd2cfa5 | 2015-05-20 03:17:42 +0300 | [diff] [blame] | 512 | cont.extend(utils.yamable(ctx.results).items()) |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 513 | raw_data = pretty_yaml.dumps(cont) |
| 514 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 515 | with open(cfg.raw_results, "w") as fd: |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 516 | fd.write(raw_data) |
| 517 | |
| 518 | |
| 519 | def console_report_stage(cfg, ctx): |
koder aka kdanilov | fd2cfa5 | 2015-05-20 03:17:42 +0300 | [diff] [blame] | 520 | first_report = True |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 521 | text_rep_fname = cfg.text_report_file |
koder aka kdanilov | fd2cfa5 | 2015-05-20 03:17:42 +0300 | [diff] [blame] | 522 | with open(text_rep_fname, "w") as fd: |
| 523 | for tp, data in ctx.results.items(): |
| 524 | if 'io' == tp and data is not None: |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 525 | rep_lst = [] |
| 526 | for result in data: |
| 527 | rep_lst.append( |
| 528 | IOPerfTest.format_for_console(list(result))) |
| 529 | rep = "\n\n".join(rep_lst) |
koder aka kdanilov | fd2cfa5 | 2015-05-20 03:17:42 +0300 | [diff] [blame] | 530 | elif tp in ['mysql', 'pgbench'] and data is not None: |
| 531 | rep = MysqlTest.format_for_console(data) |
| 532 | else: |
| 533 | logger.warning("Can't generate text report for " + tp) |
| 534 | continue |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 535 | |
koder aka kdanilov | fd2cfa5 | 2015-05-20 03:17:42 +0300 | [diff] [blame] | 536 | fd.write(rep) |
| 537 | fd.write("\n") |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 538 | |
koder aka kdanilov | fd2cfa5 | 2015-05-20 03:17:42 +0300 | [diff] [blame] | 539 | if first_report: |
| 540 | logger.info("Text report were stored in " + text_rep_fname) |
| 541 | first_report = False |
| 542 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 543 | print("\n" + rep + "\n") |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 544 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 545 | |
koder aka kdanilov | 88407ff | 2015-05-26 15:35:57 +0300 | [diff] [blame] | 546 | def test_load_report_stage(cfg, ctx): |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 547 | load_rep_fname = cfg.load_report_file |
koder aka kdanilov | 88407ff | 2015-05-26 15:35:57 +0300 | [diff] [blame] | 548 | found = False |
| 549 | for idx, (tp, data) in enumerate(ctx.results.items()): |
| 550 | if 'io' == tp and data is not None: |
| 551 | if found: |
| 552 | logger.error("Making reports for more than one " + |
| 553 | "io block isn't supported! All " + |
| 554 | "report, except first are skipped") |
| 555 | continue |
| 556 | found = True |
| 557 | report.make_load_report(idx, cfg['results'], load_rep_fname) |
| 558 | |
| 559 | |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 560 | def html_report_stage(cfg, ctx): |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 561 | html_rep_fname = cfg.html_report_file |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 562 | found = False |
koder aka kdanilov | fd2cfa5 | 2015-05-20 03:17:42 +0300 | [diff] [blame] | 563 | for tp, data in ctx.results.items(): |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 564 | if 'io' == tp and data is not None: |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 565 | if found or len(data) > 1: |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 566 | logger.error("Making reports for more than one " + |
| 567 | "io block isn't supported! All " + |
| 568 | "report, except first are skipped") |
| 569 | continue |
| 570 | found = True |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 571 | report.make_io_report(list(data[0]), |
koder aka kdanilov | 88407ff | 2015-05-26 15:35:57 +0300 | [diff] [blame] | 572 | cfg.get('comment', ''), |
| 573 | html_rep_fname, |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 574 | lab_info=ctx.hw_info) |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 575 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 576 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 577 | def load_data_from_path(test_res_dir): |
| 578 | files = get_test_files(test_res_dir) |
| 579 | raw_res = yaml_load(open(files['raw_results']).read()) |
| 580 | res = collections.defaultdict(lambda: []) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 581 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame^] | 582 | for tp, test_lists in raw_res: |
| 583 | for tests in test_lists: |
| 584 | for suite_name, suite_data in tests.items(): |
| 585 | result_folder = suite_data[0] |
| 586 | res[tp].append(TOOL_TYPE_MAPPER[tp].load(suite_name, result_folder)) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 587 | |
koder aka kdanilov | 6b87266 | 2015-06-23 01:58:36 +0300 | [diff] [blame] | 588 | return res |
| 589 | |
| 590 | |
| 591 | def load_data_from_path_stage(var_dir, _, ctx): |
| 592 | for tp, vals in load_data_from_path(var_dir).items(): |
| 593 | ctx.results.setdefault(tp, []).extend(vals) |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 594 | |
| 595 | |
koder aka kdanilov | 88407ff | 2015-05-26 15:35:57 +0300 | [diff] [blame] | 596 | def load_data_from(var_dir): |
koder aka kdanilov | 6b87266 | 2015-06-23 01:58:36 +0300 | [diff] [blame] | 597 | return functools.partial(load_data_from_path_stage, var_dir) |