From 5f87d0e0e29df5ad5a2a339d1de05a13f73e53c5 Mon Sep 17 00:00:00 2001 From: Evgeniy Zayats Date: Thu, 12 Sep 2024 23:14:20 -0400 Subject: [PATCH] Enable parallel test runs closes #710 Signed-off-by: Evgeniy Zayats --- .github/workflows/run-tests.yml | 2 +- .gitignore | 2 +- pytest_tests/lib/helpers/aws_cli_client.py | 12 ++++++------ pytest_tests/lib/helpers/common.py | 3 ++- pytest_tests/lib/helpers/rest_gate.py | 4 +--- pytest_tests/lib/s3/s3_gate_base.py | 12 ++++++++++-- pytest_tests/lib/s3/s3_gate_object.py | 3 +-- requirements.txt | 1 + 8 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 8dc960ade..b8a4335e1 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -237,7 +237,7 @@ jobs: env: ALLURE_RESULTS_DIR: ${{ env.ALLURE_RESULTS_DIR }} run: | - source venv.pytest/bin/activate && pytest --log-cli-level error --alluredir=${GITHUB_WORKSPACE}/allure-results pytest_tests/tests + source venv.pytest/bin/activate && pytest -n 3 --log-cli-level error --alluredir=${GITHUB_WORKSPACE}/allure-results pytest_tests/tests working-directory: neofs-testcases ################################################################ diff --git a/.gitignore b/.gitignore index d36e2b95c..9fb519a0f 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,7 @@ xunit_results.xml # ignore work directories and setup files .setup .env -TemporaryDir/* +TemporaryDir-/* artifacts/* docs/* venv.*/* diff --git a/pytest_tests/lib/helpers/aws_cli_client.py b/pytest_tests/lib/helpers/aws_cli_client.py index 9b4371c07..f760f0322 100644 --- a/pytest_tests/lib/helpers/aws_cli_client.py +++ b/pytest_tests/lib/helpers/aws_cli_client.py @@ -14,13 +14,13 @@ class AwsCliClient: - # Flags that we use for all S3 commands: disable SSL verification (as we use self-signed - # certificate in devenv) and disable automatic pagination in CLI output - common_flags = "--no-verify-ssl --no-paginate" - s3gate_endpoint: str - - def __init__(self, s3gate_endpoint) -> None: + def __init__(self, s3gate_endpoint, profile="") -> None: self.s3gate_endpoint = s3gate_endpoint + # Flags that we use for all S3 commands: disable SSL verification (as we use self-signed + # certificate in devenv) and disable automatic pagination in CLI output + self.common_flags = "--no-verify-ssl --no-paginate" + if profile != "": + self.common_flags += f" --profile {profile}" os.environ["AWS_EC2_METADATA_DISABLED"] = "true" def create_bucket( diff --git a/pytest_tests/lib/helpers/common.py b/pytest_tests/lib/helpers/common.py index 03b8eda76..f8cf16351 100644 --- a/pytest_tests/lib/helpers/common.py +++ b/pytest_tests/lib/helpers/common.py @@ -1,4 +1,5 @@ import os +import uuid import yaml @@ -22,7 +23,7 @@ NEOFS_CONTRACT = os.getenv("NEOFS_IR_CONTRACTS_NEOFS") -ASSETS_DIR = os.getenv("ASSETS_DIR", "TemporaryDir") +ASSETS_DIR = f"TemporaryDir-{uuid.uuid4()}" TEST_FILES_DIR = os.getenv("TEST_FILES_DIR", "TestFilesDir") TEST_OBJECTS_DIR = os.getenv("TEST_OBJECTS_DIR", "TestObjectsDir") DEVENV_PATH = os.getenv("DEVENV_PATH", os.path.join("..", "neofs-dev-env")) diff --git a/pytest_tests/lib/helpers/rest_gate.py b/pytest_tests/lib/helpers/rest_gate.py index b5437229b..0b46fd315 100644 --- a/pytest_tests/lib/helpers/rest_gate.py +++ b/pytest_tests/lib/helpers/rest_gate.py @@ -12,7 +12,7 @@ import requests from helpers.aws_cli_client import LONG_TIMEOUT from helpers.cli_helpers import _cmd_run -from helpers.common import SIMPLE_OBJECT_SIZE +from helpers.common import ASSETS_DIR, SIMPLE_OBJECT_SIZE from helpers.complex_object_actions import get_nodes_without_object from helpers.file_helper import get_file_hash from helpers.neofs_verbs import get_object @@ -20,8 +20,6 @@ logger = logging.getLogger("NeoLogger") -ASSETS_DIR = os.getenv("ASSETS_DIR", "TemporaryDir/") - @allure.step("Get via REST Gate") def get_via_rest_gate( diff --git a/pytest_tests/lib/s3/s3_gate_base.py b/pytest_tests/lib/s3/s3_gate_base.py index b52cc6c41..b5481fd9c 100644 --- a/pytest_tests/lib/s3/s3_gate_base.py +++ b/pytest_tests/lib/s3/s3_gate_base.py @@ -1,7 +1,9 @@ import json import logging import os +import random import re +import string import sys import uuid from typing import Any, Optional @@ -201,8 +203,9 @@ def configure_boto3_client(access_key_id: str, secret_access_key: str, s3gate_en @allure.step("Configure S3 client (aws cli)") def configure_cli_client(access_key_id: str, secret_access_key: str, s3gate_endpoint: str): try: - client = AwsCliClient(s3gate_endpoint) - _configure_aws_cli("aws configure", access_key_id, secret_access_key) + profile = _generate_random_profile() + client = AwsCliClient(s3gate_endpoint, profile) + _configure_aws_cli(f"aws configure --profile {profile}", access_key_id, secret_access_key) _cmd_run(f"aws configure set max_attempts {MAX_REQUEST_ATTEMPTS}") _cmd_run(f"aws configure set retry_mode {RETRY_MODE}") return client @@ -211,3 +214,8 @@ def configure_cli_client(access_key_id: str, secret_access_key: str, s3gate_endp pytest.skip("AWS CLI was not found") else: raise RuntimeError("Error while configuring AwsCliClient") from err + + +def _generate_random_profile(): + random_postfix = "".join(random.choice(string.ascii_letters + string.digits) for _ in range(10)) + return f"profile__{random_postfix}" diff --git a/pytest_tests/lib/s3/s3_gate_object.py b/pytest_tests/lib/s3/s3_gate_object.py index 09e8a648d..8d7f0df90 100644 --- a/pytest_tests/lib/s3/s3_gate_object.py +++ b/pytest_tests/lib/s3/s3_gate_object.py @@ -9,6 +9,7 @@ from botocore.exceptions import ClientError from helpers.aws_cli_client import AwsCliClient from helpers.cli_helpers import log_command_execution +from helpers.common import ASSETS_DIR from s3.s3_gate_bucket import S3_SYNC_WAIT_TIME ########################################################## @@ -28,8 +29,6 @@ "bucket-owner-full-control", ] -ASSETS_DIR = os.getenv("ASSETS_DIR", "TemporaryDir/") - @allure.step("List objects S3 v2") def list_objects_s3_v2(s3_client, bucket: str, full_output: bool = False) -> list: diff --git a/requirements.txt b/requirements.txt index 35096b747..8c2cd761e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,3 +19,4 @@ requests==2.32.0 tenacity==8.2.3 ruff==0.4.2 urllib3==2.2.2 +pytest-xdist==3.6.1 \ No newline at end of file