Assert that all PHYs in the config also exist in VPP
This commit is contained in:
@ -142,3 +142,7 @@ class Validator(object):
|
|||||||
|
|
||||||
self.logger.info("Configuration validated successfully")
|
self.logger.info("Configuration validated successfully")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def get_phys(self, yaml):
|
||||||
|
""" Return all PHYs in the config """
|
||||||
|
return interface.get_phys(yaml)
|
||||||
|
@ -60,7 +60,7 @@ class VPPApi():
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def clearconfig(self):
|
def clearconfig(self):
|
||||||
return {"lcps": {}, "interfaces": {}, "interface_addresses": {},
|
return {"lcps": {}, "interface_names": {}, "interfaces": {}, "interface_addresses": {},
|
||||||
"bondethernets": {}, "bondethernet_members": {},
|
"bondethernets": {}, "bondethernet_members": {},
|
||||||
"bridgedomains": {}, "vxlan_tunnels": {}, "l2xcs": {}}
|
"bridgedomains": {}, "vxlan_tunnels": {}, "l2xcs": {}}
|
||||||
|
|
||||||
@ -79,6 +79,7 @@ class VPPApi():
|
|||||||
r = self.vpp.api.sw_interface_dump()
|
r = self.vpp.api.sw_interface_dump()
|
||||||
for iface in r:
|
for iface in r:
|
||||||
self.config['interfaces'][iface.sw_if_index] = iface
|
self.config['interfaces'][iface.sw_if_index] = iface
|
||||||
|
self.config['interface_names'][iface.interface_name] = iface
|
||||||
self.config['interface_addresses'][iface.sw_if_index] = []
|
self.config['interface_addresses'][iface.sw_if_index] = []
|
||||||
self.logger.debug("Retrieving IPv4 addresses for %s" % iface.interface_name)
|
self.logger.debug("Retrieving IPv4 addresses for %s" % iface.interface_name)
|
||||||
ipr = self.vpp.api.ip_address_dump(sw_if_index=iface.sw_if_index, is_ipv6=False)
|
ipr = self.vpp.api.ip_address_dump(sw_if_index=iface.sw_if_index, is_ipv6=False)
|
||||||
@ -126,6 +127,16 @@ class VPPApi():
|
|||||||
encap += " exact-match"
|
encap += " exact-match"
|
||||||
return encap
|
return encap
|
||||||
|
|
||||||
|
def phys_exist(self, ifname_list):
|
||||||
|
""" Return True if all interfaces in the `ifname_list` exist as physical interface names
|
||||||
|
in VPP. Return False otherwise."""
|
||||||
|
ret = True
|
||||||
|
for ifname in ifname_list:
|
||||||
|
if not ifname in self.config['interface_names']:
|
||||||
|
self.logger.warning("Interface %s does not exist in VPP" % ifname)
|
||||||
|
ret = False
|
||||||
|
return ret
|
||||||
|
|
||||||
def dump(self):
|
def dump(self):
|
||||||
self.dump_interfaces()
|
self.dump_interfaces()
|
||||||
self.dump_bridgedomains()
|
self.dump_bridgedomains()
|
||||||
|
7
vppcfg
7
vppcfg
@ -57,9 +57,16 @@ def main():
|
|||||||
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)
|
||||||
vpp = VPPApi()
|
vpp = VPPApi()
|
||||||
vpp.readconfig()
|
vpp.readconfig()
|
||||||
|
if not vpp.phys_exist(config_phys):
|
||||||
|
logging.error("Not all PHYs in the config exist in VPP")
|
||||||
|
vpp.disconnect()
|
||||||
|
sys.exit(-3)
|
||||||
|
|
||||||
vpp.dump()
|
vpp.dump()
|
||||||
|
|
||||||
vpp.disconnect()
|
vpp.disconnect()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Reference in New Issue
Block a user