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 |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 4 | import pprint |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 5 | import getpass |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 6 | import logging |
| 7 | import argparse |
| 8 | import functools |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 9 | import contextlib |
| 10 | from typing import List, Tuple, Any, Callable, IO, cast, Optional, Iterator |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 11 | from yaml import load as _yaml_load |
| 12 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 13 | |
| 14 | YLoader = Callable[[IO], Any] |
| 15 | yaml_load = None # type: YLoader |
| 16 | |
| 17 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 18 | try: |
| 19 | from yaml import CLoader |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 20 | yaml_load = cast(YLoader, functools.partial(_yaml_load, Loader=CLoader)) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 21 | except ImportError: |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 22 | yaml_load = cast(YLoader, _yaml_load) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 23 | |
kdanylov aka koder | b083333 | 2017-05-13 20:39:17 +0300 | [diff] [blame^] | 24 | from cephlib.texttable import Texttable |
| 25 | from cephlib.istorage import IStorage |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 26 | |
| 27 | try: |
| 28 | import faulthandler |
| 29 | except ImportError: |
| 30 | faulthandler = None |
| 31 | |
kdanylov aka koder | 150b219 | 2017-04-01 16:53:01 +0300 | [diff] [blame] | 32 | from cephlib.common import setup_logging |
kdanylov aka koder | b083333 | 2017-05-13 20:39:17 +0300 | [diff] [blame^] | 33 | from cephlib.storage import make_storage |
kdanylov aka koder | 150b219 | 2017-04-01 16:53:01 +0300 | [diff] [blame] | 34 | |
kdanylov aka koder | b083333 | 2017-05-13 20:39:17 +0300 | [diff] [blame^] | 35 | from . import utils, node, report_profiles, report |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 36 | from .node_utils import log_nodes_statistic |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 37 | from .config import Config |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 38 | from .stage import Stage |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 39 | from .test_run_class import TestRun |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 40 | from .ssh import set_ssh_key_passwd |
kdanylov aka koder | b083333 | 2017-05-13 20:39:17 +0300 | [diff] [blame^] | 41 | from .result_storage import ResultStorage |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 42 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 43 | # stages |
kdanylov aka koder | b083333 | 2017-05-13 20:39:17 +0300 | [diff] [blame^] | 44 | from .ceph import DiscoverCephStage, CollectCephInfoStage |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 45 | from .openstack import DiscoverOSStage |
| 46 | from .fuel import DiscoverFuelStage |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 47 | from .run_test import (CollectInfoStage, ExplicitNodesStage, SaveNodesStage, |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 48 | RunTestsStage, ConnectStage, SleepStage, PrepareNodes, |
| 49 | LoadStoredNodesStage) |
kdanylov aka koder | 150b219 | 2017-04-01 16:53:01 +0300 | [diff] [blame] | 50 | |
| 51 | from .report import HtmlReportStage |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 52 | from .sensors import StartSensorsStage, CollectSensorsStage |
kdanylov aka koder | 150b219 | 2017-04-01 16:53:01 +0300 | [diff] [blame] | 53 | from .console_report import ConsoleReportStage |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 54 | |
| 55 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 56 | logger = logging.getLogger("wally") |
| 57 | |
| 58 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 59 | @contextlib.contextmanager |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 60 | def log_stage(stage: Stage, cleanup: bool = False) -> Iterator[None]: |
| 61 | logger.info("Start " + stage.name() + ("::cleanup" if cleanup else "")) |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 62 | try: |
| 63 | yield |
| 64 | except utils.StopTestError as exc: |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 65 | raise |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 66 | except Exception: |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 67 | logger.exception("During %s", stage.name() + ("::cleanup" if cleanup else "")) |
| 68 | raise |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 69 | |
| 70 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 71 | def list_results(path: str) -> List[Tuple[str, str, str, str]]: |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 72 | results = [] # type: List[Tuple[float, str, str, str, str]] |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 73 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 74 | for dir_name in os.listdir(path): |
| 75 | full_path = os.path.join(path, dir_name) |
| 76 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 77 | try: |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 78 | stor = make_storage(full_path, existing=True) |
| 79 | except Exception as exc: |
| 80 | logger.warning("Can't load folder {}. Error {}".format(full_path, exc)) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 81 | |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 82 | comment = cast(str, stor.get('info/comment')) |
| 83 | run_uuid = cast(str, stor.get('info/run_uuid')) |
| 84 | run_time = cast(float, stor.get('info/run_time')) |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 85 | test_types = "" |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 86 | results.append((run_time, |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 87 | run_uuid, |
| 88 | test_types, |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 89 | time.ctime(run_time), |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 90 | '-' if comment is None else comment)) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 91 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 92 | results.sort() |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 93 | return [i[1:] for i in results] |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 94 | |
| 95 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 96 | def log_nodes_statistic_stage(ctx: TestRun) -> None: |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 97 | log_nodes_statistic(ctx.nodes) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 98 | |
| 99 | |
| 100 | def parse_args(argv): |
| 101 | descr = "Disk io performance test suite" |
| 102 | parser = argparse.ArgumentParser(prog='wally', description=descr) |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 103 | 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] | 104 | parser.add_argument("--ssh-key-passwd", default=None, help="Pass ssh key password") |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 105 | parser.add_argument("--ssh-key-passwd-kbd", action="store_true", help="Enter ssh key password interactivelly") |
koder aka kdanilov | 3d2bc4f | 2016-11-12 18:31:18 +0200 | [diff] [blame] | 106 | parser.add_argument("-s", '--settings-dir', default=None, |
| 107 | help="Folder to store key/settings/history files") |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 108 | |
| 109 | subparsers = parser.add_subparsers(dest='subparser_name') |
| 110 | |
| 111 | # --------------------------------------------------------------------- |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 112 | report_parser = subparsers.add_parser('ls', help='list all results') |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 113 | report_parser.add_argument("result_storage", help="Folder with test results") |
| 114 | |
| 115 | # --------------------------------------------------------------------- |
| 116 | compare_help = 'compare two results' |
| 117 | report_parser = subparsers.add_parser('compare', help=compare_help) |
| 118 | report_parser.add_argument("data_path1", help="First folder with test results") |
| 119 | report_parser.add_argument("data_path2", help="Second folder with test results") |
| 120 | |
| 121 | # --------------------------------------------------------------------- |
| 122 | report_help = 'run report on previously obtained results' |
| 123 | report_parser = subparsers.add_parser('report', help=report_help) |
kdanylov aka koder | 150b219 | 2017-04-01 16:53:01 +0300 | [diff] [blame] | 124 | report_parser.add_argument('-R', '--reporters', help="Comma-separated list of reportes - html,txt", |
| 125 | default='html,txt') |
kdanylov aka koder | b083333 | 2017-05-13 20:39:17 +0300 | [diff] [blame^] | 126 | report_parser.add_argument('-f', '--format', help="Images format, default is " + report_profiles.default_format, |
| 127 | choices=('svg', 'png'), default=report_profiles.default_format) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 128 | report_parser.add_argument("data_dir", help="folder with rest results") |
| 129 | |
| 130 | # --------------------------------------------------------------------- |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 131 | ipython_help = 'run ipython in prepared environment' |
| 132 | ipython_parser = subparsers.add_parser('ipython', help=ipython_help) |
| 133 | ipython_parser.add_argument("storage_dir", help="Storage path") |
| 134 | # --------------------------------------------------------------------- |
| 135 | jupyter_help = 'run ipython in prepared environment' |
| 136 | jupyter_parser = subparsers.add_parser('jupyter', help=jupyter_help) |
| 137 | jupyter_parser.add_argument("storage_dir", help="Storage path") |
| 138 | |
| 139 | # --------------------------------------------------------------------- |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 140 | test_parser = subparsers.add_parser('test', help='run tests') |
kdanylov aka koder | 150b219 | 2017-04-01 16:53:01 +0300 | [diff] [blame] | 141 | test_parser.add_argument("-d", '--dont-discover-nodes', action='store_true', help="Don't discover nodes") |
| 142 | test_parser.add_argument('-D', '--dont-collect', action='store_true', help="Don't collect cluster info") |
| 143 | test_parser.add_argument("-k", '--keep-vm', action='store_true', help="Don't remove test vm's") |
| 144 | test_parser.add_argument('-L', '--load-report', action='store_true', help="Create cluster load report") |
| 145 | test_parser.add_argument('-n', '--no-tests', action='store_true', help="Don't run tests") |
| 146 | test_parser.add_argument('-N', '--no-report', action='store_true', help="Skip report stages") |
| 147 | test_parser.add_argument('-r', '--result-dir', default=None, help="Save results to DIR", metavar="DIR") |
| 148 | test_parser.add_argument('-R', '--reporters', help="Comma-separated list of reportes - html,txt", |
| 149 | default='html,txt') |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 150 | test_parser.add_argument('--build-description', type=str, default="Build info") |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 151 | test_parser.add_argument('--build-id', type=str, default="id") |
| 152 | test_parser.add_argument('--build-type', type=str, default="GA") |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 153 | test_parser.add_argument("comment", help="Test information") |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 154 | test_parser.add_argument("config_file", help="Yaml config file") |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 155 | |
| 156 | # --------------------------------------------------------------------- |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 157 | test_parser = subparsers.add_parser('resume', help='resume tests') |
| 158 | test_parser.add_argument("storage_dir", help="Path to test directory") |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 159 | |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 160 | # --------------------------------------------------------------------- |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 161 | test_parser = subparsers.add_parser('db', help='Exec command on DB') |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 162 | test_parser.add_argument("cmd", choices=("show",), help="Command to execute") |
| 163 | test_parser.add_argument("params", nargs='*', help="Command params") |
| 164 | test_parser.add_argument("storage_dir", help="Storage path") |
| 165 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 166 | return parser.parse_args(argv[1:]) |
| 167 | |
| 168 | |
koder aka kdanilov | 3d2bc4f | 2016-11-12 18:31:18 +0200 | [diff] [blame] | 169 | def get_config_path(config: Config, opts_value: Optional[str]) -> str: |
| 170 | if opts_value is None and 'settings_dir' not in config: |
| 171 | val = "~/.wally" |
| 172 | elif opts_value is not None: |
| 173 | val = opts_value |
| 174 | else: |
| 175 | val = config.settings_dir |
| 176 | |
| 177 | return os.path.abspath(os.path.expanduser(val)) |
| 178 | |
| 179 | |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 180 | def find_cfg_file(name: str, included_from: str = None) -> str: |
| 181 | paths = [".", os.path.expanduser('~/.wally')] |
| 182 | if included_from is not None: |
| 183 | paths.append(os.path.dirname(included_from)) |
| 184 | |
| 185 | search_paths = set(os.path.abspath(path) for path in paths if os.path.isdir(path)) |
| 186 | |
| 187 | for folder in search_paths: |
| 188 | path = os.path.join(folder, name) |
| 189 | if os.path.exists(path): |
| 190 | return path |
| 191 | |
| 192 | raise FileNotFoundError(name) |
| 193 | |
| 194 | |
| 195 | def load_config(path: str) -> Config: |
| 196 | path = os.path.abspath(path) |
| 197 | cfg_dict = yaml_load(open(path).read()) |
| 198 | |
| 199 | while 'include' in cfg_dict: |
| 200 | inc = cfg_dict.pop('include') |
| 201 | if isinstance(inc, str): |
| 202 | inc = [inc] |
| 203 | |
| 204 | for fname in inc: |
| 205 | inc_path = find_cfg_file(fname, path) |
| 206 | inc_dict = yaml_load(open(inc_path).read()) |
| 207 | inc_dict.update(cfg_dict) |
| 208 | cfg_dict = inc_dict |
| 209 | |
| 210 | return Config(cfg_dict) |
| 211 | |
| 212 | |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 213 | def get_run_stages() -> List[Stage]: |
| 214 | return [DiscoverCephStage(), |
kdanylov aka koder | b083333 | 2017-05-13 20:39:17 +0300 | [diff] [blame^] | 215 | CollectCephInfoStage(), |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 216 | DiscoverOSStage(), |
| 217 | DiscoverFuelStage(), |
| 218 | ExplicitNodesStage(), |
| 219 | StartSensorsStage(), |
| 220 | RunTestsStage(), |
| 221 | CollectSensorsStage(), |
| 222 | ConnectStage(), |
| 223 | SleepStage(), |
| 224 | PrepareNodes()] |
| 225 | |
| 226 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 227 | def main(argv: List[str]) -> int: |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 228 | if faulthandler is not None: |
| 229 | faulthandler.register(signal.SIGUSR1, all_threads=True) |
| 230 | |
| 231 | opts = parse_args(argv) |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 232 | stages = [] # type: List[Stage] |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 233 | |
| 234 | # stop mypy from telling that config & storage might be undeclared |
| 235 | config = None # type: Config |
kdanylov aka koder | b083333 | 2017-05-13 20:39:17 +0300 | [diff] [blame^] | 236 | storage = None # type: IStorage |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 237 | |
| 238 | if opts.subparser_name == 'test': |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 239 | config = load_config(opts.config_file) |
kdanylov aka koder | 150b219 | 2017-04-01 16:53:01 +0300 | [diff] [blame] | 240 | config.storage_url, config.run_uuid = utils.get_uniq_path_uuid(config.results_storage) |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 241 | config.comment = opts.comment |
| 242 | config.keep_vm = opts.keep_vm |
| 243 | config.no_tests = opts.no_tests |
| 244 | config.dont_discover_nodes = opts.dont_discover_nodes |
| 245 | config.build_id = opts.build_id |
| 246 | config.build_description = opts.build_description |
| 247 | config.build_type = opts.build_type |
| 248 | config.settings_dir = get_config_path(config, opts.settings_dir) |
kdanylov aka koder | cdfcdaf | 2017-04-29 10:03:39 +0300 | [diff] [blame] | 249 | config.discover = set(name for name in config.get('discover', '').split(",") if name) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 250 | |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 251 | storage = make_storage(config.storage_url) |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 252 | storage.put(config, 'config') |
koder aka kdanilov | ffaf48d | 2016-12-27 02:25:29 +0200 | [diff] [blame] | 253 | |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 254 | stages.extend(get_run_stages()) |
koder aka kdanilov | ffaf48d | 2016-12-27 02:25:29 +0200 | [diff] [blame] | 255 | stages.append(SaveNodesStage()) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 256 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 257 | if not opts.dont_collect: |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 258 | stages.append(CollectInfoStage()) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 259 | |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 260 | argv2 = argv[:] |
| 261 | if '--ssh-key-passwd' in argv2: |
| 262 | # don't save ssh key password to storage |
| 263 | argv2[argv2.index("--ssh-key-passwd") + 1] = "<removed from output>" |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 264 | storage.put(argv2, 'cli') |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 265 | |
| 266 | elif opts.subparser_name == 'resume': |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 267 | opts.resumed = True |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 268 | storage = make_storage(opts.storage_dir, existing=True) |
| 269 | config = storage.load(Config, 'config') |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 270 | stages.extend(get_run_stages()) |
| 271 | stages.append(LoadStoredNodesStage()) |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 272 | prev_opts = storage.get('cli') # type: List[str] |
| 273 | |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 274 | if '--ssh-key-passwd' in prev_opts and opts.ssh_key_passwd: |
| 275 | prev_opts[prev_opts.index("--ssh-key-passwd") + 1] = opts.ssh_key_passwd |
| 276 | |
| 277 | restored_opts = parse_args(prev_opts) |
| 278 | opts.__dict__.update(restored_opts.__dict__) |
| 279 | opts.subparser_name = 'resume' |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 280 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 281 | elif opts.subparser_name == 'ls': |
kdanylov aka koder | b083333 | 2017-05-13 20:39:17 +0300 | [diff] [blame^] | 282 | tab = Texttable(max_width=200) |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 283 | tab.set_deco(tab.HEADER | tab.VLINES | tab.BORDER) |
| 284 | tab.set_cols_align(["l", "l", "l", "l"]) |
| 285 | tab.header(["Name", "Tests", "Run at", "Comment"]) |
| 286 | tab.add_rows(list_results(opts.result_storage)) |
| 287 | print(tab.draw()) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 288 | return 0 |
| 289 | |
| 290 | elif opts.subparser_name == 'report': |
koder aka kdanilov | ffaf48d | 2016-12-27 02:25:29 +0200 | [diff] [blame] | 291 | if getattr(opts, "no_report", False): |
| 292 | print(" --no-report option can't be used with 'report' cmd") |
| 293 | return 1 |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 294 | storage = make_storage(opts.data_dir, existing=True) |
koder aka kdanilov | ffaf48d | 2016-12-27 02:25:29 +0200 | [diff] [blame] | 295 | config = storage.load(Config, 'config') |
kdanylov aka koder | b083333 | 2017-05-13 20:39:17 +0300 | [diff] [blame^] | 296 | report_profiles.default_format = opts.format |
| 297 | report.default_format = opts.format |
koder aka kdanilov | ffaf48d | 2016-12-27 02:25:29 +0200 | [diff] [blame] | 298 | stages.append(LoadStoredNodesStage()) |
kdanylov aka koder | 736e5c1 | 2017-05-07 17:27:14 +0300 | [diff] [blame] | 299 | stages.append(SaveNodesStage()) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 300 | elif opts.subparser_name == 'compare': |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 301 | # x = run_test.load_data_from_path(opts.data_path1) |
| 302 | # y = run_test.load_data_from_path(opts.data_path2) |
| 303 | # print(run_test.IOPerfTest.format_diff_for_console( |
| 304 | # [x['io'][0], y['io'][0]])) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 305 | return 0 |
| 306 | |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 307 | elif opts.subparser_name == 'db': |
| 308 | storage = make_storage(opts.storage_dir, existing=True) |
| 309 | if opts.cmd == 'show': |
| 310 | if len(opts.params) != 1: |
| 311 | print("'show' command requires parameter - key to show") |
| 312 | return 1 |
| 313 | pprint.pprint(storage.get(opts.params[0])) |
| 314 | else: |
| 315 | print("Unknown/not_implemented command {!r}".format(opts.cmd)) |
| 316 | return 1 |
| 317 | return 0 |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 318 | elif opts.subparser_name == 'ipython': |
| 319 | storage = make_storage(opts.storage_dir, existing=True) |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 320 | rstorage = ResultStorage(storage=storage) |
| 321 | |
| 322 | import IPython |
| 323 | IPython.embed() |
| 324 | |
| 325 | return 0 |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame] | 326 | else: |
| 327 | print("Subparser {!r} is not supported".format(opts.subparser_name)) |
| 328 | return 1 |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 329 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 330 | report_stages = [] # type: List[Stage] |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 331 | if not getattr(opts, "no_report", False): |
kdanylov aka koder | 150b219 | 2017-04-01 16:53:01 +0300 | [diff] [blame] | 332 | reporters = opts.reporters.split(",") |
| 333 | assert len(set(reporters)) == len(reporters) |
| 334 | assert set(reporters).issubset({'txt', 'html'}) |
| 335 | if 'txt' in reporters: |
| 336 | report_stages.append(ConsoleReportStage()) |
| 337 | if 'html' in reporters: |
| 338 | report_stages.append(HtmlReportStage()) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 339 | |
kdanylov aka koder | 150b219 | 2017-04-01 16:53:01 +0300 | [diff] [blame] | 340 | log_config_obj = config.raw().get('logging') |
| 341 | assert isinstance(log_config_obj, dict) or log_config_obj is None, "Broken 'logging' option in config" |
| 342 | setup_logging(log_config_obj=log_config_obj, log_level=opts.log_level, log_file=storage.get_fname('log')) |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 343 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 344 | logger.info("All info would be stored into %r", config.storage_url) |
| 345 | |
kdanylov aka koder | b083333 | 2017-05-13 20:39:17 +0300 | [diff] [blame^] | 346 | ctx = TestRun(config, storage, ResultStorage(storage)) |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 347 | 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] | 348 | |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 349 | if opts.ssh_key_passwd is not None: |
| 350 | set_ssh_key_passwd(opts.ssh_key_passwd) |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 351 | elif opts.ssh_key_passwd_kbd: |
| 352 | set_ssh_key_passwd(getpass.getpass("Ssh key password: ").strip()) |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 353 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 354 | stages.sort(key=lambda x: x.priority) |
| 355 | |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 356 | # TODO: run only stages, which have config |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 357 | failed = False |
| 358 | cleanup_stages = [] |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 359 | |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 360 | for stage in stages: |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 361 | if stage.config_block is not None: |
| 362 | if stage.config_block not in ctx.config: |
kdanylov aka koder | 150b219 | 2017-04-01 16:53:01 +0300 | [diff] [blame] | 363 | logger.debug("Skip stage %r, as config has no required block %r", stage.name(), stage.config_block) |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 364 | continue |
| 365 | |
| 366 | cleanup_stages.append(stage) |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 367 | try: |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 368 | with log_stage(stage): |
| 369 | stage.run(ctx) |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 370 | except (Exception, KeyboardInterrupt): |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 371 | failed = True |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 372 | break |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 373 | ctx.storage.sync() |
| 374 | ctx.storage.sync() |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 375 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 376 | logger.debug("Start cleanup") |
| 377 | cleanup_failed = False |
| 378 | for stage in cleanup_stages[::-1]: |
| 379 | try: |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 380 | with log_stage(stage, cleanup=True): |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 381 | stage.cleanup(ctx) |
| 382 | except: |
| 383 | cleanup_failed = True |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 384 | ctx.storage.sync() |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 385 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 386 | if not failed: |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 387 | for report_stage in report_stages: |
| 388 | with log_stage(report_stage): |
koder aka kdanilov | ffaf48d | 2016-12-27 02:25:29 +0200 | [diff] [blame] | 389 | try: |
| 390 | report_stage.run(ctx) |
| 391 | except utils.StopTestError: |
| 392 | logger.error("Report stage %s requested stop execution", report_stage.name()) |
| 393 | failed = True |
| 394 | break |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 395 | |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 396 | ctx.storage.sync() |
| 397 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 398 | logger.info("All info is stored into %r", config.storage_url) |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 399 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 400 | if failed or cleanup_failed: |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 401 | logger.error("Tests are failed. See error details in log above") |
koder aka kdanilov | 0fdaaee | 2015-06-30 11:10:48 +0300 | [diff] [blame] | 402 | return 1 |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 403 | else: |
| 404 | logger.info("Tests finished successfully") |
| 405 | return 0 |