diff --git a/tools/check-up-to-date.sh b/tools/check-up-to-date.sh new file mode 100755 index 0000000000..bb5bed1fb7 --- /dev/null +++ b/tools/check-up-to-date.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Report an error if the generated sample environments are not in sync with +# the current configuration and templates. + +echo 'Verifying that generated environments are in sync' + +tmpdir=$(mktemp -d) +trap "rm -rf $tmpdir" EXIT + +./tripleo_heat_templates/environment_generator.py sample-env-generator/ $tmpdir/environments + +base=$PWD +retval=0 + +cd $tmpdir + +file_list=$(find environments -type f) +for f in $file_list; do + if ! diff -q $f $base/$f; then + echo "ERROR: $base/$f is not up to date" + diff $f $base/$f + retval=1 + fi +done + +exit $retval diff --git a/tox.ini b/tox.ini index da179e91d4..78b6c4b645 100644 --- a/tox.ini +++ b/tox.ini @@ -21,6 +21,7 @@ commands = python ./network/endpoints/build_endpoint_map.py --check python ./tools/yaml-validate.py . bash -c ./tools/roles-data-validation.sh + bash -c ./tools/check-up-to-date.sh [testenv:templates] commands = python ./tools/process-templates.py diff --git a/tripleo_heat_templates/environment_generator.py b/tripleo_heat_templates/environment_generator.py index e13690dd10..e3e1e4023a 100755 --- a/tripleo_heat_templates/environment_generator.py +++ b/tripleo_heat_templates/environment_generator.py @@ -64,7 +64,7 @@ def _create_output_dir(target_file): raise -def _generate_environment(input_env, parent_env=None): +def _generate_environment(input_env, output_path, parent_env=None): if parent_env is None: parent_env = {} env = dict(parent_env) @@ -145,7 +145,7 @@ def _generate_environment(input_env, parent_env=None): } f.write(_PARAM_FORMAT % values + '\n') - target_file = os.path.join('environments', env['name'] + '.yaml') + target_file = os.path.join(output_path, env['name'] + '.yaml') _create_output_dir(target_file) with open(target_file, 'w') as env_file: env_file.write(_FILE_HEADER) @@ -177,10 +177,10 @@ def _generate_environment(input_env, parent_env=None): print('Wrote sample environment "%s"' % target_file) for e in env.get('children', []): - _generate_environment(e, env) + _generate_environment(e, output_path, env) -def generate_environments(config_path): +def generate_environments(config_path, output_path): if os.path.isdir(config_path): config_files = os.listdir(config_path) config_files = [os.path.join(config_path, i) for i in config_files @@ -192,11 +192,12 @@ def generate_environments(config_path): with open(config_file) as f: config = yaml.safe_load(f) for env in config['environments']: - _generate_environment(env) + _generate_environment(env, output_path) def usage(exit_code=1): - print('Usage: %s [ | ]' % sys.argv[0]) + print('Usage: %s [ | ] [output path]' % sys.argv[0]) + print('Output path is optional and defaults to "environments"') sys.exit(exit_code) @@ -205,7 +206,12 @@ def main(): config_path = sys.argv[1] except IndexError: usage() - generate_environments(config_path) + if len(sys.argv) > 2: + output_path = sys.argv[2] + else: + output_path = 'environments' + print('Writing output to %s' % output_path) + generate_environments(config_path, output_path) if __name__ == '__main__':