Only pass 'schema' to the validator creation.

This commit is contained in:
Pim van Pelt
2022-03-13 16:48:52 +00:00
parent 0313666f69
commit 881c0faaab
6 changed files with 14 additions and 14 deletions

View File

@ -50,21 +50,21 @@ class NullHandler(logging.Handler):
class Validator(object):
def __init__(self, args):
def __init__(self, schema):
self.logger = logging.getLogger('vppcfg.validator')
self.logger.addHandler(NullHandler())
self.args = args
self.schema = schema
def validate(self, yaml):
ret_rv = True
ret_msgs = []
if self.args.schema:
if self.schema:
try:
self.logger.info("Validating against schema %s" % self.args.schema)
self.logger.info("Validating against schema %s" % self.schema)
validators = DefaultValidators.copy()
validators[IPInterfaceWithPrefixLength.tag] = IPInterfaceWithPrefixLength
schema = yamale.make_schema(self.args.schema, validators=validators)
schema = yamale.make_schema(self.schema, validators=validators)
data = yamale.make_data(content=str(yaml))
yamale.validate(schema, data)
self.logger.debug("Schema correctly validated by yamale")
@ -79,25 +79,25 @@ class Validator(object):
self.logger.debug("Validating Semantics...")
rv, msgs = validate_bondethernets(self.args, yaml)
rv, msgs = validate_bondethernets(yaml)
if msgs:
ret_msgs.extend(msgs)
if not rv:
ret_rv = False
rv, msgs = validate_interfaces(self.args, yaml)
rv, msgs = validate_interfaces(yaml)
if msgs:
ret_msgs.extend(msgs)
if not rv:
ret_rv = False
rv, msgs = validate_loopbacks(self.args, yaml)
rv, msgs = validate_loopbacks(yaml)
if msgs:
ret_msgs.extend(msgs)
if not rv:
ret_rv = False
rv, msgs = validate_bridgedomains(self.args, yaml)
rv, msgs = validate_bridgedomains(yaml)
if msgs:
ret_msgs.extend(msgs)
if not rv:

View File

@ -16,7 +16,7 @@ def get_by_name(yaml, ifname):
return None
def validate_bondethernets(args, yaml):
def validate_bondethernets(yaml):
result = True
msgs = []
logger = logging.getLogger('vppcfg.validator')

View File

@ -16,7 +16,7 @@ def get_by_name(yaml, ifname):
return None
def validate_bridgedomains(args, yaml):
def validate_bridgedomains(yaml):
result = True
msgs = []
logger = logging.getLogger('vppcfg.validator')

View File

@ -259,7 +259,7 @@ def get_mtu(yaml, ifname):
return 1500
def validate_interfaces(args, yaml):
def validate_interfaces(yaml):
result = True
msgs = []
logger = logging.getLogger('vppcfg.validator')

View File

@ -14,7 +14,7 @@ def get_by_name(yaml, ifname):
return None
def validate_loopbacks(args, yaml):
def validate_loopbacks(yaml):
result = True
msgs = []
logger = logging.getLogger('vppcfg.validator')

2
vppcfg
View File

@ -34,7 +34,7 @@ def main():
logging.error("Couldn't read config from %s" % args.config)
sys.exit(-1)
v = Validator(args)
v = Validator(schema=args.schema)
rv, msgs = v.validate(cfg)
if not rv:
for m in msgs: