Dennis Dmitriev | efe5c0b | 2018-10-24 20:35:26 +0300 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import argparse |
| 4 | import os |
| 5 | import sys |
| 6 | import time |
| 7 | |
| 8 | sys.path.append(os.getcwd()) |
| 9 | try: |
| 10 | from tcp_tests.fixtures import config_fixtures |
| 11 | from tcp_tests.managers import underlay_ssh_manager |
| 12 | except 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 | |
| 19 | def 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 | |
| 36 | def 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 | |
| 53 | if __name__ == '__main__': |
| 54 | sys.exit(main()) |