add jsonschema validation for project data

This change adds a tool to perform basic JSONSchema validation of the
reference/projects.yaml file.

Change-Id: I28ff94af37d7f4de07c1d282bf3c37c77eeea101
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
Co-Authored-by: Zane Bitter <zbitter@redhat.com>
This commit is contained in:
Doug Hellmann 2019-07-30 15:18:00 -04:00 committed by Zane Bitter
parent b24d958367
commit 96e8407730
5 changed files with 150 additions and 2 deletions

View File

@ -0,0 +1,47 @@
# 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 data files match the schema."""
import argparse
import pkgutil
import jsonschema
from openstack_governance import yamltools
_yaml = yamltools.YAML()
_PROJECTS_SCHEMA = _yaml.load(
pkgutil.get_data('openstack_governance',
'projects_schema.yaml').decode('utf-8')
)
def main():
parser = argparse.ArgumentParser()
parser.parse_args()
errors = []
with open('reference/projects.yaml', 'r', encoding='utf-8') as f:
all_projects = _yaml.load(f.read())
validator = jsonschema.Draft4Validator(_PROJECTS_SCHEMA)
errors = False
for e in validator.iter_errors(all_projects):
errors = True
print(e)
return 1 if errors else 0

View File

@ -0,0 +1,95 @@
---
$schema: "http://json-schema.org/schema#"
$id: "https://opendev.org/openstack/releases/src/branch/master/README.rst"
additionalProperties:
# Do not allow any properties not defined here. This lets us catch
# typos.
additionalProperties: false
required:
- ptl
- deliverables
properties:
ptl:
type: "object"
required:
- name
- email
additionalProperties: false
properties:
name:
type: "string"
irc:
type: "string"
email:
type: "string"
format: "email"
appointed:
type: "array"
items:
type: "string"
irc-channel:
type: "string"
service:
type: "string"
url:
type: "string"
liaisons:
type: "array"
uniqueItems: true
items:
type: "string"
mission:
type: "string"
deliverables:
type: "object"
additionalProperties:
type: "object"
required:
- repos
additionalProperties: false
properties:
repos:
type: "array"
items:
type: "string"
pattern: "^[^/]+/[^/]+$"
minItems: 1
uniqueItems: true
tags:
type: "array"
items:
type: "string"
release-management:
type: "string"
enum:
- none
- deprecated
- external
tags:
type: "array"
items:
type: "string"
extra-atcs:
type: "array"
items:
type: "object"
required:
- name
- email
- expires-in
additionalProperties: false
properties:
name:
type: "string"
email:
type: "string"
format: "email"
expires-in:
type: "string"
pattern: >-
^(January |February |March |April |May |June |July |August
|September |October |November |December )2[0-9]{3}$
comment:
type: "string"

View File

@ -7,3 +7,4 @@ six>=1.9.0
yamlordereddictloader yamlordereddictloader
mwclient==0.8.1 mwclient==0.8.1
ruamel.yaml ruamel.yaml
jsonschema>=2.6.0

View File

@ -23,3 +23,7 @@ warnerrors = True
[flake8] [flake8]
ignore = E501,E226,H405 ignore = E501,E226,H405
[entry_points]
console_scripts =
osg-check-schema = openstack_governance._check_schema:main

View File

@ -27,6 +27,7 @@ commands =
basepython = python3 basepython = python3
whitelist_externals = bash whitelist_externals = bash
commands = commands =
osg-check-schema
bash -c "find {toxinidir} \ bash -c "find {toxinidir} \
\( -name .tox -prune \) \ \( -name .tox -prune \) \
-o -type f -name '*.yaml' \ -o -type f -name '*.yaml' \