diff options
author | Mauricio Faria de Oliveira <mfo@canonical.com> | 2020-11-11 21:55:06 +0000 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2020-11-23 10:45:10 -0500 |
commit | 7b8936d10c349749da03aba1e27660bf86ed99ea (patch) | |
tree | 6faf3533b5a4d9200074021f2c885b6930b2f0f4 | |
parent | 03a233c19113e06b5d9fae5266444d19bcf7a9c0 (diff) | |
download | sos-7b8936d10c349749da03aba1e27660bf86ed99ea.tar.gz |
[networking] Ignore stderr from ip netns for list of namespaces
The sosreport of a system with this issue:
```
# ip netns
Error: Peer netns reference is invalid.
Error: Peer netns reference is invalid.
test-ns
```
Shows that the networking plugin runs commands for the `Error:` lines:
(note the ebpf plugin does not due to differences addressed in PR #2306)
```
# ./bin/sos report -o ebpf,networking --batch
# tar tf /tmp/sosreport-*.tar.xz | grep ip_netns_exec
.../sos_commands/ebpf/ip_netns_exec_test-ns_bpftool_net_list
.../sos_commands/networking/ip_netns_exec_Error_ip6tables-save
.../sos_commands/networking/ip_netns_exec_Error_ip6tables-save.1
...
.../sos_commands/networking/ip_netns_exec_test-ns_ip6tables-save
...
```
This happens because the networking plugin calls `collect_cmd_output()`
with default `stderr=True` and does not handle such line type.
For the purposes of getting the list of network namespaces, it is OK to
ignore `stderr` since it does not provide that information. However, we
do want it in the archive, so it is fully documented for analysis/debug.
So change the call from `collect_cmd_output()` to `add_cmd_output()` to
include both `stdout` and `stderr` in the archive, and call `exec_cmd()`
that ignores `stderr` to get the list of network namespaces.
Note that the plugin _currently_ does not need `exec_cmd(stderr=False)`
to ignore `stderr`, as described in PR#2306, but will once/if that is
applied. However, with the next patch, `stderr=False` won't be needed.
Before:
```
# tar tf /tmp/sosreport-*.tar.xz | grep ip_netns_exec
.../sos_commands/ebpf/ip_netns_exec_test-ns_bpftool_net_list
.../sos_commands/networking/ip_netns_exec_Error_ip6tables-save
.../sos_commands/networking/ip_netns_exec_Error_ip6tables-save.1
...
.../sos_commands/networking/ip_netns_exec_test-ns_ip6tables-save
...
```
After:
```
# tar tf /tmp/sosreport-*.tar.xz | grep ip_netns_exec
.../sos_commands/ebpf/ip_netns_exec_test-ns_bpftool_net_list
.../sos_commands/networking/ip_netns_exec_test-ns_ip6tables-save
.../sos_commands/networking/ip_netns_exec_test-ns_ip_-s_-s_neigh_show
...
```
And the `ip netns` contents with `stderr` still remain in the archive:
```
# tar xf /tmp/sosreport-*.tar.xz --to-stdout \
--wildcards '*/sos_commands/networking/ip_netns'
Error: Peer netns reference is invalid.
Error: Peer netns reference is invalid.
test-ns
```
Test suite:
```
# ./tests/simple.sh
...
Everything worked!
```
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 | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/sos/report/plugins/networking.py b/sos/report/plugins/networking.py index af73ffe6..b2ae655c 100644 --- a/sos/report/plugins/networking.py +++ b/sos/report/plugins/networking.py @@ -230,7 +230,8 @@ class Networking(Plugin): # Capture additional data from namespaces; each command is run # per-namespace. - ip_netns = self.collect_cmd_output("ip netns") + self.add_cmd_output("ip netns") + ip_netns = self.exec_cmd("ip netns") cmd_prefix = "ip netns exec " if ip_netns['status'] == 0: out_ns = [] |