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,