2023-12-08 12:07:34 +00:00
import allure
2024-01-12 09:43:28 +00:00
import pytest
2023-11-29 13:34:59 +00:00
from frostfs_testlib import reporter
2024-11-18 12:17:52 +00:00
from frostfs_testlib . steps . cli . container import create_container , delete_container
2023-10-18 10:08:15 +00:00
from frostfs_testlib . steps . cli . object import delete_object , put_object_to_random_node
2023-10-20 10:59:15 +00:00
from frostfs_testlib . steps . node_management import get_netmap_snapshot
2024-01-12 09:43:28 +00:00
from frostfs_testlib . steps . storage_policy import get_nodes_with_object
2023-10-17 11:00:21 +00:00
from frostfs_testlib . storage . dataclasses . object_size import ObjectSize
2024-11-18 12:17:52 +00:00
from frostfs_testlib . storage . dataclasses . wallet import WalletInfo
2023-10-17 11:00:21 +00:00
from frostfs_testlib . testing . cluster_test_base import ClusterTestBase
2023-10-20 10:59:15 +00:00
from frostfs_testlib . utils . cli_utils import parse_netmap_output
2023-10-17 11:00:21 +00:00
from frostfs_testlib . utils . file_utils import generate_file
2024-11-18 12:17:52 +00:00
from . . . helpers . container_request import PUBLIC_WITH_POLICY , ContainerRequest
from . . . helpers . policy_validation import get_netmap_param , validate_object_policy
2024-10-29 10:32:07 +00:00
from . . . resources . policy_error_patterns import NOT_ENOUGH_TO_SELECT , NOT_FOUND_FILTER , NOT_FOUND_SELECTOR , NOT_PARSE_POLICY
2023-10-17 11:00:21 +00:00
2023-09-25 09:47:24 +00:00
2024-10-11 09:30:23 +00:00
@pytest.mark.nightly
2023-09-25 09:47:24 +00:00
@pytest.mark.policy
class TestPolicy ( ClusterTestBase ) :
2023-10-18 10:08:15 +00:00
@allure.title ( " [NEGATIVE] Placement policy: Can ' t parse placement policy " )
2024-11-18 12:17:52 +00:00
def test_placement_policy_negative ( self , default_wallet : WalletInfo , rpc_endpoint : str ) :
2023-09-25 09:47:24 +00:00
"""
2023-10-23 13:13:10 +00:00
Negative test for placement policy : Can ' t parse placement policy.
2023-09-25 09:47:24 +00:00
"""
2023-10-18 10:08:15 +00:00
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 "
2024-01-12 09:43:28 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Create container with policy { placement_rule } " ) :
2023-10-18 10:08:15 +00:00
with pytest . raises ( Exception , match = NOT_PARSE_POLICY ) :
2024-11-18 12:17:52 +00:00
create_container ( default_wallet , self . shell , rpc_endpoint , placement_rule )
2023-09-25 09:47:24 +00:00
2023-10-17 11:00:21 +00:00
@allure.title ( " [NEGATIVE] Placement policy: Not enough nodes to SELECT " )
2024-11-18 12:17:52 +00:00
def test_placement_policy_negative_not_enough_nodes_to_select ( self , default_wallet : WalletInfo , rpc_endpoint : str ) :
2023-09-25 09:47:24 +00:00
"""
Negative test for placement policy : Not enough nodes to SELECT .
"""
2023-10-18 10:08:15 +00:00
placement_rule = " REP 2 IN RU SELECT 2 FROM RUS AS RU FILTER Country EQ Russia AND SubDivCode EQ SPE AS RUS "
2024-11-18 12:17:52 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Create container with policy { placement_rule } " ) :
2023-10-18 10:08:15 +00:00
with pytest . raises ( Exception , match = NOT_ENOUGH_TO_SELECT ) :
2024-11-18 12:17:52 +00:00
create_container ( default_wallet , self . shell , rpc_endpoint , placement_rule )
2023-10-17 11:00:21 +00:00
@allure.title ( " [NEGATIVE] Placement policy: Filter not found " )
2024-11-18 12:17:52 +00:00
def test_placement_policy_negative_not_enough_nodes_to_filter ( self , default_wallet : WalletInfo , rpc_endpoint : str ) :
2023-09-25 09:47:24 +00:00
"""
Negative test for placement policy : Filter not found .
"""
2024-10-11 09:30:23 +00:00
placement_rule = (
" REP 2 IN HALF CBF 1 SELECT 2 FROM GT15 AS HALF FILTER @NOTRU AND Price GT 15 AS GT15 FILTER CountryCode NE RU AS NOTRU "
)
2024-11-18 12:17:52 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Create container with policy { placement_rule } " ) :
2023-10-18 10:08:15 +00:00
with pytest . raises ( Exception , match = NOT_FOUND_FILTER ) :
2024-11-18 12:17:52 +00:00
create_container ( default_wallet , self . shell , rpc_endpoint , placement_rule )
2023-10-17 11:00:21 +00:00
@allure.title ( " [NEGATIVE] Placement policy: SELECTOR not found " )
2024-11-18 12:17:52 +00:00
def test_placement_policy_negative_not_enough_nodes_to_selector ( self , default_wallet : WalletInfo , rpc_endpoint : str ) :
2023-09-25 09:47:24 +00:00
"""
Negative test for placement policy : Filter not found .
"""
2023-10-18 10:08:15 +00:00
placement_rule = " REP 2 IN HALFIC CBF 1 SELECT 2 FROM GT15 AS HALF FILTER Price GT 15 AS GT15 "
2024-11-18 12:17:52 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Create container with policy { placement_rule } " ) :
2023-10-18 10:08:15 +00:00
with pytest . raises ( Exception , match = NOT_FOUND_SELECTOR ) :
2024-11-18 12:17:52 +00:00
create_container ( default_wallet , self . shell , rpc_endpoint , placement_rule )
2023-09-25 09:47:24 +00:00
2023-10-17 11:00:21 +00:00
@allure.title ( " Simple policy results with one node " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize ( " container_request " , [ PUBLIC_WITH_POLICY ( " REP 1 REP 1 CBF 1 " ) ] , indirect = True )
2023-09-25 09:47:24 +00:00
def test_simple_policy_results_with_one_node (
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-09-25 09:47:24 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-09-25 09:47:24 +00:00
) :
"""
This test checks object ' s copies based on container ' s placement simple policy results with one node .
"""
file_path = generate_file ( simple_object_size . value )
2023-10-17 11:00:21 +00:00
expected_copies = 1
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-09-25 09:47:24 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-09-25 09:47:24 +00:00
2023-10-17 11:00:21 +00:00
@allure.title ( " Policy with SELECT results with one node " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize (
" container_request " , [ PUBLIC_WITH_POLICY ( " REP 1 IN AnyNode REP 1 IN AnyNode CBF 1 SELECT 1 FROM * AS AnyNode " ) ] , indirect = True
)
2023-10-17 11:00:21 +00:00
def test_policy_with_select_results_with_one_node (
2023-09-25 09:47:24 +00:00
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-09-25 09:47:24 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-09-25 09:47:24 +00:00
) :
"""
2023-10-17 11:00:21 +00:00
This test checks object ' s copies based on container ' s placement policy with SELECT results with one node .
2023-09-25 09:47:24 +00:00
"""
file_path = generate_file ( simple_object_size . value )
2023-10-17 11:00:21 +00:00
expected_copies = 1
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-09-25 09:47:24 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-09-25 09:47:24 +00:00
2023-10-17 11:00:21 +00:00
@allure.title ( " Policy with SELECT and FILTER results with one node " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize (
" container_request " ,
[
PUBLIC_WITH_POLICY (
" REP 1 IN MyRussianNodes REP 1 IN MyRussianNodes CBF 1 SELECT 1 FROM RussianNodes AS MyRussianNodes FILTER Country EQ ' Russia ' AS RussianNodes "
)
] ,
indirect = True ,
)
2023-10-17 11:00:21 +00:00
def test_policy_with_select_and_filter_results_with_one_node (
2023-09-25 09:47:24 +00:00
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-09-25 09:47:24 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-09-25 09:47:24 +00:00
) :
"""
2023-10-17 11:00:21 +00:00
This test checks object ' s copies based on container ' s placement policy with SELECT and FILTER results with one node .
2023-09-25 09:47:24 +00:00
"""
file_path = generate_file ( simple_object_size . value )
2023-10-17 11:00:21 +00:00
expected_copies = 1
2023-12-01 11:48:48 +00:00
placement_params = { " country " : " Russia " }
2023-09-25 09:47:24 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-09-25 09:47:24 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check the object appearance " ) :
2023-10-23 13:13:10 +00:00
netmap = parse_netmap_output ( get_netmap_snapshot ( node = resulting_copies [ 0 ] , shell = self . shell ) )
2024-11-18 12:17:52 +00:00
netmap = get_netmap_param ( netmap )
2023-10-23 13:13:10 +00:00
node_address = resulting_copies [ 0 ] . get_rpc_endpoint ( ) . split ( " : " ) [ 0 ]
2023-12-08 12:07:34 +00:00
with reporter . step ( f " Check the node is selected from { placement_params [ ' country ' ] } " ) :
2023-12-01 11:48:48 +00:00
assert (
placement_params [ " country " ] == netmap [ node_address ] [ " country " ]
) , f " The node is selected from the wrong country. Got { netmap [ node_address ] } "
2023-10-23 13:13:10 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-09-25 09:47:24 +00:00
2023-10-17 11:00:21 +00:00
@allure.title ( " Policy with SELECT and Complex FILTER results with one node " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize (
" container_request " ,
[
PUBLIC_WITH_POLICY (
" 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 "
)
] ,
indirect = True ,
)
2023-10-17 11:00:21 +00:00
def test_policy_with_select_and_complex_filter_results_with_one_nodes (
2023-09-25 09:47:24 +00:00
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-09-25 09:47:24 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-09-25 09:47:24 +00:00
) :
"""
2023-10-17 11:00:21 +00:00
This test checks object ' s copies based on container ' s placement policy with SELECT and Complex FILTER results with one node .
2023-09-25 09:47:24 +00:00
"""
2023-12-01 11:48:48 +00:00
placement_params = { " country " : [ " Russia " , " Sweden " ] , " country_code " : " FI " }
2023-09-25 09:47:24 +00:00
file_path = generate_file ( simple_object_size . value )
2023-10-17 11:00:21 +00:00
expected_copies = 1
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-09-25 09:47:24 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check the object appearance " ) :
2023-10-23 13:13:10 +00:00
netmap = parse_netmap_output ( get_netmap_snapshot ( node = resulting_copies [ 0 ] , shell = self . shell ) )
2024-11-18 12:17:52 +00:00
netmap = get_netmap_param ( netmap )
2023-10-23 13:13:10 +00:00
node_address = resulting_copies [ 0 ] . get_rpc_endpoint ( ) . split ( " : " ) [ 0 ]
2024-01-12 09:43:28 +00:00
with reporter . step ( f " Check the node is selected from { placement_params [ ' country ' ] [ 0 ] } " ) :
2023-12-01 11:48:48 +00:00
assert (
not ( placement_params [ " country " ] [ 1 ] == netmap [ node_address ] [ " country " ] )
or not ( placement_params [ " country " ] [ 1 ] == netmap [ node_address ] [ " country " ] )
and not ( placement_params [ " country_code " ] == netmap [ node_address ] [ " country_code " ] )
and ( placement_params [ " country " ] [ 0 ] == netmap [ node_address ] [ " country " ] )
) , f " The node is selected from the wrong country or country code. Got { netmap [ node_address ] } "
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-09-25 09:47:24 +00:00
2023-10-17 11:00:21 +00:00
@allure.title ( " Policy with Multi SELECTs and FILTERs results with one node " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize (
" container_request " ,
[
PUBLIC_WITH_POLICY (
" 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 "
)
] ,
indirect = True ,
)
2023-10-17 11:00:21 +00:00
def test_policy_with_multi_selects_and_filters_results_with_one_node (
2023-09-25 09:47:24 +00:00
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-09-25 09:47:24 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-09-25 09:47:24 +00:00
) :
"""
2023-10-17 11:00:21 +00:00
This test checks object ' s copies based on container ' s placement policy with Multi SELECTs and FILTERs results with one nodes .
2023-09-25 09:47:24 +00:00
"""
2023-12-01 11:48:48 +00:00
placement_params = { " country " : [ " Sweden " , " Russia " ] , " country_code " : " FI " }
2023-09-25 09:47:24 +00:00
file_path = generate_file ( simple_object_size . value )
2023-10-18 11:57:52 +00:00
expected_copies = 2
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check the object appearance " ) :
2023-10-23 13:13:10 +00:00
netmap = parse_netmap_output ( get_netmap_snapshot ( node = resulting_copies [ 0 ] , shell = self . shell ) )
2024-11-18 12:17:52 +00:00
netmap = get_netmap_param ( netmap )
2023-12-08 12:07:34 +00:00
with reporter . step ( f " Check two nodes are selected from any country " ) :
2023-12-01 11:48:48 +00:00
for node in resulting_copies :
node_address = resulting_copies [ 0 ] . get_rpc_endpoint ( ) . split ( " : " ) [ 0 ]
assert ( placement_params [ " country " ] [ 1 ] == netmap [ node_address ] [ " country " ] ) or (
not ( placement_params [ " country " ] [ 1 ] == netmap [ node_address ] [ " country " ] )
and ( placement_params [ " country " ] [ 0 ] == netmap [ node_address ] [ " country " ] )
or ( placement_params [ " country_code " ] == netmap [ node_address ] [ " country_code " ] )
) , f " The node is selected from the wrong country or country code. Got { netmap [ node_address ] } "
2023-09-25 09:47:24 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-09-25 09:47:24 +00:00
2023-10-17 11:00:21 +00:00
@allure.title ( " Policy with SELECT and FILTER results with UNIQUE nodes " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize (
" container_request " ,
[
PUBLIC_WITH_POLICY (
" UNIQUE REP 1 IN MyRussianNodes REP 1 IN MyRussianNodes CBF 1 SELECT 1 FROM RussianNodes AS MyRussianNodes FILTER Country EQ ' Russia ' AS RussianNodes "
)
] ,
indirect = True ,
)
2023-10-17 11:00:21 +00:00
def test_policy_with_select_and_filter_results_with_unique_nodes (
2023-09-25 09:47:24 +00:00
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-09-25 09:47:24 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-09-25 09:47:24 +00:00
) :
"""
2023-10-17 11:00:21 +00:00
This test checks object ' s copies based on container ' s placement policy with SELECT and FILTER results with UNIQUE nodes .
2023-09-25 09:47:24 +00:00
"""
2023-12-01 11:48:48 +00:00
placement_params = { " country " : " Russia " }
2023-09-25 09:47:24 +00:00
file_path = generate_file ( simple_object_size . value )
2023-10-17 11:00:21 +00:00
expected_copies = 2
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-09-25 09:47:24 +00:00
2023-12-08 12:07:34 +00:00
with reporter . step ( f " Check the object appearance " ) :
2023-10-23 14:11:53 +00:00
netmap = parse_netmap_output ( get_netmap_snapshot ( node = resulting_copies [ 0 ] , shell = self . shell ) )
2024-11-18 12:17:52 +00:00
netmap = get_netmap_param ( netmap )
2023-12-08 12:07:34 +00:00
with reporter . step ( f " Check two nodes are selected from { placement_params [ ' country ' ] } " ) :
2023-12-01 11:48:48 +00:00
for node in resulting_copies :
2024-01-12 09:43:28 +00:00
node_address = node . get_rpc_endpoint ( ) . split ( " : " ) [ 0 ]
2023-12-01 11:48:48 +00:00
assert (
placement_params [ " country " ] == netmap [ node_address ] [ " country " ]
) , f " The node is selected from the wrong country. Got { netmap [ node_address ] [ ' country ' ] } "
2023-10-17 11:00:21 +00:00
2024-03-11 12:32:29 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-09-25 09:47:24 +00:00
2023-10-17 11:00:21 +00:00
@allure.title ( " Simple policy results with 25 % o f available nodes " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize ( " container_request " , [ PUBLIC_WITH_POLICY ( " REP 1 CBF 1 " ) ] , indirect = True )
2023-09-25 09:47:24 +00:00
def test_simple_policy_results_with_25_of_available_nodes (
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-09-25 09:47:24 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-09-25 09:47:24 +00:00
) :
"""
This test checks object ' s copies based on container ' s placement policy results with 25 % of available nodes .
"""
file_path = generate_file ( simple_object_size . value )
2023-10-17 11:00:21 +00:00
expected_copies = 1
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-09-25 09:47:24 +00:00
2023-10-17 11:00:21 +00:00
@allure.title ( " Policy with SELECT results with 25 % o f available nodes " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize ( " container_request " , [ PUBLIC_WITH_POLICY ( " REP 1 IN One CBF 1 SELECT 1 FROM * AS One " ) ] , indirect = True )
2023-09-25 09:47:24 +00:00
def test_policy_with_select_results_with_25_of_available_nodes (
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-09-25 09:47:24 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-09-25 09:47:24 +00:00
) :
"""
2023-10-17 11:00:21 +00:00
This test checks object ' s copies based on container ' s placement policy with SELECT results with 25 % of available nodes .
2023-09-25 09:47:24 +00:00
"""
file_path = generate_file ( simple_object_size . value )
2023-10-17 11:00:21 +00:00
expected_copies = 1
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-09-25 09:47:24 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-09-25 09:47:24 +00:00
2023-10-17 11:00:21 +00:00
@allure.title ( " Simple policy results with 50 % o f available nodes " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize ( " container_request " , [ PUBLIC_WITH_POLICY ( " REP 2 CBF 1 " ) ] , indirect = True )
2023-10-17 11:00:21 +00:00
def test_simple_policy_results_with_50_of_available_nodes (
2023-09-25 09:47:24 +00:00
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-09-25 09:47:24 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-09-25 09:47:24 +00:00
) :
"""
2023-10-17 11:00:21 +00:00
This test checks object ' s copies based on container ' s placement simple policy results with 50 % of available nodes .
2023-09-25 09:47:24 +00:00
"""
file_path = generate_file ( simple_object_size . value )
2023-10-17 11:00:21 +00:00
expected_copies = 2
2023-09-25 09:47:24 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-09-25 09:47:24 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-10-17 11:00:21 +00:00
@allure.title ( " Policy with SELECT results with 50 % o f available nodes " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize ( " container_request " , [ PUBLIC_WITH_POLICY ( " REP 2 IN HALF CBF 1 SELECT 2 FROM * AS HALF " ) ] , indirect = True )
2023-10-17 11:00:21 +00:00
def test_policy_with_select_results_with_50_of_available_nodes (
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-10-17 11:00:21 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-09-25 09:47:24 +00:00
) :
2023-10-17 11:00:21 +00:00
"""
This test checks object ' s copies based on container ' s placement policy with SELECT results with 50 % of available nodes .
"""
file_path = generate_file ( simple_object_size . value )
expected_copies = 2
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-10-17 11:00:21 +00:00
@allure.title ( " Simple policy results with 75 % o f available nodes " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize ( " container_request " , [ PUBLIC_WITH_POLICY ( " REP 1 " ) ] , indirect = True )
2023-10-17 11:00:21 +00:00
def test_simple_policy_results_with_75_of_available_nodes (
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-10-17 11:00:21 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-10-17 11:00:21 +00:00
) :
"""
This test checks object ' s copies based on container ' s placement simple policy results with 75 % of available nodes .
"""
file_path = generate_file ( simple_object_size . value )
2023-10-18 11:57:52 +00:00
expected_copies = 1
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-10-17 11:00:21 +00:00
@allure.title ( " Policy with SELECT results with 75 % o f available nodes " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize (
" container_request " , [ PUBLIC_WITH_POLICY ( " REP 2 IN DS CBF 1 SELECT 3 IN DISTINCT Country FROM * AS DS " ) ] , indirect = True
)
2023-10-17 11:00:21 +00:00
def test_policy_with_select_results_with_75_of_available_nodes (
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-10-17 11:00:21 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-10-17 11:00:21 +00:00
) :
"""
2023-10-18 10:08:15 +00:00
This test checks object ' s copies based on container ' s placement policy with SELECT results with 75 % of available nodes .
2023-10-17 11:00:21 +00:00
"""
file_path = generate_file ( simple_object_size . value )
2023-10-18 11:57:52 +00:00
expected_copies = 2
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-10-17 11:00:21 +00:00
@allure.title ( " Simple policy results with 100 % o f available nodes " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize ( " container_request " , [ PUBLIC_WITH_POLICY ( " REP 4 " ) ] , indirect = True )
2023-10-17 11:00:21 +00:00
def test_simple_policy_results_with_100_of_available_nodes (
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-10-17 11:00:21 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-10-17 11:00:21 +00:00
) :
"""
This test checks object ' s copies based on container ' s placement simple policy results with 100 % of available nodes .
"""
file_path = generate_file ( simple_object_size . value )
expected_copies = 4
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-10-17 11:00:21 +00:00
@allure.title ( " Policy with SELECT results with 100 % o f available nodes " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize ( " container_request " , [ PUBLIC_WITH_POLICY ( " REP 1 IN All SELECT 4 FROM * AS All " ) ] , indirect = True )
2023-10-17 11:00:21 +00:00
def test_policy_with_select_results_with_100_of_available_nodes (
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-10-17 11:00:21 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-10-17 11:00:21 +00:00
) :
"""
This test checks object ' s copies based on container ' s placement policy with SELECT results with 100 % of available nodes .
"""
file_path = generate_file ( simple_object_size . value )
2023-10-18 11:57:52 +00:00
expected_copies = 1
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-10-17 11:00:21 +00:00
@allure.title ( " Policy with SELECT and Complex FILTER results with 100 % o f available nodes " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize (
" container_request " ,
[
PUBLIC_WITH_POLICY (
" REP 2 IN All SELECT 4 FROM AllNodes AS All FILTER Country EQ Russia OR Country EQ Sweden OR Country EQ Finland AS AllCountries FILTER @AllCountries AND Continent EQ Europe AS AllNodes "
)
] ,
indirect = True ,
)
2023-10-17 11:00:21 +00:00
def test_policy_with_select_and_complex_filter_results_with_100_of_available_nodes (
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-10-17 11:00:21 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-10-17 11:00:21 +00:00
) :
"""
This test checks object ' s copies based on container ' s placement policy with SELECT and Complex FILTER results with 100 % of available nodes .
"""
2023-12-01 11:48:48 +00:00
placement_params = { " country " : [ " Russia " , " Sweden " , " Finland " ] , " continent " : " Europe " }
2023-10-17 11:00:21 +00:00
file_path = generate_file ( simple_object_size . value )
2023-10-18 11:57:52 +00:00
expected_copies = 2
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check the object appearance " ) :
2023-10-24 08:43:53 +00:00
netmap = parse_netmap_output ( get_netmap_snapshot ( node = resulting_copies [ 0 ] , shell = self . shell ) )
2024-11-18 12:17:52 +00:00
netmap = get_netmap_param ( netmap )
2023-12-08 12:07:34 +00:00
with reporter . step ( f " Check two nodes are selected from { ' or ' . join ( placement_params [ ' country ' ] ) } " ) :
2023-12-01 11:48:48 +00:00
for node in resulting_copies :
node_address = node . get_rpc_endpoint ( ) . split ( " : " ) [ 0 ]
assert (
( netmap [ node_address ] [ " country " ] in placement_params [ " country " ] )
or ( netmap [ node_address ] [ " country " ] in placement_params [ " country " ] )
and ( netmap [ node_address ] [ " continent " ] == placement_params [ " continent " ] )
) , f " The node is selected from the wrong country or continent. Got { netmap [ node_address ] } "
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-10-17 11:00:21 +00:00
@allure.title ( " Simple policy results with UNIQUE nodes " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize ( " container_request " , [ PUBLIC_WITH_POLICY ( " UNIQUE REP 1 REP 1 CBF 1 " ) ] , indirect = True )
2023-10-23 13:13:10 +00:00
def test_simple_policy_results_with_unique_nodes (
2023-10-17 11:00:21 +00:00
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-10-17 11:00:21 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-10-17 11:00:21 +00:00
) :
"""
This test checks object ' s copies based on container ' s placement simple policy results with UNIQUE nodes .
"""
file_path = generate_file ( simple_object_size . value )
expected_copies = 2
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-10-17 11:00:21 +00:00
@allure.title ( " Policy with SELECT results with UNIQUE nodes " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize (
" container_request " ,
[ PUBLIC_WITH_POLICY ( " UNIQUE REP 1 IN AnyNode REP 1 IN AnyNode CBF 1 SELECT 1 FROM * AS AnyNode " ) ] ,
indirect = True ,
)
2023-10-17 11:00:21 +00:00
def test_policy_with_select_results_with_unique_nodes (
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-10-17 11:00:21 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-10-17 11:00:21 +00:00
) :
"""
This test checks object ' s copies based on container ' s placement policy with SELECT results with UNIQUE nodes .
"""
file_path = generate_file ( simple_object_size . value )
expected_copies = 2
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-10-17 11:00:21 +00:00
2023-12-08 12:07:34 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-10-17 11:00:21 +00:00
@allure.title ( " Policy with SELECT and Complex FILTER results with UNIQUE nodes " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize (
" container_request " ,
[
PUBLIC_WITH_POLICY (
" UNIQUE 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 "
)
] ,
indirect = True ,
)
2023-10-17 11:00:21 +00:00
def test_policy_with_select_and_complex_filter_results_with_unique_nodes (
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-10-17 11:00:21 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-10-17 11:00:21 +00:00
) :
"""
This test checks object ' s copies based on container ' s placement policy with SELECT and Complex FILTER results with UNIQUE nodes .
"""
2023-12-01 11:48:48 +00:00
placement_params = { " country_code " : " FI " , " country " : [ " Sweden " , " Russia " ] }
2023-10-17 11:00:21 +00:00
file_path = generate_file ( simple_object_size . value )
expected_copies = 2
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-10-17 11:00:21 +00:00
2023-12-08 12:07:34 +00:00
with reporter . step ( f " Check the object appearance " ) :
2023-10-23 14:11:53 +00:00
netmap = parse_netmap_output ( get_netmap_snapshot ( node = resulting_copies [ 0 ] , shell = self . shell ) )
2024-11-18 12:17:52 +00:00
netmap = get_netmap_param ( netmap )
2023-12-08 12:07:34 +00:00
with reporter . step ( f " Check two nodes are selected not from { placement_params [ ' country ' ] [ 0 ] } " ) :
2023-12-01 11:48:48 +00:00
for node in resulting_copies :
node_address = node . get_rpc_endpoint ( ) . split ( " : " ) [ 0 ]
assert not ( placement_params [ " country " ] [ 0 ] == netmap [ node_address ] [ " country " ] ) or (
not ( placement_params [ " country " ] [ 0 ] == netmap [ node_address ] [ " country " ] )
and not ( placement_params [ " country_code " ] == netmap [ node_address ] [ " country_code " ] )
and placement_params [ " country " ] [ 1 ] == netmap [ node_address ] [ " country " ]
) , f " The node is selected from the wrong country or with wrong country code. Got { netmap [ node_address ] } "
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-10-17 11:00:21 +00:00
@allure.title ( " Policy with Multi SELECTs and FILTERs results with UNIQUE nodes " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize (
" container_request " ,
[
PUBLIC_WITH_POLICY (
" UNIQUE 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 "
)
] ,
indirect = True ,
)
2023-10-17 11:00:21 +00:00
def test_policy_with_multi_selects_and_filters_results_with_unique_nodes (
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-10-17 11:00:21 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-10-17 11:00:21 +00:00
) :
"""
This test checks object ' s copies based on container ' s placement policy with Multi SELECTs and FILTERs results with UNIQUE nodes .
"""
2023-12-01 11:48:48 +00:00
placement_params = { " country " : [ " Russia " , " Sweden " ] , " country_code " : " FI " }
2023-10-17 11:00:21 +00:00
file_path = generate_file ( simple_object_size . value )
expected_copies = 3
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2024-10-11 09:30:23 +00:00
assert len ( resulting_copies ) == expected_copies , f " Expected { expected_copies } copies, got { len ( resulting_copies ) } "
2023-10-17 11:00:21 +00:00
2023-12-08 12:07:34 +00:00
with reporter . step ( f " Check the object appearance " ) :
2023-10-23 14:11:53 +00:00
netmap = parse_netmap_output ( get_netmap_snapshot ( node = resulting_copies [ 0 ] , shell = self . shell ) )
2024-11-18 12:17:52 +00:00
netmap = get_netmap_param ( netmap )
2024-01-12 09:43:28 +00:00
with reporter . step ( f " Check three nodes are selected from any country " ) :
2023-12-01 11:48:48 +00:00
for node in resulting_copies :
2024-01-12 09:43:28 +00:00
node_address = node . get_rpc_endpoint ( ) . split ( " : " ) [ 0 ]
2023-12-01 11:48:48 +00:00
assert ( placement_params [ " country " ] [ 0 ] == netmap [ node_address ] [ " country " ] ) or (
not ( placement_params [ " country " ] [ 0 ] == netmap [ node_address ] [ " country " ] )
and ( placement_params [ " country " ] [ 1 ] == netmap [ node_address ] [ " country " ] )
or ( placement_params [ " country_code " ] == netmap [ node_address ] [ " country_code " ] )
) , f " The node is selected from the wrong country or with wrong country code. Got { netmap [ node_address ] } "
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-17 11:00:21 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )
2023-10-17 11:00:21 +00:00
2023-10-18 10:54:58 +00:00
@allure.title ( " Policy: REP 1 IN SPB REP 1 IN MSK REP 3 " )
2024-11-18 12:17:52 +00:00
@pytest.mark.parametrize (
" container_request " ,
[
PUBLIC_WITH_POLICY (
" 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 "
)
] ,
indirect = True ,
)
2023-10-18 10:54:58 +00:00
def test_policy_rep_1_in_spb_rep_1_in_msk_rep_3 (
self ,
2024-11-18 12:17:52 +00:00
default_wallet : WalletInfo ,
rpc_endpoint : str ,
2023-10-18 10:54:58 +00:00
simple_object_size : ObjectSize ,
2024-11-18 12:17:52 +00:00
container : str ,
container_request : ContainerRequest ,
2023-10-18 10:54:58 +00:00
) :
"""
This test checks object ' s copies based on container ' s placement policy : REP 1 IN SPB REP 1 IN MSK REP 3.
"""
2023-12-01 11:48:48 +00:00
placement_params = { " location " : [ " Saint Petersburg (ex Leningrad) " , " Moskva " ] }
2023-10-18 10:54:58 +00:00
file_path = generate_file ( simple_object_size . value )
expected_copies = 3
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check container policy " ) :
2024-11-18 12:17:52 +00:00
validate_object_policy ( default_wallet , self . shell , container_request . policy , container , rpc_endpoint )
2023-10-18 10:54:58 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Put object in container " ) :
2024-11-18 12:17:52 +00:00
oid = put_object_to_random_node ( default_wallet , file_path , container , self . shell , self . cluster )
2023-10-18 10:54:58 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check object expected copies " ) :
2024-11-18 12:17:52 +00:00
resulting_copies = get_nodes_with_object ( container , oid , self . shell , self . cluster . storage_nodes )
2023-10-18 10:54:58 +00:00
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 ) } "
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Check the object appearance " ) :
2023-10-25 11:39:45 +00:00
netmap = parse_netmap_output ( get_netmap_snapshot ( node = resulting_copies [ 0 ] , shell = self . shell ) )
2024-11-18 12:17:52 +00:00
netmap = get_netmap_param ( netmap )
2023-11-09 20:49:27 +00:00
list_of_location = [ ]
2023-10-25 11:39:45 +00:00
for node in resulting_copies :
node_address = node . get_rpc_endpoint ( ) . split ( " : " ) [ 0 ]
2023-11-09 20:49:27 +00:00
list_of_location . append ( netmap [ node_address ] [ " location " ] )
2023-12-08 12:07:34 +00:00
with reporter . step ( f " Check two or three nodes are selected from Russia and from any other country " ) :
2023-12-01 11:48:48 +00:00
assert (
placement_params [ " location " ] [ 0 ] in list_of_location
and placement_params [ " location " ] [ 1 ] in list_of_location
and len ( resulting_copies ) > 2
) , f " The node is selected from the wrong location. Got { netmap [ node_address ] } "
2023-10-18 10:54:58 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the object from the container " ) :
2024-11-18 12:17:52 +00:00
delete_object ( default_wallet , container , oid , self . shell , rpc_endpoint )
2023-10-18 10:54:58 +00:00
2023-11-29 13:34:59 +00:00
with reporter . step ( f " Delete the container " ) :
2024-11-18 12:17:52 +00:00
delete_container ( default_wallet , container , self . shell , rpc_endpoint , await_mode = False )