Fix string representation for load params with empty fields
Signed-off-by: Andrey Berezin <a.berezin@yadro.com>
This commit is contained in:
parent
b856e82008
commit
612e088763
3 changed files with 43 additions and 8 deletions
|
@ -316,8 +316,14 @@ class LoadParams:
|
||||||
return fields_with_data or []
|
return fields_with_data or []
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
size, unit = calc_unit(self.object_size, 1)
|
load_type_str = self.scenario.value if self.scenario else self.load_type.value
|
||||||
static_params = [f"{self.scenario.value} ({size:.4g} {unit})"]
|
# TODO: migrate load_params defaults to testlib
|
||||||
|
if self.object_size is not None:
|
||||||
|
size, unit = calc_unit(self.object_size, 1)
|
||||||
|
static_params = [f"{load_type_str} ({size:.4g} {unit})"]
|
||||||
|
else:
|
||||||
|
static_params = [f"{load_type_str}"]
|
||||||
|
|
||||||
dynamic_params = [
|
dynamic_params = [
|
||||||
f"{meta_field.name}={meta_field.value}"
|
f"{meta_field.name}={meta_field.value}"
|
||||||
for meta_field in self._get_applicable_fields()
|
for meta_field in self._get_applicable_fields()
|
||||||
|
|
|
@ -53,10 +53,6 @@ class BackgroundLoadController:
|
||||||
if load_params.endpoint_selection_strategy is None:
|
if load_params.endpoint_selection_strategy is None:
|
||||||
raise RuntimeError("endpoint_selection_strategy should not be None")
|
raise RuntimeError("endpoint_selection_strategy should not be None")
|
||||||
|
|
||||||
self.endpoints = self._get_endpoints(
|
|
||||||
load_params.load_type, load_params.endpoint_selection_strategy
|
|
||||||
)
|
|
||||||
|
|
||||||
@run_optionally(optionals.OPTIONAL_BACKGROUND_LOAD_ENABLED, [])
|
@run_optionally(optionals.OPTIONAL_BACKGROUND_LOAD_ENABLED, [])
|
||||||
def _get_endpoints(
|
def _get_endpoints(
|
||||||
self, load_type: LoadType, endpoint_selection_strategy: EndpointSelectionStrategy
|
self, load_type: LoadType, endpoint_selection_strategy: EndpointSelectionStrategy
|
||||||
|
@ -100,6 +96,9 @@ class BackgroundLoadController:
|
||||||
@run_optionally(optionals.OPTIONAL_BACKGROUND_LOAD_ENABLED)
|
@run_optionally(optionals.OPTIONAL_BACKGROUND_LOAD_ENABLED)
|
||||||
@reporter.step_deco("Prepare load instances")
|
@reporter.step_deco("Prepare load instances")
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
|
self.endpoints = self._get_endpoints(
|
||||||
|
self.load_params.load_type, self.load_params.endpoint_selection_strategy
|
||||||
|
)
|
||||||
self.runner.prepare(self.load_params, self.nodes_under_load, self.k6_dir)
|
self.runner.prepare(self.load_params, self.nodes_under_load, self.k6_dir)
|
||||||
self.runner.init_k6_instances(self.load_params, self.endpoints, self.k6_dir)
|
self.runner.init_k6_instances(self.load_params, self.endpoints, self.k6_dir)
|
||||||
|
|
||||||
|
@ -204,3 +203,9 @@ class BackgroundLoadController:
|
||||||
def _get_results(self) -> dict:
|
def _get_results(self) -> dict:
|
||||||
with reporter.step(f"Get {self.load_params.scenario.value} scenario results"):
|
with reporter.step(f"Get {self.load_params.scenario.value} scenario results"):
|
||||||
return self.runner.get_results()
|
return self.runner.get_results()
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self.load_params.__str__()
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return repr(self.load_params)
|
||||||
|
|
|
@ -3,7 +3,17 @@ from typing import Any, get_args
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from frostfs_testlib.load.load_config import LoadParams, LoadScenario, LoadType, Preset
|
from frostfs_testlib.load.load_config import (
|
||||||
|
EndpointSelectionStrategy,
|
||||||
|
LoadParams,
|
||||||
|
LoadScenario,
|
||||||
|
LoadType,
|
||||||
|
Preset,
|
||||||
|
)
|
||||||
|
from frostfs_testlib.storage.cluster import ClusterNode
|
||||||
|
from frostfs_testlib.storage.controllers.background_load_controller import BackgroundLoadController
|
||||||
|
from frostfs_testlib.storage.dataclasses.frostfs_services import StorageNode
|
||||||
|
from frostfs_testlib.storage.dataclasses.node_base import NodeBase
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -36,7 +46,10 @@ class TestLoadConfig:
|
||||||
return self._get_filled_load_params(load_type, load_scenario, set_empty)
|
return self._get_filled_load_params(load_type, load_scenario, set_empty)
|
||||||
|
|
||||||
def test_load_params_only_load_type_required(self):
|
def test_load_params_only_load_type_required(self):
|
||||||
LoadParams(load_type=LoadType.S3)
|
load_params = LoadParams(load_type=LoadType.S3)
|
||||||
|
expected = "load: s3"
|
||||||
|
assert repr(load_params) == expected
|
||||||
|
assert f"{load_params}" == expected
|
||||||
|
|
||||||
def test_load_params_initially_have_all_values_none(self):
|
def test_load_params_initially_have_all_values_none(self):
|
||||||
load_params = LoadParams(load_type=LoadType.S3)
|
load_params = LoadParams(load_type=LoadType.S3)
|
||||||
|
@ -60,6 +73,17 @@ class TestLoadConfig:
|
||||||
assert f"{load_params}" == expected
|
assert f"{load_params}" == expected
|
||||||
assert repr(load_params) == expected
|
assert repr(load_params) == expected
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("load_params", [LoadScenario.gRPC], indirect=True)
|
||||||
|
def test_load_controller_string_representation(self, load_params: LoadParams):
|
||||||
|
load_params.endpoint_selection_strategy = EndpointSelectionStrategy.ALL
|
||||||
|
load_params.object_size = 512
|
||||||
|
background_load_controller = BackgroundLoadController(
|
||||||
|
"tmp", load_params, "wallet", None, None
|
||||||
|
)
|
||||||
|
expected = "load: grpc (512 KiB), writers=7, readers=7, deleters=8"
|
||||||
|
assert f"{background_load_controller}" == expected
|
||||||
|
assert repr(background_load_controller) == expected
|
||||||
|
|
||||||
def test_load_set_id_changes_fields(self):
|
def test_load_set_id_changes_fields(self):
|
||||||
load_params = LoadParams(load_type=LoadType.S3)
|
load_params = LoadParams(load_type=LoadType.S3)
|
||||||
load_params.preset = Preset()
|
load_params.preset = Preset()
|
||||||
|
|
Loading…
Reference in a new issue