From 6f99aef4065a8ab045cc7ea483252bbd63284954 Mon Sep 17 00:00:00 2001 From: Kirill Sosnovskikh Date: Tue, 16 Jul 2024 13:36:02 +0300 Subject: [PATCH] [#263] Unify version parsing Function `_parse_version` renamed to `parse_version` and changed regex for version parsing Signed-off-by: Kirill Sosnovskikh --- src/frostfs_testlib/utils/version_utils.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/frostfs_testlib/utils/version_utils.py b/src/frostfs_testlib/utils/version_utils.py index 7fcc9de..490abb0 100644 --- a/src/frostfs_testlib/utils/version_utils.py +++ b/src/frostfs_testlib/utils/version_utils.py @@ -18,14 +18,14 @@ def get_local_binaries_versions(shell: Shell) -> dict[str, str]: for binary in [NEOGO_EXECUTABLE, FROSTFS_AUTHMATE_EXEC]: out = shell.exec(f"{binary} --version").stdout - versions[binary] = _parse_version(out) + versions[binary] = parse_version(out) frostfs_cli = FrostfsCli(shell, FROSTFS_CLI_EXEC) - versions[FROSTFS_CLI_EXEC] = _parse_version(frostfs_cli.version.get().stdout) + versions[FROSTFS_CLI_EXEC] = parse_version(frostfs_cli.version.get().stdout) try: frostfs_adm = FrostfsAdm(shell, FROSTFS_ADM_EXEC) - versions[FROSTFS_ADM_EXEC] = _parse_version(frostfs_adm.version.get().stdout) + versions[FROSTFS_ADM_EXEC] = parse_version(frostfs_adm.version.get().stdout) except RuntimeError: logger.info(f"{FROSTFS_ADM_EXEC} not installed") @@ -63,7 +63,7 @@ def parallel_binary_verions(host: Host) -> dict[str, str]: binary_path = binary["exec_path"] try: result = shell.exec(f"{binary_path} {binary['param']}") - version = _parse_version(result.stdout) or _parse_version(result.stderr) or "Unknown" + version = parse_version(result.stdout) or parse_version(result.stderr) or "Unknown" versions_at_host[binary_name] = version except Exception as exc: logger.error(f"Cannot get version for {binary_path} because of\n{exc}") @@ -85,6 +85,6 @@ def get_remote_binaries_versions(hosting: Hosting) -> dict[str, dict[str, str]]: return versions_by_host -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 +def parse_version(version_output: str) -> str: + version = re.search(r"(?<=version[:=])\s?[\"\']?v?(.+)", version_output, re.IGNORECASE) + return version.group(1).strip("\"'\n\t ") if version else version_output