blob: 4484d453ff7016ddecc0708c1e1cf8cdd7b46f47 [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
koder aka kdanilov170936a2015-06-27 22:51:17 +0300441 if len(group.items()) != 1:
442 msg = "Items in tests section should have len == 1"
443 logger.error(msg)
444 raise utils.StopTestError(msg)
445
koder aka kdanilovcee43342015-04-14 22:52:53 +0300446 key, config = group.items()[0]
447
448 if 'start_test_nodes' == key:
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300449 if 'openstack' not in config:
450 msg = "No openstack block in config - can't spawn vm's"
451 logger.error(msg)
452 raise utils.StopTestError(msg)
453
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300454 num_test_nodes = sum(1 for node in ctx.nodes
455 if 'testnode' in node.roles)
456
457 vm_ctx = create_vms_ctx(ctx, cfg, config['openstack'],
458 num_test_nodes)
459 with vm_ctx as new_nodes:
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300460 if len(new_nodes) != 0:
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300461 logger.debug("Connecting to new nodes")
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300462 connect_all(new_nodes, True)
koder aka kdanilovcee43342015-04-14 22:52:53 +0300463
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300464 for node in new_nodes:
465 if node.connection is None:
466 msg = "Failed to connect to vm {0}"
467 raise RuntimeError(msg.format(node.get_conn_id()))
koder aka kdanilovcee43342015-04-14 22:52:53 +0300468
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300469 with with_sensors_util(cfg_dict, ctx.nodes):
470 for test_group in config.get('tests', []):
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300471 for tp, res in run_tests(cfg, test_group, ctx.nodes):
472 ctx.results[tp].extend(res)
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300473 else:
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300474 with with_sensors_util(cfg_dict, ctx.nodes):
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300475 for tp, res in run_tests(cfg, group, ctx.nodes):
476 ctx.results[tp].extend(res)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300477
gstepanov023c1e42015-04-08 15:50:19 +0300478
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300479def shut_down_vms_stage(cfg, ctx):
koder aka kdanilov66839a92015-04-11 13:22:31 +0300480 vm_ids_fname = cfg_dict['vm_ids_fname']
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300481 if ctx.openstack_nodes_ids is None:
koder aka kdanilov66839a92015-04-11 13:22:31 +0300482 nodes_ids = open(vm_ids_fname).read().split()
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300483 else:
484 nodes_ids = ctx.openstack_nodes_ids
485
koder aka kdanilov652cd802015-04-13 12:21:07 +0300486 if len(nodes_ids) != 0:
487 logger.info("Removing nodes")
488 start_vms.clear_nodes(nodes_ids)
489 logger.info("Nodes has been removed")
gstepanov023c1e42015-04-08 15:50:19 +0300490
koder aka kdanilov66839a92015-04-11 13:22:31 +0300491 if os.path.exists(vm_ids_fname):
492 os.remove(vm_ids_fname)
gstepanov023c1e42015-04-08 15:50:19 +0300493
koder aka kdanilov66839a92015-04-11 13:22:31 +0300494
495def store_nodes_in_log(cfg, nodes_ids):
496 with open(cfg['vm_ids_fname'], 'w') as fd:
497 fd.write("\n".join(nodes_ids))
gstepanov023c1e42015-04-08 15:50:19 +0300498
499
500def clear_enviroment(cfg, ctx):
koder aka kdanilov66839a92015-04-11 13:22:31 +0300501 if os.path.exists(cfg_dict['vm_ids_fname']):
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300502 shut_down_vms_stage(cfg, ctx)
gstepanov023c1e42015-04-08 15:50:19 +0300503
504
koder aka kdanilovda45e882015-04-06 02:24:42 +0300505def disconnect_stage(cfg, ctx):
koder aka kdanilov652cd802015-04-13 12:21:07 +0300506 ssh_utils.close_all_sessions()
507
koder aka kdanilovda45e882015-04-06 02:24:42 +0300508 for node in ctx.nodes:
509 if node.connection is not None:
510 node.connection.close()
511
512
koder aka kdanilov66839a92015-04-11 13:22:31 +0300513def store_raw_results_stage(cfg, ctx):
514
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300515 raw_results = cfg_dict['raw_results']
koder aka kdanilov66839a92015-04-11 13:22:31 +0300516
517 if os.path.exists(raw_results):
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300518 cont = yaml_load(open(raw_results).read())
koder aka kdanilov66839a92015-04-11 13:22:31 +0300519 else:
520 cont = []
521
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300522 cont.extend(utils.yamable(ctx.results).items())
koder aka kdanilov66839a92015-04-11 13:22:31 +0300523 raw_data = pretty_yaml.dumps(cont)
524
525 with open(raw_results, "w") as fd:
526 fd.write(raw_data)
527
528
529def console_report_stage(cfg, ctx):
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300530 first_report = True
531 text_rep_fname = cfg['text_report_file']
532 with open(text_rep_fname, "w") as fd:
533 for tp, data in ctx.results.items():
534 if 'io' == tp and data is not None:
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300535 rep = IOPerfTest.format_for_console(data)
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300536 elif tp in ['mysql', 'pgbench'] and data is not None:
537 rep = MysqlTest.format_for_console(data)
538 else:
539 logger.warning("Can't generate text report for " + tp)
540 continue
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300541
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300542 fd.write(rep)
543 fd.write("\n")
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300544
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300545 if first_report:
546 logger.info("Text report were stored in " + text_rep_fname)
547 first_report = False
548
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300549 print("\n" + rep + "\n")
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300550
koder aka kdanilov66839a92015-04-11 13:22:31 +0300551
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300552def test_load_report_stage(cfg, ctx):
553 load_rep_fname = cfg['load_report_file']
554 found = False
555 for idx, (tp, data) in enumerate(ctx.results.items()):
556 if 'io' == tp and data is not None:
557 if found:
558 logger.error("Making reports for more than one " +
559 "io block isn't supported! All " +
560 "report, except first are skipped")
561 continue
562 found = True
563 report.make_load_report(idx, cfg['results'], load_rep_fname)
564
565
koder aka kdanilove87ae652015-04-20 02:14:35 +0300566def html_report_stage(cfg, ctx):
Yulia Portnova8ca20572015-04-14 14:09:39 +0300567 html_rep_fname = cfg['html_report_file']
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300568 found = False
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300569 for tp, data in ctx.results.items():
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300570 if 'io' == tp and data is not None:
571 if found:
572 logger.error("Making reports for more than one " +
573 "io block isn't supported! All " +
574 "report, except first are skipped")
575 continue
576 found = True
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300577 report.make_io_report(data,
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300578 cfg.get('comment', ''),
579 html_rep_fname,
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300580 lab_info=ctx.hw_info)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300581
koder aka kdanilovda45e882015-04-06 02:24:42 +0300582
583def complete_log_nodes_statistic(cfg, ctx):
584 nodes = ctx.nodes
585 for node in nodes:
586 logger.debug(str(node))
587
588
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300589def load_data_from_file(var_dir, _, ctx):
590 raw_results = os.path.join(var_dir, 'raw_results.yaml')
591 ctx.results = {}
592 for tp, results in yaml_load(open(raw_results).read()):
593 cls = TOOL_TYPE_MAPPER[tp]
594 ctx.results[tp] = map(cls.load, results)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300595
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300596
koder aka kdanilov6b872662015-06-23 01:58:36 +0300597def load_data_from_path(var_dir):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300598 res_dir = os.path.join(var_dir, 'results')
koder aka kdanilov6b872662015-06-23 01:58:36 +0300599 res = {}
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300600 for dir_name in os.listdir(res_dir):
601 dir_path = os.path.join(res_dir, dir_name)
602 if not os.path.isdir(dir_path):
603 continue
604 rr = re.match(r"(?P<type>[a-z]+)_\d+$", dir_name)
605 if rr is None:
606 continue
607 tp = rr.group('type')
koder aka kdanilov6b872662015-06-23 01:58:36 +0300608 arr = res.setdefault(tp, [])
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300609 arr.extend(TOOL_TYPE_MAPPER[tp].load(dir_path))
koder aka kdanilov6b872662015-06-23 01:58:36 +0300610 return res
611
612
613def load_data_from_path_stage(var_dir, _, ctx):
614 for tp, vals in load_data_from_path(var_dir).items():
615 ctx.results.setdefault(tp, []).extend(vals)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300616
617
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300618def load_data_from(var_dir):
koder aka kdanilov6b872662015-06-23 01:58:36 +0300619 return functools.partial(load_data_from_path_stage, var_dir)
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300620
621
koder aka kdanilovcee43342015-04-14 22:52:53 +0300622def parse_args(argv):
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300623 descr = "Disk io performance test suite"
624 parser = argparse.ArgumentParser(prog='wally', description=descr)
koder aka kdanilovcee43342015-04-14 22:52:53 +0300625
koder aka kdanilov170936a2015-06-27 22:51:17 +0300626 # subparsers = parser.add_subparsers()
627 # test_parser = subparsers.add_parser('test', help='run tests')
628
koder aka kdanilovcee43342015-04-14 22:52:53 +0300629 parser.add_argument("-l", dest='extra_logs',
630 action='store_true', default=False,
631 help="print some extra log info")
koder aka kdanilovcee43342015-04-14 22:52:53 +0300632 parser.add_argument("-b", '--build_description',
633 type=str, default="Build info")
634 parser.add_argument("-i", '--build_id', type=str, default="id")
635 parser.add_argument("-t", '--build_type', type=str, default="GA")
636 parser.add_argument("-u", '--username', type=str, default="admin")
koder aka kdanilove87ae652015-04-20 02:14:35 +0300637 parser.add_argument("-n", '--no-tests', action='store_true',
638 help="Don't run tests", default=False)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300639 parser.add_argument("-p", '--post-process-only', metavar="VAR_DIR",
640 help="Only process data from previour run")
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300641 parser.add_argument("-x", '--xxx', action='store_true')
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300642 parser.add_argument("-k", '--keep-vm', action='store_true',
643 help="Don't remove test vm's", default=False)
koder aka kdanilove87ae652015-04-20 02:14:35 +0300644 parser.add_argument("-d", '--dont-discover-nodes', action='store_true',
645 help="Don't connect/discover fuel nodes",
646 default=False)
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300647 parser.add_argument("-r", '--no-html-report', action='store_true',
648 help="Skip html report", default=False)
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300649 parser.add_argument("--params", metavar="testname.paramname",
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300650 help="Test params", default=[])
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300651 parser.add_argument("--ls", action='store_true', default=False)
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300652 parser.add_argument("-c", "--comment", default="")
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300653 parser.add_argument("config_file")
koder aka kdanilovcee43342015-04-14 22:52:53 +0300654
655 return parser.parse_args(argv[1:])
656
657
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300658def get_stage_name(func):
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300659 nm = get_func_name(func)
660 if nm.endswith("stage"):
661 return nm
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300662 else:
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300663 return nm + " stage"
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300664
665
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300666def get_test_names(raw_res):
667 res = set()
668 for tp, data in raw_res:
669 for block in data:
670 res.add("{0}({1})".format(tp, block.get('test_name', '-')))
671 return res
koder aka kdanilovbb5fe072015-05-21 02:50:23 +0300672
673
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300674def list_results(path):
675 results = []
676
677 for dname in os.listdir(path):
678
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300679 files_cfg = get_test_files(os.path.join(path, dname))
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300680
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300681 if not os.path.isfile(files_cfg['raw_results']):
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300682 continue
683
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300684 mt = os.path.getmtime(files_cfg['raw_results'])
685 res_mtime = time.ctime(mt)
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300686
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300687 raw_res = yaml_load(open(files_cfg['raw_results']).read())
688 test_names = ",".join(sorted(get_test_names(raw_res)))
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300689
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300690 params = load_run_params(files_cfg['run_params_file'])
koder aka kdanilovbb5fe072015-05-21 02:50:23 +0300691
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300692 comm = params.get('comment')
693 results.append((mt, dname, test_names, res_mtime,
694 '-' if comm is None else comm))
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300695
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300696 tab = texttable.Texttable(max_width=200)
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300697 tab.set_deco(tab.HEADER | tab.VLINES | tab.BORDER)
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300698 tab.set_cols_align(["l", "l", "l", "l"])
699 results.sort()
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300700
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300701 for data in results[::-1]:
702 tab.add_row(data[1:])
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300703
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300704 tab.header(["Name", "Tests", "etime", "Comment"])
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300705
706 print(tab.draw())
707
708
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300709def get_func_name(obj):
710 if hasattr(obj, '__name__'):
711 return obj.__name__
712 if hasattr(obj, 'func_name'):
713 return obj.func_name
714 return obj.func.func_name
715
716
717@contextlib.contextmanager
718def log_stage(func):
719 msg_templ = "Exception during {0}: {1!s}"
720 msg_templ_no_exc = "During {0}"
721
722 logger.info("Start " + get_stage_name(func))
723
724 try:
725 yield
726 except utils.StopTestError as exc:
727 logger.error(msg_templ.format(
728 get_func_name(func), exc))
729 except Exception:
730 logger.exception(msg_templ_no_exc.format(
731 get_func_name(func)))
732
733
koder aka kdanilov3f356262015-02-13 08:06:14 -0800734def main(argv):
koder aka kdanilovbb5fe072015-05-21 02:50:23 +0300735 if faulthandler is not None:
736 faulthandler.register(signal.SIGUSR1, all_threads=True)
737
koder aka kdanilove06762a2015-03-22 23:32:09 +0200738 opts = parse_args(argv)
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300739
koder aka kdanilov170936a2015-06-27 22:51:17 +0300740 # x = load_data_from_path("/var/wally_results/uncorroborant_dinah")
741 # y = load_data_from_path("/var/wally_results/nonmelting_jamal")
koder aka kdanilov6b872662015-06-23 01:58:36 +0300742 # print(IOPerfTest.format_diff_for_console([x['io'], y['io']]))
743 # exit(1)
744
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300745 if opts.ls:
746 list_results(opts.config_file)
747 exit(0)
748
749 data_dir = load_config(opts.config_file, opts.post_process_only)
750
751 if opts.post_process_only is None:
752 cfg_dict['comment'] = opts.comment
753 save_run_params()
koder aka kdanilov2c473092015-03-29 17:12:13 +0300754
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300755 if cfg_dict.get('logging', {}).get("extra_logs", False) or opts.extra_logs:
koder aka kdanilov170936a2015-06-27 22:51:17 +0300756 # level = logging.DEBUG
757 level = logging.INFO
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300758 else:
759 level = logging.WARNING
760
761 setup_loggers(level, cfg_dict['log_file'])
762
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300763 if not os.path.exists(cfg_dict['saved_config_file']):
764 with open(cfg_dict['saved_config_file'], 'w') as fd:
765 fd.write(open(opts.config_file).read())
766
koder aka kdanilov66839a92015-04-11 13:22:31 +0300767 if opts.post_process_only is not None:
768 stages = [
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300769 load_data_from(data_dir)
koder aka kdanilov66839a92015-04-11 13:22:31 +0300770 ]
771 else:
772 stages = [
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300773 discover_stage
774 ]
775
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300776 stages.extend([
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300777 reuse_vms_stage,
koder aka kdanilov66839a92015-04-11 13:22:31 +0300778 log_nodes_statistic,
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300779 save_nodes_stage,
780 connect_stage])
781
782 if cfg_dict.get('collect_info', True):
783 stages.append(collect_hw_info_stage)
784
785 stages.extend([
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300786 # deploy_sensors_stage,
koder aka kdanilov66839a92015-04-11 13:22:31 +0300787 run_tests_stage,
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300788 store_raw_results_stage,
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300789 # gather_sensors_stage
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300790 ])
koder aka kdanilov66839a92015-04-11 13:22:31 +0300791
koder aka kdanilove87ae652015-04-20 02:14:35 +0300792 report_stages = [
793 console_report_stage,
koder aka kdanilove87ae652015-04-20 02:14:35 +0300794 ]
795
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300796 if opts.xxx:
797 report_stages.append(test_load_report_stage)
798 elif not opts.no_html_report:
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300799 report_stages.append(html_report_stage)
800
koder aka kdanilov652cd802015-04-13 12:21:07 +0300801 logger.info("All info would be stored into {0}".format(
802 cfg_dict['var_dir']))
gstepanovcd256d62015-04-07 17:47:32 +0300803
koder aka kdanilovda45e882015-04-06 02:24:42 +0300804 ctx = Context()
koder aka kdanilov6b872662015-06-23 01:58:36 +0300805 ctx.results = {}
gstepanovaffcdb12015-04-07 17:18:29 +0300806 ctx.build_meta['build_id'] = opts.build_id
807 ctx.build_meta['build_descrption'] = opts.build_description
808 ctx.build_meta['build_type'] = opts.build_type
809 ctx.build_meta['username'] = opts.username
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300810 ctx.sensors_data = SensorDatastore()
koder aka kdanilove87ae652015-04-20 02:14:35 +0300811
koder aka kdanilov168f6092015-04-19 02:33:38 +0300812 cfg_dict['keep_vm'] = opts.keep_vm
koder aka kdanilove87ae652015-04-20 02:14:35 +0300813 cfg_dict['no_tests'] = opts.no_tests
814 cfg_dict['dont_discover_nodes'] = opts.dont_discover_nodes
koder aka kdanilov6c491062015-04-09 22:33:13 +0300815
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300816 for stage in stages:
817 ok = False
818 with log_stage(stage):
koder aka kdanilovda45e882015-04-06 02:24:42 +0300819 stage(cfg_dict, ctx)
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300820 ok = True
821 if not ok:
822 break
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300823
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300824 exc, cls, tb = sys.exc_info()
825 for stage in ctx.clear_calls_stack[::-1]:
826 with log_stage(stage):
827 stage(cfg_dict, ctx)
828
829 logger.debug("Start utils.cleanup")
830 for clean_func, args, kwargs in utils.iter_clean_func():
831 with log_stage(clean_func):
832 clean_func(*args, **kwargs)
koder aka kdanilov2c473092015-03-29 17:12:13 +0300833
koder aka kdanilove2de58c2015-04-24 22:59:36 +0300834 if exc is None:
835 for report_stage in report_stages:
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300836 with log_stage(report_stage):
837 report_stage(cfg_dict, ctx)
koder aka kdanilove87ae652015-04-20 02:14:35 +0300838
839 logger.info("All info stored in {0} folder".format(cfg_dict['var_dir']))
koder aka kdanilove2de58c2015-04-24 22:59:36 +0300840
841 if exc is None:
842 logger.info("Tests finished successfully")
843 return 0
844 else:
845 logger.error("Tests are failed. See detailed error above")
846 return 1