Commit 29604bc2 authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

selftests: drv-net: factor out a DrvEnv base class



We have separate Env classes for local tests and tests with a remote
endpoint. Make it easier to share the code by creating a base class.
Make env loading a method of this class.

Reviewed-by: default avatarPetr Machata <petrm@nvidia.com>
Link: https://patch.msgid.link/20250207184140.1730466-1-kuba@kernel.org


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent a980da54
Loading
Loading
Loading
Loading
+35 −28
Original line number Diff line number Diff line
@@ -10,10 +10,18 @@ from lib.py import NetNS, NetdevSimDev
from .remote import Remote


def _load_env_file(src_path):
class NetDrvEnvBase:
    """
    Base class for a NIC / host envirnoments
    """
    def __init__(self, src_path):
        self.src_path = src_path
        self.env = self._load_env_file()

    def _load_env_file(self):
        env = os.environ.copy()

    src_dir = Path(src_path).parent.resolve()
        src_dir = Path(self.src_path).parent.resolve()
        if not (src_dir / "net.config").exists():
            return ksft_setup(env)

@@ -34,14 +42,14 @@ def _load_env_file(src_path):
        return ksft_setup(env)


class NetDrvEnv:
class NetDrvEnv(NetDrvEnvBase):
    """
    Class for a single NIC / host env, with no remote end
    """
    def __init__(self, src_path, **kwargs):
        self._ns = None
        super().__init__(src_path)

        self.env = _load_env_file(src_path)
        self._ns = None

        if 'NETIF' in self.env:
            self.dev = ip("link show dev " + self.env['NETIF'], json=True)[0]
@@ -68,7 +76,7 @@ class NetDrvEnv:
            self._ns = None


class NetDrvEpEnv:
class NetDrvEpEnv(NetDrvEnvBase):
    """
    Class for an environment with a local device and "remote endpoint"
    which can be used to send traffic in.
@@ -82,8 +90,7 @@ class NetDrvEpEnv:
    nsim_v6_pfx = "2001:db8::"

    def __init__(self, src_path, nsim_test=None):

        self.env = _load_env_file(src_path)
        super().__init__(src_path)

        self._stats_settle_time = None