Rename validator/ to config/
This commit is contained in:
@ -25,17 +25,17 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
print("ERROR: install yamale manually: sudo pip install yamale")
|
print("ERROR: install yamale manually: sudo pip install yamale")
|
||||||
sys.exit(-2)
|
sys.exit(-2)
|
||||||
from validator.loopback import validate_loopbacks
|
from config.loopback import validate_loopbacks
|
||||||
from validator.bondethernet import validate_bondethernets
|
from config.bondethernet import validate_bondethernets
|
||||||
from validator.interface import validate_interfaces
|
from config.interface import validate_interfaces
|
||||||
from validator.bridgedomain import validate_bridgedomains
|
from config.bridgedomain import validate_bridgedomains
|
||||||
from validator.vxlan_tunnel import validate_vxlan_tunnels
|
from config.vxlan_tunnel import validate_vxlan_tunnels
|
||||||
|
|
||||||
from yamale.validators import DefaultValidators, Validator
|
from yamale.validators import DefaultValidators, Validator
|
||||||
import ipaddress
|
import ipaddress
|
||||||
|
|
||||||
class IPInterfaceWithPrefixLength(Validator):
|
class IPInterfaceWithPrefixLength(Validator):
|
||||||
""" Custom IPAddress validator - takes IP/prefixlen as input:
|
""" Custom IPAddress config - takes IP/prefixlen as input:
|
||||||
192.0.2.1/29 or 2001:db8::1/64 are correct. The PrefixLength
|
192.0.2.1/29 or 2001:db8::1/64 are correct. The PrefixLength
|
||||||
is required, and must be a number (0-32 for IPv4 and 0-128 for
|
is required, and must be a number (0-32 for IPv4 and 0-128 for
|
||||||
IPv6).
|
IPv6).
|
||||||
@ -62,7 +62,7 @@ class IPInterfaceWithPrefixLength(Validator):
|
|||||||
|
|
||||||
class Validator(object):
|
class Validator(object):
|
||||||
def __init__(self, schema):
|
def __init__(self, schema):
|
||||||
self.logger = logging.getLogger('vppcfg.validator')
|
self.logger = logging.getLogger('vppcfg.config')
|
||||||
self.logger.addHandler(logging.NullHandler())
|
self.logger.addHandler(logging.NullHandler())
|
||||||
|
|
||||||
self.schema = schema
|
self.schema = schema
|
||||||
@ -129,7 +129,7 @@ class Validator(object):
|
|||||||
|
|
||||||
def valid_config(self, yaml):
|
def valid_config(self, yaml):
|
||||||
""" Validate the given YAML configuration in 'yaml' against syntax
|
""" Validate the given YAML configuration in 'yaml' against syntax
|
||||||
validation given in the yamale 'schema', and all semantic validators.
|
validation given in the yamale 'schema', and all semantic configs.
|
||||||
|
|
||||||
Returns True if the configuration is valid, False otherwise.
|
Returns True if the configuration is valid, False otherwise.
|
||||||
"""
|
"""
|
@ -12,7 +12,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
import logging
|
import logging
|
||||||
import validator.interface as interface
|
import config.interface as interface
|
||||||
import ipaddress
|
import ipaddress
|
||||||
|
|
||||||
def get_all_addresses_except_ifname(yaml, except_ifname):
|
def get_all_addresses_except_ifname(yaml, except_ifname):
|
@ -12,7 +12,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
import logging
|
import logging
|
||||||
import validator.interface as interface
|
import config.interface as interface
|
||||||
|
|
||||||
def get_by_name(yaml, ifname):
|
def get_by_name(yaml, ifname):
|
||||||
""" Return the BondEthernet by name, if it exists. Return None,None otherwise. """
|
""" Return the BondEthernet by name, if it exists. Return None,None otherwise. """
|
||||||
@ -46,7 +46,7 @@ def is_bond_member(yaml, ifname):
|
|||||||
def validate_bondethernets(yaml):
|
def validate_bondethernets(yaml):
|
||||||
result = True
|
result = True
|
||||||
msgs = []
|
msgs = []
|
||||||
logger = logging.getLogger('vppcfg.validator')
|
logger = logging.getLogger('vppcfg.config')
|
||||||
logger.addHandler(logging.NullHandler())
|
logger.addHandler(logging.NullHandler())
|
||||||
|
|
||||||
if not 'bondethernets' in yaml:
|
if not 'bondethernets' in yaml:
|
@ -12,9 +12,9 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
import logging
|
import logging
|
||||||
import validator.interface as interface
|
import config.interface as interface
|
||||||
import validator.lcp as lcp
|
import config.lcp as lcp
|
||||||
import validator.address as address
|
import config.address as address
|
||||||
|
|
||||||
def get_bridgedomains(yaml):
|
def get_bridgedomains(yaml):
|
||||||
""" Return a list of all bridgedomains. """
|
""" Return a list of all bridgedomains. """
|
||||||
@ -88,7 +88,7 @@ def is_bridge_interface(yaml, ifname):
|
|||||||
def validate_bridgedomains(yaml):
|
def validate_bridgedomains(yaml):
|
||||||
result = True
|
result = True
|
||||||
msgs = []
|
msgs = []
|
||||||
logger = logging.getLogger('vppcfg.validator')
|
logger = logging.getLogger('vppcfg.config')
|
||||||
logger.addHandler(logging.NullHandler())
|
logger.addHandler(logging.NullHandler())
|
||||||
|
|
||||||
if not 'bridgedomains' in yaml:
|
if not 'bridgedomains' in yaml:
|
@ -12,12 +12,12 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
import logging
|
import logging
|
||||||
import validator.bondethernet as bondethernet
|
import config.bondethernet as bondethernet
|
||||||
import validator.bridgedomain as bridgedomain
|
import config.bridgedomain as bridgedomain
|
||||||
import validator.loopback as loopback
|
import config.loopback as loopback
|
||||||
import validator.vxlan_tunnel as vxlan_tunnel
|
import config.vxlan_tunnel as vxlan_tunnel
|
||||||
import validator.lcp as lcp
|
import config.lcp as lcp
|
||||||
import validator.address as address
|
import config.address as address
|
||||||
|
|
||||||
def get_qinx_parent_by_name(yaml, ifname):
|
def get_qinx_parent_by_name(yaml, ifname):
|
||||||
""" Returns the sub-interface which matches a QinAD or QinQ outer tag, or None,None
|
""" Returns the sub-interface which matches a QinAD or QinQ outer tag, or None,None
|
||||||
@ -384,7 +384,7 @@ def get_mtu(yaml, ifname):
|
|||||||
def validate_interfaces(yaml):
|
def validate_interfaces(yaml):
|
||||||
result = True
|
result = True
|
||||||
msgs = []
|
msgs = []
|
||||||
logger = logging.getLogger('vppcfg.validator')
|
logger = logging.getLogger('vppcfg.config')
|
||||||
logger.addHandler(logging.NullHandler())
|
logger.addHandler(logging.NullHandler())
|
||||||
|
|
||||||
if not 'interfaces' in yaml:
|
if not 'interfaces' in yaml:
|
@ -12,8 +12,8 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
import logging
|
import logging
|
||||||
import validator.lcp as lcp
|
import config.lcp as lcp
|
||||||
import validator.address as address
|
import config.address as address
|
||||||
|
|
||||||
def get_loopbacks(yaml):
|
def get_loopbacks(yaml):
|
||||||
""" Return a list of all loopbacks. """
|
""" Return a list of all loopbacks. """
|
||||||
@ -43,7 +43,7 @@ def is_loopback(yaml, ifname):
|
|||||||
def validate_loopbacks(yaml):
|
def validate_loopbacks(yaml):
|
||||||
result = True
|
result = True
|
||||||
msgs = []
|
msgs = []
|
||||||
logger = logging.getLogger('vppcfg.validator')
|
logger = logging.getLogger('vppcfg.config')
|
||||||
logger.addHandler(logging.NullHandler())
|
logger.addHandler(logging.NullHandler())
|
||||||
|
|
||||||
if not 'loopbacks' in yaml:
|
if not 'loopbacks' in yaml:
|
@ -1,6 +1,6 @@
|
|||||||
import unittest
|
import unittest
|
||||||
import yaml
|
import yaml
|
||||||
import validator.bondethernet as bondethernet
|
import config.bondethernet as bondethernet
|
||||||
|
|
||||||
class TestBondEthernetMethods(unittest.TestCase):
|
class TestBondEthernetMethods(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
@ -1,6 +1,6 @@
|
|||||||
import unittest
|
import unittest
|
||||||
import yaml
|
import yaml
|
||||||
import validator.bridgedomain as bridgedomain
|
import config.bridgedomain as bridgedomain
|
||||||
|
|
||||||
class TestBridgeDomainMethods(unittest.TestCase):
|
class TestBridgeDomainMethods(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
@ -1,6 +1,6 @@
|
|||||||
import unittest
|
import unittest
|
||||||
import yaml
|
import yaml
|
||||||
import validator.interface as interface
|
import config.interface as interface
|
||||||
|
|
||||||
class TestInterfaceMethods(unittest.TestCase):
|
class TestInterfaceMethods(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
@ -1,7 +1,7 @@
|
|||||||
import unittest
|
import unittest
|
||||||
import yaml
|
import yaml
|
||||||
import validator.lcp as lcp
|
import config.lcp as lcp
|
||||||
import validator.interface as interface
|
import config.interface as interface
|
||||||
|
|
||||||
class TestLCPMethods(unittest.TestCase):
|
class TestLCPMethods(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
@ -1,6 +1,6 @@
|
|||||||
import unittest
|
import unittest
|
||||||
import yaml
|
import yaml
|
||||||
import validator.loopback as loopback
|
import config.loopback as loopback
|
||||||
|
|
||||||
class TestLoopbackMethods(unittest.TestCase):
|
class TestLoopbackMethods(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
@ -1,6 +1,6 @@
|
|||||||
import unittest
|
import unittest
|
||||||
import yaml
|
import yaml
|
||||||
import validator.vxlan_tunnel as vxlan_tunnel
|
import config.vxlan_tunnel as vxlan_tunnel
|
||||||
|
|
||||||
class TestVXLANMethods(unittest.TestCase):
|
class TestVXLANMethods(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
@ -12,7 +12,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
import logging
|
import logging
|
||||||
import validator.interface as interface
|
import config.interface as interface
|
||||||
import ipaddress
|
import ipaddress
|
||||||
|
|
||||||
def get_by_name(yaml, ifname):
|
def get_by_name(yaml, ifname):
|
||||||
@ -58,7 +58,7 @@ def get_vxlan_tunnels(yaml):
|
|||||||
def validate_vxlan_tunnels(yaml):
|
def validate_vxlan_tunnels(yaml):
|
||||||
result = True
|
result = True
|
||||||
msgs = []
|
msgs = []
|
||||||
logger = logging.getLogger('vppcfg.validator')
|
logger = logging.getLogger('vppcfg.config')
|
||||||
logger.addHandler(logging.NullHandler())
|
logger.addHandler(logging.NullHandler())
|
||||||
|
|
||||||
if not 'vxlan_tunnels' in yaml:
|
if not 'vxlan_tunnels' in yaml:
|
2
tests.py
2
tests.py
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import yaml
|
import yaml
|
||||||
from validator import Validator
|
from config import Validator
|
||||||
import glob
|
import glob
|
||||||
import re
|
import re
|
||||||
import unittest
|
import unittest
|
||||||
|
8
vppcfg
8
vppcfg
@ -17,7 +17,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import yaml
|
import yaml
|
||||||
import logging
|
import logging
|
||||||
from validator import Validator
|
from config import Validator
|
||||||
from vpp.vppapi import VPPApi
|
from vpp.vppapi import VPPApi
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -52,12 +52,12 @@ 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)
|
||||||
|
|
||||||
validator = Validator(schema=args.schema)
|
config = Validator(schema=args.schema)
|
||||||
if not validator.valid_config(cfg):
|
if not config.valid_config(cfg):
|
||||||
logging.error("Configuration is not valid, bailing")
|
logging.error("Configuration is not valid, bailing")
|
||||||
sys.exit(-2)
|
sys.exit(-2)
|
||||||
|
|
||||||
config_phys = validator.get_phys(cfg)
|
config_phys = config.get_phys(cfg)
|
||||||
vpp = VPPApi()
|
vpp = VPPApi()
|
||||||
vpp.readconfig()
|
vpp.readconfig()
|
||||||
if not vpp.phys_exist(config_phys):
|
if not vpp.phys_exist(config_phys):
|
||||||
|
Reference in New Issue
Block a user