Merge "config_validator: refactor the schema to a static method"

This commit is contained in:
Zuul 2020-04-16 03:15:28 +00:00 committed by Gerrit Code Review
commit 4c521fd208

View File

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