[#189] Add setup step to check binaries versions

Signed-off-by: Liza <e.chichindaeva@yadro.com>
Elizaveta Chichindaeva 2024-03-04 17:01:24 +03:00
parent 09a7f66d1e
commit f6a7f82701
1 changed files with 19 additions and 11 deletions

View File

@ -1,6 +1,7 @@
import logging
import re
from frostfs_testlib import reporter
from frostfs_testlib.cli import FrostfsAdm, FrostfsCli
from frostfs_testlib.hosting import Host, Hosting
from frostfs_testlib.resources.cli import FROSTFS_ADM_EXEC, FROSTFS_AUTHMATE_EXEC, FROSTFS_CLI_EXEC, NEOGO_EXECUTABLE
@ -11,6 +12,7 @@ from frostfs_testlib.testing.parallel import parallel
logger = logging.getLogger("NeoLogger")
@reporter.step("Get local binaries versions")
def get_local_binaries_versions(shell: Shell) -> dict[str, str]:
versions = {}
@ -30,13 +32,14 @@ def get_local_binaries_versions(shell: Shell) -> dict[str, str]:
out = shell.exec("aws --version").stdout
out_lines = out.split("\n")
versions["AWS"] = out_lines[0] if out_lines else "Unknown"
logger.info(f"Local binaries version: {out_lines[0]}")
return versions
def parallel_binary_verions(host: Host) -> dict[str, str]:
versions_by_host = {}
binary_path_by_name = {} # Maps binary name to executable path
for service_config in host.config.services:
exec_path = service_config.attributes.get("exec_path")
@ -65,8 +68,9 @@ def parallel_binary_verions(host: Host) -> dict[str, str]:
versions_at_host[binary_name] = {"version": "Unknown", "check": binary["check"]}
versions_by_host[host.config.address] = versions_at_host
return versions_by_host
@reporter.step("Get remote binaries versions")
def get_remote_binaries_versions(hosting: Hosting) -> dict[str, str]:
versions_by_host = {}
future_binary_verions = parallel(parallel_binary_verions, parallel_items=hosting.hosts)
@ -83,26 +87,30 @@ def get_remote_binaries_versions(hosting: Hosting) -> dict[str, str]:
for host, binary_versions in versions_by_host.items():
for name, binary in binary_versions.items():
version = binary["version"]
if not cheak_versions.get(f'{name[:-2]}', None):
captured_version = cheak_versions.get(f'{name[:-2]}',{}).get(host, {}).get(captured_version)
cheak_versions[f'{name[:-2]}'] = {host: {version: name}}
if not cheak_versions.get(f"{name[:-2]}", None):
captured_version = cheak_versions.get(f"{name[:-2]}", {}).get(host, {}).get(captured_version)
cheak_versions[f"{name[:-2]}"] = {host: {version: name}}
else:
captured_version = list(cheak_versions.get(f'{name[:-2]}',{}).get(previous_host).keys())[0]
cheak_versions[f'{name[:-2]}'].update({host:{version:name}})
captured_version = list(cheak_versions.get(f"{name[:-2]}", {}).get(previous_host).keys())[0]
cheak_versions[f"{name[:-2]}"].update({host: {version: name}})
if captured_version and captured_version != version:
exception.add(name[:-2])
versions[name] = {"version": version, "check": binary["check"]}
previous_host = host
logger.info(
"Remote binaries versions:\n" + "\n".join([f"{key} ver: {value['version']}" for key, value in versions.items()])
)
if exception:
for i in exception:
for host in versions_by_host.keys():
for version, name in cheak_versions.get(i).get(host).items():
exсeptions.append(f'Binary {name} has inconsistent version {version} on host {host}')
exсeptions.append('\n')
exсeptions.append(f"Binary {name} has inconsistent version {version} on host {host}")
exсeptions.append("\n")
return versions, exсeptions
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 version_output