Source code for fortrace.utility.server_interaction.server_interaction

import abc
from enum import Enum, auto

from fortrace.core.virsh_domain import VirshDomain
from fortrace.utility.logger_helper import setup_logger

logger = setup_logger(__name__)


[docs] class ServerFeedback(Enum): FILE_NOT_FOUND = auto() USER_HAS_NO_FILES = ( auto() ) # use this, if generated_files for the user is empty but a file retrieve is requested
[docs] class GenericServerInteraction(abc.ABC): """Generic interface for the Generator to perform interactions with services offered by servers. Attributes: _login_data: dict containing username <-> password entries """ _login_data: dict[str, str] def __init__(self, server: VirshDomain, config: dict): """Create an object for the generator component to simulate a server interaction Args: server: handle to the running server domain (pty should be free to use) config: configuration of the server domain (plain config, no subsection of it) """ self._domain = server self._config = config self._server_config = self._config["domain"]["server"] self._login_data = {}
[docs] @abc.abstractmethod def perform_interaction(self, action: dict) -> ServerFeedback | None: """Method to be called by the generator component. It is allowed to generate a random action inside, e.g., choose whether to store or retrieve a file) Args: action: dictionary describing the action. Orientate on action design of Generator Returns: ServerFeedback to communicate back to the generator (or None, if there is nothing to tell the generator) """ pass
def _extract_login_data(self): # TODO: this seems to be redundant -> use dict directly? for user in self._server_config.get("users", {}): self._login_data[user["username"]] = user["password"]