blob: cafbc59d44eea6e4df2cdafe3783263a3091d76c [file] [log] [blame]
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -08001import os
2import sys
3import json
4import time
5import pprint
koder aka kdanilove21d7472015-02-14 19:02:04 -08006import logging
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -08007import os.path
8import argparse
Yulia Portnova0e64ea22015-03-20 17:27:22 +02009from nodes import discover
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080010
11import ssh_runner
koder aka kdanilov4ec0f712015-02-19 19:19:27 -080012import io_scenario
Yulia Portnova0e64ea22015-03-20 17:27:22 +020013from config import cfg_dict
koder aka kdanilov4ec0f712015-02-19 19:19:27 -080014from utils import log_error
15from rest_api import add_test
Yulia Portnova0e64ea22015-03-20 17:27:22 +020016from itest import IOPerfTest,PgBenchTest
Yulia Portnova7ddfa732015-02-24 17:32:58 +020017from formatters import get_formatter
18
koder aka kdanilove21d7472015-02-14 19:02:04 -080019logger = logging.getLogger("io-perf-tool")
yportnovaa47b33e2015-03-05 20:20:31 +020020logger.setLevel(logging.DEBUG)
koder aka kdanilove21d7472015-02-14 19:02:04 -080021ch = logging.StreamHandler()
yportnovaa47b33e2015-03-05 20:20:31 +020022ch.setLevel(logging.DEBUG)
koder aka kdanilove21d7472015-02-14 19:02:04 -080023logger.addHandler(ch)
24
25log_format = '%(asctime)s - %(levelname)s - %(name)s - %(message)s'
26formatter = logging.Formatter(log_format,
27 "%H:%M:%S")
28ch.setFormatter(formatter)
29
30
Yulia Portnova7ddfa732015-02-24 17:32:58 +020031tool_type_mapper = {
32 "iozone": IOPerfTest,
33 "fio": IOPerfTest,
34 "pgbench": PgBenchTest,
35}
36
37
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080038def run_io_test(tool,
39 script_args,
40 test_runner,
41 keep_temp_files=False):
42
43 files_dir = os.path.dirname(io_scenario.__file__)
44
45 path = 'iozone' if 'iozone' == tool else 'fio'
46 src_testtool_path = os.path.join(files_dir, path)
47
Yulia Portnova7ddfa732015-02-24 17:32:58 +020048 obj_cls = tool_type_mapper[tool]
49 obj = obj_cls(script_args,
50 src_testtool_path,
51 None,
52 keep_temp_files)
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080053
54 return test_runner(obj)
55
56
57def parse_args(argv):
58 parser = argparse.ArgumentParser(
59 description="Run disk io performance test")
60
61 parser.add_argument("tool_type", help="test tool type",
yportnovaa47b33e2015-03-05 20:20:31 +020062 choices=['iozone', 'fio', 'pgbench', 'two_scripts'])
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080063
64 parser.add_argument("-l", dest='extra_logs',
65 action='store_true', default=False,
66 help="print some extra log info")
67
Yulia Portnova7ddfa732015-02-24 17:32:58 +020068 parser.add_argument("-o", "--test-opts", dest='opts',
69 help="cmd line options for test")
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080070
Yulia Portnova7ddfa732015-02-24 17:32:58 +020071 parser.add_argument("-f", "--test-opts-file", dest='opts_file',
koder aka kdanilov3f356262015-02-13 08:06:14 -080072 type=argparse.FileType('r'), default=None,
Yulia Portnova7ddfa732015-02-24 17:32:58 +020073 help="file with cmd line options for test")
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080074
75 parser.add_argument("--max-preparation-time", default=300,
76 type=int, dest="max_preparation_time")
77
gstepanov8053b012015-02-16 17:25:27 +020078 parser.add_argument("-b", "--build-info", default=None,
79 dest="build_name")
80
81 parser.add_argument("-d", "--data-server-url", default=None,
82 dest="data_server_url")
83
84 parser.add_argument("-n", "--lab-name", default=None,
85 dest="lab_name")
86
koder aka kdanilov4ec0f712015-02-19 19:19:27 -080087 parser.add_argument("--create-vms-opts", default=None,
88 help="Creating vm's before run ssh runner",
89 dest="create_vms_opts")
90
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080091 parser.add_argument("-k", "--keep", default=False,
92 help="keep temporary files",
93 dest="keep_temp_files", action='store_true')
94
koder aka kdanilov4ec0f712015-02-19 19:19:27 -080095 choices = ["local", "ssh"]
96
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080097 parser.add_argument("--runner", required=True,
koder aka kdanilov7dec9df2015-02-15 21:35:19 -080098 choices=choices, help="runner type")
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080099
koder aka kdanilov4ec0f712015-02-19 19:19:27 -0800100 parser.add_argument("--runner-extra-opts", default=None,
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -0800101 dest="runner_opts", help="runner extra options")
102
103 return parser.parse_args(argv)
104
105
Yulia Portnova7ddfa732015-02-24 17:32:58 +0200106def format_result(res, formatter):
koder aka kdanilove21d7472015-02-14 19:02:04 -0800107 data = "\n{0}\n".format("=" * 80)
108 data += pprint.pformat(res) + "\n"
109 data += "{0}\n".format("=" * 80)
koder aka kdanilovfe056622015-02-19 08:46:15 -0800110 templ = "{0}\n\n====> {1}\n\n{2}\n\n"
Yulia Portnova7ddfa732015-02-24 17:32:58 +0200111 return templ.format(data, formatter(res), "=" * 80)
koder aka kdanilove21d7472015-02-14 19:02:04 -0800112
113
Yulia Portnova0e64ea22015-03-20 17:27:22 +0200114def deploy_and_start_sensors(sensors_conf, nodes):
115 pass
koder aka kdanilov4ec0f712015-02-19 19:19:27 -0800116
117
koder aka kdanilov3f356262015-02-13 08:06:14 -0800118def main(argv):
Yulia Portnova0e64ea22015-03-20 17:27:22 +0200119 logging_conf = cfg_dict.get('logging')
120 if logging_conf:
121 if logging_conf.get('extra_logs'):
122 logger.setLevel(logging.DEBUG)
123 ch.setLevel(logging.DEBUG)
koder aka kdanilov3f356262015-02-13 08:06:14 -0800124
Yulia Portnova0e64ea22015-03-20 17:27:22 +0200125 # Discover nodes
126 nodes_to_run = discover.discover(cfg_dict.get('cluster'))
koder aka kdanilov3f356262015-02-13 08:06:14 -0800127
Yulia Portnova0e64ea22015-03-20 17:27:22 +0200128 tests = cfg_dict.get("tests", [])
koder aka kdanilov3f356262015-02-13 08:06:14 -0800129
Yulia Portnova0e64ea22015-03-20 17:27:22 +0200130 # Deploy and start sensors
131 deploy_and_start_sensors(cfg_dict.get('sensors'), nodes_to_run)
koder aka kdanilov4ec0f712015-02-19 19:19:27 -0800132
Yulia Portnova0e64ea22015-03-20 17:27:22 +0200133 for test_name, opts in tests.items():
134 cmd_line = " ".join(opts['opts'])
135 logger.debug("Run test with {0!r} params".format(cmd_line))
136 latest_start_time = 300 + time.time()
137 uris = [node.connection_url for node in nodes_to_run]
138 runner = ssh_runner.get_ssh_runner(uris,
139 latest_start_time,
140 opts.get('keep_temp_files'))
141 res = run_io_test(test_name,
142 opts['opts'],
143 runner,
144 opts.get('keep_temp_files'))
145 logger.debug(format_result(res, get_formatter(test_name)))
koder aka kdanilov3f356262015-02-13 08:06:14 -0800146
Yulia Portnova0e64ea22015-03-20 17:27:22 +0200147 if cfg_dict.get('data_server_url'):
Yulia Portnova7ddfa732015-02-24 17:32:58 +0200148 result = json.loads(get_formatter(opts.tool_type)(res))
koder aka kdanilov4ec0f712015-02-19 19:19:27 -0800149 result['name'] = opts.build_name
150 add_test(opts.build_name, result, opts.data_server_url)
151
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -0800152 return 0
153
154
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -0800155if __name__ == '__main__':
156 exit(main(sys.argv[1:]))