2022-07-11 14:11:26 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2022-12-05 22:31:45 +00:00
|
|
|
from cluster import Cluster, StorageNode
|
|
|
|
from failover_utils import wait_all_storage_nodes_returned, wait_object_replication
|
2022-10-11 08:18:08 +00:00
|
|
|
from file_helper import generate_file, get_file_hash
|
2022-12-05 22:31:45 +00:00
|
|
|
from neofs_testlib.hosting import Host
|
2022-10-13 16:13:45 +00:00
|
|
|
from neofs_testlib.shell import CommandOptions
|
2022-07-11 14:11:26 +00:00
|
|
|
from python_keywords.container import create_container
|
2022-12-05 22:31:45 +00:00
|
|
|
from python_keywords.neofs_verbs import get_object, put_object_to_random_node
|
2022-07-11 14:11:26 +00:00
|
|
|
from wellknown_acl import PUBLIC_ACL
|
2022-08-03 15:20:50 +00:00
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
from steps.cluster_test_base import ClusterTestBase
|
|
|
|
|
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-11-10 05:27:52 +00:00
|
|
|
@pytest.fixture(scope="function", autouse=True)
|
2022-10-13 16:13:45 +00:00
|
|
|
@allure.step("Return all stopped hosts")
|
2022-12-05 22:31:45 +00:00
|
|
|
def after_run_return_all_stopped_hosts(cluster: Cluster):
|
2022-07-11 14:11:26 +00:00
|
|
|
yield
|
2022-12-05 22:31:45 +00:00
|
|
|
return_stopped_hosts(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
|
|
|
|
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
def return_stopped_hosts(cluster: Cluster) -> None:
|
|
|
|
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
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
wait_all_storage_nodes_returned(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(
|
|
|
|
self,
|
|
|
|
default_wallet,
|
|
|
|
hard_reboot: bool,
|
|
|
|
require_multiple_hosts,
|
|
|
|
):
|
|
|
|
wallet = default_wallet
|
|
|
|
placement_rule = "REP 2 IN X CBF 2 SELECT 2 FROM * AS X"
|
|
|
|
source_file_path = generate_file()
|
|
|
|
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)
|
|
|
|
|
|
|
|
with allure.step(f"Return all hosts"):
|
|
|
|
return_stopped_hosts(self.cluster)
|
|
|
|
|
|
|
|
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(
|
|
|
|
self,
|
|
|
|
default_wallet,
|
|
|
|
require_multiple_hosts,
|
|
|
|
sequence: bool,
|
|
|
|
):
|
|
|
|
wallet = default_wallet
|
|
|
|
placement_rule = "REP 2 IN X CBF 2 SELECT 2 FROM * AS X"
|
|
|
|
source_file_path = generate_file()
|
|
|
|
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(
|
|
|
|
"\n".join(nodes),
|
|
|
|
"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(
|
|
|
|
"\n".join(new_nodes),
|
|
|
|
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(
|
|
|
|
"\n".join(new_nodes),
|
|
|
|
"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)
|