From c0f63e378354f643cccaea2fdf97a15cd7058c95 Mon Sep 17 00:00:00 2001 From: Dmitriy Zayakin Date: Mon, 19 Jun 2023 13:39:35 +0300 Subject: [PATCH] New methods S3 client Signed-off-by: Dmitriy Zayakin --- src/frostfs_testlib/s3/aws_cli_client.py | 4 ++++ src/frostfs_testlib/s3/boto3_client.py | 24 ++++++++++++++++++------ src/frostfs_testlib/s3/interfaces.py | 4 ++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/frostfs_testlib/s3/aws_cli_client.py b/src/frostfs_testlib/s3/aws_cli_client.py index 054a1e8..a9aeb37 100644 --- a/src/frostfs_testlib/s3/aws_cli_client.py +++ b/src/frostfs_testlib/s3/aws_cli_client.py @@ -39,6 +39,10 @@ class AwsCliClient(S3ClientWrapper): except Exception as err: raise RuntimeError("Error while configuring AwsCliClient") from err + @reporter.step_deco("Set endpoint S3 to {s3gate_endpoint}") + def set_endpoint(self, s3gate_endpoint: str): + self.s3gate_endpoint = s3gate_endpoint + @reporter.step_deco("Create bucket S3") def create_bucket( self, diff --git a/src/frostfs_testlib/s3/boto3_client.py b/src/frostfs_testlib/s3/boto3_client.py index 07c693f..6d6fc74 100644 --- a/src/frostfs_testlib/s3/boto3_client.py +++ b/src/frostfs_testlib/s3/boto3_client.py @@ -47,19 +47,31 @@ class Boto3ClientWrapper(S3ClientWrapper): @reporter.step_deco("Configure S3 client (boto3)") @report_error def __init__(self, access_key_id: str, secret_access_key: str, s3gate_endpoint: str) -> None: - session = boto3.Session() - config = Config( + self.boto3_client: S3Client = None + self.session = boto3.Session() + self.config = Config( retries={ "max_attempts": MAX_REQUEST_ATTEMPTS, "mode": RETRY_MODE, } ) + self.access_key_id: str = access_key_id + self.secret_access_key: str = secret_access_key + self.s3gate_endpoint: str = "" + self.set_endpoint(s3gate_endpoint) - self.boto3_client: S3Client = session.client( + @reporter.step_deco("Set endpoint S3 to {s3gate_endpoint}") + def set_endpoint(self, s3gate_endpoint: str): + if self.s3gate_endpoint == s3gate_endpoint: + return + + self.s3gate_endpoint = s3gate_endpoint + + self.boto3_client: S3Client = self.session.client( service_name="s3", - aws_access_key_id=access_key_id, - aws_secret_access_key=secret_access_key, - config=config, + aws_access_key_id=self.access_key_id, + aws_secret_access_key=self.secret_access_key, + config=self.config, endpoint_url=s3gate_endpoint, verify=False, ) diff --git a/src/frostfs_testlib/s3/interfaces.py b/src/frostfs_testlib/s3/interfaces.py index bd1379c..3f31395 100644 --- a/src/frostfs_testlib/s3/interfaces.py +++ b/src/frostfs_testlib/s3/interfaces.py @@ -34,6 +34,10 @@ class S3ClientWrapper(ABC): def __init__(self, access_key_id: str, secret_access_key: str, s3gate_endpoint: str) -> None: pass + @abstractmethod + def set_endpoint(self, s3gate_endpoint: str): + """Set endpoint""" + @abstractmethod def create_bucket( self,