Refactor phys_exist() into phys_exist_in_{config,vpp}(); Correct vppapi.get_phys()

This commit is contained in:
Pim van Pelt
2022-03-26 23:07:49 +00:00
parent 4c31541b3e
commit 176fd297aa
3 changed files with 20 additions and 6 deletions

View File

@ -30,17 +30,28 @@ class Reconciler():
self.vpp = VPPApi()
self.cfg = cfg
def phys_exist(self, ifname_list):
""" Return True if all interfaces in the `ifname_list` exist as physical interface names
def phys_exist_in_vpp(self):
""" Return True if all PHYs in the config exist as physical interface names
in VPP. Return False otherwise."""
ret = True
for ifname in ifname_list:
for ifname in interface.get_phys(self.cfg):
if not ifname in self.vpp.config['interface_names']:
self.logger.warning("Interface %s does not exist in VPP" % ifname)
ret = False
return ret
def phys_exist_in_config(self):
""" Return True if all interfaces in VPP exist as physical interface names
in the config. Return False otherwise."""
ret = True
for ifname in self.vpp.get_phys():
if not ifname in interface.get_interfaces(self.cfg):
self.logger.warning("Interface %s does not exist in the config" % ifname)
ret = False
return ret
def vpp_readconfig(self):
if not self.vpp.readconfig():
self.logger.error("Could not (re)read config from VPP")

View File

@ -236,7 +236,7 @@ class VPPApi():
return bvis
def get_phys(self):
phys = [self.config['interfaces'][x].interface_name for x in self.config['interfaces'] if self.config['interfaces'][x].interface_dev_type=='dpdk' and self.config['interfaces'][x].sw_if_index == self.config['interfaces'][x].sup_sw_if_index]
phys = [self.config['interfaces'][x].interface_name for x in self.config['interfaces'] if self.config['interfaces'][x].sw_if_index == self.config['interfaces'][x].sup_sw_if_index and self.config['interfaces'][x].interface_dev_type not in ['virtio', 'BVI', 'Loopback', 'VXLAN', 'local', 'bond']]
return phys
def get_bondethernets(self):

7
vppcfg
View File

@ -18,7 +18,6 @@ import sys
import yaml
import logging
from config import Validator
import config.interface as interface
from vpp.reconciler import Reconciler
try:
@ -63,10 +62,14 @@ def main():
if not r.vpp_readconfig():
sys.exit(-3)
if not r.phys_exist(interface.get_phys(cfg)):
if not r.phys_exist_in_vpp():
logging.error("Not all PHYs in the config exist in VPP")
sys.exit(-4)
if not r.phys_exist_in_config():
logging.error("Not all PHYs in VPP exist in the config")
sys.exit(-5)
failed = False
if not r.prune():
if not args.force: