From 76e951436cea70ce6a1c95648b3e5549a0475a7d Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Wed, 16 Jan 2019 13:34:14 -0600 Subject: [PATCH] Add pep8 check that generated environments are current Like the tripleo-heat-templates commit 1c9553c37ab9f121cb4a74274496067312e9b65e Change-Id: I684c941f8a4e1322d8ed361c9d8bab18724dfe51 --- bin/check-up-to-date.sh | 28 ++++++++++++++++++++++++++++ bin/environment-generator.py | 14 ++++++++------ tox.ini | 5 ++++- 3 files changed, 40 insertions(+), 7 deletions(-) create mode 100755 bin/check-up-to-date.sh mode change 100644 => 100755 bin/environment-generator.py diff --git a/bin/check-up-to-date.sh b/bin/check-up-to-date.sh new file mode 100755 index 0000000..8ac7522 --- /dev/null +++ b/bin/check-up-to-date.sh @@ -0,0 +1,28 @@ +#!/bin/bash +set -e + +# 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 + +./bin/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/bin/environment-generator.py b/bin/environment-generator.py old mode 100644 new mode 100755 index 2baf518..026096f --- a/bin/environment-generator.py +++ b/bin/environment-generator.py @@ -77,7 +77,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) @@ -167,7 +167,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) @@ -202,10 +202,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 @@ -217,7 +217,7 @@ 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 generate_index(index_path): @@ -237,6 +237,8 @@ def _parse_args(): parser.add_argument('config_path', help='Filename or directory containing the sample ' 'environment definitions.') + parser.add_argument('output_path', + help='Location to write generated files.') parser.add_argument('--index', help='Specify the output path for an index file ' 'listing all the generated environments. ' @@ -247,7 +249,7 @@ def _parse_args(): def main(): args = _parse_args() - generate_environments(args.config_path) + generate_environments(args.config_path, args.output_path) if args.index: generate_index(args.index) diff --git a/tox.ini b/tox.ini index dbf7db7..998088f 100644 --- a/tox.ini +++ b/tox.ini @@ -23,7 +23,10 @@ commands = sphinx-build -W -b html doc/source doc/build/html [testenv:pep8] deps = flake8 -commands = flake8 +whitelist_externals = bash +commands = + flake8 + bash -c bin/check-up-to-date.sh [testenv:cover] basepython = python3