2022-07-05 07:18:37 +00:00
|
|
|
import logging
|
|
|
|
import os
|
2023-11-27 10:03:18 +00:00
|
|
|
import random
|
2022-07-05 07:18:37 +00:00
|
|
|
import shutil
|
2023-10-23 14:11:53 +00:00
|
|
|
from datetime import datetime, timedelta, timezone
|
2023-11-22 16:58:49 +00:00
|
|
|
from importlib.metadata import entry_points
|
2023-05-15 09:59:33 +00:00
|
|
|
from typing import Optional
|
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-10-23 14:11:53 +00:00
|
|
|
from dateutil import parser
|
2023-11-29 13:34:59 +00:00
|
|
|
from frostfs_testlib import plugins, reporter
|
2023-10-31 11:28:44 +00:00
|
|
|
from frostfs_testlib.healthcheck.interfaces import Healthcheck
|
2023-02-27 16:54:27 +00:00
|
|
|
from frostfs_testlib.hosting import Hosting
|
2023-11-29 13:34:59 +00:00
|
|
|
from frostfs_testlib.reporter import AllureHandler, StepsLogger
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.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,
|
2023-05-15 09:59:33 +00:00
|
|
|
DEFAULT_WALLET_PASS,
|
2022-12-07 12:38:56 +00:00
|
|
|
SIMPLE_OBJECT_SIZE,
|
2022-12-06 19:57:29 +00:00
|
|
|
)
|
2023-10-31 14:51:09 +00:00
|
|
|
from frostfs_testlib.s3 import AwsCliClient, Boto3ClientWrapper, S3ClientWrapper, VersioningStatus
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.shell import LocalShell, Shell
|
|
|
|
from frostfs_testlib.steps.cli.container import list_containers
|
|
|
|
from frostfs_testlib.steps.cli.object import get_netmap_netinfo
|
|
|
|
from frostfs_testlib.steps.s3 import s3_helper
|
2023-11-22 16:58:49 +00:00
|
|
|
from frostfs_testlib.storage import get_service_registry
|
2023-09-29 13:16:06 +00:00
|
|
|
from frostfs_testlib.storage.cluster import Cluster, ClusterNode
|
2023-05-26 04:49:23 +00:00
|
|
|
from frostfs_testlib.storage.controllers.cluster_state_controller import ClusterStateController
|
2023-10-23 14:11:53 +00:00
|
|
|
from frostfs_testlib.storage.dataclasses.frostfs_services import StorageNode
|
2023-08-02 11:54:03 +00:00
|
|
|
from frostfs_testlib.storage.dataclasses.object_size import ObjectSize
|
2023-06-21 11:31:42 +00:00
|
|
|
from frostfs_testlib.storage.dataclasses.wallet import WalletFactory, WalletInfo
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.testing.cluster_test_base import ClusterTestBase
|
2023-09-29 13:16:06 +00:00
|
|
|
from frostfs_testlib.testing.parallel import parallel
|
2023-10-23 14:11:53 +00:00
|
|
|
from frostfs_testlib.testing.test_control import wait_for_success
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.utils import env_utils, version_utils
|
|
|
|
|
|
|
|
from pytest_tests.resources.common import HOSTING_CONFIG_FILE, TEST_CYCLES_COUNT
|
2022-09-05 09:35:46 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger("NeoLogger")
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2024-01-10 10:43:52 +00:00
|
|
|
SERVICE_ACTIVE_TIME = 20
|
|
|
|
|
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})"
|
|
|
|
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
number_key = pytest.StashKey[str]()
|
|
|
|
start_time = pytest.StashKey[int]()
|
|
|
|
test_outcome = pytest.StashKey[str]()
|
2023-03-14 09:21:40 +00:00
|
|
|
# pytest hook. Do not rename
|
2023-03-17 08:49:58 +00:00
|
|
|
def pytest_collection_modifyitems(items: list[pytest.Item]):
|
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
|
2023-12-12 06:57:34 +00:00
|
|
|
is_system_time_test = 10 if item.get_closest_marker("time") else 0
|
2023-11-24 10:22:00 +00:00
|
|
|
return is_node_mgmt_test + is_logs_check_test + is_system_time_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
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
# pytest hook. Do not rename
|
|
|
|
def pytest_collection_finish(session: pytest.Session):
|
|
|
|
items_total = len(session.items)
|
|
|
|
for number, item in enumerate(session.items, 1):
|
|
|
|
item.stash[number_key] = f"[{number}/{items_total}]"
|
|
|
|
item.stash[test_outcome] = ""
|
2023-12-05 08:33:59 +00:00
|
|
|
item.stash[start_time] = 0
|
2023-11-29 13:34:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
# pytest hook. Do not rename
|
|
|
|
def pytest_runtest_setup(item: pytest.Item):
|
|
|
|
item.stash[start_time] = int(datetime.now().timestamp())
|
|
|
|
logger.info(f"STARTED {item.stash[number_key]}: {item.name}")
|
|
|
|
|
|
|
|
|
|
|
|
# pytest hook. Do not rename
|
|
|
|
def pytest_runtest_makereport(item: pytest.Item, call: pytest.CallInfo):
|
|
|
|
if call.excinfo is not None:
|
2023-12-05 08:33:59 +00:00
|
|
|
if call.excinfo.typename == "Skipped":
|
|
|
|
item.stash[start_time] = int(datetime.now().timestamp())
|
|
|
|
item.stash[test_outcome] += f"SKIPPED on {call.when}; "
|
|
|
|
else:
|
|
|
|
item.stash[test_outcome] += f"FAILED on {call.when}; "
|
2023-11-29 13:34:59 +00:00
|
|
|
|
|
|
|
if call.when == "teardown":
|
|
|
|
duration = int(datetime.now().timestamp()) - item.stash[start_time]
|
|
|
|
if not item.stash[test_outcome]:
|
|
|
|
outcome = "PASSED "
|
|
|
|
else:
|
|
|
|
outcome = item.stash[test_outcome]
|
|
|
|
logger.info(f"ENDED {item.stash[number_key]}: {item.name}: {outcome}(duration={duration}s)")
|
|
|
|
|
|
|
|
|
|
|
|
# pytest hook. Do not rename
|
2023-03-17 08:49:58 +00:00
|
|
|
def pytest_generate_tests(metafunc: pytest.Metafunc):
|
|
|
|
if (
|
|
|
|
TEST_CYCLES_COUNT <= 1
|
|
|
|
or metafunc.definition.get_closest_marker("logs_after_session")
|
|
|
|
or metafunc.definition.get_closest_marker("no_cycles")
|
|
|
|
):
|
|
|
|
return
|
|
|
|
|
|
|
|
metafunc.fixturenames.append("cycle")
|
|
|
|
metafunc.parametrize(
|
|
|
|
"cycle",
|
|
|
|
range(1, TEST_CYCLES_COUNT + 1),
|
|
|
|
ids=[f"cycle {cycle}" for cycle in range(1, TEST_CYCLES_COUNT + 1)],
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-10-13 18:53:44 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2022-10-13 16:13:45 +00:00
|
|
|
def configure_testlib():
|
2023-11-29 13:34:59 +00:00
|
|
|
reporter.get_reporter().register_handler(AllureHandler())
|
|
|
|
reporter.get_reporter().register_handler(StepsLogger())
|
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
logging.getLogger("paramiko").setLevel(logging.INFO)
|
2023-11-22 16:58:49 +00:00
|
|
|
|
|
|
|
# Register Services for cluster
|
|
|
|
registry = get_service_registry()
|
|
|
|
services = entry_points(group="frostfs.testlib.services")
|
|
|
|
for svc in services:
|
|
|
|
registry.register_service(svc.name, svc.load())
|
|
|
|
|
2022-10-13 16:13:45 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2023-10-25 12:56:59 +00:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def require_multiple_interfaces(cluster: Cluster):
|
|
|
|
"""
|
|
|
|
We determine that there are the required number of interfaces for tests
|
|
|
|
|
|
|
|
If there are no required interfaces, the tests will be skipped.
|
|
|
|
"""
|
|
|
|
interfaces = cluster.cluster_nodes[0].host.config.interfaces
|
|
|
|
if "internal1" not in interfaces or "data1" not in interfaces:
|
|
|
|
pytest.skip("This test requires multiple internal and data interfaces")
|
|
|
|
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")
|
2023-09-08 10:35:34 +00:00
|
|
|
def simple_object_size(max_object_size: int) -> ObjectSize:
|
2023-08-02 11:54:03 +00:00
|
|
|
size = min(int(SIMPLE_OBJECT_SIZE), max_object_size)
|
|
|
|
return ObjectSize("simple", size)
|
2022-12-07 12:38:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
2023-09-08 10:35:34 +00:00
|
|
|
def complex_object_size(max_object_size: int) -> ObjectSize:
|
2023-08-02 11:54:03 +00:00
|
|
|
size = max_object_size * int(COMPLEX_OBJECT_CHUNKS_COUNT) + int(COMPLEX_OBJECT_TAIL_SIZE)
|
|
|
|
return ObjectSize("complex", size)
|
2022-12-07 12:38:56 +00:00
|
|
|
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
# By default we want all tests to be executed with both object sizes
|
|
|
|
# This can be overriden in choosen tests if needed
|
2023-10-31 13:47:32 +00:00
|
|
|
@pytest.fixture(
|
|
|
|
scope="session",
|
|
|
|
params=[pytest.param("simple", marks=pytest.mark.simple), pytest.param("complex", marks=pytest.mark.complex)],
|
|
|
|
)
|
2023-09-08 10:35:34 +00:00
|
|
|
def object_size(
|
|
|
|
simple_object_size: ObjectSize, complex_object_size: ObjectSize, request: pytest.FixtureRequest
|
|
|
|
) -> ObjectSize:
|
|
|
|
if request.param == "simple":
|
|
|
|
return simple_object_size
|
|
|
|
|
|
|
|
return complex_object_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")
|
2023-05-15 09:59:33 +00:00
|
|
|
def cluster(temp_directory: str, hosting: Hosting, client_shell: Shell) -> Cluster:
|
2022-12-23 08:52:05 +00:00
|
|
|
cluster = Cluster(hosting)
|
2023-05-15 09:59:33 +00:00
|
|
|
if cluster.is_local_devenv():
|
2022-12-23 08:52:05 +00:00
|
|
|
cluster.create_wallet_configs(hosting)
|
2023-05-15 09:59:33 +00:00
|
|
|
|
|
|
|
ClusterTestBase.shell = client_shell
|
|
|
|
ClusterTestBase.cluster = cluster
|
|
|
|
|
2022-12-23 08:52:05 +00:00
|
|
|
yield cluster
|
2022-11-10 14:56:25 +00:00
|
|
|
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
@reporter.step("[Class]: Provide S3 policy")
|
2023-05-15 09:59:33 +00:00
|
|
|
@pytest.fixture(scope="class")
|
|
|
|
def s3_policy(request: pytest.FixtureRequest):
|
|
|
|
policy = None
|
|
|
|
if "param" in request.__dict__:
|
|
|
|
policy = request.param
|
|
|
|
|
|
|
|
return policy
|
|
|
|
|
|
|
|
|
2023-05-26 04:49:23 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2023-10-31 11:28:44 +00:00
|
|
|
@allure.title("[Session] Create healthcheck object")
|
|
|
|
def healthcheck(cluster: Cluster) -> Healthcheck:
|
2023-11-22 16:58:49 +00:00
|
|
|
healthcheck_cls = plugins.load_plugin(
|
2023-10-31 11:28:44 +00:00
|
|
|
"frostfs.testlib.healthcheck", cluster.cluster_nodes[0].host.config.healthcheck_plugin_name
|
|
|
|
)
|
|
|
|
|
|
|
|
return healthcheck_cls()
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def cluster_state_controller(client_shell: Shell, cluster: Cluster, healthcheck: Healthcheck) -> ClusterStateController:
|
|
|
|
controller = ClusterStateController(client_shell, cluster, healthcheck)
|
2023-05-26 04:49:23 +00:00
|
|
|
yield controller
|
|
|
|
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
@reporter.step("[Class]: Create S3 client")
|
2023-10-31 14:51:09 +00:00
|
|
|
@pytest.fixture(
|
|
|
|
scope="class",
|
|
|
|
params=[
|
2023-11-02 08:43:36 +00:00
|
|
|
pytest.param(AwsCliClient, marks=pytest.mark.aws),
|
2023-10-31 14:51:09 +00:00
|
|
|
pytest.param(Boto3ClientWrapper, marks=pytest.mark.boto3),
|
|
|
|
],
|
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
def s3_client(
|
|
|
|
default_wallet: str,
|
|
|
|
client_shell: Shell,
|
|
|
|
s3_policy: Optional[str],
|
|
|
|
cluster: Cluster,
|
2023-09-18 13:56:53 +00:00
|
|
|
auth_container_placement_policy: str,
|
2023-05-15 09:59:33 +00:00
|
|
|
request: pytest.FixtureRequest,
|
|
|
|
) -> S3ClientWrapper:
|
2023-06-21 11:31:42 +00:00
|
|
|
wallet = WalletInfo(path=default_wallet, password=DEFAULT_WALLET_PASS)
|
2023-05-15 09:59:33 +00:00
|
|
|
|
|
|
|
(cid, access_key_id, secret_access_key) = s3_helper.init_s3_credentials(
|
2023-06-21 11:31:42 +00:00
|
|
|
wallet,
|
|
|
|
client_shell,
|
|
|
|
cluster,
|
|
|
|
s3gates=[cluster_node.s3_gate for cluster_node in cluster.cluster_nodes],
|
|
|
|
policy=s3_policy,
|
2023-09-18 13:56:53 +00:00
|
|
|
container_placement_policy=auth_container_placement_policy,
|
2023-05-15 09:59:33 +00:00
|
|
|
)
|
2023-10-23 14:11:53 +00:00
|
|
|
containers_list = list_containers(wallet.path, shell=client_shell, endpoint=cluster.default_rpc_endpoint)
|
2023-05-15 09:59:33 +00:00
|
|
|
assert cid in containers_list, f"Expected cid {cid} in {containers_list}"
|
|
|
|
|
|
|
|
s3_client_cls = request.param
|
|
|
|
client = s3_client_cls(access_key_id, secret_access_key, cluster.default_s3_gate_endpoint)
|
|
|
|
yield client
|
|
|
|
|
|
|
|
|
2023-08-29 13:43:16 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def versioning_status(request: pytest.FixtureRequest) -> VersioningStatus:
|
|
|
|
if "param" in request.__dict__:
|
|
|
|
return request.param
|
|
|
|
|
|
|
|
return VersioningStatus.UNDEFINED
|
|
|
|
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
@reporter.step("Create/delete bucket")
|
2023-05-15 09:59:33 +00:00
|
|
|
@pytest.fixture
|
2023-11-01 16:20:15 +00:00
|
|
|
def bucket(s3_client: S3ClientWrapper, versioning_status: VersioningStatus, request: pytest.FixtureRequest):
|
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
bucket_name = s3_client.create_bucket()
|
|
|
|
|
|
|
|
if versioning_status:
|
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket_name, versioning_status)
|
|
|
|
|
|
|
|
yield bucket_name
|
2023-10-31 14:51:09 +00:00
|
|
|
|
2023-11-01 16:20:15 +00:00
|
|
|
if "sanity" not in request.config.option.markexpr:
|
|
|
|
s3_helper.delete_bucket_with_objects(s3_client, bucket_name)
|
2023-05-15 09:59:33 +00:00
|
|
|
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
@reporter.step("Create two buckets")
|
2023-05-15 09:59:33 +00:00
|
|
|
@pytest.fixture
|
2023-11-01 16:20:15 +00:00
|
|
|
def two_buckets(s3_client: S3ClientWrapper, request: pytest.FixtureRequest):
|
2023-05-15 09:59:33 +00:00
|
|
|
bucket_1 = s3_client.create_bucket()
|
|
|
|
bucket_2 = s3_client.create_bucket()
|
|
|
|
yield bucket_1, bucket_2
|
2023-10-31 14:51:09 +00:00
|
|
|
|
2023-11-01 16:20:15 +00:00
|
|
|
if "sanity" not in request.config.option.markexpr:
|
|
|
|
for bucket_name in [bucket_1, bucket_2]:
|
|
|
|
s3_helper.delete_bucket_with_objects(s3_client, bucket_name)
|
2023-05-15 09:59:33 +00:00
|
|
|
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
@reporter.step("[Autouse/Session] Check binary versions")
|
2022-10-09 20:01:59 +00:00
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
2023-05-15 09:59:33 +00:00
|
|
|
def check_binary_versions(hosting: Hosting, client_shell: Shell, request: pytest.FixtureRequest):
|
|
|
|
local_versions = version_utils.get_local_binaries_versions(client_shell)
|
2024-01-29 16:00:47 +00:00
|
|
|
remote_versions, exсeptions_remote_binaries_versions = version_utils.get_remote_binaries_versions(hosting)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
all_versions = {
|
|
|
|
**local_versions,
|
|
|
|
**{binary_name: binary["version"] for binary_name, binary in remote_versions.items()},
|
|
|
|
}
|
2023-05-15 09:59:33 +00:00
|
|
|
|
|
|
|
environment_dir = request.config.getoption("--alluredir")
|
|
|
|
if not environment_dir:
|
|
|
|
return None
|
|
|
|
|
|
|
|
file_path = f"{environment_dir}/environment.properties"
|
|
|
|
env_utils.save_env_properties(file_path, all_versions)
|
2022-08-03 15:20:50 +00:00
|
|
|
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
@reporter.step("Prepare tmp directory")
|
2022-09-05 09:35:46 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2023-11-29 13:34:59 +00:00
|
|
|
def temp_directory(configure_testlib):
|
|
|
|
with reporter.step("Prepare tmp directory"):
|
2022-11-10 14:56:25 +00:00
|
|
|
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
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Remove tmp directory"):
|
2022-11-10 14:56:25 +00:00
|
|
|
shutil.rmtree(full_path)
|
2022-08-29 20:42:34 +00:00
|
|
|
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
@reporter.step("[Autouse/Session] Test session start time")
|
2022-08-29 20:42:34 +00:00
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
2023-11-29 13:34:59 +00:00
|
|
|
def session_start_time(configure_testlib):
|
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
|
|
|
|
2023-10-23 14:11:53 +00:00
|
|
|
@allure.title("[Autouse/Session] After deploy healthcheck")
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
|
|
def after_deploy_healthcheck(cluster: Cluster):
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Wait for cluster readiness after deploy"):
|
2023-10-23 14:11:53 +00:00
|
|
|
parallel(readiness_on_node, cluster.cluster_nodes)
|
|
|
|
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
@wait_for_success(60 * SERVICE_ACTIVE_TIME * 3, 60, title="Wait for {cluster_node} readiness")
|
2023-10-23 14:11:53 +00:00
|
|
|
def readiness_on_node(cluster_node: ClusterNode):
|
2024-01-12 15:16:56 +00:00
|
|
|
if (
|
|
|
|
"skip_readiness_check" in cluster_node.host.config.attributes
|
|
|
|
and cluster_node.host.config.attributes["skip_readiness_check"]
|
|
|
|
):
|
|
|
|
return
|
|
|
|
|
2023-10-23 14:11:53 +00:00
|
|
|
# TODO: Move to healtcheck classes
|
|
|
|
svc_name = cluster_node.service(StorageNode).get_service_systemctl_name()
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step(f"Check service {svc_name} is active"):
|
2023-10-23 14:11:53 +00:00
|
|
|
result = cluster_node.host.get_shell().exec(f"systemctl is-active {svc_name}")
|
|
|
|
assert "active" == result.stdout.strip(), f"Service {svc_name} should be in active state"
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step(f"Check service {svc_name} is active more than {SERVICE_ACTIVE_TIME} minutes"):
|
2023-10-23 14:11:53 +00:00
|
|
|
result = cluster_node.host.get_shell().exec(
|
|
|
|
f"systemctl show {svc_name} --property ActiveEnterTimestamp | cut -d '=' -f 2"
|
|
|
|
)
|
|
|
|
start_time = parser.parse(result.stdout.strip())
|
|
|
|
current_time = datetime.now(tz=timezone.utc)
|
|
|
|
active_time = current_time - start_time
|
|
|
|
|
|
|
|
active_minutes = active_time.seconds // 60
|
|
|
|
active_seconds = active_time.seconds - active_minutes * 60
|
|
|
|
|
|
|
|
assert active_time > timedelta(
|
|
|
|
minutes=SERVICE_ACTIVE_TIME
|
|
|
|
), f"Service should be in active state more than {SERVICE_ACTIVE_TIME} minutes, current {active_minutes}m:{active_seconds}s"
|
|
|
|
|
|
|
|
|
|
|
|
@allure.title("[Autouse/Test] Run health check for all nodes")
|
2023-09-29 13:16:06 +00:00
|
|
|
@pytest.fixture(autouse=True)
|
2023-11-22 14:26:59 +00:00
|
|
|
def run_health_check(healthcheck: Healthcheck, cluster: Cluster, request: pytest.FixtureRequest):
|
2023-09-29 13:16:06 +00:00
|
|
|
if request.node.get_closest_marker("no_healthcheck"):
|
|
|
|
# Skip healthcheck for tests marked with no_healthcheck
|
|
|
|
return
|
2023-11-22 14:26:59 +00:00
|
|
|
parallel(healthcheck.storage_healthcheck, cluster.cluster_nodes)
|
2022-07-20 14:55:25 +00:00
|
|
|
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
@reporter.step("Prepare wallet and deposit")
|
2022-11-28 19:27:37 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2023-05-15 09:59:33 +00:00
|
|
|
def default_wallet(wallet_factory: WalletFactory) -> str:
|
|
|
|
wallet = wallet_factory.create_wallet(password=DEFAULT_WALLET_PASS)
|
2023-11-29 13:34:59 +00:00
|
|
|
reporter.attach(wallet.path, os.path.basename(wallet.path))
|
2023-05-15 09:59:33 +00:00
|
|
|
return wallet.path
|
2023-09-18 13:56:53 +00:00
|
|
|
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
@reporter.step("[Class]: Container placement policy for keys")
|
2023-09-18 13:56:53 +00:00
|
|
|
@pytest.fixture(scope="class")
|
|
|
|
def auth_container_placement_policy(cluster: Cluster, request: pytest.FixtureRequest):
|
|
|
|
placeholders = {
|
2023-09-18 18:01:06 +00:00
|
|
|
"$ALPHABET_NODE_COUNT$": 4 if len(cluster.cluster_nodes) < 8 else 8,
|
2023-09-18 13:56:53 +00:00
|
|
|
"$NODE_COUNT$": len(cluster.cluster_nodes),
|
|
|
|
}
|
2023-09-18 18:01:06 +00:00
|
|
|
placement_policy = None
|
2023-09-18 13:56:53 +00:00
|
|
|
if "param" in request.__dict__:
|
2023-09-18 18:01:06 +00:00
|
|
|
placement_policy = request.param
|
2023-09-18 13:56:53 +00:00
|
|
|
for key, value in placeholders.items():
|
2023-09-18 18:01:06 +00:00
|
|
|
placement_policy = placement_policy.replace(key, str(value))
|
|
|
|
return placement_policy
|
2023-11-27 10:03:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
|
|
|
@allure.title("Select random node for testing")
|
|
|
|
def node_under_test(cluster: Cluster) -> ClusterNode:
|
|
|
|
selected_node = random.choice(cluster.cluster_nodes)
|
2023-11-29 13:34:59 +00:00
|
|
|
reporter.attach(f"{selected_node}", "Selected node")
|
2023-11-27 10:03:18 +00:00
|
|
|
return selected_node
|