Add policy REP 1 IN SPB REP 1 IN MSK REP 3

This commit is contained in:
Ekaterina Chernitsyna 2023-10-18 13:54:58 +03:00
parent 5eae65b471
commit 6b8800760d

View file

@ -1387,11 +1387,58 @@ class TestPolicy(ClusterTestBase):
with allure.step(f"Delete the container"): with allure.step(f"Delete the container"):
delete_container(wallet=default_wallet, cid=cid, shell=self.shell, endpoint=endpoint) delete_container(wallet=default_wallet, cid=cid, shell=self.shell, endpoint=endpoint)
@pytest.mark.policy
@allure.title("Policy: REP 1 IN SPB REP 1 IN MSK REP 3")
def test_policy_rep_1_in_spb_rep_1_in_msk_rep_3(
self,
default_wallet,
simple_object_size: ObjectSize,
):
"""
This test checks object's copies based on container's placement policy: REP 1 IN SPB REP 1 IN MSK REP 3.
"""
placement_rule = "REP 1 IN SPB REP 1 IN MSK REP 3 CBF 1 SELECT 2 FROM LED AS SPB SELECT 2 FROM MOW AS MSK FILTER Location EQ 'Saint Petersburg (ex Leningrad)' AS LED FILTER Location EQ Moskva AS MOW"
file_path = generate_file(simple_object_size.value)
expected_copies = 3
endpoint = self.cluster.default_rpc_endpoint
with allure.step(f"Create container with policy {placement_rule}"):
cid = create_container(
wallet=default_wallet, rule=placement_rule, basic_acl=PUBLIC_ACL, shell=self.shell, endpoint=endpoint
)
with allure.step(f"Check container policy"):
self.validate_object_policy(default_wallet, placement_rule, cid, endpoint)
with allure.step(f"Put object in container"):
oid = put_object_to_random_node(default_wallet, file_path, cid, shell=self.shell, cluster=self.cluster)
with allure.step(f"Check object expected copies"):
resulting_copies = get_nodes_with_object(cid, oid, shell=self.shell, nodes=self.cluster.storage_nodes)
assert len(resulting_copies) >= expected_copies and len(resulting_copies) <= len(
self.cluster.storage_nodes
), f"Expected {expected_copies} or {expected_copies + 1} copies, got {len(resulting_copies)}"
with allure.step(f"Check the object appearance"):
nodes_without_object = get_nodes_without_object(
wallet=default_wallet, cid=cid, oid=oid, shell=self.shell, nodes=self.cluster.storage_nodes
)
assert set(resulting_copies) | set(nodes_without_object) == set(
self.cluster.storage_nodes
), f"nodes filling error: nodes with object = {resulting_copies}, nodes witout object = {nodes_without_object}"
self.check_for_the_uniqueness_of_the_nodes(resulting_copies)
with allure.step(f"Delete the object from the container"):
delete_object(wallet=default_wallet, cid=cid, oid=oid, shell=self.shell, endpoint=endpoint)
with allure.step(f"Delete the container"):
delete_container(wallet=default_wallet, cid=cid, shell=self.shell, endpoint=endpoint)
def validate_object_policy(self, wallet: str, placement_rule: str, cid: str, endpoint: str): def validate_object_policy(self, wallet: str, placement_rule: str, cid: str, endpoint: str):
got_policy = placement_policy_from_container( got_policy = placement_policy_from_container(
get_container(wallet, cid, json_mode=False, shell=self.shell, endpoint=endpoint) get_container(wallet, cid, json_mode=False, shell=self.shell, endpoint=endpoint)
) )
assert got_policy == placement_rule.replace( assert got_policy.replace("'", "") == placement_rule.replace(
"'", "" "'", ""
), f"Expected \n{placement_rule} and got policy \n{got_policy} are the same" ), f"Expected \n{placement_rule} and got policy \n{got_policy} are the same"