Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: drv-net: make linters happy with our imports

Linters are still not very happy with our __init__ files,
which was pointed out in recent review (see Link).

We have previously started importing things one by one to
make linters happy with the test files (which import from __init__).
But __init__ file itself still makes linters unhappy.

To clean it up I believe we must completely remove the wildcard
imports, and assign the imported modules to __all__.

hds.py needs to be fixed because it seems to be importing
the Python standard random from lib.net.

We can't use ksft_pr() / ktap_result() in case importing
from net.lib fails. Linters complain that those helpers
themselves may not have been imported.

Link: https://lore.kernel.org/9d215979-6c6d-4e9b-9cdd-39cff595866e@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Link: https://patch.msgid.link/20251003164748.860042-1-kuba@kernel.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Jakub Kicinski and committed by
Paolo Abeni
b615879d c9d1b0b5

+34 -12
+2 -1
tools/testing/selftests/drivers/net/hds.py
··· 3 3 4 4 import errno 5 5 import os 6 + import random 6 7 from typing import Union 7 8 from lib.py import ksft_run, ksft_exit, ksft_eq, ksft_raises, KsftSkipEx 8 9 from lib.py import CmdExitFailure, EthtoolFamily, NlError 9 10 from lib.py import NetDrvEnv 10 - from lib.py import defer, ethtool, ip, random 11 + from lib.py import defer, ethtool, ip 11 12 12 13 13 14 def _get_hds_mode(cfg, netnl) -> str:
+32 -11
tools/testing/selftests/drivers/net/lib/py/__init__.py
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 + """ 4 + Driver test environment. 5 + NetDrvEnv and NetDrvEpEnv are the main environment classes. 6 + Former is for local host only tests, latter creates / connects 7 + to a remote endpoint. See NIPA wiki for more information about 8 + running and writing driver tests. 9 + """ 10 + 3 11 import sys 4 12 from pathlib import Path 5 13 ··· 16 8 try: 17 9 sys.path.append(KSFT_DIR.as_posix()) 18 10 19 - from net.lib.py import * 20 - 21 11 # Import one by one to avoid pylint false positives 12 + from net.lib.py import NetNS, NetNSEnter, NetdevSimDev 22 13 from net.lib.py import EthtoolFamily, NetdevFamily, NetshaperFamily, \ 23 14 NlError, RtnlFamily, DevlinkFamily, PSPFamily 24 15 from net.lib.py import CmdExitFailure 25 16 from net.lib.py import bkg, cmd, bpftool, bpftrace, defer, ethtool, \ 26 17 fd_read_timeout, ip, rand_port, tool, wait_port_listen, wait_file 27 - from net.lib.py import fd_read_timeout 28 18 from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx 29 19 from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \ 30 20 ksft_setup 31 21 from net.lib.py import ksft_eq, ksft_ge, ksft_in, ksft_is, ksft_lt, \ 32 22 ksft_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt, ksft_not_none 33 - except ModuleNotFoundError as e: 34 - ksft_pr("Failed importing `net` library from kernel sources") 35 - ksft_pr(str(e)) 36 - ktap_result(True, comment="SKIP") 37 - sys.exit(4) 38 23 39 - from .env import * 40 - from .load import * 41 - from .remote import Remote 24 + __all__ = ["NetNS", "NetNSEnter", "NetdevSimDev", 25 + "EthtoolFamily", "NetdevFamily", "NetshaperFamily", 26 + "NlError", "RtnlFamily", "DevlinkFamily", "PSPFamily", 27 + "CmdExitFailure", 28 + "bkg", "cmd", "bpftool", "bpftrace", "defer", "ethtool", 29 + "fd_read_timeout", "ip", "rand_port", "tool", 30 + "wait_port_listen", "wait_file", 31 + "KsftSkipEx", "KsftFailEx", "KsftXfailEx", 32 + "ksft_disruptive", "ksft_exit", "ksft_pr", "ksft_run", 33 + "ksft_setup", 34 + "ksft_eq", "ksft_ge", "ksft_in", "ksft_is", "ksft_lt", 35 + "ksft_ne", "ksft_not_in", "ksft_raises", "ksft_true", "ksft_gt", 36 + "ksft_not_none", "ksft_not_none"] 37 + 38 + from .env import NetDrvEnv, NetDrvEpEnv 39 + from .load import GenerateTraffic 40 + from .remote import Remote 41 + 42 + __all__ += ["NetDrvEnv", "NetDrvEpEnv", "GenerateTraffic", "Remote"] 43 + except ModuleNotFoundError as e: 44 + print("Failed importing `net` library from kernel sources") 45 + print(str(e)) 46 + sys.exit(4)