Add jsonschema and validation script
Define the structure of the documents and also provide a way to validate incoming patches against it. (The setup.py and setup.cfg are there just to empower tox to run the test script) Change-Id: I819c2df1c7c9081bd6f51caae1e4f3794275abaa
This commit is contained in:
parent
41b82757d6
commit
29adc6e29b
|
@ -0,0 +1,4 @@
|
|||
AUTHORS
|
||||
ChangeLog
|
||||
*.egg-info
|
||||
.tox
|
|
@ -24,6 +24,9 @@ Each service dictionary should contain a top level dictionary with a key
|
|||
If either min_version or max_version are given, they both must be given. If
|
||||
the service does not have microversions, they should be omitted.
|
||||
|
||||
This is also expressed in jsonschema form in the file `schema.json` in this
|
||||
repository.
|
||||
|
||||
.. _API WG document: https://specs.openstack.org/openstack/api-wg/guidelines/microversion_specification.html#version-discovery
|
||||
|
||||
Process Description
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"id": "https://git.openstack.org/cgit/openstack/project-navigator-data/plain/schema.json#",
|
||||
"type": "object",
|
||||
"required": ["versions"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"versions": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/version"
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"version": {
|
||||
"properties": {
|
||||
"status": {
|
||||
"type": "string",
|
||||
"enum": ["CURRENT", "SUPPORTED", "DEPRECATED"]
|
||||
},
|
||||
"id": {
|
||||
"type": "string",
|
||||
"pattern": "^v[0-9]{1,2}.?[0-9]{0,2}$"
|
||||
},
|
||||
"max_version": {
|
||||
"type": "string",
|
||||
"pattern": "^[0-9]{1,2}.[0-9]{1,2}$"
|
||||
},
|
||||
"min_version": {
|
||||
"type": "string",
|
||||
"pattern": "^[0-9]{1,2}.[0-9]{1,2}$"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"reqiured": ["status", "id"]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
[metadata]
|
||||
name = project_navigator_data
|
||||
summary = Data for OpenStack Project Navigator
|
||||
description-file =
|
||||
README.rst
|
||||
author = OpenStack
|
||||
author-email = openstack-dev@lists.openstack.org
|
||||
home-page = http://git.openstack.org/cgit/openstack/project-navigator-data
|
||||
classifier =
|
||||
Environment :: OpenStack
|
||||
Intended Audience :: Information Technology
|
||||
Intended Audience :: System Administrators
|
||||
License :: OSI Approved :: Apache Software License
|
||||
Operating System :: POSIX :: Linux
|
||||
|
||||
[egg_info]
|
||||
tag_build =
|
||||
tag_date = 0
|
||||
tag_svn_revision = 0
|
||||
|
||||
[wheel]
|
||||
universal = 1
|
||||
|
||||
[pbr]
|
||||
# Treat sphinx warnings as errors during the docs build; this helps us keep
|
||||
# the documentation clean.
|
||||
warnerrors = true
|
|
@ -0,0 +1,29 @@
|
|||
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# 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.
|
||||
|
||||
# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT
|
||||
import setuptools
|
||||
|
||||
# In python < 2.7.4, a lazy loading of package `pbr` will break
|
||||
# setuptools if some other modules registered functions in `atexit`.
|
||||
# solution from: http://bugs.python.org/issue15881#msg170215
|
||||
try:
|
||||
import multiprocessing # noqa
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['pbr>=1.8'],
|
||||
pbr=True)
|
|
@ -0,0 +1,24 @@
|
|||
[tox]
|
||||
minversion = 1.6
|
||||
envlist = pep8,validate
|
||||
skipdist = True
|
||||
|
||||
[testenv]
|
||||
install_command = pip install -U {opts} {packages}
|
||||
setenv =
|
||||
VIRTUAL_ENV={envdir}
|
||||
basepython = python3
|
||||
|
||||
[testenv:validate]
|
||||
deps = jsonschema
|
||||
commands =
|
||||
python validate.py
|
||||
|
||||
[testenv:pep8]
|
||||
deps = hacking
|
||||
commands = flake8
|
||||
|
||||
[flake8]
|
||||
show-source = True
|
||||
builtins = _
|
||||
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build
|
|
@ -0,0 +1,50 @@
|
|||
# Copyright (c) 2017 Red Hat, Inc.
|
||||
#
|
||||
# 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 json
|
||||
import os
|
||||
import sys
|
||||
|
||||
import jsonschema
|
||||
|
||||
_return = 0
|
||||
|
||||
|
||||
def validate_release(release, validator):
|
||||
global _return
|
||||
data = json.load(open(release, 'r'))
|
||||
for error in validator.iter_errors(data):
|
||||
print("{filename}: {message}".format(
|
||||
filename=release, message=error.message))
|
||||
_return = 1
|
||||
|
||||
|
||||
def walk_releases(arg, dirname, fnames):
|
||||
for fname in fnames:
|
||||
validate_release(os.path.join(dirname, fname), arg)
|
||||
|
||||
|
||||
def main():
|
||||
global _return
|
||||
schema = json.load(open('schema.json', 'r'))
|
||||
validator = jsonschema.Draft4Validator(schema)
|
||||
for (dirpath, dirnames, filenames) in os.walk('releases'):
|
||||
for fname in filenames:
|
||||
validate_release(os.path.join(dirpath, fname), validator)
|
||||
return _return
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
Loading…
Reference in New Issue