taolib.testing.remote#

远端 SSH 自动化接口集合。

提供 SSH 配置读取/脱敏、prefix 上下文管理与远端探测接口(可注入 connection_factory 便于测试)。 更完整的使用说明见文档:doc/libs/python/Fabric/taolib_remote.md。

Submodules#

Attributes#

Exceptions#

RemoteConfigError

配置不合法或缺失导致的错误。

RemoteDependencyError

依赖缺失或版本不兼容导致的错误。

RemoteExecutionError

远端命令执行失败导致的错误。

Classes#

SshConfig

SSH 连接配置结构(与 Fabric Connection 的关键字参数兼容)。

RemoteProbeCommands

远端探测使用的命令集合。

RemoteProber

远端探测执行器(可注入连接工厂,便于测试与扩展)。

RemoteProbeReport

远端探测结果。

RemoteProbeRunOptions

远端命令执行选项与错误处理策略。

Functions#

load_ssh_config(→ SshConfig)

从 TOML 读取 SSH 连接配置(返回深拷贝)。

redact_ssh_config(→ dict[str, Any])

脱敏 SSH 配置,避免输出敏感字段。

probe_remote(...)

兼容接口:连接远端并执行探测命令,返回结构化结果。

remote_prefixes(→ collections.abc.Iterator[None])

在同一个命令执行上下文中叠加多个 prefix。

Package Contents#

class taolib.testing.remote.SshConfig#

Bases: TypedDict

SSH 连接配置结构(与 Fabric Connection 的关键字参数兼容)。

host: str#
user: str#
port: int#
connect_kwargs: dict[str, Any]#
taolib.testing.remote.load_ssh_config(config_path: str | pathlib.Path) SshConfig#

从 TOML 读取 SSH 连接配置(返回深拷贝)。

taolib.testing.remote.redact_ssh_config(config: SshConfig | dict[str, Any]) dict[str, Any]#

脱敏 SSH 配置,避免输出敏感字段。

exception taolib.testing.remote.RemoteConfigError#

Bases: RemoteError

配置不合法或缺失导致的错误。

exception taolib.testing.remote.RemoteDependencyError#

Bases: RemoteError

依赖缺失或版本不兼容导致的错误。

exception taolib.testing.remote.RemoteExecutionError(message: str, *, command: str | None = None)#

Bases: RemoteError

远端命令执行失败导致的错误。

command = None#
taolib.testing.remote.DEFAULT_CONDA_ACTIVATE_CMD#
taolib.testing.remote.DEFAULT_ENCODING#
taolib.testing.remote.DEFAULT_PROBE_CMD#
taolib.testing.remote.DEFAULT_TOOLS_ENV_CMD#
class taolib.testing.remote.RemoteProbeCommands#

远端探测使用的命令集合。

命令分为两类: - prefix 命令:tools_env_cmd、conda_activate_cmd,会在同一执行上下文中叠加生效; - 常规命令:uname_cmd、check_conda_cmd、probe_cmd,会在远端依次运行。

tools_env_cmd: str#
conda_activate_cmd: str#
probe_cmd: str#
check_conda_cmd: str = 'command -v conda'#
uname_cmd: str = 'uname -a'#
class taolib.testing.remote.RemoteProber#

远端探测执行器(可注入连接工厂,便于测试与扩展)。

connection_factory: taolib.testing.remote.connection.ConnectionFactory | None = None#
commands: taolib.testing.remote.probe_models.RemoteProbeCommands#
options: taolib.testing.remote.probe_models.RemoteProbeRunOptions#
probe(ssh_config: collections.abc.Mapping[str, Any]) taolib.testing.remote.probe_models.RemoteProbeReport#
class taolib.testing.remote.RemoteProbeReport#

远端探测结果。

语义约定: - conda_available=False 时,不会尝试执行 probe_cmd(probe_attempted=False, probe_ok=None)。 - conda_available=True 且 probe_attempted=True 时,probe_ok 表示探测命令退出状态是否成功。

uname: str#
conda_available: bool#
probe_attempted: bool#
probe_ok: bool | None#
class taolib.testing.remote.RemoteProbeRunOptions#

远端命令执行选项与错误处理策略。

encoding 与 run_kwargs 会被合并用于 Connection.run(...)。 raise_on_* 用于控制缺少 conda 或 probe 失败时,是返回结构化结果还是抛出异常。 timeout 用于设置命令执行超时时间(秒)。 retry 用于设置命令执行失败时的最大重试次数。 retry_delay 用于设置重试间隔时间(秒)。

encoding: str#
run_kwargs: collections.abc.Mapping[str, Any] | None = None#
raise_on_conda_missing: bool = False#
raise_on_probe_failure: bool = False#
timeout: int | None = None#
retry: int = 0#
retry_delay: float = 1.0#
merged_run_kwargs() dict[str, Any]#
taolib.testing.remote.probe_remote(ssh_config: collections.abc.Mapping[str, Any], *, tools_env_cmd: str = DEFAULT_TOOLS_ENV_CMD, conda_activate_cmd: str = DEFAULT_CONDA_ACTIVATE_CMD, probe_cmd: str = DEFAULT_PROBE_CMD, encoding: str = DEFAULT_ENCODING, check_conda_cmd: str = 'command -v conda', uname_cmd: str = 'uname -a', connection_factory: taolib.testing.remote.connection.ConnectionFactory | None = None, run_kwargs: collections.abc.Mapping[str, Any] | None = None, raise_on_conda_missing: bool = False, raise_on_probe_failure: bool = False, timeout: int | None = None, retry: int = 0) taolib.testing.remote.probe_models.RemoteProbeReport#

兼容接口:连接远端并执行探测命令,返回结构化结果。

参数:
  • ssh_config -- SSH 配置映射,包含 host、user 等信息。

  • tools_env_cmd -- 工具环境配置命令,默认为 DEFAULT_TOOLS_ENV_CMD。

  • conda_activate_cmd -- Conda 激活命令,默认为 DEFAULT_CONDA_ACTIVATE_CMD。

  • probe_cmd -- 探测命令,默认为 DEFAULT_PROBE_CMD。

  • encoding -- 输出编码,默认为 'utf-8'。

  • check_conda_cmd -- 检查 conda 是否可用的命令。

  • uname_cmd -- 获取系统信息的命令。

  • connection_factory -- 连接工厂,可用于注入自定义连接行为。

  • run_kwargs -- 额外的运行参数。

  • raise_on_conda_missing -- conda 缺失时是否抛出异常。

  • raise_on_probe_failure -- 探测失败时是否抛出异常。

  • timeout -- 命令执行超时时间(秒)。

  • retry -- 命令执行失败时的最大重试次数。

返回:

包含探测结果的报告对象。

返回类型:

RemoteProbeReport

抛出:
taolib.testing.remote.remote_prefixes(connection: SupportsPrefix, *prefix_cmds: str) collections.abc.Iterator[None]#

在同一个命令执行上下文中叠加多个 prefix。