Make vpp_readconfig() explicit again. I want to try to read the VPP config only once, and pathplan the entire prune/create/sync cycle with one set of API reads at the beginning.

This commit is contained in:
Pim van Pelt
2022-03-26 21:08:41 +00:00
parent f5601765b0
commit 619c579561
2 changed files with 13 additions and 20 deletions

View File

@ -34,10 +34,6 @@ class Reconciler():
""" Return True if all interfaces in the `ifname_list` exist as physical interface names """ Return True if all interfaces in the `ifname_list` exist as physical interface names
in VPP. Return False otherwise.""" in VPP. Return False otherwise."""
if not self.vpp.config_read and not self.vpp.readconfig():
self.logger.error("Could not read configuration from VPP")
return False
ret = True ret = True
for ifname in ifname_list: for ifname in ifname_list:
if not ifname in self.vpp.config['interface_names']: if not ifname in self.vpp.config['interface_names']:
@ -45,14 +41,16 @@ class Reconciler():
ret = False ret = False
return ret return ret
def vpp_readconfig(self):
if not self.vpp.readconfig():
self.logger.error("Could not (re)read config from VPP")
return False
return True
def prune(self): def prune(self):
""" Remove all objects from VPP that do not occur in the config. For an indepth explanation """ Remove all objects from VPP that do not occur in the config. For an indepth explanation
of how and why this particular pruning order is chosen, see README.md section on of how and why this particular pruning order is chosen, see README.md section on
Reconciling. """ Reconciling. """
if not self.vpp.config_read and not self.vpp.readconfig():
self.logger.error("Could not read configuration from VPP")
return False
ret = True ret = True
if not self.prune_admin_state(): if not self.prune_admin_state():
self.logger.warning("Could not set interfaces down in VPP") self.logger.warning("Could not set interfaces down in VPP")
@ -575,10 +573,6 @@ class Reconciler():
""" Create all objects in VPP that occur in the config but not in VPP. For an indepth """ Create all objects in VPP that occur in the config but not in VPP. For an indepth
explanation of how and why this particular pruning order is chosen, see README.md explanation of how and why this particular pruning order is chosen, see README.md
section on Reconciling. """ section on Reconciling. """
if not self.vpp.config_read and not self.vpp.readconfig():
self.logger.error("Could not read configuration from VPP")
return False
ret = True ret = True
if not self.create_loopbacks(): if not self.create_loopbacks():
self.logger.warning("Could not create Loopbacks in VPP") self.logger.warning("Could not create Loopbacks in VPP")
@ -704,10 +698,6 @@ class Reconciler():
return True return True
def sync(self): def sync(self):
if not self.vpp.readconfig():
self.logger.error("Could not (re)read config from VPP")
return False
ret = True ret = True
if not self.sync_bondethernets(): if not self.sync_bondethernets():
self.logger.warning("Could not sync bondethernets in VPP") self.logger.warning("Could not sync bondethernets in VPP")

11
vppcfg
View File

@ -60,26 +60,29 @@ def main():
sys.exit(-2) sys.exit(-2)
r = Reconciler(cfg) r = Reconciler(cfg)
if not r.vpp_readconfig():
sys.exit(-3)
if not r.phys_exist(interface.get_phys(cfg)): if not r.phys_exist(interface.get_phys(cfg)):
logging.error("Not all PHYs in the config exist in VPP") logging.error("Not all PHYs in the config exist in VPP")
sys.exit(-3) sys.exit(-4)
if not r.prune(): if not r.prune():
if not args.force: if not args.force:
logging.error("Reconciliation prune failure") logging.error("Reconciliation prune failure")
sys.exit(-4) sys.exit(-10)
logging.warning("Reconciliation prune failure, continuing due to --force") logging.warning("Reconciliation prune failure, continuing due to --force")
if not r.create(): if not r.create():
if not args.force: if not args.force:
logging.error("Reconciliation create failure") logging.error("Reconciliation create failure")
sys.exit(-5) sys.exit(-20)
logging.warning("Reconciliation create failure, continuing due to --force") logging.warning("Reconciliation create failure, continuing due to --force")
if not r.sync(): if not r.sync():
if not args.force: if not args.force:
logging.error("Reconciliation sync failure") logging.error("Reconciliation sync failure")
sys.exit(-6) sys.exit(-30)
logging.warning("Reconciliation sync failure, continuing due to --force") logging.warning("Reconciliation sync failure, continuing due to --force")