forked from TrueCloudLab/frostfs-testlib
Compare commits
6 commits
fix-delete
...
master
Author | SHA1 | Date | |
---|---|---|---|
9ad620121e | |||
aab4d4f657 | |||
80226ee0a8 | |||
d38808a1f5 | |||
c4ab14fce8 | |||
c8eec11906 |
8 changed files with 98 additions and 11 deletions
|
@ -28,7 +28,7 @@ dependencies = [
|
|||
"pytest==7.1.2",
|
||||
"tenacity==8.0.1",
|
||||
"boto3==1.35.30",
|
||||
"boto3-stubs[essential]==1.35.30",
|
||||
"boto3-stubs[s3,iam,sts]==1.35.30",
|
||||
]
|
||||
requires-python = ">=3.10"
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ testrail-api==1.12.0
|
|||
tenacity==8.0.1
|
||||
pytest==7.1.2
|
||||
boto3==1.35.30
|
||||
boto3-stubs[essential]==1.35.30
|
||||
boto3-stubs[s3,iam,sts]==1.35.30
|
||||
pydantic==2.10.6
|
||||
|
||||
# Dev dependencies
|
||||
|
@ -22,4 +22,4 @@ pylint==2.17.4
|
|||
# Packaging dependencies
|
||||
build==0.8.0
|
||||
setuptools==65.3.0
|
||||
twine==4.0.1
|
||||
twine==4.0.1
|
|
@ -15,14 +15,14 @@ LOGGING_CONFIG = {
|
|||
"handlers": {"default": {"class": "logging.StreamHandler", "formatter": "http", "stream": "ext://sys.stderr"}},
|
||||
"formatters": {
|
||||
"http": {
|
||||
"format": "%(levelname)s [%(asctime)s] %(name)s - %(message)s",
|
||||
"format": "%(asctime)s [%(levelname)s] %(name)s - %(message)s",
|
||||
"datefmt": "%Y-%m-%d %H:%M:%S",
|
||||
}
|
||||
},
|
||||
"loggers": {
|
||||
"httpx": {
|
||||
"handlers": ["default"],
|
||||
"level": "DEBUG",
|
||||
"level": "ERROR",
|
||||
},
|
||||
"httpcore": {
|
||||
"handlers": ["default"],
|
||||
|
@ -43,7 +43,7 @@ class HttpClient:
|
|||
response = client.request(method, url, **kwargs)
|
||||
|
||||
self._attach_response(response, **kwargs)
|
||||
logger.info(f"Response: {response.status_code} => {response.text}")
|
||||
# logger.info(f"Response: {response.status_code} => {response.text}")
|
||||
|
||||
if expected_status_code:
|
||||
assert (
|
||||
|
@ -131,6 +131,7 @@ class HttpClient:
|
|||
|
||||
reporter.attach(report, "Requests Info")
|
||||
reporter.attach(curl_request, "CURL")
|
||||
cls._write_log(curl_request, response_body, response.status_code)
|
||||
|
||||
@classmethod
|
||||
def _create_curl_request(cls, url: str, method: str, headers: httpx.Headers, data: str, files: dict) -> str:
|
||||
|
@ -143,3 +144,9 @@ class HttpClient:
|
|||
|
||||
# Option -k means no verify SSL
|
||||
return f"curl {url} -X {method} {headers}{data} -k"
|
||||
|
||||
@classmethod
|
||||
def _write_log(cls, curl: str, res_body: str, res_code: int) -> None:
|
||||
if res_body:
|
||||
curl += f"\nResponse: {res_code}\n{res_body}"
|
||||
logger.info(f"{curl}")
|
||||
|
|
|
@ -959,6 +959,15 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return json_output
|
||||
|
||||
@reporter.step("Create presign url for the object")
|
||||
def create_presign_url(self, method: str, bucket: str, key: str, expires_in: Optional[int] = 3600) -> str:
|
||||
# AWS CLI does not support method definition and world only in 'get_object' state by default
|
||||
cmd = f"aws {self.common_flags} s3 presign s3://{bucket}/{key} " f"--endpoint-url {self.s3gate_endpoint} --profile {self.profile}"
|
||||
if expires_in:
|
||||
cmd += f" --expires-in {expires_in}"
|
||||
response = self.local_shell.exec(cmd).stdout
|
||||
return response.strip()
|
||||
|
||||
# IAM METHODS #
|
||||
# Some methods don't have checks because AWS is silent in some cases (delete, attach, etc.)
|
||||
|
||||
|
|
|
@ -10,7 +10,9 @@ import boto3
|
|||
import urllib3
|
||||
from botocore.config import Config
|
||||
from botocore.exceptions import ClientError
|
||||
from mypy_boto3_iam import IAMClient
|
||||
from mypy_boto3_s3 import S3Client
|
||||
from mypy_boto3_sts import STSClient
|
||||
|
||||
from frostfs_testlib import reporter
|
||||
from frostfs_testlib.clients.s3.interfaces import S3ClientWrapper, VersioningStatus, _make_objs_dict
|
||||
|
@ -39,8 +41,8 @@ class Boto3ClientWrapper(S3ClientWrapper):
|
|||
self.boto3_client: S3Client = None
|
||||
|
||||
self.iam_endpoint: str = ""
|
||||
self.boto3_iam_client: S3Client = None
|
||||
self.boto3_sts_client: S3Client = None
|
||||
self.boto3_iam_client: IAMClient = None
|
||||
self.boto3_sts_client: STSClient = None
|
||||
|
||||
self.access_key_id = access_key_id
|
||||
self.secret_access_key = secret_access_key
|
||||
|
@ -48,7 +50,13 @@ class Boto3ClientWrapper(S3ClientWrapper):
|
|||
self.region = region
|
||||
|
||||
self.session = boto3.Session()
|
||||
self.config = Config(retries={"max_attempts": MAX_REQUEST_ATTEMPTS, "mode": RETRY_MODE})
|
||||
self.config = Config(
|
||||
signature_version="s3v4",
|
||||
retries={
|
||||
"max_attempts": MAX_REQUEST_ATTEMPTS,
|
||||
"mode": RETRY_MODE,
|
||||
},
|
||||
)
|
||||
|
||||
self.set_endpoint(s3gate_endpoint)
|
||||
|
||||
|
@ -90,6 +98,7 @@ class Boto3ClientWrapper(S3ClientWrapper):
|
|||
aws_access_key_id=self.access_key_id,
|
||||
aws_secret_access_key=self.secret_access_key,
|
||||
endpoint_url=iam_endpoint,
|
||||
region_name=self.region,
|
||||
verify=False,
|
||||
)
|
||||
|
||||
|
@ -812,6 +821,16 @@ class Boto3ClientWrapper(S3ClientWrapper):
|
|||
) -> dict:
|
||||
raise NotImplementedError("Cp is not supported for boto3 client")
|
||||
|
||||
@reporter.step("Create presign url for the object")
|
||||
def create_presign_url(self, method: str, bucket: str, key: str, expires_in: Optional[int] = 3600) -> str:
|
||||
response = self._exec_request(
|
||||
method=self.boto3_client.generate_presigned_url,
|
||||
params={"ClientMethod": method, "Params": {"Bucket": bucket, "Key": key}, "ExpiresIn": expires_in},
|
||||
endpoint=self.s3gate_endpoint,
|
||||
profile=self.profile,
|
||||
)
|
||||
return response
|
||||
|
||||
# END OBJECT METHODS #
|
||||
|
||||
# IAM METHODS #
|
||||
|
|
|
@ -425,6 +425,10 @@ class S3ClientWrapper(HumanReadableABC):
|
|||
) -> dict:
|
||||
"""cp directory TODO: Add proper description"""
|
||||
|
||||
@abstractmethod
|
||||
def create_presign_url(self, method: str, bucket: str, key: str, expires_in: Optional[int] = 3600) -> str:
|
||||
"""Creates presign URL"""
|
||||
|
||||
# END OF OBJECT METHODS #
|
||||
|
||||
# IAM METHODS #
|
||||
|
|
|
@ -33,6 +33,7 @@ def get_via_http_gate(
|
|||
oid: str,
|
||||
node: ClusterNode,
|
||||
request_path: Optional[str] = None,
|
||||
presigned_url: Optional[str] = None,
|
||||
timeout: Optional[int] = 300,
|
||||
):
|
||||
"""
|
||||
|
@ -47,6 +48,9 @@ def get_via_http_gate(
|
|||
if request_path:
|
||||
request = f"{node.http_gate.get_endpoint()}{request_path}"
|
||||
|
||||
if presigned_url:
|
||||
request = presigned_url
|
||||
|
||||
response = requests.get(request, stream=True, timeout=timeout, verify=False)
|
||||
|
||||
if not response.ok:
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
import time
|
||||
from functools import wraps
|
||||
from typing import Callable
|
||||
|
||||
import pytest
|
||||
|
||||
from frostfs_testlib.hosting import Host
|
||||
from frostfs_testlib.shell.interfaces import CommandResult
|
||||
|
||||
|
@ -7,11 +13,11 @@ class Metrics:
|
|||
self.storage = StorageMetrics(host, metrics_endpoint)
|
||||
|
||||
|
||||
|
||||
class StorageMetrics:
|
||||
"""
|
||||
Class represents storage metrics in a cluster
|
||||
"""
|
||||
|
||||
def __init__(self, host: Host, metrics_endpoint: str) -> None:
|
||||
self.host = host
|
||||
self.metrics_endpoint = metrics_endpoint
|
||||
|
@ -29,8 +35,46 @@ class StorageMetrics:
|
|||
additional_greps = " |grep ".join([grep_command for grep_command in greps.values()])
|
||||
result = shell.exec(f"curl -s {self.metrics_endpoint} | grep {additional_greps}")
|
||||
return result
|
||||
|
||||
|
||||
def get_all_metrics(self) -> CommandResult:
|
||||
shell = self.host.get_shell()
|
||||
result = shell.exec(f"curl -s {self.metrics_endpoint}")
|
||||
return result
|
||||
|
||||
|
||||
def wait_until_metric_result_is_stable(
|
||||
relative_deviation: float = None, absolute_deviation: int = None, max_attempts: int = 10, sleep_interval: int = 30
|
||||
):
|
||||
"""
|
||||
A decorator function that repeatedly calls the decorated function until its result stabilizes
|
||||
within a specified relative tolerance or until the maximum number of attempts is reached.
|
||||
|
||||
This decorator is useful for scenarios where a function returns a metric or value that may fluctuate
|
||||
over time, and you want to ensure that the result has stabilized before proceeding.
|
||||
"""
|
||||
|
||||
def decorator(func: Callable):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
last_result = None
|
||||
for _ in range(max_attempts):
|
||||
# first function call
|
||||
first_result = func(*args, **kwargs)
|
||||
|
||||
# waiting before the second call
|
||||
time.sleep(sleep_interval)
|
||||
|
||||
# second function call
|
||||
last_result = func(*args, **kwargs)
|
||||
|
||||
# checking value stability
|
||||
if first_result == pytest.approx(last_result, rel=relative_deviation, abs=absolute_deviation):
|
||||
return last_result
|
||||
|
||||
# if stability is not achieved, return the last value
|
||||
if last_result is not None:
|
||||
return last_result
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
|
Loading…
Add table
Reference in a new issue