selftests: net: devlink_port_split: check devlink returned an element before derefere...
authorPaolo Pisati <paolo.pisati@canonical.com>
Mon, 28 Jun 2021 14:54:24 +0000 (16:54 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Jun 2021 23:14:38 +0000 (16:14 -0700)
And thus avoid a Python stacktrace:

~/linux/tools/testing/selftests/net$ ./devlink_port_split.py
Traceback (most recent call last):
  File "/home/linux/tools/testing/selftests/net/./devlink_port_split.py",
line 277, in <module> main()
  File "/home/linux/tools/testing/selftests/net/./devlink_port_split.py",
line 242, in main
    dev = list(devs.keys())[0]
IndexError: list index out of range

Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/selftests/net/devlink_port_split.py

index 834066d..d162915 100755 (executable)
@@ -239,6 +239,9 @@ def main(cmdline=None):
         assert stderr == ""
 
         devs = json.loads(stdout)['dev']
+        if len(devs.keys()) == 0:
+            print("no devlink device found")
+            sys.exit(1)
         dev = list(devs.keys())[0]
 
     cmd = "devlink dev show %s" % dev