Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[networking] call ethtool for proper vlan device names #1458

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 25 additions & 42 deletions sos/plugins/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,6 @@ def get_bridge_name(self, brctl_file):
out.append(br_name)
return out

def get_eth_interfaces(self, ip_link_out):
"""Return a dictionary for which keys are ethernet interface
names taken from the output of "ip -o link".
"""
out = {}
for line in ip_link_out.splitlines():
match = re.match('.*link/ether', line)
if match:
iface = match.string.split(':')[1].lstrip()
out[iface] = True
return out

def get_ip_netns(self, ip_netns_file):
"""Returns a list for which items are namespaces in the output of
ip netns stored in the ip_netns_file.
Expand All @@ -73,19 +61,6 @@ def get_ip_netns(self, ip_netns_file):
out.append(line.partition(' ')[0])
return out

def get_netns_devs(self, namespace):
"""Returns a list for which items are devices that exist within
the provided namespace.
"""
ip_link_result = self.call_ext_prog("ip netns exec " + namespace +
" ip -o link")
dev_list = []
if ip_link_result['status'] == 0:
for eth in self.get_eth_interfaces(ip_link_result['output']):
dev = eth.replace('@NONE', '')
dev_list.append(dev)
return dev_list

def collect_iptable(self, tablename):
""" When running the iptables command, it unfortunately auto-loads
the modules before trying to get output. Some people explicitly
Expand Down Expand Up @@ -199,21 +174,22 @@ def setup(self):

# Get ethtool output for every device that does not exist in a
# namespace.
ip_link_result = self.call_ext_prog("ip -o link")
if ip_link_result['status'] == 0:
for dev in self.get_eth_interfaces(ip_link_result['output']):
eth = dev.replace('@NONE', '')
self.add_cmd_output([
"ethtool "+eth,
"ethtool -d "+eth,
"ethtool -i "+eth,
"ethtool -k "+eth,
"ethtool -S "+eth,
"ethtool -T "+eth,
"ethtool -a "+eth,
"ethtool -c "+eth,
"ethtool -g "+eth
])
for eth in os.listdir("/sys/class/net/"):
# skip 'bonding_masters' file created when loading the bonding
# module but the file does not correspond to a device
if eth == "bonding_masters":
continue
self.add_cmd_output([
"ethtool " + eth,
"ethtool -d " + eth,
"ethtool -i " + eth,
"ethtool -k " + eth,
"ethtool -S " + eth,
"ethtool -T " + eth,
"ethtool -a " + eth,
"ethtool -c " + eth,
"ethtool -g " + eth
])

# brctl command will load bridge and related kernel modules
# if those modules are not loaded at the time of brctl command running
Expand Down Expand Up @@ -251,8 +227,15 @@ def setup(self):
# Devices that exist in a namespace use less ethtool
# parameters. Run this per namespace.
for namespace in self.get_ip_netns(ip_netns_file):
for eth in self.get_netns_devs(namespace):
ns_cmd_prefix = cmd_prefix + namespace + " "
ns_cmd_prefix = cmd_prefix + namespace + " "
netns_netdev_list = self.call_ext_prog(ns_cmd_prefix +
"ls -1 /sys/class/net/")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to use os.listdir() here? It is typically cleaner than shelling out to ls...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, OK. The ns prefix. I wonder if there isn't a better way to do that, it's kinda fugly...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, haven't found a direct pythonic way outside calling shell. I can add a comment if it clarifies the code..?

for eth in netns_netdev_list['output'].splitlines():
# skip 'bonding_masters' file created when loading the
# bonding module but the file does not correspond to
# a device
if eth == "bonding_masters":
continue
self.add_cmd_output([
ns_cmd_prefix + "ethtool " + eth,
ns_cmd_prefix + "ethtool -i " + eth,
Expand Down