config_validator: refactor the schema to a static method

This change moves the top_level schema to a static method so that
it can be used externally.

Change-Id: Ifa4849e3de7731957b90130e080bf3331be44fa9
This commit is contained in:
Tristan Cacqueray 2020-04-08 23:39:11 +00:00
parent 2779a61a10
commit c31158e2f7
1 changed files with 12 additions and 10 deletions

View File

@ -26,14 +26,8 @@ class ConfigValidator:
def __init__(self, config_file):
self.config_file = config_file
def validate(self):
'''
Validate a configuration file
:return: 0 for success, non-zero for failure
'''
provider = ProviderConfig.getCommonSchemaDict()
@staticmethod
def getSchema():
label = {
'name': str,
'min-ready': int,
@ -77,6 +71,15 @@ class ConfigValidator:
'diskimages': [diskimage],
'max-hold-age': int,
}
return v.Schema(top_level)
def validate(self):
'''
Validate a configuration file
:return: 0 for success, non-zero for failure
'''
provider = ProviderConfig.getCommonSchemaDict()
log.info("validating %s" % self.config_file)
@ -89,8 +92,7 @@ class ConfigValidator:
try:
# validate the overall schema
schema = v.Schema(top_level)
schema(config)
ConfigValidator.getSchema()(config)
for provider_dict in config.get('providers', []):
provider_schema = \
get_provider_config(provider_dict).getSchema()