2022-07-05 07:18:37 +00:00
|
|
|
import logging
|
|
|
|
import os
|
2022-07-26 07:28:13 +00:00
|
|
|
import re
|
2022-07-05 07:18:37 +00:00
|
|
|
import shutil
|
2022-08-26 19:58:56 +00:00
|
|
|
from datetime import datetime
|
2022-07-05 07:18:37 +00:00
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2022-07-01 17:30:07 +00:00
|
|
|
from robot.api import deco
|
|
|
|
|
2022-07-05 07:18:37 +00:00
|
|
|
import wallet
|
|
|
|
from cli_helpers import _cmd_run
|
2022-07-26 19:44:05 +00:00
|
|
|
from common import (ASSETS_DIR, FREE_STORAGE, INFRASTRUCTURE_TYPE, MAINNET_WALLET_PATH,
|
|
|
|
NEOFS_NETMAP_DICT)
|
2022-08-08 16:51:28 +00:00
|
|
|
from env_properties import save_env_properties
|
2022-07-01 17:30:07 +00:00
|
|
|
from payment_neogo import neofs_deposit, transfer_mainnet_gas
|
2022-08-04 21:03:06 +00:00
|
|
|
from python_keywords.node_management import node_healthcheck
|
|
|
|
from service_helper import get_storage_service_helper
|
2022-07-20 14:55:25 +00:00
|
|
|
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-07-12 09:59:19 +00:00
|
|
|
def robot_keyword_adapter(name=None, tags=(), types=()):
|
|
|
|
return allure.step(name)
|
2022-07-20 14:55:25 +00:00
|
|
|
|
|
|
|
|
2022-07-12 09:59:19 +00:00
|
|
|
deco.keyword = robot_keyword_adapter
|
2022-07-05 07:18:37 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger('NeoLogger')
|
|
|
|
|
|
|
|
|
2022-08-01 06:16:36 +00:00
|
|
|
@pytest.fixture(scope='session')
|
2022-08-02 06:37:28 +00:00
|
|
|
def cloud_infrastructure_check():
|
2022-08-04 21:03:06 +00:00
|
|
|
if INFRASTRUCTURE_TYPE != "CLOUD_VM":
|
2022-08-01 06:16:36 +00:00
|
|
|
pytest.skip('Test only works on SberCloud infrastructure')
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
2022-07-05 07:18:37 +00:00
|
|
|
@pytest.fixture(scope='session', autouse=True)
|
|
|
|
@allure.title('Check binary versions')
|
|
|
|
def check_binary_versions(request):
|
2022-08-04 21:03:06 +00:00
|
|
|
# Collect versions of local binaries
|
2022-07-26 07:28:13 +00:00
|
|
|
binaries = ['neo-go', 'neofs-cli', 'neofs-authmate']
|
2022-08-08 16:51:28 +00:00
|
|
|
local_binaries = _get_binaries_version_local(binaries)
|
2022-08-03 15:20:50 +00:00
|
|
|
|
2022-08-04 21:03:06 +00:00
|
|
|
# Collect versions of remote binaries
|
|
|
|
helper = get_storage_service_helper()
|
|
|
|
remote_binaries = helper.get_binaries_version()
|
2022-08-08 16:51:28 +00:00
|
|
|
all_binaries = {**local_binaries, **remote_binaries}
|
2022-07-26 07:28:13 +00:00
|
|
|
|
|
|
|
# Get version of aws binary
|
|
|
|
out = _cmd_run('aws --version')
|
|
|
|
out_lines = out.split("\n")
|
2022-08-08 16:51:28 +00:00
|
|
|
all_binaries["AWS"] = out_lines[0] if out_lines else 'Unknown'
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-08-08 16:51:28 +00:00
|
|
|
save_env_properties(request.config, all_binaries)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
|
|
|
|
2022-08-03 15:20:50 +00:00
|
|
|
def _get_binaries_version_local(binaries: list) -> dict:
|
|
|
|
env_out = {}
|
|
|
|
for binary in binaries:
|
|
|
|
out = _cmd_run(f'{binary} --version')
|
|
|
|
version = re.search(r'version[:\s]*(.+)', out, re.IGNORECASE)
|
2022-08-08 14:49:08 +00:00
|
|
|
env_out[binary] = version.group(1).strip() if version else 'Unknown'
|
2022-08-03 15:20:50 +00:00
|
|
|
return env_out
|
|
|
|
|
|
|
|
|
2022-08-26 19:58:56 +00:00
|
|
|
@pytest.fixture(scope='session', autouse=True)
|
|
|
|
@allure.title('Collect logs')
|
|
|
|
def collect_logs():
|
|
|
|
start_time = datetime.utcnow()
|
|
|
|
yield
|
|
|
|
end_time = datetime.utcnow()
|
|
|
|
|
|
|
|
helper = get_storage_service_helper()
|
|
|
|
logs_by_service_id = helper.logs(since=start_time, until=end_time)
|
|
|
|
for service_id, logs in logs_by_service_id.items():
|
|
|
|
allure.attach(logs, f"logs_{service_id}", allure.attachment_type.TEXT)
|
|
|
|
|
|
|
|
|
2022-07-20 14:55:25 +00:00
|
|
|
@pytest.fixture(scope='session', autouse=True)
|
|
|
|
@allure.title('Run health check for all storage nodes')
|
2022-08-26 19:58:56 +00:00
|
|
|
def run_health_check(collect_logs):
|
2022-07-20 14:55:25 +00:00
|
|
|
failed_nodes = []
|
|
|
|
for node_name in NEOFS_NETMAP_DICT.keys():
|
|
|
|
health_check = node_healthcheck(node_name)
|
|
|
|
if health_check.health_status != 'READY' or health_check.network_status != 'ONLINE':
|
|
|
|
failed_nodes.append(node_name)
|
|
|
|
|
|
|
|
if failed_nodes:
|
|
|
|
raise AssertionError(f'Nodes {failed_nodes} are not healthy')
|
|
|
|
|
|
|
|
|
2022-07-05 07:18:37 +00:00
|
|
|
@pytest.fixture(scope='session')
|
2022-07-08 17:24:55 +00:00
|
|
|
@allure.title('Prepare tmp directory')
|
|
|
|
def prepare_tmp_dir():
|
|
|
|
full_path = f'{os.getcwd()}/{ASSETS_DIR}'
|
2022-07-11 14:11:26 +00:00
|
|
|
shutil.rmtree(full_path, ignore_errors=True)
|
2022-07-08 17:24:55 +00:00
|
|
|
os.mkdir(full_path)
|
2022-07-12 08:23:48 +00:00
|
|
|
yield full_path
|
2022-07-05 07:18:37 +00:00
|
|
|
shutil.rmtree(full_path)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='session')
|
|
|
|
@allure.title('Prepare wallet and deposit')
|
2022-07-26 19:44:05 +00:00
|
|
|
def prepare_wallet_and_deposit(prepare_tmp_dir):
|
|
|
|
wallet_path, addr, _ = wallet.init_wallet(ASSETS_DIR)
|
|
|
|
logger.info(f'Init wallet: {wallet_path},\naddr: {addr}')
|
|
|
|
allure.attach.file(wallet_path, os.path.basename(wallet_path), allure.attachment_type.JSON)
|
2022-07-01 17:30:07 +00:00
|
|
|
|
2022-07-05 10:17:36 +00:00
|
|
|
if not FREE_STORAGE:
|
|
|
|
deposit = 30
|
2022-07-26 19:44:05 +00:00
|
|
|
transfer_mainnet_gas(wallet_path, deposit + 1, wallet_path=MAINNET_WALLET_PATH)
|
|
|
|
neofs_deposit(wallet_path, deposit)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-07-26 19:44:05 +00:00
|
|
|
return wallet_path
|