blob: d4b33bfd17d74478dfa9862dd0ef00aad3ef55f7 [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 kdanilove87ae652015-04-20 02:14:35 +030018from wally.sensors_utils 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 kdanilov0c598a12015-04-21 03:01:40 +030046 if node.conn_url == 'local':
47 node.connection = ssh_utils.connect(node.conn_url)
48 return
49
koder aka kdanilov5d589b42015-03-26 12:25:51 +020050 try:
koder aka kdanilov2c473092015-03-29 17:12:13 +030051 ssh_pref = "ssh://"
52 if node.conn_url.startswith(ssh_pref):
53 url = node.conn_url[len(ssh_pref):]
koder aka kdanilov168f6092015-04-19 02:33:38 +030054
55 if vm:
koder aka kdanilov6b1341a2015-04-21 22:44:21 +030056 conn_timeout = 240
koder aka kdanilov168f6092015-04-19 02:33:38 +030057 else:
koder aka kdanilov6b1341a2015-04-21 22:44:21 +030058 conn_timeout = 30
koder aka kdanilov168f6092015-04-19 02:33:38 +030059
60 node.connection = ssh_utils.connect(url,
koder aka kdanilov6b1341a2015-04-21 22:44:21 +030061 conn_timeout=conn_timeout)
koder aka kdanilov2c473092015-03-29 17:12:13 +030062 else:
63 raise ValueError("Unknown url type {0}".format(node.conn_url))
koder aka kdanilove87ae652015-04-20 02:14:35 +030064 except Exception as exc:
65 # logger.exception("During connect to " + node.get_conn_id())
66 msg = "During connect to {0}: {1}".format(node.get_conn_id(),
67 exc.message)
68 logger.error(msg)
koder aka kdanilov168f6092015-04-19 02:33:38 +030069 node.connection = None
koder aka kdanilov5d589b42015-03-26 12:25:51 +020070
71
koder aka kdanilov168f6092015-04-19 02:33:38 +030072def connect_all(nodes, vm=False):
koder aka kdanilov2c473092015-03-29 17:12:13 +030073 logger.info("Connecting to nodes")
74 with ThreadPoolExecutor(32) as pool:
koder aka kdanilov168f6092015-04-19 02:33:38 +030075 connect_one_f = functools.partial(connect_one, vm=vm)
76 list(pool.map(connect_one_f, nodes))
koder aka kdanilov2c473092015-03-29 17:12:13 +030077
78
koder aka kdanilov652cd802015-04-13 12:21:07 +030079def test_thread(test, node, barrier, res_q):
koder aka kdanilov4d4771c2015-04-23 01:32:02 +030080 exc = None
koder aka kdanilov2c473092015-03-29 17:12:13 +030081 try:
koder aka kdanilova047e1b2015-04-21 23:16:59 +030082 logger.debug("Run preparation for {0}".format(node.get_conn_id()))
koder aka kdanilov4d4771c2015-04-23 01:32:02 +030083 test.pre_run()
koder aka kdanilova047e1b2015-04-21 23:16:59 +030084 logger.debug("Run test for {0}".format(node.get_conn_id()))
koder aka kdanilov4d4771c2015-04-23 01:32:02 +030085 test.run(barrier)
koder aka kdanilov652cd802015-04-13 12:21:07 +030086 except Exception as exc:
koder aka kdanilov2c473092015-03-29 17:12:13 +030087 logger.exception("In test {0} for node {1}".format(test, node))
88
koder aka kdanilov4500a5f2015-04-17 16:55:17 +030089 try:
koder aka kdanilov4d4771c2015-04-23 01:32:02 +030090 test.cleanup()
koder aka kdanilov4500a5f2015-04-17 16:55:17 +030091 except:
92 msg = "Duringf cleanup - in test {0} for node {1}"
93 logger.exception(msg.format(test, node))
94
koder aka kdanilov4d4771c2015-04-23 01:32:02 +030095 if exc is not None:
96 res_q.put(exc)
koder aka kdanilov2c473092015-03-29 17:12:13 +030097
koder aka kdanilov4d4771c2015-04-23 01:32:02 +030098
99def run_tests(test_block, nodes, test_uuid):
koder aka kdanilov2c473092015-03-29 17:12:13 +0300100 tool_type_mapper = {
101 "io": IOPerfTest,
102 "pgbench": PgBenchTest,
103 }
104
105 test_nodes = [node for node in nodes
106 if 'testnode' in node.roles]
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300107 test_number_per_type = {}
koder aka kdanilov2c473092015-03-29 17:12:13 +0300108 res_q = Queue.Queue()
109
koder aka kdanilovcee43342015-04-14 22:52:53 +0300110 for name, params in test_block.items():
111 logger.info("Starting {0} tests".format(name))
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300112 test_num = test_number_per_type.get(name, 0)
113 test_number_per_type[name] = test_num + 1
koder aka kdanilovcee43342015-04-14 22:52:53 +0300114 threads = []
115 barrier = utils.Barrier(len(test_nodes))
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300116
koder aka kdanilovcee43342015-04-14 22:52:53 +0300117 for node in test_nodes:
118 msg = "Starting {0} test on {1} node"
119 logger.debug(msg.format(name, node.conn_url))
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300120
121 dr = os.path.join(
122 cfg_dict['test_log_directory'],
123 "{0}_{1}_{2}".format(name, test_num, node.get_ip())
124 )
125
126 if not os.path.exists(dr):
127 os.makedirs(dr)
128
koder aka kdanilov4d4771c2015-04-23 01:32:02 +0300129 test = tool_type_mapper[name](params, res_q.put, test_uuid, node,
130 log_directory=dr)
koder aka kdanilovcee43342015-04-14 22:52:53 +0300131 th = threading.Thread(None, test_thread, None,
132 (test, node, barrier, res_q))
133 threads.append(th)
134 th.daemon = True
135 th.start()
koder aka kdanilov2c473092015-03-29 17:12:13 +0300136
koder aka kdanilovcee43342015-04-14 22:52:53 +0300137 def gather_results(res_q, results):
138 while not res_q.empty():
139 val = res_q.get()
koder aka kdanilov66839a92015-04-11 13:22:31 +0300140
koder aka kdanilovcee43342015-04-14 22:52:53 +0300141 if isinstance(val, Exception):
142 msg = "Exception during test execution: {0}"
143 raise ValueError(msg.format(val.message))
koder aka kdanilov652cd802015-04-13 12:21:07 +0300144
koder aka kdanilovcee43342015-04-14 22:52:53 +0300145 results.append(val)
koder aka kdanilov652cd802015-04-13 12:21:07 +0300146
koder aka kdanilovcee43342015-04-14 22:52:53 +0300147 results = []
koder aka kdanilov652cd802015-04-13 12:21:07 +0300148
koder aka kdanilove87ae652015-04-20 02:14:35 +0300149 # MAX_WAIT_TIME = 10
150 # end_time = time.time() + MAX_WAIT_TIME
151
152 # while time.time() < end_time:
koder aka kdanilovcee43342015-04-14 22:52:53 +0300153 while True:
154 for th in threads:
155 th.join(1)
156 gather_results(res_q, results)
koder aka kdanilove87ae652015-04-20 02:14:35 +0300157 # if time.time() > end_time:
158 # break
koder aka kdanilov652cd802015-04-13 12:21:07 +0300159
koder aka kdanilovcee43342015-04-14 22:52:53 +0300160 if all(not th.is_alive() for th in threads):
161 break
koder aka kdanilov652cd802015-04-13 12:21:07 +0300162
koder aka kdanilove87ae652015-04-20 02:14:35 +0300163 # if any(th.is_alive() for th in threads):
164 # logger.warning("Some test threads still running")
165
koder aka kdanilovcee43342015-04-14 22:52:53 +0300166 gather_results(res_q, results)
167 yield name, test.merge_results(results)
koder aka kdanilov2c473092015-03-29 17:12:13 +0300168
169
koder aka kdanilovda45e882015-04-06 02:24:42 +0300170def log_nodes_statistic(_, ctx):
171 nodes = ctx.nodes
koder aka kdanilov2c473092015-03-29 17:12:13 +0300172 logger.info("Found {0} nodes total".format(len(nodes)))
173 per_role = collections.defaultdict(lambda: 0)
174 for node in nodes:
175 for role in node.roles:
176 per_role[role] += 1
177
178 for role, count in sorted(per_role.items()):
179 logger.debug("Found {0} nodes with role {1}".format(count, role))
180
181
koder aka kdanilovda45e882015-04-06 02:24:42 +0300182def connect_stage(cfg, ctx):
183 ctx.clear_calls_stack.append(disconnect_stage)
184 connect_all(ctx.nodes)
185
koder aka kdanilov168f6092015-04-19 02:33:38 +0300186 all_ok = True
koder aka kdanilovda45e882015-04-06 02:24:42 +0300187
koder aka kdanilov168f6092015-04-19 02:33:38 +0300188 for node in ctx.nodes:
189 if node.connection is None:
190 if 'testnode' in node.roles:
191 msg = "Can't connect to testnode {0}"
192 raise RuntimeError(msg.format(node.get_conn_id()))
193 else:
194 msg = "Node {0} would be excluded - can't connect"
195 logger.warning(msg.format(node.get_conn_id()))
196 all_ok = False
197
198 if all_ok:
199 logger.info("All nodes connected successfully")
200
201 ctx.nodes = [node for node in ctx.nodes
202 if node.connection is not None]
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300203
204
koder aka kdanilovda45e882015-04-06 02:24:42 +0300205def discover_stage(cfg, ctx):
koder aka kdanilov652cd802015-04-13 12:21:07 +0300206 if cfg.get('discover') is not None:
koder aka kdanilovda45e882015-04-06 02:24:42 +0300207 discover_objs = [i.strip() for i in cfg['discover'].strip().split(",")]
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300208
koder aka kdanilove87ae652015-04-20 02:14:35 +0300209 nodes, clean_data = discover(ctx,
210 discover_objs,
211 cfg['clouds'],
212 cfg['var_dir'],
213 not cfg['dont_discover_nodes'])
koder aka kdanilov168f6092015-04-19 02:33:38 +0300214
215 def undiscover_stage(cfg, ctx):
216 undiscover(clean_data)
217
218 ctx.clear_calls_stack.append(undiscover_stage)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300219 ctx.nodes.extend(nodes)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300220
221 for url, roles in cfg.get('explicit_nodes', {}).items():
222 ctx.nodes.append(Node(url, roles.split(",")))
223
224
koder aka kdanilove87ae652015-04-20 02:14:35 +0300225def get_OS_credentials(cfg, ctx, creds_type):
koder aka kdanilovcee43342015-04-14 22:52:53 +0300226 creds = None
koder aka kdanilovda45e882015-04-06 02:24:42 +0300227
koder aka kdanilovcee43342015-04-14 22:52:53 +0300228 if creds_type == 'clouds':
229 if 'openstack' in cfg['clouds']:
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300230 os_cfg = cfg['clouds']['openstack']
koder aka kdanilovcee43342015-04-14 22:52:53 +0300231
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300232 tenant = os_cfg['OS_TENANT_NAME'].strip()
233 user = os_cfg['OS_USERNAME'].strip()
234 passwd = os_cfg['OS_PASSWORD'].strip()
235 auth_url = os_cfg['OS_AUTH_URL'].strip()
236
koder aka kdanilovcee43342015-04-14 22:52:53 +0300237 elif 'fuel' in cfg['clouds'] and \
238 'openstack_env' in cfg['clouds']['fuel']:
239 creds = ctx.fuel_openstack_creds
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300240
koder aka kdanilovcee43342015-04-14 22:52:53 +0300241 elif creds_type == 'ENV':
242 user, passwd, tenant, auth_url = start_vms.ostack_get_creds()
243 elif os.path.isfile(creds_type):
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300244 raise NotImplementedError()
245 # user, passwd, tenant, auth_url = start_vms.ostack_get_creds()
koder aka kdanilovcee43342015-04-14 22:52:53 +0300246 else:
247 msg = "Creds {0!r} isn't supported".format(creds_type)
248 raise ValueError(msg)
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300249
koder aka kdanilovcee43342015-04-14 22:52:53 +0300250 if creds is None:
251 creds = {'name': user,
252 'passwd': passwd,
253 'tenant': tenant,
254 'auth_url': auth_url}
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300255
koder aka kdanilovcee43342015-04-14 22:52:53 +0300256 return creds
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +0300257
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300258
koder aka kdanilov168f6092015-04-19 02:33:38 +0300259@contextlib.contextmanager
260def create_vms_ctx(ctx, cfg, config):
261 params = config['vm_params'].copy()
262 os_nodes_ids = []
263
264 os_creds_type = config['creds']
koder aka kdanilove87ae652015-04-20 02:14:35 +0300265 os_creds = get_OS_credentials(cfg, ctx, os_creds_type)
koder aka kdanilov168f6092015-04-19 02:33:38 +0300266
267 start_vms.nova_connect(**os_creds)
268
269 logger.info("Preparing openstack")
270 start_vms.prepare_os_subpr(**os_creds)
271
272 new_nodes = []
273 try:
274 params['group_name'] = cfg_dict['run_uuid']
275 for new_node, node_id in start_vms.launch_vms(params):
276 new_node.roles.append('testnode')
277 ctx.nodes.append(new_node)
278 os_nodes_ids.append(node_id)
279 new_nodes.append(new_node)
280
281 store_nodes_in_log(cfg, os_nodes_ids)
282 ctx.openstack_nodes_ids = os_nodes_ids
283
284 yield new_nodes
285
286 finally:
287 if not cfg['keep_vm']:
288 shut_down_vms_stage(cfg, ctx)
289
290
koder aka kdanilovcee43342015-04-14 22:52:53 +0300291def run_tests_stage(cfg, ctx):
292 ctx.results = []
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300293
koder aka kdanilovcee43342015-04-14 22:52:53 +0300294 if 'tests' not in cfg:
295 return
gstepanov023c1e42015-04-08 15:50:19 +0300296
koder aka kdanilovcee43342015-04-14 22:52:53 +0300297 for group in cfg['tests']:
298
299 assert len(group.items()) == 1
300 key, config = group.items()[0]
301
302 if 'start_test_nodes' == key:
koder aka kdanilov168f6092015-04-19 02:33:38 +0300303 with create_vms_ctx(ctx, cfg, config) as new_nodes:
304 connect_all(new_nodes, True)
koder aka kdanilovcee43342015-04-14 22:52:53 +0300305
koder aka kdanilov168f6092015-04-19 02:33:38 +0300306 for node in new_nodes:
307 if node.connection is None:
308 msg = "Failed to connect to vm {0}"
309 raise RuntimeError(msg.format(node.get_conn_id()))
koder aka kdanilovcee43342015-04-14 22:52:53 +0300310
koder aka kdanilov168f6092015-04-19 02:33:38 +0300311 deploy_sensors_stage(cfg_dict,
312 ctx,
313 nodes=new_nodes,
314 undeploy=False)
koder aka kdanilov12ae0632015-04-15 01:13:43 +0300315
koder aka kdanilove87ae652015-04-20 02:14:35 +0300316 if not cfg['no_tests']:
317 for test_group in config.get('tests', []):
koder aka kdanilov4d4771c2015-04-23 01:32:02 +0300318 test_res = run_tests(test_group, ctx.nodes,
319 cfg['run_uuid'])
320 ctx.results.extend(test_res)
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300321 else:
koder aka kdanilove87ae652015-04-20 02:14:35 +0300322 if not cfg['no_tests']:
koder aka kdanilov4d4771c2015-04-23 01:32:02 +0300323 test_res = run_tests(group, ctx.nodes, cfg['run_uuid'])
324 ctx.results.extend(test_res)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300325
gstepanov023c1e42015-04-08 15:50:19 +0300326
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300327def shut_down_vms_stage(cfg, ctx):
koder aka kdanilov66839a92015-04-11 13:22:31 +0300328 vm_ids_fname = cfg_dict['vm_ids_fname']
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300329 if ctx.openstack_nodes_ids is None:
koder aka kdanilov66839a92015-04-11 13:22:31 +0300330 nodes_ids = open(vm_ids_fname).read().split()
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300331 else:
332 nodes_ids = ctx.openstack_nodes_ids
333
koder aka kdanilov652cd802015-04-13 12:21:07 +0300334 if len(nodes_ids) != 0:
335 logger.info("Removing nodes")
336 start_vms.clear_nodes(nodes_ids)
337 logger.info("Nodes has been removed")
gstepanov023c1e42015-04-08 15:50:19 +0300338
koder aka kdanilov66839a92015-04-11 13:22:31 +0300339 if os.path.exists(vm_ids_fname):
340 os.remove(vm_ids_fname)
gstepanov023c1e42015-04-08 15:50:19 +0300341
koder aka kdanilov66839a92015-04-11 13:22:31 +0300342
343def store_nodes_in_log(cfg, nodes_ids):
344 with open(cfg['vm_ids_fname'], 'w') as fd:
345 fd.write("\n".join(nodes_ids))
gstepanov023c1e42015-04-08 15:50:19 +0300346
347
348def clear_enviroment(cfg, ctx):
koder aka kdanilov66839a92015-04-11 13:22:31 +0300349 if os.path.exists(cfg_dict['vm_ids_fname']):
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300350 shut_down_vms_stage(cfg, ctx)
gstepanov023c1e42015-04-08 15:50:19 +0300351
352
koder aka kdanilovda45e882015-04-06 02:24:42 +0300353def disconnect_stage(cfg, ctx):
koder aka kdanilov652cd802015-04-13 12:21:07 +0300354 ssh_utils.close_all_sessions()
355
koder aka kdanilovda45e882015-04-06 02:24:42 +0300356 for node in ctx.nodes:
357 if node.connection is not None:
358 node.connection.close()
359
360
koder aka kdanilov66839a92015-04-11 13:22:31 +0300361def store_raw_results_stage(cfg, ctx):
362
363 raw_results = os.path.join(cfg_dict['var_dir'], 'raw_results.yaml')
364
365 if os.path.exists(raw_results):
366 cont = yaml.load(open(raw_results).read())
367 else:
368 cont = []
369
koder aka kdanilov168f6092015-04-19 02:33:38 +0300370 cont.extend(utils.yamable(ctx.results))
koder aka kdanilov66839a92015-04-11 13:22:31 +0300371 raw_data = pretty_yaml.dumps(cont)
372
373 with open(raw_results, "w") as fd:
374 fd.write(raw_data)
375
376
377def console_report_stage(cfg, ctx):
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 kdanilove87ae652015-04-20 02:14:35 +0300380 print("\n")
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300381 print(IOPerfTest.format_for_console(data))
koder aka kdanilove87ae652015-04-20 02:14:35 +0300382 print("\n")
koder aka kdanilov66839a92015-04-11 13:22:31 +0300383
384
koder aka kdanilove87ae652015-04-20 02:14:35 +0300385def html_report_stage(cfg, ctx):
Yulia Portnova8ca20572015-04-14 14:09:39 +0300386 html_rep_fname = cfg['html_report_file']
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300387
388 try:
389 fuel_url = cfg['clouds']['fuel']['url']
390 except KeyError:
391 fuel_url = None
392
393 try:
394 creds = cfg['clouds']['fuel']['creds']
395 except KeyError:
396 creds = None
397
gstepanov69339ac2015-04-16 20:09:33 +0300398 report.make_io_report(ctx.results, html_rep_fname, fuel_url, creds=creds)
koder aka kdanilov652cd802015-04-13 12:21:07 +0300399
koder aka kdanilov652cd802015-04-13 12:21:07 +0300400 text_rep_fname = cfg_dict['text_report_file']
401 with open(text_rep_fname, "w") as fd:
402 for tp, data in ctx.results:
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300403 if 'io' == tp and data is not None:
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300404 fd.write(IOPerfTest.format_for_console(data))
koder aka kdanilov652cd802015-04-13 12:21:07 +0300405 fd.write("\n")
406 fd.flush()
407
408 logger.info("Text report were stored in " + text_rep_fname)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300409
410
411def complete_log_nodes_statistic(cfg, ctx):
412 nodes = ctx.nodes
413 for node in nodes:
414 logger.debug(str(node))
415
416
koder aka kdanilov66839a92015-04-11 13:22:31 +0300417def load_data_from(var_dir):
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +0300418 def load_data_from_file(cfg, ctx):
koder aka kdanilov66839a92015-04-11 13:22:31 +0300419 raw_results = os.path.join(var_dir, 'raw_results.yaml')
420 ctx.results = yaml.load(open(raw_results).read())
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +0300421 return load_data_from_file
gstepanovcd256d62015-04-07 17:47:32 +0300422
423
koder aka kdanilovcee43342015-04-14 22:52:53 +0300424def parse_args(argv):
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300425 descr = "Disk io performance test suite"
426 parser = argparse.ArgumentParser(prog='wally', description=descr)
koder aka kdanilovcee43342015-04-14 22:52:53 +0300427
428 parser.add_argument("-l", dest='extra_logs',
429 action='store_true', default=False,
430 help="print some extra log info")
koder aka kdanilovcee43342015-04-14 22:52:53 +0300431 parser.add_argument("-b", '--build_description',
432 type=str, default="Build info")
433 parser.add_argument("-i", '--build_id', type=str, default="id")
434 parser.add_argument("-t", '--build_type', type=str, default="GA")
435 parser.add_argument("-u", '--username', type=str, default="admin")
koder aka kdanilove87ae652015-04-20 02:14:35 +0300436 parser.add_argument("-n", '--no-tests', action='store_true',
437 help="Don't run tests", default=False)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300438 parser.add_argument("-p", '--post-process-only', metavar="VAR_DIR",
439 help="Only process data from previour run")
440 parser.add_argument("-k", '--keep-vm', action='store_true',
441 help="Don't remove test vm's", default=False)
koder aka kdanilove87ae652015-04-20 02:14:35 +0300442 parser.add_argument("-d", '--dont-discover-nodes', action='store_true',
443 help="Don't connect/discover fuel nodes",
444 default=False)
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300445 parser.add_argument("-r", '--no-html-report', action='store_true',
446 help="Skip html report", default=False)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300447 parser.add_argument("config_file")
koder aka kdanilovcee43342015-04-14 22:52:53 +0300448
449 return parser.parse_args(argv[1:])
450
451
koder aka kdanilov3f356262015-02-13 08:06:14 -0800452def main(argv):
koder aka kdanilove06762a2015-03-22 23:32:09 +0200453 opts = parse_args(argv)
koder aka kdanilov2c473092015-03-29 17:12:13 +0300454
koder aka kdanilov66839a92015-04-11 13:22:31 +0300455 if opts.post_process_only is not None:
456 stages = [
koder aka kdanilove87ae652015-04-20 02:14:35 +0300457 load_data_from(opts.post_process_only)
koder aka kdanilov66839a92015-04-11 13:22:31 +0300458 ]
459 else:
460 stages = [
461 discover_stage,
462 log_nodes_statistic,
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300463 connect_stage,
koder aka kdanilov66839a92015-04-11 13:22:31 +0300464 deploy_sensors_stage,
465 run_tests_stage,
koder aka kdanilove87ae652015-04-20 02:14:35 +0300466 store_raw_results_stage
koder aka kdanilov66839a92015-04-11 13:22:31 +0300467 ]
468
koder aka kdanilove87ae652015-04-20 02:14:35 +0300469 report_stages = [
470 console_report_stage,
koder aka kdanilove87ae652015-04-20 02:14:35 +0300471 ]
472
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300473 if not opts.no_html_report:
474 report_stages.append(html_report_stage)
475
koder aka kdanilovcee43342015-04-14 22:52:53 +0300476 load_config(opts.config_file, opts.post_process_only)
koder aka kdanilovf4b82c22015-04-11 13:35:25 +0300477
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300478 if cfg_dict.get('logging', {}).get("extra_logs", False) or opts.extra_logs:
479 level = logging.DEBUG
480 else:
481 level = logging.WARNING
482
483 setup_loggers(level, cfg_dict['log_file'])
koder aka kdanilovf4b82c22015-04-11 13:35:25 +0300484
koder aka kdanilov652cd802015-04-13 12:21:07 +0300485 logger.info("All info would be stored into {0}".format(
486 cfg_dict['var_dir']))
gstepanovcd256d62015-04-07 17:47:32 +0300487
koder aka kdanilovda45e882015-04-06 02:24:42 +0300488 ctx = Context()
gstepanovaffcdb12015-04-07 17:18:29 +0300489 ctx.build_meta['build_id'] = opts.build_id
490 ctx.build_meta['build_descrption'] = opts.build_description
491 ctx.build_meta['build_type'] = opts.build_type
492 ctx.build_meta['username'] = opts.username
koder aka kdanilove87ae652015-04-20 02:14:35 +0300493
koder aka kdanilov168f6092015-04-19 02:33:38 +0300494 cfg_dict['keep_vm'] = opts.keep_vm
koder aka kdanilove87ae652015-04-20 02:14:35 +0300495 cfg_dict['no_tests'] = opts.no_tests
496 cfg_dict['dont_discover_nodes'] = opts.dont_discover_nodes
koder aka kdanilov6c491062015-04-09 22:33:13 +0300497
koder aka kdanilovda45e882015-04-06 02:24:42 +0300498 try:
499 for stage in stages:
500 logger.info("Start {0.__name__} stage".format(stage))
501 stage(cfg_dict, ctx)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300502 except Exception as exc:
koder aka kdanilove87ae652015-04-20 02:14:35 +0300503 emsg = exc.message
504 if emsg == "":
505 emsg = str(exc)
506 msg = "Exception during {0.__name__}: {1}".format(stage, emsg)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300507 logger.error(msg)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300508 finally:
509 exc, cls, tb = sys.exc_info()
510 for stage in ctx.clear_calls_stack[::-1]:
511 try:
512 logger.info("Start {0.__name__} stage".format(stage))
513 stage(cfg_dict, ctx)
koder aka kdanilov1c2b5112015-04-10 16:53:51 +0300514 except Exception as exc:
515 logger.exception("During {0.__name__} stage".format(stage))
koder aka kdanilov2c473092015-03-29 17:12:13 +0300516
koder aka kdanilovda45e882015-04-06 02:24:42 +0300517 if exc is not None:
518 raise exc, cls, tb
koder aka kdanilov2c473092015-03-29 17:12:13 +0300519
koder aka kdanilove87ae652015-04-20 02:14:35 +0300520 for report_stage in report_stages:
521 report_stage(cfg_dict, ctx)
522
523 logger.info("All info stored in {0} folder".format(cfg_dict['var_dir']))
koder aka kdanilove06762a2015-03-22 23:32:09 +0200524 return 0