Skip to content

Commit dd048d3

Browse files
util/agents/network_interface: bail out if NM did not find an interface
nm.get_device_by_iface() returns None if there is no device for an interface. This can happen if NetworkManager is not running, it it's in an undefined state or if it does not manage the interface at all. Instead of trying to call methods on the returned None type, let's bail out early with a proper exception. Signed-off-by: Bastian Krause <[email protected]>
1 parent 01628dc commit dd048d3

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

labgrid/util/agents/network_interface.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class NMDev:
9898
def __init__(self, interface):
9999
self._interface = interface
100100
self._nm_dev = nm.get_device_by_iface(interface) # pylint: disable=possibly-used-before-assignment
101+
if self._nm_dev is None:
102+
raise ValueError(f"No device found for interface {interface}")
101103

102104
def _delete_connection(self, con):
103105
future = Future()

0 commit comments

Comments
 (0)