forked from TrueCloudLab/frostfs-testcases
Refactor env properties
Encapculate reading/writing environment.properties in helper. Signed-off-by: Vladimir Domnich <v.domnich@yadro.com>
This commit is contained in:
parent
9fea2efe83
commit
d6861f4f62
3 changed files with 59 additions and 34 deletions
40
pytest_tests/helpers/env_properties.py
Normal file
40
pytest_tests/helpers/env_properties.py
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
|
import allure
|
||||||
|
from pytest import Config
|
||||||
|
|
||||||
|
logger = logging.getLogger('NeoLogger')
|
||||||
|
|
||||||
|
|
||||||
|
@allure.step('Read environment.properties')
|
||||||
|
def read_env_properties(config: Config) -> dict:
|
||||||
|
environment_dir = config.getoption('--alluredir')
|
||||||
|
if not environment_dir:
|
||||||
|
return None
|
||||||
|
|
||||||
|
file_path = f'{environment_dir}/environment.properties'
|
||||||
|
with open(file_path, 'r') as file:
|
||||||
|
raw_content = file.read()
|
||||||
|
|
||||||
|
env_properties = {}
|
||||||
|
for line in raw_content.split('\n'):
|
||||||
|
m = re.match('(.*?)=(.*)', line)
|
||||||
|
if not m:
|
||||||
|
logger.warning(f'Could not parse env property from {line}')
|
||||||
|
continue
|
||||||
|
key, value = m.group(1), m.group(2)
|
||||||
|
env_properties[key] = value
|
||||||
|
return env_properties
|
||||||
|
|
||||||
|
|
||||||
|
@allure.step('Update data in environment.properties')
|
||||||
|
def save_env_properties(config: Config, env_data: dict) -> None:
|
||||||
|
environment_dir = config.getoption('--alluredir')
|
||||||
|
if not environment_dir:
|
||||||
|
return None
|
||||||
|
|
||||||
|
file_path = f'{environment_dir}/environment.properties'
|
||||||
|
with open(file_path, 'a+') as env_file:
|
||||||
|
for env, env_value in env_data.items():
|
||||||
|
env_file.write(f'{env}={env_value}\n')
|
|
@ -11,6 +11,7 @@ import wallet
|
||||||
from cli_helpers import _cmd_run
|
from cli_helpers import _cmd_run
|
||||||
from common import (ASSETS_DIR, FREE_STORAGE, INFRASTRUCTURE_TYPE, MAINNET_WALLET_PATH,
|
from common import (ASSETS_DIR, FREE_STORAGE, INFRASTRUCTURE_TYPE, MAINNET_WALLET_PATH,
|
||||||
NEOFS_NETMAP_DICT)
|
NEOFS_NETMAP_DICT)
|
||||||
|
from env_properties import save_env_properties
|
||||||
from payment_neogo import neofs_deposit, transfer_mainnet_gas
|
from payment_neogo import neofs_deposit, transfer_mainnet_gas
|
||||||
from python_keywords.node_management import node_healthcheck
|
from python_keywords.node_management import node_healthcheck
|
||||||
from service_helper import get_storage_service_helper
|
from service_helper import get_storage_service_helper
|
||||||
|
@ -37,23 +38,19 @@ def cloud_infrastructure_check():
|
||||||
def check_binary_versions(request):
|
def check_binary_versions(request):
|
||||||
# Collect versions of local binaries
|
# Collect versions of local binaries
|
||||||
binaries = ['neo-go', 'neofs-cli', 'neofs-authmate']
|
binaries = ['neo-go', 'neofs-cli', 'neofs-authmate']
|
||||||
env_out = _get_binaries_version_local(binaries)
|
local_binaries = _get_binaries_version_local(binaries)
|
||||||
|
|
||||||
# Collect versions of remote binaries
|
# Collect versions of remote binaries
|
||||||
helper = get_storage_service_helper()
|
helper = get_storage_service_helper()
|
||||||
remote_binaries = helper.get_binaries_version()
|
remote_binaries = helper.get_binaries_version()
|
||||||
env_out = {**env_out, **remote_binaries}
|
all_binaries = {**local_binaries, **remote_binaries}
|
||||||
|
|
||||||
# Get version of aws binary
|
# Get version of aws binary
|
||||||
out = _cmd_run('aws --version')
|
out = _cmd_run('aws --version')
|
||||||
out_lines = out.split("\n")
|
out_lines = out.split("\n")
|
||||||
env_out["AWS"] = out_lines[0] if out_lines else 'Unknown'
|
all_binaries["AWS"] = out_lines[0] if out_lines else 'Unknown'
|
||||||
|
|
||||||
environment_dir = request.config.getoption('--alluredir')
|
save_env_properties(request.config, all_binaries)
|
||||||
if environment_dir:
|
|
||||||
with open(f'{environment_dir}/environment.properties', 'w') as out_file:
|
|
||||||
for env, env_value in env_out.items():
|
|
||||||
out_file.write(f'{env}={env_value}\n')
|
|
||||||
|
|
||||||
|
|
||||||
def _get_binaries_version_local(binaries: list) -> dict:
|
def _get_binaries_version_local(binaries: list) -> dict:
|
||||||
|
|
|
@ -7,6 +7,7 @@ import pytest
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from common import BIN_VERSIONS_FILE
|
from common import BIN_VERSIONS_FILE
|
||||||
|
from env_properties import read_env_properties, save_env_properties
|
||||||
from service_helper import get_storage_service_helper
|
from service_helper import get_storage_service_helper
|
||||||
|
|
||||||
logger = logging.getLogger('NeoLogger')
|
logger = logging.getLogger('NeoLogger')
|
||||||
|
@ -21,34 +22,28 @@ def test_binaries_versions(request):
|
||||||
if not BIN_VERSIONS_FILE:
|
if not BIN_VERSIONS_FILE:
|
||||||
pytest.skip('File with binaries and versions was not provided')
|
pytest.skip('File with binaries and versions was not provided')
|
||||||
|
|
||||||
failed_versions = {}
|
|
||||||
environment_dir = request.config.getoption('--alluredir')
|
|
||||||
env_data = None
|
|
||||||
data_for_env = {}
|
|
||||||
|
|
||||||
binaries_to_check = download_versions_info(BIN_VERSIONS_FILE)
|
binaries_to_check = download_versions_info(BIN_VERSIONS_FILE)
|
||||||
|
|
||||||
with allure.step('Get binaries versions from servers'):
|
with allure.step('Get binaries versions from servers'):
|
||||||
helper = get_storage_service_helper()
|
helper = get_storage_service_helper()
|
||||||
got_versions = helper.get_binaries_version(binaries=list(binaries_to_check.keys()))
|
got_versions = helper.get_binaries_version(binaries=list(binaries_to_check.keys()))
|
||||||
|
|
||||||
if environment_dir:
|
env_properties = read_env_properties(request.config)
|
||||||
with open(f'{environment_dir}/environment.properties', 'r') as env_file:
|
|
||||||
env_data = env_file.read()
|
|
||||||
|
|
||||||
# compare versions from servers and file
|
# compare versions from servers and file
|
||||||
|
failed_versions = {}
|
||||||
|
additional_env_properties = {}
|
||||||
for binary, version in binaries_to_check.items():
|
for binary, version in binaries_to_check.items():
|
||||||
if binary not in got_versions:
|
actual_version = got_versions.get(binary)
|
||||||
failed_versions[binary] = 'Can not find binary'
|
if actual_version != version:
|
||||||
if got_versions[binary] != version:
|
failed_versions[binary] = f'Expected version {version}, found version {actual_version}'
|
||||||
failed_versions[binary] = f'Expected version {version}, found version {got_versions[binary]}'
|
|
||||||
|
|
||||||
# if something missed in environment.properties file, let's add
|
# If some binary was not listed in the env properties file, let's add it
|
||||||
if env_data and binary not in env_data:
|
# so that we have full information about versions in allure report
|
||||||
data_for_env[binary] = got_versions[binary]
|
if env_properties and binary not in env_properties:
|
||||||
|
additional_env_properties[binary] = actual_version
|
||||||
|
|
||||||
if environment_dir and data_for_env:
|
if env_properties and additional_env_properties:
|
||||||
add_to_environment_properties(f'{environment_dir}/environment.properties', data_for_env)
|
save_env_properties(request.config, additional_env_properties)
|
||||||
|
|
||||||
# create clear beautiful error with aggregation info
|
# create clear beautiful error with aggregation info
|
||||||
if failed_versions:
|
if failed_versions:
|
||||||
|
@ -56,7 +51,7 @@ def test_binaries_versions(request):
|
||||||
raise AssertionError(f'Found binaries with unexpected versions:\n{msg}')
|
raise AssertionError(f'Found binaries with unexpected versions:\n{msg}')
|
||||||
|
|
||||||
|
|
||||||
@allure.step('Download info from {url}')
|
@allure.step('Download versions info from {url}')
|
||||||
def download_versions_info(url: str) -> dict:
|
def download_versions_info(url: str) -> dict:
|
||||||
binaries_to_version = {}
|
binaries_to_version = {}
|
||||||
|
|
||||||
|
@ -77,10 +72,3 @@ def download_versions_info(url: str) -> dict:
|
||||||
binaries_to_version[bin_name] = bin_version
|
binaries_to_version[bin_name] = bin_version
|
||||||
|
|
||||||
return binaries_to_version
|
return binaries_to_version
|
||||||
|
|
||||||
|
|
||||||
@allure.step('Update data in environment.properties')
|
|
||||||
def add_to_environment_properties(file_path: str, env_data: dict):
|
|
||||||
with open(file_path, 'a+') as env_file:
|
|
||||||
for env, env_value in env_data.items():
|
|
||||||
env_file.write(f'{env}={env_value}\n')
|
|
||||||
|
|
Loading…
Reference in a new issue