Update check filters results with one node the object appearance

This commit is contained in:
Ekaterina Chernitsyna 2023-10-23 16:13:10 +03:00
parent cbbbc686f4
commit af50be78e6

View file

@ -28,7 +28,7 @@ class TestPolicy(ClusterTestBase):
@pytest.mark.policy
def test_placement_policy_negative(self, default_wallet):
"""
Negative test for placement policy.
Negative test for placement policy: Can't parse placement policy.
"""
placement_rule = "REP 1 IN SPB REP 1 in MSK CBF 1 SELECT 1 FROM SPBRU AS SPB SELECT 1 FROM MSKRU AS MSK FILTER SubDivCode EQ SPE AS SPBRU FILTER NOT (Country EQ Sweden OR CountryCode EQ FI) AND Location EQ Moskva AS MSKRU"
endpoint = self.cluster.default_rpc_endpoint
@ -186,6 +186,7 @@ class TestPolicy(ClusterTestBase):
file_path = generate_file(simple_object_size.value)
expected_copies = 1
endpoint = self.cluster.default_rpc_endpoint
expected_params = {"country": "Russia"}
with allure.step(f"Create container with policy {placement_rule}"):
cid = create_container(
@ -204,6 +205,14 @@ class TestPolicy(ClusterTestBase):
len(resulting_copies) == expected_copies
), f"Expected {expected_copies} copies, got {len(resulting_copies)}"
with allure.step(f"Check the object appearance"):
netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell))
netmap = self.get_netmap_param(netmap)
node_address = resulting_copies[0].get_rpc_endpoint().split(":")[0]
assert (
expected_params["country"] == netmap[node_address]["country"]
), f"The node is selected from the wrong country. Expected {expected_params['country']} and got {netmap[node_address]['country']}"
with allure.step(f"Delete the object from the container"):
delete_object(wallet=default_wallet, cid=cid, oid=oid, shell=self.shell, endpoint=endpoint)
@ -221,6 +230,8 @@ class TestPolicy(ClusterTestBase):
This test checks object's copies based on container's placement policy with SELECT and Complex FILTER results with one node.
"""
placement_rule = "REP 1 IN RUS REP 1 IN RUS CBF 1 SELECT 1 FROM RU AS RUS FILTER Country NE Sweden AS NotSE FILTER @NotSE AND NOT (CountryCode EQ FI) AND Country EQ 'Russia' AS RU"
expected_params = {"country": ["Russia", "Sweden"]}
unexpected_params = {"country": "Sweden", "country_code": "FI"}
file_path = generate_file(simple_object_size.value)
expected_copies = 1
endpoint = self.cluster.default_rpc_endpoint
@ -243,9 +254,15 @@ class TestPolicy(ClusterTestBase):
), f"Expected {expected_copies} 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
)
netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell))
netmap = self.get_netmap_param(netmap)
node_address = resulting_copies[0].get_rpc_endpoint().split(":")[0]
assert (
(expected_params["country"][1] == netmap[node_address]["country"])
or not (unexpected_params["country"] == netmap[node_address]["country"])
and not (unexpected_params["country_code"] == netmap[node_address]["country_code"])
and (expected_params["country"][0] == netmap[node_address]["country"])
), f"The node is selected from the wrong country or country code. Expected {expected_params} and got {netmap[node_address]}"
with allure.step(f"Delete the object from the container"):
delete_object(wallet=default_wallet, cid=cid, oid=oid, shell=self.shell, endpoint=endpoint)
@ -264,6 +281,8 @@ class TestPolicy(ClusterTestBase):
This test checks object's copies based on container's placement policy with Multi SELECTs and FILTERs results with one nodes.
"""
placement_rule = "REP 1 IN RU REP 1 IN EU REP 1 IN RU CBF 1 SELECT 1 FROM RUS AS RU SELECT 1 FROM EUR AS EU FILTER Country EQ Russia AS RUS FILTER NOT (@RUS) AND Country EQ Sweden OR CountryCode EQ FI AS EUR"
expected_params = {"country": ["Sweden", "Russia"], "country_code": "FI"}
unexpected_params = {"country": "Russia"}
file_path = generate_file(simple_object_size.value)
expected_copies = 2
endpoint = self.cluster.default_rpc_endpoint
@ -286,9 +305,15 @@ class TestPolicy(ClusterTestBase):
), f"Expected {expected_copies} 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
)
netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell))
netmap = self.get_netmap_param(netmap)
for node in resulting_copies:
node_address = resulting_copies[0].get_rpc_endpoint().split(":")[0]
assert (expected_params["country"][1] == netmap[node_address]["country"]) or (
not (unexpected_params["country"][1] == netmap[node_address]["country"])
and (expected_params["country"][0] == netmap[node_address]["country"])
or (expected_params["country_code"] == netmap[node_address]["country_code"])
), f"The node is selected from the wrong country or country code. Expected {expected_params} and got {netmap[node_address]}"
with allure.step(f"Delete the object from the container"):
delete_object(wallet=default_wallet, cid=cid, oid=oid, shell=self.shell, endpoint=endpoint)
@ -464,7 +489,7 @@ class TestPolicy(ClusterTestBase):
simple_object_size: ObjectSize,
):
"""
110596 This test checks object's copies based on container's placement policy with SELECT and Complex FILTER results with 25% of available nodes.
This test checks object's copies based on container's placement policy with SELECT and Complex FILTER results with 25% of available nodes.
"""
placement_rule = "REP 1 IN Nodes25 SELECT 1 FROM BET0AND10 AS Nodes25 FILTER Price LE 10 AS LE10 FILTER Price GT 0 AS GT0 FILTER @LE10 AND @GT0 AS BET0AND10"
file_path = generate_file(simple_object_size.value)
@ -869,13 +894,13 @@ class TestPolicy(ClusterTestBase):
@pytest.mark.policy
@allure.title("Policy with SELECT and Complex FILTER results with 75% of available nodes")
def tets_policy_with_select_and_complex_filter_results_with_75_of_available_nodes(
def test_policy_with_select_and_complex_filter_results_with_75_of_available_nodes(
self,
default_wallet,
simple_object_size: ObjectSize,
):
"""
110608 This test checks object's copies based on container's placement policy with SELECT and Complex FILTER results with 75% of available nodes.
This test checks object's copies based on container's placement policy with SELECT and Complex FILTER results with 75% of available nodes.
"""
placement_rule = "REP 2 IN NODES75 SELECT 2 FROM LT65 AS NODES75 FILTER Price LT 65 AS LT65"
file_path = generate_file(simple_object_size.value)
@ -912,13 +937,13 @@ class TestPolicy(ClusterTestBase):
@pytest.mark.policy
@allure.title("Policy with Multi SELECTs and FILTERs results with 75% of available nodes")
def tets_policy_with_multi_selects_and_filters_results_with_75_of_available_nodes(
def test_policy_with_multi_selects_and_filters_results_with_75_of_available_nodes(
self,
default_wallet,
simple_object_size: ObjectSize,
):
"""
110608 This test checks object's copies based on container's placement policy with Multi SELECTs and FILTERs results with 75% of available nodes.
This test checks object's copies based on container's placement policy with Multi SELECTs and FILTERs results with 75% of available nodes.
"""
placement_rule = "REP 2 IN EXPNSV REP 2 IN CHEAP SELECT 3 FROM GT10 AS EXPNSV SELECT 3 FROM LT65 AS CHEAP FILTER NOT(Continent EQ America) AS NOAM FILTER @NOAM AND Price LT 65 AS LT65 FILTER @NOAM AND Price GT 10 AS GT10"
file_path = generate_file(simple_object_size.value)
@ -1160,7 +1185,7 @@ class TestPolicy(ClusterTestBase):
@pytest.mark.policy
@allure.title("Simple policy results with UNIQUE nodes")
def simple_policy_results_with_unique_nodes(
def test_simple_policy_results_with_unique_nodes(
self,
default_wallet,
simple_object_size: ObjectSize,
@ -1380,3 +1405,14 @@ class TestPolicy(ClusterTestBase):
def check_for_the_uniqueness_of_the_nodes(self, nodes: list):
assert len(set(nodes)) == len(nodes), f"The nodes found must be unique, but {nodes}"
def get_netmap_param(self, netmap_info: list[NodeNetmapInfo]) -> dict:
dict_external = dict()
for node in netmap_info:
external_adress = node.external_address[0].split("/")[2]
dict_external[external_adress] = {
"country": node.country,
"country_code": node.country_code,
"price": node.price,
}
return dict_external