From c31158e2f7f1b8530ba3f6b87ceea92b4bf53877 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Wed, 8 Apr 2020 23:39:11 +0000 Subject: [PATCH] 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 --- nodepool/cmd/config_validator.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/nodepool/cmd/config_validator.py b/nodepool/cmd/config_validator.py index ae2c2ad86..a5ef265d8 100644 --- a/nodepool/cmd/config_validator.py +++ b/nodepool/cmd/config_validator.py @@ -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()