blob: ec77a413d3e42486d3a8b85672cabdcdf31f2896 [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
57def parse_args(argv):
58 parser = argparse.ArgumentParser(
59 description="Run disk io performance test")
60
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080061 parser.add_argument("-l", dest='extra_logs',
62 action='store_true', default=False,
63 help="print some extra log info")
64
koder aka kdanilove06762a2015-03-22 23:32:09 +020065 parser.add_argument('stages', nargs="+",
66 choices=["discover", "connect", "start_new_nodes",
67 "deploy_sensors"])
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080068
koder aka kdanilove06762a2015-03-22 23:32:09 +020069 # THIS ALL MOVE TO CONFIG FILE
70 # parser.add_argument("-o", "--test-opts", dest='opts',
71 # help="cmd line options for test")
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080072
koder aka kdanilove06762a2015-03-22 23:32:09 +020073 # parser.add_argument("-f", "--test-opts-file", dest='opts_file',
74 # type=argparse.FileType('r'), default=None,
75 # help="file with cmd line options for test")
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080076
koder aka kdanilove06762a2015-03-22 23:32:09 +020077 # parser.add_argument("--max-preparation-time", default=300,
78 # type=int, dest="max_preparation_time")
gstepanov8053b012015-02-16 17:25:27 +020079
koder aka kdanilove06762a2015-03-22 23:32:09 +020080 # parser.add_argument("-b", "--build-info", default=None,
81 # dest="build_name")
gstepanov8053b012015-02-16 17:25:27 +020082
koder aka kdanilove06762a2015-03-22 23:32:09 +020083 # parser.add_argument("-d", "--data-server-url", default=None,
84 # dest="data_server_url")
gstepanov8053b012015-02-16 17:25:27 +020085
koder aka kdanilove06762a2015-03-22 23:32:09 +020086 # parser.add_argument("-n", "--lab-name", default=None,
87 # dest="lab_name")
koder aka kdanilov4ec0f712015-02-19 19:19:27 -080088
koder aka kdanilove06762a2015-03-22 23:32:09 +020089 # parser.add_argument("--create-vms-opts", default=None,
90 # help="Creating vm's before run ssh runner",
91 # dest="create_vms_opts")
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080092
koder aka kdanilove06762a2015-03-22 23:32:09 +020093 # parser.add_argument("-k", "--keep", default=False,
94 # help="keep temporary files",
95 # dest="keep_temp_files", action='store_true')
koder aka kdanilov4ec0f712015-02-19 19:19:27 -080096
koder aka kdanilove06762a2015-03-22 23:32:09 +020097 # parser.add_argument("--runner", required=True,
98 # choices=["local", "ssh"], help="runner type")
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080099
koder aka kdanilove06762a2015-03-22 23:32:09 +0200100 # parser.add_argument("--runner-extra-opts", default=None,
101 # dest="runner_opts", help="runner extra options")
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -0800102
koder aka kdanilove06762a2015-03-22 23:32:09 +0200103 return parser.parse_args(argv[1:])
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -0800104
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
koder aka kdanilov3f356262015-02-13 08:06:14 -0800114def main(argv):
Yulia Portnova0e64ea22015-03-20 17:27:22 +0200115 logging_conf = cfg_dict.get('logging')
116 if logging_conf:
117 if logging_conf.get('extra_logs'):
118 logger.setLevel(logging.DEBUG)
119 ch.setLevel(logging.DEBUG)
koder aka kdanilov3f356262015-02-13 08:06:14 -0800120
koder aka kdanilove06762a2015-03-22 23:32:09 +0200121 opts = parse_args(argv)
122 if 'discover' in opts.stages:
123 current_data = discover.discover(cfg_dict.get('cluster'))
124
125 if 'connect' in opts.stages:
126 for node in current_data:
127 node.connection = ssh_utils.connect(node.connection_url)
128
129 print "\n".join(map(str, current_data))
130 return 0
Yulia Portnova0e64ea22015-03-20 17:27:22 +0200131 # Discover nodes
koder aka kdanilov3f356262015-02-13 08:06:14 -0800132
Yulia Portnova0e64ea22015-03-20 17:27:22 +0200133 tests = cfg_dict.get("tests", [])
koder aka kdanilov3f356262015-02-13 08:06:14 -0800134
Yulia Portnova0e64ea22015-03-20 17:27:22 +0200135 # Deploy and start sensors
koder aka kdanilove06762a2015-03-22 23:32:09 +0200136 # deploy_and_start_sensors(cfg_dict.get('sensors'), nodes_to_run)
koder aka kdanilov4ec0f712015-02-19 19:19:27 -0800137
Yulia Portnova0e64ea22015-03-20 17:27:22 +0200138 for test_name, opts in tests.items():
139 cmd_line = " ".join(opts['opts'])
140 logger.debug("Run test with {0!r} params".format(cmd_line))
141 latest_start_time = 300 + time.time()
142 uris = [node.connection_url for node in nodes_to_run]
143 runner = ssh_runner.get_ssh_runner(uris,
144 latest_start_time,
145 opts.get('keep_temp_files'))
146 res = run_io_test(test_name,
147 opts['opts'],
148 runner,
149 opts.get('keep_temp_files'))
150 logger.debug(format_result(res, get_formatter(test_name)))
koder aka kdanilov3f356262015-02-13 08:06:14 -0800151
koder aka kdanilove06762a2015-03-22 23:32:09 +0200152 # if cfg_dict.get('data_server_url'):
153 # result = json.loads(get_formatter(opts.tool_type)(res))
154 # result['name'] = opts.build_name
155 # add_test(opts.build_name, result, opts.data_server_url)
koder aka kdanilov4ec0f712015-02-19 19:19:27 -0800156
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -0800157 return 0
158
159
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -0800160if __name__ == '__main__':
koder aka kdanilove06762a2015-03-22 23:32:09 +0200161 exit(main(sys.argv))