frostfs-testcases/pytest_tests/testsuites/services/test_binaries.py
a.berezin 439a5595f8 [#252] Refactor version checks
Signed-off-by: a.berezin <a.berezin@yadro.com>
2024-06-07 17:20:50 +03:00

42 lines
1.6 KiB
Python

import logging
from re import fullmatch
import allure
import pytest
from frostfs_testlib import reporter
from frostfs_testlib.hosting import Hosting
from frostfs_testlib.utils.version_utils import get_remote_binaries_versions
logger = logging.getLogger("NeoLogger")
VERSION_REGEX = r"^([a-zA-Z0-9]*/)?\d+\.\d+\.\d+(-.*)?(?<!dirty)"
VERSION_ERROR_MSG = "{name} [{host}]: Actual version doesn't conform to format '0.0.0-000-aaaaaaa': {version}"
def _check_version_format(version):
return fullmatch(VERSION_REGEX, version)
@allure.title("Check binaries versions")
@pytest.mark.check_binaries
def test_binaries_versions(hosting: Hosting):
"""
Compare binaries versions from external source (url) and deployed on servers.
"""
with reporter.step("Get binaries versions from servers"):
versions_by_host = get_remote_binaries_versions(hosting)
exсeptions = []
last_host, versions_on_last_host = versions_by_host.popitem()
for name, version in versions_on_last_host.items():
for host, versions_on_host in versions_by_host.items():
if versions_on_host[name] != version:
exсeptions.append(f"Binary of {name} has inconsistent version {versions_on_host[name]} on host {host}")
if not _check_version_format(versions_on_host[name]):
exсeptions.append(VERSION_ERROR_MSG.format(name=name, host=host, version=version))
if not _check_version_format(version):
exсeptions.append(VERSION_ERROR_MSG.format(name=name, host=last_host, version=version))
assert not exсeptions, "\n".join(exсeptions)