2022-08-01 06:16:36 +00:00
|
|
|
import logging
|
|
|
|
from random import choices
|
|
|
|
from time import sleep
|
|
|
|
|
|
|
|
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-08-01 06:16:36 +00:00
|
|
|
from iptables_helper import IpTablesHelper
|
2022-10-09 20:01:59 +00:00
|
|
|
from neofs_testlib.hosting import Hosting
|
2022-08-01 06:16:36 +00:00
|
|
|
from python_keywords.container import create_container
|
|
|
|
from python_keywords.neofs_verbs import get_object, put_object
|
|
|
|
from ssh_helper import HostClient
|
|
|
|
from wellknown_acl import PUBLIC_ACL
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
logger = logging.getLogger("NeoLogger")
|
|
|
|
STORAGE_NODE_COMMUNICATION_PORT = "8080"
|
|
|
|
STORAGE_NODE_COMMUNICATION_PORT_TLS = "8082"
|
2022-08-01 06:16:36 +00:00
|
|
|
PORTS_TO_BLOCK = [STORAGE_NODE_COMMUNICATION_PORT, STORAGE_NODE_COMMUNICATION_PORT_TLS]
|
|
|
|
blocked_hosts = []
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.step("Restore network")
|
2022-10-09 20:01:59 +00:00
|
|
|
def restore_network(hosting: Hosting):
|
2022-08-01 06:16:36 +00:00
|
|
|
yield
|
|
|
|
|
|
|
|
not_empty = len(blocked_hosts) != 0
|
|
|
|
for host in list(blocked_hosts):
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step(f"Start storage node {host}"):
|
|
|
|
client = HostClient(
|
|
|
|
ip=host,
|
|
|
|
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
|
|
|
with client.create_ssh_connection():
|
|
|
|
IpTablesHelper.restore_input_traffic_to_port(client, PORTS_TO_BLOCK)
|
|
|
|
blocked_hosts.remove(host)
|
|
|
|
if not_empty:
|
2022-10-09 20:01:59 +00:00
|
|
|
wait_all_storage_node_returned(hosting)
|
2022-08-01 06:16:36 +00:00
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.title("Block Storage node traffic")
|
2022-08-01 06:16:36 +00:00
|
|
|
@pytest.mark.failover
|
|
|
|
@pytest.mark.failover_net
|
2022-10-13 12:12:28 +00:00
|
|
|
def test_block_storage_node_traffic(prepare_wallet_and_deposit, client_shell, require_multiple_hosts):
|
2022-08-01 06:16:36 +00:00
|
|
|
"""
|
|
|
|
Block storage nodes traffic using iptables and wait for replication for objects.
|
|
|
|
"""
|
|
|
|
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-08-01 06:16:36 +00:00
|
|
|
excluded_nodes = []
|
|
|
|
wakeup_node_timeout = 10 # timeout to let nodes detect that traffic has blocked
|
|
|
|
nodes_to_block_count = 2
|
|
|
|
|
|
|
|
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-08-01 06:16:36 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
logger.info(f"Nodes are {nodes}")
|
|
|
|
random_nodes = [(node, node.split(":")[0]) for node in nodes]
|
2022-08-01 06:16:36 +00:00
|
|
|
if nodes_to_block_count > len(nodes):
|
2022-09-28 12:07:16 +00:00
|
|
|
random_nodes = [(node, node.split(":")[0]) for node in choices(nodes, k=2)]
|
2022-08-01 06:16:36 +00:00
|
|
|
|
|
|
|
for random_node, random_node_ip in random_nodes:
|
2022-09-28 12:07:16 +00:00
|
|
|
client = HostClient(
|
|
|
|
ip=random_node_ip,
|
|
|
|
login=STORAGE_NODE_SSH_USER,
|
|
|
|
password=STORAGE_NODE_SSH_PASSWORD,
|
|
|
|
private_key_path=STORAGE_NODE_SSH_PRIVATE_KEY_PATH,
|
|
|
|
)
|
|
|
|
|
|
|
|
with allure.step(f"Block incoming traffic for node {random_node} on port {PORTS_TO_BLOCK}"):
|
2022-08-01 06:16:36 +00:00
|
|
|
with client.create_ssh_connection():
|
|
|
|
IpTablesHelper.drop_input_traffic_to_port(client, PORTS_TO_BLOCK)
|
|
|
|
blocked_hosts.append(random_node_ip)
|
|
|
|
excluded_nodes.append(random_node)
|
|
|
|
sleep(wakeup_node_timeout)
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
new_nodes = wait_object_replication_on_nodes(
|
|
|
|
wallet, cid, oid, 2, excluded_nodes=excluded_nodes
|
|
|
|
)
|
2022-08-01 06:16:36 +00:00
|
|
|
|
|
|
|
assert random_node not 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-08-01 06:16:36 +00:00
|
|
|
assert get_file_hash(source_file_path) == get_file_hash(got_file_path)
|
|
|
|
|
|
|
|
for random_node, random_node_ip in random_nodes:
|
2022-09-28 12:07:16 +00:00
|
|
|
client = HostClient(
|
|
|
|
ip=random_node_ip,
|
|
|
|
login=STORAGE_NODE_SSH_USER,
|
|
|
|
password=STORAGE_NODE_SSH_PASSWORD,
|
|
|
|
private_key_path=STORAGE_NODE_SSH_PRIVATE_KEY_PATH,
|
|
|
|
)
|
|
|
|
|
|
|
|
with allure.step(
|
|
|
|
f"Unblock incoming traffic for node {random_node} on port {PORTS_TO_BLOCK}"
|
|
|
|
):
|
2022-08-01 06:16:36 +00:00
|
|
|
with client.create_ssh_connection():
|
|
|
|
IpTablesHelper.restore_input_traffic_to_port(client, PORTS_TO_BLOCK)
|
|
|
|
blocked_hosts.remove(random_node_ip)
|
|
|
|
sleep(wakeup_node_timeout)
|
|
|
|
|
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-10-13 18:53:44 +00:00
|
|
|
got_file_path = get_object(wallet, cid, oid, shell=client_shell, endpoint=new_nodes[0])
|
2022-08-01 06:16:36 +00:00
|
|
|
assert get_file_hash(source_file_path) == get_file_hash(got_file_path)
|