2022-07-08 17:24:55 +00:00
|
|
|
import logging
|
|
|
|
from random import choice
|
|
|
|
from time import sleep
|
2022-10-09 20:01:59 +00:00
|
|
|
from typing import Optional
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2022-09-23 11:09:41 +00:00
|
|
|
from common import (
|
|
|
|
COMPLEX_OBJ_SIZE,
|
|
|
|
MORPH_BLOCK_TIME,
|
|
|
|
NEOFS_CONTRACT_CACHE_TIMEOUT,
|
|
|
|
NEOFS_NETMAP_DICT,
|
|
|
|
STORAGE_RPC_ENDPOINT_1,
|
|
|
|
STORAGE_WALLET_PASS,
|
|
|
|
)
|
2022-08-01 10:15:02 +00:00
|
|
|
from data_formatters import get_wallet_public_key
|
2022-07-07 18:48:47 +00:00
|
|
|
from epoch import tick_epoch
|
2022-10-11 08:18:08 +00:00
|
|
|
from file_helper import generate_file
|
2022-08-12 16:44:10 +00:00
|
|
|
from grpc_responses import OBJECT_NOT_FOUND, error_matches_status
|
2022-10-09 20:01:59 +00:00
|
|
|
from neofs_testlib.hosting import Hosting
|
2022-10-13 16:13:45 +00:00
|
|
|
from neofs_testlib.shell import Shell
|
2022-07-08 17:24:55 +00:00
|
|
|
from python_keywords.container import create_container, get_container
|
2022-08-03 15:20:50 +00:00
|
|
|
from python_keywords.failover_utils import wait_object_replication_on_nodes
|
|
|
|
from python_keywords.neofs_verbs import delete_object, get_object, head_object, put_object
|
2022-09-23 11:09:41 +00:00
|
|
|
from python_keywords.node_management import (
|
|
|
|
check_node_in_map,
|
|
|
|
delete_node_data,
|
|
|
|
drop_object,
|
|
|
|
exclude_node_from_network_map,
|
|
|
|
get_locode,
|
|
|
|
get_netmap_snapshot,
|
|
|
|
include_node_to_network_map,
|
|
|
|
node_healthcheck,
|
|
|
|
node_set_status,
|
|
|
|
node_shard_list,
|
|
|
|
node_shard_set_mode,
|
|
|
|
start_nodes,
|
|
|
|
stop_nodes,
|
|
|
|
)
|
2022-07-08 17:24:55 +00:00
|
|
|
from storage_policy import get_nodes_with_object, get_simple_object_copies
|
2022-09-23 11:09:41 +00:00
|
|
|
from utility import parse_time, placement_policy_from_container, wait_for_gc_pass_on_storage_nodes
|
2022-07-08 17:24:55 +00:00
|
|
|
from wellknown_acl import PUBLIC_ACL
|
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
logger = logging.getLogger("NeoLogger")
|
2022-08-03 15:20:50 +00:00
|
|
|
check_nodes = []
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2022-09-23 11:09:41 +00:00
|
|
|
@allure.title("Create container and pick the node with data")
|
2022-10-09 20:01:59 +00:00
|
|
|
def create_container_and_pick_node(prepare_wallet_and_deposit, client_shell, hosting: Hosting):
|
2022-07-08 17:24:55 +00:00
|
|
|
wallet = prepare_wallet_and_deposit
|
|
|
|
file_path = generate_file()
|
2022-09-23 11:09:41 +00:00
|
|
|
placement_rule = "REP 1 IN X CBF 1 SELECT 1 FROM * AS X"
|
2022-07-08 17:24:55 +00:00
|
|
|
|
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, file_path, cid, shell=client_shell)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-10-13 18:53:44 +00:00
|
|
|
nodes = get_nodes_with_object(wallet, cid, oid, shell=client_shell)
|
2022-07-08 17:24:55 +00:00
|
|
|
assert len(nodes) == 1
|
|
|
|
node = nodes[0]
|
|
|
|
|
2022-09-16 13:26:10 +00:00
|
|
|
node_name = choice(
|
2022-09-23 11:09:41 +00:00
|
|
|
[node_name for node_name, params in NEOFS_NETMAP_DICT.items() if params.get("rpc") == node]
|
|
|
|
)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
yield cid, node_name
|
|
|
|
|
2022-10-09 20:01:59 +00:00
|
|
|
shards = node_shard_list(hosting, node_name)
|
2022-07-08 17:24:55 +00:00
|
|
|
assert shards
|
|
|
|
|
|
|
|
for shard in shards:
|
2022-10-09 20:01:59 +00:00
|
|
|
node_shard_set_mode(hosting, node_name, shard, "read-write")
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-10-09 20:01:59 +00:00
|
|
|
node_shard_list(hosting, node_name)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2022-10-09 20:01:59 +00:00
|
|
|
def after_run_start_all_nodes(hosting: Hosting):
|
2022-07-08 17:24:55 +00:00
|
|
|
yield
|
|
|
|
try:
|
2022-10-09 20:01:59 +00:00
|
|
|
start_nodes(hosting, list(NEOFS_NETMAP_DICT.keys()))
|
2022-07-08 17:24:55 +00:00
|
|
|
except Exception as err:
|
2022-09-23 11:09:41 +00:00
|
|
|
logger.error(f"Node start fails with error:\n{err}")
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
2022-08-03 15:20:50 +00:00
|
|
|
@pytest.fixture
|
2022-10-09 20:01:59 +00:00
|
|
|
def return_nodes_after_test_run(client_shell: Shell, hosting: Hosting):
|
2022-08-03 15:20:50 +00:00
|
|
|
yield
|
2022-10-09 20:01:59 +00:00
|
|
|
return_nodes(client_shell, hosting)
|
2022-08-03 15:20:50 +00:00
|
|
|
|
|
|
|
|
2022-11-28 19:27:37 +00:00
|
|
|
@allure.step("Tick epoch with retries")
|
|
|
|
def tick_epoch_with_retries(shell: Shell, attempts: int = 3, timeout: int = 3):
|
|
|
|
for __attempt in range(attempts):
|
|
|
|
try:
|
|
|
|
tick_epoch(shell=shell)
|
|
|
|
except RuntimeError:
|
|
|
|
sleep(timeout)
|
|
|
|
continue
|
|
|
|
return
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
@allure.step("Return node to cluster")
|
2022-10-09 20:01:59 +00:00
|
|
|
def return_nodes(shell: Shell, hosting: Hosting, alive_node: Optional[str] = None) -> None:
|
2022-08-03 15:20:50 +00:00
|
|
|
for node in list(check_nodes):
|
2022-09-23 11:09:41 +00:00
|
|
|
with allure.step(f"Start node {node}"):
|
2022-10-09 20:01:59 +00:00
|
|
|
host = hosting.get_host_by_service(node)
|
|
|
|
host.start_service(node)
|
2022-09-23 11:09:41 +00:00
|
|
|
with allure.step(f"Waiting status ready for node {node}"):
|
2022-10-09 20:01:59 +00:00
|
|
|
wait_for_node_to_be_ready(hosting, node)
|
2022-08-15 14:40:04 +00:00
|
|
|
|
2022-08-15 15:21:23 +00:00
|
|
|
# We need to wait for node to establish notifications from morph-chain
|
|
|
|
# Otherwise it will hang up when we will try to set status
|
2022-09-23 11:09:41 +00:00
|
|
|
sleep(parse_time(MORPH_BLOCK_TIME))
|
2022-08-03 15:20:50 +00:00
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
with allure.step(f"Move node {node} to online state"):
|
2022-10-09 20:01:59 +00:00
|
|
|
node_set_status(hosting, node, status="online", retries=2)
|
2022-08-03 15:20:50 +00:00
|
|
|
|
|
|
|
check_nodes.remove(node)
|
2022-09-23 11:09:41 +00:00
|
|
|
sleep(parse_time(MORPH_BLOCK_TIME))
|
2022-11-28 19:27:37 +00:00
|
|
|
tick_epoch_with_retries(attempts=3)
|
2022-10-13 18:53:44 +00:00
|
|
|
check_node_in_map(node, shell=shell, alive_node=alive_node)
|
2022-08-03 15:20:50 +00:00
|
|
|
|
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
@allure.title("Add one node to cluster")
|
2022-08-03 15:20:50 +00:00
|
|
|
@pytest.mark.add_nodes
|
|
|
|
@pytest.mark.node_mgmt
|
2022-10-13 18:53:44 +00:00
|
|
|
def test_add_nodes(
|
2022-10-13 16:13:45 +00:00
|
|
|
prepare_tmp_dir,
|
|
|
|
client_shell,
|
|
|
|
prepare_wallet_and_deposit,
|
|
|
|
return_nodes_after_test_run,
|
|
|
|
hosting: Hosting,
|
2022-10-13 18:53:44 +00:00
|
|
|
):
|
2022-08-03 15:20:50 +00:00
|
|
|
wallet = prepare_wallet_and_deposit
|
2022-09-23 11:09:41 +00:00
|
|
|
placement_rule_3 = "REP 3 IN X CBF 1 SELECT 3 FROM * AS X"
|
|
|
|
placement_rule_4 = "REP 4 IN X CBF 1 SELECT 4 FROM * AS X"
|
2022-08-03 15:20:50 +00:00
|
|
|
source_file_path = generate_file()
|
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
additional_node = choice(
|
|
|
|
[
|
|
|
|
node
|
|
|
|
for node, node_config in NEOFS_NETMAP_DICT.items()
|
|
|
|
if node_config.get("rpc") != STORAGE_RPC_ENDPOINT_1
|
|
|
|
]
|
|
|
|
)
|
2022-08-03 15:20:50 +00:00
|
|
|
alive_node = choice([node for node in NEOFS_NETMAP_DICT if node != additional_node])
|
|
|
|
|
2022-10-13 18:53:44 +00:00
|
|
|
check_node_in_map(additional_node, shell=client_shell, alive_node=alive_node)
|
2022-08-03 15:20:50 +00:00
|
|
|
|
2022-08-08 07:56:04 +00:00
|
|
|
# Add node to recovery list before messing with it
|
|
|
|
check_nodes.append(additional_node)
|
2022-10-13 16:13:45 +00:00
|
|
|
exclude_node_from_network_map(hosting, additional_node, alive_node, shell=client_shell)
|
2022-10-09 20:01:59 +00:00
|
|
|
delete_node_data(hosting, additional_node)
|
2022-08-03 15:20:50 +00:00
|
|
|
|
2022-10-13 16:13:45 +00:00
|
|
|
cid = create_container(wallet, rule=placement_rule_3, basic_acl=PUBLIC_ACL, shell=client_shell)
|
2022-09-23 11:09:41 +00:00
|
|
|
oid = put_object(
|
2022-10-13 16:13:45 +00:00
|
|
|
wallet,
|
|
|
|
source_file_path,
|
|
|
|
cid,
|
|
|
|
endpoint=NEOFS_NETMAP_DICT[alive_node].get("rpc"),
|
|
|
|
shell=client_shell,
|
2022-09-23 11:09:41 +00:00
|
|
|
)
|
2022-10-13 16:13:45 +00:00
|
|
|
wait_object_replication_on_nodes(wallet, cid, oid, 3, shell=client_shell)
|
2022-08-03 15:20:50 +00:00
|
|
|
|
2022-10-09 20:01:59 +00:00
|
|
|
return_nodes(shell=client_shell, hosting=hosting, alive_node=alive_node)
|
2022-08-03 15:20:50 +00:00
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
with allure.step("Check data could be replicated to new node"):
|
2022-09-16 13:26:10 +00:00
|
|
|
random_node = choice(
|
2022-09-23 11:09:41 +00:00
|
|
|
[node for node in NEOFS_NETMAP_DICT if node not in (additional_node, alive_node)]
|
|
|
|
)
|
2022-10-13 16:13:45 +00:00
|
|
|
exclude_node_from_network_map(hosting, random_node, alive_node, shell=client_shell)
|
2022-08-03 15:20:50 +00:00
|
|
|
|
2022-10-13 16:13:45 +00:00
|
|
|
wait_object_replication_on_nodes(
|
|
|
|
wallet, cid, oid, 3, excluded_nodes=[random_node], shell=client_shell
|
|
|
|
)
|
2022-10-09 20:01:59 +00:00
|
|
|
include_node_to_network_map(hosting, random_node, alive_node, shell=client_shell)
|
2022-10-13 16:13:45 +00:00
|
|
|
wait_object_replication_on_nodes(wallet, cid, oid, 3, shell=client_shell)
|
2022-08-03 15:20:50 +00:00
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
with allure.step("Check container could be created with new node"):
|
2022-10-13 16:13:45 +00:00
|
|
|
cid = create_container(
|
|
|
|
wallet, rule=placement_rule_4, basic_acl=PUBLIC_ACL, shell=client_shell
|
|
|
|
)
|
2022-09-23 11:09:41 +00:00
|
|
|
oid = put_object(
|
2022-10-13 16:13:45 +00:00
|
|
|
wallet,
|
|
|
|
source_file_path,
|
|
|
|
cid,
|
|
|
|
endpoint=NEOFS_NETMAP_DICT[alive_node].get("rpc"),
|
|
|
|
shell=client_shell,
|
2022-09-23 11:09:41 +00:00
|
|
|
)
|
2022-10-13 18:53:44 +00:00
|
|
|
wait_object_replication_on_nodes(wallet, cid, oid, 4, shell=client_shell)
|
2022-08-03 15:20:50 +00:00
|
|
|
|
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
@allure.title("Control Operations with storage nodes")
|
2022-07-08 17:24:55 +00:00
|
|
|
@pytest.mark.node_mgmt
|
2022-10-09 20:01:59 +00:00
|
|
|
def test_nodes_management(prepare_tmp_dir, client_shell, hosting: Hosting):
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
|
|
|
This test checks base control operations with storage nodes (healthcheck, netmap-snapshot, set-status).
|
|
|
|
"""
|
|
|
|
random_node = choice(list(NEOFS_NETMAP_DICT))
|
|
|
|
alive_node = choice([node for node in NEOFS_NETMAP_DICT if node != random_node])
|
2022-07-21 12:25:17 +00:00
|
|
|
|
2022-09-28 09:53:08 +00:00
|
|
|
# Calculate public key that identifies node in netmap
|
2022-09-23 11:09:41 +00:00
|
|
|
random_node_wallet_path = NEOFS_NETMAP_DICT[random_node]["wallet_path"]
|
2022-09-28 09:53:08 +00:00
|
|
|
random_node_netmap_key = get_wallet_public_key(random_node_wallet_path, STORAGE_WALLET_PASS)
|
2022-07-21 14:47:01 +00:00
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
with allure.step("Check node {random_node} is in netmap"):
|
2022-10-13 18:53:44 +00:00
|
|
|
snapshot = get_netmap_snapshot(node_name=alive_node, shell=client_shell)
|
2022-09-23 11:09:41 +00:00
|
|
|
assert random_node_netmap_key in snapshot, f"Expected node {random_node} in netmap"
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
with allure.step("Run health check for all storage nodes"):
|
2022-07-08 17:24:55 +00:00
|
|
|
for node_name in NEOFS_NETMAP_DICT.keys():
|
2022-10-09 20:01:59 +00:00
|
|
|
health_check = node_healthcheck(hosting, node_name)
|
2022-09-23 11:09:41 +00:00
|
|
|
assert health_check.health_status == "READY" and health_check.network_status == "ONLINE"
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
with allure.step(f"Move node {random_node} to offline state"):
|
2022-10-09 20:01:59 +00:00
|
|
|
node_set_status(hosting, random_node, status="offline")
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
sleep(parse_time(MORPH_BLOCK_TIME))
|
2022-10-28 08:01:33 +00:00
|
|
|
tick_epoch(shell=client_shell)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
with allure.step(f"Check node {random_node} went to offline"):
|
2022-10-09 20:01:59 +00:00
|
|
|
health_check = node_healthcheck(hosting, random_node)
|
2022-09-23 11:09:41 +00:00
|
|
|
assert health_check.health_status == "READY" and health_check.network_status == "OFFLINE"
|
2022-10-13 18:53:44 +00:00
|
|
|
snapshot = get_netmap_snapshot(node_name=alive_node, shell=client_shell)
|
2022-09-23 11:09:41 +00:00
|
|
|
assert random_node_netmap_key not in snapshot, f"Expected node {random_node} not in netmap"
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
with allure.step(f"Check node {random_node} went to online"):
|
2022-10-09 20:01:59 +00:00
|
|
|
node_set_status(hosting, random_node, status="online")
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
sleep(parse_time(MORPH_BLOCK_TIME))
|
2022-10-28 08:01:33 +00:00
|
|
|
tick_epoch(shell=client_shell)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
with allure.step(f"Check node {random_node} went to online"):
|
2022-10-09 20:01:59 +00:00
|
|
|
health_check = node_healthcheck(hosting, random_node)
|
2022-09-23 11:09:41 +00:00
|
|
|
assert health_check.health_status == "READY" and health_check.network_status == "ONLINE"
|
2022-10-13 18:53:44 +00:00
|
|
|
snapshot = get_netmap_snapshot(node_name=alive_node, shell=client_shell)
|
2022-09-23 11:09:41 +00:00
|
|
|
assert random_node_netmap_key in snapshot, f"Expected node {random_node} in netmap"
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"placement_rule,expected_copies",
|
|
|
|
[
|
|
|
|
("REP 2 IN X CBF 2 SELECT 2 FROM * AS X", 2),
|
|
|
|
("REP 2 IN X CBF 1 SELECT 2 FROM * AS X", 2),
|
|
|
|
("REP 3 IN X CBF 1 SELECT 3 FROM * AS X", 3),
|
|
|
|
("REP 1 IN X CBF 1 SELECT 1 FROM * AS X", 1),
|
|
|
|
("REP 1 IN X CBF 2 SELECT 1 FROM * AS X", 1),
|
|
|
|
("REP 4 IN X CBF 1 SELECT 4 FROM * AS X", 4),
|
|
|
|
("REP 2 IN X CBF 1 SELECT 4 FROM * AS X", 2),
|
|
|
|
],
|
|
|
|
)
|
2022-07-08 17:24:55 +00:00
|
|
|
@pytest.mark.node_mgmt
|
2022-09-23 11:09:41 +00:00
|
|
|
@allure.title("Test object copies based on placement policy")
|
2022-10-13 16:13:45 +00:00
|
|
|
def test_placement_policy(
|
|
|
|
prepare_wallet_and_deposit, placement_rule, expected_copies, client_shell: Shell
|
|
|
|
):
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
|
|
|
This test checks object's copies based on container's placement policy.
|
|
|
|
"""
|
|
|
|
wallet = prepare_wallet_and_deposit
|
|
|
|
file_path = generate_file()
|
2022-10-13 16:13:45 +00:00
|
|
|
validate_object_copies(wallet, placement_rule, file_path, expected_copies, shell=client_shell)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"placement_rule,expected_copies,nodes",
|
|
|
|
[
|
|
|
|
("REP 4 IN X CBF 1 SELECT 4 FROM * AS X", 4, ["s01", "s02", "s03", "s04"]),
|
|
|
|
(
|
|
|
|
"REP 1 IN LOC_PLACE CBF 1 SELECT 1 FROM LOC_SW AS LOC_PLACE FILTER Country EQ Sweden AS LOC_SW",
|
|
|
|
1,
|
|
|
|
["s03"],
|
|
|
|
),
|
|
|
|
("REP 1 CBF 1 SELECT 1 FROM LOC_SPB FILTER 'UN-LOCODE' EQ 'RU LED' AS LOC_SPB", 1, ["s02"]),
|
|
|
|
(
|
|
|
|
"REP 1 IN LOC_SPB_PLACE REP 1 IN LOC_MSK_PLACE CBF 1 SELECT 1 FROM LOC_SPB AS LOC_SPB_PLACE "
|
|
|
|
"SELECT 1 FROM LOC_MSK AS LOC_MSK_PLACE "
|
|
|
|
"FILTER 'UN-LOCODE' EQ 'RU LED' AS LOC_SPB FILTER 'UN-LOCODE' EQ 'RU MOW' AS LOC_MSK",
|
|
|
|
2,
|
|
|
|
["s01", "s02"],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"REP 4 CBF 1 SELECT 4 FROM LOC_EU FILTER Continent EQ Europe AS LOC_EU",
|
|
|
|
4,
|
|
|
|
["s01", "s02", "s03", "s04"],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"REP 1 CBF 1 SELECT 1 FROM LOC_SPB "
|
|
|
|
"FILTER 'UN-LOCODE' NE 'RU MOW' AND 'UN-LOCODE' NE 'SE STO' AND 'UN-LOCODE' NE 'FI HEL' AS LOC_SPB",
|
|
|
|
1,
|
|
|
|
["s02"],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"REP 2 CBF 1 SELECT 2 FROM LOC_RU FILTER SubDivCode NE 'AB' AND SubDivCode NE '18' AS LOC_RU",
|
|
|
|
2,
|
|
|
|
["s01", "s02"],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"REP 2 CBF 1 SELECT 2 FROM LOC_RU FILTER Country EQ 'Russia' AS LOC_RU",
|
|
|
|
2,
|
|
|
|
["s01", "s02"],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"REP 2 CBF 1 SELECT 2 FROM LOC_EU FILTER Country NE 'Russia' AS LOC_EU",
|
|
|
|
2,
|
|
|
|
["s03", "s04"],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2022-07-08 17:24:55 +00:00
|
|
|
@pytest.mark.node_mgmt
|
2022-09-23 11:09:41 +00:00
|
|
|
@allure.title("Test object copies and storage nodes based on placement policy")
|
|
|
|
def test_placement_policy_with_nodes(
|
2022-10-13 16:13:45 +00:00
|
|
|
prepare_wallet_and_deposit, placement_rule, expected_copies, nodes, client_shell: Shell
|
2022-09-23 11:09:41 +00:00
|
|
|
):
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
|
|
|
Based on container's placement policy check that storage nodes are piked correctly and object has
|
|
|
|
correct copies amount.
|
|
|
|
"""
|
|
|
|
wallet = prepare_wallet_and_deposit
|
|
|
|
file_path = generate_file()
|
2022-09-23 11:09:41 +00:00
|
|
|
cid, oid, found_nodes = validate_object_copies(
|
2022-10-13 16:13:45 +00:00
|
|
|
wallet, placement_rule, file_path, expected_copies, shell=client_shell
|
2022-09-23 11:09:41 +00:00
|
|
|
)
|
|
|
|
expected_nodes = [NEOFS_NETMAP_DICT[node_name].get("rpc") for node_name in nodes]
|
2022-09-16 13:26:10 +00:00
|
|
|
assert set(found_nodes) == set(
|
2022-09-23 11:09:41 +00:00
|
|
|
expected_nodes
|
|
|
|
), f"Expected nodes {expected_nodes}, got {found_nodes}"
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"placement_rule,expected_copies",
|
|
|
|
[
|
|
|
|
("REP 2 IN X CBF 2 SELECT 6 FROM * AS X", 2),
|
|
|
|
],
|
|
|
|
)
|
2022-07-08 17:24:55 +00:00
|
|
|
@pytest.mark.node_mgmt
|
2022-09-23 11:09:41 +00:00
|
|
|
@allure.title("Negative cases for placement policy")
|
2022-10-13 16:13:45 +00:00
|
|
|
def test_placement_policy_negative(
|
|
|
|
prepare_wallet_and_deposit, placement_rule, expected_copies, client_shell: Shell
|
|
|
|
):
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
|
|
|
Negative test for placement policy.
|
|
|
|
"""
|
|
|
|
wallet = prepare_wallet_and_deposit
|
|
|
|
file_path = generate_file()
|
2022-09-23 11:09:41 +00:00
|
|
|
with pytest.raises(RuntimeError, match=".*not enough nodes to SELECT from.*"):
|
2022-10-13 16:13:45 +00:00
|
|
|
validate_object_copies(
|
|
|
|
wallet, placement_rule, file_path, expected_copies, shell=client_shell
|
|
|
|
)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
2022-10-13 16:13:45 +00:00
|
|
|
@pytest.mark.skip(reason="We cover this scenario in failover tests")
|
2022-11-10 05:27:52 +00:00
|
|
|
@pytest.mark.sanity
|
2022-07-08 17:24:55 +00:00
|
|
|
@pytest.mark.node_mgmt
|
2022-07-14 07:33:45 +00:00
|
|
|
@allure.title("NeoFS object replication on node failover")
|
2022-10-28 08:01:33 +00:00
|
|
|
def test_replication(
|
2022-11-07 07:10:11 +00:00
|
|
|
prepare_wallet_and_deposit, client_shell: Shell, after_run_start_all_nodes, hosting: Hosting
|
2022-10-28 08:01:33 +00:00
|
|
|
):
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
|
|
|
Test checks object replication on storage not failover and come back.
|
|
|
|
"""
|
|
|
|
wallet = prepare_wallet_and_deposit
|
|
|
|
file_path = generate_file()
|
|
|
|
expected_nodes_count = 2
|
|
|
|
|
|
|
|
cid = create_container(wallet, basic_acl=PUBLIC_ACL)
|
|
|
|
oid = put_object(wallet, file_path, cid)
|
|
|
|
|
|
|
|
nodes = get_nodes_with_object(wallet, cid, oid)
|
2022-09-23 11:09:41 +00:00
|
|
|
assert (
|
|
|
|
len(nodes) == expected_nodes_count
|
|
|
|
), f"Expected {expected_nodes_count} copies, got {len(nodes)}"
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
node_names = [name for name, config in NEOFS_NETMAP_DICT.items() if config.get("rpc") in nodes]
|
2022-10-09 20:01:59 +00:00
|
|
|
stopped_nodes = stop_nodes(hosting, 1, node_names)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-10-28 08:22:27 +00:00
|
|
|
wait_for_expected_object_copies(client_shell, wallet, cid, oid)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-10-09 20:01:59 +00:00
|
|
|
start_nodes(hosting, stopped_nodes)
|
2022-10-28 08:01:33 +00:00
|
|
|
tick_epoch(shell=client_shell)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
for node_name in node_names:
|
2022-10-09 20:01:59 +00:00
|
|
|
wait_for_node_go_online(hosting, node_name)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-10-28 08:22:27 +00:00
|
|
|
wait_for_expected_object_copies(client_shell, wallet, cid, oid)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.node_mgmt
|
2022-09-23 11:09:41 +00:00
|
|
|
@allure.title("NeoFS object could be dropped using control command")
|
2022-10-19 06:26:14 +00:00
|
|
|
def test_drop_object(prepare_wallet_and_deposit, client_shell: Shell, hosting: Hosting):
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
|
|
|
Test checks object could be dropped using `neofs-cli control drop-objects` command.
|
|
|
|
"""
|
|
|
|
wallet = prepare_wallet_and_deposit
|
|
|
|
file_path_simple, file_path_complex = generate_file(), generate_file(COMPLEX_OBJ_SIZE)
|
|
|
|
|
|
|
|
locode = get_locode()
|
|
|
|
rule = f"REP 1 CBF 1 SELECT 1 FROM * FILTER 'UN-LOCODE' EQ '{locode}' AS LOC"
|
2022-10-19 06:26:14 +00:00
|
|
|
cid = create_container(wallet, rule=rule, shell=client_shell)
|
|
|
|
oid_simple = put_object(wallet, file_path_simple, cid, shell=client_shell)
|
|
|
|
oid_complex = put_object(wallet, file_path_complex, cid, shell=client_shell)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
for oid in (oid_simple, oid_complex):
|
2022-10-19 06:26:14 +00:00
|
|
|
get_object(wallet, cid, oid, client_shell)
|
|
|
|
head_object(wallet, cid, oid, client_shell)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-10-19 06:26:14 +00:00
|
|
|
nodes = get_nodes_with_object(wallet, cid, oid_simple, shell=client_shell)
|
2022-09-16 13:26:10 +00:00
|
|
|
node_name = choice(
|
2022-09-23 11:09:41 +00:00
|
|
|
[name for name, config in NEOFS_NETMAP_DICT.items() if config.get("rpc") in nodes]
|
|
|
|
)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
for oid in (oid_simple, oid_complex):
|
2022-09-23 11:09:41 +00:00
|
|
|
with allure.step(f"Drop object {oid}"):
|
2022-10-19 06:26:14 +00:00
|
|
|
get_object(wallet, cid, oid, shell=client_shell)
|
|
|
|
head_object(wallet, cid, oid, shell=client_shell)
|
2022-10-09 20:01:59 +00:00
|
|
|
drop_object(hosting, node_name, cid, oid)
|
2022-10-19 06:26:14 +00:00
|
|
|
wait_for_obj_dropped(wallet, cid, oid, client_shell, get_object)
|
|
|
|
wait_for_obj_dropped(wallet, cid, oid, client_shell, head_object)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.node_mgmt
|
2022-09-23 11:09:41 +00:00
|
|
|
@pytest.mark.skip(reason="Need to clarify scenario")
|
|
|
|
@allure.title("Control Operations with storage nodes")
|
2022-10-19 06:26:14 +00:00
|
|
|
def test_shards(
|
|
|
|
prepare_wallet_and_deposit,
|
|
|
|
create_container_and_pick_node,
|
|
|
|
client_shell: Shell,
|
|
|
|
hosting: Hosting,
|
|
|
|
):
|
2022-07-08 17:24:55 +00:00
|
|
|
wallet = prepare_wallet_and_deposit
|
|
|
|
file_path = generate_file()
|
|
|
|
|
2022-08-17 13:14:42 +00:00
|
|
|
cid, node_name = create_container_and_pick_node
|
2022-10-19 06:26:14 +00:00
|
|
|
original_oid = put_object(wallet, file_path, cid, shell=client_shell)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
# for mode in ('read-only', 'degraded'):
|
2022-09-23 11:09:41 +00:00
|
|
|
for mode in ("degraded",):
|
2022-10-09 20:01:59 +00:00
|
|
|
shards = node_shard_list(hosting, node_name)
|
2022-07-08 17:24:55 +00:00
|
|
|
assert shards
|
|
|
|
|
|
|
|
for shard in shards:
|
2022-10-09 20:01:59 +00:00
|
|
|
node_shard_set_mode(hosting, node_name, shard, mode)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-10-09 20:01:59 +00:00
|
|
|
shards = node_shard_list(hosting, node_name)
|
2022-07-08 17:24:55 +00:00
|
|
|
assert shards
|
|
|
|
|
|
|
|
with pytest.raises(RuntimeError):
|
2022-10-19 06:26:14 +00:00
|
|
|
put_object(wallet, file_path, cid, shell=client_shell)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
with pytest.raises(RuntimeError):
|
2022-10-19 06:26:14 +00:00
|
|
|
delete_object(wallet, cid, original_oid, shell=client_shell)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-10-19 06:26:14 +00:00
|
|
|
get_object(wallet, cid, original_oid, shell=client_shell)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
for shard in shards:
|
2022-10-09 20:01:59 +00:00
|
|
|
node_shard_set_mode(hosting, node_name, shard, "read-write")
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-10-09 20:01:59 +00:00
|
|
|
shards = node_shard_list(hosting, node_name)
|
2022-07-08 17:24:55 +00:00
|
|
|
assert shards
|
|
|
|
|
2022-10-19 06:26:14 +00:00
|
|
|
oid = put_object(wallet, file_path, cid, shell=client_shell)
|
|
|
|
delete_object(wallet, cid, oid, shell=client_shell)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
@allure.step("Validate object has {expected_copies} copies")
|
2022-10-13 16:13:45 +00:00
|
|
|
def validate_object_copies(
|
|
|
|
wallet: str, placement_rule: str, file_path: str, expected_copies: int, shell: Shell
|
|
|
|
):
|
|
|
|
cid = create_container(wallet, rule=placement_rule, basic_acl=PUBLIC_ACL, shell=shell)
|
|
|
|
got_policy = placement_policy_from_container(
|
|
|
|
get_container(wallet, cid, json_mode=False, shell=shell)
|
|
|
|
)
|
2022-09-23 11:09:41 +00:00
|
|
|
assert got_policy == placement_rule.replace(
|
|
|
|
"'", ""
|
|
|
|
), f"Expected \n{placement_rule} and got policy \n{got_policy} are the same"
|
2022-10-13 16:13:45 +00:00
|
|
|
oid = put_object(wallet, file_path, cid, shell=shell)
|
|
|
|
nodes = get_nodes_with_object(wallet, cid, oid, shell=shell)
|
2022-09-23 11:09:41 +00:00
|
|
|
assert len(nodes) == expected_copies, f"Expected {expected_copies} copies, got {len(nodes)}"
|
2022-07-08 17:24:55 +00:00
|
|
|
return cid, oid, nodes
|
|
|
|
|
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
@allure.step("Wait for node {node_name} goes online")
|
2022-10-09 20:01:59 +00:00
|
|
|
def wait_for_node_go_online(hosting: Hosting, node_name: str) -> None:
|
2022-07-08 17:24:55 +00:00
|
|
|
timeout, attempts = 5, 20
|
|
|
|
for _ in range(attempts):
|
|
|
|
try:
|
2022-10-09 20:01:59 +00:00
|
|
|
health_check = node_healthcheck(hosting, node_name)
|
2022-09-23 11:09:41 +00:00
|
|
|
assert health_check.health_status == "READY" and health_check.network_status == "ONLINE"
|
2022-07-08 17:24:55 +00:00
|
|
|
return
|
|
|
|
except Exception as err:
|
2022-09-23 11:09:41 +00:00
|
|
|
logger.warning(f"Node {node_name} is not online:\n{err}")
|
2022-09-16 13:26:10 +00:00
|
|
|
sleep(timeout)
|
|
|
|
raise AssertionError(
|
2022-09-23 11:09:41 +00:00
|
|
|
f"Node {node_name} hasn't gone to the READY and ONLINE state after {timeout * attempts} second"
|
|
|
|
)
|
2022-09-16 13:26:10 +00:00
|
|
|
|
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
@allure.step("Wait for node {node_name} is ready")
|
2022-10-09 20:01:59 +00:00
|
|
|
def wait_for_node_to_be_ready(hosting: Hosting, node_name: str) -> None:
|
2022-09-16 13:26:10 +00:00
|
|
|
timeout, attempts = 30, 6
|
|
|
|
for _ in range(attempts):
|
|
|
|
try:
|
2022-10-09 20:01:59 +00:00
|
|
|
health_check = node_healthcheck(hosting, node_name)
|
2022-09-23 11:09:41 +00:00
|
|
|
if health_check.health_status == "READY":
|
2022-09-16 13:26:10 +00:00
|
|
|
return
|
|
|
|
except Exception as err:
|
2022-09-23 11:09:41 +00:00
|
|
|
logger.warning(f"Node {node_name} is not ready:\n{err}")
|
2022-09-16 13:26:10 +00:00
|
|
|
sleep(timeout)
|
|
|
|
raise AssertionError(
|
2022-09-23 11:09:41 +00:00
|
|
|
f"Node {node_name} hasn't gone to the READY state after {timeout * attempts} seconds"
|
|
|
|
)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
@allure.step("Wait for {expected_copies} object copies in the wallet")
|
|
|
|
def wait_for_expected_object_copies(
|
2022-10-28 08:22:27 +00:00
|
|
|
shell: Shell, wallet: str, cid: str, oid: str, expected_copies: int = 2
|
2022-09-23 11:09:41 +00:00
|
|
|
) -> None:
|
2022-07-08 17:24:55 +00:00
|
|
|
for i in range(2):
|
|
|
|
copies = get_simple_object_copies(wallet, cid, oid)
|
|
|
|
if copies == expected_copies:
|
|
|
|
break
|
2022-10-28 08:22:27 +00:00
|
|
|
tick_epoch(shell=shell)
|
2022-09-23 11:09:41 +00:00
|
|
|
sleep(parse_time(NEOFS_CONTRACT_CACHE_TIMEOUT))
|
2022-07-08 17:24:55 +00:00
|
|
|
else:
|
2022-09-23 11:09:41 +00:00
|
|
|
raise AssertionError(f"There are no {expected_copies} copies during time")
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
@allure.step("Wait for object to be dropped")
|
2022-10-19 06:26:14 +00:00
|
|
|
def wait_for_obj_dropped(wallet: str, cid: str, oid: str, shell: Shell, checker) -> None:
|
2022-07-08 17:24:55 +00:00
|
|
|
for _ in range(3):
|
|
|
|
try:
|
2022-10-19 06:26:14 +00:00
|
|
|
checker(wallet, cid, oid, shell=shell)
|
2022-07-27 10:42:29 +00:00
|
|
|
wait_for_gc_pass_on_storage_nodes()
|
2022-07-08 17:24:55 +00:00
|
|
|
except Exception as err:
|
2022-08-12 16:44:10 +00:00
|
|
|
if error_matches_status(err, OBJECT_NOT_FOUND):
|
|
|
|
return
|
|
|
|
raise AssertionError(f'Expected "{OBJECT_NOT_FOUND}" error, got\n{err}')
|
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
raise AssertionError(f"Object {oid} was not dropped from node")
|