diff --git a/lnst/Tests/PktGen.py b/lnst/Tests/PktGen.py index f7381da3a..7d34cd7d7 100644 --- a/lnst/Tests/PktGen.py +++ b/lnst/Tests/PktGen.py @@ -1,7 +1,7 @@ import re import time import logging -from subprocess import Popen +from subprocess import Popen, check_output, CalledProcessError from threading import Thread from typing import Iterator, Union @@ -139,9 +139,7 @@ def __init__(self, **kwargs): self._output_parser = None def run(self): - if not kmod_loaded("pktgen"): - raise TestModuleError("pktgen module is not loaded") - + self._load_pktgen_module() self._pg_ctrl("reset") self._configure_generator() @@ -161,6 +159,15 @@ def run(self): self._deconfigure_generator() return True + def _load_pktgen_module(self): + try: + check_output(["/usr/sbin/modprobe", "pktgen"]) + except CalledProcessError as e: + logging.debug(f"Modprobe of pktgen failed {e.output}") + + if not kmod_loaded("pktgen"): + raise TestModuleError("pktgen module is not loaded") + def _configure_generator(self): logging.debug("Configuring generator")