From 1e8577e858bb5a54144db1d1fdf0e4ac9c1c19b0 Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Fri, 20 Jul 2018 17:14:48 -0500 Subject: [PATCH] Don't require files key in env-generator We have environments that are exclusively resource_registry entries, and we shouldn't have to include a dummy files: key to make that work with the generator. Change-Id: I8ffabb5e583aabbfa4f2f22a4418783c857118fa --- .../environment_generator.py | 2 +- .../tests/test_environment_generator.py | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tripleo_heat_templates/environment_generator.py b/tripleo_heat_templates/environment_generator.py index 818e74b851..dbbac01a95 100755 --- a/tripleo_heat_templates/environment_generator.py +++ b/tripleo_heat_templates/environment_generator.py @@ -82,7 +82,7 @@ def _generate_environment(input_env, output_path, parent_env=None): param_names = defaultdict(list) sample_values = env.get('sample_values', {}) static_names = env.get('static', []) - for template_file, template_data in env['files'].items(): + for template_file, template_data in env.get('files', {}).items(): with open(template_file) as f: f_data = yaml.safe_load(f) f_params = f_data['parameters'] diff --git a/tripleo_heat_templates/tests/test_environment_generator.py b/tripleo_heat_templates/tests/test_environment_generator.py index 8dc174947e..d6e15285c9 100644 --- a/tripleo_heat_templates/tests/test_environment_generator.py +++ b/tripleo_heat_templates/tests/test_environment_generator.py @@ -698,6 +698,25 @@ parameter_defaults: # ********************* # End static parameters # ********************* +''', + }), + ('no-files', + {'template': basic_template, + 'exception': None, + 'nested_output': '', + 'input_file': '''environments: + - + name: basic + title: Basic Environment + description: Basic description + resource_registry: + foo: bar +''', + 'expected_output': '''# title: Basic Environment +# description: | +# Basic description +resource_registry: + foo: bar ''', }), ] @@ -715,6 +734,9 @@ parameter_defaults: with mock.patch('tripleo_heat_templates.environment_generator.open', create=True) as mock_open: mock_se = [fake_input, fake_template, fake_output] + if 'files:' not in self.input_file: + # No files were specified so that open call won't happen + mock_se.remove(fake_template) if self.nested_output: _, fake_nested_output_path = tempfile.mkstemp() fake_nested_output = open(fake_nested_output_path, 'w')