From 6e394f9558c8d48a0a857a40043b4e8599227d86 Mon Sep 17 00:00:00 2001 From: Jan Tluka Date: Wed, 4 Sep 2024 11:42:15 +0200 Subject: [PATCH] Tests/PktGen: load pktgen module Signed-off-by: Jan Tluka --- lnst/Tests/PktGen.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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")