2022-07-11 14:11:26 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2022-08-03 15:20:50 +00:00
|
|
|
from failover_utils import wait_all_storage_node_returned, wait_object_replication_on_nodes
|
2022-10-11 08:18:08 +00:00
|
|
|
from file_helper import generate_file, get_file_hash
|
2022-10-13 16:13:45 +00:00
|
|
|
from neofs_testlib.hosting import Host, Hosting
|
|
|
|
from neofs_testlib.shell import CommandOptions
|
2022-07-11 14:11:26 +00:00
|
|
|
from python_keywords.container import create_container
|
|
|
|
from python_keywords.neofs_verbs import get_object, put_object
|
|
|
|
from wellknown_acl import PUBLIC_ACL
|
2022-08-03 15:20:50 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
logger = logging.getLogger("NeoLogger")
|
2022-07-11 14:11:26 +00:00
|
|
|
stopped_hosts = []
|
|
|
|
|
|
|
|
|
2022-07-14 07:33:45 +00:00
|
|
|
@pytest.fixture(autouse=True)
|
2022-10-13 16:13:45 +00:00
|
|
|
@allure.step("Return all stopped hosts")
|
|
|
|
def after_run_return_all_stopped_hosts(hosting: Hosting):
|
2022-07-11 14:11:26 +00:00
|
|
|
yield
|
2022-10-13 16:13:45 +00:00
|
|
|
return_stopped_hosts(hosting)
|
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-10-13 16:13:45 +00:00
|
|
|
def return_stopped_hosts(hosting: Hosting) -> None:
|
2022-10-09 20:01:59 +00:00
|
|
|
for host_address in list(stopped_hosts):
|
|
|
|
with allure.step(f"Start host {host_address}"):
|
|
|
|
host = hosting.get_host_by_address(host_address)
|
|
|
|
host.start_host()
|
|
|
|
stopped_hosts.remove(host_address)
|
2022-08-01 06:16:36 +00:00
|
|
|
|
2022-10-09 20:01:59 +00:00
|
|
|
wait_all_storage_node_returned(hosting)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
|
|
|
|
2022-10-13 16:13:45 +00:00
|
|
|
@allure.title("Lose and return storage node's host")
|
2022-09-28 12:07:16 +00:00
|
|
|
@pytest.mark.parametrize("hard_reboot", [True, False])
|
2022-07-14 06:21:20 +00:00
|
|
|
@pytest.mark.failover
|
2022-10-13 16:13:45 +00:00
|
|
|
def test_lose_storage_node_host(
|
2022-09-28 12:07:16 +00:00
|
|
|
prepare_wallet_and_deposit,
|
2022-10-13 18:53:44 +00:00
|
|
|
client_shell,
|
2022-10-09 20:01:59 +00:00
|
|
|
hosting: Hosting,
|
2022-09-28 12:07:16 +00:00
|
|
|
hard_reboot: bool,
|
2022-10-13 12:12:28 +00:00
|
|
|
require_multiple_hosts,
|
2022-09-28 12:07:16 +00:00
|
|
|
):
|
2022-07-13 08:50:48 +00:00
|
|
|
wallet = prepare_wallet_and_deposit
|
2022-09-28 12:07:16 +00:00
|
|
|
placement_rule = "REP 2 IN X CBF 2 SELECT 2 FROM * AS X"
|
2022-07-13 08:50:48 +00:00
|
|
|
source_file_path = generate_file()
|
2022-10-13 18:53:44 +00:00
|
|
|
cid = create_container(wallet, shell=client_shell, rule=placement_rule, basic_acl=PUBLIC_ACL)
|
|
|
|
oid = put_object(wallet, source_file_path, cid, shell=client_shell)
|
2022-10-13 16:13:45 +00:00
|
|
|
node_endpoints = wait_object_replication_on_nodes(wallet, cid, oid, 2, shell=client_shell)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
2022-10-13 16:13:45 +00:00
|
|
|
for node_endpoint in node_endpoints:
|
|
|
|
host_address = node_endpoint.split(":")[0]
|
|
|
|
host = hosting.get_host_by_address(host_address)
|
2022-10-09 20:01:59 +00:00
|
|
|
stopped_hosts.append(host.config.address)
|
2022-10-13 16:13:45 +00:00
|
|
|
|
|
|
|
with allure.step(f"Stop host {host_address}"):
|
2022-10-09 20:01:59 +00:00
|
|
|
host.stop_host("hard" if hard_reboot else "soft")
|
2022-07-11 14:11:26 +00:00
|
|
|
|
2022-10-21 14:53:54 +00:00
|
|
|
new_nodes = wait_object_replication_on_nodes(
|
|
|
|
wallet, cid, oid, 2, shell=client_shell, excluded_nodes=[node_endpoint]
|
|
|
|
)
|
2022-10-13 16:13:45 +00:00
|
|
|
assert all(old_node not in new_nodes for old_node in node_endpoints)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
2022-10-13 16:13:45 +00:00
|
|
|
with allure.step("Check object data is not corrupted"):
|
2022-10-21 14:53:54 +00:00
|
|
|
got_file_path = get_object(wallet, cid, oid, endpoint=new_nodes[0], shell=client_shell)
|
2022-10-13 16:13:45 +00:00
|
|
|
assert get_file_hash(source_file_path) == get_file_hash(got_file_path)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
2022-10-13 16:13:45 +00:00
|
|
|
with allure.step(f"Return all hosts"):
|
|
|
|
return_stopped_hosts(hosting)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
2022-10-13 16:13:45 +00:00
|
|
|
with allure.step("Check object data is not corrupted"):
|
|
|
|
new_nodes = wait_object_replication_on_nodes(wallet, cid, oid, 2, shell=client_shell)
|
|
|
|
got_file_path = get_object(wallet, cid, oid, shell=client_shell, endpoint=new_nodes[0])
|
|
|
|
assert get_file_hash(source_file_path) == get_file_hash(got_file_path)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
|
|
|
|
2022-10-13 16:13:45 +00:00
|
|
|
@allure.title("Panic storage node's host")
|
2022-09-28 12:07:16 +00:00
|
|
|
@pytest.mark.parametrize("sequence", [True, False])
|
2022-08-01 06:16:36 +00:00
|
|
|
@pytest.mark.failover_panic
|
2022-07-14 06:21:20 +00:00
|
|
|
@pytest.mark.failover
|
2022-10-13 16:13:45 +00:00
|
|
|
def test_panic_storage_node_host(
|
|
|
|
prepare_wallet_and_deposit,
|
|
|
|
client_shell,
|
|
|
|
hosting: Hosting,
|
|
|
|
require_multiple_hosts,
|
|
|
|
sequence: bool,
|
2022-10-13 18:53:44 +00:00
|
|
|
):
|
2022-07-13 08:50:48 +00:00
|
|
|
wallet = prepare_wallet_and_deposit
|
2022-09-28 12:07:16 +00:00
|
|
|
placement_rule = "REP 2 IN X CBF 2 SELECT 2 FROM * AS X"
|
2022-07-13 08:50:48 +00:00
|
|
|
source_file_path = generate_file()
|
2022-10-13 18:53:44 +00:00
|
|
|
cid = create_container(wallet, shell=client_shell, rule=placement_rule, basic_acl=PUBLIC_ACL)
|
|
|
|
oid = put_object(wallet, source_file_path, cid, shell=client_shell)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
2022-10-13 16:13:45 +00:00
|
|
|
node_endpoints = wait_object_replication_on_nodes(wallet, cid, oid, 2, shell=client_shell)
|
|
|
|
allure.attach(
|
|
|
|
"\n".join(node_endpoints),
|
|
|
|
"Current nodes with object",
|
|
|
|
allure.attachment_type.TEXT,
|
|
|
|
)
|
|
|
|
|
2022-08-19 02:22:20 +00:00
|
|
|
new_nodes: list[str] = []
|
2022-10-13 16:13:45 +00:00
|
|
|
for node_endpoint in node_endpoints:
|
|
|
|
host_address = node_endpoint.split(":")[0]
|
|
|
|
|
|
|
|
with allure.step(f"Hard reboot host {node_endpoint} via magic SysRq option"):
|
|
|
|
host = hosting.get_host_by_address(host_address)
|
|
|
|
panic_reboot_host(host)
|
2022-07-11 14:11:26 +00:00
|
|
|
if sequence:
|
2022-08-01 06:16:36 +00:00
|
|
|
try:
|
2022-09-28 12:07:16 +00:00
|
|
|
new_nodes = wait_object_replication_on_nodes(
|
2022-10-13 16:13:45 +00:00
|
|
|
wallet, cid, oid, 2, shell=client_shell, excluded_nodes=[node_endpoint]
|
2022-09-28 12:07:16 +00:00
|
|
|
)
|
2022-08-01 06:16:36 +00:00
|
|
|
except AssertionError:
|
2022-10-13 18:53:44 +00:00
|
|
|
new_nodes = wait_object_replication_on_nodes(
|
|
|
|
wallet, cid, oid, 2, shell=client_shell
|
|
|
|
)
|
2022-08-01 06:16:36 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
allure.attach(
|
|
|
|
"\n".join(new_nodes),
|
2022-10-13 16:13:45 +00:00
|
|
|
f"Nodes with object after {node_endpoint} fail",
|
2022-09-28 12:07:16 +00:00
|
|
|
allure.attachment_type.TEXT,
|
|
|
|
)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
2022-07-14 07:20:39 +00:00
|
|
|
if not sequence:
|
2022-10-13 18:53:44 +00:00
|
|
|
new_nodes = wait_object_replication_on_nodes(wallet, cid, oid, 2, shell=client_shell)
|
2022-09-28 12:07:16 +00:00
|
|
|
allure.attach(
|
|
|
|
"\n".join(new_nodes), "Nodes with object after nodes fail", allure.attachment_type.TEXT
|
|
|
|
)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
2022-10-13 18:53:44 +00:00
|
|
|
got_file_path = get_object(wallet, cid, oid, shell=client_shell, endpoint=new_nodes[0])
|
2022-07-14 07:20:39 +00:00
|
|
|
assert get_file_hash(source_file_path) == get_file_hash(got_file_path)
|