2022-10-09 20:01:59 +00:00
|
|
|
import logging
|
|
|
|
import re
|
|
|
|
|
2023-01-09 12:46:03 +00:00
|
|
|
from frostfs_testlib.cli import FrostfsAdm, FrostfsCli
|
|
|
|
from frostfs_testlib.hosting import Hosting
|
|
|
|
from frostfs_testlib.shell import Shell
|
2022-10-09 20:01:59 +00:00
|
|
|
|
2023-05-03 13:23:05 +00:00
|
|
|
from pytest_tests.resources.common import (
|
|
|
|
FROSTFS_ADM_EXEC,
|
|
|
|
FROSTFS_AUTHMATE_EXEC,
|
|
|
|
FROSTFS_CLI_EXEC,
|
|
|
|
NEOGO_EXECUTABLE,
|
|
|
|
WALLET_CONFIG,
|
|
|
|
)
|
2023-02-27 16:54:27 +00:00
|
|
|
|
2022-10-09 20:01:59 +00:00
|
|
|
logger = logging.getLogger("NeoLogger")
|
|
|
|
|
|
|
|
|
|
|
|
def get_local_binaries_versions(shell: Shell) -> dict[str, str]:
|
|
|
|
versions = {}
|
|
|
|
|
2023-05-03 13:23:05 +00:00
|
|
|
for binary in [NEOGO_EXECUTABLE, FROSTFS_AUTHMATE_EXEC]:
|
2022-10-09 20:01:59 +00:00
|
|
|
out = shell.exec(f"{binary} --version").stdout
|
|
|
|
versions[binary] = _parse_version(out)
|
|
|
|
|
2023-01-09 12:46:03 +00:00
|
|
|
frostfs_cli = FrostfsCli(shell, FROSTFS_CLI_EXEC, WALLET_CONFIG)
|
2023-05-03 13:23:05 +00:00
|
|
|
versions[FROSTFS_CLI_EXEC] = _parse_version(frostfs_cli.version.get().stdout)
|
2022-10-09 20:01:59 +00:00
|
|
|
|
|
|
|
try:
|
2023-01-09 12:46:03 +00:00
|
|
|
frostfs_adm = FrostfsAdm(shell, FROSTFS_ADM_EXEC)
|
2023-05-03 13:23:05 +00:00
|
|
|
versions[FROSTFS_ADM_EXEC] = _parse_version(frostfs_adm.version.get().stdout)
|
2022-10-09 20:01:59 +00:00
|
|
|
except RuntimeError:
|
2023-05-03 13:23:05 +00:00
|
|
|
logger.info("frostfs-adm not installed")
|
2022-10-09 20:01:59 +00:00
|
|
|
|
|
|
|
out = shell.exec("aws --version").stdout
|
|
|
|
out_lines = out.split("\n")
|
|
|
|
versions["AWS"] = out_lines[0] if out_lines else "Unknown"
|
|
|
|
|
|
|
|
return versions
|
|
|
|
|
|
|
|
|
|
|
|
def get_remote_binaries_versions(hosting: Hosting) -> dict[str, str]:
|
|
|
|
versions_by_host = {}
|
|
|
|
for host in hosting.hosts:
|
2022-10-13 16:13:45 +00:00
|
|
|
binary_path_by_name = {} # Maps binary name to executable path
|
2022-10-09 20:01:59 +00:00
|
|
|
for service_config in host.config.services:
|
|
|
|
exec_path = service_config.attributes.get("exec_path")
|
|
|
|
if exec_path:
|
2022-10-13 16:13:45 +00:00
|
|
|
binary_path_by_name[service_config.name] = exec_path
|
2022-10-09 20:01:59 +00:00
|
|
|
for cli_config in host.config.clis:
|
2022-10-13 16:13:45 +00:00
|
|
|
binary_path_by_name[cli_config.name] = cli_config.exec_path
|
2022-10-09 20:01:59 +00:00
|
|
|
|
|
|
|
shell = host.get_shell()
|
|
|
|
versions_at_host = {}
|
2022-10-13 16:13:45 +00:00
|
|
|
for binary_name, binary_path in binary_path_by_name.items():
|
2022-10-09 20:01:59 +00:00
|
|
|
try:
|
2022-10-13 16:13:45 +00:00
|
|
|
result = shell.exec(f"{binary_path} --version")
|
|
|
|
versions_at_host[binary_name] = _parse_version(result.stdout)
|
2022-10-09 20:01:59 +00:00
|
|
|
except Exception as exc:
|
2022-10-13 16:13:45 +00:00
|
|
|
logger.error(f"Cannot get version for {binary_path} because of\n{exc}")
|
|
|
|
versions_at_host[binary_name] = "Unknown"
|
2022-10-09 20:01:59 +00:00
|
|
|
versions_by_host[host.config.address] = versions_at_host
|
|
|
|
|
|
|
|
# Consolidate versions across all hosts
|
|
|
|
versions = {}
|
|
|
|
for host, binary_versions in versions_by_host.items():
|
|
|
|
for name, version in binary_versions.items():
|
|
|
|
captured_version = versions.get(name)
|
|
|
|
if captured_version:
|
2022-10-13 16:13:45 +00:00
|
|
|
assert (
|
|
|
|
captured_version == version
|
|
|
|
), f"Binary {name} has inconsistent version on host {host}"
|
2022-10-09 20:01:59 +00:00
|
|
|
else:
|
|
|
|
versions[name] = version
|
|
|
|
return versions
|
|
|
|
|
|
|
|
|
|
|
|
def _parse_version(version_output: str) -> str:
|
|
|
|
version = re.search(r"version[:\s]*v?(.+)", version_output, re.IGNORECASE)
|
|
|
|
return version.group(1).strip() if version else "Unknown"
|