Add a clouds.yaml checker
Load our various cloud configuration files into openstacksdk for a basic sanity check of the configuration. Change-Id: Ieedb3439533f3162d2b5cecca4b7fc07b631019e
This commit is contained in:
parent
c807245d8b
commit
19ed6637b6
@ -7,3 +7,4 @@ oslosphinx>=4.7.0 # Apache-2.0
|
|||||||
bashate>=0.2 # Apache-2.0
|
bashate>=0.2 # Apache-2.0
|
||||||
PyYAML>=3.10.0 # MIT
|
PyYAML>=3.10.0 # MIT
|
||||||
ansible-lint
|
ansible-lint
|
||||||
|
openstacksdk
|
||||||
|
58
tools/check_clouds_yaml.py
Normal file
58
tools/check_clouds_yaml.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#! /usr/bin/env python
|
||||||
|
|
||||||
|
# Copyright 2018 Red Hat
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import openstack
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
FILES_TO_CHECK = (
|
||||||
|
'modules/openstack_project/templates/nodepool/clouds.yaml.erb',
|
||||||
|
'modules/openstack_project/templates/puppetmaster/all-clouds.yaml.erb',
|
||||||
|
'modules/openstack_project/templates/puppetmaster/ansible-clouds.yaml.erb'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def check_files():
|
||||||
|
|
||||||
|
with tempfile.TemporaryDirectory() as tempdir:
|
||||||
|
for file in FILES_TO_CHECK:
|
||||||
|
# These are actually erb files that have templating in
|
||||||
|
# them, we just rewrite them with a string in there for
|
||||||
|
# the parser to read, as the <>'s can confuse yaml
|
||||||
|
# depending on how they're quoted in the file
|
||||||
|
temp = open(os.path.join(tempdir,
|
||||||
|
os.path.basename(file)), 'w')
|
||||||
|
in_file = open(file, 'r')
|
||||||
|
for line in in_file:
|
||||||
|
line = re.sub(r'<%.*%>', 'loremipsum', line)
|
||||||
|
temp.write(line)
|
||||||
|
temp.close()
|
||||||
|
|
||||||
|
try:
|
||||||
|
print("Checking parsing of %s" % file)
|
||||||
|
c = openstack.config.OpenStackConfig(config_files=[temp.name])
|
||||||
|
except Exception as e:
|
||||||
|
print("Error parsing : %s" % file)
|
||||||
|
print(e)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
check_files()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
6
tox.ini
6
tox.ini
@ -9,12 +9,14 @@ install_command = pip install {opts} {packages}
|
|||||||
deps = -r{toxinidir}/test-requirements.txt
|
deps = -r{toxinidir}/test-requirements.txt
|
||||||
|
|
||||||
[testenv:linters]
|
[testenv:linters]
|
||||||
|
basepython = python3
|
||||||
whitelist_externals = bash
|
whitelist_externals = bash
|
||||||
commands =
|
commands =
|
||||||
flake8
|
flake8
|
||||||
{toxinidir}/tools/run-bashate.sh
|
{toxinidir}/tools/run-bashate.sh
|
||||||
python {toxinidir}/tools/sorted_modules_env.py {toxinidir}/modules.env
|
python3 {toxinidir}/tools/sorted_modules_env.py {toxinidir}/modules.env
|
||||||
python {toxinidir}/tools/irc_checks.py
|
python3 {toxinidir}/tools/irc_checks.py
|
||||||
|
python3 {toxinidir}/tools/check_clouds_yaml.py
|
||||||
# Ansible Lint Check
|
# Ansible Lint Check
|
||||||
bash -c "find playbooks -type f -regex '.*.y[a]?ml' -print0 | xargs -t -n1 -0 \
|
bash -c "find playbooks -type f -regex '.*.y[a]?ml' -print0 | xargs -t -n1 -0 \
|
||||||
ansible-lint -x ANSIBLE0004 -x ANSIBLE0006 -x ANSIBLE0007 -x ANSIBLE0011 \
|
ansible-lint -x ANSIBLE0004 -x ANSIBLE0006 -x ANSIBLE0007 -x ANSIBLE0011 \
|
||||||
|
Loading…
Reference in New Issue
Block a user