blob: 0e8f6e99cee2ca47779d58d0a27d30e74085788b [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 kdanilovbc2c8982015-06-13 02:50:43 +03004import re
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -08005import sys
koder aka kdanilov57ce4db2015-04-25 21:25:51 +03006import time
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 kdanilovd5ed4da2015-05-07 23:33:23 +030012import contextlib
koder aka kdanilov2c473092015-03-29 17:12:13 +030013import collections
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080014
koder aka kdanilov88407ff2015-05-26 15:35:57 +030015from yaml import load as _yaml_load
16
17try:
18 from yaml import CLoader
19 yaml_load = functools.partial(_yaml_load, Loader=CLoader)
20except ImportError:
21 yaml_load = _yaml_load
22
23
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +030024import texttable
koder aka kdanilovbb5fe072015-05-21 02:50:23 +030025
26try:
27 import faulthandler
28except ImportError:
29 faulthandler = None
30
koder aka kdanilov2c473092015-03-29 17:12:13 +030031from concurrent.futures import ThreadPoolExecutor
koder aka kdanilov6c491062015-04-09 22:33:13 +030032
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030033from wally import pretty_yaml
koder aka kdanilovf86d7af2015-05-06 04:01:54 +030034from wally.hw_info import get_hw_info
35from wally.discover import discover, Node
koder aka kdanilov63ad2062015-04-27 13:11:40 +030036from wally.timeseries import SensorDatastore
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030037from wally import utils, report, ssh_utils, start_vms
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +030038from wally.config import (cfg_dict, load_config, setup_loggers,
koder aka kdanilov88407ff2015-05-26 15:35:57 +030039 get_test_files, save_run_params, load_run_params)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030040from wally.sensors_utils import with_sensors_util, sensors_info_util
41
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030042from wally.suits.mysql import MysqlTest
43from wally.suits.itest import TestConfig
44from wally.suits.io.fio import IOPerfTest
45from wally.suits.postgres import PgBenchTest
46
47
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030048TOOL_TYPE_MAPPER = {
49 "io": IOPerfTest,
50 "pgbench": PgBenchTest,
51 "mysql": MysqlTest,
52}
koder aka kdanilov63ad2062015-04-27 13:11:40 +030053
koder aka kdanilov57ce4db2015-04-25 21:25:51 +030054
55try:
56 from wally import webui
57except ImportError:
58 webui = None
koder aka kdanilov2c473092015-03-29 17:12:13 +030059
60
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030061logger = logging.getLogger("wally")
koder aka kdanilovcee43342015-04-14 22:52:53 +030062
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080063
Yulia Portnova7ddfa732015-02-24 17:32:58 +020064def format_result(res, formatter):
koder aka kdanilove21d7472015-02-14 19:02:04 -080065 data = "\n{0}\n".format("=" * 80)
66 data += pprint.pformat(res) + "\n"
67 data += "{0}\n".format("=" * 80)
koder aka kdanilovfe056622015-02-19 08:46:15 -080068 templ = "{0}\n\n====> {1}\n\n{2}\n\n"
Yulia Portnova7ddfa732015-02-24 17:32:58 +020069 return templ.format(data, formatter(res), "=" * 80)
koder aka kdanilove21d7472015-02-14 19:02:04 -080070
71
koder aka kdanilov1c2b5112015-04-10 16:53:51 +030072class Context(object):
73 def __init__(self):
74 self.build_meta = {}
75 self.nodes = []
76 self.clear_calls_stack = []
77 self.openstack_nodes_ids = []
koder aka kdanilov168f6092015-04-19 02:33:38 +030078 self.sensors_mon_q = None
koder aka kdanilovf86d7af2015-05-06 04:01:54 +030079 self.hw_info = []
koder aka kdanilov1c2b5112015-04-10 16:53:51 +030080
81
koder aka kdanilov168f6092015-04-19 02:33:38 +030082def connect_one(node, vm=False):
koder aka kdanilov0c598a12015-04-21 03:01:40 +030083 if node.conn_url == 'local':
84 node.connection = ssh_utils.connect(node.conn_url)
85 return
86
koder aka kdanilov5d589b42015-03-26 12:25:51 +020087 try:
koder aka kdanilov2c473092015-03-29 17:12:13 +030088 ssh_pref = "ssh://"
89 if node.conn_url.startswith(ssh_pref):
90 url = node.conn_url[len(ssh_pref):]
koder aka kdanilov168f6092015-04-19 02:33:38 +030091
92 if vm:
koder aka kdanilov6b1341a2015-04-21 22:44:21 +030093 conn_timeout = 240
koder aka kdanilov168f6092015-04-19 02:33:38 +030094 else:
koder aka kdanilov6b1341a2015-04-21 22:44:21 +030095 conn_timeout = 30
koder aka kdanilov168f6092015-04-19 02:33:38 +030096
97 node.connection = ssh_utils.connect(url,
koder aka kdanilov6b1341a2015-04-21 22:44:21 +030098 conn_timeout=conn_timeout)
koder aka kdanilov2c473092015-03-29 17:12:13 +030099 else:
100 raise ValueError("Unknown url type {0}".format(node.conn_url))
koder aka kdanilove87ae652015-04-20 02:14:35 +0300101 except Exception as exc:
102 # logger.exception("During connect to " + node.get_conn_id())
koder aka kdanilovec1b9732015-04-23 20:43:29 +0300103 msg = "During connect to {0}: {1!s}".format(node.get_conn_id(),
104 exc)
koder aka kdanilove87ae652015-04-20 02:14:35 +0300105 logger.error(msg)
koder aka kdanilov168f6092015-04-19 02:33:38 +0300106 node.connection = None
koder aka kdanilov5d589b42015-03-26 12:25:51 +0200107
108
koder aka kdanilov168f6092015-04-19 02:33:38 +0300109def connect_all(nodes, vm=False):
koder aka kdanilov2c473092015-03-29 17:12:13 +0300110 logger.info("Connecting to nodes")
111 with ThreadPoolExecutor(32) as pool:
koder aka kdanilov168f6092015-04-19 02:33:38 +0300112 connect_one_f = functools.partial(connect_one, vm=vm)
113 list(pool.map(connect_one_f, nodes))
koder aka kdanilov2c473092015-03-29 17:12:13 +0300114
115
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300116def collect_hw_info_stage(cfg, ctx):
117 if os.path.exists(cfg['hwreport_fname']):
118 msg = "{0} already exists. Skip hw info"
119 logger.info(msg.format(cfg['hwreport_fname']))
120 return
121
122 with ThreadPoolExecutor(32) as pool:
123 connections = (node.connection for node in ctx.nodes)
124 ctx.hw_info.extend(pool.map(get_hw_info, connections))
125
126 with open(cfg['hwreport_fname'], 'w') as hwfd:
127 for node, info in zip(ctx.nodes, ctx.hw_info):
128 hwfd.write("-" * 60 + "\n")
129 hwfd.write("Roles : " + ", ".join(node.roles) + "\n")
130 hwfd.write(str(info) + "\n")
131 hwfd.write("-" * 60 + "\n\n")
132
133 if info.hostname is not None:
134 fname = os.path.join(
135 cfg_dict['hwinfo_directory'],
136 info.hostname + "_lshw.xml")
137
138 with open(fname, "w") as fd:
139 fd.write(info.raw)
140 logger.info("Hardware report stored in " + cfg['hwreport_fname'])
141 logger.debug("Raw hardware info in " + cfg['hwinfo_directory'] + " folder")
142
143
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300144def run_single_test(test_nodes, name, params, log_directory,
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300145 test_local_folder, run_uuid):
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300146
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300147 test_cls = TOOL_TYPE_MAPPER[name]
148 test_cfg = TestConfig(test_cls.__name__,
149 params=params,
150 test_uuid=run_uuid,
151 nodes=test_nodes,
152 log_directory=log_directory,
153 remote_dir=test_local_folder.format(name=name))
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300154
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300155 test = test_cls(test_cfg)
156 return test.run()
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300157
158
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300159def suspend_vm_nodes(unused_nodes):
160 pausable_nodes_ids = [node.os_vm_id for node in unused_nodes
161 if node.os_vm_id is not None]
162 non_pausable = len(unused_nodes) - len(pausable_nodes_ids)
koder aka kdanilov2c473092015-03-29 17:12:13 +0300163
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300164 if 0 != non_pausable:
165 logger.warning("Can't pause {0} nodes".format(
166 non_pausable))
167
168 if len(pausable_nodes_ids) != 0:
169 logger.debug("Try to pause {0} unused nodes".format(
170 len(pausable_nodes_ids)))
171 start_vms.pause(pausable_nodes_ids)
172
173 return pausable_nodes_ids
174
175
176def run_tests(cfg, test_block, nodes):
koder aka kdanilov2c473092015-03-29 17:12:13 +0300177 test_nodes = [node for node in nodes
178 if 'testnode' in node.roles]
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300179
180 not_test_nodes = [node for node in nodes
181 if 'testnode' not in node.roles]
182
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300183 if len(test_nodes) == 0:
184 logger.error("No test nodes found")
185 return
186
koder aka kdanilovcee43342015-04-14 22:52:53 +0300187 for name, params in test_block.items():
koder aka kdanilovcee43342015-04-14 22:52:53 +0300188 results = []
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300189 limit = params.get('node_limit')
190 if isinstance(limit, (int, long)):
191 vm_limits = [limit]
192 elif limit is None:
193 vm_limits = [len(test_nodes)]
194 else:
195 vm_limits = limit
koder aka kdanilov652cd802015-04-13 12:21:07 +0300196
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300197 for vm_count in vm_limits:
198 if vm_count == 'all':
199 curr_test_nodes = test_nodes
200 unused_nodes = []
201 else:
202 curr_test_nodes = test_nodes[:vm_count]
203 unused_nodes = test_nodes[vm_count:]
koder aka kdanilove87ae652015-04-20 02:14:35 +0300204
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300205 if 0 == len(curr_test_nodes):
206 continue
koder aka kdanilov652cd802015-04-13 12:21:07 +0300207
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300208 # make a directory for results
209 all_tests_dirs = os.listdir(cfg_dict['results'])
210
211 if 'name' in params:
212 dir_name = "{0}_{1}".format(name, params['name'])
213 else:
214 for idx in range(len(all_tests_dirs) + 1):
215 dir_name = "{0}_{1}".format(name, idx)
216 if dir_name not in all_tests_dirs:
217 break
218 else:
219 raise utils.StopTestError(
220 "Can't select directory for test results")
221
222 dir_path = os.path.join(cfg_dict['results'], dir_name)
223 if not os.path.exists(dir_path):
224 os.mkdir(dir_path)
225
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300226 if cfg.get('suspend_unused_vms', True):
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300227 pausable_nodes_ids = suspend_vm_nodes(unused_nodes)
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300228
229 resumable_nodes_ids = [node.os_vm_id for node in curr_test_nodes
230 if node.os_vm_id is not None]
231
232 if len(resumable_nodes_ids) != 0:
233 logger.debug("Check and unpause {0} nodes".format(
234 len(resumable_nodes_ids)))
235 start_vms.unpause(resumable_nodes_ids)
236
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300237 try:
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300238 sens_nodes = curr_test_nodes + not_test_nodes
239 with sensors_info_util(cfg, sens_nodes) as sensor_data:
240 t_start = time.time()
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300241 res = run_single_test(curr_test_nodes,
242 name,
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300243 params,
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300244 dir_path,
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300245 cfg['default_test_local_folder'],
246 cfg['run_uuid'])
247 t_end = time.time()
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300248 finally:
249 if cfg.get('suspend_unused_vms', True):
250 if len(pausable_nodes_ids) != 0:
251 logger.debug("Unpausing {0} nodes".format(
252 len(pausable_nodes_ids)))
253 start_vms.unpause(pausable_nodes_ids)
254
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300255 if sensor_data is not None:
256 fname = "{0}_{1}.csv".format(int(t_start), int(t_end))
257 fpath = os.path.join(cfg['sensor_storage'], fname)
258
259 with open(fpath, "w") as fd:
260 fd.write("\n\n".join(sensor_data))
261
262 results.extend(res)
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300263
264 yield name, results
koder aka kdanilov2c473092015-03-29 17:12:13 +0300265
266
koder aka kdanilovda45e882015-04-06 02:24:42 +0300267def log_nodes_statistic(_, ctx):
268 nodes = ctx.nodes
koder aka kdanilov2c473092015-03-29 17:12:13 +0300269 logger.info("Found {0} nodes total".format(len(nodes)))
270 per_role = collections.defaultdict(lambda: 0)
271 for node in nodes:
272 for role in node.roles:
273 per_role[role] += 1
274
275 for role, count in sorted(per_role.items()):
276 logger.debug("Found {0} nodes with role {1}".format(count, role))
277
278
koder aka kdanilovda45e882015-04-06 02:24:42 +0300279def connect_stage(cfg, ctx):
280 ctx.clear_calls_stack.append(disconnect_stage)
281 connect_all(ctx.nodes)
282
koder aka kdanilov168f6092015-04-19 02:33:38 +0300283 all_ok = True
koder aka kdanilovda45e882015-04-06 02:24:42 +0300284
koder aka kdanilov168f6092015-04-19 02:33:38 +0300285 for node in ctx.nodes:
286 if node.connection is None:
287 if 'testnode' in node.roles:
288 msg = "Can't connect to testnode {0}"
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300289 msg = msg.format(node.get_conn_id())
290 logger.error(msg)
291 raise utils.StopTestError(msg)
koder aka kdanilov168f6092015-04-19 02:33:38 +0300292 else:
293 msg = "Node {0} would be excluded - can't connect"
294 logger.warning(msg.format(node.get_conn_id()))
295 all_ok = False
296
297 if all_ok:
298 logger.info("All nodes connected successfully")
299
300 ctx.nodes = [node for node in ctx.nodes
301 if node.connection is not None]
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300302
303
koder aka kdanilovda45e882015-04-06 02:24:42 +0300304def discover_stage(cfg, ctx):
koder aka kdanilov652cd802015-04-13 12:21:07 +0300305 if cfg.get('discover') is not None:
koder aka kdanilovda45e882015-04-06 02:24:42 +0300306 discover_objs = [i.strip() for i in cfg['discover'].strip().split(",")]
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300307
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300308 nodes = discover(ctx,
309 discover_objs,
310 cfg['clouds'],
311 cfg['var_dir'],
312 not cfg['dont_discover_nodes'])
koder aka kdanilov168f6092015-04-19 02:33:38 +0300313
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300314 ctx.nodes.extend(nodes)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300315
316 for url, roles in cfg.get('explicit_nodes', {}).items():
317 ctx.nodes.append(Node(url, roles.split(",")))
318
319
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300320def save_nodes_stage(cfg, ctx):
321 cluster = {}
322 for node in ctx.nodes:
323 roles = node.roles[:]
324 if 'testnode' in roles:
325 roles.remove('testnode')
326
327 if len(roles) != 0:
328 cluster[node.conn_url] = roles
329
330 with open(cfg['nodes_report_file'], "w") as fd:
331 fd.write(pretty_yaml.dumps(cluster))
332
333
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300334def reuse_vms_stage(cfg, ctx):
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300335 p = cfg.get('clouds', {}).get('openstack', {}).get('vms', [])
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300336
337 for creds in p:
338 vm_name_pattern, conn_pattern = creds.split(",")
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300339 msg = "Vm like {0} lookup failed".format(vm_name_pattern)
340 with utils.log_error(msg):
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300341 msg = "Looking for vm with name like {0}".format(vm_name_pattern)
342 logger.debug(msg)
343
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300344 if not start_vms.is_connected():
345 os_creds = get_OS_credentials(cfg, ctx)
346 else:
347 os_creds = {}
348
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300349 conn = start_vms.nova_connect(**os_creds)
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300350 for ip, vm_id in start_vms.find_vms(conn, vm_name_pattern):
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300351 node = Node(conn_pattern.format(ip=ip), ['testnode'])
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300352 node.os_vm_id = vm_id
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300353 ctx.nodes.append(node)
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300354
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300355
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300356def get_OS_credentials(cfg, ctx):
koder aka kdanilovcee43342015-04-14 22:52:53 +0300357 creds = None
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300358 tenant = None
359
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300360 if 'openstack' in cfg['clouds']:
361 os_cfg = cfg['clouds']['openstack']
362 if 'OPENRC' in os_cfg:
363 logger.info("Using OS credentials from " + os_cfg['OPENRC'])
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300364 user, passwd, tenant, auth_url = utils.get_creds_openrc(os_cfg['OPENRC'])
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300365 elif 'ENV' in os_cfg:
366 logger.info("Using OS credentials from shell environment")
367 user, passwd, tenant, auth_url = start_vms.ostack_get_creds()
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300368 elif 'OS_TENANT_NAME' in os_cfg:
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300369 logger.info("Using predefined credentials")
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300370 tenant = os_cfg['OS_TENANT_NAME'].strip()
371 user = os_cfg['OS_USERNAME'].strip()
372 passwd = os_cfg['OS_PASSWORD'].strip()
373 auth_url = os_cfg['OS_AUTH_URL'].strip()
374
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300375 if tenant is None and 'fuel' in cfg['clouds'] and \
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300376 'openstack_env' in cfg['clouds']['fuel'] and \
377 ctx.fuel_openstack_creds is not None:
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300378 logger.info("Using fuel creds")
379 creds = ctx.fuel_openstack_creds
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300380 elif tenant is None:
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300381 logger.error("Can't found OS credentials")
382 raise utils.StopTestError("Can't found OS credentials", None)
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300383
koder aka kdanilovcee43342015-04-14 22:52:53 +0300384 if creds is None:
385 creds = {'name': user,
386 'passwd': passwd,
387 'tenant': tenant,
388 'auth_url': auth_url}
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300389
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300390 logger.debug("OS_CREDS: user={name} tenant={tenant} auth_url={auth_url}".format(**creds))
koder aka kdanilovcee43342015-04-14 22:52:53 +0300391 return creds
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +0300392
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300393
koder aka kdanilov168f6092015-04-19 02:33:38 +0300394@contextlib.contextmanager
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300395def create_vms_ctx(ctx, cfg, config, already_has_count=0):
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300396 params = cfg['vm_configs'][config['cfg_name']].copy()
koder aka kdanilov168f6092015-04-19 02:33:38 +0300397 os_nodes_ids = []
398
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300399 if not start_vms.is_connected():
400 os_creds = get_OS_credentials(cfg, ctx)
401 else:
402 os_creds = {}
koder aka kdanilov168f6092015-04-19 02:33:38 +0300403 start_vms.nova_connect(**os_creds)
404
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300405 params.update(config)
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300406 if 'keypair_file_private' not in params:
407 params['keypair_file_private'] = params['keypair_name'] + ".pem"
408
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300409 params['group_name'] = cfg_dict['run_uuid']
410
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300411 if not config.get('skip_preparation', False):
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300412 logger.info("Preparing openstack")
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300413 start_vms.prepare_os_subpr(params=params, **os_creds)
koder aka kdanilov168f6092015-04-19 02:33:38 +0300414
415 new_nodes = []
416 try:
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300417 for new_node, node_id in start_vms.launch_vms(params, already_has_count):
koder aka kdanilov168f6092015-04-19 02:33:38 +0300418 new_node.roles.append('testnode')
419 ctx.nodes.append(new_node)
420 os_nodes_ids.append(node_id)
421 new_nodes.append(new_node)
422
423 store_nodes_in_log(cfg, os_nodes_ids)
424 ctx.openstack_nodes_ids = os_nodes_ids
425
426 yield new_nodes
427
428 finally:
429 if not cfg['keep_vm']:
430 shut_down_vms_stage(cfg, ctx)
431
432
koder aka kdanilovcee43342015-04-14 22:52:53 +0300433def run_tests_stage(cfg, ctx):
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300434 ctx.results = collections.defaultdict(lambda: [])
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300435
koder aka kdanilovcee43342015-04-14 22:52:53 +0300436 if 'tests' not in cfg:
437 return
gstepanov023c1e42015-04-08 15:50:19 +0300438
koder aka kdanilovcee43342015-04-14 22:52:53 +0300439 for group in cfg['tests']:
440
441 assert len(group.items()) == 1
442 key, config = group.items()[0]
443
444 if 'start_test_nodes' == key:
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300445 if 'openstack' not in config:
446 msg = "No openstack block in config - can't spawn vm's"
447 logger.error(msg)
448 raise utils.StopTestError(msg)
449
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300450 num_test_nodes = sum(1 for node in ctx.nodes
451 if 'testnode' in node.roles)
452
453 vm_ctx = create_vms_ctx(ctx, cfg, config['openstack'],
454 num_test_nodes)
455 with vm_ctx as new_nodes:
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300456 if len(new_nodes) != 0:
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300457 logger.debug("Connecting to new nodes")
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300458 connect_all(new_nodes, True)
koder aka kdanilovcee43342015-04-14 22:52:53 +0300459
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300460 for node in new_nodes:
461 if node.connection is None:
462 msg = "Failed to connect to vm {0}"
463 raise RuntimeError(msg.format(node.get_conn_id()))
koder aka kdanilovcee43342015-04-14 22:52:53 +0300464
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300465 with with_sensors_util(cfg_dict, ctx.nodes):
466 for test_group in config.get('tests', []):
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300467 for tp, res in run_tests(cfg, test_group, ctx.nodes):
468 ctx.results[tp].extend(res)
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300469 else:
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300470 with with_sensors_util(cfg_dict, ctx.nodes):
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300471 for tp, res in run_tests(cfg, group, ctx.nodes):
472 ctx.results[tp].extend(res)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300473
gstepanov023c1e42015-04-08 15:50:19 +0300474
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300475def shut_down_vms_stage(cfg, ctx):
koder aka kdanilov66839a92015-04-11 13:22:31 +0300476 vm_ids_fname = cfg_dict['vm_ids_fname']
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300477 if ctx.openstack_nodes_ids is None:
koder aka kdanilov66839a92015-04-11 13:22:31 +0300478 nodes_ids = open(vm_ids_fname).read().split()
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300479 else:
480 nodes_ids = ctx.openstack_nodes_ids
481
koder aka kdanilov652cd802015-04-13 12:21:07 +0300482 if len(nodes_ids) != 0:
483 logger.info("Removing nodes")
484 start_vms.clear_nodes(nodes_ids)
485 logger.info("Nodes has been removed")
gstepanov023c1e42015-04-08 15:50:19 +0300486
koder aka kdanilov66839a92015-04-11 13:22:31 +0300487 if os.path.exists(vm_ids_fname):
488 os.remove(vm_ids_fname)
gstepanov023c1e42015-04-08 15:50:19 +0300489
koder aka kdanilov66839a92015-04-11 13:22:31 +0300490
491def store_nodes_in_log(cfg, nodes_ids):
492 with open(cfg['vm_ids_fname'], 'w') as fd:
493 fd.write("\n".join(nodes_ids))
gstepanov023c1e42015-04-08 15:50:19 +0300494
495
496def clear_enviroment(cfg, ctx):
koder aka kdanilov66839a92015-04-11 13:22:31 +0300497 if os.path.exists(cfg_dict['vm_ids_fname']):
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300498 shut_down_vms_stage(cfg, ctx)
gstepanov023c1e42015-04-08 15:50:19 +0300499
500
koder aka kdanilovda45e882015-04-06 02:24:42 +0300501def disconnect_stage(cfg, ctx):
koder aka kdanilov652cd802015-04-13 12:21:07 +0300502 ssh_utils.close_all_sessions()
503
koder aka kdanilovda45e882015-04-06 02:24:42 +0300504 for node in ctx.nodes:
505 if node.connection is not None:
506 node.connection.close()
507
508
koder aka kdanilov66839a92015-04-11 13:22:31 +0300509def store_raw_results_stage(cfg, ctx):
510
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300511 raw_results = cfg_dict['raw_results']
koder aka kdanilov66839a92015-04-11 13:22:31 +0300512
513 if os.path.exists(raw_results):
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300514 cont = yaml_load(open(raw_results).read())
koder aka kdanilov66839a92015-04-11 13:22:31 +0300515 else:
516 cont = []
517
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300518 cont.extend(utils.yamable(ctx.results).items())
koder aka kdanilov66839a92015-04-11 13:22:31 +0300519 raw_data = pretty_yaml.dumps(cont)
520
521 with open(raw_results, "w") as fd:
522 fd.write(raw_data)
523
524
525def console_report_stage(cfg, ctx):
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300526 first_report = True
527 text_rep_fname = cfg['text_report_file']
528 with open(text_rep_fname, "w") as fd:
529 for tp, data in ctx.results.items():
530 if 'io' == tp and data is not None:
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300531 rep = IOPerfTest.format_for_console(data)
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300532 elif tp in ['mysql', 'pgbench'] and data is not None:
533 rep = MysqlTest.format_for_console(data)
534 else:
535 logger.warning("Can't generate text report for " + tp)
536 continue
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300537
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300538 fd.write(rep)
539 fd.write("\n")
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300540
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300541 if first_report:
542 logger.info("Text report were stored in " + text_rep_fname)
543 first_report = False
544
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300545 print("\n" + rep + "\n")
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300546
koder aka kdanilov66839a92015-04-11 13:22:31 +0300547
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300548def test_load_report_stage(cfg, ctx):
549 load_rep_fname = cfg['load_report_file']
550 found = False
551 for idx, (tp, data) in enumerate(ctx.results.items()):
552 if 'io' == tp and data is not None:
553 if found:
554 logger.error("Making reports for more than one " +
555 "io block isn't supported! All " +
556 "report, except first are skipped")
557 continue
558 found = True
559 report.make_load_report(idx, cfg['results'], load_rep_fname)
560
561
koder aka kdanilove87ae652015-04-20 02:14:35 +0300562def html_report_stage(cfg, ctx):
Yulia Portnova8ca20572015-04-14 14:09:39 +0300563 html_rep_fname = cfg['html_report_file']
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300564 found = False
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300565 for tp, data in ctx.results.items():
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300566 if 'io' == tp and data is not None:
567 if found:
568 logger.error("Making reports for more than one " +
569 "io block isn't supported! All " +
570 "report, except first are skipped")
571 continue
572 found = True
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300573 report.make_io_report(data,
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300574 cfg.get('comment', ''),
575 html_rep_fname,
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300576 lab_info=ctx.hw_info)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300577
koder aka kdanilovda45e882015-04-06 02:24:42 +0300578
579def complete_log_nodes_statistic(cfg, ctx):
580 nodes = ctx.nodes
581 for node in nodes:
582 logger.debug(str(node))
583
584
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300585def load_data_from_file(var_dir, _, ctx):
586 raw_results = os.path.join(var_dir, 'raw_results.yaml')
587 ctx.results = {}
588 for tp, results in yaml_load(open(raw_results).read()):
589 cls = TOOL_TYPE_MAPPER[tp]
590 ctx.results[tp] = map(cls.load, results)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300591
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300592
koder aka kdanilov6b872662015-06-23 01:58:36 +0300593def load_data_from_path(var_dir):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300594 res_dir = os.path.join(var_dir, 'results')
koder aka kdanilov6b872662015-06-23 01:58:36 +0300595 res = {}
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300596 for dir_name in os.listdir(res_dir):
597 dir_path = os.path.join(res_dir, dir_name)
598 if not os.path.isdir(dir_path):
599 continue
600 rr = re.match(r"(?P<type>[a-z]+)_\d+$", dir_name)
601 if rr is None:
602 continue
603 tp = rr.group('type')
koder aka kdanilov6b872662015-06-23 01:58:36 +0300604 arr = res.setdefault(tp, [])
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300605 arr.extend(TOOL_TYPE_MAPPER[tp].load(dir_path))
koder aka kdanilov6b872662015-06-23 01:58:36 +0300606 return res
607
608
609def load_data_from_path_stage(var_dir, _, ctx):
610 for tp, vals in load_data_from_path(var_dir).items():
611 ctx.results.setdefault(tp, []).extend(vals)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300612
613
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300614def load_data_from(var_dir):
koder aka kdanilov6b872662015-06-23 01:58:36 +0300615 return functools.partial(load_data_from_path_stage, var_dir)
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300616
617
koder aka kdanilovcee43342015-04-14 22:52:53 +0300618def parse_args(argv):
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300619 descr = "Disk io performance test suite"
620 parser = argparse.ArgumentParser(prog='wally', description=descr)
koder aka kdanilovcee43342015-04-14 22:52:53 +0300621
622 parser.add_argument("-l", dest='extra_logs',
623 action='store_true', default=False,
624 help="print some extra log info")
koder aka kdanilovcee43342015-04-14 22:52:53 +0300625 parser.add_argument("-b", '--build_description',
626 type=str, default="Build info")
627 parser.add_argument("-i", '--build_id', type=str, default="id")
628 parser.add_argument("-t", '--build_type', type=str, default="GA")
629 parser.add_argument("-u", '--username', type=str, default="admin")
koder aka kdanilove87ae652015-04-20 02:14:35 +0300630 parser.add_argument("-n", '--no-tests', action='store_true',
631 help="Don't run tests", default=False)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300632 parser.add_argument("-p", '--post-process-only', metavar="VAR_DIR",
633 help="Only process data from previour run")
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300634 parser.add_argument("-x", '--xxx', action='store_true')
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300635 parser.add_argument("-k", '--keep-vm', action='store_true',
636 help="Don't remove test vm's", default=False)
koder aka kdanilove87ae652015-04-20 02:14:35 +0300637 parser.add_argument("-d", '--dont-discover-nodes', action='store_true',
638 help="Don't connect/discover fuel nodes",
639 default=False)
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300640 parser.add_argument("-r", '--no-html-report', action='store_true',
641 help="Skip html report", default=False)
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300642 parser.add_argument("--params", metavar="testname.paramname",
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300643 help="Test params", default=[])
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300644 parser.add_argument("--ls", action='store_true', default=False)
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300645 parser.add_argument("-c", "--comment", default="")
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300646 parser.add_argument("config_file")
koder aka kdanilovcee43342015-04-14 22:52:53 +0300647
648 return parser.parse_args(argv[1:])
649
650
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300651def get_stage_name(func):
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300652 nm = get_func_name(func)
653 if nm.endswith("stage"):
654 return nm
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300655 else:
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300656 return nm + " stage"
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300657
658
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300659def get_test_names(raw_res):
660 res = set()
661 for tp, data in raw_res:
662 for block in data:
663 res.add("{0}({1})".format(tp, block.get('test_name', '-')))
664 return res
koder aka kdanilovbb5fe072015-05-21 02:50:23 +0300665
666
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300667def list_results(path):
668 results = []
669
670 for dname in os.listdir(path):
671
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300672 files_cfg = get_test_files(os.path.join(path, dname))
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300673
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300674 if not os.path.isfile(files_cfg['raw_results']):
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300675 continue
676
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300677 mt = os.path.getmtime(files_cfg['raw_results'])
678 res_mtime = time.ctime(mt)
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300679
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300680 raw_res = yaml_load(open(files_cfg['raw_results']).read())
681 test_names = ",".join(sorted(get_test_names(raw_res)))
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300682
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300683 params = load_run_params(files_cfg['run_params_file'])
koder aka kdanilovbb5fe072015-05-21 02:50:23 +0300684
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300685 comm = params.get('comment')
686 results.append((mt, dname, test_names, res_mtime,
687 '-' if comm is None else comm))
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300688
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300689 tab = texttable.Texttable(max_width=200)
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300690 tab.set_deco(tab.HEADER | tab.VLINES | tab.BORDER)
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300691 tab.set_cols_align(["l", "l", "l", "l"])
692 results.sort()
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300693
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300694 for data in results[::-1]:
695 tab.add_row(data[1:])
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300696
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300697 tab.header(["Name", "Tests", "etime", "Comment"])
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300698
699 print(tab.draw())
700
701
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300702def get_func_name(obj):
703 if hasattr(obj, '__name__'):
704 return obj.__name__
705 if hasattr(obj, 'func_name'):
706 return obj.func_name
707 return obj.func.func_name
708
709
710@contextlib.contextmanager
711def log_stage(func):
712 msg_templ = "Exception during {0}: {1!s}"
713 msg_templ_no_exc = "During {0}"
714
715 logger.info("Start " + get_stage_name(func))
716
717 try:
718 yield
719 except utils.StopTestError as exc:
720 logger.error(msg_templ.format(
721 get_func_name(func), exc))
722 except Exception:
723 logger.exception(msg_templ_no_exc.format(
724 get_func_name(func)))
725
726
koder aka kdanilov3f356262015-02-13 08:06:14 -0800727def main(argv):
koder aka kdanilovbb5fe072015-05-21 02:50:23 +0300728 if faulthandler is not None:
729 faulthandler.register(signal.SIGUSR1, all_threads=True)
730
koder aka kdanilove06762a2015-03-22 23:32:09 +0200731 opts = parse_args(argv)
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300732
koder aka kdanilov6b872662015-06-23 01:58:36 +0300733 # x = load_data_from_path("/var/wally_results/silky_virgen")
734 # y = load_data_from_path("/var/wally_results/cibarial_jacob")
735 # print(IOPerfTest.format_diff_for_console([x['io'], y['io']]))
736 # exit(1)
737
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300738 if opts.ls:
739 list_results(opts.config_file)
740 exit(0)
741
742 data_dir = load_config(opts.config_file, opts.post_process_only)
743
744 if opts.post_process_only is None:
745 cfg_dict['comment'] = opts.comment
746 save_run_params()
koder aka kdanilov2c473092015-03-29 17:12:13 +0300747
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300748 if cfg_dict.get('logging', {}).get("extra_logs", False) or opts.extra_logs:
749 level = logging.DEBUG
750 else:
751 level = logging.WARNING
752
753 setup_loggers(level, cfg_dict['log_file'])
754
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300755 if not os.path.exists(cfg_dict['saved_config_file']):
756 with open(cfg_dict['saved_config_file'], 'w') as fd:
757 fd.write(open(opts.config_file).read())
758
koder aka kdanilov66839a92015-04-11 13:22:31 +0300759 if opts.post_process_only is not None:
760 stages = [
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300761 load_data_from(data_dir)
koder aka kdanilov66839a92015-04-11 13:22:31 +0300762 ]
763 else:
764 stages = [
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300765 discover_stage
766 ]
767
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300768 stages.extend([
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300769 reuse_vms_stage,
koder aka kdanilov66839a92015-04-11 13:22:31 +0300770 log_nodes_statistic,
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300771 save_nodes_stage,
772 connect_stage])
773
774 if cfg_dict.get('collect_info', True):
775 stages.append(collect_hw_info_stage)
776
777 stages.extend([
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300778 # deploy_sensors_stage,
koder aka kdanilov66839a92015-04-11 13:22:31 +0300779 run_tests_stage,
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300780 store_raw_results_stage,
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300781 # gather_sensors_stage
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300782 ])
koder aka kdanilov66839a92015-04-11 13:22:31 +0300783
koder aka kdanilove87ae652015-04-20 02:14:35 +0300784 report_stages = [
785 console_report_stage,
koder aka kdanilove87ae652015-04-20 02:14:35 +0300786 ]
787
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300788 if opts.xxx:
789 report_stages.append(test_load_report_stage)
790 elif not opts.no_html_report:
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300791 report_stages.append(html_report_stage)
792
koder aka kdanilov652cd802015-04-13 12:21:07 +0300793 logger.info("All info would be stored into {0}".format(
794 cfg_dict['var_dir']))
gstepanovcd256d62015-04-07 17:47:32 +0300795
koder aka kdanilovda45e882015-04-06 02:24:42 +0300796 ctx = Context()
koder aka kdanilov6b872662015-06-23 01:58:36 +0300797 ctx.results = {}
gstepanovaffcdb12015-04-07 17:18:29 +0300798 ctx.build_meta['build_id'] = opts.build_id
799 ctx.build_meta['build_descrption'] = opts.build_description
800 ctx.build_meta['build_type'] = opts.build_type
801 ctx.build_meta['username'] = opts.username
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300802 ctx.sensors_data = SensorDatastore()
koder aka kdanilove87ae652015-04-20 02:14:35 +0300803
koder aka kdanilov168f6092015-04-19 02:33:38 +0300804 cfg_dict['keep_vm'] = opts.keep_vm
koder aka kdanilove87ae652015-04-20 02:14:35 +0300805 cfg_dict['no_tests'] = opts.no_tests
806 cfg_dict['dont_discover_nodes'] = opts.dont_discover_nodes
koder aka kdanilov6c491062015-04-09 22:33:13 +0300807
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300808 for stage in stages:
809 ok = False
810 with log_stage(stage):
koder aka kdanilovda45e882015-04-06 02:24:42 +0300811 stage(cfg_dict, ctx)
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300812 ok = True
813 if not ok:
814 break
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300815
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300816 exc, cls, tb = sys.exc_info()
817 for stage in ctx.clear_calls_stack[::-1]:
818 with log_stage(stage):
819 stage(cfg_dict, ctx)
820
821 logger.debug("Start utils.cleanup")
822 for clean_func, args, kwargs in utils.iter_clean_func():
823 with log_stage(clean_func):
824 clean_func(*args, **kwargs)
koder aka kdanilov2c473092015-03-29 17:12:13 +0300825
koder aka kdanilove2de58c2015-04-24 22:59:36 +0300826 if exc is None:
827 for report_stage in report_stages:
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300828 with log_stage(report_stage):
829 report_stage(cfg_dict, ctx)
koder aka kdanilove87ae652015-04-20 02:14:35 +0300830
831 logger.info("All info stored in {0} folder".format(cfg_dict['var_dir']))
koder aka kdanilove2de58c2015-04-24 22:59:36 +0300832
833 if exc is None:
834 logger.info("Tests finished successfully")
835 return 0
836 else:
837 logger.error("Tests are failed. See detailed error above")
838 return 1