koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 1 | import os |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 2 | import time |
| 3 | import signal |
| 4 | import logging |
| 5 | import argparse |
| 6 | import functools |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 7 | import contextlib |
| 8 | from typing import List, Tuple, Any, Callable, IO, cast, Optional, Iterator |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 9 | from yaml import load as _yaml_load |
| 10 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 11 | |
| 12 | YLoader = Callable[[IO], Any] |
| 13 | yaml_load = None # type: YLoader |
| 14 | |
| 15 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 16 | try: |
| 17 | from yaml import CLoader |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 18 | yaml_load = cast(YLoader, functools.partial(_yaml_load, Loader=CLoader)) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 19 | except ImportError: |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 20 | yaml_load = cast(YLoader, _yaml_load) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 21 | |
| 22 | |
| 23 | import texttable |
| 24 | |
| 25 | try: |
| 26 | import faulthandler |
| 27 | except ImportError: |
| 28 | faulthandler = None |
| 29 | |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 30 | from . import utils, node |
koder aka kdanilov | 3d2bc4f | 2016-11-12 18:31:18 +0200 | [diff] [blame] | 31 | from .storage import make_storage, Storage |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 32 | from .config import Config |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 33 | from .logger import setup_loggers |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 34 | from .stage import Stage |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 35 | from .test_run_class import TestRun |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 36 | from .ssh import set_ssh_key_passwd |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 37 | |
| 38 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 39 | # stages |
| 40 | from .ceph import DiscoverCephStage |
| 41 | from .openstack import DiscoverOSStage |
| 42 | from .fuel import DiscoverFuelStage |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 43 | from .run_test import CollectInfoStage, ExplicitNodesStage, SaveNodesStage, RunTestsStage, ConnectStage, SleepStage |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 44 | from .report import ConsoleReportStage, HtmlReportStage |
| 45 | from .sensors import StartSensorsStage, CollectSensorsStage |
| 46 | |
| 47 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 48 | logger = logging.getLogger("wally") |
| 49 | |
| 50 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 51 | @contextlib.contextmanager |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 52 | def log_stage(stage: Stage, cleanup: bool = False) -> Iterator[None]: |
| 53 | logger.info("Start " + stage.name() + ("::cleanup" if cleanup else "")) |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 54 | try: |
| 55 | yield |
| 56 | except utils.StopTestError as exc: |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 57 | raise |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 58 | except Exception: |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 59 | logger.exception("During %s", stage.name() + ("::cleanup" if cleanup else "")) |
| 60 | raise |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 61 | |
| 62 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 63 | def list_results(path: str) -> List[Tuple[str, str, str, str]]: |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 64 | results = [] # type: List[Tuple[float, str, str, str, str]] |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 65 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 66 | for dir_name in os.listdir(path): |
| 67 | full_path = os.path.join(path, dir_name) |
| 68 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 69 | try: |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 70 | stor = make_storage(full_path, existing=True) |
| 71 | except Exception as exc: |
| 72 | logger.warning("Can't load folder {}. Error {}".format(full_path, exc)) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 73 | |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 74 | comment = cast(str, stor['info/comment']) |
| 75 | run_uuid = cast(str, stor['info/run_uuid']) |
| 76 | run_time = cast(float, stor['info/run_time']) |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 77 | test_types = "" |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 78 | results.append((run_time, |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 79 | run_uuid, |
| 80 | test_types, |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 81 | time.ctime(run_time), |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 82 | '-' if comment is None else comment)) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 83 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 84 | results.sort() |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 85 | return [i[1:] for i in results] |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 86 | |
| 87 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 88 | def log_nodes_statistic_stage(ctx: TestRun) -> None: |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 89 | utils.log_nodes_statistic(ctx.nodes) |
| 90 | |
| 91 | |
| 92 | def parse_args(argv): |
| 93 | descr = "Disk io performance test suite" |
| 94 | parser = argparse.ArgumentParser(prog='wally', description=descr) |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 95 | parser.add_argument("-l", '--log-level', help="print some extra log info") |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 96 | parser.add_argument("--ssh-key-passwd", default=None, help="Pass ssh key password") |
koder aka kdanilov | 3d2bc4f | 2016-11-12 18:31:18 +0200 | [diff] [blame] | 97 | parser.add_argument("-s", '--settings-dir', default=None, |
| 98 | help="Folder to store key/settings/history files") |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 99 | |
| 100 | subparsers = parser.add_subparsers(dest='subparser_name') |
| 101 | |
| 102 | # --------------------------------------------------------------------- |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 103 | report_parser = subparsers.add_parser('ls', help='list all results') |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 104 | report_parser.add_argument("result_storage", help="Folder with test results") |
| 105 | |
| 106 | # --------------------------------------------------------------------- |
| 107 | compare_help = 'compare two results' |
| 108 | report_parser = subparsers.add_parser('compare', help=compare_help) |
| 109 | report_parser.add_argument("data_path1", help="First folder with test results") |
| 110 | report_parser.add_argument("data_path2", help="Second folder with test results") |
| 111 | |
| 112 | # --------------------------------------------------------------------- |
| 113 | report_help = 'run report on previously obtained results' |
| 114 | report_parser = subparsers.add_parser('report', help=report_help) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 115 | report_parser.add_argument("data_dir", help="folder with rest results") |
| 116 | |
| 117 | # --------------------------------------------------------------------- |
| 118 | test_parser = subparsers.add_parser('test', help='run tests') |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 119 | test_parser.add_argument('--build-description', type=str, default="Build info") |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 120 | test_parser.add_argument('--build-id', type=str, default="id") |
| 121 | test_parser.add_argument('--build-type', type=str, default="GA") |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 122 | test_parser.add_argument('--dont-collect', action='store_true', help="Don't collect cluster info") |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 123 | test_parser.add_argument('-n', '--no-tests', action='store_true', help="Don't run tests") |
| 124 | test_parser.add_argument('--load-report', action='store_true') |
| 125 | test_parser.add_argument("-k", '--keep-vm', action='store_true', help="Don't remove test vm's") |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 126 | test_parser.add_argument("-d", '--dont-discover-nodes', action='store_true', |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 127 | help="Don't connect/discover fuel nodes") |
| 128 | test_parser.add_argument('--no-report', action='store_true', help="Skip report stages") |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 129 | test_parser.add_argument('--result-dir', default=None, help="Save results to DIR", metavar="DIR") |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 130 | test_parser.add_argument("comment", help="Test information") |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 131 | test_parser.add_argument("config_file", help="Yaml config file") |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 132 | |
| 133 | # --------------------------------------------------------------------- |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 134 | test_parser = subparsers.add_parser('resume', help='resume tests') |
| 135 | test_parser.add_argument("storage_dir", help="Path to test directory") |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 136 | |
| 137 | return parser.parse_args(argv[1:]) |
| 138 | |
| 139 | |
koder aka kdanilov | 3d2bc4f | 2016-11-12 18:31:18 +0200 | [diff] [blame] | 140 | def get_config_path(config: Config, opts_value: Optional[str]) -> str: |
| 141 | if opts_value is None and 'settings_dir' not in config: |
| 142 | val = "~/.wally" |
| 143 | elif opts_value is not None: |
| 144 | val = opts_value |
| 145 | else: |
| 146 | val = config.settings_dir |
| 147 | |
| 148 | return os.path.abspath(os.path.expanduser(val)) |
| 149 | |
| 150 | |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 151 | def find_cfg_file(name: str, included_from: str = None) -> str: |
| 152 | paths = [".", os.path.expanduser('~/.wally')] |
| 153 | if included_from is not None: |
| 154 | paths.append(os.path.dirname(included_from)) |
| 155 | |
| 156 | search_paths = set(os.path.abspath(path) for path in paths if os.path.isdir(path)) |
| 157 | |
| 158 | for folder in search_paths: |
| 159 | path = os.path.join(folder, name) |
| 160 | if os.path.exists(path): |
| 161 | return path |
| 162 | |
| 163 | raise FileNotFoundError(name) |
| 164 | |
| 165 | |
| 166 | def load_config(path: str) -> Config: |
| 167 | path = os.path.abspath(path) |
| 168 | cfg_dict = yaml_load(open(path).read()) |
| 169 | |
| 170 | while 'include' in cfg_dict: |
| 171 | inc = cfg_dict.pop('include') |
| 172 | if isinstance(inc, str): |
| 173 | inc = [inc] |
| 174 | |
| 175 | for fname in inc: |
| 176 | inc_path = find_cfg_file(fname, path) |
| 177 | inc_dict = yaml_load(open(inc_path).read()) |
| 178 | inc_dict.update(cfg_dict) |
| 179 | cfg_dict = inc_dict |
| 180 | |
| 181 | return Config(cfg_dict) |
| 182 | |
| 183 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 184 | def main(argv: List[str]) -> int: |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 185 | if faulthandler is not None: |
| 186 | faulthandler.register(signal.SIGUSR1, all_threads=True) |
| 187 | |
| 188 | opts = parse_args(argv) |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 189 | stages = [] # type: List[Stage] |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 190 | |
| 191 | # stop mypy from telling that config & storage might be undeclared |
| 192 | config = None # type: Config |
koder aka kdanilov | 3d2bc4f | 2016-11-12 18:31:18 +0200 | [diff] [blame] | 193 | storage = None # type: Storage |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 194 | |
| 195 | if opts.subparser_name == 'test': |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 196 | config = load_config(opts.config_file) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 197 | |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 198 | config.storage_url, config.run_uuid = utils.get_uniq_path_uuid(config.results_dir) |
| 199 | config.comment = opts.comment |
| 200 | config.keep_vm = opts.keep_vm |
| 201 | config.no_tests = opts.no_tests |
| 202 | config.dont_discover_nodes = opts.dont_discover_nodes |
| 203 | config.build_id = opts.build_id |
| 204 | config.build_description = opts.build_description |
| 205 | config.build_type = opts.build_type |
| 206 | config.settings_dir = get_config_path(config, opts.settings_dir) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 207 | |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 208 | storage = make_storage(config.storage_url) |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 209 | |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 210 | storage['config'] = config # type: ignore |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 211 | |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 212 | stages.append(DiscoverCephStage()) |
| 213 | stages.append(DiscoverOSStage()) |
| 214 | stages.append(DiscoverFuelStage()) |
| 215 | stages.append(ExplicitNodesStage()) |
| 216 | stages.append(SaveNodesStage()) |
| 217 | stages.append(StartSensorsStage()) |
| 218 | stages.append(RunTestsStage()) |
| 219 | stages.append(CollectSensorsStage()) |
| 220 | stages.append(ConnectStage()) |
| 221 | stages.append(SleepStage()) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 222 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 223 | if not opts.dont_collect: |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 224 | stages.append(CollectInfoStage()) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 225 | |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 226 | argv2 = argv[:] |
| 227 | if '--ssh-key-passwd' in argv2: |
| 228 | # don't save ssh key password to storage |
| 229 | argv2[argv2.index("--ssh-key-passwd") + 1] = "<removed from output>" |
| 230 | storage['cli'] = argv2 |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 231 | |
| 232 | elif opts.subparser_name == 'resume': |
| 233 | storage = make_storage(opts.storage_dir, existing=True) |
| 234 | config = storage.load(Config, 'config') |
| 235 | # TODO: fix this |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 236 | # TODO: add node loading from storage |
| 237 | # TODO: fill nodes conncreds with keys |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 238 | raise NotImplementedError("Resume in not fully implemented") |
| 239 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 240 | elif opts.subparser_name == 'ls': |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 241 | tab = texttable.Texttable(max_width=200) |
| 242 | tab.set_deco(tab.HEADER | tab.VLINES | tab.BORDER) |
| 243 | tab.set_cols_align(["l", "l", "l", "l"]) |
| 244 | tab.header(["Name", "Tests", "Run at", "Comment"]) |
| 245 | tab.add_rows(list_results(opts.result_storage)) |
| 246 | print(tab.draw()) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 247 | return 0 |
| 248 | |
| 249 | elif opts.subparser_name == 'report': |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 250 | storage = make_storage(opts.data_dir, existing=True) |
koder aka kdanilov | 3d2bc4f | 2016-11-12 18:31:18 +0200 | [diff] [blame] | 251 | config.settings_dir = get_config_path(config, opts.settings_dir) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 252 | |
| 253 | elif opts.subparser_name == 'compare': |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 254 | # x = run_test.load_data_from_path(opts.data_path1) |
| 255 | # y = run_test.load_data_from_path(opts.data_path2) |
| 256 | # print(run_test.IOPerfTest.format_diff_for_console( |
| 257 | # [x['io'][0], y['io'][0]])) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 258 | return 0 |
| 259 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 260 | report_stages = [] # type: List[Stage] |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 261 | if not getattr(opts, "no_report", False): |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 262 | report_stages.append(ConsoleReportStage()) |
| 263 | report_stages.append(HtmlReportStage()) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 264 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 265 | # log level is not a part of config |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 266 | if opts.log_level is not None: |
| 267 | str_level = opts.log_level |
| 268 | else: |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 269 | str_level = config.get('logging/log_level', 'INFO') |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 270 | |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 271 | log_config_file = config.get('logging/config', None) |
| 272 | |
| 273 | if log_config_file is not None: |
| 274 | log_config_file = find_cfg_file(log_config_file, opts.config_file) |
| 275 | |
| 276 | setup_loggers(getattr(logging, str_level), |
| 277 | log_fd=storage.get_stream('log', "w"), |
| 278 | config_file=log_config_file) |
| 279 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 280 | logger.info("All info would be stored into %r", config.storage_url) |
| 281 | |
| 282 | ctx = TestRun(config, storage) |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 283 | ctx.rpc_code, ctx.default_rpc_plugins = node.get_rpc_server_code() |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 284 | |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 285 | if opts.ssh_key_passwd is not None: |
| 286 | set_ssh_key_passwd(opts.ssh_key_passwd) |
| 287 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 288 | stages.sort(key=lambda x: x.priority) |
| 289 | |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 290 | # TODO: run only stages, which have config |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 291 | failed = False |
| 292 | cleanup_stages = [] |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 293 | for stage in stages: |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 294 | if stage.config_block is not None: |
| 295 | if stage.config_block not in ctx.config: |
| 296 | continue |
| 297 | |
| 298 | cleanup_stages.append(stage) |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 299 | try: |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 300 | with log_stage(stage): |
| 301 | stage.run(ctx) |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 302 | except (Exception, KeyboardInterrupt): |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 303 | failed = True |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 304 | break |
| 305 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 306 | logger.debug("Start cleanup") |
| 307 | cleanup_failed = False |
| 308 | for stage in cleanup_stages[::-1]: |
| 309 | try: |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 310 | with log_stage(stage, cleanup=True): |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 311 | stage.cleanup(ctx) |
| 312 | except: |
| 313 | cleanup_failed = True |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 314 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 315 | if not failed: |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 316 | for report_stage in report_stages: |
| 317 | with log_stage(report_stage): |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 318 | report_stage.run(ctx) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 319 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 320 | logger.info("All info is stored into %r", config.storage_url) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 321 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 322 | if failed or cleanup_failed: |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 323 | logger.error("Tests are failed. See error details in log above") |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 324 | return 1 |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 325 | else: |
| 326 | logger.info("Tests finished successfully") |
| 327 | return 0 |