koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 1 | import os |
| 2 | import sys |
| 3 | import json |
| 4 | import time |
| 5 | import pprint |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 6 | import logging |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 7 | import os.path |
| 8 | import argparse |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 9 | from nodes import discover |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 10 | |
| 11 | import ssh_runner |
koder aka kdanilov | 4ec0f71 | 2015-02-19 19:19:27 -0800 | [diff] [blame] | 12 | import io_scenario |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 13 | from config import cfg_dict |
koder aka kdanilov | 4ec0f71 | 2015-02-19 19:19:27 -0800 | [diff] [blame] | 14 | from utils import log_error |
| 15 | from rest_api import add_test |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 16 | from itest import IOPerfTest,PgBenchTest |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 17 | from formatters import get_formatter |
| 18 | |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 19 | logger = logging.getLogger("io-perf-tool") |
yportnova | a47b33e | 2015-03-05 20:20:31 +0200 | [diff] [blame] | 20 | logger.setLevel(logging.DEBUG) |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 21 | ch = logging.StreamHandler() |
yportnova | a47b33e | 2015-03-05 20:20:31 +0200 | [diff] [blame] | 22 | ch.setLevel(logging.DEBUG) |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 23 | logger.addHandler(ch) |
| 24 | |
| 25 | log_format = '%(asctime)s - %(levelname)s - %(name)s - %(message)s' |
| 26 | formatter = logging.Formatter(log_format, |
| 27 | "%H:%M:%S") |
| 28 | ch.setFormatter(formatter) |
| 29 | |
| 30 | |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 31 | tool_type_mapper = { |
| 32 | "iozone": IOPerfTest, |
| 33 | "fio": IOPerfTest, |
| 34 | "pgbench": PgBenchTest, |
| 35 | } |
| 36 | |
| 37 | |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 38 | def 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 Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 48 | obj_cls = tool_type_mapper[tool] |
| 49 | obj = obj_cls(script_args, |
| 50 | src_testtool_path, |
| 51 | None, |
| 52 | keep_temp_files) |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 53 | |
| 54 | return test_runner(obj) |
| 55 | |
| 56 | |
| 57 | def 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", |
yportnova | a47b33e | 2015-03-05 20:20:31 +0200 | [diff] [blame] | 62 | choices=['iozone', 'fio', 'pgbench', 'two_scripts']) |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 63 | |
| 64 | parser.add_argument("-l", dest='extra_logs', |
| 65 | action='store_true', default=False, |
| 66 | help="print some extra log info") |
| 67 | |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 68 | parser.add_argument("-o", "--test-opts", dest='opts', |
| 69 | help="cmd line options for test") |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 70 | |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 71 | parser.add_argument("-f", "--test-opts-file", dest='opts_file', |
koder aka kdanilov | 3f35626 | 2015-02-13 08:06:14 -0800 | [diff] [blame] | 72 | type=argparse.FileType('r'), default=None, |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 73 | help="file with cmd line options for test") |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 74 | |
| 75 | parser.add_argument("--max-preparation-time", default=300, |
| 76 | type=int, dest="max_preparation_time") |
| 77 | |
gstepanov | 8053b01 | 2015-02-16 17:25:27 +0200 | [diff] [blame] | 78 | 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 kdanilov | 4ec0f71 | 2015-02-19 19:19:27 -0800 | [diff] [blame] | 87 | 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 kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 91 | parser.add_argument("-k", "--keep", default=False, |
| 92 | help="keep temporary files", |
| 93 | dest="keep_temp_files", action='store_true') |
| 94 | |
koder aka kdanilov | 4ec0f71 | 2015-02-19 19:19:27 -0800 | [diff] [blame] | 95 | choices = ["local", "ssh"] |
| 96 | |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 97 | parser.add_argument("--runner", required=True, |
koder aka kdanilov | 7dec9df | 2015-02-15 21:35:19 -0800 | [diff] [blame] | 98 | choices=choices, help="runner type") |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 99 | |
koder aka kdanilov | 4ec0f71 | 2015-02-19 19:19:27 -0800 | [diff] [blame] | 100 | parser.add_argument("--runner-extra-opts", default=None, |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 101 | dest="runner_opts", help="runner extra options") |
| 102 | |
| 103 | return parser.parse_args(argv) |
| 104 | |
| 105 | |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 106 | def format_result(res, formatter): |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 107 | data = "\n{0}\n".format("=" * 80) |
| 108 | data += pprint.pformat(res) + "\n" |
| 109 | data += "{0}\n".format("=" * 80) |
koder aka kdanilov | fe05662 | 2015-02-19 08:46:15 -0800 | [diff] [blame] | 110 | templ = "{0}\n\n====> {1}\n\n{2}\n\n" |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 111 | return templ.format(data, formatter(res), "=" * 80) |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 112 | |
| 113 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 114 | def deploy_and_start_sensors(sensors_conf, nodes): |
| 115 | pass |
koder aka kdanilov | 4ec0f71 | 2015-02-19 19:19:27 -0800 | [diff] [blame] | 116 | |
| 117 | |
koder aka kdanilov | 3f35626 | 2015-02-13 08:06:14 -0800 | [diff] [blame] | 118 | def main(argv): |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 119 | 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 kdanilov | 3f35626 | 2015-02-13 08:06:14 -0800 | [diff] [blame] | 124 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 125 | # Discover nodes |
| 126 | nodes_to_run = discover.discover(cfg_dict.get('cluster')) |
koder aka kdanilov | 3f35626 | 2015-02-13 08:06:14 -0800 | [diff] [blame] | 127 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 128 | tests = cfg_dict.get("tests", []) |
koder aka kdanilov | 3f35626 | 2015-02-13 08:06:14 -0800 | [diff] [blame] | 129 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 130 | # Deploy and start sensors |
| 131 | deploy_and_start_sensors(cfg_dict.get('sensors'), nodes_to_run) |
koder aka kdanilov | 4ec0f71 | 2015-02-19 19:19:27 -0800 | [diff] [blame] | 132 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 133 | 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 kdanilov | 3f35626 | 2015-02-13 08:06:14 -0800 | [diff] [blame] | 146 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 147 | if cfg_dict.get('data_server_url'): |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 148 | result = json.loads(get_formatter(opts.tool_type)(res)) |
koder aka kdanilov | 4ec0f71 | 2015-02-19 19:19:27 -0800 | [diff] [blame] | 149 | result['name'] = opts.build_name |
| 150 | add_test(opts.build_name, result, opts.data_server_url) |
| 151 | |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 152 | return 0 |
| 153 | |
| 154 | |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 155 | if __name__ == '__main__': |
| 156 | exit(main(sys.argv[1:])) |