2022-07-11 14:11:26 +00:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
from time import sleep
|
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
|
|
|
from python_keywords.container import create_container
|
|
|
|
from python_keywords.neofs_verbs import get_object, put_object
|
2022-07-13 08:50:48 +00:00
|
|
|
from python_keywords.utility_keywords import generate_file, get_file_hash
|
2022-07-11 14:11:26 +00:00
|
|
|
from sbercloud_helper import SberCloud
|
|
|
|
from ssh_helper import HostClient, HostIsNotAvailable
|
|
|
|
from storage_policy import get_nodes_with_object
|
|
|
|
from wellknown_acl import PUBLIC_ACL
|
|
|
|
|
2022-07-14 06:18:06 +00:00
|
|
|
SSH_PK_PATH = f'{os.getcwd()}/configuration/id_rsa'
|
2022-07-11 14:11:26 +00:00
|
|
|
logger = logging.getLogger('NeoLogger')
|
|
|
|
stopped_hosts = []
|
|
|
|
|
|
|
|
|
2022-07-14 06:18:06 +00:00
|
|
|
@pytest.fixture(scope='session')
|
|
|
|
def free_storage_check():
|
|
|
|
if os.getenv('FREE_STORAGE', default='False').lower() not in ('true', '1'):
|
|
|
|
pytest.skip('Test work only on SberCloud infrastructure')
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
2022-07-11 14:11:26 +00:00
|
|
|
@pytest.fixture(scope='session')
|
|
|
|
def sbercloud_client():
|
2022-07-14 06:18:06 +00:00
|
|
|
with allure.step('Connect to SberCloud'):
|
|
|
|
try:
|
|
|
|
yield SberCloud(f'{os.getcwd()}/configuration/sbercloud.yaml')
|
|
|
|
except Exception:
|
|
|
|
pytest.fail('SberCloud infrastructure not available')
|
|
|
|
yield None
|
2022-07-11 14:11:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='session', autouse=True)
|
|
|
|
def return_all_storage_nodes_fixture(sbercloud_client):
|
|
|
|
yield
|
|
|
|
return_all_storage_nodes(sbercloud_client)
|
|
|
|
|
|
|
|
|
|
|
|
@allure.title('Hard reboot host via magic SysRq option')
|
|
|
|
def panic_reboot_host(ip: str = None):
|
2022-07-14 06:18:06 +00:00
|
|
|
ssh = HostClient(ip=ip, init_ssh_client=False)
|
|
|
|
ssh.pk = SSH_PK_PATH
|
2022-07-11 14:11:26 +00:00
|
|
|
ssh.create_connection(attempts=1)
|
|
|
|
ssh.exec('echo 1 > /proc/sys/kernel/sysrq')
|
|
|
|
with pytest.raises(HostIsNotAvailable):
|
|
|
|
ssh.exec('echo b > /proc/sysrq-trigger', timeout=1)
|
|
|
|
|
|
|
|
|
|
|
|
def return_all_storage_nodes(sbercloud_client: SberCloud):
|
|
|
|
for host in stopped_hosts:
|
|
|
|
sbercloud_client.start_node(node_ip=host.split(':')[-2])
|
|
|
|
stopped_hosts.remove(host)
|
|
|
|
|
|
|
|
|
|
|
|
def wait_object_replication(wallet, cid, oid, expected_copies: int) -> [str]:
|
|
|
|
sleep_interval, attempts = 10, 12
|
|
|
|
nodes = []
|
|
|
|
for __attempt in range(attempts):
|
|
|
|
nodes = get_nodes_with_object(wallet, cid, oid)
|
|
|
|
if len(nodes) == expected_copies:
|
|
|
|
return nodes
|
|
|
|
sleep(sleep_interval)
|
|
|
|
raise AssertionError(f'Expected {expected_copies} copies of object, but found {len(nodes)} ')
|
|
|
|
|
|
|
|
|
|
|
|
@allure.title('Lost and return nodes')
|
|
|
|
@pytest.mark.parametrize('hard_reboot', [True, False])
|
2022-07-14 06:21:20 +00:00
|
|
|
@pytest.mark.failover
|
2022-07-14 06:18:06 +00:00
|
|
|
def test_lost_storage_node(prepare_wallet_and_deposit, sbercloud_client: SberCloud,
|
|
|
|
free_storage_check, hard_reboot: bool):
|
2022-07-13 08:50:48 +00:00
|
|
|
wallet = prepare_wallet_and_deposit
|
2022-07-11 14:11:26 +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-07-11 14:11:26 +00:00
|
|
|
cid = create_container(wallet, rule=placement_rule, basic_acl=PUBLIC_ACL)
|
2022-07-13 08:50:48 +00:00
|
|
|
oid = put_object(wallet, source_file_path, cid)
|
2022-07-11 14:11:26 +00:00
|
|
|
nodes = wait_object_replication(wallet, cid, oid, 2)
|
|
|
|
|
|
|
|
new_nodes = []
|
|
|
|
for node in nodes:
|
|
|
|
with allure.step(f'Stop storage node {node}'):
|
|
|
|
sbercloud_client.stop_node(node_ip=node.split(':')[-2], hard=hard_reboot)
|
|
|
|
new_nodes = wait_object_replication(wallet, cid, oid, 2)
|
|
|
|
|
|
|
|
assert not [node for node in nodes if node in new_nodes]
|
|
|
|
got_file_path = get_object(wallet, cid, oid)
|
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
|
|
|
|
|
|
|
with allure.step(f'Return storage nodes'):
|
|
|
|
return_all_storage_nodes(sbercloud_client)
|
|
|
|
|
|
|
|
wait_object_replication(wallet, cid, oid, 2)
|
|
|
|
|
|
|
|
got_file_path = get_object(wallet, cid, oid)
|
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
|
|
|
|
|
|
|
|
|
|
|
@allure.title('Panic storage node(s)')
|
|
|
|
@pytest.mark.parametrize('sequence', [True, False])
|
2022-07-14 06:21:20 +00:00
|
|
|
@pytest.mark.failover
|
2022-07-14 06:18:06 +00:00
|
|
|
def test_panic_storage_node(prepare_wallet_and_deposit, free_storage_check, sequence: bool):
|
2022-07-13 08:50:48 +00:00
|
|
|
wallet = prepare_wallet_and_deposit
|
2022-07-11 14:11:26 +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-07-11 14:11:26 +00:00
|
|
|
cid = create_container(wallet, rule=placement_rule, basic_acl=PUBLIC_ACL)
|
2022-07-13 08:50:48 +00:00
|
|
|
oid = put_object(wallet, source_file_path, cid)
|
2022-07-11 14:11:26 +00:00
|
|
|
|
|
|
|
with allure.step(f'Return storage nodes'):
|
|
|
|
nodes = wait_object_replication(wallet, cid, oid, 2)
|
|
|
|
for node in nodes:
|
|
|
|
panic_reboot_host(ip=node.split(':')[-2])
|
|
|
|
if sequence:
|
|
|
|
wait_object_replication(wallet, cid, oid, 2)
|
|
|
|
|
|
|
|
if not sequence:
|
|
|
|
wait_object_replication(wallet, cid, oid, 2)
|
|
|
|
|
|
|
|
got_file_path = get_object(wallet, cid, oid)
|
2022-07-13 08:50:48 +00:00
|
|
|
assert get_file_hash(source_file_path) == get_file_hash(got_file_path)
|