forked from TrueCloudLab/frostfs-testlib
[#156] load_time in the format of days, hours and minutes; new params
Signed-off-by: Liza <e.chichindaeva@yadro.com>
This commit is contained in:
parent
d6a2cf92a2
commit
df8d99d83c
2 changed files with 131 additions and 2 deletions
|
@ -3,11 +3,28 @@ import os
|
|||
from dataclasses import dataclass, field, fields, is_dataclass
|
||||
from enum import Enum
|
||||
from types import MappingProxyType
|
||||
from typing import Any, Optional, get_args
|
||||
from typing import Any, Callable, Optional, get_args
|
||||
|
||||
from frostfs_testlib.utils.converting_utils import calc_unit
|
||||
|
||||
|
||||
def convert_time_to_seconds(time: int | str | None) -> int:
|
||||
if time is None:
|
||||
return None
|
||||
if str(time).isdigit():
|
||||
seconds = int(time)
|
||||
else:
|
||||
days, hours, minutes = 0, 0, 0
|
||||
if "d" in time:
|
||||
days, time = time.split("d")
|
||||
if "h" in time:
|
||||
hours, time = time.split("h")
|
||||
if "min" in time:
|
||||
minutes = time.replace("min", "")
|
||||
seconds = int(days) * 86400 + int(hours) * 3600 + int(minutes) * 60
|
||||
return seconds
|
||||
|
||||
|
||||
class LoadType(Enum):
|
||||
gRPC = "grpc"
|
||||
S3 = "s3"
|
||||
|
@ -76,6 +93,7 @@ def metadata_field(
|
|||
scenario_variable: Optional[str] = None,
|
||||
string_repr: Optional[bool] = True,
|
||||
distributed: Optional[bool] = False,
|
||||
formatter: Optional[Callable] = None,
|
||||
):
|
||||
return field(
|
||||
default=None,
|
||||
|
@ -85,6 +103,7 @@ def metadata_field(
|
|||
"env_variable": scenario_variable,
|
||||
"string_repr": string_repr,
|
||||
"distributed": distributed,
|
||||
"formatter": formatter,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -200,7 +219,9 @@ class LoadParams:
|
|||
|
||||
# ------- COMMON SCENARIO PARAMS -------
|
||||
# Load time is the maximum duration for k6 to give load. Default is the BACKGROUND_LOAD_DEFAULT_TIME value.
|
||||
load_time: Optional[int] = metadata_field(all_load_scenarios, None, "DURATION", False)
|
||||
load_time: Optional[int] = metadata_field(
|
||||
all_load_scenarios, None, "DURATION", False, formatter=convert_time_to_seconds
|
||||
)
|
||||
# Object size in KB for load and preset.
|
||||
object_size: Optional[int] = metadata_field(all_load_scenarios, "size", "WRITE_OBJ_SIZE", False)
|
||||
# For read operations, controls from which set get objects to read
|
||||
|
@ -384,6 +405,25 @@ class LoadParams:
|
|||
|
||||
return fields_with_data or []
|
||||
|
||||
def _get_field_formatter(self, field_name: str) -> Callable | None:
|
||||
data_fields = fields(self)
|
||||
formatters = [
|
||||
field.metadata["formatter"]
|
||||
for field in data_fields
|
||||
if field.name == field_name and "formatter" in field.metadata and field.metadata["formatter"] != None
|
||||
]
|
||||
if formatters:
|
||||
return formatters[0]
|
||||
|
||||
return None
|
||||
|
||||
def __setattr__(self, field_name, value):
|
||||
formatter = self._get_field_formatter(field_name)
|
||||
if formatter:
|
||||
value = formatter(value)
|
||||
|
||||
super().__setattr__(field_name, value)
|
||||
|
||||
def __str__(self) -> str:
|
||||
load_type_str = self.scenario.value if self.scenario else self.load_type.value
|
||||
# TODO: migrate load_params defaults to testlib
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue