2022-07-05 07:18:37 +00:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import shutil
|
2022-10-27 05:43:20 +00:00
|
|
|
import uuid
|
2022-08-26 19:58:56 +00:00
|
|
|
from datetime import datetime
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
import allure
|
2022-07-05 07:18:37 +00:00
|
|
|
import pytest
|
2022-10-09 20:01:59 +00:00
|
|
|
import yaml
|
2023-02-27 16:54:27 +00:00
|
|
|
from frostfs_testlib.hosting import Hosting
|
|
|
|
from frostfs_testlib.reporter import AllureHandler, get_reporter
|
|
|
|
from frostfs_testlib.shell import LocalShell, Shell
|
|
|
|
from frostfs_testlib.utils import wallet_utils
|
|
|
|
|
|
|
|
from pytest_tests.helpers import binary_version, env_properties
|
|
|
|
from pytest_tests.helpers.cluster import Cluster
|
|
|
|
from pytest_tests.helpers.frostfs_verbs import get_netmap_netinfo
|
|
|
|
from pytest_tests.helpers.k6 import LoadParams
|
|
|
|
from pytest_tests.helpers.node_management import storage_node_healthcheck
|
|
|
|
from pytest_tests.helpers.payment_neogo import deposit_gas, transfer_gas
|
|
|
|
from pytest_tests.helpers.wallet import WalletFactory
|
|
|
|
from pytest_tests.resources.common import (
|
2022-11-28 19:27:37 +00:00
|
|
|
ASSETS_DIR,
|
2022-12-07 12:38:56 +00:00
|
|
|
COMPLEX_OBJECT_CHUNKS_COUNT,
|
|
|
|
COMPLEX_OBJECT_TAIL_SIZE,
|
2022-11-28 19:27:37 +00:00
|
|
|
FREE_STORAGE,
|
|
|
|
HOSTING_CONFIG_FILE,
|
2022-12-07 12:38:56 +00:00
|
|
|
SIMPLE_OBJECT_SIZE,
|
2022-11-28 19:27:37 +00:00
|
|
|
STORAGE_NODE_SERVICE_NAME_REGEX,
|
|
|
|
WALLET_PASS,
|
|
|
|
)
|
2023-02-27 16:54:27 +00:00
|
|
|
from pytest_tests.resources.load_params import (
|
2022-12-06 19:57:29 +00:00
|
|
|
BACKGROUND_LOAD_MAX_TIME,
|
|
|
|
BACKGROUND_OBJ_SIZE,
|
|
|
|
BACKGROUND_READERS_COUNT,
|
|
|
|
BACKGROUND_WRITERS_COUNT,
|
|
|
|
LOAD_NODE_SSH_PRIVATE_KEY_PATH,
|
|
|
|
LOAD_NODE_SSH_USER,
|
|
|
|
LOAD_NODES,
|
|
|
|
)
|
2023-02-27 16:54:27 +00:00
|
|
|
from pytest_tests.steps.load import get_services_endpoints, prepare_k6_instances
|
2022-09-05 09:35:46 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger("NeoLogger")
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-11-07 07:10:11 +00:00
|
|
|
|
2023-03-14 09:21:40 +00:00
|
|
|
# Add logs check test even if it's not fit to mark selectors
|
|
|
|
def pytest_configure(config: pytest.Config):
|
|
|
|
markers = config.option.markexpr
|
|
|
|
if markers != "":
|
|
|
|
config.option.markexpr = f"logs_after_session or ({markers})"
|
|
|
|
|
|
|
|
|
|
|
|
# pytest hook. Do not rename
|
2022-11-03 13:17:08 +00:00
|
|
|
def pytest_collection_modifyitems(items):
|
2023-03-14 09:21:40 +00:00
|
|
|
# Make network tests last based on @pytest.mark.node_mgmt and logs_test to be latest
|
2022-11-03 13:17:08 +00:00
|
|
|
def priority(item: pytest.Item) -> int:
|
2023-03-14 09:21:40 +00:00
|
|
|
is_node_mgmt_test = 1 if item.get_closest_marker("node_mgmt") else 0
|
|
|
|
is_logs_check_test = 100 if item.get_closest_marker("logs_after_session") else 0
|
|
|
|
return is_node_mgmt_test + is_logs_check_test
|
2022-11-03 13:17:08 +00:00
|
|
|
|
|
|
|
items.sort(key=lambda item: priority(item))
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-11-07 07:10:11 +00:00
|
|
|
|
2022-10-13 18:53:44 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2022-10-13 16:13:45 +00:00
|
|
|
def configure_testlib():
|
|
|
|
get_reporter().register_handler(AllureHandler())
|
|
|
|
yield
|
2022-10-13 18:53:44 +00:00
|
|
|
|
|
|
|
|
2022-09-05 09:35:46 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2022-10-13 16:13:45 +00:00
|
|
|
def client_shell(configure_testlib) -> Shell:
|
|
|
|
yield LocalShell()
|
2022-08-01 06:16:36 +00:00
|
|
|
|
|
|
|
|
2022-10-09 20:01:59 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2022-10-13 16:13:45 +00:00
|
|
|
def hosting(configure_testlib) -> Hosting:
|
2022-10-09 20:01:59 +00:00
|
|
|
with open(HOSTING_CONFIG_FILE, "r") as file:
|
|
|
|
hosting_config = yaml.full_load(file)
|
2022-07-26 07:28:13 +00:00
|
|
|
|
2022-10-09 20:01:59 +00:00
|
|
|
hosting_instance = Hosting()
|
|
|
|
hosting_instance.configure(hosting_config)
|
2022-12-05 22:31:45 +00:00
|
|
|
|
2022-10-09 20:01:59 +00:00
|
|
|
yield hosting_instance
|
2022-07-05 07:18:37 +00:00
|
|
|
|
|
|
|
|
2022-10-13 16:13:45 +00:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def require_multiple_hosts(hosting: Hosting):
|
2022-10-14 16:56:15 +00:00
|
|
|
"""Designates tests that require environment with multiple hosts.
|
|
|
|
|
|
|
|
These tests will be skipped on an environment that has only 1 host.
|
|
|
|
"""
|
2022-10-13 16:13:45 +00:00
|
|
|
if len(hosting.hosts) <= 1:
|
|
|
|
pytest.skip("Test only works with multiple hosts")
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
2022-12-07 12:38:56 +00:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def max_object_size(cluster: Cluster, client_shell: Shell) -> int:
|
|
|
|
storage_node = cluster.storage_nodes[0]
|
|
|
|
net_info = get_netmap_netinfo(
|
|
|
|
wallet=storage_node.get_wallet_path(),
|
|
|
|
wallet_config=storage_node.get_wallet_config_path(),
|
|
|
|
endpoint=storage_node.get_rpc_endpoint(),
|
|
|
|
shell=client_shell,
|
|
|
|
)
|
|
|
|
yield net_info["maximum_object_size"]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def simple_object_size(max_object_size: int) -> int:
|
|
|
|
yield int(SIMPLE_OBJECT_SIZE) if int(SIMPLE_OBJECT_SIZE) < max_object_size else max_object_size
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def complex_object_size(max_object_size: int) -> int:
|
|
|
|
return max_object_size * int(COMPLEX_OBJECT_CHUNKS_COUNT) + int(COMPLEX_OBJECT_TAIL_SIZE)
|
|
|
|
|
|
|
|
|
2022-11-10 14:56:25 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2022-12-05 22:31:45 +00:00
|
|
|
def wallet_factory(temp_directory: str, client_shell: Shell, cluster: Cluster) -> WalletFactory:
|
|
|
|
return WalletFactory(temp_directory, client_shell, cluster)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
2022-12-23 08:52:05 +00:00
|
|
|
def cluster(temp_directory: str, hosting: Hosting) -> Cluster:
|
|
|
|
cluster = Cluster(hosting)
|
|
|
|
if cluster.is_local_devevn():
|
|
|
|
cluster.create_wallet_configs(hosting)
|
|
|
|
yield cluster
|
2022-11-10 14:56:25 +00:00
|
|
|
|
|
|
|
|
2022-10-09 20:01:59 +00:00
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
|
|
@allure.title("Check binary versions")
|
|
|
|
def check_binary_versions(request, hosting: Hosting, client_shell: Shell):
|
2023-02-27 16:54:27 +00:00
|
|
|
local_versions = binary_version.get_local_binaries_versions(client_shell)
|
|
|
|
remote_versions = binary_version.get_remote_binaries_versions(hosting)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-10-09 20:01:59 +00:00
|
|
|
all_versions = {**local_versions, **remote_versions}
|
2023-02-27 16:54:27 +00:00
|
|
|
env_properties.save_env_properties(request.config, all_versions)
|
2022-08-03 15:20:50 +00:00
|
|
|
|
|
|
|
|
2022-09-05 09:35:46 +00:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
@allure.title("Prepare tmp directory")
|
2022-12-05 22:31:45 +00:00
|
|
|
def temp_directory():
|
2022-11-10 14:56:25 +00:00
|
|
|
with allure.step("Prepare tmp directory"):
|
|
|
|
full_path = os.path.join(os.getcwd(), ASSETS_DIR)
|
|
|
|
shutil.rmtree(full_path, ignore_errors=True)
|
|
|
|
os.mkdir(full_path)
|
|
|
|
|
2022-08-29 20:42:34 +00:00
|
|
|
yield full_path
|
2022-11-10 14:56:25 +00:00
|
|
|
|
|
|
|
with allure.step("Remove tmp directory"):
|
|
|
|
shutil.rmtree(full_path)
|
2022-08-29 20:42:34 +00:00
|
|
|
|
|
|
|
|
2023-03-14 09:21:40 +00:00
|
|
|
@allure.step("[Autouse/Session] Test session start time")
|
2022-08-29 20:42:34 +00:00
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
2023-03-14 09:21:40 +00:00
|
|
|
def session_start_time():
|
2022-08-26 19:58:56 +00:00
|
|
|
start_time = datetime.utcnow()
|
2023-03-14 09:21:40 +00:00
|
|
|
return start_time
|
2022-11-15 08:39:07 +00:00
|
|
|
|
2022-08-26 19:58:56 +00:00
|
|
|
|
2022-09-05 09:35:46 +00:00
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
|
|
@allure.title("Run health check for all storage nodes")
|
2023-03-14 09:21:40 +00:00
|
|
|
def run_health_check(session_start_time, cluster: Cluster):
|
2022-07-20 14:55:25 +00:00
|
|
|
failed_nodes = []
|
2022-12-05 22:31:45 +00:00
|
|
|
for node in cluster.storage_nodes:
|
|
|
|
health_check = storage_node_healthcheck(node)
|
2022-09-20 15:03:52 +00:00
|
|
|
if health_check.health_status != "READY" or health_check.network_status != "ONLINE":
|
2022-12-05 22:31:45 +00:00
|
|
|
failed_nodes.append(node)
|
2022-07-20 14:55:25 +00:00
|
|
|
|
|
|
|
if failed_nodes:
|
2022-09-05 09:35:46 +00:00
|
|
|
raise AssertionError(f"Nodes {failed_nodes} are not healthy")
|
2022-07-20 14:55:25 +00:00
|
|
|
|
|
|
|
|
2022-11-28 19:27:37 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2022-12-19 15:12:45 +00:00
|
|
|
def background_grpc_load(client_shell: Shell, hosting: Hosting):
|
2022-11-28 19:27:37 +00:00
|
|
|
registry_file = os.path.join("/tmp/", f"{str(uuid.uuid4())}.bolt")
|
|
|
|
prepare_file = os.path.join("/tmp/", f"{str(uuid.uuid4())}.json")
|
|
|
|
allure.dynamic.title(
|
|
|
|
f"Start background load with parameters: "
|
|
|
|
f"writers = {BACKGROUND_WRITERS_COUNT}, "
|
|
|
|
f"obj_size = {BACKGROUND_OBJ_SIZE}, "
|
|
|
|
f"load_time = {BACKGROUND_LOAD_MAX_TIME}"
|
|
|
|
f"prepare_json = {prepare_file}"
|
|
|
|
)
|
|
|
|
with allure.step("Get endpoints"):
|
|
|
|
endpoints_list = get_services_endpoints(
|
|
|
|
hosting=hosting,
|
|
|
|
service_name_regex=STORAGE_NODE_SERVICE_NAME_REGEX,
|
|
|
|
endpoint_attribute="rpc_endpoint",
|
|
|
|
)
|
|
|
|
endpoints = ",".join(endpoints_list)
|
|
|
|
load_params = LoadParams(
|
|
|
|
endpoint=endpoints,
|
|
|
|
obj_size=BACKGROUND_OBJ_SIZE,
|
|
|
|
registry_file=registry_file,
|
|
|
|
containers_count=1,
|
|
|
|
obj_count=0,
|
|
|
|
out_file=prepare_file,
|
|
|
|
readers=0,
|
|
|
|
writers=BACKGROUND_WRITERS_COUNT,
|
|
|
|
deleters=0,
|
|
|
|
load_time=BACKGROUND_LOAD_MAX_TIME,
|
|
|
|
load_type="grpc",
|
|
|
|
)
|
|
|
|
k6_load_instances = prepare_k6_instances(
|
|
|
|
load_nodes=LOAD_NODES,
|
|
|
|
login=LOAD_NODE_SSH_USER,
|
|
|
|
pkey=LOAD_NODE_SSH_PRIVATE_KEY_PATH,
|
|
|
|
load_params=load_params,
|
|
|
|
)
|
|
|
|
with allure.step("Run background load"):
|
|
|
|
for k6_load_instance in k6_load_instances:
|
|
|
|
k6_load_instance.start()
|
|
|
|
yield
|
|
|
|
with allure.step("Stop background load"):
|
|
|
|
for k6_load_instance in k6_load_instances:
|
|
|
|
k6_load_instance.stop()
|
|
|
|
with allure.step("Verify background load data"):
|
|
|
|
verify_params = LoadParams(
|
|
|
|
endpoint=endpoints,
|
|
|
|
clients=BACKGROUND_READERS_COUNT,
|
|
|
|
registry_file=registry_file,
|
|
|
|
load_time=BACKGROUND_LOAD_MAX_TIME,
|
|
|
|
load_type="verify",
|
|
|
|
)
|
|
|
|
k6_verify_instances = prepare_k6_instances(
|
|
|
|
load_nodes=LOAD_NODES,
|
|
|
|
login=LOAD_NODE_SSH_USER,
|
|
|
|
pkey=LOAD_NODE_SSH_PRIVATE_KEY_PATH,
|
|
|
|
load_params=verify_params,
|
|
|
|
prepare=False,
|
|
|
|
)
|
|
|
|
with allure.step("Run verify background load data"):
|
|
|
|
for k6_verify_instance in k6_verify_instances:
|
|
|
|
k6_verify_instance.start()
|
|
|
|
k6_verify_instance.wait_until_finished(BACKGROUND_LOAD_MAX_TIME)
|
|
|
|
|
|
|
|
|
2022-09-05 09:35:46 +00:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
@allure.title("Prepare wallet and deposit")
|
2022-12-05 22:31:45 +00:00
|
|
|
def default_wallet(client_shell: Shell, temp_directory: str, cluster: Cluster):
|
2022-10-27 05:43:20 +00:00
|
|
|
wallet_path = os.path.join(os.getcwd(), ASSETS_DIR, f"{str(uuid.uuid4())}.json")
|
2023-02-19 23:58:07 +00:00
|
|
|
wallet_utils.init_wallet(wallet_path, WALLET_PASS)
|
2022-09-20 15:03:52 +00:00
|
|
|
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:
|
2022-12-05 22:31:45 +00:00
|
|
|
main_chain = cluster.main_chain_nodes[0]
|
2022-07-05 10:17:36 +00:00
|
|
|
deposit = 30
|
2022-10-27 05:43:20 +00:00
|
|
|
transfer_gas(
|
|
|
|
shell=client_shell,
|
|
|
|
amount=deposit + 1,
|
2022-12-05 22:31:45 +00:00
|
|
|
main_chain=main_chain,
|
2022-10-27 05:43:20 +00:00
|
|
|
wallet_to_path=wallet_path,
|
|
|
|
wallet_to_password=WALLET_PASS,
|
|
|
|
)
|
|
|
|
deposit_gas(
|
|
|
|
shell=client_shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
main_chain=main_chain,
|
2022-10-27 05:43:20 +00:00
|
|
|
amount=deposit,
|
|
|
|
wallet_from_path=wallet_path,
|
|
|
|
wallet_from_password=WALLET_PASS,
|
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-07-26 19:44:05 +00:00
|
|
|
return wallet_path
|