blob: 42e96ff4972772b52168e5ecca67198a58f928ec [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 kdanilov2c473092015-03-29 17:12:13 +03005import Queue
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -08006import pprint
koder aka kdanilove21d7472015-02-14 19:02:04 -08007import logging
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -08008import argparse
koder aka kdanilov168f6092015-04-19 02:33:38 +03009import functools
koder aka kdanilov2c473092015-03-29 17:12:13 +030010import threading
koder aka kdanilov168f6092015-04-19 02:33:38 +030011import contextlib
koder aka kdanilov2c473092015-03-29 17:12:13 +030012import collections
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080013
koder aka kdanilov66839a92015-04-11 13:22:31 +030014import yaml
koder aka kdanilov2c473092015-03-29 17:12:13 +030015from concurrent.futures import ThreadPoolExecutor
koder aka kdanilov6c491062015-04-09 22:33:13 +030016
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030017from wally import pretty_yaml
koder aka kdanilov168f6092015-04-19 02:33:38 +030018from wally.tests_sensors import deploy_sensors_stage
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030019from wally.discover import discover, Node, undiscover
20from wally import utils, report, ssh_utils, start_vms
21from wally.suits.itest import IOPerfTest, PgBenchTest
22from wally.config import cfg_dict, load_config, setup_loggers
koder aka kdanilov2c473092015-03-29 17:12:13 +030023
24
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030025logger = logging.getLogger("wally")
koder aka kdanilovcee43342015-04-14 22:52:53 +030026
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080027
Yulia Portnova7ddfa732015-02-24 17:32:58 +020028def format_result(res, formatter):
koder aka kdanilove21d7472015-02-14 19:02:04 -080029 data = "\n{0}\n".format("=" * 80)
30 data += pprint.pformat(res) + "\n"
31 data += "{0}\n".format("=" * 80)
koder aka kdanilovfe056622015-02-19 08:46:15 -080032 templ = "{0}\n\n====> {1}\n\n{2}\n\n"
Yulia Portnova7ddfa732015-02-24 17:32:58 +020033 return templ.format(data, formatter(res), "=" * 80)
koder aka kdanilove21d7472015-02-14 19:02:04 -080034
35
koder aka kdanilov1c2b5112015-04-10 16:53:51 +030036class Context(object):
37 def __init__(self):
38 self.build_meta = {}
39 self.nodes = []
40 self.clear_calls_stack = []
41 self.openstack_nodes_ids = []
koder aka kdanilov168f6092015-04-19 02:33:38 +030042 self.sensors_mon_q = None
koder aka kdanilov1c2b5112015-04-10 16:53:51 +030043
44
koder aka kdanilov168f6092015-04-19 02:33:38 +030045def connect_one(node, vm=False):
koder aka kdanilov5d589b42015-03-26 12:25:51 +020046 try:
koder aka kdanilov2c473092015-03-29 17:12:13 +030047 ssh_pref = "ssh://"
48 if node.conn_url.startswith(ssh_pref):
49 url = node.conn_url[len(ssh_pref):]
koder aka kdanilov168f6092015-04-19 02:33:38 +030050
51 if vm:
52 ret_count = 24
53 log_warns = False
54 else:
55 ret_count = 3
56 log_warns = True
57
58 node.connection = ssh_utils.connect(url,
59 retry_count=ret_count,
60 log_warns=log_warns)
koder aka kdanilov2c473092015-03-29 17:12:13 +030061 else:
62 raise ValueError("Unknown url type {0}".format(node.conn_url))
koder aka kdanilov3a6633e2015-03-26 18:20:00 +020063 except Exception:
koder aka kdanilov168f6092015-04-19 02:33:38 +030064 logger.exception("During connect to " + node.get_conn_id())
65 node.connection = None
koder aka kdanilov5d589b42015-03-26 12:25:51 +020066
67
koder aka kdanilov168f6092015-04-19 02:33:38 +030068def connect_all(nodes, vm=False):
koder aka kdanilov2c473092015-03-29 17:12:13 +030069 logger.info("Connecting to nodes")
70 with ThreadPoolExecutor(32) as pool:
koder aka kdanilov168f6092015-04-19 02:33:38 +030071 connect_one_f = functools.partial(connect_one, vm=vm)
72 list(pool.map(connect_one_f, nodes))
koder aka kdanilov2c473092015-03-29 17:12:13 +030073
74
koder aka kdanilov652cd802015-04-13 12:21:07 +030075def test_thread(test, node, barrier, res_q):
koder aka kdanilov2c473092015-03-29 17:12:13 +030076 try:
77 logger.debug("Run preparation for {0}".format(node.conn_url))
78 test.pre_run(node.connection)
79 logger.debug("Run test for {0}".format(node.conn_url))
80 test.run(node.connection, barrier)
koder aka kdanilov652cd802015-04-13 12:21:07 +030081 except Exception as exc:
koder aka kdanilov2c473092015-03-29 17:12:13 +030082 logger.exception("In test {0} for node {1}".format(test, node))
koder aka kdanilov652cd802015-04-13 12:21:07 +030083 res_q.put(exc)
koder aka kdanilov2c473092015-03-29 17:12:13 +030084
koder aka kdanilov4500a5f2015-04-17 16:55:17 +030085 try:
86 test.cleanup(node.connection)
87 except:
88 msg = "Duringf cleanup - in test {0} for node {1}"
89 logger.exception(msg.format(test, node))
90
koder aka kdanilov2c473092015-03-29 17:12:13 +030091
koder aka kdanilovcee43342015-04-14 22:52:53 +030092def run_tests(test_block, nodes):
koder aka kdanilov2c473092015-03-29 17:12:13 +030093 tool_type_mapper = {
94 "io": IOPerfTest,
95 "pgbench": PgBenchTest,
96 }
97
98 test_nodes = [node for node in nodes
99 if 'testnode' in node.roles]
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300100 test_number_per_type = {}
koder aka kdanilov2c473092015-03-29 17:12:13 +0300101 res_q = Queue.Queue()
102
koder aka kdanilovcee43342015-04-14 22:52:53 +0300103 for name, params in test_block.items():
104 logger.info("Starting {0} tests".format(name))
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300105 test_num = test_number_per_type.get(name, 0)
106 test_number_per_type[name] = test_num + 1
koder aka kdanilovcee43342015-04-14 22:52:53 +0300107 threads = []
108 barrier = utils.Barrier(len(test_nodes))
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300109
koder aka kdanilovcee43342015-04-14 22:52:53 +0300110 for node in test_nodes:
111 msg = "Starting {0} test on {1} node"
112 logger.debug(msg.format(name, node.conn_url))
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300113
114 dr = os.path.join(
115 cfg_dict['test_log_directory'],
116 "{0}_{1}_{2}".format(name, test_num, node.get_ip())
117 )
118
119 if not os.path.exists(dr):
120 os.makedirs(dr)
121
122 test = tool_type_mapper[name](params, res_q.put, dr,
123 node=node.get_ip())
koder aka kdanilovcee43342015-04-14 22:52:53 +0300124 th = threading.Thread(None, test_thread, None,
125 (test, node, barrier, res_q))
126 threads.append(th)
127 th.daemon = True
128 th.start()
koder aka kdanilov2c473092015-03-29 17:12:13 +0300129
koder aka kdanilovcee43342015-04-14 22:52:53 +0300130 def gather_results(res_q, results):
131 while not res_q.empty():
132 val = res_q.get()
koder aka kdanilov66839a92015-04-11 13:22:31 +0300133
koder aka kdanilovcee43342015-04-14 22:52:53 +0300134 if isinstance(val, Exception):
135 msg = "Exception during test execution: {0}"
136 raise ValueError(msg.format(val.message))
koder aka kdanilov652cd802015-04-13 12:21:07 +0300137
koder aka kdanilovcee43342015-04-14 22:52:53 +0300138 results.append(val)
koder aka kdanilov652cd802015-04-13 12:21:07 +0300139
koder aka kdanilovcee43342015-04-14 22:52:53 +0300140 results = []
koder aka kdanilov652cd802015-04-13 12:21:07 +0300141
koder aka kdanilovcee43342015-04-14 22:52:53 +0300142 while True:
143 for th in threads:
144 th.join(1)
145 gather_results(res_q, results)
koder aka kdanilov652cd802015-04-13 12:21:07 +0300146
koder aka kdanilovcee43342015-04-14 22:52:53 +0300147 if all(not th.is_alive() for th in threads):
148 break
koder aka kdanilov652cd802015-04-13 12:21:07 +0300149
koder aka kdanilovcee43342015-04-14 22:52:53 +0300150 gather_results(res_q, results)
151 yield name, test.merge_results(results)
koder aka kdanilov2c473092015-03-29 17:12:13 +0300152
153
koder aka kdanilovda45e882015-04-06 02:24:42 +0300154def log_nodes_statistic(_, ctx):
155 nodes = ctx.nodes
koder aka kdanilov2c473092015-03-29 17:12:13 +0300156 logger.info("Found {0} nodes total".format(len(nodes)))
157 per_role = collections.defaultdict(lambda: 0)
158 for node in nodes:
159 for role in node.roles:
160 per_role[role] += 1
161
162 for role, count in sorted(per_role.items()):
163 logger.debug("Found {0} nodes with role {1}".format(count, role))
164
165
koder aka kdanilovda45e882015-04-06 02:24:42 +0300166def connect_stage(cfg, ctx):
167 ctx.clear_calls_stack.append(disconnect_stage)
168 connect_all(ctx.nodes)
169
koder aka kdanilov168f6092015-04-19 02:33:38 +0300170 all_ok = True
koder aka kdanilovda45e882015-04-06 02:24:42 +0300171
koder aka kdanilov168f6092015-04-19 02:33:38 +0300172 for node in ctx.nodes:
173 if node.connection is None:
174 if 'testnode' in node.roles:
175 msg = "Can't connect to testnode {0}"
176 raise RuntimeError(msg.format(node.get_conn_id()))
177 else:
178 msg = "Node {0} would be excluded - can't connect"
179 logger.warning(msg.format(node.get_conn_id()))
180 all_ok = False
181
182 if all_ok:
183 logger.info("All nodes connected successfully")
184
185 ctx.nodes = [node for node in ctx.nodes
186 if node.connection is not None]
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300187
188
koder aka kdanilovda45e882015-04-06 02:24:42 +0300189def discover_stage(cfg, ctx):
koder aka kdanilov652cd802015-04-13 12:21:07 +0300190 if cfg.get('discover') is not None:
koder aka kdanilovda45e882015-04-06 02:24:42 +0300191 discover_objs = [i.strip() for i in cfg['discover'].strip().split(",")]
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300192
193 nodes, clean_data = discover(ctx, discover_objs,
194 cfg['clouds'], cfg['var_dir'])
koder aka kdanilov168f6092015-04-19 02:33:38 +0300195
196 def undiscover_stage(cfg, ctx):
197 undiscover(clean_data)
198
199 ctx.clear_calls_stack.append(undiscover_stage)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300200 ctx.nodes.extend(nodes)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300201
202 for url, roles in cfg.get('explicit_nodes', {}).items():
203 ctx.nodes.append(Node(url, roles.split(",")))
204
205
koder aka kdanilovcee43342015-04-14 22:52:53 +0300206def get_os_credentials(cfg, ctx, creds_type):
207 creds = None
koder aka kdanilovda45e882015-04-06 02:24:42 +0300208
koder aka kdanilovcee43342015-04-14 22:52:53 +0300209 if creds_type == 'clouds':
210 if 'openstack' in cfg['clouds']:
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300211 os_cfg = cfg['clouds']['openstack']
koder aka kdanilovcee43342015-04-14 22:52:53 +0300212
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300213 tenant = os_cfg['OS_TENANT_NAME'].strip()
214 user = os_cfg['OS_USERNAME'].strip()
215 passwd = os_cfg['OS_PASSWORD'].strip()
216 auth_url = os_cfg['OS_AUTH_URL'].strip()
217
koder aka kdanilovcee43342015-04-14 22:52:53 +0300218 elif 'fuel' in cfg['clouds'] and \
219 'openstack_env' in cfg['clouds']['fuel']:
220 creds = ctx.fuel_openstack_creds
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300221
koder aka kdanilovcee43342015-04-14 22:52:53 +0300222 elif creds_type == 'ENV':
223 user, passwd, tenant, auth_url = start_vms.ostack_get_creds()
224 elif os.path.isfile(creds_type):
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300225 raise NotImplementedError()
226 # user, passwd, tenant, auth_url = start_vms.ostack_get_creds()
koder aka kdanilovcee43342015-04-14 22:52:53 +0300227 else:
228 msg = "Creds {0!r} isn't supported".format(creds_type)
229 raise ValueError(msg)
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300230
koder aka kdanilovcee43342015-04-14 22:52:53 +0300231 if creds is None:
232 creds = {'name': user,
233 'passwd': passwd,
234 'tenant': tenant,
235 'auth_url': auth_url}
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300236
koder aka kdanilovcee43342015-04-14 22:52:53 +0300237 return creds
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +0300238
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300239
koder aka kdanilov168f6092015-04-19 02:33:38 +0300240@contextlib.contextmanager
241def create_vms_ctx(ctx, cfg, config):
242 params = config['vm_params'].copy()
243 os_nodes_ids = []
244
245 os_creds_type = config['creds']
246 os_creds = get_os_credentials(cfg, ctx, os_creds_type)
247
248 start_vms.nova_connect(**os_creds)
249
250 logger.info("Preparing openstack")
251 start_vms.prepare_os_subpr(**os_creds)
252
253 new_nodes = []
254 try:
255 params['group_name'] = cfg_dict['run_uuid']
256 for new_node, node_id in start_vms.launch_vms(params):
257 new_node.roles.append('testnode')
258 ctx.nodes.append(new_node)
259 os_nodes_ids.append(node_id)
260 new_nodes.append(new_node)
261
262 store_nodes_in_log(cfg, os_nodes_ids)
263 ctx.openstack_nodes_ids = os_nodes_ids
264
265 yield new_nodes
266
267 finally:
268 if not cfg['keep_vm']:
269 shut_down_vms_stage(cfg, ctx)
270
271
koder aka kdanilovcee43342015-04-14 22:52:53 +0300272def run_tests_stage(cfg, ctx):
273 ctx.results = []
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300274
koder aka kdanilovcee43342015-04-14 22:52:53 +0300275 if 'tests' not in cfg:
276 return
gstepanov023c1e42015-04-08 15:50:19 +0300277
koder aka kdanilovcee43342015-04-14 22:52:53 +0300278 for group in cfg['tests']:
279
280 assert len(group.items()) == 1
281 key, config = group.items()[0]
282
283 if 'start_test_nodes' == key:
koder aka kdanilov168f6092015-04-19 02:33:38 +0300284 with create_vms_ctx(ctx, cfg, config) as new_nodes:
285 connect_all(new_nodes, True)
koder aka kdanilovcee43342015-04-14 22:52:53 +0300286
koder aka kdanilov168f6092015-04-19 02:33:38 +0300287 for node in new_nodes:
288 if node.connection is None:
289 msg = "Failed to connect to vm {0}"
290 raise RuntimeError(msg.format(node.get_conn_id()))
koder aka kdanilovcee43342015-04-14 22:52:53 +0300291
koder aka kdanilov168f6092015-04-19 02:33:38 +0300292 deploy_sensors_stage(cfg_dict,
293 ctx,
294 nodes=new_nodes,
295 undeploy=False)
koder aka kdanilov12ae0632015-04-15 01:13:43 +0300296
koder aka kdanilovcee43342015-04-14 22:52:53 +0300297 for test_group in config.get('tests', []):
298 ctx.results.extend(run_tests(test_group, ctx.nodes))
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300299 else:
300 ctx.results.extend(run_tests(group, ctx.nodes))
koder aka kdanilovda45e882015-04-06 02:24:42 +0300301
gstepanov023c1e42015-04-08 15:50:19 +0300302
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300303def shut_down_vms_stage(cfg, ctx):
koder aka kdanilov66839a92015-04-11 13:22:31 +0300304 vm_ids_fname = cfg_dict['vm_ids_fname']
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300305 if ctx.openstack_nodes_ids is None:
koder aka kdanilov66839a92015-04-11 13:22:31 +0300306 nodes_ids = open(vm_ids_fname).read().split()
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300307 else:
308 nodes_ids = ctx.openstack_nodes_ids
309
koder aka kdanilov652cd802015-04-13 12:21:07 +0300310 if len(nodes_ids) != 0:
311 logger.info("Removing nodes")
312 start_vms.clear_nodes(nodes_ids)
313 logger.info("Nodes has been removed")
gstepanov023c1e42015-04-08 15:50:19 +0300314
koder aka kdanilov66839a92015-04-11 13:22:31 +0300315 if os.path.exists(vm_ids_fname):
316 os.remove(vm_ids_fname)
gstepanov023c1e42015-04-08 15:50:19 +0300317
koder aka kdanilov66839a92015-04-11 13:22:31 +0300318
319def store_nodes_in_log(cfg, nodes_ids):
320 with open(cfg['vm_ids_fname'], 'w') as fd:
321 fd.write("\n".join(nodes_ids))
gstepanov023c1e42015-04-08 15:50:19 +0300322
323
324def clear_enviroment(cfg, ctx):
koder aka kdanilov66839a92015-04-11 13:22:31 +0300325 if os.path.exists(cfg_dict['vm_ids_fname']):
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300326 shut_down_vms_stage(cfg, ctx)
gstepanov023c1e42015-04-08 15:50:19 +0300327
328
koder aka kdanilovda45e882015-04-06 02:24:42 +0300329def disconnect_stage(cfg, ctx):
koder aka kdanilov652cd802015-04-13 12:21:07 +0300330 ssh_utils.close_all_sessions()
331
koder aka kdanilovda45e882015-04-06 02:24:42 +0300332 for node in ctx.nodes:
333 if node.connection is not None:
334 node.connection.close()
335
336
koder aka kdanilov66839a92015-04-11 13:22:31 +0300337def store_raw_results_stage(cfg, ctx):
338
339 raw_results = os.path.join(cfg_dict['var_dir'], 'raw_results.yaml')
340
341 if os.path.exists(raw_results):
342 cont = yaml.load(open(raw_results).read())
343 else:
344 cont = []
345
koder aka kdanilov168f6092015-04-19 02:33:38 +0300346 cont.extend(utils.yamable(ctx.results))
koder aka kdanilov66839a92015-04-11 13:22:31 +0300347 raw_data = pretty_yaml.dumps(cont)
348
349 with open(raw_results, "w") as fd:
350 fd.write(raw_data)
351
352
353def console_report_stage(cfg, ctx):
354 for tp, data in ctx.results:
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300355 if 'io' == tp and data is not None:
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300356 print(IOPerfTest.format_for_console(data))
koder aka kdanilov66839a92015-04-11 13:22:31 +0300357
358
koder aka kdanilovda45e882015-04-06 02:24:42 +0300359def report_stage(cfg, ctx):
Yulia Portnova8ca20572015-04-14 14:09:39 +0300360 html_rep_fname = cfg['html_report_file']
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300361
362 try:
363 fuel_url = cfg['clouds']['fuel']['url']
364 except KeyError:
365 fuel_url = None
366
367 try:
368 creds = cfg['clouds']['fuel']['creds']
369 except KeyError:
370 creds = None
371
gstepanov69339ac2015-04-16 20:09:33 +0300372 report.make_io_report(ctx.results, html_rep_fname, fuel_url, creds=creds)
koder aka kdanilov652cd802015-04-13 12:21:07 +0300373
Yulia Portnova8ca20572015-04-14 14:09:39 +0300374 logger.info("Html report were stored in " + html_rep_fname)
koder aka kdanilov652cd802015-04-13 12:21:07 +0300375
376 text_rep_fname = cfg_dict['text_report_file']
377 with open(text_rep_fname, "w") as fd:
378 for tp, data in ctx.results:
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300379 if 'io' == tp and data is not None:
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300380 fd.write(IOPerfTest.format_for_console(data))
koder aka kdanilov652cd802015-04-13 12:21:07 +0300381 fd.write("\n")
382 fd.flush()
383
384 logger.info("Text report were stored in " + text_rep_fname)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300385
386
387def complete_log_nodes_statistic(cfg, ctx):
388 nodes = ctx.nodes
389 for node in nodes:
390 logger.debug(str(node))
391
392
koder aka kdanilov66839a92015-04-11 13:22:31 +0300393def load_data_from(var_dir):
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +0300394 def load_data_from_file(cfg, ctx):
koder aka kdanilov66839a92015-04-11 13:22:31 +0300395 raw_results = os.path.join(var_dir, 'raw_results.yaml')
396 ctx.results = yaml.load(open(raw_results).read())
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +0300397 return load_data_from_file
gstepanovcd256d62015-04-07 17:47:32 +0300398
399
koder aka kdanilovcee43342015-04-14 22:52:53 +0300400def parse_args(argv):
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300401 descr = "Disk io performance test suite"
402 parser = argparse.ArgumentParser(prog='wally', description=descr)
koder aka kdanilovcee43342015-04-14 22:52:53 +0300403
404 parser.add_argument("-l", dest='extra_logs',
405 action='store_true', default=False,
406 help="print some extra log info")
koder aka kdanilovcee43342015-04-14 22:52:53 +0300407 parser.add_argument("-b", '--build_description',
408 type=str, default="Build info")
409 parser.add_argument("-i", '--build_id', type=str, default="id")
410 parser.add_argument("-t", '--build_type', type=str, default="GA")
411 parser.add_argument("-u", '--username', type=str, default="admin")
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300412 parser.add_argument("-p", '--post-process-only', metavar="VAR_DIR",
413 help="Only process data from previour run")
414 parser.add_argument("-k", '--keep-vm', action='store_true',
415 help="Don't remove test vm's", default=False)
416 parser.add_argument("config_file")
koder aka kdanilovcee43342015-04-14 22:52:53 +0300417
418 return parser.parse_args(argv[1:])
419
420
koder aka kdanilov3f356262015-02-13 08:06:14 -0800421def main(argv):
koder aka kdanilove06762a2015-03-22 23:32:09 +0200422 opts = parse_args(argv)
koder aka kdanilov2c473092015-03-29 17:12:13 +0300423
koder aka kdanilov66839a92015-04-11 13:22:31 +0300424 if opts.post_process_only is not None:
425 stages = [
426 load_data_from(opts.post_process_only),
427 console_report_stage,
koder aka kdanilov652cd802015-04-13 12:21:07 +0300428 report_stage
koder aka kdanilov66839a92015-04-11 13:22:31 +0300429 ]
430 else:
431 stages = [
432 discover_stage,
433 log_nodes_statistic,
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300434 connect_stage,
koder aka kdanilov66839a92015-04-11 13:22:31 +0300435 deploy_sensors_stage,
436 run_tests_stage,
437 store_raw_results_stage,
438 console_report_stage,
439 report_stage
440 ]
441
koder aka kdanilovcee43342015-04-14 22:52:53 +0300442 load_config(opts.config_file, opts.post_process_only)
koder aka kdanilovf4b82c22015-04-11 13:35:25 +0300443
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300444 if cfg_dict.get('logging', {}).get("extra_logs", False) or opts.extra_logs:
445 level = logging.DEBUG
446 else:
447 level = logging.WARNING
448
449 setup_loggers(level, cfg_dict['log_file'])
koder aka kdanilovf4b82c22015-04-11 13:35:25 +0300450
koder aka kdanilov652cd802015-04-13 12:21:07 +0300451 logger.info("All info would be stored into {0}".format(
452 cfg_dict['var_dir']))
gstepanovcd256d62015-04-07 17:47:32 +0300453
koder aka kdanilovda45e882015-04-06 02:24:42 +0300454 ctx = Context()
gstepanovaffcdb12015-04-07 17:18:29 +0300455 ctx.build_meta['build_id'] = opts.build_id
456 ctx.build_meta['build_descrption'] = opts.build_description
457 ctx.build_meta['build_type'] = opts.build_type
458 ctx.build_meta['username'] = opts.username
koder aka kdanilov168f6092015-04-19 02:33:38 +0300459 cfg_dict['keep_vm'] = opts.keep_vm
koder aka kdanilov6c491062015-04-09 22:33:13 +0300460
koder aka kdanilovda45e882015-04-06 02:24:42 +0300461 try:
462 for stage in stages:
463 logger.info("Start {0.__name__} stage".format(stage))
464 stage(cfg_dict, ctx)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300465 except Exception as exc:
466 msg = "Exception during current stage: {0}".format(exc.message)
467 logger.error(msg)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300468 finally:
469 exc, cls, tb = sys.exc_info()
470 for stage in ctx.clear_calls_stack[::-1]:
471 try:
472 logger.info("Start {0.__name__} stage".format(stage))
473 stage(cfg_dict, ctx)
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300474 except Exception as exc:
475 logger.exception("During {0.__name__} stage".format(stage))
koder aka kdanilov2c473092015-03-29 17:12:13 +0300476
koder aka kdanilovda45e882015-04-06 02:24:42 +0300477 if exc is not None:
478 raise exc, cls, tb
koder aka kdanilov2c473092015-03-29 17:12:13 +0300479
koder aka kdanilovcee43342015-04-14 22:52:53 +0300480 logger.info("All info stored into {0}".format(cfg_dict['var_dir']))
koder aka kdanilove06762a2015-03-22 23:32:09 +0200481 return 0