add jsonschema

Use jsonschema to define the valid structure of a deliverables file.
Retain the custom logic for some of the more complex rules we have
relating values and checking types.

Change-Id: I5dc87445c505ebd978b4c1d59171217a2fe047c7
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2017-05-31 12:47:15 -04:00
parent 80c49657a6
commit 305843fae3
3 changed files with 85 additions and 0 deletions

View File

@ -23,10 +23,12 @@ import atexit
import glob
import os
import os.path
import pkgutil
import re
import shutil
import tempfile
import jsonschema
import requests
import six
import yaml
@ -73,6 +75,9 @@ _NO_STABLE_BRANCH_CHECK = set([
])
_PLEASE = ('It is too expensive to determine this value during '
'the site build, please set it explicitly.')
_SCHEMA = yaml.load(
pkgutil.get_data('openstack_releases', 'schema.yaml').decode('utf-8')
)
def is_a_hash(val):
@ -80,6 +85,12 @@ def is_a_hash(val):
return re.search('^[a-f0-9]{40}$', val, re.I) is not None
def validate_schema(deliverable_info, mk_warning, mk_error):
validator = jsonschema.Draft4Validator(_SCHEMA)
for error in validator.iter_errors(deliverable_info):
mk_error(str(error))
def validate_series_open(deliverable_info,
series_name, filename,
mk_warning, mk_error):
@ -807,6 +818,7 @@ def main():
print('ERROR: {}'.format(msg))
errors.append('{}: {}'.format(filename, msg))
validate_schema(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_release_notes(deliverable_info, mk_warning, mk_error)

View File

@ -0,0 +1,72 @@
---
$schema: "http://json-schema.org/schema#"
$id: "http://git.openstack.org/cgit/openstack/releases/tree/README.rst"
# Do not allow any properties not defined here. This lets us catch
# typos.
additionalProperties: false
properties:
team:
type: "string"
launchpad:
type: "string"
storyboard:
type: "integer"
release-notes:
oneOf:
- type: "string"
# We don't include any details about the object form of the
# release notes because the keys are the repository names.
- type: "object"
include-pypi-link:
type: "boolean"
release-model:
type: "string"
enum: ["cycle-with-intermediary", "cycle-with-milestones", "cycle-trailing"]
type:
type: "string"
enum: ["horizon-plugin", "library", "service", "other"]
artifact-link-mode:
type: "string"
enum: ["tarball", "none"]
repository-settings:
# TODO(dhellmann): Need to expand this to handle the flags.
type: "object"
release-type:
type: "string"
enum: [ "std", "xstatic", "fuel" ]
stable-branch-type:
type: "string"
enum: [ "std", "tagless" ]
releases:
type: "array"
items:
type: "object"
properties:
version:
type: "string"
projects:
type: "array"
items:
type: "object"
properties:
repo:
type: "string"
hash:
type: "string"
highlights:
type: "string"
tarball-base:
type: "string"
branches:
type: "array"
items:
type: "object"
properties:
name:
type: "string"
location:
oneOf:
- type: "string"
- type: "object"

View File

@ -12,3 +12,4 @@ prompt_toolkit
tqdm
packaging>=15.2
mwclient==0.8.1
jsonschema>=2.6.0