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 | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 5 | import Queue |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 6 | import pprint |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 7 | import logging |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 8 | import argparse |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 9 | import functools |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 10 | import threading |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 11 | import contextlib |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 12 | import collections |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 13 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 14 | import yaml |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 15 | from concurrent.futures import ThreadPoolExecutor |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 16 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 17 | from wally import pretty_yaml |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 18 | from wally.sensors_utils import deploy_sensors_stage |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 19 | from wally.discover import discover, Node, undiscover |
| 20 | from wally import utils, report, ssh_utils, start_vms |
| 21 | from wally.suits.itest import IOPerfTest, PgBenchTest |
| 22 | from wally.config import cfg_dict, load_config, setup_loggers |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 23 | |
| 24 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 25 | logger = logging.getLogger("wally") |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 26 | |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 27 | |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 28 | def format_result(res, formatter): |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 29 | data = "\n{0}\n".format("=" * 80) |
| 30 | data += pprint.pformat(res) + "\n" |
| 31 | data += "{0}\n".format("=" * 80) |
koder aka kdanilov | fe05662 | 2015-02-19 08:46:15 -0800 | [diff] [blame] | 32 | templ = "{0}\n\n====> {1}\n\n{2}\n\n" |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 33 | return templ.format(data, formatter(res), "=" * 80) |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 34 | |
| 35 | |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 36 | class Context(object): |
| 37 | def __init__(self): |
| 38 | self.build_meta = {} |
| 39 | self.nodes = [] |
| 40 | self.clear_calls_stack = [] |
| 41 | self.openstack_nodes_ids = [] |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 42 | self.sensors_mon_q = None |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 43 | |
| 44 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 45 | def connect_one(node, vm=False): |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 46 | if node.conn_url == 'local': |
| 47 | node.connection = ssh_utils.connect(node.conn_url) |
| 48 | return |
| 49 | |
koder aka kdanilov | 5d589b4 | 2015-03-26 12:25:51 +0200 | [diff] [blame] | 50 | try: |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 51 | ssh_pref = "ssh://" |
| 52 | if node.conn_url.startswith(ssh_pref): |
| 53 | url = node.conn_url[len(ssh_pref):] |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 54 | |
| 55 | if vm: |
koder aka kdanilov | 6b1341a | 2015-04-21 22:44:21 +0300 | [diff] [blame] | 56 | conn_timeout = 240 |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 57 | else: |
koder aka kdanilov | 6b1341a | 2015-04-21 22:44:21 +0300 | [diff] [blame] | 58 | conn_timeout = 30 |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 59 | |
| 60 | node.connection = ssh_utils.connect(url, |
koder aka kdanilov | 6b1341a | 2015-04-21 22:44:21 +0300 | [diff] [blame] | 61 | conn_timeout=conn_timeout) |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 62 | else: |
| 63 | raise ValueError("Unknown url type {0}".format(node.conn_url)) |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 64 | except Exception as exc: |
| 65 | # logger.exception("During connect to " + node.get_conn_id()) |
| 66 | msg = "During connect to {0}: {1}".format(node.get_conn_id(), |
| 67 | exc.message) |
| 68 | logger.error(msg) |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 69 | node.connection = None |
koder aka kdanilov | 5d589b4 | 2015-03-26 12:25:51 +0200 | [diff] [blame] | 70 | |
| 71 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 72 | def connect_all(nodes, vm=False): |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 73 | logger.info("Connecting to nodes") |
| 74 | with ThreadPoolExecutor(32) as pool: |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 75 | connect_one_f = functools.partial(connect_one, vm=vm) |
| 76 | list(pool.map(connect_one_f, nodes)) |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 77 | |
| 78 | |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 79 | def test_thread(test, node, barrier, res_q): |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 80 | exc = None |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 81 | try: |
koder aka kdanilov | a047e1b | 2015-04-21 23:16:59 +0300 | [diff] [blame] | 82 | logger.debug("Run preparation for {0}".format(node.get_conn_id())) |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 83 | test.pre_run() |
koder aka kdanilov | a047e1b | 2015-04-21 23:16:59 +0300 | [diff] [blame] | 84 | logger.debug("Run test for {0}".format(node.get_conn_id())) |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 85 | test.run(barrier) |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 86 | except Exception as exc: |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 87 | logger.exception("In test {0} for node {1}".format(test, node)) |
| 88 | |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 89 | try: |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 90 | test.cleanup() |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 91 | except: |
| 92 | msg = "Duringf cleanup - in test {0} for node {1}" |
| 93 | logger.exception(msg.format(test, node)) |
| 94 | |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 95 | if exc is not None: |
| 96 | res_q.put(exc) |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 97 | |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 98 | |
| 99 | def run_tests(test_block, nodes, test_uuid): |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 100 | tool_type_mapper = { |
| 101 | "io": IOPerfTest, |
| 102 | "pgbench": PgBenchTest, |
| 103 | } |
| 104 | |
| 105 | test_nodes = [node for node in nodes |
| 106 | if 'testnode' in node.roles] |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 107 | test_number_per_type = {} |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 108 | res_q = Queue.Queue() |
| 109 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 110 | for name, params in test_block.items(): |
| 111 | logger.info("Starting {0} tests".format(name)) |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 112 | test_num = test_number_per_type.get(name, 0) |
| 113 | test_number_per_type[name] = test_num + 1 |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 114 | threads = [] |
| 115 | barrier = utils.Barrier(len(test_nodes)) |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 116 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 117 | for node in test_nodes: |
| 118 | msg = "Starting {0} test on {1} node" |
| 119 | logger.debug(msg.format(name, node.conn_url)) |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 120 | |
| 121 | dr = os.path.join( |
| 122 | cfg_dict['test_log_directory'], |
| 123 | "{0}_{1}_{2}".format(name, test_num, node.get_ip()) |
| 124 | ) |
| 125 | |
| 126 | if not os.path.exists(dr): |
| 127 | os.makedirs(dr) |
| 128 | |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 129 | test = tool_type_mapper[name](params, res_q.put, test_uuid, node, |
| 130 | log_directory=dr) |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 131 | th = threading.Thread(None, test_thread, None, |
| 132 | (test, node, barrier, res_q)) |
| 133 | threads.append(th) |
| 134 | th.daemon = True |
| 135 | th.start() |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 136 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 137 | def gather_results(res_q, results): |
| 138 | while not res_q.empty(): |
| 139 | val = res_q.get() |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 140 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 141 | if isinstance(val, Exception): |
| 142 | msg = "Exception during test execution: {0}" |
| 143 | raise ValueError(msg.format(val.message)) |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 144 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 145 | results.append(val) |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 146 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 147 | results = [] |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 148 | |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 149 | # MAX_WAIT_TIME = 10 |
| 150 | # end_time = time.time() + MAX_WAIT_TIME |
| 151 | |
| 152 | # while time.time() < end_time: |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 153 | while True: |
| 154 | for th in threads: |
| 155 | th.join(1) |
| 156 | gather_results(res_q, results) |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 157 | # if time.time() > end_time: |
| 158 | # break |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 159 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 160 | if all(not th.is_alive() for th in threads): |
| 161 | break |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 162 | |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 163 | # if any(th.is_alive() for th in threads): |
| 164 | # logger.warning("Some test threads still running") |
| 165 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 166 | gather_results(res_q, results) |
| 167 | yield name, test.merge_results(results) |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 168 | |
| 169 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 170 | def log_nodes_statistic(_, ctx): |
| 171 | nodes = ctx.nodes |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 172 | logger.info("Found {0} nodes total".format(len(nodes))) |
| 173 | per_role = collections.defaultdict(lambda: 0) |
| 174 | for node in nodes: |
| 175 | for role in node.roles: |
| 176 | per_role[role] += 1 |
| 177 | |
| 178 | for role, count in sorted(per_role.items()): |
| 179 | logger.debug("Found {0} nodes with role {1}".format(count, role)) |
| 180 | |
| 181 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 182 | def connect_stage(cfg, ctx): |
| 183 | ctx.clear_calls_stack.append(disconnect_stage) |
| 184 | connect_all(ctx.nodes) |
| 185 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 186 | all_ok = True |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 187 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 188 | for node in ctx.nodes: |
| 189 | if node.connection is None: |
| 190 | if 'testnode' in node.roles: |
| 191 | msg = "Can't connect to testnode {0}" |
| 192 | raise RuntimeError(msg.format(node.get_conn_id())) |
| 193 | else: |
| 194 | msg = "Node {0} would be excluded - can't connect" |
| 195 | logger.warning(msg.format(node.get_conn_id())) |
| 196 | all_ok = False |
| 197 | |
| 198 | if all_ok: |
| 199 | logger.info("All nodes connected successfully") |
| 200 | |
| 201 | ctx.nodes = [node for node in ctx.nodes |
| 202 | if node.connection is not None] |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 203 | |
| 204 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 205 | def discover_stage(cfg, ctx): |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 206 | if cfg.get('discover') is not None: |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 207 | discover_objs = [i.strip() for i in cfg['discover'].strip().split(",")] |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 208 | |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 209 | nodes, clean_data = discover(ctx, |
| 210 | discover_objs, |
| 211 | cfg['clouds'], |
| 212 | cfg['var_dir'], |
| 213 | not cfg['dont_discover_nodes']) |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 214 | |
| 215 | def undiscover_stage(cfg, ctx): |
| 216 | undiscover(clean_data) |
| 217 | |
| 218 | ctx.clear_calls_stack.append(undiscover_stage) |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 219 | ctx.nodes.extend(nodes) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 220 | |
| 221 | for url, roles in cfg.get('explicit_nodes', {}).items(): |
| 222 | ctx.nodes.append(Node(url, roles.split(","))) |
| 223 | |
| 224 | |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 225 | def get_OS_credentials(cfg, ctx, creds_type): |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 226 | creds = None |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 227 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 228 | if creds_type == 'clouds': |
| 229 | if 'openstack' in cfg['clouds']: |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 230 | os_cfg = cfg['clouds']['openstack'] |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 231 | |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 232 | tenant = os_cfg['OS_TENANT_NAME'].strip() |
| 233 | user = os_cfg['OS_USERNAME'].strip() |
| 234 | passwd = os_cfg['OS_PASSWORD'].strip() |
| 235 | auth_url = os_cfg['OS_AUTH_URL'].strip() |
| 236 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 237 | elif 'fuel' in cfg['clouds'] and \ |
| 238 | 'openstack_env' in cfg['clouds']['fuel']: |
| 239 | creds = ctx.fuel_openstack_creds |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 240 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 241 | elif creds_type == 'ENV': |
| 242 | user, passwd, tenant, auth_url = start_vms.ostack_get_creds() |
| 243 | elif os.path.isfile(creds_type): |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 244 | raise NotImplementedError() |
| 245 | # user, passwd, tenant, auth_url = start_vms.ostack_get_creds() |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 246 | else: |
| 247 | msg = "Creds {0!r} isn't supported".format(creds_type) |
| 248 | raise ValueError(msg) |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 249 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 250 | if creds is None: |
| 251 | creds = {'name': user, |
| 252 | 'passwd': passwd, |
| 253 | 'tenant': tenant, |
| 254 | 'auth_url': auth_url} |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 255 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 256 | return creds |
koder aka kdanilov | 4e9f3ed | 2015-04-14 11:26:12 +0300 | [diff] [blame] | 257 | |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 258 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 259 | @contextlib.contextmanager |
| 260 | def create_vms_ctx(ctx, cfg, config): |
| 261 | params = config['vm_params'].copy() |
| 262 | os_nodes_ids = [] |
| 263 | |
| 264 | os_creds_type = config['creds'] |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 265 | os_creds = get_OS_credentials(cfg, ctx, os_creds_type) |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 266 | |
| 267 | start_vms.nova_connect(**os_creds) |
| 268 | |
| 269 | logger.info("Preparing openstack") |
| 270 | start_vms.prepare_os_subpr(**os_creds) |
| 271 | |
| 272 | new_nodes = [] |
| 273 | try: |
| 274 | params['group_name'] = cfg_dict['run_uuid'] |
| 275 | for new_node, node_id in start_vms.launch_vms(params): |
| 276 | new_node.roles.append('testnode') |
| 277 | ctx.nodes.append(new_node) |
| 278 | os_nodes_ids.append(node_id) |
| 279 | new_nodes.append(new_node) |
| 280 | |
| 281 | store_nodes_in_log(cfg, os_nodes_ids) |
| 282 | ctx.openstack_nodes_ids = os_nodes_ids |
| 283 | |
| 284 | yield new_nodes |
| 285 | |
| 286 | finally: |
| 287 | if not cfg['keep_vm']: |
| 288 | shut_down_vms_stage(cfg, ctx) |
| 289 | |
| 290 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 291 | def run_tests_stage(cfg, ctx): |
| 292 | ctx.results = [] |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 293 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 294 | if 'tests' not in cfg: |
| 295 | return |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 296 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 297 | for group in cfg['tests']: |
| 298 | |
| 299 | assert len(group.items()) == 1 |
| 300 | key, config = group.items()[0] |
| 301 | |
| 302 | if 'start_test_nodes' == key: |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 303 | with create_vms_ctx(ctx, cfg, config) as new_nodes: |
| 304 | connect_all(new_nodes, True) |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 305 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 306 | for node in new_nodes: |
| 307 | if node.connection is None: |
| 308 | msg = "Failed to connect to vm {0}" |
| 309 | raise RuntimeError(msg.format(node.get_conn_id())) |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 310 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 311 | deploy_sensors_stage(cfg_dict, |
| 312 | ctx, |
| 313 | nodes=new_nodes, |
| 314 | undeploy=False) |
koder aka kdanilov | 12ae063 | 2015-04-15 01:13:43 +0300 | [diff] [blame] | 315 | |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 316 | if not cfg['no_tests']: |
| 317 | for test_group in config.get('tests', []): |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 318 | test_res = run_tests(test_group, ctx.nodes, |
| 319 | cfg['run_uuid']) |
| 320 | ctx.results.extend(test_res) |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 321 | else: |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 322 | if not cfg['no_tests']: |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 323 | test_res = run_tests(group, ctx.nodes, cfg['run_uuid']) |
| 324 | ctx.results.extend(test_res) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 325 | |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 326 | |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 327 | def shut_down_vms_stage(cfg, ctx): |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 328 | vm_ids_fname = cfg_dict['vm_ids_fname'] |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 329 | if ctx.openstack_nodes_ids is None: |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 330 | nodes_ids = open(vm_ids_fname).read().split() |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 331 | else: |
| 332 | nodes_ids = ctx.openstack_nodes_ids |
| 333 | |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 334 | if len(nodes_ids) != 0: |
| 335 | logger.info("Removing nodes") |
| 336 | start_vms.clear_nodes(nodes_ids) |
| 337 | logger.info("Nodes has been removed") |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 338 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 339 | if os.path.exists(vm_ids_fname): |
| 340 | os.remove(vm_ids_fname) |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 341 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 342 | |
| 343 | def store_nodes_in_log(cfg, nodes_ids): |
| 344 | with open(cfg['vm_ids_fname'], 'w') as fd: |
| 345 | fd.write("\n".join(nodes_ids)) |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 346 | |
| 347 | |
| 348 | def clear_enviroment(cfg, ctx): |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 349 | if os.path.exists(cfg_dict['vm_ids_fname']): |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 350 | shut_down_vms_stage(cfg, ctx) |
gstepanov | 023c1e4 | 2015-04-08 15:50:19 +0300 | [diff] [blame] | 351 | |
| 352 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 353 | def disconnect_stage(cfg, ctx): |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 354 | ssh_utils.close_all_sessions() |
| 355 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 356 | for node in ctx.nodes: |
| 357 | if node.connection is not None: |
| 358 | node.connection.close() |
| 359 | |
| 360 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 361 | def store_raw_results_stage(cfg, ctx): |
| 362 | |
| 363 | raw_results = os.path.join(cfg_dict['var_dir'], 'raw_results.yaml') |
| 364 | |
| 365 | if os.path.exists(raw_results): |
| 366 | cont = yaml.load(open(raw_results).read()) |
| 367 | else: |
| 368 | cont = [] |
| 369 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 370 | cont.extend(utils.yamable(ctx.results)) |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 371 | raw_data = pretty_yaml.dumps(cont) |
| 372 | |
| 373 | with open(raw_results, "w") as fd: |
| 374 | fd.write(raw_data) |
| 375 | |
| 376 | |
| 377 | def console_report_stage(cfg, ctx): |
| 378 | for tp, data in ctx.results: |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 379 | if 'io' == tp and data is not None: |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 380 | print("\n") |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 381 | print(IOPerfTest.format_for_console(data)) |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 382 | print("\n") |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 383 | |
| 384 | |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 385 | def html_report_stage(cfg, ctx): |
Yulia Portnova | 8ca2057 | 2015-04-14 14:09:39 +0300 | [diff] [blame] | 386 | html_rep_fname = cfg['html_report_file'] |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 387 | |
| 388 | try: |
| 389 | fuel_url = cfg['clouds']['fuel']['url'] |
| 390 | except KeyError: |
| 391 | fuel_url = None |
| 392 | |
| 393 | try: |
| 394 | creds = cfg['clouds']['fuel']['creds'] |
| 395 | except KeyError: |
| 396 | creds = None |
| 397 | |
gstepanov | 69339ac | 2015-04-16 20:09:33 +0300 | [diff] [blame] | 398 | report.make_io_report(ctx.results, html_rep_fname, fuel_url, creds=creds) |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 399 | |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 400 | text_rep_fname = cfg_dict['text_report_file'] |
| 401 | with open(text_rep_fname, "w") as fd: |
| 402 | for tp, data in ctx.results: |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 403 | if 'io' == tp and data is not None: |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 404 | fd.write(IOPerfTest.format_for_console(data)) |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 405 | fd.write("\n") |
| 406 | fd.flush() |
| 407 | |
| 408 | logger.info("Text report were stored in " + text_rep_fname) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 409 | |
| 410 | |
| 411 | def complete_log_nodes_statistic(cfg, ctx): |
| 412 | nodes = ctx.nodes |
| 413 | for node in nodes: |
| 414 | logger.debug(str(node)) |
| 415 | |
| 416 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 417 | def load_data_from(var_dir): |
koder aka kdanilov | 4e9f3ed | 2015-04-14 11:26:12 +0300 | [diff] [blame] | 418 | def load_data_from_file(cfg, ctx): |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 419 | raw_results = os.path.join(var_dir, 'raw_results.yaml') |
| 420 | ctx.results = yaml.load(open(raw_results).read()) |
koder aka kdanilov | 4e9f3ed | 2015-04-14 11:26:12 +0300 | [diff] [blame] | 421 | return load_data_from_file |
gstepanov | cd256d6 | 2015-04-07 17:47:32 +0300 | [diff] [blame] | 422 | |
| 423 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 424 | def parse_args(argv): |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 425 | descr = "Disk io performance test suite" |
| 426 | parser = argparse.ArgumentParser(prog='wally', description=descr) |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 427 | |
| 428 | parser.add_argument("-l", dest='extra_logs', |
| 429 | action='store_true', default=False, |
| 430 | help="print some extra log info") |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 431 | parser.add_argument("-b", '--build_description', |
| 432 | type=str, default="Build info") |
| 433 | parser.add_argument("-i", '--build_id', type=str, default="id") |
| 434 | parser.add_argument("-t", '--build_type', type=str, default="GA") |
| 435 | parser.add_argument("-u", '--username', type=str, default="admin") |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 436 | parser.add_argument("-n", '--no-tests', action='store_true', |
| 437 | help="Don't run tests", default=False) |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 438 | parser.add_argument("-p", '--post-process-only', metavar="VAR_DIR", |
| 439 | help="Only process data from previour run") |
| 440 | parser.add_argument("-k", '--keep-vm', action='store_true', |
| 441 | help="Don't remove test vm's", default=False) |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 442 | parser.add_argument("-d", '--dont-discover-nodes', action='store_true', |
| 443 | help="Don't connect/discover fuel nodes", |
| 444 | default=False) |
koder aka kdanilov | a047e1b | 2015-04-21 23:16:59 +0300 | [diff] [blame] | 445 | parser.add_argument("-r", '--no-html-report', action='store_true', |
| 446 | help="Skip html report", default=False) |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 447 | parser.add_argument("config_file") |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 448 | |
| 449 | return parser.parse_args(argv[1:]) |
| 450 | |
| 451 | |
koder aka kdanilov | 3f35626 | 2015-02-13 08:06:14 -0800 | [diff] [blame] | 452 | def main(argv): |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 453 | opts = parse_args(argv) |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 454 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 455 | if opts.post_process_only is not None: |
| 456 | stages = [ |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 457 | load_data_from(opts.post_process_only) |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 458 | ] |
| 459 | else: |
| 460 | stages = [ |
| 461 | discover_stage, |
| 462 | log_nodes_statistic, |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 463 | connect_stage, |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 464 | deploy_sensors_stage, |
| 465 | run_tests_stage, |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 466 | store_raw_results_stage |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 467 | ] |
| 468 | |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 469 | report_stages = [ |
| 470 | console_report_stage, |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 471 | ] |
| 472 | |
koder aka kdanilov | a047e1b | 2015-04-21 23:16:59 +0300 | [diff] [blame] | 473 | if not opts.no_html_report: |
| 474 | report_stages.append(html_report_stage) |
| 475 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 476 | load_config(opts.config_file, opts.post_process_only) |
koder aka kdanilov | f4b82c2 | 2015-04-11 13:35:25 +0300 | [diff] [blame] | 477 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 478 | if cfg_dict.get('logging', {}).get("extra_logs", False) or opts.extra_logs: |
| 479 | level = logging.DEBUG |
| 480 | else: |
| 481 | level = logging.WARNING |
| 482 | |
| 483 | setup_loggers(level, cfg_dict['log_file']) |
koder aka kdanilov | f4b82c2 | 2015-04-11 13:35:25 +0300 | [diff] [blame] | 484 | |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 485 | logger.info("All info would be stored into {0}".format( |
| 486 | cfg_dict['var_dir'])) |
gstepanov | cd256d6 | 2015-04-07 17:47:32 +0300 | [diff] [blame] | 487 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 488 | ctx = Context() |
gstepanov | affcdb1 | 2015-04-07 17:18:29 +0300 | [diff] [blame] | 489 | ctx.build_meta['build_id'] = opts.build_id |
| 490 | ctx.build_meta['build_descrption'] = opts.build_description |
| 491 | ctx.build_meta['build_type'] = opts.build_type |
| 492 | ctx.build_meta['username'] = opts.username |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 493 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 494 | cfg_dict['keep_vm'] = opts.keep_vm |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 495 | cfg_dict['no_tests'] = opts.no_tests |
| 496 | cfg_dict['dont_discover_nodes'] = opts.dont_discover_nodes |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 497 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 498 | try: |
| 499 | for stage in stages: |
| 500 | logger.info("Start {0.__name__} stage".format(stage)) |
| 501 | stage(cfg_dict, ctx) |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 502 | except Exception as exc: |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 503 | emsg = exc.message |
| 504 | if emsg == "": |
| 505 | emsg = str(exc) |
| 506 | msg = "Exception during {0.__name__}: {1}".format(stage, emsg) |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 507 | logger.error(msg) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 508 | finally: |
| 509 | exc, cls, tb = sys.exc_info() |
| 510 | for stage in ctx.clear_calls_stack[::-1]: |
| 511 | try: |
| 512 | logger.info("Start {0.__name__} stage".format(stage)) |
| 513 | stage(cfg_dict, ctx) |
koder aka kdanilov | 1c2b511 | 2015-04-10 16:53:51 +0300 | [diff] [blame] | 514 | except Exception as exc: |
| 515 | logger.exception("During {0.__name__} stage".format(stage)) |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 516 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 517 | if exc is not None: |
| 518 | raise exc, cls, tb |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 519 | |
koder aka kdanilov | e87ae65 | 2015-04-20 02:14:35 +0300 | [diff] [blame] | 520 | for report_stage in report_stages: |
| 521 | report_stage(cfg_dict, ctx) |
| 522 | |
| 523 | logger.info("All info stored in {0} folder".format(cfg_dict['var_dir'])) |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 524 | return 0 |