diff --git a/dts/framework/remote_session/linux_session.py b/dts/framework/remote_session/linux_session.py index f13f399121..f64aa8efb0 100644 --- a/dts/framework/remote_session/linux_session.py +++ b/dts/framework/remote_session/linux_session.py @@ -14,7 +14,8 @@ class LinuxSession(PosixSession): The implementation of non-Posix compliant parts of Linux remote sessions. """ - def _get_privileged_command(self, command: str) -> str: + @staticmethod + def _get_privileged_command(command: str) -> str: return f"sudo -- sh -c '{command}'" def get_remote_cpus(self, use_first_core: bool) -> list[LogicalCore]: diff --git a/dts/framework/remote_session/os_session.py b/dts/framework/remote_session/os_session.py index f03275b21d..dad8d4da1b 100644 --- a/dts/framework/remote_session/os_session.py +++ b/dts/framework/remote_session/os_session.py @@ -100,8 +100,9 @@ def create_interactive_shell( timeout, ) + @staticmethod @abstractmethod - def _get_privileged_command(self, command: str) -> str: + def _get_privileged_command(command: str) -> str: """Modify the command so that it executes with administrative privileges. Args: diff --git a/dts/framework/remote_session/remote/interactive_shell.py b/dts/framework/remote_session/remote/interactive_shell.py index 4d9c7638a5..3512f1f8a9 100644 --- a/dts/framework/remote_session/remote/interactive_shell.py +++ b/dts/framework/remote_session/remote/interactive_shell.py @@ -22,7 +22,6 @@ class InteractiveShell: _app_args: str _default_prompt: str = "" _privileged: bool - _get_privileged_command: Callable[[str], str] # Allows for app specific extra characters to be appended to commands _command_extra_chars: str = "" path: PurePath @@ -34,7 +33,7 @@ def __init__( logger: DTSLOG, startup_command: str, privileged: bool, - _get_privileged_command: Callable[[str], str], + get_privileged_command: Callable[[str], str], app_args: str = "", timeout: float = SETTINGS.timeout, ) -> None: @@ -48,11 +47,10 @@ def __init__( self._timeout = timeout self._startup_command = startup_command self._app_args = app_args - self._get_privileged_command = _get_privileged_command # type: ignore self._privileged = privileged - self._start_application() + self._start_application(get_privileged_command) - def _start_application(self) -> None: + def _start_application(self, get_privileged_command: Callable[[str], str]) -> None: """Starts a new interactive application based on _startup_command. This method is often overridden by subclasses as their process for @@ -60,7 +58,7 @@ def _start_application(self) -> None: """ start_command = f"{self._startup_command} {self._app_args}" if self._privileged: - start_command = self._get_privileged_command(start_command) # type: ignore + start_command = get_privileged_command(start_command) self.send_command(start_command) def send_command(self, command: str, prompt: str | None = None) -> str: diff --git a/dts/framework/remote_session/remote/testpmd_shell.py b/dts/framework/remote_session/remote/testpmd_shell.py index 4abe70d421..af8ac2a057 100644 --- a/dts/framework/remote_session/remote/testpmd_shell.py +++ b/dts/framework/remote_session/remote/testpmd_shell.py @@ -2,6 +2,7 @@ # Copyright(c) 2023 University of New Hampshire from pathlib import PurePath +from typing import Callable from .interactive_shell import InteractiveShell @@ -24,10 +25,10 @@ class TestPmdShell(InteractiveShell): "\n" # We want to append an extra newline to every command ) - def _start_application(self) -> None: + def _start_application(self, get_privileged_command: Callable[[str], str]) -> None: """See "_start_application" in InteractiveShell.""" self._app_args += " -- -i" - super()._start_application() + super()._start_application(get_privileged_command) def get_devices(self) -> list[TestPmdDevice]: """Get a list of device names that are known to testpmd