blob: 5e6b4f901cd4770d5738d7fa04b5c4064cf17119 [file] [log] [blame]
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +03001from __future__ import print_function
2
gstepanov023c1e42015-04-08 15:50:19 +03003import os
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -08004import sys
koder aka kdanilov57ce4db2015-04-25 21:25:51 +03005import time
koder aka kdanilov2c473092015-03-29 17:12:13 +03006import Queue
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -08007import pprint
koder aka kdanilov416b87a2015-05-12 00:26:04 +03008import signal
koder aka kdanilove21d7472015-02-14 19:02:04 -08009import logging
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080010import argparse
koder aka kdanilov168f6092015-04-19 02:33:38 +030011import functools
koder aka kdanilov2c473092015-03-29 17:12:13 +030012import threading
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +030013import contextlib
koder aka kdanilov2c473092015-03-29 17:12:13 +030014import collections
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080015
koder aka kdanilov66839a92015-04-11 13:22:31 +030016import yaml
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +030017import texttable
koder aka kdanilov416b87a2015-05-12 00:26:04 +030018import faulthandler
koder aka kdanilov2c473092015-03-29 17:12:13 +030019from concurrent.futures import ThreadPoolExecutor
koder aka kdanilov6c491062015-04-09 22:33:13 +030020
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030021from wally import pretty_yaml
koder aka kdanilovf86d7af2015-05-06 04:01:54 +030022from wally.hw_info import get_hw_info
23from wally.discover import discover, Node
koder aka kdanilov63ad2062015-04-27 13:11:40 +030024from wally.timeseries import SensorDatastore
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030025from wally import utils, report, ssh_utils, start_vms
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030026from wally.suits import IOPerfTest, PgBenchTest, MysqlTest
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +030027from wally.config import (cfg_dict, load_config, setup_loggers,
28 get_test_files)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030029from wally.sensors_utils import with_sensors_util, sensors_info_util
30
31TOOL_TYPE_MAPPER = {
32 "io": IOPerfTest,
33 "pgbench": PgBenchTest,
34 "mysql": MysqlTest,
35}
koder aka kdanilov63ad2062015-04-27 13:11:40 +030036
koder aka kdanilov57ce4db2015-04-25 21:25:51 +030037
38try:
39 from wally import webui
40except ImportError:
41 webui = None
koder aka kdanilov2c473092015-03-29 17:12:13 +030042
43
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030044logger = logging.getLogger("wally")
koder aka kdanilovcee43342015-04-14 22:52:53 +030045
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080046
Yulia Portnova7ddfa732015-02-24 17:32:58 +020047def format_result(res, formatter):
koder aka kdanilove21d7472015-02-14 19:02:04 -080048 data = "\n{0}\n".format("=" * 80)
49 data += pprint.pformat(res) + "\n"
50 data += "{0}\n".format("=" * 80)
koder aka kdanilovfe056622015-02-19 08:46:15 -080051 templ = "{0}\n\n====> {1}\n\n{2}\n\n"
Yulia Portnova7ddfa732015-02-24 17:32:58 +020052 return templ.format(data, formatter(res), "=" * 80)
koder aka kdanilove21d7472015-02-14 19:02:04 -080053
54
koder aka kdanilov1c2b5112015-04-10 16:53:51 +030055class Context(object):
56 def __init__(self):
57 self.build_meta = {}
58 self.nodes = []
59 self.clear_calls_stack = []
60 self.openstack_nodes_ids = []
koder aka kdanilov168f6092015-04-19 02:33:38 +030061 self.sensors_mon_q = None
koder aka kdanilovf86d7af2015-05-06 04:01:54 +030062 self.hw_info = []
koder aka kdanilov1c2b5112015-04-10 16:53:51 +030063
64
koder aka kdanilov168f6092015-04-19 02:33:38 +030065def connect_one(node, vm=False):
koder aka kdanilov0c598a12015-04-21 03:01:40 +030066 if node.conn_url == 'local':
67 node.connection = ssh_utils.connect(node.conn_url)
68 return
69
koder aka kdanilov5d589b42015-03-26 12:25:51 +020070 try:
koder aka kdanilov2c473092015-03-29 17:12:13 +030071 ssh_pref = "ssh://"
72 if node.conn_url.startswith(ssh_pref):
73 url = node.conn_url[len(ssh_pref):]
koder aka kdanilov168f6092015-04-19 02:33:38 +030074
75 if vm:
koder aka kdanilov6b1341a2015-04-21 22:44:21 +030076 conn_timeout = 240
koder aka kdanilov168f6092015-04-19 02:33:38 +030077 else:
koder aka kdanilov6b1341a2015-04-21 22:44:21 +030078 conn_timeout = 30
koder aka kdanilov168f6092015-04-19 02:33:38 +030079
80 node.connection = ssh_utils.connect(url,
koder aka kdanilov6b1341a2015-04-21 22:44:21 +030081 conn_timeout=conn_timeout)
koder aka kdanilov2c473092015-03-29 17:12:13 +030082 else:
83 raise ValueError("Unknown url type {0}".format(node.conn_url))
koder aka kdanilove87ae652015-04-20 02:14:35 +030084 except Exception as exc:
85 # logger.exception("During connect to " + node.get_conn_id())
koder aka kdanilovec1b9732015-04-23 20:43:29 +030086 msg = "During connect to {0}: {1!s}".format(node.get_conn_id(),
87 exc)
koder aka kdanilove87ae652015-04-20 02:14:35 +030088 logger.error(msg)
koder aka kdanilov168f6092015-04-19 02:33:38 +030089 node.connection = None
koder aka kdanilov5d589b42015-03-26 12:25:51 +020090
91
koder aka kdanilov168f6092015-04-19 02:33:38 +030092def connect_all(nodes, vm=False):
koder aka kdanilov2c473092015-03-29 17:12:13 +030093 logger.info("Connecting to nodes")
94 with ThreadPoolExecutor(32) as pool:
koder aka kdanilov168f6092015-04-19 02:33:38 +030095 connect_one_f = functools.partial(connect_one, vm=vm)
96 list(pool.map(connect_one_f, nodes))
koder aka kdanilov2c473092015-03-29 17:12:13 +030097
98
koder aka kdanilovf86d7af2015-05-06 04:01:54 +030099def collect_hw_info_stage(cfg, ctx):
100 if os.path.exists(cfg['hwreport_fname']):
101 msg = "{0} already exists. Skip hw info"
102 logger.info(msg.format(cfg['hwreport_fname']))
103 return
104
105 with ThreadPoolExecutor(32) as pool:
106 connections = (node.connection for node in ctx.nodes)
107 ctx.hw_info.extend(pool.map(get_hw_info, connections))
108
109 with open(cfg['hwreport_fname'], 'w') as hwfd:
110 for node, info in zip(ctx.nodes, ctx.hw_info):
111 hwfd.write("-" * 60 + "\n")
112 hwfd.write("Roles : " + ", ".join(node.roles) + "\n")
113 hwfd.write(str(info) + "\n")
114 hwfd.write("-" * 60 + "\n\n")
115
116 if info.hostname is not None:
117 fname = os.path.join(
118 cfg_dict['hwinfo_directory'],
119 info.hostname + "_lshw.xml")
120
121 with open(fname, "w") as fd:
122 fd.write(info.raw)
123 logger.info("Hardware report stored in " + cfg['hwreport_fname'])
124 logger.debug("Raw hardware info in " + cfg['hwinfo_directory'] + " folder")
125
126
koder aka kdanilov652cd802015-04-13 12:21:07 +0300127def test_thread(test, node, barrier, res_q):
koder aka kdanilov4d4771c2015-04-23 01:32:02 +0300128 exc = None
koder aka kdanilov2c473092015-03-29 17:12:13 +0300129 try:
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300130 logger.debug("Run preparation for {0}".format(node.get_conn_id()))
koder aka kdanilov4d4771c2015-04-23 01:32:02 +0300131 test.pre_run()
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300132 logger.debug("Run test for {0}".format(node.get_conn_id()))
koder aka kdanilov4d4771c2015-04-23 01:32:02 +0300133 test.run(barrier)
koder aka kdanilove2de58c2015-04-24 22:59:36 +0300134 except utils.StopTestError as exc:
135 pass
koder aka kdanilov652cd802015-04-13 12:21:07 +0300136 except Exception as exc:
koder aka kdanilove2de58c2015-04-24 22:59:36 +0300137 msg = "In test {0} for node {1}"
138 msg = msg.format(test, node.get_conn_id())
139 logger.exception(msg)
140 exc = utils.StopTestError(msg, exc)
koder aka kdanilov2c473092015-03-29 17:12:13 +0300141
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300142 try:
koder aka kdanilov4d4771c2015-04-23 01:32:02 +0300143 test.cleanup()
koder aka kdanilove2de58c2015-04-24 22:59:36 +0300144 except utils.StopTestError as exc1:
145 if exc is None:
146 exc = exc1
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300147 except:
148 msg = "Duringf cleanup - in test {0} for node {1}"
149 logger.exception(msg.format(test, node))
150
koder aka kdanilov4d4771c2015-04-23 01:32:02 +0300151 if exc is not None:
152 res_q.put(exc)
koder aka kdanilov2c473092015-03-29 17:12:13 +0300153
koder aka kdanilov4d4771c2015-04-23 01:32:02 +0300154
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300155def run_single_test(test_nodes, name, test_cls, params, log_directory,
156 test_local_folder, run_uuid):
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300157 logger.info("Starting {0} tests".format(name))
158 res_q = Queue.Queue()
159 threads = []
160 coord_q = Queue.Queue()
161 rem_folder = test_local_folder.format(name=name)
162
163 barrier = utils.Barrier(len(test_nodes))
164 for idx, node in enumerate(test_nodes):
165 msg = "Starting {0} test on {1} node"
166 logger.debug(msg.format(name, node.conn_url))
167
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300168 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,
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300176 log_directory=log_directory,
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300177 coordination_queue=coord_q,
178 total_nodes_count=len(test_nodes))
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300179 th = threading.Thread(None, test_thread,
180 "Test:" + node.get_conn_id(),
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300181 (test, node, barrier, res_q))
182 threads.append(th)
183 th.daemon = True
184 th.start()
185
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300186 th = threading.Thread(None, test_cls.coordination_th,
187 "Coordination thread",
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300188 (coord_q, barrier, len(threads)))
189 threads.append(th)
190 th.daemon = True
191 th.start()
192
193 results = []
194 coord_q.put(None)
195
196 while len(threads) != 0:
197 nthreads = []
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300198 time.sleep(0.1)
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300199
200 for th in threads:
201 if not th.is_alive():
202 th.join()
203 else:
204 nthreads.append(th)
205
206 threads = nthreads
207
208 while not res_q.empty():
209 val = res_q.get()
210
211 if isinstance(val, utils.StopTestError):
212 raise val
213
214 if isinstance(val, Exception):
215 msg = "Exception during test execution: {0!s}"
216 raise ValueError(msg.format(val))
217
218 results.append(val)
219
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300220 return results
221
222
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300223def suspend_vm_nodes(unused_nodes):
224 pausable_nodes_ids = [node.os_vm_id for node in unused_nodes
225 if node.os_vm_id is not None]
226 non_pausable = len(unused_nodes) - len(pausable_nodes_ids)
koder aka kdanilov2c473092015-03-29 17:12:13 +0300227
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300228 if 0 != non_pausable:
229 logger.warning("Can't pause {0} nodes".format(
230 non_pausable))
231
232 if len(pausable_nodes_ids) != 0:
233 logger.debug("Try to pause {0} unused nodes".format(
234 len(pausable_nodes_ids)))
235 start_vms.pause(pausable_nodes_ids)
236
237 return pausable_nodes_ids
238
239
240def run_tests(cfg, test_block, nodes):
koder aka kdanilov2c473092015-03-29 17:12:13 +0300241 test_nodes = [node for node in nodes
242 if 'testnode' in node.roles]
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300243
244 not_test_nodes = [node for node in nodes
245 if 'testnode' not in node.roles]
246
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300247 if len(test_nodes) == 0:
248 logger.error("No test nodes found")
249 return
250
koder aka kdanilovcee43342015-04-14 22:52:53 +0300251 for name, params in test_block.items():
koder aka kdanilovcee43342015-04-14 22:52:53 +0300252 results = []
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300253 limit = params.get('node_limit')
254 if isinstance(limit, (int, long)):
255 vm_limits = [limit]
256 elif limit is None:
257 vm_limits = [len(test_nodes)]
258 else:
259 vm_limits = limit
koder aka kdanilov652cd802015-04-13 12:21:07 +0300260
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300261 for vm_count in vm_limits:
262 if vm_count == 'all':
263 curr_test_nodes = test_nodes
264 unused_nodes = []
265 else:
266 curr_test_nodes = test_nodes[:vm_count]
267 unused_nodes = test_nodes[vm_count:]
koder aka kdanilove87ae652015-04-20 02:14:35 +0300268
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300269 if 0 == len(curr_test_nodes):
270 continue
koder aka kdanilov652cd802015-04-13 12:21:07 +0300271
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300272 # make a directory for results
273 all_tests_dirs = os.listdir(cfg_dict['results'])
274
275 if 'name' in params:
276 dir_name = "{0}_{1}".format(name, params['name'])
277 else:
278 for idx in range(len(all_tests_dirs) + 1):
279 dir_name = "{0}_{1}".format(name, idx)
280 if dir_name not in all_tests_dirs:
281 break
282 else:
283 raise utils.StopTestError(
284 "Can't select directory for test results")
285
286 dir_path = os.path.join(cfg_dict['results'], dir_name)
287 if not os.path.exists(dir_path):
288 os.mkdir(dir_path)
289
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300290 if cfg.get('suspend_unused_vms', True):
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300291 pausable_nodes_ids = suspend_vm_nodes(unused_nodes)
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300292
293 resumable_nodes_ids = [node.os_vm_id for node in curr_test_nodes
294 if node.os_vm_id is not None]
295
296 if len(resumable_nodes_ids) != 0:
297 logger.debug("Check and unpause {0} nodes".format(
298 len(resumable_nodes_ids)))
299 start_vms.unpause(resumable_nodes_ids)
300
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300301 test_cls = TOOL_TYPE_MAPPER[name]
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300302 try:
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300303 sens_nodes = curr_test_nodes + not_test_nodes
304 with sensors_info_util(cfg, sens_nodes) as sensor_data:
305 t_start = time.time()
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300306 res = run_single_test(curr_test_nodes,
307 name,
308 test_cls,
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300309 params,
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300310 dir_path,
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300311 cfg['default_test_local_folder'],
312 cfg['run_uuid'])
313 t_end = time.time()
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300314 finally:
315 if cfg.get('suspend_unused_vms', True):
316 if len(pausable_nodes_ids) != 0:
317 logger.debug("Unpausing {0} nodes".format(
318 len(pausable_nodes_ids)))
319 start_vms.unpause(pausable_nodes_ids)
320
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300321 if sensor_data is not None:
322 fname = "{0}_{1}.csv".format(int(t_start), int(t_end))
323 fpath = os.path.join(cfg['sensor_storage'], fname)
324
325 with open(fpath, "w") as fd:
326 fd.write("\n\n".join(sensor_data))
327
328 results.extend(res)
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300329
330 yield name, results
koder aka kdanilov2c473092015-03-29 17:12:13 +0300331
332
koder aka kdanilovda45e882015-04-06 02:24:42 +0300333def log_nodes_statistic(_, ctx):
334 nodes = ctx.nodes
koder aka kdanilov2c473092015-03-29 17:12:13 +0300335 logger.info("Found {0} nodes total".format(len(nodes)))
336 per_role = collections.defaultdict(lambda: 0)
337 for node in nodes:
338 for role in node.roles:
339 per_role[role] += 1
340
341 for role, count in sorted(per_role.items()):
342 logger.debug("Found {0} nodes with role {1}".format(count, role))
343
344
koder aka kdanilovda45e882015-04-06 02:24:42 +0300345def connect_stage(cfg, ctx):
346 ctx.clear_calls_stack.append(disconnect_stage)
347 connect_all(ctx.nodes)
348
koder aka kdanilov168f6092015-04-19 02:33:38 +0300349 all_ok = True
koder aka kdanilovda45e882015-04-06 02:24:42 +0300350
koder aka kdanilov168f6092015-04-19 02:33:38 +0300351 for node in ctx.nodes:
352 if node.connection is None:
353 if 'testnode' in node.roles:
354 msg = "Can't connect to testnode {0}"
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300355 msg = msg.format(node.get_conn_id())
356 logger.error(msg)
357 raise utils.StopTestError(msg)
koder aka kdanilov168f6092015-04-19 02:33:38 +0300358 else:
359 msg = "Node {0} would be excluded - can't connect"
360 logger.warning(msg.format(node.get_conn_id()))
361 all_ok = False
362
363 if all_ok:
364 logger.info("All nodes connected successfully")
365
366 ctx.nodes = [node for node in ctx.nodes
367 if node.connection is not None]
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300368
369
koder aka kdanilovda45e882015-04-06 02:24:42 +0300370def discover_stage(cfg, ctx):
koder aka kdanilov652cd802015-04-13 12:21:07 +0300371 if cfg.get('discover') is not None:
koder aka kdanilovda45e882015-04-06 02:24:42 +0300372 discover_objs = [i.strip() for i in cfg['discover'].strip().split(",")]
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300373
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300374 nodes = discover(ctx,
375 discover_objs,
376 cfg['clouds'],
377 cfg['var_dir'],
378 not cfg['dont_discover_nodes'])
koder aka kdanilov168f6092015-04-19 02:33:38 +0300379
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300380 ctx.nodes.extend(nodes)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300381
382 for url, roles in cfg.get('explicit_nodes', {}).items():
383 ctx.nodes.append(Node(url, roles.split(",")))
384
385
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300386def save_nodes_stage(cfg, ctx):
387 cluster = {}
388 for node in ctx.nodes:
389 roles = node.roles[:]
390 if 'testnode' in roles:
391 roles.remove('testnode')
392
393 if len(roles) != 0:
394 cluster[node.conn_url] = roles
395
396 with open(cfg['nodes_report_file'], "w") as fd:
397 fd.write(pretty_yaml.dumps(cluster))
398
399
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300400def reuse_vms_stage(cfg, ctx):
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300401 p = cfg.get('clouds', {}).get('openstack', {}).get('vms', [])
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300402
403 for creds in p:
404 vm_name_pattern, conn_pattern = creds.split(",")
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300405 msg = "Vm like {0} lookup failed".format(vm_name_pattern)
406 with utils.log_error(msg):
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300407 msg = "Looking for vm with name like {0}".format(vm_name_pattern)
408 logger.debug(msg)
409
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300410 if not start_vms.is_connected():
411 os_creds = get_OS_credentials(cfg, ctx)
412 else:
413 os_creds = {}
414
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300415 conn = start_vms.nova_connect(**os_creds)
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300416 for ip, vm_id in start_vms.find_vms(conn, vm_name_pattern):
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300417 node = Node(conn_pattern.format(ip=ip), ['testnode'])
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300418 node.os_vm_id = vm_id
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300419 ctx.nodes.append(node)
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300420
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300421
422def get_creds_openrc(path):
423 fc = open(path).read()
424
425 echo = 'echo "$OS_TENANT_NAME:$OS_USERNAME:$OS_PASSWORD@$OS_AUTH_URL"'
426
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300427 msg = "Failed to get creads from openrc file"
428 with utils.log_error(msg):
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300429 data = utils.run_locally(['/bin/bash'],
430 input_data=fc + "\n" + echo)
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300431
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300432 msg = "Failed to get creads from openrc file: " + data
433 with utils.log_error(msg):
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300434 data = data.strip()
435 user, tenant, passwd_auth_url = data.split(':', 2)
436 passwd, auth_url = passwd_auth_url.rsplit("@", 1)
437 assert (auth_url.startswith("https://") or
438 auth_url.startswith("http://"))
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300439
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300440 return user, passwd, tenant, auth_url
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300441
442
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300443def get_OS_credentials(cfg, ctx):
koder aka kdanilovcee43342015-04-14 22:52:53 +0300444 creds = None
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300445 tenant = None
446
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300447 if 'openstack' in cfg['clouds']:
448 os_cfg = cfg['clouds']['openstack']
449 if 'OPENRC' in os_cfg:
450 logger.info("Using OS credentials from " + os_cfg['OPENRC'])
451 user, passwd, tenant, auth_url = \
452 get_creds_openrc(os_cfg['OPENRC'])
453 elif 'ENV' in os_cfg:
454 logger.info("Using OS credentials from shell environment")
455 user, passwd, tenant, auth_url = start_vms.ostack_get_creds()
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300456 elif 'OS_TENANT_NAME' in os_cfg:
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300457 logger.info("Using predefined credentials")
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300458 tenant = os_cfg['OS_TENANT_NAME'].strip()
459 user = os_cfg['OS_USERNAME'].strip()
460 passwd = os_cfg['OS_PASSWORD'].strip()
461 auth_url = os_cfg['OS_AUTH_URL'].strip()
462
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300463 if tenant is None and 'fuel' in cfg['clouds'] and \
464 'openstack_env' in cfg['clouds']['fuel']:
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300465 logger.info("Using fuel creds")
466 creds = ctx.fuel_openstack_creds
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300467 elif tenant is None:
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300468 logger.error("Can't found OS credentials")
469 raise utils.StopTestError("Can't found OS credentials", None)
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300470
koder aka kdanilovcee43342015-04-14 22:52:53 +0300471 if creds is None:
472 creds = {'name': user,
473 'passwd': passwd,
474 'tenant': tenant,
475 'auth_url': auth_url}
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300476
koder aka kdanilov46d4f392015-04-24 11:35:00 +0300477 msg = "OS_CREDS: user={name} tenant={tenant} auth_url={auth_url}"
478 logger.debug(msg.format(**creds))
koder aka kdanilovcee43342015-04-14 22:52:53 +0300479 return creds
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +0300480
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300481
koder aka kdanilov168f6092015-04-19 02:33:38 +0300482@contextlib.contextmanager
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300483def create_vms_ctx(ctx, cfg, config, already_has_count=0):
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300484 params = cfg['vm_configs'][config['cfg_name']].copy()
koder aka kdanilov168f6092015-04-19 02:33:38 +0300485 os_nodes_ids = []
486
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300487 if not start_vms.is_connected():
488 os_creds = get_OS_credentials(cfg, ctx)
489 else:
490 os_creds = {}
koder aka kdanilov168f6092015-04-19 02:33:38 +0300491 start_vms.nova_connect(**os_creds)
492
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300493 params.update(config)
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300494 if 'keypair_file_private' not in params:
495 params['keypair_file_private'] = params['keypair_name'] + ".pem"
496
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300497 params['group_name'] = cfg_dict['run_uuid']
498
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300499 if not config.get('skip_preparation', False):
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300500 logger.info("Preparing openstack")
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300501 start_vms.prepare_os_subpr(params=params, **os_creds)
koder aka kdanilov168f6092015-04-19 02:33:38 +0300502
503 new_nodes = []
504 try:
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300505 for new_node, node_id in start_vms.launch_vms(params,
506 already_has_count):
koder aka kdanilov168f6092015-04-19 02:33:38 +0300507 new_node.roles.append('testnode')
508 ctx.nodes.append(new_node)
509 os_nodes_ids.append(node_id)
510 new_nodes.append(new_node)
511
512 store_nodes_in_log(cfg, os_nodes_ids)
513 ctx.openstack_nodes_ids = os_nodes_ids
514
515 yield new_nodes
516
517 finally:
518 if not cfg['keep_vm']:
519 shut_down_vms_stage(cfg, ctx)
520
521
koder aka kdanilovcee43342015-04-14 22:52:53 +0300522def run_tests_stage(cfg, ctx):
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300523 ctx.results = collections.defaultdict(lambda: [])
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300524
koder aka kdanilovcee43342015-04-14 22:52:53 +0300525 if 'tests' not in cfg:
526 return
gstepanov023c1e42015-04-08 15:50:19 +0300527
koder aka kdanilovcee43342015-04-14 22:52:53 +0300528 for group in cfg['tests']:
529
530 assert len(group.items()) == 1
531 key, config = group.items()[0]
532
533 if 'start_test_nodes' == key:
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300534 if 'openstack' not in config:
535 msg = "No openstack block in config - can't spawn vm's"
536 logger.error(msg)
537 raise utils.StopTestError(msg)
538
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300539 num_test_nodes = sum(1 for node in ctx.nodes
540 if 'testnode' in node.roles)
541
542 vm_ctx = create_vms_ctx(ctx, cfg, config['openstack'],
543 num_test_nodes)
544 with vm_ctx as new_nodes:
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300545 if len(new_nodes) != 0:
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300546 logger.debug("Connecting to new nodes")
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300547 connect_all(new_nodes, True)
koder aka kdanilovcee43342015-04-14 22:52:53 +0300548
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300549 for node in new_nodes:
550 if node.connection is None:
551 msg = "Failed to connect to vm {0}"
552 raise RuntimeError(msg.format(node.get_conn_id()))
koder aka kdanilovcee43342015-04-14 22:52:53 +0300553
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300554 with with_sensors_util(cfg_dict, ctx.nodes):
555 for test_group in config.get('tests', []):
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300556 for tp, res in run_tests(cfg, test_group, ctx.nodes):
557 ctx.results[tp].extend(res)
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300558 else:
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300559 with with_sensors_util(cfg_dict, ctx.nodes):
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300560 for tp, res in run_tests(cfg, group, ctx.nodes):
561 ctx.results[tp].extend(res)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300562
gstepanov023c1e42015-04-08 15:50:19 +0300563
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300564def shut_down_vms_stage(cfg, ctx):
koder aka kdanilov66839a92015-04-11 13:22:31 +0300565 vm_ids_fname = cfg_dict['vm_ids_fname']
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300566 if ctx.openstack_nodes_ids is None:
koder aka kdanilov66839a92015-04-11 13:22:31 +0300567 nodes_ids = open(vm_ids_fname).read().split()
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300568 else:
569 nodes_ids = ctx.openstack_nodes_ids
570
koder aka kdanilov652cd802015-04-13 12:21:07 +0300571 if len(nodes_ids) != 0:
572 logger.info("Removing nodes")
573 start_vms.clear_nodes(nodes_ids)
574 logger.info("Nodes has been removed")
gstepanov023c1e42015-04-08 15:50:19 +0300575
koder aka kdanilov66839a92015-04-11 13:22:31 +0300576 if os.path.exists(vm_ids_fname):
577 os.remove(vm_ids_fname)
gstepanov023c1e42015-04-08 15:50:19 +0300578
koder aka kdanilov66839a92015-04-11 13:22:31 +0300579
580def store_nodes_in_log(cfg, nodes_ids):
581 with open(cfg['vm_ids_fname'], 'w') as fd:
582 fd.write("\n".join(nodes_ids))
gstepanov023c1e42015-04-08 15:50:19 +0300583
584
585def clear_enviroment(cfg, ctx):
koder aka kdanilov66839a92015-04-11 13:22:31 +0300586 if os.path.exists(cfg_dict['vm_ids_fname']):
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300587 shut_down_vms_stage(cfg, ctx)
gstepanov023c1e42015-04-08 15:50:19 +0300588
589
koder aka kdanilovda45e882015-04-06 02:24:42 +0300590def disconnect_stage(cfg, ctx):
koder aka kdanilov652cd802015-04-13 12:21:07 +0300591 ssh_utils.close_all_sessions()
592
koder aka kdanilovda45e882015-04-06 02:24:42 +0300593 for node in ctx.nodes:
594 if node.connection is not None:
595 node.connection.close()
596
597
koder aka kdanilov66839a92015-04-11 13:22:31 +0300598def store_raw_results_stage(cfg, ctx):
599
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300600 raw_results = cfg_dict['raw_results']
koder aka kdanilov66839a92015-04-11 13:22:31 +0300601
602 if os.path.exists(raw_results):
603 cont = yaml.load(open(raw_results).read())
604 else:
605 cont = []
606
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300607 cont.extend(utils.yamable(ctx.results).items())
koder aka kdanilov66839a92015-04-11 13:22:31 +0300608 raw_data = pretty_yaml.dumps(cont)
609
610 with open(raw_results, "w") as fd:
611 fd.write(raw_data)
612
613
614def console_report_stage(cfg, ctx):
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300615 first_report = True
616 text_rep_fname = cfg['text_report_file']
617 with open(text_rep_fname, "w") as fd:
618 for tp, data in ctx.results.items():
619 if 'io' == tp and data is not None:
620 dinfo = report.process_disk_info(data)
621 rep = IOPerfTest.format_for_console(data, dinfo)
622 elif tp in ['mysql', 'pgbench'] and data is not None:
623 rep = MysqlTest.format_for_console(data)
624 else:
625 logger.warning("Can't generate text report for " + tp)
626 continue
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300627
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300628 fd.write(rep)
629 fd.write("\n")
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300630
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300631 if first_report:
632 logger.info("Text report were stored in " + text_rep_fname)
633 first_report = False
634
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300635 print("\n" + rep + "\n")
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300636
koder aka kdanilov66839a92015-04-11 13:22:31 +0300637
koder aka kdanilove87ae652015-04-20 02:14:35 +0300638def html_report_stage(cfg, ctx):
Yulia Portnova8ca20572015-04-14 14:09:39 +0300639 html_rep_fname = cfg['html_report_file']
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300640 found = False
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300641 for tp, data in ctx.results.items():
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300642 if 'io' == tp and data is not None:
643 if found:
644 logger.error("Making reports for more than one " +
645 "io block isn't supported! All " +
646 "report, except first are skipped")
647 continue
648 found = True
649 dinfo = report.process_disk_info(data)
650 report.make_io_report(dinfo, data, html_rep_fname,
651 lab_info=ctx.hw_info)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300652
koder aka kdanilovda45e882015-04-06 02:24:42 +0300653
654def complete_log_nodes_statistic(cfg, ctx):
655 nodes = ctx.nodes
656 for node in nodes:
657 logger.debug(str(node))
658
659
koder aka kdanilov66839a92015-04-11 13:22:31 +0300660def load_data_from(var_dir):
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300661 def load_data_from_file(_, ctx):
koder aka kdanilov66839a92015-04-11 13:22:31 +0300662 raw_results = os.path.join(var_dir, 'raw_results.yaml')
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300663 ctx.results = {}
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300664 for tp, results in yaml.load(open(raw_results).read()):
665 cls = TOOL_TYPE_MAPPER[tp]
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300666 ctx.results[tp] = map(cls.load, results)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300667
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +0300668 return load_data_from_file
gstepanovcd256d62015-04-07 17:47:32 +0300669
670
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300671def start_web_ui(cfg, ctx):
672 if webui is None:
673 logger.error("Can't start webui. Install cherrypy module")
674 ctx.web_thread = None
675 else:
676 th = threading.Thread(None, webui.web_main_thread, "webui", (None,))
677 th.daemon = True
678 th.start()
679 ctx.web_thread = th
680
681
682def stop_web_ui(cfg, ctx):
683 webui.web_main_stop()
684 time.sleep(1)
685
686
koder aka kdanilovcee43342015-04-14 22:52:53 +0300687def parse_args(argv):
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300688 descr = "Disk io performance test suite"
689 parser = argparse.ArgumentParser(prog='wally', description=descr)
koder aka kdanilovcee43342015-04-14 22:52:53 +0300690
691 parser.add_argument("-l", dest='extra_logs',
692 action='store_true', default=False,
693 help="print some extra log info")
koder aka kdanilovcee43342015-04-14 22:52:53 +0300694 parser.add_argument("-b", '--build_description',
695 type=str, default="Build info")
696 parser.add_argument("-i", '--build_id', type=str, default="id")
697 parser.add_argument("-t", '--build_type', type=str, default="GA")
698 parser.add_argument("-u", '--username', type=str, default="admin")
koder aka kdanilove87ae652015-04-20 02:14:35 +0300699 parser.add_argument("-n", '--no-tests', action='store_true',
700 help="Don't run tests", default=False)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300701 parser.add_argument("-p", '--post-process-only', metavar="VAR_DIR",
702 help="Only process data from previour run")
703 parser.add_argument("-k", '--keep-vm', action='store_true',
704 help="Don't remove test vm's", default=False)
koder aka kdanilove87ae652015-04-20 02:14:35 +0300705 parser.add_argument("-d", '--dont-discover-nodes', action='store_true',
706 help="Don't connect/discover fuel nodes",
707 default=False)
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300708 parser.add_argument("-r", '--no-html-report', action='store_true',
709 help="Skip html report", default=False)
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300710 parser.add_argument("--params", metavar="testname.paramname",
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300711 help="Test params", default=[])
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300712 parser.add_argument("--ls", action='store_true', default=False)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300713 parser.add_argument("config_file")
koder aka kdanilovcee43342015-04-14 22:52:53 +0300714
715 return parser.parse_args(argv[1:])
716
717
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300718def get_stage_name(func):
719 if func.__name__.endswith("stage"):
720 return func.__name__
721 else:
722 return func.__name__ + " stage"
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300723
724
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300725def list_results(path):
726 results = []
727
728 for dname in os.listdir(path):
729
730 cfg = get_test_files(os.path.join(path, dname))
731
732 if not os.path.isfile(cfg['raw_results']):
733 continue
734
735 res_mtime = time.ctime(os.path.getmtime(cfg['raw_results']))
736 cfg = yaml.load(open(cfg['saved_config_file']).read())
737
738 test_names = []
739
740 for block in cfg['tests']:
741 assert len(block.items()) == 1
742 name, data = block.items()[0]
743 if name == 'start_test_nodes':
744 for in_blk in data['tests']:
745 assert len(in_blk.items()) == 1
746 in_name, _ = in_blk.items()[0]
747 test_names.append(in_name)
748 else:
749 test_names.append(name)
750 results.append((dname, test_names, res_mtime))
751
752 tab = texttable.Texttable(max_width=120)
753 tab.set_deco(tab.HEADER | tab.VLINES | tab.BORDER)
754 tab.set_cols_align(["l", "l", "l"])
755 results.sort(key=lambda x: x[2])
756
757 for data in results:
758 dname, tests, mtime = data
759 tab.add_row([dname, ', '.join(tests), mtime])
760
761 tab.header(["Name", "Tests", "etime"])
762
763 print(tab.draw())
764
765
koder aka kdanilov3f356262015-02-13 08:06:14 -0800766def main(argv):
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300767 if '--ls' in argv:
768 list_results(argv[-1])
769 exit(0)
770
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300771 faulthandler.register(signal.SIGUSR1, all_threads=True)
koder aka kdanilove06762a2015-03-22 23:32:09 +0200772 opts = parse_args(argv)
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300773 load_config(opts.config_file, opts.post_process_only)
koder aka kdanilov2c473092015-03-29 17:12:13 +0300774
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300775 if cfg_dict.get('logging', {}).get("extra_logs", False) or opts.extra_logs:
776 level = logging.DEBUG
777 else:
778 level = logging.WARNING
779
780 setup_loggers(level, cfg_dict['log_file'])
781
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300782 if not os.path.exists(cfg_dict['saved_config_file']):
783 with open(cfg_dict['saved_config_file'], 'w') as fd:
784 fd.write(open(opts.config_file).read())
785
koder aka kdanilov66839a92015-04-11 13:22:31 +0300786 if opts.post_process_only is not None:
787 stages = [
koder aka kdanilove87ae652015-04-20 02:14:35 +0300788 load_data_from(opts.post_process_only)
koder aka kdanilov66839a92015-04-11 13:22:31 +0300789 ]
790 else:
791 stages = [
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300792 discover_stage
793 ]
794
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300795 stages.extend([
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300796 reuse_vms_stage,
koder aka kdanilov66839a92015-04-11 13:22:31 +0300797 log_nodes_statistic,
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300798 save_nodes_stage,
799 connect_stage])
800
801 if cfg_dict.get('collect_info', True):
802 stages.append(collect_hw_info_stage)
803
804 stages.extend([
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300805 # deploy_sensors_stage,
koder aka kdanilov66839a92015-04-11 13:22:31 +0300806 run_tests_stage,
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300807 store_raw_results_stage,
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300808 # gather_sensors_stage
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300809 ])
koder aka kdanilov66839a92015-04-11 13:22:31 +0300810
koder aka kdanilove87ae652015-04-20 02:14:35 +0300811 report_stages = [
812 console_report_stage,
koder aka kdanilove87ae652015-04-20 02:14:35 +0300813 ]
814
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300815 if not opts.no_html_report:
816 report_stages.append(html_report_stage)
817
koder aka kdanilov652cd802015-04-13 12:21:07 +0300818 logger.info("All info would be stored into {0}".format(
819 cfg_dict['var_dir']))
gstepanovcd256d62015-04-07 17:47:32 +0300820
koder aka kdanilovda45e882015-04-06 02:24:42 +0300821 ctx = Context()
gstepanovaffcdb12015-04-07 17:18:29 +0300822 ctx.build_meta['build_id'] = opts.build_id
823 ctx.build_meta['build_descrption'] = opts.build_description
824 ctx.build_meta['build_type'] = opts.build_type
825 ctx.build_meta['username'] = opts.username
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300826 ctx.sensors_data = SensorDatastore()
koder aka kdanilove87ae652015-04-20 02:14:35 +0300827
koder aka kdanilov168f6092015-04-19 02:33:38 +0300828 cfg_dict['keep_vm'] = opts.keep_vm
koder aka kdanilove87ae652015-04-20 02:14:35 +0300829 cfg_dict['no_tests'] = opts.no_tests
830 cfg_dict['dont_discover_nodes'] = opts.dont_discover_nodes
koder aka kdanilov6c491062015-04-09 22:33:13 +0300831
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300832 if cfg_dict.get('run_web_ui', False):
833 start_web_ui(cfg_dict, ctx)
834
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300835 msg_templ = "Exception during {0.__name__}: {1!s}"
836 msg_templ_no_exc = "During {0.__name__}"
837
koder aka kdanilovda45e882015-04-06 02:24:42 +0300838 try:
839 for stage in stages:
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300840 logger.info("Start " + get_stage_name(stage))
koder aka kdanilovda45e882015-04-06 02:24:42 +0300841 stage(cfg_dict, ctx)
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300842 except utils.StopTestError as exc:
843 logger.error(msg_templ.format(stage, exc))
844 except Exception:
845 logger.exception(msg_templ_no_exc.format(stage))
koder aka kdanilovda45e882015-04-06 02:24:42 +0300846 finally:
847 exc, cls, tb = sys.exc_info()
848 for stage in ctx.clear_calls_stack[::-1]:
849 try:
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300850 logger.info("Start " + get_stage_name(stage))
koder aka kdanilovda45e882015-04-06 02:24:42 +0300851 stage(cfg_dict, ctx)
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300852 except utils.StopTestError as cleanup_exc:
853 logger.error(msg_templ.format(stage, cleanup_exc))
854 except Exception:
855 logger.exception(msg_templ_no_exc.format(stage))
856
857 logger.debug("Start utils.cleanup")
858 for clean_func, args, kwargs in utils.iter_clean_func():
859 try:
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300860 logger.info("Start " + get_stage_name(clean_func))
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300861 clean_func(*args, **kwargs)
862 except utils.StopTestError as cleanup_exc:
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300863 logger.error(msg_templ.format(clean_func, cleanup_exc))
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300864 except Exception:
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300865 logger.exception(msg_templ_no_exc.format(clean_func))
koder aka kdanilov2c473092015-03-29 17:12:13 +0300866
koder aka kdanilove2de58c2015-04-24 22:59:36 +0300867 if exc is None:
868 for report_stage in report_stages:
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300869 logger.info("Start " + get_stage_name(report_stage))
koder aka kdanilove2de58c2015-04-24 22:59:36 +0300870 report_stage(cfg_dict, ctx)
koder aka kdanilove87ae652015-04-20 02:14:35 +0300871
872 logger.info("All info stored in {0} folder".format(cfg_dict['var_dir']))
koder aka kdanilove2de58c2015-04-24 22:59:36 +0300873
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300874 if cfg_dict.get('run_web_ui', False):
875 stop_web_ui(cfg_dict, ctx)
876
koder aka kdanilove2de58c2015-04-24 22:59:36 +0300877 if exc is None:
878 logger.info("Tests finished successfully")
879 return 0
880 else:
881 logger.error("Tests are failed. See detailed error above")
882 return 1