Gracefully handle Invalid argument from /sys/.../speed

Not all interfaces support retrieval of link speed through sysfs,
gracefully handle those that don't.

Closes-Bug: #1990481
Change-Id: I2f43cd67bab52704c80da569912b7770f4c1877b
This commit is contained in:
Frode Nordahl
2022-09-22 10:27:15 +02:00
parent 5d03ce8390
commit 921ea2d452
3 changed files with 44 additions and 2 deletions

View File

@@ -605,8 +605,14 @@ def check_bonds(bonds, lldp=None):
def get_link_speed(iface):
with open('/sys/class/net/{}/speed'.format(iface)) as f:
return int(f.read())
try:
with open('/sys/class/net/{}/speed'.format(iface)) as f:
return int(f.read())
except OSError as e:
hookenv.log('Unable to determine link speed for {}: {}'
.format(iface, str(e)),
hookenv.WARNING)
return -1
def check_nodes(nodes, iperf_client=False):