From f0ea6b5895c21d0dbef71ff7aaecac8cde4c46dd Mon Sep 17 00:00:00 2001 From: "a.berezin" Date: Mon, 28 Oct 2024 23:46:38 +0300 Subject: [PATCH] [#315] Use abspath for files Signed-off-by: a.berezin --- __init__.py | 3 ++ pytest_tests/resources/common.py | 3 ++ pytest_tests/testsuites/failovers/__init__.py | 0 .../failovers/test_failover_storage.py | 32 +++++++------------ .../replication/test_ec_replication.py | 6 ++-- .../services/s3_gate/test_s3_policy.py | 6 ++-- 6 files changed, 24 insertions(+), 26 deletions(-) create mode 100644 __init__.py create mode 100644 pytest_tests/testsuites/failovers/__init__.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 00000000..13bd6404 --- /dev/null +++ b/__init__.py @@ -0,0 +1,3 @@ +import os + +TESTS_BASE_PATH = os.path.dirname(os.path.abspath(__file__)) diff --git a/pytest_tests/resources/common.py b/pytest_tests/resources/common.py index ebede363..38cef385 100644 --- a/pytest_tests/resources/common.py +++ b/pytest_tests/resources/common.py @@ -1,5 +1,8 @@ import os +from ... import TESTS_BASE_PATH + TEST_CYCLES_COUNT = int(os.getenv("TEST_CYCLES_COUNT", "1")) DEVENV_PATH = os.getenv("DEVENV_PATH", os.path.join("..", "frostfs-dev-env")) +S3_POLICY_FILE_LOCATION = os.path.join(TESTS_BASE_PATH, "pytest_tests/resources/files/policy.json") diff --git a/pytest_tests/testsuites/failovers/__init__.py b/pytest_tests/testsuites/failovers/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pytest_tests/testsuites/failovers/test_failover_storage.py b/pytest_tests/testsuites/failovers/test_failover_storage.py index 5f9eba51..f99333f8 100644 --- a/pytest_tests/testsuites/failovers/test_failover_storage.py +++ b/pytest_tests/testsuites/failovers/test_failover_storage.py @@ -34,6 +34,8 @@ from frostfs_testlib.utils.failover_utils import wait_object_replication from frostfs_testlib.utils.file_keeper import FileKeeper from frostfs_testlib.utils.file_utils import generate_file, get_file_hash +from ...resources.common import S3_POLICY_FILE_LOCATION + logger = logging.getLogger("NeoLogger") stopped_nodes: list[StorageNode] = [] @@ -95,9 +97,7 @@ class TestFailoverStorage(ClusterTestBase): ) with reporter.step("Check object data is not corrupted"): - got_file_path = get_object( - wallet, cid, oid, endpoint=replicated_nodes[0].get_rpc_endpoint(), shell=self.shell - ) + got_file_path = get_object(wallet, cid, oid, endpoint=replicated_nodes[0].get_rpc_endpoint(), shell=self.shell) assert get_file_hash(source_file_path) == get_file_hash(got_file_path) with reporter.step("Return all hosts"): @@ -105,12 +105,10 @@ class TestFailoverStorage(ClusterTestBase): with reporter.step("Check object data is not corrupted"): replicated_nodes = wait_object_replication(cid, oid, 2, shell=self.shell, nodes=self.cluster.storage_nodes) - got_file_path = get_object( - wallet, cid, oid, shell=self.shell, endpoint=replicated_nodes[0].get_rpc_endpoint() - ) + got_file_path = get_object(wallet, cid, oid, shell=self.shell, endpoint=replicated_nodes[0].get_rpc_endpoint()) assert get_file_hash(source_file_path) == get_file_hash(got_file_path) - @pytest.mark.parametrize("s3_policy", ["pytest_tests/resources/files/policy.json"], indirect=True) + @pytest.mark.parametrize("s3_policy", [S3_POLICY_FILE_LOCATION], indirect=True) @allure.title("Do not ignore unhealthy tree endpoints (s3_client={s3_client})") def test_unhealthy_tree( self, @@ -151,7 +149,7 @@ class TestFailoverStorage(ClusterTestBase): wallet=default_wallet, shell=self.shell, endpoint=self.cluster.storage_nodes[0].get_rpc_endpoint(), - bucket_container_resolver=bucket_container_resolver + bucket_container_resolver=bucket_container_resolver, )[0] with reporter.step("Turn off all storage nodes except bucket node"): @@ -282,9 +280,7 @@ class TestEmptyMap(ClusterTestBase): cluster_state_controller.stop_services_of_type(StorageNode) with reporter.step("Remove all nodes from network map"): - remove_nodes_from_map_morph( - shell=self.shell, cluster=self.cluster, remove_nodes=self.cluster.services(StorageNode) - ) + remove_nodes_from_map_morph(shell=self.shell, cluster=self.cluster, remove_nodes=self.cluster.services(StorageNode)) with reporter.step("Return all storage nodes to network map"): self.return_nodes_after_stop_with_check_empty_map(cluster_state_controller) @@ -465,9 +461,7 @@ class TestStorageDataLoss(ClusterTestBase): s3_client.put_object(bucket, complex_object_path) with reporter.step("Check objects are in bucket"): - s3_helper.check_objects_in_bucket( - s3_client, bucket, expected_objects=[simple_object_key, complex_object_key] - ) + s3_helper.check_objects_in_bucket(s3_client, bucket, expected_objects=[simple_object_key, complex_object_key]) with reporter.step("Stop storage services on all nodes"): cluster_state_controller.stop_services_of_type(StorageNode) @@ -581,17 +575,13 @@ class TestStorageDataLoss(ClusterTestBase): exception_messages.append(f"Shard {shard} changed status to {status}") with reporter.step("No related errors should be in log"): - if node_under_test.host.is_message_in_logs( - message_regex=r"\Wno such file or directory\W", since=test_start_time - ): + if node_under_test.host.is_message_in_logs(message_regex=r"\Wno such file or directory\W", since=test_start_time): exception_messages.append(f"Node {node_under_test} have shard errors in logs") with reporter.step("Pass test if no errors found"): assert not exception_messages, "\n".join(exception_messages) - @allure.title( - "Loss of one node should trigger use of tree and storage service in another node (s3_client={s3_client})" - ) + @allure.title("Loss of one node should trigger use of tree and storage service in another node (s3_client={s3_client})") def test_s3_one_endpoint_loss( self, bucket, @@ -613,7 +603,7 @@ class TestStorageDataLoss(ClusterTestBase): put_object = s3_client.put_object(bucket, file_path) s3_helper.check_objects_in_bucket(s3_client, bucket, expected_objects=[file_name]) - @pytest.mark.parametrize("s3_policy", ["pytest_tests/resources/files/policy.json"], indirect=True) + @pytest.mark.parametrize("s3_policy", [S3_POLICY_FILE_LOCATION], indirect=True) @allure.title("After Pilorama.db loss on one node object is retrievable (s3_client={s3_client})") def test_s3_one_pilorama_loss( self, diff --git a/pytest_tests/testsuites/replication/test_ec_replication.py b/pytest_tests/testsuites/replication/test_ec_replication.py index 21ce932e..0877da59 100644 --- a/pytest_tests/testsuites/replication/test_ec_replication.py +++ b/pytest_tests/testsuites/replication/test_ec_replication.py @@ -22,6 +22,8 @@ from frostfs_testlib.testing.test_control import wait_for_success from frostfs_testlib.utils import datetime_utils from frostfs_testlib.utils.file_utils import generate_file, get_file_hash +from ...resources.common import S3_POLICY_FILE_LOCATION + def pytest_generate_tests(metafunc: pytest.Metafunc) -> None: if "ec_policy" not in metafunc.fixturenames: @@ -678,7 +680,7 @@ class TestECReplication(ClusterTestBase): ) @allure.title("Create bucket with EC policy (s3_client={s3_client})") - @pytest.mark.parametrize("s3_policy, s3_client", [("pytest_tests/resources/files/policy.json", AwsCliClient)], indirect=True) + @pytest.mark.parametrize("s3_policy, s3_client", [(S3_POLICY_FILE_LOCATION, AwsCliClient)], indirect=True) def test_create_bucket_with_ec_location( self, s3_client: S3ClientWrapper, bucket_container_resolver: BucketContainerResolver, grpc_client: GrpcClientWrapper ) -> None: @@ -693,7 +695,7 @@ class TestECReplication(ClusterTestBase): assert container @allure.title("Bucket object count chunks (s3_client={s3_client}, size={object_size})") - @pytest.mark.parametrize("s3_policy, s3_client", [("pytest_tests/resources/files/policy.json", AwsCliClient)], indirect=True) + @pytest.mark.parametrize("s3_policy, s3_client", [(S3_POLICY_FILE_LOCATION, AwsCliClient)], indirect=True) def test_count_chunks_bucket_with_ec_location( self, s3_client: S3ClientWrapper, diff --git a/pytest_tests/testsuites/services/s3_gate/test_s3_policy.py b/pytest_tests/testsuites/services/s3_gate/test_s3_policy.py index 3c6803bb..d5334173 100644 --- a/pytest_tests/testsuites/services/s3_gate/test_s3_policy.py +++ b/pytest_tests/testsuites/services/s3_gate/test_s3_policy.py @@ -1,5 +1,4 @@ import json -import os import allure import pytest @@ -15,10 +14,12 @@ from frostfs_testlib.testing.cluster_test_base import ClusterTestBase from frostfs_testlib.testing.test_control import expect_not_raises from frostfs_testlib.utils.file_utils import generate_file +from ....resources.common import S3_POLICY_FILE_LOCATION + @pytest.mark.nightly @pytest.mark.s3_gate -@pytest.mark.parametrize("s3_policy", ["pytest_tests/resources/files/policy.json"], indirect=True) +@pytest.mark.parametrize("s3_policy", [S3_POLICY_FILE_LOCATION], indirect=True) class TestS3GatePolicy(ClusterTestBase): @allure.title("Bucket creation with retention policy applied (s3_client={s3_client})") def test_s3_bucket_location( @@ -100,7 +101,6 @@ class TestS3GatePolicy(ClusterTestBase): s3_client.get_bucket_policy(bucket) with reporter.step("Put new policy"): - custom_policy = f"file://{os.getcwd()}/pytest_tests/resources/files/bucket_policy.json" custom_policy = { "Version": "2012-10-17", "Id": "aaaa-bbbb-cccc-dddd",