Dennis Dmitriev | 4174e1e | 2019-04-12 13:50:16 +0300 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import os |
| 4 | import sys |
| 5 | |
| 6 | from heatclient.common import template_utils |
| 7 | |
| 8 | |
| 9 | if len(sys.argv) <= 1: |
| 10 | print("Usage:\n" |
| 11 | " export LAB_CONFIG_NAME=cookied-cicd-... " |
| 12 | "# see directories in tcp_tests/templates/\n" |
| 13 | " export LAB_PARAM_DEFAULTS=nnnn.env " |
| 14 | "# see files in tcp_tests/templates/_heat_environments") |
| 15 | sys.exit(1) |
| 16 | |
| 17 | sys.path.append(os.getcwd()) |
| 18 | try: |
| 19 | from tcp_tests import settings_oslo |
| 20 | except ImportError: |
| 21 | print("ImportError: Run the application from the tcp-qa directory or " |
| 22 | "set the PYTHONPATH environment variable to directory which contains" |
| 23 | " ./tcp_tests") |
| 24 | sys.exit(1) |
| 25 | |
| 26 | config = settings_oslo.load_config([]) |
| 27 | |
| 28 | template_file = config.hardware.heat_conf_path |
| 29 | env_file = config.hardware.heat_env_path |
| 30 | |
| 31 | if not os.path.exists(template_file): |
| 32 | raise Exception("Heat template '{0}' not found!\n" |
| 33 | "Please set the correct LAB_CONFIG_NAME with underlay.hot" |
| 34 | .format(template_file)) |
| 35 | |
| 36 | tpl_files, template = template_utils.get_template_contents( |
| 37 | template_file) |
| 38 | |
| 39 | if os.path.exists(env_file): |
| 40 | env_files_list = [] |
| 41 | env_files, env = ( |
| 42 | template_utils.process_multiple_environments_and_files( |
| 43 | env_paths=[env_file], |
| 44 | env_list_tracker=env_files_list)) |
| 45 | else: |
| 46 | env = {} |
| 47 | |
| 48 | parameter_name = sys.argv[1] |
| 49 | parameter_value = env['parameter_defaults'].get(parameter_name) |
| 50 | if parameter_value is None: |
Dennis Dmitriev | 4ec9622 | 2019-05-30 13:00:37 +0300 | [diff] [blame] | 51 | parameter_template = template['parameters'].get(parameter_name, {}) |
| 52 | parameter_value = parameter_template.get('default') |
Dennis Dmitriev | 4174e1e | 2019-04-12 13:50:16 +0300 | [diff] [blame] | 53 | if parameter_value is None: |
| 54 | raise Exception("Parameter '{0}' not found in env file '{1}' " |
| 55 | "and temlate file '{2}'" |
| 56 | .format(parameter_name, env_file, template_file)) |
| 57 | |
| 58 | print(parameter_value) |