Add pep8 check that generated environments are up to date
This check ensures that if a parameter is changed that would affect a generated environment then the environment must be updated before pep8 will pass. It will also catch any mistaken hand edits to the generated files. bp generated-environments Change-Id: I2d12992ed55f963285422e1282a4cee06e989b6d
This commit is contained in:
parent
e10dd12cef
commit
1c9553c37a
27
tools/check-up-to-date.sh
Executable file
27
tools/check-up-to-date.sh
Executable file
@ -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
|
1
tox.ini
1
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
|
||||
|
@ -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 [<filename.yaml> | <directory>]' % sys.argv[0])
|
||||
print('Usage: %s [<filename.yaml> | <directory>] [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__':
|
||||
|
Loading…
Reference in New Issue
Block a user