2022-07-11 14:11:26 +00:00
|
|
|
import logging
|
2023-05-15 09:59:33 +00:00
|
|
|
import os
|
2023-03-09 10:19:41 +00:00
|
|
|
from time import sleep
|
2022-07-11 14:11:26 +00:00
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2023-03-09 10:19:41 +00:00
|
|
|
from frostfs_testlib.analytics import test_case
|
2023-01-09 12:46:03 +00:00
|
|
|
from frostfs_testlib.hosting import Host
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.resources.common import MORPH_BLOCK_TIME
|
|
|
|
from frostfs_testlib.resources.wellknown_acl import PUBLIC_ACL
|
|
|
|
from frostfs_testlib.s3 import AwsCliClient, Boto3ClientWrapper, S3ClientWrapper
|
|
|
|
from frostfs_testlib.shell import CommandOptions, Shell
|
|
|
|
from frostfs_testlib.steps.cli.container import create_container
|
|
|
|
from frostfs_testlib.steps.cli.object import get_object, put_object_to_random_node
|
|
|
|
from frostfs_testlib.steps.node_management import (
|
2023-03-09 10:19:41 +00:00
|
|
|
check_node_in_map,
|
|
|
|
check_node_not_in_map,
|
|
|
|
exclude_node_from_network_map,
|
|
|
|
include_node_to_network_map,
|
2023-05-15 09:59:33 +00:00
|
|
|
remove_nodes_from_map_morph,
|
2023-03-09 10:19:41 +00:00
|
|
|
wait_for_node_to_be_ready,
|
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.steps.s3 import s3_helper
|
|
|
|
from frostfs_testlib.storage.cluster import Cluster, StorageNode
|
|
|
|
from frostfs_testlib.testing.cluster_test_base import ClusterTestBase
|
|
|
|
from frostfs_testlib.utils import datetime_utils
|
|
|
|
from frostfs_testlib.utils.failover_utils import (
|
|
|
|
wait_all_storage_nodes_returned,
|
|
|
|
wait_object_replication,
|
2023-03-09 10:19:41 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.utils.file_utils import generate_file, get_file_hash
|
2023-03-09 10:19:41 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
logger = logging.getLogger("NeoLogger")
|
2022-12-05 22:31:45 +00:00
|
|
|
stopped_nodes: list[StorageNode] = []
|
2022-07-11 14:11:26 +00:00
|
|
|
|
|
|
|
|
2022-10-13 16:13:45 +00:00
|
|
|
@allure.step("Return all stopped hosts")
|
2023-03-14 09:21:40 +00:00
|
|
|
@pytest.fixture(scope="function", autouse=True)
|
2023-05-15 09:59:33 +00:00
|
|
|
def after_run_return_all_stopped_hosts(client_shell: Shell, cluster: Cluster):
|
2022-07-11 14:11:26 +00:00
|
|
|
yield
|
2023-05-15 09:59:33 +00:00
|
|
|
return_stopped_hosts(client_shell, cluster)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
|
|
|
|
2022-10-13 16:13:45 +00:00
|
|
|
def panic_reboot_host(host: Host) -> None:
|
|
|
|
shell = host.get_shell()
|
|
|
|
shell.exec('sudo sh -c "echo 1 > /proc/sys/kernel/sysrq"')
|
|
|
|
|
|
|
|
options = CommandOptions(close_stdin=True, timeout=1, check=False)
|
|
|
|
shell.exec('sudo sh -c "echo b > /proc/sysrq-trigger"', options)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
def return_stopped_hosts(shell: Shell, cluster: Cluster) -> None:
|
2022-12-05 22:31:45 +00:00
|
|
|
for node in list(stopped_nodes):
|
|
|
|
with allure.step(f"Start host {node}"):
|
|
|
|
node.host.start_host()
|
|
|
|
stopped_nodes.remove(node)
|
2022-08-01 06:16:36 +00:00
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
wait_all_storage_nodes_returned(shell, cluster)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
|
|
|
|
2022-07-14 06:21:20 +00:00
|
|
|
@pytest.mark.failover
|
2022-12-05 22:31:45 +00:00
|
|
|
class TestFailoverStorage(ClusterTestBase):
|
|
|
|
@allure.title("Lose and return storage node's host")
|
|
|
|
@pytest.mark.parametrize("hard_reboot", [True, False])
|
|
|
|
@pytest.mark.failover_reboot
|
|
|
|
def test_lose_storage_node_host(
|
2022-12-07 12:38:56 +00:00
|
|
|
self, default_wallet, hard_reboot: bool, require_multiple_hosts, simple_object_size
|
2022-12-05 22:31:45 +00:00
|
|
|
):
|
|
|
|
wallet = default_wallet
|
|
|
|
placement_rule = "REP 2 IN X CBF 2 SELECT 2 FROM * AS X"
|
2022-12-07 12:38:56 +00:00
|
|
|
source_file_path = generate_file(simple_object_size)
|
2022-12-05 22:31:45 +00:00
|
|
|
cid = create_container(
|
|
|
|
wallet,
|
|
|
|
shell=self.shell,
|
|
|
|
endpoint=self.cluster.default_rpc_endpoint,
|
|
|
|
rule=placement_rule,
|
|
|
|
basic_acl=PUBLIC_ACL,
|
|
|
|
)
|
|
|
|
oid = put_object_to_random_node(
|
|
|
|
wallet, source_file_path, cid, shell=self.shell, cluster=self.cluster
|
|
|
|
)
|
|
|
|
nodes = wait_object_replication(
|
|
|
|
cid, oid, 2, shell=self.shell, nodes=self.cluster.storage_nodes
|
2022-10-21 14:53:54 +00:00
|
|
|
)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
for node in nodes:
|
|
|
|
stopped_nodes.append(node)
|
|
|
|
|
|
|
|
with allure.step(f"Stop host {node}"):
|
|
|
|
node.host.stop_host("hard" if hard_reboot else "soft")
|
|
|
|
|
|
|
|
new_nodes = wait_object_replication(
|
|
|
|
cid,
|
|
|
|
oid,
|
|
|
|
2,
|
|
|
|
shell=self.shell,
|
|
|
|
nodes=list(set(self.cluster.storage_nodes) - {node}),
|
|
|
|
)
|
|
|
|
assert all(old_node not in new_nodes for old_node in nodes)
|
|
|
|
|
|
|
|
with allure.step("Check object data is not corrupted"):
|
|
|
|
got_file_path = get_object(
|
|
|
|
wallet, cid, oid, endpoint=new_nodes[0].get_rpc_endpoint(), shell=self.shell
|
|
|
|
)
|
|
|
|
assert get_file_hash(source_file_path) == get_file_hash(got_file_path)
|
|
|
|
|
2022-12-16 08:30:47 +00:00
|
|
|
with allure.step("Return all hosts"):
|
2023-05-15 09:59:33 +00:00
|
|
|
return_stopped_hosts(self.shell, self.cluster)
|
2022-12-05 22:31:45 +00:00
|
|
|
|
|
|
|
with allure.step("Check object data is not corrupted"):
|
|
|
|
new_nodes = wait_object_replication(
|
|
|
|
cid, oid, 2, shell=self.shell, nodes=self.cluster.storage_nodes
|
|
|
|
)
|
|
|
|
got_file_path = get_object(
|
|
|
|
wallet, cid, oid, shell=self.shell, endpoint=new_nodes[0].get_rpc_endpoint()
|
|
|
|
)
|
|
|
|
assert get_file_hash(source_file_path) == get_file_hash(got_file_path)
|
|
|
|
|
|
|
|
@allure.title("Panic storage node's host")
|
|
|
|
@pytest.mark.parametrize("sequence", [True, False])
|
|
|
|
@pytest.mark.failover_panic
|
|
|
|
def test_panic_storage_node_host(
|
2022-12-07 12:38:56 +00:00
|
|
|
self, default_wallet, require_multiple_hosts, sequence: bool, simple_object_size
|
2022-12-05 22:31:45 +00:00
|
|
|
):
|
|
|
|
wallet = default_wallet
|
|
|
|
placement_rule = "REP 2 IN X CBF 2 SELECT 2 FROM * AS X"
|
2022-12-07 12:38:56 +00:00
|
|
|
source_file_path = generate_file(simple_object_size)
|
2022-12-05 22:31:45 +00:00
|
|
|
cid = create_container(
|
|
|
|
wallet,
|
|
|
|
shell=self.shell,
|
|
|
|
endpoint=self.cluster.default_rpc_endpoint,
|
|
|
|
rule=placement_rule,
|
|
|
|
basic_acl=PUBLIC_ACL,
|
|
|
|
)
|
|
|
|
oid = put_object_to_random_node(
|
|
|
|
wallet, source_file_path, cid, shell=self.shell, cluster=self.cluster
|
|
|
|
)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
nodes = wait_object_replication(
|
|
|
|
cid, oid, 2, shell=self.shell, nodes=self.cluster.storage_nodes
|
|
|
|
)
|
|
|
|
allure.attach(
|
2022-12-16 08:30:47 +00:00
|
|
|
"\n".join([str(node) for node in nodes]),
|
2022-12-05 22:31:45 +00:00
|
|
|
"Current nodes with object",
|
|
|
|
allure.attachment_type.TEXT,
|
|
|
|
)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
new_nodes: list[StorageNode] = []
|
|
|
|
for node in nodes:
|
|
|
|
with allure.step(f"Hard reboot host {node} via magic SysRq option"):
|
|
|
|
panic_reboot_host(node.host)
|
|
|
|
if sequence:
|
|
|
|
try:
|
|
|
|
new_nodes = wait_object_replication(
|
|
|
|
cid,
|
|
|
|
oid,
|
|
|
|
2,
|
|
|
|
shell=self.shell,
|
|
|
|
nodes=list(set(self.cluster.storage_nodes) - {node}),
|
|
|
|
)
|
|
|
|
except AssertionError:
|
|
|
|
new_nodes = wait_object_replication(
|
|
|
|
cid,
|
|
|
|
oid,
|
|
|
|
2,
|
|
|
|
shell=self.shell,
|
|
|
|
nodes=self.cluster.storage_nodes,
|
|
|
|
)
|
|
|
|
|
|
|
|
allure.attach(
|
2022-12-16 08:30:47 +00:00
|
|
|
"\n".join([str(new_node) for new_node in new_nodes]),
|
2022-12-05 22:31:45 +00:00
|
|
|
f"Nodes with object after {node} fail",
|
|
|
|
allure.attachment_type.TEXT,
|
2022-10-13 18:53:44 +00:00
|
|
|
)
|
2022-08-01 06:16:36 +00:00
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
if not sequence:
|
|
|
|
new_nodes = wait_object_replication(
|
|
|
|
cid, oid, 2, shell=self.shell, nodes=self.cluster.storage_nodes
|
|
|
|
)
|
|
|
|
allure.attach(
|
2022-12-16 08:30:47 +00:00
|
|
|
"\n".join([str(new_node) for new_node in new_nodes]),
|
2022-12-05 22:31:45 +00:00
|
|
|
"Nodes with object after nodes fail",
|
|
|
|
allure.attachment_type.TEXT,
|
|
|
|
)
|
|
|
|
|
|
|
|
got_file_path = get_object(
|
|
|
|
wallet, cid, oid, shell=self.shell, endpoint=new_nodes[0].get_rpc_endpoint()
|
2022-09-28 12:07:16 +00:00
|
|
|
)
|
2022-12-05 22:31:45 +00:00
|
|
|
assert get_file_hash(source_file_path) == get_file_hash(got_file_path)
|
2023-03-09 10:19:41 +00:00
|
|
|
|
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
def pytest_generate_tests(metafunc: pytest.Metafunc):
|
2023-03-09 10:19:41 +00:00
|
|
|
if "s3_client" in metafunc.fixturenames:
|
2023-05-15 09:59:33 +00:00
|
|
|
metafunc.parametrize("s3_client", [AwsCliClient, Boto3ClientWrapper], indirect=True)
|
|
|
|
|
2023-03-09 10:19:41 +00:00
|
|
|
|
|
|
|
@pytest.mark.failover
|
|
|
|
@pytest.mark.failover_empty_map
|
2023-05-15 09:59:33 +00:00
|
|
|
class TestEmptyMap(ClusterTestBase):
|
2023-03-09 10:19:41 +00:00
|
|
|
"""
|
|
|
|
A set of tests for makes map empty and verify that we can read objects after that
|
|
|
|
"""
|
2023-05-15 09:59:33 +00:00
|
|
|
|
2023-03-09 10:19:41 +00:00
|
|
|
@allure.step("Teardown after EmptyMap offline test")
|
|
|
|
@pytest.fixture()
|
|
|
|
def empty_map_offline_teardown(self):
|
|
|
|
yield
|
|
|
|
with allure.step("Return all storage nodes to network map"):
|
|
|
|
for node in list(stopped_nodes):
|
2023-05-15 09:59:33 +00:00
|
|
|
include_node_to_network_map(node, node, shell=self.shell, cluster=self.cluster)
|
2023-03-09 10:19:41 +00:00
|
|
|
stopped_nodes.remove(node)
|
|
|
|
|
|
|
|
@test_case.title("Test makes network map empty (offline all storage nodes)")
|
|
|
|
@test_case.priority(test_case.TestCasePriority.HIGH)
|
|
|
|
@test_case.suite_name("failovers")
|
|
|
|
@test_case.suite_section("test_failover_storage")
|
|
|
|
@pytest.mark.failover_empty_map_offlne
|
|
|
|
@allure.title("Test makes network map empty (offline all storage nodes)")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_offline_all_storage_nodes(
|
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
bucket: str,
|
|
|
|
simple_object_size: int,
|
|
|
|
empty_map_offline_teardown,
|
|
|
|
):
|
2023-03-09 10:19:41 +00:00
|
|
|
"""
|
|
|
|
The test makes network map empty (set offline status on all storage nodes) then returns all nodes to map and checks that object can read through s3.
|
2023-05-15 09:59:33 +00:00
|
|
|
|
2023-03-09 10:19:41 +00:00
|
|
|
Steps:
|
|
|
|
1. Check that bucket is empty
|
|
|
|
2: PUT object into bucket
|
|
|
|
3: Check that object exists in bucket
|
|
|
|
4: Exclude all storage nodes from network map (set status OFFLINE)
|
|
|
|
5: Return all storage nodes to network map
|
|
|
|
6: Check that we can read object from #2
|
|
|
|
Args:
|
|
|
|
bucket: bucket which contains tested object
|
|
|
|
simple_object_size: size of object
|
|
|
|
"""
|
|
|
|
file_path = generate_file(simple_object_size)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path)
|
2023-03-09 10:19:41 +00:00
|
|
|
bucket_objects = [file_name]
|
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
objects_list = s3_client.list_objects(bucket)
|
2023-03-09 10:19:41 +00:00
|
|
|
assert not objects_list, f"Expected empty bucket, got {objects_list}"
|
|
|
|
|
|
|
|
with allure.step("Put object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path)
|
2023-03-09 10:19:41 +00:00
|
|
|
|
|
|
|
with allure.step("Check that object exists in bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket, bucket_objects)
|
2023-03-09 10:19:41 +00:00
|
|
|
|
|
|
|
storage_nodes = self.cluster.storage_nodes
|
|
|
|
with allure.step("Exclude all storage nodes from network map"):
|
|
|
|
for node in storage_nodes:
|
2023-05-15 09:59:33 +00:00
|
|
|
exclude_node_from_network_map(node, node, shell=self.shell, cluster=self.cluster)
|
2023-03-09 10:19:41 +00:00
|
|
|
stopped_nodes.append(node)
|
|
|
|
|
|
|
|
with allure.step("Return all storage nodes to network map"):
|
|
|
|
for node in storage_nodes:
|
2023-05-15 09:59:33 +00:00
|
|
|
include_node_to_network_map(node, node, shell=self.shell, cluster=self.cluster)
|
2023-03-09 10:19:41 +00:00
|
|
|
stopped_nodes.remove(node)
|
|
|
|
|
|
|
|
with allure.step("Check that we can read object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket, bucket_objects)
|
2023-03-09 10:19:41 +00:00
|
|
|
|
|
|
|
@allure.step("Teardown after EmptyMap stop service test")
|
|
|
|
@pytest.fixture()
|
|
|
|
def empty_map_stop_service_teardown(self):
|
|
|
|
yield
|
|
|
|
with allure.step("Return all storage nodes to network map"):
|
|
|
|
for node in list(list(stopped_nodes)):
|
|
|
|
with allure.step(f"Start node {node}"):
|
|
|
|
node.start_service()
|
|
|
|
with allure.step(f"Waiting status ready for node {node}"):
|
|
|
|
wait_for_node_to_be_ready(node)
|
|
|
|
|
|
|
|
sleep(datetime_utils.parse_time(MORPH_BLOCK_TIME))
|
|
|
|
self.tick_epochs(1)
|
|
|
|
check_node_in_map(node, shell=self.shell, alive_node=node)
|
|
|
|
stopped_nodes.remove(node)
|
|
|
|
|
|
|
|
@test_case.title("Test makes network map empty (stop storage service on all nodes)")
|
|
|
|
@test_case.priority(test_case.TestCasePriority.HIGH)
|
|
|
|
@test_case.suite_name("failovers")
|
|
|
|
@test_case.suite_section("test_failover_storage")
|
|
|
|
@pytest.mark.failover_empty_map_stop_service
|
|
|
|
@allure.title("Test makes network map empty (stop storage service on all nodes)")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_stop_all_storage_nodes(
|
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
bucket: str,
|
|
|
|
simple_object_size: int,
|
|
|
|
empty_map_stop_service_teardown,
|
|
|
|
):
|
2023-03-09 10:19:41 +00:00
|
|
|
"""
|
2023-05-15 09:59:33 +00:00
|
|
|
The test makes network map empty (stop storage service on all nodes
|
|
|
|
then use 'frostfs-adm morph delete-nodes' to delete nodes from map)
|
2023-03-09 10:19:41 +00:00
|
|
|
then start all services and checks that object can read through s3.
|
|
|
|
|
|
|
|
Steps:
|
|
|
|
1. Check that bucket is empty
|
|
|
|
2: PUT object into bucket
|
|
|
|
3: Check that object exists in bucket
|
2023-05-15 09:59:33 +00:00
|
|
|
4: Exclude all storage nodes from network map (stop storage service
|
2023-03-09 10:19:41 +00:00
|
|
|
and manual exclude from map)
|
|
|
|
5: Return all storage nodes to network map
|
|
|
|
6: Check that we can read object from #2
|
|
|
|
Args:
|
|
|
|
bucket: bucket which contains tested object
|
|
|
|
simple_object_size: size of object
|
|
|
|
"""
|
|
|
|
file_path = generate_file(simple_object_size)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path)
|
2023-03-09 10:19:41 +00:00
|
|
|
bucket_objects = [file_name]
|
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
objects_list = s3_client.list_objects(bucket)
|
2023-03-09 10:19:41 +00:00
|
|
|
assert not objects_list, f"Expected empty bucket, got {objects_list}"
|
|
|
|
|
|
|
|
with allure.step("Put object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path)
|
2023-03-09 10:19:41 +00:00
|
|
|
|
|
|
|
with allure.step("Check that object exists in bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket, bucket_objects)
|
2023-03-09 10:19:41 +00:00
|
|
|
|
|
|
|
with allure.step("Stop all storage nodes"):
|
|
|
|
for node in self.cluster.storage_nodes:
|
|
|
|
with allure.step(f"Stop storage service on node: {node}"):
|
|
|
|
node.stop_service()
|
|
|
|
stopped_nodes.append(node)
|
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
with allure.step("Remove all nodes from network map"):
|
|
|
|
remove_nodes_from_map_morph(
|
|
|
|
shell=self.shell, cluster=self.cluster, remove_nodes=stopped_nodes
|
|
|
|
)
|
2023-03-09 10:19:41 +00:00
|
|
|
|
|
|
|
with allure.step("Return all storage nodes to network map"):
|
|
|
|
self.return_nodes_after_stop_with_check_empty_map(stopped_nodes)
|
|
|
|
|
|
|
|
with allure.step("Check that object exists in bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket, bucket_objects)
|
2023-03-09 10:19:41 +00:00
|
|
|
|
|
|
|
@allure.step("Return all nodes to cluster with check empty map first")
|
2023-05-15 09:59:33 +00:00
|
|
|
def return_nodes_after_stop_with_check_empty_map(self, return_nodes=None) -> None:
|
2023-03-09 10:19:41 +00:00
|
|
|
first_node = True
|
|
|
|
for node in list(return_nodes):
|
|
|
|
with allure.step(f"Start node {node}"):
|
|
|
|
node.start_service()
|
|
|
|
with allure.step(f"Waiting status ready for node {node}"):
|
|
|
|
wait_for_node_to_be_ready(node)
|
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
with allure.step("Make sure that network map is empty"):
|
2023-03-09 10:19:41 +00:00
|
|
|
if first_node:
|
|
|
|
for check_node in list(return_nodes):
|
|
|
|
check_node_not_in_map(check_node, shell=self.shell, alive_node=node)
|
|
|
|
first_node = False
|
|
|
|
|
|
|
|
sleep(datetime_utils.parse_time(MORPH_BLOCK_TIME))
|
|
|
|
self.tick_epochs(1)
|
|
|
|
check_node_in_map(node, shell=self.shell, alive_node=node)
|
|
|
|
stopped_nodes.remove(node)
|