Clean up logging a little bit

This commit is contained in:
Pim van Pelt
2022-03-24 12:14:26 +00:00
parent b43d7903fd
commit 8129235031
9 changed files with 32 additions and 51 deletions

View File

@ -60,15 +60,10 @@ class IPInterfaceWithPrefixLength(Validator):
class NullHandler(logging.Handler):
def emit(self, record):
pass
class Validator(object):
def __init__(self, schema):
self.logger = logging.getLogger('vppcfg.validator')
self.logger.addHandler(NullHandler())
self.logger.addHandler(logging.NullHandler())
self.schema = schema
@ -131,3 +126,19 @@ class Validator(object):
if ret_rv:
self.logger.debug("Semantics correctly validated")
return ret_rv, ret_msgs
def valid_config(self, yaml):
""" Validate the given YAML configuration in 'yaml' against syntax
validation given in the yamale 'schema', and all semantic validators.
Returns True if the configuration is valid, False otherwise.
"""
rv, msgs = self.validate(yaml)
if not rv:
for m in msgs:
self.logger.error(m)
return False
self.logger.info("Configuration validated successfully")
return True