Disable blocking on buildable queue (Functest)
[releng.git] / releases / scripts / verify_schema.py
1 #!/usr/bin/env python2
2 # SPDX-License-Identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018 The Linux Foundation and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 """
11 Verify YAML Schema
12 """
13 import argparse
14 import logging
15 import jsonschema
16 import yaml
17
18 LOADER = yaml.CSafeLoader if yaml.__with_libyaml__ else yaml.SafeLoader
19
20
21 def main():
22     """
23     Parse arguments and verify YAML
24     """
25     logging.basicConfig(level=logging.INFO)
26
27     parser = argparse.ArgumentParser()
28     parser.add_argument('--yaml', '-y', type=str, required=True)
29     parser.add_argument('--schema', '-s', type=str, required=True)
30
31     args = parser.parse_args()
32
33     with open(args.yaml) as _:
34         yaml_file = yaml.load(_, Loader=LOADER)
35
36     with open(args.schema) as _:
37         schema_file = yaml.load(_, Loader=LOADER)
38
39     # Load the schema
40     validation = jsonschema.Draft4Validator(
41         schema_file,
42         format_checker=jsonschema.FormatChecker()
43     )
44
45     # Look for errors
46     errors = 0
47     for error in validation.iter_errors(yaml_file):
48         errors += 1
49         logging.error(error)
50     if errors > 0:
51         raise RuntimeError("%d issues invalidate the release schema" % errors)
52
53
54 if __name__ == "__main__":
55     main()