2022-07-11 14:11:26 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2022-09-28 12:07:16 +00:00
|
|
|
from common import (
|
|
|
|
STORAGE_NODE_SSH_PASSWORD,
|
|
|
|
STORAGE_NODE_SSH_PRIVATE_KEY_PATH,
|
|
|
|
STORAGE_NODE_SSH_USER,
|
|
|
|
)
|
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-07-11 14:11:26 +00:00
|
|
|
from python_keywords.container import create_container
|
|
|
|
from python_keywords.neofs_verbs import get_object, put_object
|
2022-08-01 07:41:04 +00:00
|
|
|
from sbercloud_helper import SberCloud, SberCloudConfig
|
2022-08-03 15:20:50 +00:00
|
|
|
from ssh_helper import HostClient
|
2022-07-11 14:11:26 +00:00
|
|
|
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-09-28 12:07:16 +00:00
|
|
|
@pytest.fixture(scope="session")
|
2022-07-11 14:11:26 +00:00
|
|
|
def sbercloud_client():
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step("Connect to SberCloud"):
|
2022-07-14 06:18:06 +00:00
|
|
|
try:
|
2022-08-01 07:41:04 +00:00
|
|
|
config = SberCloudConfig.from_env()
|
|
|
|
yield SberCloud(config)
|
2022-08-01 06:16:36 +00:00
|
|
|
except Exception as err:
|
2022-09-28 12:07:16 +00:00
|
|
|
pytest.fail(f"SberCloud infrastructure not available. Error\n{err}")
|
2022-07-11 14:11:26 +00:00
|
|
|
|
|
|
|
|
2022-07-14 07:33:45 +00:00
|
|
|
@pytest.fixture(autouse=True)
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.step("Return all storage nodes")
|
2022-07-11 14:11:26 +00:00
|
|
|
def return_all_storage_nodes_fixture(sbercloud_client):
|
|
|
|
yield
|
|
|
|
return_all_storage_nodes(sbercloud_client)
|
|
|
|
|
|
|
|
|
|
|
|
def panic_reboot_host(ip: str = None):
|
2022-09-28 12:07:16 +00:00
|
|
|
ssh = HostClient(
|
|
|
|
ip=ip,
|
|
|
|
login=STORAGE_NODE_SSH_USER,
|
|
|
|
password=STORAGE_NODE_SSH_PASSWORD,
|
|
|
|
private_key_path=STORAGE_NODE_SSH_PRIVATE_KEY_PATH,
|
|
|
|
)
|
2022-08-01 06:16:36 +00:00
|
|
|
ssh.exec('sudo sh -c "echo 1 > /proc/sys/kernel/sysrq"')
|
2022-09-28 12:07:16 +00:00
|
|
|
ssh_stdin, _, _ = ssh.ssh_client.exec_command(
|
|
|
|
'sudo sh -c "echo b > /proc/sysrq-trigger"', timeout=1
|
|
|
|
)
|
2022-08-02 06:43:56 +00:00
|
|
|
ssh_stdin.close()
|
2022-07-11 14:11:26 +00:00
|
|
|
|
|
|
|
|
2022-08-01 07:41:04 +00:00
|
|
|
def return_all_storage_nodes(sbercloud_client: SberCloud) -> None:
|
2022-08-01 06:16:36 +00:00
|
|
|
for host in list(stopped_hosts):
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step(f"Start storage node {host}"):
|
|
|
|
sbercloud_client.start_node(node_ip=host.split(":")[-2])
|
2022-08-01 06:16:36 +00:00
|
|
|
stopped_hosts.remove(host)
|
|
|
|
|
2022-07-14 07:20:39 +00:00
|
|
|
wait_all_storage_node_returned()
|
2022-07-11 14:11:26 +00:00
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.title("Lost and returned nodes")
|
|
|
|
@pytest.mark.parametrize("hard_reboot", [True, False])
|
2022-07-14 06:21:20 +00:00
|
|
|
@pytest.mark.failover
|
2022-09-28 12:07:16 +00:00
|
|
|
def test_lost_storage_node(
|
|
|
|
prepare_wallet_and_deposit,
|
2022-10-13 18:53:44 +00:00
|
|
|
client_shell,
|
2022-09-28 12:07:16 +00:00
|
|
|
sbercloud_client: SberCloud,
|
|
|
|
cloud_infrastructure_check,
|
|
|
|
hard_reboot: bool,
|
|
|
|
):
|
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)
|
|
|
|
nodes = wait_object_replication_on_nodes(wallet, cid, oid, 2, shell=client_shell)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
|
|
|
new_nodes = []
|
|
|
|
for node in nodes:
|
2022-07-14 07:20:39 +00:00
|
|
|
stopped_hosts.append(node)
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step(f"Stop storage node {node}"):
|
|
|
|
sbercloud_client.stop_node(node_ip=node.split(":")[-2], hard=hard_reboot)
|
2022-10-13 18:53:44 +00:00
|
|
|
new_nodes = wait_object_replication_on_nodes(
|
|
|
|
wallet, cid, oid, 2, shell=client_shell, excluded_nodes=[node]
|
|
|
|
)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
|
|
|
assert not [node for node in nodes if node in new_nodes]
|
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-13 08:50:48 +00:00
|
|
|
assert get_file_hash(source_file_path) == get_file_hash(got_file_path)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step(f"Return storage nodes"):
|
2022-07-11 14:11:26 +00:00
|
|
|
return_all_storage_nodes(sbercloud_client)
|
|
|
|
|
2022-10-13 18:53:44 +00:00
|
|
|
new_nodes = wait_object_replication_on_nodes(wallet, cid, oid, 2, shell=client_shell)
|
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-13 08:50:48 +00:00
|
|
|
assert get_file_hash(source_file_path) == get_file_hash(got_file_path)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.title("Panic storage node(s)")
|
|
|
|
@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 18:53:44 +00:00
|
|
|
def test_panic_storage_node(
|
|
|
|
prepare_wallet_and_deposit, client_shell, cloud_infrastructure_check, sequence: bool
|
|
|
|
):
|
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 18:53:44 +00:00
|
|
|
nodes = wait_object_replication_on_nodes(wallet, cid, oid, 2, shell=client_shell)
|
2022-08-19 02:22:20 +00:00
|
|
|
new_nodes: list[str] = []
|
2022-09-28 12:07:16 +00:00
|
|
|
allure.attach("\n".join(nodes), "Current nodes with object", allure.attachment_type.TEXT)
|
2022-07-14 07:20:39 +00:00
|
|
|
for node in nodes:
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step(f"Hard reboot host {node} via magic SysRq option"):
|
|
|
|
panic_reboot_host(ip=node.split(":")[-2])
|
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 18:53:44 +00:00
|
|
|
wallet, cid, oid, 2, shell=client_shell, excluded_nodes=[node]
|
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),
|
|
|
|
f"Nodes with object after {node} fail",
|
|
|
|
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)
|