blob: 38ed4950bc740b8209e6340d0ea63f82424383f0 [file] [log] [blame]
#!/usr/bin/env python
import argparse
import json
import sys
import jsonschema
r"""
Validates the phosphor-regulators configuration file. Checks it against a JSON
schema as well as doing some extra checks that can't be encoded in the schema.
"""
def validate_schema(config, schema):
r"""
Validates the specified config file using the specified
schema file.
config: Path of the file containing the config JSON
schema: Path of the file containing the schema JSON
"""
with open(config) as config_handle:
config_json = json.load(config_handle)
with open(schema) as schema_handle:
schema_json = json.load(schema_handle)
try:
jsonschema.validate(config_json, schema_json)
except jsonschema.ValidationError as e:
print(e)
sys.exit("Validation failed.")
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='phosphor-regulators configuration file validator')
parser.add_argument('-s', '--schema-file', dest='schema_file',
help='The phosphor-regulators schema file')
parser.add_argument('-c', '--configuration-file', dest='configuration_file',
help='The phosphor-regulators configuration file')
args = parser.parse_args()
if not args.schema_file:
parser.print_help()
sys.exit("Error: Schema file is required.")
if not args.configuration_file:
parser.print_help()
sys.exit("Error: Configuration file is required.")
validate_schema(args.configuration_file, args.schema_file)