blob: 25da0abfa5d0f56d80ab2658727a25708785c5f5 [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
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -08009
koder aka kdanilove06762a2015-03-22 23:32:09 +020010import ssh_utils
koder aka kdanilov4ec0f712015-02-19 19:19:27 -080011import io_scenario
koder aka kdanilove06762a2015-03-22 23:32:09 +020012from nodes import discover
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 Portnova7ddfa732015-02-24 17:32:58 +020016from formatters import get_formatter
koder aka kdanilove06762a2015-03-22 23:32:09 +020017from itest import IOPerfTest, PgBenchTest
Yulia Portnova7ddfa732015-02-24 17:32:58 +020018
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
koder aka kdanilov3a6633e2015-03-26 18:20:00 +020057def conn_func(obj, barrier, latest_start_time, conn):
58 try:
59 test_iter = itest.run_test_iter(obj, conn)
60 next(test_iter)
61
62 wait_on_barrier(barrier, latest_start_time)
63
64 with log_error("!Run test"):
65 return next(test_iter)
66 except:
67 print traceback.format_exc()
68 raise
69
70
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080071def parse_args(argv):
72 parser = argparse.ArgumentParser(
73 description="Run disk io performance test")
74
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080075 parser.add_argument("-l", dest='extra_logs',
76 action='store_true', default=False,
77 help="print some extra log info")
78
koder aka kdanilove06762a2015-03-22 23:32:09 +020079 parser.add_argument('stages', nargs="+",
80 choices=["discover", "connect", "start_new_nodes",
81 "deploy_sensors"])
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080082
koder aka kdanilove06762a2015-03-22 23:32:09 +020083 # THIS ALL MOVE TO CONFIG FILE
84 # parser.add_argument("-o", "--test-opts", dest='opts',
85 # help="cmd line options for test")
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080086
koder aka kdanilove06762a2015-03-22 23:32:09 +020087 # parser.add_argument("-f", "--test-opts-file", dest='opts_file',
88 # type=argparse.FileType('r'), default=None,
89 # help="file with cmd line options for test")
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080090
koder aka kdanilove06762a2015-03-22 23:32:09 +020091 # parser.add_argument("--max-preparation-time", default=300,
92 # type=int, dest="max_preparation_time")
gstepanov8053b012015-02-16 17:25:27 +020093
koder aka kdanilove06762a2015-03-22 23:32:09 +020094 # parser.add_argument("-b", "--build-info", default=None,
95 # dest="build_name")
gstepanov8053b012015-02-16 17:25:27 +020096
koder aka kdanilove06762a2015-03-22 23:32:09 +020097 # parser.add_argument("-d", "--data-server-url", default=None,
98 # dest="data_server_url")
gstepanov8053b012015-02-16 17:25:27 +020099
koder aka kdanilove06762a2015-03-22 23:32:09 +0200100 # parser.add_argument("-n", "--lab-name", default=None,
101 # dest="lab_name")
koder aka kdanilov4ec0f712015-02-19 19:19:27 -0800102
koder aka kdanilove06762a2015-03-22 23:32:09 +0200103 # parser.add_argument("--create-vms-opts", default=None,
104 # help="Creating vm's before run ssh runner",
105 # dest="create_vms_opts")
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -0800106
koder aka kdanilove06762a2015-03-22 23:32:09 +0200107 # parser.add_argument("-k", "--keep", default=False,
108 # help="keep temporary files",
109 # dest="keep_temp_files", action='store_true')
koder aka kdanilov4ec0f712015-02-19 19:19:27 -0800110
koder aka kdanilove06762a2015-03-22 23:32:09 +0200111 # parser.add_argument("--runner", required=True,
112 # choices=["local", "ssh"], help="runner type")
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -0800113
koder aka kdanilove06762a2015-03-22 23:32:09 +0200114 # parser.add_argument("--runner-extra-opts", default=None,
115 # dest="runner_opts", help="runner extra options")
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -0800116
koder aka kdanilove06762a2015-03-22 23:32:09 +0200117 return parser.parse_args(argv[1:])
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -0800118
119
Yulia Portnova7ddfa732015-02-24 17:32:58 +0200120def format_result(res, formatter):
koder aka kdanilove21d7472015-02-14 19:02:04 -0800121 data = "\n{0}\n".format("=" * 80)
122 data += pprint.pformat(res) + "\n"
123 data += "{0}\n".format("=" * 80)
koder aka kdanilovfe056622015-02-19 08:46:15 -0800124 templ = "{0}\n\n====> {1}\n\n{2}\n\n"
Yulia Portnova7ddfa732015-02-24 17:32:58 +0200125 return templ.format(data, formatter(res), "=" * 80)
koder aka kdanilove21d7472015-02-14 19:02:04 -0800126
127
koder aka kdanilov5d589b42015-03-26 12:25:51 +0200128def connect_one(node):
129 try:
130 node.connection = ssh_utils.connect(node.connection_url)
koder aka kdanilov3a6633e2015-03-26 18:20:00 +0200131 except Exception:
132 logger.exception()
koder aka kdanilov5d589b42015-03-26 12:25:51 +0200133
134
135def connect_all(nodes):
136 pass
137
138
koder aka kdanilov3f356262015-02-13 08:06:14 -0800139def main(argv):
Yulia Portnova0e64ea22015-03-20 17:27:22 +0200140 logging_conf = cfg_dict.get('logging')
141 if logging_conf:
142 if logging_conf.get('extra_logs'):
143 logger.setLevel(logging.DEBUG)
144 ch.setLevel(logging.DEBUG)
koder aka kdanilov3f356262015-02-13 08:06:14 -0800145
koder aka kdanilove06762a2015-03-22 23:32:09 +0200146 opts = parse_args(argv)
147 if 'discover' in opts.stages:
koder aka kdanilov3a6633e2015-03-26 18:20:00 +0200148 current_data = discover.discover(cfg_dict.get('discover'))
koder aka kdanilove06762a2015-03-22 23:32:09 +0200149
150 if 'connect' in opts.stages:
151 for node in current_data:
koder aka kdanilov3a6633e2015-03-26 18:20:00 +0200152 pass
koder aka kdanilove06762a2015-03-22 23:32:09 +0200153
154 print "\n".join(map(str, current_data))
155 return 0
koder aka kdanilov3f356262015-02-13 08:06:14 -0800156
koder aka kdanilov5d589b42015-03-26 12:25:51 +0200157 # tests = cfg_dict.get("tests", [])
koder aka kdanilov3f356262015-02-13 08:06:14 -0800158
Yulia Portnova0e64ea22015-03-20 17:27:22 +0200159 # Deploy and start sensors
koder aka kdanilove06762a2015-03-22 23:32:09 +0200160 # deploy_and_start_sensors(cfg_dict.get('sensors'), nodes_to_run)
koder aka kdanilov4ec0f712015-02-19 19:19:27 -0800161
koder aka kdanilov5d589b42015-03-26 12:25:51 +0200162 # for test_name, opts in tests.items():
163 # cmd_line = " ".join(opts['opts'])
164 # logger.debug("Run test with {0!r} params".format(cmd_line))
165 # latest_start_time = 300 + time.time()
166 # uris = [node.connection_url for node in nodes_to_run]
koder aka kdanilov3a6633e2015-03-26 18:20:00 +0200167 # runner = ssh_runner.get_ssh_runner(uris, conn_func,
koder aka kdanilov5d589b42015-03-26 12:25:51 +0200168 # latest_start_time,
169 # opts.get('keep_temp_files'))
170 # res = run_io_test(test_name,
171 # opts['opts'],
172 # runner,
173 # opts.get('keep_temp_files'))
174 # logger.debug(format_result(res, get_formatter(test_name)))
koder aka kdanilov3f356262015-02-13 08:06:14 -0800175
koder aka kdanilove06762a2015-03-22 23:32:09 +0200176 # if cfg_dict.get('data_server_url'):
177 # result = json.loads(get_formatter(opts.tool_type)(res))
178 # result['name'] = opts.build_name
179 # add_test(opts.build_name, result, opts.data_server_url)
koder aka kdanilov4ec0f712015-02-19 19:19:27 -0800180
koder aka kdanilov5d589b42015-03-26 12:25:51 +0200181 # return 0
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -0800182
183
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -0800184if __name__ == '__main__':
koder aka kdanilove06762a2015-03-22 23:32:09 +0200185 exit(main(sys.argv))