diff options
author | Mauricio Faria de Oliveira <mfo@canonical.com> | 2020-11-19 16:18:01 +0000 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2020-11-23 10:45:59 -0500 |
commit | 2996d4078a28f865c9bf339c62b55c914b336815 (patch) | |
tree | 706e98590f5104e1ddc47ee8435da52b8fd20822 | |
parent | f104b083962a53c3c3e890be85f28a30eaccbf60 (diff) | |
download | sos-2996d4078a28f865c9bf339c62b55c914b336815.tar.gz |
[networking] Remove superfluous if/out_ns and re-indent per-ns code
Split this into its own commit as it's mostly indentation changes.
From:
```
if self.g_n_n():
out_ns = self.g_n_n(<filters>)
for namespace in out_ns:
...
if self.get_option('ethtool_namespaces'):
for namespace in out_ns:
...
```
To:
```
for namespace in self.g_n_n(<filters>):
...
if self.get_option('ethtool_namespaces'):
for namespace in self.g_n_n(<filters>):
...
```
Resolves: #2308
Signed-off-by: Mauricio Faria de Oliveira <mfo@canonical.com>
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | sos/report/plugins/networking.py | 91 |
1 files changed, 45 insertions, 46 deletions
diff --git a/sos/report/plugins/networking.py b/sos/report/plugins/networking.py index a919fa17..5504474d 100644 --- a/sos/report/plugins/networking.py +++ b/sos/report/plugins/networking.py @@ -231,53 +231,52 @@ class Networking(Plugin): # per-namespace. self.add_cmd_output("ip netns") cmd_prefix = "ip netns exec " - if self.get_network_namespaces(): - out_ns = self.get_network_namespaces( - self.get_option("namespace_pattern"), - self.get_option("namespaces")) - - for namespace in out_ns: + for namespace in self.get_network_namespaces( + self.get_option("namespace_pattern"), + self.get_option("namespaces")): + ns_cmd_prefix = cmd_prefix + namespace + " " + self.add_cmd_output([ + ns_cmd_prefix + "ip address show", + ns_cmd_prefix + "ip route show table all", + ns_cmd_prefix + "ip -s -s neigh show", + ns_cmd_prefix + "ip rule list", + ns_cmd_prefix + "iptables-save", + ns_cmd_prefix + "ip6tables-save", + ns_cmd_prefix + "netstat %s -neopa" % self.ns_wide, + ns_cmd_prefix + "netstat -s", + ns_cmd_prefix + "netstat %s -agn" % self.ns_wide, + ]) + + ss_cmd = ns_cmd_prefix + "ss -peaonmi" + # --allow-system-changes is handled directly in predicate + # evaluation, so plugin code does not need to separately + # check for it + self.add_cmd_output(ss_cmd, pred=ss_pred) + + # Collect ethtool commands only when ethtool_namespaces + # is set to true. + if self.get_option("ethtool_namespaces"): + # Devices that exist in a namespace use less ethtool + # parameters. Run this per namespace. + for namespace in self.get_network_namespaces( + self.get_option("namespace_pattern"), + self.get_option("namespaces")): ns_cmd_prefix = cmd_prefix + namespace + " " - self.add_cmd_output([ - ns_cmd_prefix + "ip address show", - ns_cmd_prefix + "ip route show table all", - ns_cmd_prefix + "ip -s -s neigh show", - ns_cmd_prefix + "ip rule list", - ns_cmd_prefix + "iptables-save", - ns_cmd_prefix + "ip6tables-save", - ns_cmd_prefix + "netstat %s -neopa" % self.ns_wide, - ns_cmd_prefix + "netstat -s", - ns_cmd_prefix + "netstat %s -agn" % self.ns_wide, - ]) - - ss_cmd = ns_cmd_prefix + "ss -peaonmi" - # --allow-system-changes is handled directly in predicate - # evaluation, so plugin code does not need to separately - # check for it - self.add_cmd_output(ss_cmd, pred=ss_pred) - - # Collect ethtool commands only when ethtool_namespaces - # is set to true. - if self.get_option("ethtool_namespaces"): - # Devices that exist in a namespace use less ethtool - # parameters. Run this per namespace. - for namespace in out_ns: - ns_cmd_prefix = cmd_prefix + namespace + " " - netns_netdev_list = self.exec_cmd( - ns_cmd_prefix + "ls -1 /sys/class/net/" - ) - 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, - ns_cmd_prefix + "ethtool -k " + eth, - ns_cmd_prefix + "ethtool -S " + eth - ]) + netns_netdev_list = self.exec_cmd( + ns_cmd_prefix + "ls -1 /sys/class/net/" + ) + 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, + ns_cmd_prefix + "ethtool -k " + eth, + ns_cmd_prefix + "ethtool -S " + eth + ]) return |