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

View File

@ -14,11 +14,6 @@
import logging
import validator.interface as interface
class NullHandler(logging.Handler):
def emit(self, record):
pass
def get_by_name(yaml, ifname):
""" Return the BondEthernet by name, if it exists. Return None,None otherwise. """
try:
@ -52,7 +47,7 @@ def validate_bondethernets(yaml):
result = True
msgs = []
logger = logging.getLogger('vppcfg.validator')
logger.addHandler(NullHandler())
logger.addHandler(logging.NullHandler())
if not 'bondethernets' in yaml:
return result, msgs

View File

@ -16,11 +16,6 @@ import validator.interface as interface
import validator.lcp as lcp
import validator.address as address
class NullHandler(logging.Handler):
def emit(self, record):
pass
def get_bridgedomains(yaml):
""" Return a list of all bridgedomains. """
ret = []
@ -94,7 +89,7 @@ def validate_bridgedomains(yaml):
result = True
msgs = []
logger = logging.getLogger('vppcfg.validator')
logger.addHandler(NullHandler())
logger.addHandler(logging.NullHandler())
if not 'bridgedomains' in yaml:
return result, msgs

View File

@ -19,10 +19,6 @@ import validator.vxlan_tunnel as vxlan_tunnel
import validator.lcp as lcp
import validator.address as address
class NullHandler(logging.Handler):
def emit(self, record):
pass
def get_qinx_parent_by_name(yaml, ifname):
""" Returns the sub-interface which matches a QinAD or QinQ outer tag, or None,None
if that sub-interface doesn't exist. """
@ -389,7 +385,7 @@ def validate_interfaces(yaml):
result = True
msgs = []
logger = logging.getLogger('vppcfg.validator')
logger.addHandler(NullHandler())
logger.addHandler(logging.NullHandler())
if not 'interfaces' in yaml:
return result, msgs

View File

@ -15,10 +15,6 @@ import logging
import validator.lcp as lcp
import validator.address as address
class NullHandler(logging.Handler):
def emit(self, record):
pass
def get_loopbacks(yaml):
""" Return a list of all loopbacks. """
ret = []
@ -48,7 +44,7 @@ def validate_loopbacks(yaml):
result = True
msgs = []
logger = logging.getLogger('vppcfg.validator')
logger.addHandler(NullHandler())
logger.addHandler(logging.NullHandler())
if not 'loopbacks' in yaml:
return result, msgs

View File

@ -15,11 +15,6 @@ import logging
import validator.interface as interface
import ipaddress
class NullHandler(logging.Handler):
def emit(self, record):
pass
def get_by_name(yaml, ifname):
""" Return the VXLAN by name, if it exists. Return None otherwise. """
try:
@ -64,7 +59,7 @@ def validate_vxlan_tunnels(yaml):
result = True
msgs = []
logger = logging.getLogger('vppcfg.validator')
logger.addHandler(NullHandler())
logger.addHandler(logging.NullHandler())
if not 'vxlan_tunnels' in yaml:
return result, msgs