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