blob: 09a245072a46fbcd0dde1f775a62465ff5809f67 [file] [log] [blame]
Dennis Dmitriev4174e1e2019-04-12 13:50:16 +03001#!/usr/bin/env python
2
3import os
4import sys
5
6from heatclient.common import template_utils
7
8
9if 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
17sys.path.append(os.getcwd())
18try:
19 from tcp_tests import settings_oslo
20except 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
26config = settings_oslo.load_config([])
27
28template_file = config.hardware.heat_conf_path
29env_file = config.hardware.heat_env_path
30
31if 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
36tpl_files, template = template_utils.get_template_contents(
37 template_file)
38
39if 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))
45else:
46 env = {}
47
48parameter_name = sys.argv[1]
49parameter_value = env['parameter_defaults'].get(parameter_name)
50if parameter_value is None:
Dennis Dmitriev4ec96222019-05-30 13:00:37 +030051 parameter_template = template['parameters'].get(parameter_name, {})
52 parameter_value = parameter_template.get('default')
Dennis Dmitriev4174e1e2019-04-12 13:50:16 +030053 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
58print(parameter_value)