update policy with field price

This commit is contained in:
Ekaterina Chernitsyna 2024-01-12 12:43:28 +03:00 committed by Andrey Berezin
parent 522b8e576d
commit 5bc170e6f9

View file

@ -1,15 +1,18 @@
import pytest
import allure import allure
import pytest
from frostfs_testlib import reporter from frostfs_testlib import reporter
from frostfs_testlib.resources.wellknown_acl import PUBLIC_ACL from frostfs_testlib.resources.wellknown_acl import PUBLIC_ACL
from frostfs_testlib.steps.cli.container import create_container, delete_container, get_container from frostfs_testlib.steps.cli.container import create_container, delete_container, get_container
from frostfs_testlib.steps.cli.object import delete_object, put_object_to_random_node from frostfs_testlib.steps.cli.object import delete_object, put_object_to_random_node
from frostfs_testlib.steps.node_management import get_netmap_snapshot from frostfs_testlib.steps.node_management import get_netmap_snapshot
from frostfs_testlib.steps.storage_policy import get_nodes_with_object, get_nodes_without_object from frostfs_testlib.steps.storage_policy import get_nodes_with_object
from frostfs_testlib.storage.controllers.cluster_state_controller import ClusterStateController
from frostfs_testlib.storage.controllers.state_managers.config_state_manager import ConfigStateManager
from frostfs_testlib.storage.dataclasses.frostfs_services import StorageNode from frostfs_testlib.storage.dataclasses.frostfs_services import StorageNode
from frostfs_testlib.storage.dataclasses.object_size import ObjectSize from frostfs_testlib.storage.dataclasses.object_size import ObjectSize
from frostfs_testlib.storage.dataclasses.storage_object_info import NodeNetmapInfo from frostfs_testlib.storage.dataclasses.storage_object_info import NodeNetmapInfo
from frostfs_testlib.testing.cluster_test_base import ClusterTestBase from frostfs_testlib.testing.cluster_test_base import ClusterTestBase
from frostfs_testlib.testing.test_control import wait_for_success
from frostfs_testlib.utils.cli_utils import parse_netmap_output from frostfs_testlib.utils.cli_utils import parse_netmap_output
from frostfs_testlib.utils.file_utils import generate_file from frostfs_testlib.utils.file_utils import generate_file
@ -25,6 +28,31 @@ from pytest_tests.resources.policy_error_patterns import (
@pytest.mark.container @pytest.mark.container
@pytest.mark.policy @pytest.mark.policy
class TestPolicy(ClusterTestBase): class TestPolicy(ClusterTestBase):
@wait_for_success(1200, 60, title="Wait for full field price on node", expected_result=True)
def await_for_price_attribute_on_nodes(self):
netmap = parse_netmap_output(get_netmap_snapshot(node=self.cluster.storage_nodes[0], shell=self.shell))
netmap = self.get_netmap_param(netmap)
for node in self.cluster.storage_nodes:
node_address = node.get_rpc_endpoint().split(":")[0]
if netmap[node_address]["Price"] is None:
return False
return True
@pytest.fixture(scope="module")
def fill_field_price(self, cluster_state_controller: ClusterStateController):
prices = ["15", "10", "65", "55"]
config_manager = cluster_state_controller.manager(ConfigStateManager)
for i in zip(self.cluster.cluster_nodes, prices):
config_manager.set_on_node(i[0], StorageNode, {"node:attribute_5": f"Price:{i[1]}"})
self.tick_epoch()
self.await_for_price_attribute_on_nodes()
yield
cluster_state_controller.manager(ConfigStateManager).revert_all()
@allure.title("[NEGATIVE] Placement policy: Can't parse placement policy") @allure.title("[NEGATIVE] Placement policy: Can't parse placement policy")
def test_placement_policy_negative(self, default_wallet): def test_placement_policy_negative(self, default_wallet):
""" """
@ -32,6 +60,7 @@ class TestPolicy(ClusterTestBase):
""" """
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" 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 endpoint = self.cluster.default_rpc_endpoint
with reporter.step(f"Create container with policy {placement_rule}"): with reporter.step(f"Create container with policy {placement_rule}"):
with pytest.raises(Exception, match=NOT_PARSE_POLICY): with pytest.raises(Exception, match=NOT_PARSE_POLICY):
cid = create_container( cid = create_container(
@ -93,7 +122,6 @@ class TestPolicy(ClusterTestBase):
endpoint=endpoint, endpoint=endpoint,
) )
@pytest.mark.sanity
@allure.title("Simple policy results with one node") @allure.title("Simple policy results with one node")
def test_simple_policy_results_with_one_node( def test_simple_policy_results_with_one_node(
self, self,
@ -168,7 +196,6 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.sanity
@allure.title("Policy with SELECT and FILTER results with one node") @allure.title("Policy with SELECT and FILTER results with one node")
def test_policy_with_select_and_filter_results_with_one_node( def test_policy_with_select_and_filter_results_with_one_node(
self, self,
@ -252,9 +279,7 @@ class TestPolicy(ClusterTestBase):
netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell)) netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell))
netmap = self.get_netmap_param(netmap) netmap = self.get_netmap_param(netmap)
node_address = resulting_copies[0].get_rpc_endpoint().split(":")[0] node_address = resulting_copies[0].get_rpc_endpoint().split(":")[0]
with reporter.step( with reporter.step(f"Check the node is selected from {placement_params['country'][0]}"):
f"Check the node is selected from {placement_params['country'][0]}"
):
assert ( assert (
not (placement_params["country"][1] == netmap[node_address]["country"]) not (placement_params["country"][1] == netmap[node_address]["country"])
or not (placement_params["country"][1] == netmap[node_address]["country"]) or not (placement_params["country"][1] == netmap[node_address]["country"])
@ -268,7 +293,6 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.sanity
@allure.title("Policy with Multi SELECTs and FILTERs results with one node") @allure.title("Policy with Multi SELECTs and FILTERs results with one node")
def test_policy_with_multi_selects_and_filters_results_with_one_node( def test_policy_with_multi_selects_and_filters_results_with_one_node(
self, self,
@ -319,7 +343,6 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.sanity
@allure.title("Policy with SELECT and FILTER results with UNIQUE nodes") @allure.title("Policy with SELECT and FILTER results with UNIQUE nodes")
def test_policy_with_select_and_filter_results_with_unique_nodes( def test_policy_with_select_and_filter_results_with_unique_nodes(
self, self,
@ -442,18 +465,18 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.skip(reason="price")
@allure.title("Policy with SELECT and FILTER results with 25% of available nodes") @allure.title("Policy with SELECT and FILTER results with 25% of available nodes")
def test_policy_with_select_and_filter_results_with_25_of_available_nodes( def test_policy_with_select_and_filter_results_with_25_of_available_nodes(
self, self,
default_wallet, default_wallet,
simple_object_size: ObjectSize, simple_object_size: ObjectSize,
fill_field_price,
): ):
""" """
This test checks object's copies based on container's placement policy with SELECT and FILTER results with 25% of available nodes. This test checks object's copies based on container's placement policy with SELECT and FILTER results with 25% of available nodes.
""" """
placement_rule = "REP 1 IN Nodes25 SELECT 1 FROM LE10 AS Nodes25 FILTER Price LE 10 AS LE10" placement_rule = "REP 1 IN Nodes25 SELECT 1 FROM LE10 AS Nodes25 FILTER Price LE 10 AS LE10"
placement_params = {"price": 10} placement_params = {"Price": 10}
file_path = generate_file(simple_object_size.value) file_path = generate_file(simple_object_size.value)
expected_copies = 1 expected_copies = 1
endpoint = self.cluster.default_rpc_endpoint endpoint = self.cluster.default_rpc_endpoint
@ -479,9 +502,9 @@ class TestPolicy(ClusterTestBase):
netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell)) netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell))
netmap = self.get_netmap_param(netmap) netmap = self.get_netmap_param(netmap)
node_address = resulting_copies[0].get_rpc_endpoint().split(":")[0] node_address = resulting_copies[0].get_rpc_endpoint().split(":")[0]
with reporter.step(f"Check the node is selected with price <= {placement_params['price']}"): with reporter.step(f"Check the node is selected with price <= {placement_params['Price']}"):
assert ( assert (
int(netmap[node_address]["price"]) <= placement_params["price"] int(netmap[node_address]["Price"]) <= placement_params["Price"]
), f"The node is selected with the wrong price. Got {netmap[node_address]}" ), f"The node is selected with the wrong price. Got {netmap[node_address]}"
with reporter.step(f"Delete the object from the container"): with reporter.step(f"Delete the object from the container"):
@ -490,18 +513,18 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.skip(reason="price")
@allure.title("Policy with select and complex filter results with 25% of available nodes") @allure.title("Policy with select and complex filter results with 25% of available nodes")
def test_policy_with_select_and_complex_filter_results_with_25_of_available_nodes( def test_policy_with_select_and_complex_filter_results_with_25_of_available_nodes(
self, self,
default_wallet, default_wallet,
simple_object_size: ObjectSize, simple_object_size: ObjectSize,
fill_field_price,
): ):
""" """
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" 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"
placement_params = {"price": [10, 0]} placement_params = {"Price": [10, 0]}
file_path = generate_file(simple_object_size.value) file_path = generate_file(simple_object_size.value)
expected_copies = 1 expected_copies = 1
endpoint = self.cluster.default_rpc_endpoint endpoint = self.cluster.default_rpc_endpoint
@ -530,8 +553,8 @@ class TestPolicy(ClusterTestBase):
for node in resulting_copies: for node in resulting_copies:
node_address = node.get_rpc_endpoint().split(":")[0] node_address = node.get_rpc_endpoint().split(":")[0]
assert ( assert (
int(netmap[node_address]["price"]) > placement_params["price"][1] int(netmap[node_address]["Price"]) > placement_params["Price"][1]
and int(netmap[node_address]["price"]) <= placement_params["price"][0] and int(netmap[node_address]["Price"]) <= placement_params["Price"][0]
), f"The node is selected with the wrong price. Got {netmap[node_address]}" ), f"The node is selected with the wrong price. Got {netmap[node_address]}"
with reporter.step(f"Delete the object from the container"): with reporter.step(f"Delete the object from the container"):
@ -540,18 +563,18 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.skip(reason="price")
@allure.title("Policy with Multi SELECTs and FILTERs results with 25% of available nodes") @allure.title("Policy with Multi SELECTs and FILTERs results with 25% of available nodes")
def test_policy_with_multi_selects_and_filters_results_with_25_of_available_nodes( def test_policy_with_multi_selects_and_filters_results_with_25_of_available_nodes(
self, self,
default_wallet, default_wallet,
simple_object_size: ObjectSize, simple_object_size: ObjectSize,
fill_field_price,
): ):
""" """
This test checks object's copies based on container's placement policy with Multi SELECTs and FILTERs results with 25% of available nodes. This test checks object's copies based on container's placement policy with Multi SELECTs and FILTERs results with 25% of available nodes.
""" """
placement_rule = "UNIQUE REP 1 IN One REP 1 IN One CBF 1 SELECT 1 FROM MINMAX AS One FILTER Price LT 15 AS LT15 FILTER Price GT 55 AS GT55 FILTER @LT15 OR @GT55 AS MINMAX" placement_rule = "UNIQUE REP 1 IN One REP 1 IN One CBF 1 SELECT 1 FROM MINMAX AS One FILTER Price LT 15 AS LT15 FILTER Price GT 55 AS GT55 FILTER @LT15 OR @GT55 AS MINMAX"
placement_params = {"price": [15, 55]} placement_params = {"Price": [15, 55]}
file_path = generate_file(simple_object_size.value) file_path = generate_file(simple_object_size.value)
expected_copies = 2 expected_copies = 2
endpoint = self.cluster.default_rpc_endpoint endpoint = self.cluster.default_rpc_endpoint
@ -580,8 +603,8 @@ class TestPolicy(ClusterTestBase):
for node in resulting_copies: for node in resulting_copies:
node_address = node.get_rpc_endpoint().split(":")[0] node_address = node.get_rpc_endpoint().split(":")[0]
assert ( assert (
int(netmap[node_address]["price"]) > placement_params["price"][1] int(netmap[node_address]["Price"]) > placement_params["Price"][1]
or int(netmap[node_address]["price"]) < placement_params["price"][0] or int(netmap[node_address]["Price"]) < placement_params["Price"][0]
), f"The node is selected with the wrong price. Got {netmap[node_address]}" ), f"The node is selected with the wrong price. Got {netmap[node_address]}"
with reporter.step(f"Delete the object from the container"): with reporter.step(f"Delete the object from the container"):
@ -664,18 +687,18 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.skip(reason="price")
@allure.title("Policy with SELECT and FILTER results with 50% of available nodes") @allure.title("Policy with SELECT and FILTER results with 50% of available nodes")
def test_policy_with_select_and_filter_results_with_50_of_available_nodes( def test_policy_with_select_and_filter_results_with_50_of_available_nodes(
self, self,
default_wallet, default_wallet,
simple_object_size: ObjectSize, simple_object_size: ObjectSize,
fill_field_price,
): ):
""" """
This test checks object's copies based on container's placement policy with SELECT and FILTER results with 50% of available nodes. This test checks object's copies based on container's placement policy with SELECT and FILTER results with 50% of available nodes.
""" """
placement_rule = "REP 2 IN HALF CBF 1 SELECT 2 FROM GT15 AS HALF FILTER Price GT 15 AS GT15" placement_rule = "REP 2 IN HALF CBF 1 SELECT 2 FROM GT15 AS HALF FILTER Price GT 15 AS GT15"
placement_params = {"price": 15} placement_params = {"Price": 15}
file_path = generate_file(simple_object_size.value) file_path = generate_file(simple_object_size.value)
expected_copies = 2 expected_copies = 2
endpoint = self.cluster.default_rpc_endpoint endpoint = self.cluster.default_rpc_endpoint
@ -700,11 +723,11 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Check the object appearance"): with reporter.step(f"Check the object appearance"):
netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell)) netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell))
netmap = self.get_netmap_param(netmap) netmap = self.get_netmap_param(netmap)
with reporter.step(f"Check two nodes are selected with price > {placement_params['price']}"): with reporter.step(f"Check two nodes are selected with price > {placement_params['Price']}"):
for node in resulting_copies: for node in resulting_copies:
node_address = node.get_rpc_endpoint().split(":")[0] node_address = node.get_rpc_endpoint().split(":")[0]
assert ( assert (
int(netmap[node_address]["price"]) > placement_params["price"] int(netmap[node_address]["Price"]) > placement_params["Price"]
), f"The node is selected with the wrong price. Got {netmap[node_address]}" ), f"The node is selected with the wrong price. Got {netmap[node_address]}"
with reporter.step(f"Delete the object from the container"): with reporter.step(f"Delete the object from the container"):
@ -713,18 +736,18 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.skip(reason="price")
@allure.title("Policy with SELECT and Complex FILTER results with 50% of available nodes") @allure.title("Policy with SELECT and Complex FILTER results with 50% of available nodes")
def test_policy_with_select_and_complex_filter_results_with_50_of_available_nodes( def test_policy_with_select_and_complex_filter_results_with_50_of_available_nodes(
self, self,
default_wallet, default_wallet,
simple_object_size: ObjectSize, simple_object_size: ObjectSize,
fill_field_price,
): ):
""" """
This test checks object's copies based on container's placement policy with SELECT and Complex FILTER results with 50% of available nodes. This test checks object's copies based on container's placement policy with SELECT and Complex FILTER results with 50% of available nodes.
""" """
placement_rule = "REP 2 IN HALF CBF 2 SELECT 2 FROM GE15 AS HALF FILTER CountryCode NE RU AS NOTRU FILTER @NOTRU AND Price GE 15 AS GE15" placement_rule = "REP 2 IN HALF CBF 2 SELECT 2 FROM GE15 AS HALF FILTER CountryCode NE RU AS NOTRU FILTER @NOTRU AND Price GE 15 AS GE15"
placement_params = {"price": 15, "country_code": "RU"} placement_params = {"Price": 15, "country_code": "RU"}
file_path = generate_file(simple_object_size.value) file_path = generate_file(simple_object_size.value)
expected_copies = 2 expected_copies = 2
endpoint = self.cluster.default_rpc_endpoint endpoint = self.cluster.default_rpc_endpoint
@ -749,12 +772,15 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Check the object appearance"): with reporter.step(f"Check the object appearance"):
netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell)) netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell))
netmap = self.get_netmap_param(netmap) netmap = self.get_netmap_param(netmap)
with reporter.step(f"Check two nodes are selected not with country code '{placement_params['country_code']}'"): with reporter.step(
f"Check two nodes are selected not with country code '{placement_params['country_code']}'"
):
for node in resulting_copies: for node in resulting_copies:
node_address = node.get_rpc_endpoint().split(":")[0] node_address = node.get_rpc_endpoint().split(":")[0]
assert (not netmap[node_address]["country_code"] == placement_params["country_code"] assert (
not netmap[node_address]["country_code"] == placement_params["country_code"]
or not netmap[node_address]["country_code"] == placement_params["country_code"] or not netmap[node_address]["country_code"] == placement_params["country_code"]
and int(netmap[node_address]["price"]) >= placement_params["price"] and int(netmap[node_address]["Price"]) >= placement_params["Price"]
), f"The node is selected with the wrong price or country code. Got {netmap[node_address]}" ), f"The node is selected with the wrong price or country code. Got {netmap[node_address]}"
with reporter.step(f"Delete the object from the container"): with reporter.step(f"Delete the object from the container"):
@ -763,20 +789,20 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.skip(reason="price")
@allure.title("Policy with Multi SELECTs and FILTERs results with 50% of available nodes") @allure.title("Policy with Multi SELECTs and FILTERs results with 50% of available nodes")
def test_policy_with_multi_selects_and_filters_results_with_50_of_available_nodes( def test_policy_with_multi_selects_and_filters_results_with_50_of_available_nodes(
self, self,
default_wallet, default_wallet,
simple_object_size: ObjectSize, simple_object_size: ObjectSize,
fill_field_price,
): ):
""" """
This test checks object's copies based on container's placement policy with Multi SELECTs and FILTERs results with 50% of available nodes. This test checks object's copies based on container's placement policy with Multi SELECTs and FILTERs results with 50% of available nodes.
""" """
placement_rule = "REP 2 IN FH REP 1 IN SH CBF 2 SELECT 2 FROM LE55 AS FH SELECT 2 FROM GE15 AS SH FILTER 'UN-LOCODE' EQ RU_LED OR 'UN-LOCODE' EQ RU_MOW AS RU FILTER NOT(@RU) AS NOTRU FILTER @NOTRU AND Price GE 15 AS GE15 FILTER @RU AND Price LE 55 AS LE55" placement_rule = "REP 2 IN FH REP 1 IN SH CBF 2 SELECT 2 FROM LE55 AS FH SELECT 2 FROM GE15 AS SH FILTER 'UN-LOCODE' EQ 'RU LED' OR 'UN-LOCODE' EQ 'RU MOW' AS RU FILTER NOT (@RU) AS NOTRU FILTER @NOTRU AND Price GE 15 AS GE15 FILTER @RU AND Price LE 55 AS LE55"
placement_params = {"un_locode": ["RU_LED", "RU_MOW"], "price": [15, 55]} placement_params = {"un_locode": ["RU LED", "RU MOW"], "Price": [15, 55]}
file_path = generate_file(simple_object_size.value) file_path = generate_file(simple_object_size.value)
expected_copies = 4 expected_copies = 3
endpoint = self.cluster.default_rpc_endpoint endpoint = self.cluster.default_rpc_endpoint
with reporter.step(f"Create container with policy {placement_rule}"): with reporter.step(f"Create container with policy {placement_rule}"):
@ -807,11 +833,11 @@ class TestPolicy(ClusterTestBase):
or not netmap[node_address]["un_locode"] == placement_params["un_locode"][1] or not netmap[node_address]["un_locode"] == placement_params["un_locode"][1]
or ( or (
not netmap[node_address]["un_locode"] == placement_params["un_locode"][1] not netmap[node_address]["un_locode"] == placement_params["un_locode"][1]
and int(netmap[node_address]["price"]) >= placement_params["price"][0] and int(netmap[node_address]["Price"]) >= placement_params["Price"][0]
) )
or ( or (
netmap[node_address]["un_locode"] == placement_params["un_locode"][1] netmap[node_address]["un_locode"] == placement_params["un_locode"][1]
and int(netmap[node_address]["price"]) <= placement_params["price"][1] and int(netmap[node_address]["Price"]) <= placement_params["Price"][1]
) )
), f"The node is selected with the wrong price or un_locode. Expected {placement_params} and got {netmap[node_address]}" ), f"The node is selected with the wrong price or un_locode. Expected {placement_params} and got {netmap[node_address]}"
@ -821,7 +847,6 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.sanity
@allure.title("Simple policy results with 75% of available nodes") @allure.title("Simple policy results with 75% of available nodes")
def test_simple_policy_results_with_75_of_available_nodes( def test_simple_policy_results_with_75_of_available_nodes(
self, self,
@ -896,18 +921,18 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.skip(reason="price")
@allure.title("Policy with SELECT and FILTER results with 75% of available nodes") @allure.title("Policy with SELECT and FILTER results with 75% of available nodes")
def test_policy_with_select_and_filter_results_with_75_of_available_nodes( def test_policy_with_select_and_filter_results_with_75_of_available_nodes(
self, self,
default_wallet, default_wallet,
simple_object_size: ObjectSize, simple_object_size: ObjectSize,
fill_field_price,
): ):
""" """
This test checks object's copies based on container's placement policy with SELECT and FILTER results with 75% of available nodes. This test checks object's copies based on container's placement policy with SELECT and 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" placement_rule = "REP 2 IN NODES75 SELECT 2 FROM LT65 AS NODES75 FILTER Price LT 65 AS LT65"
placement_params = {"price": 65} placement_params = {"Price": 65}
file_path = generate_file(simple_object_size.value) file_path = generate_file(simple_object_size.value)
expected_copies = 2 expected_copies = 2
endpoint = self.cluster.default_rpc_endpoint endpoint = self.cluster.default_rpc_endpoint
@ -932,11 +957,11 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Check the object appearance"): with reporter.step(f"Check the object appearance"):
netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell)) netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell))
netmap = self.get_netmap_param(netmap) netmap = self.get_netmap_param(netmap)
with reporter.step(f"Check two nodes are selected with price < {placement_params['price']}"): with reporter.step(f"Check two nodes are selected with price < {placement_params['Price']}"):
for node in resulting_copies: for node in resulting_copies:
node_address = node.get_rpc_endpoint().split(":")[0] node_address = node.get_rpc_endpoint().split(":")[0]
assert ( assert (
int(netmap[node_address]["price"]) < placement_params["price"] int(netmap[node_address]["Price"]) < placement_params["Price"]
), f"The node is selected with the wrong price. Got {netmap[node_address]}" ), f"The node is selected with the wrong price. Got {netmap[node_address]}"
with reporter.step(f"Delete the object from the container"): with reporter.step(f"Delete the object from the container"):
@ -945,20 +970,20 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.skip(reason="price")
@allure.title("Policy with SELECT and Complex FILTER results with 75% of available nodes") @allure.title("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( def test_policy_with_select_and_complex_filter_results_with_75_of_available_nodes(
self, self,
default_wallet, default_wallet,
simple_object_size: ObjectSize, simple_object_size: ObjectSize,
fill_field_price: None,
): ):
""" """
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 Continent NE America AS NOAM FILTER @NOAM AND Price LT 65 AS LT65" placement_rule = "REP 2 IN NODES75 SELECT 2 FROM LT65 AS NODES75 FILTER Continent NE America AS NOAM FILTER @NOAM AND Price LT 65 AS LT65"
placement_params = {"price": 65, "continent": "America"} placement_params = {"Price": 65, "continent": "America"}
file_path = generate_file(simple_object_size.value) file_path = generate_file(simple_object_size.value)
expected_copies = 3 expected_copies = 2
endpoint = self.cluster.default_rpc_endpoint endpoint = self.cluster.default_rpc_endpoint
with reporter.step(f"Create container with policy {placement_rule}"): with reporter.step(f"Create container with policy {placement_rule}"):
@ -981,12 +1006,11 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Check the object appearance"): with reporter.step(f"Check the object appearance"):
netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell)) netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell))
netmap = self.get_netmap_param(netmap) netmap = self.get_netmap_param(netmap)
with reporter.step(f"Check three nodes are selected not from {placement_params['continent']}" with reporter.step(f"Check three nodes are selected not from {placement_params['continent']}"):
):
for node in resulting_copies: for node in resulting_copies:
node_address = node.get_rpc_endpoint().split(":")[0] node_address = node.get_rpc_endpoint().split(":")[0]
assert ( assert (
int(netmap[node_address]["price"]) < placement_params["price"] int(netmap[node_address]["Price"]) < placement_params["Price"]
and not netmap[node_address]["continent"] == placement_params["continent"] and not netmap[node_address]["continent"] == placement_params["continent"]
) or ( ) or (
not netmap[node_address]["continent"] == placement_params["continent"] not netmap[node_address]["continent"] == placement_params["continent"]
@ -998,18 +1022,18 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.skip(reason="price")
@allure.title("Policy with Multi SELECTs and FILTERs results with 75% of available nodes") @allure.title("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( def test_policy_with_multi_selects_and_filters_results_with_75_of_available_nodes(
self, self,
default_wallet, default_wallet,
simple_object_size: ObjectSize, simple_object_size: ObjectSize,
fill_field_price,
): ):
""" """
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" placement_rule = "REP 3 IN EXPNSV REP 3 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"
placement_params = {"price": [65, 10], "continent": "America"} placement_params = {"Price": [65, 10], "continent": "America"}
file_path = generate_file(simple_object_size.value) file_path = generate_file(simple_object_size.value)
expected_copies = 4 expected_copies = 4
endpoint = self.cluster.default_rpc_endpoint endpoint = self.cluster.default_rpc_endpoint
@ -1039,11 +1063,11 @@ class TestPolicy(ClusterTestBase):
node_address = node.get_rpc_endpoint().split(":")[0] node_address = node.get_rpc_endpoint().split(":")[0]
assert ( assert (
( (
int(netmap[node_address]["price"]) > placement_params["price"][1] int(netmap[node_address]["Price"]) > placement_params["Price"][1]
and not netmap[node_address]["continent"] == placement_params["continent"] and not netmap[node_address]["continent"] == placement_params["continent"]
) )
or ( or (
int(netmap[node_address]["price"]) < placement_params["price"][0] int(netmap[node_address]["Price"]) < placement_params["Price"][0]
and not netmap[node_address]["continent"] == placement_params["continent"] and not netmap[node_address]["continent"] == placement_params["continent"]
) )
or not (netmap[node_address]["continent"] == placement_params["continent"]) or not (netmap[node_address]["continent"] == placement_params["continent"])
@ -1055,7 +1079,6 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.sanity
@allure.title("Simple policy results with 100% of available nodes") @allure.title("Simple policy results with 100% of available nodes")
def test_simple_policy_results_with_100_of_available_nodes( def test_simple_policy_results_with_100_of_available_nodes(
self, self,
@ -1130,18 +1153,18 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.skip(reason="price")
@allure.title("Policy with SELECT and FILTER results with 100% of available nodes") @allure.title("Policy with SELECT and FILTER results with 100% of available nodes")
def test_policy_with_select_and_filter_results_with_100_of_available_nodes( def test_policy_with_select_and_filter_results_with_100_of_available_nodes(
self, self,
default_wallet, default_wallet,
simple_object_size: ObjectSize, simple_object_size: ObjectSize,
fill_field_price,
): ):
""" """
This test checks object's copies based on container's placement policy with SELECT and FILTER results with 100% of available nodes. This test checks object's copies based on container's placement policy with SELECT and FILTER results with 100% of available nodes.
""" """
placement_rule = "REP 1 IN All SELECT 4 FROM AllNodes AS All FILTER Price GE 0 AS AllNodes" placement_rule = "REP 1 IN All SELECT 4 FROM AllNodes AS All FILTER Price GE 0 AS AllNodes"
placement_params = {"price": 0} placement_params = {"Price": 0}
file_path = generate_file(simple_object_size.value) file_path = generate_file(simple_object_size.value)
expected_copies = 1 expected_copies = 1
endpoint = self.cluster.default_rpc_endpoint endpoint = self.cluster.default_rpc_endpoint
@ -1167,9 +1190,9 @@ class TestPolicy(ClusterTestBase):
netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell)) netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell))
netmap = self.get_netmap_param(netmap) netmap = self.get_netmap_param(netmap)
node_address = resulting_copies[0].get_rpc_endpoint().split(":")[0] node_address = resulting_copies[0].get_rpc_endpoint().split(":")[0]
with reporter.step(f"Check the node is selected with price >= {placement_params['price']}"): with reporter.step(f"Check the node is selected with price >= {placement_params['Price']}"):
assert ( assert (
netmap[node_address]["price"] >= int(placement_params["price"]) int(netmap[node_address]["Price"]) >= placement_params["Price"]
), f"The node is selected with the wrong price. Got {netmap[node_address]}" ), f"The node is selected with the wrong price. Got {netmap[node_address]}"
with reporter.step(f"Delete the object from the container"): with reporter.step(f"Delete the object from the container"):
@ -1233,12 +1256,13 @@ class TestPolicy(ClusterTestBase):
self, self,
default_wallet, default_wallet,
simple_object_size: ObjectSize, simple_object_size: ObjectSize,
fill_field_price,
): ):
""" """
This test checks object's copies based on container's placement policy with Multi SELECTs and FILTERs results with 100% of available nodes. This test checks object's copies based on container's placement policy with Multi SELECTs and FILTERs results with 100% of available nodes.
""" """
placement_rule = "REP 4 IN AllOne REP 4 IN AllTwo CBF 4 SELECT 2 FROM GEZero AS AllOne SELECT 2 FROM AllCountries AS AllTwo FILTER Country EQ Russia OR Country EQ Sweden OR Country EQ Finland AS AllCountries FILTER Price GE 0 AS GEZero" placement_rule = "REP 4 IN AllOne REP 4 IN AllTwo CBF 4 SELECT 2 FROM GEZero AS AllOne SELECT 2 FROM AllCountries AS AllTwo FILTER Country EQ Russia OR Country EQ Sweden OR Country EQ Finland AS AllCountries FILTER Price GE 0 AS GEZero"
placement_params = {"country": ["Russia", "Sweden", "Finland"], "price": 0} placement_params = {"country": ["Russia", "Sweden", "Finland"], "Price": 0}
file_path = generate_file(simple_object_size.value) file_path = generate_file(simple_object_size.value)
expected_copies = 4 expected_copies = 4
endpoint = self.cluster.default_rpc_endpoint endpoint = self.cluster.default_rpc_endpoint
@ -1267,7 +1291,7 @@ class TestPolicy(ClusterTestBase):
for node in resulting_copies: for node in resulting_copies:
node_address = node.get_rpc_endpoint().split(":")[0] node_address = node.get_rpc_endpoint().split(":")[0]
assert (netmap[node_address]["country"] in placement_params["country"]) or ( assert (netmap[node_address]["country"] in placement_params["country"]) or (
int(netmap[node_address]["price"]) >= placement_params["price"] int(netmap[node_address]["Price"]) >= placement_params["Price"]
), f"The node is selected from the wrong country or with wrong price. Got {netmap[node_address]}" ), f"The node is selected from the wrong country or with wrong price. Got {netmap[node_address]}"
with reporter.step(f"Delete the object from the container"): with reporter.step(f"Delete the object from the container"):
@ -1276,7 +1300,6 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.sanity
@allure.title("Simple policy results with UNIQUE nodes") @allure.title("Simple policy results with UNIQUE nodes")
def test_simple_policy_results_with_unique_nodes( def test_simple_policy_results_with_unique_nodes(
self, self,
@ -1351,7 +1374,6 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.sanity
@allure.title("Policy with SELECT and Complex FILTER results with UNIQUE nodes") @allure.title("Policy with SELECT and Complex FILTER results with UNIQUE nodes")
def test_policy_with_select_and_complex_filter_results_with_unique_nodes( def test_policy_with_select_and_complex_filter_results_with_unique_nodes(
self, self,
@ -1402,7 +1424,6 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Delete the container"): with reporter.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.sanity
@allure.title("Policy with Multi SELECTs and FILTERs results with UNIQUE nodes") @allure.title("Policy with Multi SELECTs and FILTERs results with UNIQUE nodes")
def test_policy_with_multi_selects_and_filters_results_with_unique_nodes( def test_policy_with_multi_selects_and_filters_results_with_unique_nodes(
self, self,
@ -1438,9 +1459,7 @@ class TestPolicy(ClusterTestBase):
with reporter.step(f"Check the object appearance"): with reporter.step(f"Check the object appearance"):
netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell)) netmap = parse_netmap_output(get_netmap_snapshot(node=resulting_copies[0], shell=self.shell))
netmap = self.get_netmap_param(netmap) netmap = self.get_netmap_param(netmap)
with reporter.step( with reporter.step(f"Check three nodes are selected from any country"):
f"Check three nodes are selected from any country"
):
for node in resulting_copies: for node in resulting_copies:
node_address = node.get_rpc_endpoint().split(":")[0] node_address = node.get_rpc_endpoint().split(":")[0]
assert (placement_params["country"][0] == netmap[node_address]["country"]) or ( assert (placement_params["country"][0] == netmap[node_address]["country"]) or (
@ -1523,7 +1542,7 @@ class TestPolicy(ClusterTestBase):
dict_external[external_adress] = { dict_external[external_adress] = {
"country": node.country, "country": node.country,
"country_code": node.country_code, "country_code": node.country_code,
"price": node.price, "Price": node.price,
"continent": node.continent, "continent": node.continent,
"un_locode": node.un_locode, "un_locode": node.un_locode,
"location": node.location, "location": node.location,