Skip to content

wifi: speed reading fix (can't read speed file for wifi devices)

Štěpán Henek requested to merge wifi_speed_fix into master

turrishw fails with an exception when wifi interface is up It is causes by reading speed file

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.7/site-packages/turrishw/__init__.py", line 57, in get_ifaces
    ifaces = omnia.get_interfaces()
  File "/usr/lib/python3.7/site-packages/turrishw/omnia.py", line 56, in get_interfaces
    ifaces = ifaces + _get_wifi_interfaces()
  File "/usr/lib/python3.7/site-packages/turrishw/omnia.py", line 39, in _get_wifi_interfaces
    ifaces.append(utils.iface_info(iface, "wifi", "pci", 0, "2"))
  File "/usr/lib/python3.7/site-packages/turrishw/utils.py", line 70, in iface_info
    "link_speed": get_iface_speed(iface) if state == "up" else 0}
  File "/usr/lib/python3.7/site-packages/turrishw/utils.py", line 45, in get_iface_speed
    speed = get_first_line(os.path.join(__P_ROOT__, 'sys/class/net/{}/speed'.format(iface)))
  File "/usr/lib/python3.7/site-packages/turrishw/utils.py", line 31, in get_first_line
    return f.readline()
OSError: [Errno 22] Invalid argument
root@turris:~# cat /sys/class/net/wlan0/speed
cat: read error: Invalid argument

This patch catches the exception and sets the speed to 0

Merge request reports