From dc190a9fde94f575e660e782831d922b89c00507 Mon Sep 17 00:00:00 2001 From: Jake Hunsaker Date: Wed, 19 Jul 2023 13:09:28 -0400 Subject: [PATCH] [report] Don't use sysroot for network device enumeration If sos is being used in a live environment to diagnose an issue, using sysroot can cause the network device enumeration via /sys/class/net crawling to fail. This will be the case for systems that do not use `nmcli`. When in a live environment, network devices will not be under `/$sysroot/sys/class/net` but the "regular" path for the booted environment. Similarly, if sos is being run in a container that is properly configured, network devices will appear under `/sys/class/net` and not (necessarily) under the sysroot path that mounts the host's filesystem. As such, disregard a configured sysroot when enumerating network devices by crawling `/sys/class/net`, and trap any exceptions that may percolate up from this in edge case environments. Closes: #3307 Signed-off-by: Jake Hunsaker --- sos/report/__init__.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sos/report/__init__.py b/sos/report/__init__.py index 9c51b3a6db..eb985cd072 100644 --- a/sos/report/__init__.py +++ b/sos/report/__init__.py @@ -612,10 +612,18 @@ def _get_eth_devs(self, namespace=None): filt_devs = ['bonding_masters'] _eth_devs = [] if not namespace: - _eth_devs = [ - dev for dev in listdir('/sys/class/net', self.opts.sysroot) - if dev not in filt_devs - ] + try: + # Override checking sysroot here, as network devices will not + # be under the sysroot in live environments or in containers + # that are correctly setup to collect from the host + _eth_devs = [ + dev for dev in listdir('/sys/class/net', None) + if dev not in filt_devs + ] + except Exception as err: + self.soslog.warning( + f'Failed to manually determine network devices: {err}' + ) else: try: _nscmd = "ip netns exec %s ls /sys/class/net" % namespace