2022-08-08 14:49:08 +00:00
|
|
|
import logging
|
|
|
|
from http import HTTPStatus
|
|
|
|
from re import match
|
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
|
|
|
import requests
|
2022-10-09 20:01:59 +00:00
|
|
|
from binary_version_helper import get_remote_binaries_versions
|
2022-08-08 14:49:08 +00:00
|
|
|
from common import BIN_VERSIONS_FILE
|
2022-08-08 16:51:28 +00:00
|
|
|
from env_properties import read_env_properties, save_env_properties
|
2023-01-09 12:46:03 +00:00
|
|
|
from frostfs_testlib.hosting import Hosting
|
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
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.title("Check binaries versions")
|
2022-11-10 05:27:52 +00:00
|
|
|
@pytest.mark.sanity
|
2022-08-08 14:49:08 +00:00
|
|
|
@pytest.mark.check_binaries
|
2022-09-28 12:07:16 +00:00
|
|
|
@pytest.mark.skip("Skipped due to https://j.yadro.com/browse/OBJECT-628")
|
2022-10-09 20:01:59 +00:00
|
|
|
def test_binaries_versions(request, hosting: Hosting):
|
2022-08-08 14:49:08 +00:00
|
|
|
"""
|
|
|
|
Compare binaries versions from external source (url) and deployed on servers.
|
|
|
|
"""
|
|
|
|
if not BIN_VERSIONS_FILE:
|
2022-09-28 12:07:16 +00:00
|
|
|
pytest.skip("File with binaries and versions was not provided")
|
2022-08-08 14:49:08 +00:00
|
|
|
|
|
|
|
binaries_to_check = download_versions_info(BIN_VERSIONS_FILE)
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.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
|
|
|
|
2022-08-08 16:51:28 +00:00
|
|
|
env_properties = read_env_properties(request.config)
|
2022-08-08 14:49:08 +00:00
|
|
|
|
|
|
|
# compare versions from servers and file
|
2022-08-08 16:51:28 +00:00
|
|
|
failed_versions = {}
|
|
|
|
additional_env_properties = {}
|
2022-08-08 14:49:08 +00:00
|
|
|
for binary, version in binaries_to_check.items():
|
2022-08-08 16:51:28 +00:00
|
|
|
actual_version = got_versions.get(binary)
|
|
|
|
if actual_version != version:
|
2022-09-28 12:07:16 +00:00
|
|
|
failed_versions[binary] = f"Expected version {version}, found version {actual_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
|
|
|
|
if env_properties and binary not in env_properties:
|
|
|
|
additional_env_properties[binary] = actual_version
|
2022-08-08 14:49:08 +00:00
|
|
|
|
2022-08-08 16:51:28 +00:00
|
|
|
if env_properties and additional_env_properties:
|
|
|
|
save_env_properties(request.config, additional_env_properties)
|
2022-08-08 14:49:08 +00:00
|
|
|
|
|
|
|
# create clear beautiful error with aggregation info
|
|
|
|
if failed_versions:
|
2022-09-28 12:07:16 +00:00
|
|
|
msg = "\n".join({f"{binary}: {error}" for binary, error in failed_versions.items()})
|
|
|
|
raise AssertionError(f"Found binaries with unexpected versions:\n{msg}")
|
2022-08-08 14:49:08 +00:00
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.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)
|
|
|
|
|
2022-09-28 12:07:16 +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
|