From c1b6ffc78c4e8e2f02a587de1ad0c8c951163ede Mon Sep 17 00:00:00 2001 From: Julien Fortin Date: Tue, 21 Jan 2020 09:20:41 +0100 Subject: [PATCH] addons: ethtool: add support for "ethtool_ignore_errors" policy The goal of this policy is to ignore ethtool related errors, this is useful for specific scenario like VMs. This policy is off by default. To turn it on simply set: "module_globals" : { "ethtool_ignore_errors": true } under the ethtool top object. Signed-off-by: Julien Fortin --- ifupdown2/addons/ethtool.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/ifupdown2/addons/ethtool.py b/ifupdown2/addons/ethtool.py index 4a20ef5..72f5ca1 100644 --- a/ifupdown2/addons/ethtool.py +++ b/ifupdown2/addons/ethtool.py @@ -143,6 +143,11 @@ class ethtool(moduleBase,utilsBase): except Exception, e: self.log_error('%s: %s' %(ifaceobj.name, str(e)), ifaceobj) + self.ethtool_ignore_errors = policymanager.policymanager_api.get_module_globals( + module_name=self.__class__.__name__, + attr='ethtool_ignore_errors' + ) + def do_fec_settings(self, ifaceobj): feccmd = '' @@ -192,7 +197,8 @@ class ethtool(moduleBase,utilsBase): (utils.ethtool_cmd, ifaceobj.name, feccmd)) utils.exec_command(feccmd) except Exception, e: - self.log_error('%s: %s' %(ifaceobj.name, str(e)), ifaceobj) + if not self.ethtool_ignore_errors: + self.log_error('%s: %s' %(ifaceobj.name, str(e)), ifaceobj) else: pass @@ -286,7 +292,8 @@ class ethtool(moduleBase,utilsBase): cmd = ('%s -s %s %s' % (utils.ethtool_cmd, ifaceobj.name, cmd)) utils.exec_command(cmd) except Exception, e: - self.log_error('%s: %s' % (ifaceobj.name, str(e)), ifaceobj) + if not self.ethtool_ignore_errors: + self.log_error('%s: %s' % (ifaceobj.name, str(e)), ifaceobj) def _pre_up(self, ifaceobj, operation='post_up'): """ @@ -460,10 +467,11 @@ class ethtool(moduleBase,utilsBase): running_attr = self.read_file_oneline('/sys/class/net/%s/%s' % \ (ifaceobj.name, attr)) except Exception as e: - # for nonexistent interfaces, we get an error (rc = 256 or 19200) - self.logger.debug('ethtool: problems calling ethtool or reading' - ' /sys/class on iface %s for attr %s: %s' % - (ifaceobj.name, attr, str(e))) + if not self.ethtool_ignore_errors: + # for nonexistent interfaces, we get an error (rc = 256 or 19200) + self.logger.debug('ethtool: problems calling ethtool or reading' + ' /sys/class on iface %s for attr %s: %s' % + (ifaceobj.name, attr, str(e))) return running_attr