blob: a20ade5e5400ef5137810c7cc912d5fb27f4a9ec [file] [log] [blame]
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +03001import os
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +03002import time
3import signal
koder aka kdanilov7f59d562016-12-26 01:34:23 +02004import pprint
koder aka kdanilovf2865172016-12-30 03:35:11 +02005import getpass
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +03006import logging
7import argparse
8import functools
koder aka kdanilov39e449e2016-12-17 15:15:26 +02009import contextlib
10from typing import List, Tuple, Any, Callable, IO, cast, Optional, Iterator
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +030011from yaml import load as _yaml_load
12
koder aka kdanilov22d134e2016-11-08 11:33:19 +020013
14YLoader = Callable[[IO], Any]
15yaml_load = None # type: YLoader
16
17
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +030018try:
19 from yaml import CLoader
koder aka kdanilov22d134e2016-11-08 11:33:19 +020020 yaml_load = cast(YLoader, functools.partial(_yaml_load, Loader=CLoader))
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +030021except ImportError:
koder aka kdanilov22d134e2016-11-08 11:33:19 +020022 yaml_load = cast(YLoader, _yaml_load)
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +030023
24
25import texttable
26
27try:
28 import faulthandler
29except ImportError:
30 faulthandler = None
31
kdanylov aka koder150b2192017-04-01 16:53:01 +030032from cephlib.common import setup_logging
33
koder aka kdanilove7e1a4d2016-12-17 20:29:52 +020034from . import utils, node
koder aka kdanilov108ac362017-01-19 20:17:16 +020035from .node_utils import log_nodes_statistic
koder aka kdanilov3d2bc4f2016-11-12 18:31:18 +020036from .storage import make_storage, Storage
koder aka kdanilov22d134e2016-11-08 11:33:19 +020037from .config import Config
koder aka kdanilov39e449e2016-12-17 15:15:26 +020038from .stage import Stage
koder aka kdanilov22d134e2016-11-08 11:33:19 +020039from .test_run_class import TestRun
koder aka kdanilov962ee5f2016-12-19 02:40:08 +020040from .ssh import set_ssh_key_passwd
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +030041
42
koder aka kdanilov39e449e2016-12-17 15:15:26 +020043# stages
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +030044from .ceph import DiscoverCephStage, FillCephInfoStage
koder aka kdanilov39e449e2016-12-17 15:15:26 +020045from .openstack import DiscoverOSStage
46from .fuel import DiscoverFuelStage
koder aka kdanilov23e6bdf2016-12-24 02:18:54 +020047from .run_test import (CollectInfoStage, ExplicitNodesStage, SaveNodesStage,
koder aka kdanilov7f59d562016-12-26 01:34:23 +020048 RunTestsStage, ConnectStage, SleepStage, PrepareNodes,
49 LoadStoredNodesStage)
kdanylov aka koder150b2192017-04-01 16:53:01 +030050
51from .report import HtmlReportStage
koder aka kdanilov39e449e2016-12-17 15:15:26 +020052from .sensors import StartSensorsStage, CollectSensorsStage
kdanylov aka koder150b2192017-04-01 16:53:01 +030053from .console_report import ConsoleReportStage
koder aka kdanilov39e449e2016-12-17 15:15:26 +020054
55
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +030056logger = logging.getLogger("wally")
57
58
koder aka kdanilov39e449e2016-12-17 15:15:26 +020059@contextlib.contextmanager
koder aka kdanilov962ee5f2016-12-19 02:40:08 +020060def log_stage(stage: Stage, cleanup: bool = False) -> Iterator[None]:
61 logger.info("Start " + stage.name() + ("::cleanup" if cleanup else ""))
koder aka kdanilov39e449e2016-12-17 15:15:26 +020062 try:
63 yield
64 except utils.StopTestError as exc:
koder aka kdanilov962ee5f2016-12-19 02:40:08 +020065 raise
koder aka kdanilov39e449e2016-12-17 15:15:26 +020066 except Exception:
koder aka kdanilov962ee5f2016-12-19 02:40:08 +020067 logger.exception("During %s", stage.name() + ("::cleanup" if cleanup else ""))
68 raise
koder aka kdanilov39e449e2016-12-17 15:15:26 +020069
70
koder aka kdanilov22d134e2016-11-08 11:33:19 +020071def list_results(path: str) -> List[Tuple[str, str, str, str]]:
koder aka kdanilov73084622016-11-16 21:51:08 +020072 results = [] # type: List[Tuple[float, str, str, str, str]]
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +030073
koder aka kdanilov22d134e2016-11-08 11:33:19 +020074 for dir_name in os.listdir(path):
75 full_path = os.path.join(path, dir_name)
76
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +030077 try:
koder aka kdanilov22d134e2016-11-08 11:33:19 +020078 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 kdanilov0fdaaee2015-06-30 11:10:48 +030081
koder aka kdanilov7f59d562016-12-26 01:34:23 +020082 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 kdanilov22d134e2016-11-08 11:33:19 +020085 test_types = ""
koder aka kdanilov73084622016-11-16 21:51:08 +020086 results.append((run_time,
koder aka kdanilov22d134e2016-11-08 11:33:19 +020087 run_uuid,
88 test_types,
koder aka kdanilov73084622016-11-16 21:51:08 +020089 time.ctime(run_time),
koder aka kdanilov22d134e2016-11-08 11:33:19 +020090 '-' if comment is None else comment))
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +030091
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +030092 results.sort()
koder aka kdanilov22d134e2016-11-08 11:33:19 +020093 return [i[1:] for i in results]
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +030094
95
koder aka kdanilov22d134e2016-11-08 11:33:19 +020096def log_nodes_statistic_stage(ctx: TestRun) -> None:
koder aka kdanilov108ac362017-01-19 20:17:16 +020097 log_nodes_statistic(ctx.nodes)
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +030098
99
100def parse_args(argv):
101 descr = "Disk io performance test suite"
102 parser = argparse.ArgumentParser(prog='wally', description=descr)
koder aka kdanilov22d134e2016-11-08 11:33:19 +0200103 parser.add_argument("-l", '--log-level', help="print some extra log info")
koder aka kdanilov962ee5f2016-12-19 02:40:08 +0200104 parser.add_argument("--ssh-key-passwd", default=None, help="Pass ssh key password")
koder aka kdanilovf2865172016-12-30 03:35:11 +0200105 parser.add_argument("--ssh-key-passwd-kbd", action="store_true", help="Enter ssh key password interactivelly")
koder aka kdanilov3d2bc4f2016-11-12 18:31:18 +0200106 parser.add_argument("-s", '--settings-dir', default=None,
107 help="Folder to store key/settings/history files")
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300108
109 subparsers = parser.add_subparsers(dest='subparser_name')
110
111 # ---------------------------------------------------------------------
koder aka kdanilov22d134e2016-11-08 11:33:19 +0200112 report_parser = subparsers.add_parser('ls', help='list all results')
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300113 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 koder150b2192017-04-01 16:53:01 +0300124 report_parser.add_argument('-R', '--reporters', help="Comma-separated list of reportes - html,txt",
125 default='html,txt')
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300126 report_parser.add_argument("data_dir", help="folder with rest results")
127
128 # ---------------------------------------------------------------------
koder aka kdanilov108ac362017-01-19 20:17:16 +0200129 ipython_help = 'run ipython in prepared environment'
130 ipython_parser = subparsers.add_parser('ipython', help=ipython_help)
131 ipython_parser.add_argument("storage_dir", help="Storage path")
132 # ---------------------------------------------------------------------
133 jupyter_help = 'run ipython in prepared environment'
134 jupyter_parser = subparsers.add_parser('jupyter', help=jupyter_help)
135 jupyter_parser.add_argument("storage_dir", help="Storage path")
136
137 # ---------------------------------------------------------------------
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300138 test_parser = subparsers.add_parser('test', help='run tests')
kdanylov aka koder150b2192017-04-01 16:53:01 +0300139 test_parser.add_argument("-d", '--dont-discover-nodes', action='store_true', help="Don't discover nodes")
140 test_parser.add_argument('-D', '--dont-collect', action='store_true', help="Don't collect cluster info")
141 test_parser.add_argument("-k", '--keep-vm', action='store_true', help="Don't remove test vm's")
142 test_parser.add_argument('-L', '--load-report', action='store_true', help="Create cluster load report")
143 test_parser.add_argument('-n', '--no-tests', action='store_true', help="Don't run tests")
144 test_parser.add_argument('-N', '--no-report', action='store_true', help="Skip report stages")
145 test_parser.add_argument('-r', '--result-dir', default=None, help="Save results to DIR", metavar="DIR")
146 test_parser.add_argument('-R', '--reporters', help="Comma-separated list of reportes - html,txt",
147 default='html,txt')
koder aka kdanilov22d134e2016-11-08 11:33:19 +0200148 test_parser.add_argument('--build-description', type=str, default="Build info")
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300149 test_parser.add_argument('--build-id', type=str, default="id")
150 test_parser.add_argument('--build-type', type=str, default="GA")
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300151 test_parser.add_argument("comment", help="Test information")
koder aka kdanilov962ee5f2016-12-19 02:40:08 +0200152 test_parser.add_argument("config_file", help="Yaml config file")
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300153
154 # ---------------------------------------------------------------------
koder aka kdanilove7e1a4d2016-12-17 20:29:52 +0200155 test_parser = subparsers.add_parser('resume', help='resume tests')
156 test_parser.add_argument("storage_dir", help="Path to test directory")
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300157
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200158 # ---------------------------------------------------------------------
koder aka kdanilov108ac362017-01-19 20:17:16 +0200159 test_parser = subparsers.add_parser('db', help='Exec command on DB')
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200160 test_parser.add_argument("cmd", choices=("show",), help="Command to execute")
161 test_parser.add_argument("params", nargs='*', help="Command params")
162 test_parser.add_argument("storage_dir", help="Storage path")
163
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300164 return parser.parse_args(argv[1:])
165
166
koder aka kdanilov3d2bc4f2016-11-12 18:31:18 +0200167def get_config_path(config: Config, opts_value: Optional[str]) -> str:
168 if opts_value is None and 'settings_dir' not in config:
169 val = "~/.wally"
170 elif opts_value is not None:
171 val = opts_value
172 else:
173 val = config.settings_dir
174
175 return os.path.abspath(os.path.expanduser(val))
176
177
koder aka kdanilov962ee5f2016-12-19 02:40:08 +0200178def find_cfg_file(name: str, included_from: str = None) -> str:
179 paths = [".", os.path.expanduser('~/.wally')]
180 if included_from is not None:
181 paths.append(os.path.dirname(included_from))
182
183 search_paths = set(os.path.abspath(path) for path in paths if os.path.isdir(path))
184
185 for folder in search_paths:
186 path = os.path.join(folder, name)
187 if os.path.exists(path):
188 return path
189
190 raise FileNotFoundError(name)
191
192
193def load_config(path: str) -> Config:
194 path = os.path.abspath(path)
195 cfg_dict = yaml_load(open(path).read())
196
197 while 'include' in cfg_dict:
198 inc = cfg_dict.pop('include')
199 if isinstance(inc, str):
200 inc = [inc]
201
202 for fname in inc:
203 inc_path = find_cfg_file(fname, path)
204 inc_dict = yaml_load(open(inc_path).read())
205 inc_dict.update(cfg_dict)
206 cfg_dict = inc_dict
207
208 return Config(cfg_dict)
209
210
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200211def get_run_stages() -> List[Stage]:
212 return [DiscoverCephStage(),
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300213 FillCephInfoStage(),
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200214 DiscoverOSStage(),
215 DiscoverFuelStage(),
216 ExplicitNodesStage(),
217 StartSensorsStage(),
218 RunTestsStage(),
219 CollectSensorsStage(),
220 ConnectStage(),
221 SleepStage(),
222 PrepareNodes()]
223
224
koder aka kdanilov22d134e2016-11-08 11:33:19 +0200225def main(argv: List[str]) -> int:
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300226 if faulthandler is not None:
227 faulthandler.register(signal.SIGUSR1, all_threads=True)
228
229 opts = parse_args(argv)
koder aka kdanilov39e449e2016-12-17 15:15:26 +0200230 stages = [] # type: List[Stage]
koder aka kdanilov22d134e2016-11-08 11:33:19 +0200231
232 # stop mypy from telling that config & storage might be undeclared
233 config = None # type: Config
koder aka kdanilov3d2bc4f2016-11-12 18:31:18 +0200234 storage = None # type: Storage
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300235
236 if opts.subparser_name == 'test':
koder aka kdanilov962ee5f2016-12-19 02:40:08 +0200237 config = load_config(opts.config_file)
kdanylov aka koder150b2192017-04-01 16:53:01 +0300238 config.storage_url, config.run_uuid = utils.get_uniq_path_uuid(config.results_storage)
koder aka kdanilove7e1a4d2016-12-17 20:29:52 +0200239 config.comment = opts.comment
240 config.keep_vm = opts.keep_vm
241 config.no_tests = opts.no_tests
242 config.dont_discover_nodes = opts.dont_discover_nodes
243 config.build_id = opts.build_id
244 config.build_description = opts.build_description
245 config.build_type = opts.build_type
246 config.settings_dir = get_config_path(config, opts.settings_dir)
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300247 config.discover = set(name for name in config.get('discover', '').split(",") if name)
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300248
koder aka kdanilove7e1a4d2016-12-17 20:29:52 +0200249 storage = make_storage(config.storage_url)
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200250 storage.put(config, 'config')
koder aka kdanilovffaf48d2016-12-27 02:25:29 +0200251
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200252 stages.extend(get_run_stages())
koder aka kdanilovffaf48d2016-12-27 02:25:29 +0200253 stages.append(SaveNodesStage())
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300254
koder aka kdanilov39e449e2016-12-17 15:15:26 +0200255 if not opts.dont_collect:
koder aka kdanilov962ee5f2016-12-19 02:40:08 +0200256 stages.append(CollectInfoStage())
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300257
koder aka kdanilov962ee5f2016-12-19 02:40:08 +0200258 argv2 = argv[:]
259 if '--ssh-key-passwd' in argv2:
260 # don't save ssh key password to storage
261 argv2[argv2.index("--ssh-key-passwd") + 1] = "<removed from output>"
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200262 storage.put(argv2, 'cli')
koder aka kdanilove7e1a4d2016-12-17 20:29:52 +0200263
264 elif opts.subparser_name == 'resume':
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200265 opts.resumed = True
koder aka kdanilove7e1a4d2016-12-17 20:29:52 +0200266 storage = make_storage(opts.storage_dir, existing=True)
267 config = storage.load(Config, 'config')
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200268 stages.extend(get_run_stages())
269 stages.append(LoadStoredNodesStage())
koder aka kdanilov108ac362017-01-19 20:17:16 +0200270 prev_opts = storage.get('cli') # type: List[str]
271
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200272 if '--ssh-key-passwd' in prev_opts and opts.ssh_key_passwd:
273 prev_opts[prev_opts.index("--ssh-key-passwd") + 1] = opts.ssh_key_passwd
274
275 restored_opts = parse_args(prev_opts)
276 opts.__dict__.update(restored_opts.__dict__)
277 opts.subparser_name = 'resume'
koder aka kdanilove7e1a4d2016-12-17 20:29:52 +0200278
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300279 elif opts.subparser_name == 'ls':
koder aka kdanilov22d134e2016-11-08 11:33:19 +0200280 tab = texttable.Texttable(max_width=200)
281 tab.set_deco(tab.HEADER | tab.VLINES | tab.BORDER)
282 tab.set_cols_align(["l", "l", "l", "l"])
283 tab.header(["Name", "Tests", "Run at", "Comment"])
284 tab.add_rows(list_results(opts.result_storage))
285 print(tab.draw())
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300286 return 0
287
288 elif opts.subparser_name == 'report':
koder aka kdanilovffaf48d2016-12-27 02:25:29 +0200289 if getattr(opts, "no_report", False):
290 print(" --no-report option can't be used with 'report' cmd")
291 return 1
koder aka kdanilov22d134e2016-11-08 11:33:19 +0200292 storage = make_storage(opts.data_dir, existing=True)
koder aka kdanilovffaf48d2016-12-27 02:25:29 +0200293 config = storage.load(Config, 'config')
294 stages.append(LoadStoredNodesStage())
kdanylov aka koder736e5c12017-05-07 17:27:14 +0300295 stages.append(SaveNodesStage())
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300296
297 elif opts.subparser_name == 'compare':
koder aka kdanilov73084622016-11-16 21:51:08 +0200298 # x = run_test.load_data_from_path(opts.data_path1)
299 # y = run_test.load_data_from_path(opts.data_path2)
300 # print(run_test.IOPerfTest.format_diff_for_console(
301 # [x['io'][0], y['io'][0]]))
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300302 return 0
303
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200304 elif opts.subparser_name == 'db':
305 storage = make_storage(opts.storage_dir, existing=True)
306 if opts.cmd == 'show':
307 if len(opts.params) != 1:
308 print("'show' command requires parameter - key to show")
309 return 1
310 pprint.pprint(storage.get(opts.params[0]))
311 else:
312 print("Unknown/not_implemented command {!r}".format(opts.cmd))
313 return 1
314 return 0
koder aka kdanilov108ac362017-01-19 20:17:16 +0200315 elif opts.subparser_name == 'ipython':
316 storage = make_storage(opts.storage_dir, existing=True)
317 from .hlstorage import ResultStorage
318 rstorage = ResultStorage(storage=storage)
319
320 import IPython
321 IPython.embed()
322
323 return 0
koder aka kdanilova732a602017-02-01 20:29:56 +0200324 else:
325 print("Subparser {!r} is not supported".format(opts.subparser_name))
326 return 1
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200327
koder aka kdanilov39e449e2016-12-17 15:15:26 +0200328 report_stages = [] # type: List[Stage]
koder aka kdanilov22d134e2016-11-08 11:33:19 +0200329 if not getattr(opts, "no_report", False):
kdanylov aka koder150b2192017-04-01 16:53:01 +0300330 reporters = opts.reporters.split(",")
331 assert len(set(reporters)) == len(reporters)
332 assert set(reporters).issubset({'txt', 'html'})
333 if 'txt' in reporters:
334 report_stages.append(ConsoleReportStage())
335 if 'html' in reporters:
336 report_stages.append(HtmlReportStage())
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300337
kdanylov aka koder150b2192017-04-01 16:53:01 +0300338 log_config_obj = config.raw().get('logging')
339 assert isinstance(log_config_obj, dict) or log_config_obj is None, "Broken 'logging' option in config"
340 setup_logging(log_config_obj=log_config_obj, log_level=opts.log_level, log_file=storage.get_fname('log'))
koder aka kdanilov962ee5f2016-12-19 02:40:08 +0200341
koder aka kdanilov22d134e2016-11-08 11:33:19 +0200342 logger.info("All info would be stored into %r", config.storage_url)
343
344 ctx = TestRun(config, storage)
koder aka kdanilove7e1a4d2016-12-17 20:29:52 +0200345 ctx.rpc_code, ctx.default_rpc_plugins = node.get_rpc_server_code()
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300346
koder aka kdanilov962ee5f2016-12-19 02:40:08 +0200347 if opts.ssh_key_passwd is not None:
348 set_ssh_key_passwd(opts.ssh_key_passwd)
koder aka kdanilovf2865172016-12-30 03:35:11 +0200349 elif opts.ssh_key_passwd_kbd:
350 set_ssh_key_passwd(getpass.getpass("Ssh key password: ").strip())
koder aka kdanilov962ee5f2016-12-19 02:40:08 +0200351
koder aka kdanilov39e449e2016-12-17 15:15:26 +0200352 stages.sort(key=lambda x: x.priority)
353
koder aka kdanilov962ee5f2016-12-19 02:40:08 +0200354 # TODO: run only stages, which have config
koder aka kdanilov39e449e2016-12-17 15:15:26 +0200355 failed = False
356 cleanup_stages = []
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200357
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300358 for stage in stages:
koder aka kdanilove7e1a4d2016-12-17 20:29:52 +0200359 if stage.config_block is not None:
360 if stage.config_block not in ctx.config:
kdanylov aka koder150b2192017-04-01 16:53:01 +0300361 logger.debug("Skip stage %r, as config has no required block %r", stage.name(), stage.config_block)
koder aka kdanilove7e1a4d2016-12-17 20:29:52 +0200362 continue
363
364 cleanup_stages.append(stage)
koder aka kdanilov39e449e2016-12-17 15:15:26 +0200365 try:
koder aka kdanilov39e449e2016-12-17 15:15:26 +0200366 with log_stage(stage):
367 stage.run(ctx)
koder aka kdanilov962ee5f2016-12-19 02:40:08 +0200368 except (Exception, KeyboardInterrupt):
koder aka kdanilov39e449e2016-12-17 15:15:26 +0200369 failed = True
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300370 break
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200371 ctx.storage.sync()
372 ctx.storage.sync()
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300373
koder aka kdanilov39e449e2016-12-17 15:15:26 +0200374 logger.debug("Start cleanup")
375 cleanup_failed = False
376 for stage in cleanup_stages[::-1]:
377 try:
koder aka kdanilov962ee5f2016-12-19 02:40:08 +0200378 with log_stage(stage, cleanup=True):
koder aka kdanilov39e449e2016-12-17 15:15:26 +0200379 stage.cleanup(ctx)
380 except:
381 cleanup_failed = True
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200382 ctx.storage.sync()
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300383
koder aka kdanilov39e449e2016-12-17 15:15:26 +0200384 if not failed:
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300385 for report_stage in report_stages:
386 with log_stage(report_stage):
koder aka kdanilovffaf48d2016-12-27 02:25:29 +0200387 try:
388 report_stage.run(ctx)
389 except utils.StopTestError:
390 logger.error("Report stage %s requested stop execution", report_stage.name())
391 failed = True
392 break
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300393
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200394 ctx.storage.sync()
395
koder aka kdanilov22d134e2016-11-08 11:33:19 +0200396 logger.info("All info is stored into %r", config.storage_url)
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300397
koder aka kdanilov39e449e2016-12-17 15:15:26 +0200398 if failed or cleanup_failed:
koder aka kdanilov22d134e2016-11-08 11:33:19 +0200399 logger.error("Tests are failed. See error details in log above")
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300400 return 1
koder aka kdanilov39e449e2016-12-17 15:15:26 +0200401 else:
402 logger.info("Tests finished successfully")
403 return 0