2023-07-26 10:14:16 +00:00
|
|
|
import logging
|
|
|
|
import random
|
|
|
|
from time import sleep
|
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2023-11-29 13:34:59 +00:00
|
|
|
from frostfs_testlib import reporter
|
2023-07-26 10:14:16 +00:00
|
|
|
from frostfs_testlib.shell import Shell
|
|
|
|
from frostfs_testlib.steps.cli.container import create_container, delete_container
|
|
|
|
from frostfs_testlib.steps.cli.object import delete_object, head_object, put_object
|
|
|
|
from frostfs_testlib.storage.cluster import Cluster
|
2023-07-31 09:27:12 +00:00
|
|
|
from frostfs_testlib.storage.controllers.cluster_state_controller import ClusterStateController
|
2023-08-02 11:54:03 +00:00
|
|
|
from frostfs_testlib.storage.dataclasses.object_size import ObjectSize
|
2023-07-26 10:14:16 +00:00
|
|
|
from frostfs_testlib.testing.cluster_test_base import ClusterTestBase
|
2023-10-19 07:38:42 +00:00
|
|
|
from frostfs_testlib.utils.failover_utils import wait_object_replication
|
2023-07-26 10:14:16 +00:00
|
|
|
from frostfs_testlib.utils.file_utils import generate_file
|
|
|
|
|
|
|
|
logger = logging.getLogger("NeoLogger")
|
|
|
|
|
|
|
|
OBJECT_ATTRIBUTES = {"common_key": "common_value"}
|
|
|
|
WAIT_FOR_REPLICATION = 60
|
|
|
|
|
2023-07-31 09:27:12 +00:00
|
|
|
# Adding failover mark because it may make cluster unhealthy
|
2023-10-31 14:51:09 +00:00
|
|
|
@pytest.mark.sanity
|
2023-07-31 09:27:12 +00:00
|
|
|
@pytest.mark.failover
|
2023-07-26 10:14:16 +00:00
|
|
|
@pytest.mark.replication
|
|
|
|
class TestReplication(ClusterTestBase):
|
2023-07-31 09:27:12 +00:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def start_stopped_nodes_after_test(self, cluster_state_controller: ClusterStateController):
|
|
|
|
yield
|
|
|
|
cluster_state_controller.start_stopped_hosts()
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Replication (obj_size={object_size})")
|
2023-07-26 10:14:16 +00:00
|
|
|
def test_replication(
|
|
|
|
self,
|
|
|
|
default_wallet: str,
|
|
|
|
client_shell: Shell,
|
|
|
|
cluster: Cluster,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_size: ObjectSize,
|
2023-07-31 09:27:12 +00:00
|
|
|
cluster_state_controller: ClusterStateController,
|
2023-07-26 10:14:16 +00:00
|
|
|
):
|
|
|
|
nodes_count = len(cluster.cluster_nodes)
|
|
|
|
node_for_rep = random.choice(cluster.cluster_nodes)
|
|
|
|
alive_nodes = [node for node in cluster.cluster_nodes if node != node_for_rep]
|
|
|
|
cid = create_container(
|
|
|
|
wallet=default_wallet,
|
|
|
|
shell=client_shell,
|
|
|
|
endpoint=cluster.default_rpc_endpoint,
|
|
|
|
rule=f"REP 1 IN SELF_PLACE REP {nodes_count - 1} IN OTHER_PLACE CBF 1 "
|
|
|
|
"SELECT 1 FROM SELF AS SELF_PLACE "
|
|
|
|
f"SELECT {nodes_count - 1} FROM OTHER AS OTHER_PLACE "
|
|
|
|
f"FILTER 'UN-LOCODE' EQ '{node_for_rep.storage_node.get_un_locode()}' AS SELF "
|
|
|
|
f"FILTER 'UN-LOCODE' NE '{node_for_rep.storage_node.get_un_locode()}' AS OTHER",
|
|
|
|
)
|
|
|
|
|
|
|
|
cluster_state_controller.stop_node_host(node_for_rep, mode="hard")
|
|
|
|
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path = generate_file(object_size.value)
|
2023-07-26 10:14:16 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put object"):
|
2023-07-26 10:14:16 +00:00
|
|
|
oid = put_object(
|
|
|
|
wallet=default_wallet,
|
|
|
|
path=file_path,
|
|
|
|
cid=cid,
|
|
|
|
shell=client_shell,
|
|
|
|
attributes=OBJECT_ATTRIBUTES,
|
|
|
|
copies_number=3,
|
|
|
|
endpoint=random.choice(alive_nodes).storage_node.get_rpc_endpoint(),
|
2023-10-19 07:38:42 +00:00
|
|
|
timeout="45s",
|
2023-07-26 10:14:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
cluster_state_controller.start_node_host(node_for_rep)
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step(f"Wait for replication."):
|
2023-10-19 07:38:42 +00:00
|
|
|
object_nodes = wait_object_replication(
|
|
|
|
cid=cid,
|
|
|
|
oid=oid,
|
|
|
|
expected_copies=len(self.cluster.cluster_nodes),
|
|
|
|
shell=client_shell,
|
|
|
|
nodes=self.cluster.storage_nodes,
|
|
|
|
)
|
2023-07-26 10:14:16 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Check attributes"):
|
2023-10-19 07:38:42 +00:00
|
|
|
for node in object_nodes:
|
2023-07-26 10:14:16 +00:00
|
|
|
header_info = head_object(
|
|
|
|
wallet=default_wallet,
|
|
|
|
oid=oid,
|
|
|
|
cid=cid,
|
|
|
|
shell=self.shell,
|
2023-10-19 07:38:42 +00:00
|
|
|
endpoint=node.get_rpc_endpoint(),
|
2023-07-26 10:14:16 +00:00
|
|
|
is_direct=True,
|
|
|
|
)["header"]
|
|
|
|
attributes = header_info["attributes"]
|
|
|
|
for attribute_key, attribute_value in OBJECT_ATTRIBUTES.items():
|
2023-10-19 07:38:42 +00:00
|
|
|
assert attribute_key in attributes, f"{attribute_key} not found in {header_info}"
|
2023-07-26 10:14:16 +00:00
|
|
|
assert header_info["attributes"].get(attribute_key) == str(attribute_value), (
|
|
|
|
f"{attribute_key} value not equal: "
|
|
|
|
f"got attribute value: {attributes.get(attribute_key)}"
|
|
|
|
f"expected attribute value: {attribute_value}"
|
|
|
|
)
|
2023-10-19 07:38:42 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Cleanup"):
|
2023-07-26 10:14:16 +00:00
|
|
|
delete_object(
|
2023-07-31 09:27:12 +00:00
|
|
|
wallet=default_wallet,
|
2023-07-26 10:14:16 +00:00
|
|
|
cid=cid,
|
|
|
|
oid=oid,
|
|
|
|
shell=client_shell,
|
|
|
|
endpoint=cluster.default_rpc_endpoint,
|
|
|
|
)
|
|
|
|
|
|
|
|
delete_container(
|
2023-07-31 09:27:12 +00:00
|
|
|
wallet=default_wallet,
|
2023-07-26 10:14:16 +00:00
|
|
|
cid=cid,
|
|
|
|
shell=client_shell,
|
|
|
|
endpoint=cluster.default_rpc_endpoint,
|
|
|
|
)
|