Initial formatting run with Black. Integration tests and unit tests pass before and after this change.

This commit is contained in:
Pim van Pelt
2022-04-22 13:05:55 +00:00
parent b375ddb433
commit baaaaa67b5
22 changed files with 1757 additions and 1178 deletions

View File

@ -15,42 +15,43 @@ import logging
import config.interface as interface
import ipaddress
def get_by_name(yaml, ifname):
""" Return the VXLAN by name, if it exists. Return None otherwise. """
"""Return the VXLAN by name, if it exists. Return None otherwise."""
try:
if ifname in yaml['vxlan_tunnels']:
return ifname, yaml['vxlan_tunnels'][ifname]
if ifname in yaml["vxlan_tunnels"]:
return ifname, yaml["vxlan_tunnels"][ifname]
except:
pass
return None, None
def is_vxlan_tunnel(yaml, ifname):
""" Returns True if the interface name is an existing VXLAN Tunnel. """
"""Returns True if the interface name is an existing VXLAN Tunnel."""
ifname, iface = get_by_name(yaml, ifname)
return not iface == None
def vni_unique(yaml, vni):
""" Return True if the VNI is unique amongst all VXLANs """
if not 'vxlan_tunnels' in yaml:
"""Return True if the VNI is unique amongst all VXLANs"""
if not "vxlan_tunnels" in yaml:
return True
ncount = 0
for ifname, iface in yaml['vxlan_tunnels'].items():
if iface['vni'] == vni:
for ifname, iface in yaml["vxlan_tunnels"].items():
if iface["vni"] == vni:
ncount = ncount + 1
return ncount < 2
def get_vxlan_tunnels(yaml):
""" Returns a list of all VXLAN tunnel interface names. """
"""Returns a list of all VXLAN tunnel interface names."""
ret = []
if not 'vxlan_tunnels' in yaml:
if not "vxlan_tunnels" in yaml:
return ret
for ifname, iface in yaml['vxlan_tunnels'].items():
for ifname, iface in yaml["vxlan_tunnels"].items():
ret.append(ifname)
return ret
@ -58,27 +59,31 @@ def get_vxlan_tunnels(yaml):
def validate_vxlan_tunnels(yaml):
result = True
msgs = []
logger = logging.getLogger('vppcfg.config')
logger = logging.getLogger("vppcfg.config")
logger.addHandler(logging.NullHandler())
if not 'vxlan_tunnels' in yaml:
if not "vxlan_tunnels" in yaml:
return result, msgs
for ifname, iface in yaml['vxlan_tunnels'].items():
for ifname, iface in yaml["vxlan_tunnels"].items():
logger.debug(f"vxlan_tunnel {ifname}: {iface}")
instance = int(ifname[12:])
if instance > 2147483647:
msgs.append(f"vxlan_tunnel {ifname} has instance {int(instance)} which is too large")
msgs.append(
f"vxlan_tunnel {ifname} has instance {int(instance)} which is too large"
)
result = False
vni = iface['vni']
vni = iface["vni"]
if not vni_unique(yaml, vni):
msgs.append(f"vxlan_tunnel {ifname} VNI {int(vni)} is not unique")
result = False
local = ipaddress.ip_address(iface['local'])
remote = ipaddress.ip_address(iface['remote'])
local = ipaddress.ip_address(iface["local"])
remote = ipaddress.ip_address(iface["remote"])
if local.version != remote.version:
msgs.append(f"vxlan_tunnel {ifname} local and remote are not the same address family")
msgs.append(
f"vxlan_tunnel {ifname} local and remote are not the same address family"
)
result = False
return result, msgs