2022-08-08 14:49:08 +00:00
|
|
|
import logging
|
2023-05-15 09:59:33 +00:00
|
|
|
import os
|
2022-08-08 14:49:08 +00:00
|
|
|
from http import HTTPStatus
|
2023-11-02 09:19:23 +00:00
|
|
|
from re import fullmatch, match
|
2022-08-08 14:49:08 +00:00
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
|
|
|
import requests
|
2023-11-29 13:34:59 +00:00
|
|
|
from frostfs_testlib import reporter
|
2023-01-09 12:46:03 +00:00
|
|
|
from frostfs_testlib.hosting import Hosting
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.resources.common import ASSETS_DIR
|
|
|
|
from frostfs_testlib.utils.env_utils import read_env_properties, save_env_properties
|
|
|
|
from frostfs_testlib.utils.version_utils import get_remote_binaries_versions
|
|
|
|
from pytest import FixtureRequest
|
2022-08-08 14:49:08 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
logger = logging.getLogger("NeoLogger")
|
2022-08-08 14:49:08 +00:00
|
|
|
|
2023-11-02 09:19:23 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.title("Check binaries versions")
|
2022-08-08 14:49:08 +00:00
|
|
|
@pytest.mark.check_binaries
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_binaries_versions(request: FixtureRequest, hosting: Hosting):
|
2022-08-08 14:49:08 +00:00
|
|
|
"""
|
|
|
|
Compare binaries versions from external source (url) and deployed on servers.
|
|
|
|
"""
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Get binaries versions from servers"):
|
2022-10-09 20:01:59 +00:00
|
|
|
got_versions = get_remote_binaries_versions(hosting)
|
2022-08-08 14:49:08 +00:00
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
environment_dir = request.config.getoption("--alluredir") or ASSETS_DIR
|
|
|
|
env_file = os.path.join(environment_dir, "environment.properties")
|
|
|
|
env_properties = read_env_properties(env_file)
|
2022-08-08 14:49:08 +00:00
|
|
|
|
|
|
|
# compare versions from servers and file
|
2023-08-03 09:41:03 +00:00
|
|
|
exeptions = []
|
2022-08-08 16:51:28 +00:00
|
|
|
additional_env_properties = {}
|
2023-11-02 09:19:23 +00:00
|
|
|
|
2023-11-24 16:50:47 +00:00
|
|
|
for binary_name, binary in got_versions.items():
|
|
|
|
version = binary["version"]
|
|
|
|
requires_check = binary["check"]
|
|
|
|
if requires_check and not fullmatch(r"^\d+\.\d+\.\d+(-.*)?(?<!dirty)", version):
|
|
|
|
exeptions.append(f"{binary_name}: Actual version doesn't conform to format '0.0.0-000-aaaaaaa': {version}")
|
2022-08-08 14:49:08 +00:00
|
|
|
|
2022-08-08 16:51:28 +00:00
|
|
|
# If some binary was not listed in the env properties file, let's add it
|
|
|
|
# so that we have full information about versions in allure report
|
2023-11-24 16:50:47 +00:00
|
|
|
if env_properties and binary_name not in env_properties:
|
|
|
|
additional_env_properties[binary_name] = version
|
2022-08-08 14:49:08 +00:00
|
|
|
|
2022-08-08 16:51:28 +00:00
|
|
|
if env_properties and additional_env_properties:
|
2023-05-15 09:59:33 +00:00
|
|
|
save_env_properties(env_file, additional_env_properties)
|
2022-08-08 14:49:08 +00:00
|
|
|
|
|
|
|
# create clear beautiful error with aggregation info
|
2023-08-03 09:41:03 +00:00
|
|
|
if exeptions:
|
|
|
|
msg = "\n".join(exeptions)
|
2022-09-28 12:07:16 +00:00
|
|
|
raise AssertionError(f"Found binaries with unexpected versions:\n{msg}")
|
2022-08-08 14:49:08 +00:00
|
|
|
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
@reporter.step("Download versions info from {url}")
|
2022-08-08 14:49:08 +00:00
|
|
|
def download_versions_info(url: str) -> dict:
|
|
|
|
binaries_to_version = {}
|
|
|
|
|
|
|
|
response = requests.get(url)
|
|
|
|
|
2023-11-02 09:19:23 +00:00
|
|
|
assert response.status_code == HTTPStatus.OK, f"Got {response.status_code} code. Content {response.json()}"
|
2022-08-08 14:49:08 +00:00
|
|
|
|
|
|
|
content = response.text
|
2022-09-28 12:07:16 +00:00
|
|
|
assert content, f"Expected file with content, got {response}"
|
2022-08-08 14:49:08 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
for line in content.split("\n"):
|
|
|
|
m = match("(.*)=(.*)", line)
|
2022-08-08 14:49:08 +00:00
|
|
|
if not m:
|
2022-09-28 12:07:16 +00:00
|
|
|
logger.warning(f"Could not get binary/version from {line}")
|
2022-08-08 14:49:08 +00:00
|
|
|
continue
|
|
|
|
bin_name, bin_version = m.group(1), m.group(2)
|
|
|
|
binaries_to_version[bin_name] = bin_version
|
|
|
|
|
|
|
|
return binaries_to_version
|