forked from TrueCloudLab/frostfs-testlib
Implement basic version of local shell
Also added two simple reporters that can be used by the shell to report command execution details. Signed-off-by: Vladimir Domnich <v.domnich@yadro.com>
This commit is contained in:
parent
c0bbfd1705
commit
f6ee129354
11 changed files with 453 additions and 0 deletions
59
shell/interfaces.py
Normal file
59
shell/interfaces.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@dataclass
|
||||
class InteractiveInput:
|
||||
"""
|
||||
Interactive input for a shell command.
|
||||
|
||||
:attr str prompt_pattern: regular expression that defines expected prompt from the command.
|
||||
:attr str input: user input that should be supplied to the command in response to the prompt.
|
||||
"""
|
||||
prompt_pattern: str
|
||||
input: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class CommandOptions:
|
||||
"""
|
||||
Options that control command execution.
|
||||
|
||||
:attr list interactive_inputs: user inputs that should be interactively supplied to
|
||||
the command during its' execution.
|
||||
:attr int timeout: timeout for command execution (in seconds).
|
||||
:attr bool check: controls whether to check return code of the command. Set to False to
|
||||
ignore non-zero return codes.
|
||||
"""
|
||||
interactive_inputs: Optional[list[InteractiveInput]] = None
|
||||
timeout: int = 30
|
||||
check: bool = True
|
||||
|
||||
|
||||
@dataclass
|
||||
class CommandResult:
|
||||
"""
|
||||
Represents a result of a command executed via shell.
|
||||
"""
|
||||
stdout: str
|
||||
stderr: str
|
||||
return_code: int
|
||||
|
||||
|
||||
class Shell(ABC):
|
||||
"""
|
||||
Interface of a command shell on some system (local or remote).
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def exec(self, command: str, options: Optional[CommandOptions] = None) -> CommandResult:
|
||||
"""
|
||||
Executes specified command on this shell. To execute interactive command, user inputs
|
||||
should be specified in *options*.
|
||||
|
||||
:param str command: command to execute on the shell.
|
||||
:param CommandOptions options: options that control command execution.
|
||||
:return command result.
|
||||
"""
|
||||
pass
|
Loading…
Add table
Add a link
Reference in a new issue