Skip to content

Commit

Permalink
[report] Don't use sysroot for network device enumeration
Browse files Browse the repository at this point in the history
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.

Related: #3307

Signed-off-by: Jake Hunsaker <[email protected]>
  • Loading branch information
TurboTurtle committed Jul 31, 2023
1 parent 0af74a8 commit 473f495
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions sos/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 473f495

Please sign in to comment.