From 8d60ab416367a2f10281bd624ccae6bae2ae632d Mon Sep 17 00:00:00 2001 From: Sam Tannous Date: Thu, 2 Jul 2015 15:59:34 -0400 Subject: [PATCH] ifquery --running should not show link attributes on logical interfaces Ticket: CM-6557 Reviewed By: roopa, gospo Testing Done: unit tested ifquery should not show link attributes for interfaces we do not have defaults for. Although somewhat useful, we don't want people saving the bond link attributes to try to use then in a config --- addons/ethtool.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/addons/ethtool.py b/addons/ethtool.py index cb7e5d6..d8b18f3 100644 --- a/addons/ethtool.py +++ b/addons/ethtool.py @@ -101,15 +101,18 @@ class ethtool(moduleBase,utilsBase): (the default will get set). """ for attr in ['speed', 'duplex', 'autoneg']: - # autoneg comes from ethtool whereas speed and duplex from /sys/class - running_attr = self.get_running_attr(attr, ifaceobj) - - configured = ifaceobj.get_attr_value_first('link-%s'%attr) default = policymanager.policymanager_api.get_iface_default( module_name='ethtool', ifname=ifaceobj.name, attr='link-%s'%attr) + # if we have no default, do not bother checking + # this avoids ethtool calls on virtual interfaces + if not default: + continue + # autoneg comes from ethtool whereas speed and duplex from /sys/class + running_attr = self.get_running_attr(attr, ifaceobj) + configured = ifaceobj.get_attr_value_first('link-%s'%attr) # there is a case where there is no running config or # (there is no default and it is not configured). # In this case, we do nothing (e.g. eth0 has only a @@ -178,9 +181,19 @@ class ethtool(moduleBase,utilsBase): if not self.ipcmd.is_link_up(ifaceobj.name): return for attr in ['speed', 'duplex', 'autoneg']: + default_val = policymanager.policymanager_api.get_iface_default( + module_name='ethtool', + ifname=ifaceobj.name, + attr='link-%s'%attr) + # do not continue if we have no defaults + # this avoids ethtool calls on virtual interfaces + if not default_val: + continue running_attr = self.get_running_attr(attr, ifaceobj) - # show it - if (running_attr): + # if we can change it (have a default) then show it + # otherwise, customers will show the running and save it to startup + # which will result in errors (ethtool does not work on bonds, etc.) + if running_attr: ifaceobj.update_config('link-%s'%attr, running_attr) return