Add negative policy tests

This commit is contained in:
Ekaterina Chernitsyna 2023-10-18 13:08:15 +03:00
parent b58af1b01b
commit 5eae65b471
2 changed files with 62 additions and 47 deletions

View file

@ -0,0 +1,4 @@
NOT_PARSE_POLICY = "can't parse placement policy"
NOT_ENOUGH_TO_SELECT = "selector is not enough"
NOT_FOUND_FILTER = "filter not found"
NOT_FOUND_SELECTOR = "selector not found"

View file

@ -2,84 +2,95 @@ import allure
import pytest
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.object import delete_object, put_object_to_random_node, search_object
from frostfs_testlib.steps.node_management import check_node_in_map
from frostfs_testlib.steps.storage_policy import (
get_nodes_with_object,
get_nodes_without_object,
get_object_copies,
get_simple_object_copies,
)
from frostfs_testlib.steps.cli.object import delete_object, put_object_to_random_node
from frostfs_testlib.steps.storage_policy import get_nodes_with_object, get_nodes_without_object
from frostfs_testlib.storage.dataclasses.object_size import ObjectSize
from frostfs_testlib.testing.cluster_test_base import ClusterTestBase
from frostfs_testlib.utils.file_utils import generate_file
from pytest_tests.helpers.utility import placement_policy_from_container
from pytest_tests.resources.policy_error_patterns import (
NOT_ENOUGH_TO_SELECT,
NOT_FOUND_FILTER,
NOT_FOUND_SELECTOR,
NOT_PARSE_POLICY,
)
@pytest.mark.container
@pytest.mark.policy
class TestPolicy(ClusterTestBase):
@pytest.mark.skip(reason="ошибка с фикстурой")
@allure.title("[NEGATIVE] Placement policy")
@allure.title("[NEGATIVE] Placement policy: Can't parse placement policy")
@pytest.mark.policy
def test_placement_policy_negative(self, default_wallet, placement_rule):
def test_placement_policy_negative(self, default_wallet):
"""
Negative test for placement policy.
"""
wallet = default_wallet
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
try:
cid = create_container(
wallet, rule=placement_rule, basic_acl=PUBLIC_ACL, shell=self.shell, endpoint=endpoint
)
except:
got_policy = placement_policy_from_container(
get_container(wallet, cid, json_mode=False, shell=self.shell, endpoint=endpoint)
)
assert got_policy == placement_rule.replace("'", ""), f"Can't parse placement policy"
with allure.step(f"Create container with policy {placement_rule}"):
with pytest.raises(Exception, match=NOT_PARSE_POLICY):
cid = create_container(
wallet=default_wallet,
rule=placement_rule,
basic_acl=PUBLIC_ACL,
shell=self.shell,
endpoint=endpoint,
)
@pytest.mark.skip(reason="ошибка с фикстурой")
@allure.title("[NEGATIVE] Placement policy: Not enough nodes to SELECT")
@pytest.mark.policy
def test_placement_policy_negative_not_enough_nodes_to_select(self, default_wallet, placement_rule):
def test_placement_policy_negative_not_enough_nodes_to_select(self, default_wallet):
"""
Negative test for placement policy: Not enough nodes to SELECT.
"""
wallet = default_wallet
placement_rule = "REP 2 IN RU SELECT 2 FROM RUS AS RU FILTER Country EQ Russia AND SubDivCode EQ SPE AS RUS"
endpoint = self.cluster.default_rpc_endpoint
with pytest.raises(RuntimeError, match=".*not enough nodes to SELECT from.*"):
cid = create_container(
wallet, rule=placement_rule, basic_acl=PUBLIC_ACL, shell=self.shell, endpoint=endpoint
)
with allure.step(f"Create container with policy {placement_rule}"):
with pytest.raises(Exception, match=NOT_ENOUGH_TO_SELECT):
cid = create_container(
wallet=default_wallet,
rule=placement_rule,
basic_acl=PUBLIC_ACL,
shell=self.shell,
endpoint=endpoint,
)
@pytest.mark.skip(reason="ошибка с фикстурой")
@allure.title("[NEGATIVE] Placement policy: Filter not found")
@pytest.mark.policy
def test_placement_policy_negative_not_enough_nodes_to_filter(self, default_wallet, placement_rule):
def test_placement_policy_negative_not_enough_nodes_to_filter(self, default_wallet):
"""
Negative test for placement policy: Filter not found.
"""
wallet = default_wallet
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"
endpoint = self.cluster.default_rpc_endpoint
with pytest.raises(RuntimeError, match=".*not enough nodes to FILTER from.*"):
cid = create_container(
wallet, rule=placement_rule, basic_acl=PUBLIC_ACL, shell=self.shell, endpoint=endpoint
)
with allure.step(f"Create container with policy {placement_rule}"):
with pytest.raises(Exception, match=NOT_FOUND_FILTER):
cid = create_container(
wallet=default_wallet,
rule=placement_rule,
basic_acl=PUBLIC_ACL,
shell=self.shell,
endpoint=endpoint,
)
@pytest.mark.skip(reason="ошибка с фикстурой")
@allure.title("[NEGATIVE] Placement policy: SELECTOR not found")
@pytest.mark.policy
def test_placement_policy_negative_not_enough_nodes_to_selector(self, default_wallet, placement_rule):
def test_placement_policy_negative_not_enough_nodes_to_selector(self, default_wallet):
"""
Negative test for placement policy: Filter not found.
"""
wallet = default_wallet
placement_rule = "REP 2 IN HALFIC CBF 1 SELECT 2 FROM GT15 AS HALF FILTER Price GT 15 AS GT15"
endpoint = self.cluster.default_rpc_endpoint
with pytest.raises(RuntimeError, match=".*not enough nodes to SELECTOR from.*"):
cid = create_container(
wallet, rule=placement_rule, basic_acl=PUBLIC_ACL, shell=self.shell, endpoint=endpoint
)
with allure.step(f"Create container with policy {placement_rule}"):
with pytest.raises(Exception, match=NOT_FOUND_SELECTOR):
cid = create_container(
wallet=default_wallet,
rule=placement_rule,
basic_acl=PUBLIC_ACL,
shell=self.shell,
endpoint=endpoint,
)
@pytest.mark.policy
@allure.title("Simple policy results with one node")
@ -476,7 +487,7 @@ class TestPolicy(ClusterTestBase):
simple_object_size: ObjectSize,
):
"""
110596 This test checks object's copies based on container's placement policy with SELECT and Complex FILTER results with 25% of available nodes.
This test checks object's copies based on container's placement policy with SELECT and Complex FILTER results with 25% of available nodes.
"""
placement_rule = "REP 1 IN Nodes25 SELECT 1 FROM BET0AND10 AS Nodes25 FILTER Price LE 10 AS LE10 FILTER Price GT 0 AS GT0 FILTER @LE10 AND @GT0 AS BET0AND10"
file_path = generate_file(simple_object_size.value)
@ -821,7 +832,7 @@ class TestPolicy(ClusterTestBase):
simple_object_size: ObjectSize,
):
"""
110606 This test checks object's copies based on container's placement policy with SELECT results with 75% of available nodes.
This test checks object's copies based on container's placement policy with SELECT results with 75% of available nodes.
"""
placement_rule = "REP 2 IN DS CBF 1 SELECT 3 IN DISTINCT Country FROM * AS DS"
file_path = generate_file(simple_object_size.value)
@ -864,7 +875,7 @@ class TestPolicy(ClusterTestBase):
simple_object_size: ObjectSize,
):
"""
110607 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"
file_path = generate_file(simple_object_size.value)
@ -907,7 +918,7 @@ class TestPolicy(ClusterTestBase):
simple_object_size: ObjectSize,
):
"""
110608 This test checks object's copies based on container's placement policy with SELECT and Complex FILTER results with 75% of available nodes.
This test checks object's copies based on container's placement policy with SELECT and Complex FILTER results with 75% of available nodes.
"""
placement_rule = "REP 2 IN NODES75 SELECT 2 FROM LT65 AS NODES75 FILTER Price LT 65 AS LT65"
file_path = generate_file(simple_object_size.value)
@ -950,7 +961,7 @@ class TestPolicy(ClusterTestBase):
simple_object_size: ObjectSize,
):
"""
110608 This test checks object's copies based on container's placement policy with Multi SELECTs and FILTERs results with 75% of available nodes.
This test checks object's copies based on container's placement policy with Multi SELECTs and FILTERs results with 75% of available nodes.
"""
placement_rule = "REP 2 IN EXPNSV REP 2 IN CHEAP SELECT 3 FROM GT10 AS EXPNSV SELECT 3 FROM LT65 AS CHEAP FILTER NOT(Continent EQ America) AS NOAM FILTER @NOAM AND Price LT 65 AS LT65 FILTER @NOAM AND Price GT 10 AS GT10"
file_path = generate_file(simple_object_size.value)