Skip to content

Commit b615879

Browse files
kuba-mooPaolo Abeni
authored andcommitted
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/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent c9d1b0b commit b615879

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

tools/testing/selftests/drivers/net/hds.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33

44
import errno
55
import os
6+
import random
67
from typing import Union
78
from lib.py import ksft_run, ksft_exit, ksft_eq, ksft_raises, KsftSkipEx
89
from lib.py import CmdExitFailure, EthtoolFamily, NlError
910
from lib.py import NetDrvEnv
10-
from lib.py import defer, ethtool, ip, random
11+
from lib.py import defer, ethtool, ip
1112

1213

1314
def _get_hds_mode(cfg, netnl) -> str:

tools/testing/selftests/drivers/net/lib/py/__init__.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# SPDX-License-Identifier: GPL-2.0
22

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+
311
import sys
412
from pathlib import Path
513

@@ -8,26 +16,39 @@
816
try:
917
sys.path.append(KSFT_DIR.as_posix())
1018

11-
from net.lib.py import *
12-
1319
# Import one by one to avoid pylint false positives
20+
from net.lib.py import NetNS, NetNSEnter, NetdevSimDev
1421
from net.lib.py import EthtoolFamily, NetdevFamily, NetshaperFamily, \
1522
NlError, RtnlFamily, DevlinkFamily, PSPFamily
1623
from net.lib.py import CmdExitFailure
1724
from net.lib.py import bkg, cmd, bpftool, bpftrace, defer, ethtool, \
1825
fd_read_timeout, ip, rand_port, tool, wait_port_listen, wait_file
19-
from net.lib.py import fd_read_timeout
2026
from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx
2127
from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \
2228
ksft_setup
2329
from net.lib.py import ksft_eq, ksft_ge, ksft_in, ksft_is, ksft_lt, \
2430
ksft_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt, ksft_not_none
31+
32+
__all__ = ["NetNS", "NetNSEnter", "NetdevSimDev",
33+
"EthtoolFamily", "NetdevFamily", "NetshaperFamily",
34+
"NlError", "RtnlFamily", "DevlinkFamily", "PSPFamily",
35+
"CmdExitFailure",
36+
"bkg", "cmd", "bpftool", "bpftrace", "defer", "ethtool",
37+
"fd_read_timeout", "ip", "rand_port", "tool",
38+
"wait_port_listen", "wait_file",
39+
"KsftSkipEx", "KsftFailEx", "KsftXfailEx",
40+
"ksft_disruptive", "ksft_exit", "ksft_pr", "ksft_run",
41+
"ksft_setup",
42+
"ksft_eq", "ksft_ge", "ksft_in", "ksft_is", "ksft_lt",
43+
"ksft_ne", "ksft_not_in", "ksft_raises", "ksft_true", "ksft_gt",
44+
"ksft_not_none", "ksft_not_none"]
45+
46+
from .env import NetDrvEnv, NetDrvEpEnv
47+
from .load import GenerateTraffic
48+
from .remote import Remote
49+
50+
__all__ += ["NetDrvEnv", "NetDrvEpEnv", "GenerateTraffic", "Remote"]
2551
except ModuleNotFoundError as e:
26-
ksft_pr("Failed importing `net` library from kernel sources")
27-
ksft_pr(str(e))
28-
ktap_result(True, comment="SKIP")
52+
print("Failed importing `net` library from kernel sources")
53+
print(str(e))
2954
sys.exit(4)
30-
31-
from .env import *
32-
from .load import *
33-
from .remote import Remote

0 commit comments

Comments
 (0)