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