koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 1 | from __future__ import print_function |
| 2 | |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 3 | import os |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 4 | import sys |
koder aka kdanilov | 57ce4db | 2015-04-25 21:25:51 +0300 | [diff] [blame] | 5 | import time |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 6 | import Queue |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 7 | import pprint |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 8 | import signal |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 9 | import logging |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 10 | import argparse |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 11 | import functools |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 12 | import threading |
koder aka kdanilov | 7306c64 | 2015-04-23 15:29:45 +0300 | [diff] [blame] | 13 | import subprocess |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 14 | import contextlib |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 15 | import collections |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 16 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 17 | import yaml |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 18 | import faulthandler |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 19 | from concurrent.futures import ThreadPoolExecutor |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 20 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 21 | from wally import pretty_yaml |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 22 | from wally.hw_info import get_hw_info |
| 23 | from wally.discover import discover, Node |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame] | 24 | from wally.timeseries import SensorDatastore |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 25 | from wally import utils, report, ssh_utils, start_vms |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 26 | from wally.config import cfg_dict, load_config, setup_loggers |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 27 | from wally.suits.itest import IOPerfTest, PgBenchTest, MysqlTest |
| 28 | from wally.sensors_utils import deploy_sensors_stage, gather_sensors_stage |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame] | 29 | |
koder aka kdanilov | 57ce4db | 2015-04-25 21:25:51 +0300 | [diff] [blame] | 30 | |
| 31 | try: |
| 32 | from wally import webui |
| 33 | except ImportError: |
| 34 | webui = None |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 35 | |
| 36 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 37 | logger = logging.getLogger("wally") |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 38 | |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 39 | |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 40 | def format_result(res, formatter): |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 41 | data = "\n{0}\n".format("=" * 80) |
| 42 | data += pprint.pformat(res) + "\n" |
| 43 | data += "{0}\n".format("=" * 80) |
koder aka kdanilov | fe05662 | 2015-02-19 08:46:15 -0800 | [diff] [blame] | 44 | templ = "{0}\n\n====> {1}\n\n{2}\n\n" |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 45 | return templ.format(data, formatter(res), "=" * 80) |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 46 | |
| 47 | |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 48 | class Context(object): |
| 49 | def __init__(self): |
| 50 | self.build_meta = {} |
| 51 | self.nodes = [] |
| 52 | self.clear_calls_stack = [] |
| 53 | self.openstack_nodes_ids = [] |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 54 | self.sensors_mon_q = None |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 55 | self.hw_info = [] |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 56 | |
| 57 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 58 | def connect_one(node, vm=False): |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 59 | if node.conn_url == 'local': |
| 60 | node.connection = ssh_utils.connect(node.conn_url) |
| 61 | return |
| 62 | |
koder aka kdanilov | 5d589b4 | 2015-03-26 12:25:51 +0200 | [diff] [blame] | 63 | try: |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 64 | ssh_pref = "ssh://" |
| 65 | if node.conn_url.startswith(ssh_pref): |
| 66 | url = node.conn_url[len(ssh_pref):] |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 67 | |
| 68 | if vm: |
koder aka kdanilov | 6b1341a | 2015-04-21 22:44:21 +0300 | [diff] [blame] | 69 | conn_timeout = 240 |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 70 | else: |
koder aka kdanilov | 6b1341a | 2015-04-21 22:44:21 +0300 | [diff] [blame] | 71 | conn_timeout = 30 |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 72 | |
| 73 | node.connection = ssh_utils.connect(url, |
koder aka kdanilov | 6b1341a | 2015-04-21 22:44:21 +0300 | [diff] [blame] | 74 | conn_timeout=conn_timeout) |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 75 | else: |
| 76 | raise ValueError("Unknown url type {0}".format(node.conn_url)) |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 77 | except Exception as exc: |
| 78 | # logger.exception("During connect to " + node.get_conn_id()) |
koder aka kdanilov | ec1b973 | 2015-04-23 20:43:29 +0300 | [diff] [blame] | 79 | msg = "During connect to {0}: {1!s}".format(node.get_conn_id(), |
| 80 | exc) |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 81 | logger.error(msg) |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 82 | node.connection = None |
koder aka kdanilov | 5d589b4 | 2015-03-26 12:25:51 +0200 | [diff] [blame] | 83 | |
| 84 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 85 | def connect_all(nodes, vm=False): |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 86 | logger.info("Connecting to nodes") |
| 87 | with ThreadPoolExecutor(32) as pool: |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 88 | connect_one_f = functools.partial(connect_one, vm=vm) |
| 89 | list(pool.map(connect_one_f, nodes)) |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 90 | |
| 91 | |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 92 | def collect_hw_info_stage(cfg, ctx): |
| 93 | if os.path.exists(cfg['hwreport_fname']): |
| 94 | msg = "{0} already exists. Skip hw info" |
| 95 | logger.info(msg.format(cfg['hwreport_fname'])) |
| 96 | return |
| 97 | |
| 98 | with ThreadPoolExecutor(32) as pool: |
| 99 | connections = (node.connection for node in ctx.nodes) |
| 100 | ctx.hw_info.extend(pool.map(get_hw_info, connections)) |
| 101 | |
| 102 | with open(cfg['hwreport_fname'], 'w') as hwfd: |
| 103 | for node, info in zip(ctx.nodes, ctx.hw_info): |
| 104 | hwfd.write("-" * 60 + "\n") |
| 105 | hwfd.write("Roles : " + ", ".join(node.roles) + "\n") |
| 106 | hwfd.write(str(info) + "\n") |
| 107 | hwfd.write("-" * 60 + "\n\n") |
| 108 | |
| 109 | if info.hostname is not None: |
| 110 | fname = os.path.join( |
| 111 | cfg_dict['hwinfo_directory'], |
| 112 | info.hostname + "_lshw.xml") |
| 113 | |
| 114 | with open(fname, "w") as fd: |
| 115 | fd.write(info.raw) |
| 116 | logger.info("Hardware report stored in " + cfg['hwreport_fname']) |
| 117 | logger.debug("Raw hardware info in " + cfg['hwinfo_directory'] + " folder") |
| 118 | |
| 119 | |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 120 | def test_thread(test, node, barrier, res_q): |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 121 | exc = None |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 122 | try: |
koder aka kdanilov | a047e1b | 2015-04-21 23:16:59 +0300 | [diff] [blame] | 123 | logger.debug("Run preparation for {0}".format(node.get_conn_id())) |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 124 | test.pre_run() |
koder aka kdanilov | a047e1b | 2015-04-21 23:16:59 +0300 | [diff] [blame] | 125 | logger.debug("Run test for {0}".format(node.get_conn_id())) |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 126 | test.run(barrier) |
koder aka kdanilov | e2de58c | 2015-04-24 22:59:36 +0300 | [diff] [blame] | 127 | except utils.StopTestError as exc: |
| 128 | pass |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 129 | except Exception as exc: |
koder aka kdanilov | e2de58c | 2015-04-24 22:59:36 +0300 | [diff] [blame] | 130 | msg = "In test {0} for node {1}" |
| 131 | msg = msg.format(test, node.get_conn_id()) |
| 132 | logger.exception(msg) |
| 133 | exc = utils.StopTestError(msg, exc) |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 134 | |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 135 | try: |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 136 | test.cleanup() |
koder aka kdanilov | e2de58c | 2015-04-24 22:59:36 +0300 | [diff] [blame] | 137 | except utils.StopTestError as exc1: |
| 138 | if exc is None: |
| 139 | exc = exc1 |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 140 | except: |
| 141 | msg = "Duringf cleanup - in test {0} for node {1}" |
| 142 | logger.exception(msg.format(test, node)) |
| 143 | |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 144 | if exc is not None: |
| 145 | res_q.put(exc) |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 146 | |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 147 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 148 | def run_single_test(test_nodes, name, test_cls, params, |
| 149 | test_local_folder, run_uuid, counter=[0]): |
| 150 | logger.info("Starting {0} tests".format(name)) |
| 151 | res_q = Queue.Queue() |
| 152 | threads = [] |
| 153 | coord_q = Queue.Queue() |
| 154 | rem_folder = test_local_folder.format(name=name) |
| 155 | |
| 156 | barrier = utils.Barrier(len(test_nodes)) |
| 157 | for idx, node in enumerate(test_nodes): |
| 158 | msg = "Starting {0} test on {1} node" |
| 159 | logger.debug(msg.format(name, node.conn_url)) |
| 160 | |
| 161 | dname = "{0}_{1}_{2}".format(name, counter[0], node.get_ip()) |
| 162 | counter[0] += 1 |
| 163 | dr = os.path.join(cfg_dict['test_log_directory'], dname) |
| 164 | |
| 165 | if not os.path.exists(dr): |
| 166 | os.makedirs(dr) |
| 167 | |
| 168 | params = params.copy() |
| 169 | params['testnodes_count'] = len(test_nodes) |
| 170 | test = test_cls(options=params, |
| 171 | is_primary=(idx == 0), |
| 172 | on_result_cb=res_q.put, |
| 173 | test_uuid=run_uuid, |
| 174 | node=node, |
| 175 | remote_dir=rem_folder, |
| 176 | log_directory=dr, |
| 177 | coordination_queue=coord_q) |
| 178 | th = threading.Thread(None, test_thread, None, |
| 179 | (test, node, barrier, res_q)) |
| 180 | threads.append(th) |
| 181 | th.daemon = True |
| 182 | th.start() |
| 183 | |
| 184 | th = threading.Thread(None, test_cls.coordination_th, None, |
| 185 | (coord_q, barrier, len(threads))) |
| 186 | threads.append(th) |
| 187 | th.daemon = True |
| 188 | th.start() |
| 189 | |
| 190 | results = [] |
| 191 | coord_q.put(None) |
| 192 | |
| 193 | while len(threads) != 0: |
| 194 | nthreads = [] |
| 195 | |
| 196 | for th in threads: |
| 197 | if not th.is_alive(): |
| 198 | th.join() |
| 199 | else: |
| 200 | nthreads.append(th) |
| 201 | |
| 202 | threads = nthreads |
| 203 | |
| 204 | while not res_q.empty(): |
| 205 | val = res_q.get() |
| 206 | |
| 207 | if isinstance(val, utils.StopTestError): |
| 208 | raise val |
| 209 | |
| 210 | if isinstance(val, Exception): |
| 211 | msg = "Exception during test execution: {0!s}" |
| 212 | raise ValueError(msg.format(val)) |
| 213 | |
| 214 | results.append(val) |
| 215 | |
| 216 | results = test_cls.merge_results(results) |
| 217 | return results |
| 218 | |
| 219 | |
koder aka kdanilov | 2066daf | 2015-04-23 21:05:41 +0300 | [diff] [blame] | 220 | def run_tests(cfg, test_block, nodes): |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 221 | tool_type_mapper = { |
| 222 | "io": IOPerfTest, |
| 223 | "pgbench": PgBenchTest, |
Yulia Portnova | b1a1507 | 2015-05-06 14:59:25 +0300 | [diff] [blame] | 224 | "mysql": MysqlTest, |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | test_nodes = [node for node in nodes |
| 228 | if 'testnode' in node.roles] |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 229 | if len(test_nodes) == 0: |
| 230 | logger.error("No test nodes found") |
| 231 | return |
| 232 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 233 | for name, params in test_block.items(): |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 234 | results = [] |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 235 | limit = params.get('node_limit') |
| 236 | if isinstance(limit, (int, long)): |
| 237 | vm_limits = [limit] |
| 238 | elif limit is None: |
| 239 | vm_limits = [len(test_nodes)] |
| 240 | else: |
| 241 | vm_limits = limit |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 242 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 243 | for vm_count in vm_limits: |
| 244 | if vm_count == 'all': |
| 245 | curr_test_nodes = test_nodes |
| 246 | unused_nodes = [] |
| 247 | else: |
| 248 | curr_test_nodes = test_nodes[:vm_count] |
| 249 | unused_nodes = test_nodes[vm_count:] |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 250 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 251 | if 0 == len(curr_test_nodes): |
| 252 | continue |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 253 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 254 | if cfg.get('suspend_unused_vms', True): |
| 255 | pausable_nodes_ids = [node.os_vm_id for node in unused_nodes |
| 256 | if node.os_vm_id is not None] |
| 257 | non_pausable = len(unused_nodes) - len(pausable_nodes_ids) |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 258 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 259 | if 0 != non_pausable: |
| 260 | logger.warning("Can't pause {0} nodes".format( |
| 261 | non_pausable)) |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 262 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 263 | if len(pausable_nodes_ids) != 0: |
| 264 | logger.debug("Try to pause {0} unused nodes".format( |
| 265 | len(pausable_nodes_ids))) |
| 266 | start_vms.pause(pausable_nodes_ids) |
| 267 | |
| 268 | resumable_nodes_ids = [node.os_vm_id for node in curr_test_nodes |
| 269 | if node.os_vm_id is not None] |
| 270 | |
| 271 | if len(resumable_nodes_ids) != 0: |
| 272 | logger.debug("Check and unpause {0} nodes".format( |
| 273 | len(resumable_nodes_ids))) |
| 274 | start_vms.unpause(resumable_nodes_ids) |
| 275 | |
| 276 | test_cls = tool_type_mapper[name] |
| 277 | try: |
| 278 | res = run_single_test(curr_test_nodes, name, test_cls, |
| 279 | params, |
| 280 | cfg['default_test_local_folder'], |
| 281 | cfg['run_uuid']) |
| 282 | finally: |
| 283 | if cfg.get('suspend_unused_vms', True): |
| 284 | if len(pausable_nodes_ids) != 0: |
| 285 | logger.debug("Unpausing {0} nodes".format( |
| 286 | len(pausable_nodes_ids))) |
| 287 | start_vms.unpause(pausable_nodes_ids) |
| 288 | |
| 289 | results.append(res) |
| 290 | |
| 291 | yield name, results |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 292 | |
| 293 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 294 | def log_nodes_statistic(_, ctx): |
| 295 | nodes = ctx.nodes |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 296 | logger.info("Found {0} nodes total".format(len(nodes))) |
| 297 | per_role = collections.defaultdict(lambda: 0) |
| 298 | for node in nodes: |
| 299 | for role in node.roles: |
| 300 | per_role[role] += 1 |
| 301 | |
| 302 | for role, count in sorted(per_role.items()): |
| 303 | logger.debug("Found {0} nodes with role {1}".format(count, role)) |
| 304 | |
| 305 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 306 | def connect_stage(cfg, ctx): |
| 307 | ctx.clear_calls_stack.append(disconnect_stage) |
| 308 | connect_all(ctx.nodes) |
| 309 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 310 | all_ok = True |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 311 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 312 | for node in ctx.nodes: |
| 313 | if node.connection is None: |
| 314 | if 'testnode' in node.roles: |
| 315 | msg = "Can't connect to testnode {0}" |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 316 | msg = msg.format(node.get_conn_id()) |
| 317 | logger.error(msg) |
| 318 | raise utils.StopTestError(msg) |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 319 | else: |
| 320 | msg = "Node {0} would be excluded - can't connect" |
| 321 | logger.warning(msg.format(node.get_conn_id())) |
| 322 | all_ok = False |
| 323 | |
| 324 | if all_ok: |
| 325 | logger.info("All nodes connected successfully") |
| 326 | |
| 327 | ctx.nodes = [node for node in ctx.nodes |
| 328 | if node.connection is not None] |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 329 | |
| 330 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 331 | def discover_stage(cfg, ctx): |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 332 | if cfg.get('discover') is not None: |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 333 | discover_objs = [i.strip() for i in cfg['discover'].strip().split(",")] |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 334 | |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 335 | nodes = discover(ctx, |
| 336 | discover_objs, |
| 337 | cfg['clouds'], |
| 338 | cfg['var_dir'], |
| 339 | not cfg['dont_discover_nodes']) |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 340 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 341 | ctx.nodes.extend(nodes) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 342 | |
| 343 | for url, roles in cfg.get('explicit_nodes', {}).items(): |
| 344 | ctx.nodes.append(Node(url, roles.split(","))) |
| 345 | |
| 346 | |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 347 | def save_nodes_stage(cfg, ctx): |
| 348 | cluster = {} |
| 349 | for node in ctx.nodes: |
| 350 | roles = node.roles[:] |
| 351 | if 'testnode' in roles: |
| 352 | roles.remove('testnode') |
| 353 | |
| 354 | if len(roles) != 0: |
| 355 | cluster[node.conn_url] = roles |
| 356 | |
| 357 | with open(cfg['nodes_report_file'], "w") as fd: |
| 358 | fd.write(pretty_yaml.dumps(cluster)) |
| 359 | |
| 360 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 361 | def reuse_vms_stage(cfg, ctx): |
| 362 | p = cfg.get('clouds', {}) |
| 363 | p = p.get('openstack', {}) |
| 364 | p = p.get('vms', []) |
| 365 | |
| 366 | for creds in p: |
| 367 | vm_name_pattern, conn_pattern = creds.split(",") |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 368 | try: |
| 369 | msg = "Looking for vm with name like {0}".format(vm_name_pattern) |
| 370 | logger.debug(msg) |
| 371 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 372 | if not start_vms.is_connected(): |
| 373 | os_creds = get_OS_credentials(cfg, ctx) |
| 374 | else: |
| 375 | os_creds = {} |
| 376 | |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 377 | conn = start_vms.nova_connect(**os_creds) |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 378 | for ip, vm_id in start_vms.find_vms(conn, vm_name_pattern): |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 379 | node = Node(conn_pattern.format(ip=ip), ['testnode']) |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 380 | node.os_vm_id = vm_id |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 381 | ctx.nodes.append(node) |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 382 | except utils.StopTestError: |
| 383 | raise |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 384 | except Exception as exc: |
| 385 | msg = "Vm like {0} lookup failed".format(vm_name_pattern) |
| 386 | logger.exception(msg) |
| 387 | raise utils.StopTestError(msg, exc) |
| 388 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 389 | |
| 390 | def get_creds_openrc(path): |
| 391 | fc = open(path).read() |
| 392 | |
| 393 | echo = 'echo "$OS_TENANT_NAME:$OS_USERNAME:$OS_PASSWORD@$OS_AUTH_URL"' |
| 394 | |
| 395 | try: |
| 396 | data = utils.run_locally(['/bin/bash'], |
| 397 | input_data=fc + "\n" + echo) |
| 398 | except subprocess.CalledProcessError as exc: |
| 399 | msg = "Failed to get creads from openrc file: " + data |
| 400 | logger.exception(msg) |
| 401 | raise utils.StopTestError(msg, exc) |
| 402 | |
| 403 | try: |
| 404 | data = data.strip() |
| 405 | user, tenant, passwd_auth_url = data.split(':', 2) |
| 406 | passwd, auth_url = passwd_auth_url.rsplit("@", 1) |
| 407 | assert (auth_url.startswith("https://") or |
| 408 | auth_url.startswith("http://")) |
| 409 | except Exception as exc: |
| 410 | msg = "Failed to get creads from openrc file: " + data |
| 411 | logger.exception(msg) |
| 412 | raise utils.StopTestError(msg, exc) |
| 413 | return user, passwd, tenant, auth_url |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 414 | |
| 415 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 416 | def get_OS_credentials(cfg, ctx): |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 417 | creds = None |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 418 | if 'openstack' in cfg['clouds']: |
| 419 | os_cfg = cfg['clouds']['openstack'] |
| 420 | if 'OPENRC' in os_cfg: |
| 421 | logger.info("Using OS credentials from " + os_cfg['OPENRC']) |
| 422 | user, passwd, tenant, auth_url = \ |
| 423 | get_creds_openrc(os_cfg['OPENRC']) |
| 424 | elif 'ENV' in os_cfg: |
| 425 | logger.info("Using OS credentials from shell environment") |
| 426 | user, passwd, tenant, auth_url = start_vms.ostack_get_creds() |
| 427 | else: |
| 428 | logger.info("Using predefined credentials") |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 429 | tenant = os_cfg['OS_TENANT_NAME'].strip() |
| 430 | user = os_cfg['OS_USERNAME'].strip() |
| 431 | passwd = os_cfg['OS_PASSWORD'].strip() |
| 432 | auth_url = os_cfg['OS_AUTH_URL'].strip() |
| 433 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 434 | elif 'fuel' in cfg['clouds'] and \ |
| 435 | 'openstack_env' in cfg['clouds']['fuel']: |
| 436 | logger.info("Using fuel creds") |
| 437 | creds = ctx.fuel_openstack_creds |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 438 | else: |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 439 | logger.error("Can't found OS credentials") |
| 440 | raise utils.StopTestError("Can't found OS credentials", None) |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 441 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 442 | if creds is None: |
| 443 | creds = {'name': user, |
| 444 | 'passwd': passwd, |
| 445 | 'tenant': tenant, |
| 446 | 'auth_url': auth_url} |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 447 | |
koder aka kdanilov | 46d4f39 | 2015-04-24 11:35:00 +0300 | [diff] [blame] | 448 | msg = "OS_CREDS: user={name} tenant={tenant} auth_url={auth_url}" |
| 449 | logger.debug(msg.format(**creds)) |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 450 | return creds |
koder aka kdanilov | 4e9f3ed | 2015-04-14 11:26:12 +0300 | [diff] [blame] | 451 | |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 452 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 453 | @contextlib.contextmanager |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 454 | def create_vms_ctx(ctx, cfg, config, already_has_count=0): |
koder aka kdanilov | c368eb6 | 2015-04-28 18:22:01 +0300 | [diff] [blame] | 455 | params = cfg['vm_configs'][config['cfg_name']].copy() |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 456 | os_nodes_ids = [] |
| 457 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 458 | if not start_vms.is_connected(): |
| 459 | os_creds = get_OS_credentials(cfg, ctx) |
| 460 | else: |
| 461 | os_creds = {} |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 462 | start_vms.nova_connect(**os_creds) |
| 463 | |
koder aka kdanilov | c368eb6 | 2015-04-28 18:22:01 +0300 | [diff] [blame] | 464 | params.update(config) |
| 465 | params['keypair_file_private'] = params['keypair_name'] + ".pem" |
| 466 | params['group_name'] = cfg_dict['run_uuid'] |
| 467 | |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 468 | if not config.get('skip_preparation', False): |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 469 | logger.info("Preparing openstack") |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 470 | start_vms.prepare_os_subpr(params=params, **os_creds) |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 471 | |
| 472 | new_nodes = [] |
| 473 | try: |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 474 | for new_node, node_id in start_vms.launch_vms(params, |
| 475 | already_has_count): |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 476 | new_node.roles.append('testnode') |
| 477 | ctx.nodes.append(new_node) |
| 478 | os_nodes_ids.append(node_id) |
| 479 | new_nodes.append(new_node) |
| 480 | |
| 481 | store_nodes_in_log(cfg, os_nodes_ids) |
| 482 | ctx.openstack_nodes_ids = os_nodes_ids |
| 483 | |
| 484 | yield new_nodes |
| 485 | |
| 486 | finally: |
| 487 | if not cfg['keep_vm']: |
| 488 | shut_down_vms_stage(cfg, ctx) |
| 489 | |
| 490 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 491 | def run_tests_stage(cfg, ctx): |
| 492 | ctx.results = [] |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 493 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 494 | if 'tests' not in cfg: |
| 495 | return |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 496 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 497 | for group in cfg['tests']: |
| 498 | |
| 499 | assert len(group.items()) == 1 |
| 500 | key, config = group.items()[0] |
| 501 | |
| 502 | if 'start_test_nodes' == key: |
koder aka kdanilov | c368eb6 | 2015-04-28 18:22:01 +0300 | [diff] [blame] | 503 | if 'openstack' not in config: |
| 504 | msg = "No openstack block in config - can't spawn vm's" |
| 505 | logger.error(msg) |
| 506 | raise utils.StopTestError(msg) |
| 507 | |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 508 | num_test_nodes = sum(1 for node in ctx.nodes |
| 509 | if 'testnode' in node.roles) |
| 510 | |
| 511 | vm_ctx = create_vms_ctx(ctx, cfg, config['openstack'], |
| 512 | num_test_nodes) |
| 513 | with vm_ctx as new_nodes: |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 514 | if len(new_nodes) != 0: |
| 515 | connect_all(new_nodes, True) |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 516 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 517 | for node in new_nodes: |
| 518 | if node.connection is None: |
| 519 | msg = "Failed to connect to vm {0}" |
| 520 | raise RuntimeError(msg.format(node.get_conn_id())) |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 521 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 522 | deploy_sensors_stage(cfg_dict, |
| 523 | ctx, |
| 524 | nodes=new_nodes, |
| 525 | undeploy=False) |
koder aka kdanilov | 12ae063 | 2015-04-15 01:13:43 +0300 | [diff] [blame] | 526 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 527 | for test_group in config.get('tests', []): |
| 528 | test_res = run_tests(cfg, test_group, ctx.nodes) |
| 529 | ctx.results.extend(test_res) |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 530 | else: |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 531 | test_res = run_tests(cfg, group, ctx.nodes) |
| 532 | ctx.results.extend(test_res) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 533 | |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 534 | |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 535 | def shut_down_vms_stage(cfg, ctx): |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 536 | vm_ids_fname = cfg_dict['vm_ids_fname'] |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 537 | if ctx.openstack_nodes_ids is None: |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 538 | nodes_ids = open(vm_ids_fname).read().split() |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 539 | else: |
| 540 | nodes_ids = ctx.openstack_nodes_ids |
| 541 | |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 542 | if len(nodes_ids) != 0: |
| 543 | logger.info("Removing nodes") |
| 544 | start_vms.clear_nodes(nodes_ids) |
| 545 | logger.info("Nodes has been removed") |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 546 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 547 | if os.path.exists(vm_ids_fname): |
| 548 | os.remove(vm_ids_fname) |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 549 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 550 | |
| 551 | def store_nodes_in_log(cfg, nodes_ids): |
| 552 | with open(cfg['vm_ids_fname'], 'w') as fd: |
| 553 | fd.write("\n".join(nodes_ids)) |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 554 | |
| 555 | |
| 556 | def clear_enviroment(cfg, ctx): |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 557 | if os.path.exists(cfg_dict['vm_ids_fname']): |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 558 | shut_down_vms_stage(cfg, ctx) |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 559 | |
| 560 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 561 | def disconnect_stage(cfg, ctx): |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 562 | ssh_utils.close_all_sessions() |
| 563 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 564 | for node in ctx.nodes: |
| 565 | if node.connection is not None: |
| 566 | node.connection.close() |
| 567 | |
| 568 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 569 | def store_raw_results_stage(cfg, ctx): |
| 570 | |
| 571 | raw_results = os.path.join(cfg_dict['var_dir'], 'raw_results.yaml') |
| 572 | |
| 573 | if os.path.exists(raw_results): |
| 574 | cont = yaml.load(open(raw_results).read()) |
| 575 | else: |
| 576 | cont = [] |
| 577 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 578 | cont.extend(utils.yamable(ctx.results)) |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 579 | raw_data = pretty_yaml.dumps(cont) |
| 580 | |
| 581 | with open(raw_results, "w") as fd: |
| 582 | fd.write(raw_data) |
| 583 | |
| 584 | |
| 585 | def console_report_stage(cfg, ctx): |
| 586 | for tp, data in ctx.results: |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 587 | if 'io' == tp and data is not None: |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 588 | dinfo = report.process_disk_info(data) |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 589 | text_rep_fname = cfg['text_report_file'] |
| 590 | rep = IOPerfTest.format_for_console(data, dinfo) |
| 591 | |
| 592 | with open(text_rep_fname, "w") as fd: |
| 593 | fd.write(rep) |
| 594 | fd.write("\n") |
| 595 | fd.flush() |
| 596 | |
| 597 | logger.info("Text report were stored in " + text_rep_fname) |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 598 | print("\n") |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 599 | print(IOPerfTest.format_for_console(data, dinfo)) |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 600 | print("\n") |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 601 | |
Yulia Portnova | 1f12396 | 2015-05-06 18:48:11 +0300 | [diff] [blame] | 602 | if tp in ['mysql', 'pgbench'] and data is not None: |
Yulia Portnova | b1a1507 | 2015-05-06 14:59:25 +0300 | [diff] [blame] | 603 | print("\n") |
| 604 | print(MysqlTest.format_for_console(data)) |
| 605 | print("\n") |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 606 | |
| 607 | |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 608 | def html_report_stage(cfg, ctx): |
Yulia Portnova | 8ca2057 | 2015-04-14 14:09:39 +0300 | [diff] [blame] | 609 | html_rep_fname = cfg['html_report_file'] |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 610 | found = False |
| 611 | for tp, data in ctx.results: |
| 612 | if 'io' == tp and data is not None: |
| 613 | if found: |
| 614 | logger.error("Making reports for more than one " + |
| 615 | "io block isn't supported! All " + |
| 616 | "report, except first are skipped") |
| 617 | continue |
| 618 | found = True |
| 619 | dinfo = report.process_disk_info(data) |
| 620 | report.make_io_report(dinfo, data, html_rep_fname, |
koder aka kdanilov | d5ed4da | 2015-05-07 23:33:23 +0300 | [diff] [blame] | 621 | cfg['charts_img_path'], |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 622 | lab_info=ctx.hw_info) |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 623 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 624 | |
| 625 | def complete_log_nodes_statistic(cfg, ctx): |
| 626 | nodes = ctx.nodes |
| 627 | for node in nodes: |
| 628 | logger.debug(str(node)) |
| 629 | |
| 630 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 631 | def load_data_from(var_dir): |
koder aka kdanilov | 4e9f3ed | 2015-04-14 11:26:12 +0300 | [diff] [blame] | 632 | def load_data_from_file(cfg, ctx): |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 633 | raw_results = os.path.join(var_dir, 'raw_results.yaml') |
| 634 | ctx.results = yaml.load(open(raw_results).read()) |
koder aka kdanilov | 4e9f3ed | 2015-04-14 11:26:12 +0300 | [diff] [blame] | 635 | return load_data_from_file |
gstepanov | cd256d6 | 2015-04-07 17:47:32 +0300 | [diff] [blame] | 636 | |
| 637 | |
koder aka kdanilov | 57ce4db | 2015-04-25 21:25:51 +0300 | [diff] [blame] | 638 | def start_web_ui(cfg, ctx): |
| 639 | if webui is None: |
| 640 | logger.error("Can't start webui. Install cherrypy module") |
| 641 | ctx.web_thread = None |
| 642 | else: |
| 643 | th = threading.Thread(None, webui.web_main_thread, "webui", (None,)) |
| 644 | th.daemon = True |
| 645 | th.start() |
| 646 | ctx.web_thread = th |
| 647 | |
| 648 | |
| 649 | def stop_web_ui(cfg, ctx): |
| 650 | webui.web_main_stop() |
| 651 | time.sleep(1) |
| 652 | |
| 653 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 654 | def parse_args(argv): |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 655 | descr = "Disk io performance test suite" |
| 656 | parser = argparse.ArgumentParser(prog='wally', description=descr) |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 657 | |
| 658 | parser.add_argument("-l", dest='extra_logs', |
| 659 | action='store_true', default=False, |
| 660 | help="print some extra log info") |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 661 | parser.add_argument("-b", '--build_description', |
| 662 | type=str, default="Build info") |
| 663 | parser.add_argument("-i", '--build_id', type=str, default="id") |
| 664 | parser.add_argument("-t", '--build_type', type=str, default="GA") |
| 665 | parser.add_argument("-u", '--username', type=str, default="admin") |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 666 | parser.add_argument("-n", '--no-tests', action='store_true', |
| 667 | help="Don't run tests", default=False) |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 668 | parser.add_argument("-p", '--post-process-only', metavar="VAR_DIR", |
| 669 | help="Only process data from previour run") |
| 670 | parser.add_argument("-k", '--keep-vm', action='store_true', |
| 671 | help="Don't remove test vm's", default=False) |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 672 | parser.add_argument("-d", '--dont-discover-nodes', action='store_true', |
| 673 | help="Don't connect/discover fuel nodes", |
| 674 | default=False) |
koder aka kdanilov | a047e1b | 2015-04-21 23:16:59 +0300 | [diff] [blame] | 675 | parser.add_argument("-r", '--no-html-report', action='store_true', |
| 676 | help="Skip html report", default=False) |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 677 | parser.add_argument("--params", metavar="testname.paramname", |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame] | 678 | help="Test params", default=[]) |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 679 | parser.add_argument("config_file") |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 680 | |
| 681 | return parser.parse_args(argv[1:]) |
| 682 | |
| 683 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 684 | # from plop.collector import Collector |
| 685 | |
| 686 | |
koder aka kdanilov | 3f35626 | 2015-02-13 08:06:14 -0800 | [diff] [blame] | 687 | def main(argv): |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 688 | # collector = Collector() |
| 689 | # collector.start() |
| 690 | |
| 691 | faulthandler.register(signal.SIGUSR1, all_threads=True) |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 692 | opts = parse_args(argv) |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 693 | load_config(opts.config_file, opts.post_process_only) |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 694 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 695 | if opts.post_process_only is not None: |
| 696 | stages = [ |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 697 | load_data_from(opts.post_process_only) |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 698 | ] |
| 699 | else: |
| 700 | stages = [ |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 701 | discover_stage |
| 702 | ] |
| 703 | |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 704 | stages.extend([ |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 705 | reuse_vms_stage, |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 706 | log_nodes_statistic, |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 707 | save_nodes_stage, |
| 708 | connect_stage]) |
| 709 | |
| 710 | if cfg_dict.get('collect_info', True): |
| 711 | stages.append(collect_hw_info_stage) |
| 712 | |
| 713 | stages.extend([ |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 714 | deploy_sensors_stage, |
| 715 | run_tests_stage, |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 716 | store_raw_results_stage, |
| 717 | gather_sensors_stage |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 718 | ]) |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 719 | |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 720 | report_stages = [ |
| 721 | console_report_stage, |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 722 | ] |
| 723 | |
koder aka kdanilov | a047e1b | 2015-04-21 23:16:59 +0300 | [diff] [blame] | 724 | if not opts.no_html_report: |
| 725 | report_stages.append(html_report_stage) |
| 726 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 727 | if cfg_dict.get('logging', {}).get("extra_logs", False) or opts.extra_logs: |
| 728 | level = logging.DEBUG |
| 729 | else: |
| 730 | level = logging.WARNING |
| 731 | |
| 732 | setup_loggers(level, cfg_dict['log_file']) |
koder aka kdanilov | f4b82c2 | 2015-04-11 13:35:25 +0300 | [diff] [blame] | 733 | |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 734 | logger.info("All info would be stored into {0}".format( |
| 735 | cfg_dict['var_dir'])) |
gstepanov | cd256d6 | 2015-04-07 17:47:32 +0300 | [diff] [blame] | 736 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 737 | ctx = Context() |
gstepanov | affcdb1 | 2015-04-07 17:18:29 +0300 | [diff] [blame] | 738 | ctx.build_meta['build_id'] = opts.build_id |
| 739 | ctx.build_meta['build_descrption'] = opts.build_description |
| 740 | ctx.build_meta['build_type'] = opts.build_type |
| 741 | ctx.build_meta['username'] = opts.username |
koder aka kdanilov | 57ce4db | 2015-04-25 21:25:51 +0300 | [diff] [blame] | 742 | ctx.sensors_data = SensorDatastore() |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 743 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 744 | cfg_dict['keep_vm'] = opts.keep_vm |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 745 | cfg_dict['no_tests'] = opts.no_tests |
| 746 | cfg_dict['dont_discover_nodes'] = opts.dont_discover_nodes |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 747 | |
koder aka kdanilov | 57ce4db | 2015-04-25 21:25:51 +0300 | [diff] [blame] | 748 | if cfg_dict.get('run_web_ui', False): |
| 749 | start_web_ui(cfg_dict, ctx) |
| 750 | |
koder aka kdanilov | c368eb6 | 2015-04-28 18:22:01 +0300 | [diff] [blame] | 751 | msg_templ = "Exception during {0.__name__}: {1!s}" |
| 752 | msg_templ_no_exc = "During {0.__name__}" |
| 753 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 754 | try: |
| 755 | for stage in stages: |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 756 | if stage.__name__.endswith("stage"): |
| 757 | logger.info("Start {0.__name__}".format(stage)) |
| 758 | else: |
| 759 | logger.info("Start {0.__name__} stage".format(stage)) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 760 | stage(cfg_dict, ctx) |
koder aka kdanilov | c368eb6 | 2015-04-28 18:22:01 +0300 | [diff] [blame] | 761 | except utils.StopTestError as exc: |
| 762 | logger.error(msg_templ.format(stage, exc)) |
| 763 | except Exception: |
| 764 | logger.exception(msg_templ_no_exc.format(stage)) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 765 | finally: |
| 766 | exc, cls, tb = sys.exc_info() |
| 767 | for stage in ctx.clear_calls_stack[::-1]: |
| 768 | try: |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 769 | if stage.__name__.endswith("stage"): |
| 770 | logger.info("Start {0.__name__}".format(stage)) |
| 771 | else: |
| 772 | logger.info("Start {0.__name__} stage".format(stage)) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 773 | stage(cfg_dict, ctx) |
koder aka kdanilov | f86d7af | 2015-05-06 04:01:54 +0300 | [diff] [blame] | 774 | except utils.StopTestError as cleanup_exc: |
| 775 | logger.error(msg_templ.format(stage, cleanup_exc)) |
| 776 | except Exception: |
| 777 | logger.exception(msg_templ_no_exc.format(stage)) |
| 778 | |
| 779 | logger.debug("Start utils.cleanup") |
| 780 | for clean_func, args, kwargs in utils.iter_clean_func(): |
| 781 | try: |
| 782 | clean_func(*args, **kwargs) |
| 783 | except utils.StopTestError as cleanup_exc: |
| 784 | logger.error(msg_templ.format(stage, cleanup_exc)) |
koder aka kdanilov | c368eb6 | 2015-04-28 18:22:01 +0300 | [diff] [blame] | 785 | except Exception: |
| 786 | logger.exception(msg_templ_no_exc.format(stage)) |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 787 | |
koder aka kdanilov | e2de58c | 2015-04-24 22:59:36 +0300 | [diff] [blame] | 788 | if exc is None: |
| 789 | for report_stage in report_stages: |
| 790 | report_stage(cfg_dict, ctx) |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 791 | |
| 792 | logger.info("All info stored in {0} folder".format(cfg_dict['var_dir'])) |
koder aka kdanilov | e2de58c | 2015-04-24 22:59:36 +0300 | [diff] [blame] | 793 | |
koder aka kdanilov | 57ce4db | 2015-04-25 21:25:51 +0300 | [diff] [blame] | 794 | if cfg_dict.get('run_web_ui', False): |
| 795 | stop_web_ui(cfg_dict, ctx) |
| 796 | |
koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 797 | # collector.stop() |
| 798 | # open("plop.out", "w").write(repr(dict(collector.stack_counts))) |
| 799 | |
koder aka kdanilov | e2de58c | 2015-04-24 22:59:36 +0300 | [diff] [blame] | 800 | if exc is None: |
| 801 | logger.info("Tests finished successfully") |
| 802 | return 0 |
| 803 | else: |
| 804 | logger.error("Tests are failed. See detailed error above") |
| 805 | return 1 |