
- Adds bashate test using v0.6.0 - Bump pre-commit-hooks release to v2.2.4 - Bump ansible-lint release to v4.1.0a0 - Fix some minor flake8 errors Change-Id: I66b796fab1d8651163226febbc4e99648a9ecc6a Signed-off-by: Gael Chamoulaud <gchamoul@redhat.com>
147 lines
4.5 KiB
Python
147 lines
4.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# 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.
|
|
|
|
from glob import glob
|
|
import os
|
|
|
|
import yaml
|
|
|
|
DEFAULT_METADATA = {
|
|
'name': 'Unnamed',
|
|
'description': 'No description',
|
|
'groups': [],
|
|
}
|
|
|
|
|
|
def get_validation_metadata(validation, key):
|
|
try:
|
|
return validation['vars']['metadata'][key]
|
|
except KeyError:
|
|
return DEFAULT_METADATA.get(key)
|
|
|
|
|
|
def get_include_role(validation):
|
|
try:
|
|
if 'tasks' in validation:
|
|
return validation['tasks'][0]['include_role']['name']
|
|
else:
|
|
return validation['roles'][0]
|
|
except KeyError:
|
|
return list()
|
|
|
|
|
|
def get_remaining_metadata(validation):
|
|
try:
|
|
return {k: v for k, v in validation['vars']['metadata'].items()
|
|
if k not in ['name', 'description', 'groups']}
|
|
except KeyError:
|
|
return dict()
|
|
|
|
|
|
def get_validation_parameters(validation):
|
|
try:
|
|
return {k: v for k, v in validation['vars'].items()
|
|
if k != 'metadata'}
|
|
except KeyError:
|
|
return dict()
|
|
|
|
|
|
def build_summary(group, validations):
|
|
entries = [
|
|
"* :ref:`{}`: {}".format(group + '_' + validation['id'],
|
|
validation['name'])
|
|
for validation in validations
|
|
]
|
|
with open('doc/source/validations-{}.rst'.format(group), 'w') as f:
|
|
f.write("\n".join(entries))
|
|
f.write("\n")
|
|
|
|
|
|
def format_dict(my_dict):
|
|
return ''.join(['\n\n - **{}**: {}'.format(key, value)
|
|
for key, value in my_dict.items()])
|
|
|
|
|
|
def build_detail(group, validations):
|
|
entries = ['{}\n{}\n'.format(group, len(group) * '=')]
|
|
entries = entries + [
|
|
""".. _{label}:
|
|
|
|
{title}
|
|
{adornment}
|
|
|
|
{name}.
|
|
|
|
{desc}
|
|
|
|
- **hosts**: {hosts}
|
|
- **groups**: {groups}
|
|
- **parameters**:{parameters}
|
|
- **roles**: {roles}
|
|
|
|
Role documentation
|
|
|
|
.. toctree::
|
|
|
|
roles/role-{roles}
|
|
|
|
"""
|
|
.format(label=(group + '_' + validation['id']),
|
|
title=validation['id'],
|
|
adornment=(len(validation['id']) * '-'),
|
|
name=validation['name'],
|
|
desc=validation['description'],
|
|
groups=', '.join(validation['groups']),
|
|
metadata=format_dict(validation['metadata']),
|
|
hosts=validation['hosts'],
|
|
parameters=format_dict(validation['parameters']),
|
|
roles=validation['roles']
|
|
)
|
|
for validation in validations]
|
|
with open('doc/source/validations-{}-details.rst'.format(group), 'w') as f:
|
|
f.write("\n".join(entries))
|
|
|
|
|
|
def setup(app):
|
|
# Seed it with the known groups:
|
|
groups = set(('no-op', 'prep', 'pre-introspection',
|
|
'pre-deployment', 'post-deployment',
|
|
'pre-update', 'pre-upgrade',
|
|
'post-upgrade', 'openshift-on-openstack'))
|
|
validations = []
|
|
for validation_path in sorted(glob('playbooks/*.yaml')):
|
|
with open(validation_path) as f:
|
|
loaded_validation = yaml.safe_load(f.read())[0]
|
|
for group in get_validation_metadata(loaded_validation, 'groups'):
|
|
groups.add(group)
|
|
validations.append({
|
|
'hosts': loaded_validation['hosts'],
|
|
'parameters': get_validation_parameters(loaded_validation),
|
|
'id': os.path.splitext(
|
|
os.path.basename(validation_path))[0],
|
|
'name': get_validation_metadata(loaded_validation, 'name'),
|
|
'groups': get_validation_metadata(loaded_validation, 'groups'),
|
|
'description': get_validation_metadata(loaded_validation,
|
|
'description'),
|
|
'metadata': get_remaining_metadata(loaded_validation),
|
|
'roles': get_include_role(loaded_validation)
|
|
})
|
|
|
|
for group in groups:
|
|
validations_in_group = [validation for validation
|
|
in validations
|
|
if group in validation['groups']]
|
|
build_detail(group, validations_in_group)
|
|
build_summary(group, validations_in_group)
|