Only pass 'schema' to the validator creation.
This commit is contained in:
@ -50,21 +50,21 @@ class NullHandler(logging.Handler):
|
|||||||
|
|
||||||
|
|
||||||
class Validator(object):
|
class Validator(object):
|
||||||
def __init__(self, args):
|
def __init__(self, schema):
|
||||||
self.logger = logging.getLogger('vppcfg.validator')
|
self.logger = logging.getLogger('vppcfg.validator')
|
||||||
self.logger.addHandler(NullHandler())
|
self.logger.addHandler(NullHandler())
|
||||||
|
|
||||||
self.args = args
|
self.schema = schema
|
||||||
|
|
||||||
def validate(self, yaml):
|
def validate(self, yaml):
|
||||||
ret_rv = True
|
ret_rv = True
|
||||||
ret_msgs = []
|
ret_msgs = []
|
||||||
if self.args.schema:
|
if self.schema:
|
||||||
try:
|
try:
|
||||||
self.logger.info("Validating against schema %s" % self.args.schema)
|
self.logger.info("Validating against schema %s" % self.schema)
|
||||||
validators = DefaultValidators.copy()
|
validators = DefaultValidators.copy()
|
||||||
validators[IPInterfaceWithPrefixLength.tag] = IPInterfaceWithPrefixLength
|
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))
|
data = yamale.make_data(content=str(yaml))
|
||||||
yamale.validate(schema, data)
|
yamale.validate(schema, data)
|
||||||
self.logger.debug("Schema correctly validated by yamale")
|
self.logger.debug("Schema correctly validated by yamale")
|
||||||
@ -79,25 +79,25 @@ class Validator(object):
|
|||||||
|
|
||||||
self.logger.debug("Validating Semantics...")
|
self.logger.debug("Validating Semantics...")
|
||||||
|
|
||||||
rv, msgs = validate_bondethernets(self.args, yaml)
|
rv, msgs = validate_bondethernets(yaml)
|
||||||
if msgs:
|
if msgs:
|
||||||
ret_msgs.extend(msgs)
|
ret_msgs.extend(msgs)
|
||||||
if not rv:
|
if not rv:
|
||||||
ret_rv = False
|
ret_rv = False
|
||||||
|
|
||||||
rv, msgs = validate_interfaces(self.args, yaml)
|
rv, msgs = validate_interfaces(yaml)
|
||||||
if msgs:
|
if msgs:
|
||||||
ret_msgs.extend(msgs)
|
ret_msgs.extend(msgs)
|
||||||
if not rv:
|
if not rv:
|
||||||
ret_rv = False
|
ret_rv = False
|
||||||
|
|
||||||
rv, msgs = validate_loopbacks(self.args, yaml)
|
rv, msgs = validate_loopbacks(yaml)
|
||||||
if msgs:
|
if msgs:
|
||||||
ret_msgs.extend(msgs)
|
ret_msgs.extend(msgs)
|
||||||
if not rv:
|
if not rv:
|
||||||
ret_rv = False
|
ret_rv = False
|
||||||
|
|
||||||
rv, msgs = validate_bridgedomains(self.args, yaml)
|
rv, msgs = validate_bridgedomains(yaml)
|
||||||
if msgs:
|
if msgs:
|
||||||
ret_msgs.extend(msgs)
|
ret_msgs.extend(msgs)
|
||||||
if not rv:
|
if not rv:
|
||||||
|
@ -16,7 +16,7 @@ def get_by_name(yaml, ifname):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def validate_bondethernets(args, yaml):
|
def validate_bondethernets(yaml):
|
||||||
result = True
|
result = True
|
||||||
msgs = []
|
msgs = []
|
||||||
logger = logging.getLogger('vppcfg.validator')
|
logger = logging.getLogger('vppcfg.validator')
|
||||||
|
@ -16,7 +16,7 @@ def get_by_name(yaml, ifname):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def validate_bridgedomains(args, yaml):
|
def validate_bridgedomains(yaml):
|
||||||
result = True
|
result = True
|
||||||
msgs = []
|
msgs = []
|
||||||
logger = logging.getLogger('vppcfg.validator')
|
logger = logging.getLogger('vppcfg.validator')
|
||||||
|
@ -259,7 +259,7 @@ def get_mtu(yaml, ifname):
|
|||||||
return 1500
|
return 1500
|
||||||
|
|
||||||
|
|
||||||
def validate_interfaces(args, yaml):
|
def validate_interfaces(yaml):
|
||||||
result = True
|
result = True
|
||||||
msgs = []
|
msgs = []
|
||||||
logger = logging.getLogger('vppcfg.validator')
|
logger = logging.getLogger('vppcfg.validator')
|
||||||
|
@ -14,7 +14,7 @@ def get_by_name(yaml, ifname):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def validate_loopbacks(args, yaml):
|
def validate_loopbacks(yaml):
|
||||||
result = True
|
result = True
|
||||||
msgs = []
|
msgs = []
|
||||||
logger = logging.getLogger('vppcfg.validator')
|
logger = logging.getLogger('vppcfg.validator')
|
||||||
|
2
vppcfg
2
vppcfg
@ -34,7 +34,7 @@ def main():
|
|||||||
logging.error("Couldn't read config from %s" % args.config)
|
logging.error("Couldn't read config from %s" % args.config)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
v = Validator(args)
|
v = Validator(schema=args.schema)
|
||||||
rv, msgs = v.validate(cfg)
|
rv, msgs = v.validate(cfg)
|
||||||
if not rv:
|
if not rv:
|
||||||
for m in msgs:
|
for m in msgs:
|
||||||
|
Reference in New Issue
Block a user