From 8598c690e3c337adda8c00137709f3177a1698e9 Mon Sep 17 00:00:00 2001 From: Julien Fortin Date: Wed, 19 Feb 2020 15:50:27 +0100 Subject: [PATCH] lib: nlcache: fix dry_run exception Ticket: CM-28312 Testing Done: Test from the ticket error: link_set_bridge_info_data_dry_run() takes exactly 3 arguments (4 given) error: link_set_brport_with_info_slave_data_dry_run() got an unexpected keyword argument 'kind' seems like when updating a method, it's associated dry-run method wasn't updated accordingly. Maybe there is a way to programmatically check that I will look into it. warning: bridge: skipping port X invalid ether addr warning: interface not recognized - please check interface configuration Won't show on dry-run anymore Log info for commands executed with utils.exec_command() weren't prefixed with DRY-RUN. Signed-off-by: Julien Fortin --- ifupdown2/addons/bridge.py | 2 +- ifupdown2/ifupdown/ifupdownmain.py | 2 +- ifupdown2/ifupdown/utils.py | 5 +++-- ifupdown2/lib/nlcache.py | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ifupdown2/addons/bridge.py b/ifupdown2/addons/bridge.py index 00b1eaa..bcedb11 100644 --- a/ifupdown2/addons/bridge.py +++ b/ifupdown2/addons/bridge.py @@ -1125,7 +1125,7 @@ class bridge(Addon, moduleBase): err += 1 continue hwaddress = self.cache.get_link_address(bridgeport) - if not self._valid_ethaddr(hwaddress): + if not ifupdownflags.flags.DRYRUN and not self._valid_ethaddr(hwaddress): self.log_warn('%s: skipping port %s, ' %(ifaceobj.name, bridgeport) + 'invalid ether addr %s' %hwaddress) diff --git a/ifupdown2/ifupdown/ifupdownmain.py b/ifupdown2/ifupdown/ifupdownmain.py index 01163e2..59435c8 100644 --- a/ifupdown2/ifupdown/ifupdownmain.py +++ b/ifupdown2/ifupdown/ifupdownmain.py @@ -1804,7 +1804,7 @@ class ifupdownMain: auto = False break - if auto and not os.path.exists("/sys/class/net/%s" % ifname): + if not ifupdownflags.flags.DRYRUN and auto and not os.path.exists("/sys/class/net/%s" % ifname): self.logger.warning("%s: interface not recognized - please check interface configuration" % ifname) def _get_filtered_ifacenames_with_classes(self, auto, allow_classes, excludepats, ifacenames): diff --git a/ifupdown2/ifupdown/utils.py b/ifupdown2/ifupdown/utils.py index 08091e5..77aaed9 100644 --- a/ifupdown2/ifupdown/utils.py +++ b/ifupdown2/ifupdown/utils.py @@ -289,10 +289,11 @@ class utils(): @classmethod def _log_command_exec(cls, cmd, stdin): + dry_run = "DRY-RUN: " if ifupdownflags.flags.DRYRUN else "" if stdin: - cls.logger.info('executing %s [%s]' % (cmd, stdin)) + cls.logger.info('%sexecuting %s [%s]' % (dry_run, cmd, stdin)) else: - cls.logger.info('executing %s' % cmd) + cls.logger.info('%sexecuting %s' % (dry_run, cmd)) @classmethod def _format_error(cls, cmd, cmd_returncode, cmd_output, stdin): diff --git a/ifupdown2/lib/nlcache.py b/ifupdown2/lib/nlcache.py index 6b188bd..a7869e4 100644 --- a/ifupdown2/lib/nlcache.py +++ b/ifupdown2/lib/nlcache.py @@ -2801,7 +2801,7 @@ class NetlinkListenerWithCache(nllistener.NetlinkManagerWithListener, BaseObject except Exception as e: raise Exception("%s: netlink: cannot create bridge or set attributes: %s" % (ifname, str(e))) - def link_set_bridge_info_data_dry_run(self, ifname, ifla_info_data): + def link_set_bridge_info_data_dry_run(self, ifname, ifla_info_data, link_just_created): self.log_info_ifname_dry_run(ifname, "netlink: ip link add dev %s type bridge (with attributes)" % ifname) self.logger.debug("attributes: %s" % ifla_info_data) @@ -3054,7 +3054,7 @@ class NetlinkListenerWithCache(nllistener.NetlinkManagerWithListener, BaseObject except Exception as e: raise Exception("netlink: %s: cannot set %s (bridge slave) with options: %s" % (kind, ifname, str(e))) - def link_set_brport_with_info_slave_data_dry_run(self, ifname, _, __, ifla_info_slave_data): + def link_set_brport_with_info_slave_data_dry_run(self, ifname, kind, ifla_info_data, ifla_info_slave_data): self.log_info_ifname_dry_run(ifname, "netlink: ip link set dev %s: bridge port attributes" % ifname) self.logger.debug("attributes: %s" % ifla_info_slave_data)