move deliverable schema checking into its own command
We've run into problems because we weren't maintaining older deliverable files as we extended the schema. This change moves schema validation out of the main validation command so it runs as a separate step and processes all deliverable files by default. The more complex validation rules are still only checked for files being modified in a given commit. Change-Id: I4b69ca3c59da6606cf2b27d05c8846223d52998a Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
5cbf743595
commit
6fca7a1f07
98
openstack_releases/cmds/check_schema.py
Normal file
98
openstack_releases/cmds/check_schema.py
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
"""Verify that all deliverable files match the schema.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import glob
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import os.path
|
||||||
|
import pkgutil
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import jsonschema
|
||||||
|
|
||||||
|
from openstack_releases import yamlutils
|
||||||
|
|
||||||
|
_SCHEMA = yamlutils.loads(
|
||||||
|
pkgutil.get_data('openstack_releases', 'schema.yaml').decode('utf-8')
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument(
|
||||||
|
'--debug',
|
||||||
|
default=False,
|
||||||
|
action='store_true',
|
||||||
|
help='throw exception on error',
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'input',
|
||||||
|
nargs='*',
|
||||||
|
help=('YAML files to validate, defaults to '
|
||||||
|
'files changed in the latest commit'),
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# Set up logging, including making some loggers quiet.
|
||||||
|
logging.basicConfig(
|
||||||
|
format='%(levelname)7s: %(message)s',
|
||||||
|
stream=sys.stdout,
|
||||||
|
level=logging.DEBUG,
|
||||||
|
)
|
||||||
|
logging.getLogger('urllib3.connectionpool').setLevel(logging.WARNING)
|
||||||
|
log = logging.getLogger('')
|
||||||
|
|
||||||
|
filenames = args.input or sorted(glob.glob('deliverables/*/*.yaml'))
|
||||||
|
|
||||||
|
errors = []
|
||||||
|
warnings = []
|
||||||
|
|
||||||
|
for filename in filenames:
|
||||||
|
log.info('Checking %s', filename)
|
||||||
|
if not os.path.isfile(filename):
|
||||||
|
log.info("File was deleted, skipping.")
|
||||||
|
continue
|
||||||
|
with open(filename, 'r', encoding='utf-8') as f:
|
||||||
|
deliverable_info = yamlutils.loads(f.read())
|
||||||
|
|
||||||
|
def mk_warning(msg):
|
||||||
|
log.warning(msg)
|
||||||
|
warnings.append('{}: {}'.format(filename, msg))
|
||||||
|
|
||||||
|
def mk_error(msg):
|
||||||
|
log.error(msg)
|
||||||
|
errors.append('{}: {}'.format(filename, msg))
|
||||||
|
if args.debug:
|
||||||
|
raise RuntimeError(msg)
|
||||||
|
|
||||||
|
validator = jsonschema.Draft4Validator(_SCHEMA)
|
||||||
|
for error in validator.iter_errors(deliverable_info):
|
||||||
|
mk_error(str(error))
|
||||||
|
|
||||||
|
print('\n\n%s warnings found' % len(warnings))
|
||||||
|
for w in warnings:
|
||||||
|
print(w)
|
||||||
|
|
||||||
|
print('\n\n%s errors found' % len(errors))
|
||||||
|
for e in errors:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
return 1 if errors else 0
|
@ -24,13 +24,11 @@ import glob
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import pkgutil
|
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
import jsonschema
|
|
||||||
import requests
|
import requests
|
||||||
import six
|
import six
|
||||||
|
|
||||||
@ -95,9 +93,6 @@ _NO_STABLE_BRANCH_CHECK = set([
|
|||||||
])
|
])
|
||||||
_PLEASE = ('It is too expensive to determine this value during '
|
_PLEASE = ('It is too expensive to determine this value during '
|
||||||
'the site build, please set it explicitly.')
|
'the site build, please set it explicitly.')
|
||||||
_SCHEMA = yamlutils.loads(
|
|
||||||
pkgutil.get_data('openstack_releases', 'schema.yaml').decode('utf-8')
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def header(title):
|
def header(title):
|
||||||
@ -110,13 +105,6 @@ def is_a_hash(val):
|
|||||||
return re.search('^[a-f0-9]{40}$', val, re.I) is not None
|
return re.search('^[a-f0-9]{40}$', val, re.I) is not None
|
||||||
|
|
||||||
|
|
||||||
def validate_schema(deliverable_info, mk_warning, mk_error):
|
|
||||||
header('Validate Schema')
|
|
||||||
validator = jsonschema.Draft4Validator(_SCHEMA)
|
|
||||||
for error in validator.iter_errors(deliverable_info):
|
|
||||||
mk_error(str(error))
|
|
||||||
|
|
||||||
|
|
||||||
def validate_series_open(deliverable_info,
|
def validate_series_open(deliverable_info,
|
||||||
series_name, filename,
|
series_name, filename,
|
||||||
mk_warning, mk_error):
|
mk_warning, mk_error):
|
||||||
@ -1308,7 +1296,6 @@ def main():
|
|||||||
raise RuntimeError(msg)
|
raise RuntimeError(msg)
|
||||||
|
|
||||||
clone_deliverable(deliverable_info, workdir, mk_warning, mk_error)
|
clone_deliverable(deliverable_info, workdir, mk_warning, mk_error)
|
||||||
validate_schema(deliverable_info, mk_warning, mk_error)
|
|
||||||
validate_bugtracker(deliverable_info, mk_warning, mk_error)
|
validate_bugtracker(deliverable_info, mk_warning, mk_error)
|
||||||
validate_team(deliverable_info, team_data, mk_warning, mk_error)
|
validate_team(deliverable_info, team_data, mk_warning, mk_error)
|
||||||
validate_release_notes(deliverable_info, mk_warning, mk_error)
|
validate_release_notes(deliverable_info, mk_warning, mk_error)
|
||||||
|
@ -40,6 +40,7 @@ console_scripts =
|
|||||||
edit-deliverable = openstack_releases.cmds.edit_deliverable:main
|
edit-deliverable = openstack_releases.cmds.edit_deliverable:main
|
||||||
send-mail = openstack_releases.cmds.mail:main
|
send-mail = openstack_releases.cmds.mail:main
|
||||||
release-notes = openstack_releases.cmds.release_notes:main
|
release-notes = openstack_releases.cmds.release_notes:main
|
||||||
|
check-schema = openstack_releases.cmds.check_schema:main
|
||||||
|
|
||||||
[extras]
|
[extras]
|
||||||
sphinxext =
|
sphinxext =
|
||||||
|
1
tox.ini
1
tox.ini
@ -24,6 +24,7 @@ deps =
|
|||||||
yamllint==1.4.1
|
yamllint==1.4.1
|
||||||
commands =
|
commands =
|
||||||
{toxinidir}/tools/tox-log-command.sh {toxinidir}/tools/run_yamllint.sh
|
{toxinidir}/tools/tox-log-command.sh {toxinidir}/tools/run_yamllint.sh
|
||||||
|
{toxinidir}/tools/tox-log-command.sh check-schema {posargs}
|
||||||
{toxinidir}/tools/tox-log-command.sh validate-request {posargs}
|
{toxinidir}/tools/tox-log-command.sh validate-request {posargs}
|
||||||
|
|
||||||
[testenv:list-changes]
|
[testenv:list-changes]
|
||||||
|
Loading…
Reference in New Issue
Block a user