Dennis Dmitriev | 3ec2e53 | 2018-06-08 04:33:34 +0300 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import argparse |
| 4 | import os |
| 5 | import sys |
| 6 | |
| 7 | sys.path.append(os.getcwd()) |
| 8 | try: |
| 9 | from tcp_tests.fixtures import config_fixtures |
| 10 | from tcp_tests.managers import underlay_ssh_manager |
| 11 | from tcp_tests.managers import execute_commands |
| 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 | 'Run commands from yaml templates' |
| 27 | )) |
| 28 | parser.add_argument('path_to_template', |
| 29 | help='Path to YAML template') |
| 30 | parser.add_argument('--template-steps-label', |
| 31 | help=('Text that will be shown as steps label'), |
| 32 | default='', |
| 33 | type=str) |
| 34 | |
| 35 | return parser |
| 36 | |
| 37 | |
| 38 | def main(): |
| 39 | """Create fuel-devops environment from template""" |
| 40 | parser = load_params() |
| 41 | opts = parser.parse_args() |
| 42 | |
| 43 | if opts.path_to_template is None: |
| 44 | parser.print_help() |
| 45 | return 10 |
| 46 | |
| 47 | path = os.path.abspath(opts.path_to_template) |
| 48 | label = opts.template_steps_label |
| 49 | if not label: |
| 50 | label = os.path.basename(path).split('.')[0] |
| 51 | |
| 52 | config = config_fixtures.config() |
| 53 | underlay = underlay_ssh_manager.UnderlaySSHManager(config) |
| 54 | |
| 55 | commands = underlay.read_template(path) |
| 56 | |
| 57 | commander = execute_commands.ExecuteCommandsMixin(config, underlay) |
| 58 | commander.execute_commands(commands, label=label) |
| 59 | |
| 60 | |
| 61 | if __name__ == '__main__': |
| 62 | sys.exit(main()) |