From 619c57956121f620e802c2e546704ab7d648cce7 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Sat, 26 Mar 2022 21:08:41 +0000 Subject: [PATCH] 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. --- vpp/reconciler.py | 22 ++++++---------------- vppcfg | 11 +++++++---- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/vpp/reconciler.py b/vpp/reconciler.py index 61e8f23..fbe219b 100644 --- a/vpp/reconciler.py +++ b/vpp/reconciler.py @@ -34,10 +34,6 @@ class Reconciler(): """ Return True if all interfaces in the `ifname_list` exist as physical interface names 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 for ifname in ifname_list: if not ifname in self.vpp.config['interface_names']: @@ -45,14 +41,16 @@ class Reconciler(): ret = False 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): """ 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 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 if not self.prune_admin_state(): 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 explanation of how and why this particular pruning order is chosen, see README.md 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 if not self.create_loopbacks(): self.logger.warning("Could not create Loopbacks in VPP") @@ -704,10 +698,6 @@ class Reconciler(): return True def sync(self): - if not self.vpp.readconfig(): - self.logger.error("Could not (re)read config from VPP") - return False - ret = True if not self.sync_bondethernets(): self.logger.warning("Could not sync bondethernets in VPP") diff --git a/vppcfg b/vppcfg index f6f6bed..e9bcac8 100755 --- a/vppcfg +++ b/vppcfg @@ -60,26 +60,29 @@ def main(): sys.exit(-2) r = Reconciler(cfg) + if not r.vpp_readconfig(): + sys.exit(-3) + if not r.phys_exist(interface.get_phys(cfg)): logging.error("Not all PHYs in the config exist in VPP") - sys.exit(-3) + sys.exit(-4) if not r.prune(): if not args.force: logging.error("Reconciliation prune failure") - sys.exit(-4) + sys.exit(-10) logging.warning("Reconciliation prune failure, continuing due to --force") if not r.create(): if not args.force: logging.error("Reconciliation create failure") - sys.exit(-5) + sys.exit(-20) logging.warning("Reconciliation create failure, continuing due to --force") if not r.sync(): if not args.force: logging.error("Reconciliation sync failure") - sys.exit(-6) + sys.exit(-30) logging.warning("Reconciliation sync failure, continuing due to --force")