blob: 225f9d70ea66c5d4d2b479755040fcbd654e0351 [file] [log] [blame]
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +03001#!/usr/bin/env python
2
3import argparse
4import os
5import sys
6import time
7
8sys.path.append(os.getcwd())
9try:
10 from tcp_tests.fixtures import config_fixtures
11 from tcp_tests.managers import underlay_ssh_manager
12except ImportError:
13 print("ImportError: Run the application from the tcp-qa directory or "
14 "set the PYTHONPATH environment variable to directory which contains"
15 " ./tcp_tests")
16 sys.exit(1)
17
18
19def load_params():
20 """
21 Parse CLI arguments and environment variables
22
23 Returns: ArgumentParser instance
24 """
25 parser = argparse.ArgumentParser(description=(
26 'Download logs and debug info from salt minions'
27 ))
28 default_name_prefix = 'logs_' + time.strftime("%Y%m%d_%H%M%S")
29 parser.add_argument('--archive-name-prefix',
30 help=('Custom prefix for creating archive name'),
31 default=default_name_prefix,
32 type=str)
33 return parser
34
35
36def main():
37 parser = load_params()
38 opts = parser.parse_args()
39
40 tests_configs = os.environ.get('TESTS_CONFIGS', None)
41 if not tests_configs or not os.path.isfile(tests_configs):
42 print("Download logs and debug info from salt minions. "
43 "Please set TESTS_CONFIGS environment variable whith"
44 "the path to INI file with lab metadata.")
45 return 11
46
47 config = config_fixtures.config()
48 underlay = underlay_ssh_manager.UnderlaySSHManager(config)
49
50 underlay.get_logs(opts.archive_name_prefix)
51
52
53if __name__ == '__main__':
54 sys.exit(main())