Skip to content

Commit 734696f

Browse files
committed
test: refactor baseline loading into a common function
Besides the refactor there is one behavior change. The function can return an empty baseline if there isn't an existing instance/CPU, where the previous implementations raised an exception. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent abd5757 commit 734696f

File tree

6 files changed

+24
-64
lines changed

6 files changed

+24
-64
lines changed

tests/framework/stats/baseline.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"""Module for common statistic tests baselines providers."""
44

55
from abc import ABC, abstractmethod
6+
from collections import defaultdict
67

8+
from framework.properties import global_props
79
from framework.utils import DictQuery
810

911

@@ -21,3 +23,15 @@ def get(self, ms_name: str, st_name: str) -> dict:
2123
2224
...combination.
2325
"""
26+
27+
def read_baseline(self, data: dict):
28+
"""
29+
Read baseline data from a dictionary
30+
"""
31+
baselines = defaultdict(dict)
32+
for instance, cpus in data["hosts"]["instances"].items():
33+
for cpu in cpus["cpus"]:
34+
cpu_model = cpu["model"]
35+
for baseline, val in cpu["baselines"].items():
36+
baselines[instance, cpu_model][baseline] = val
37+
return baselines.get((global_props.instance, global_props.cpu_model))

tests/integration_tests/performance/test_block_performance.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
get_kernel_version,
2222
run_cmd,
2323
)
24-
from framework.utils_cpuid import get_cpu_model_name, get_instance_type
2524
from integration_tests.performance.configs import defs
2625

2726
TEST_ID = "block_performance"
@@ -45,18 +44,8 @@ class BlockBaselinesProvider(BaselineProvider):
4544

4645
def __init__(self, env_id, fio_id):
4746
"""Block baseline provider initialization."""
48-
cpu_model_name = get_cpu_model_name()
49-
baselines = list(
50-
filter(
51-
lambda cpu_baseline: cpu_baseline["model"] == cpu_model_name,
52-
CONFIG["hosts"]["instances"][get_instance_type()]["cpus"],
53-
)
54-
)
55-
56-
super().__init__(DictQuery({}))
57-
if len(baselines) > 0:
58-
super().__init__(DictQuery(baselines[0]))
59-
47+
baseline = self.read_baseline(CONFIG)
48+
super().__init__(DictQuery(baseline))
6049
self._tag = "baselines/{}/" + env_id + "/{}/" + fio_id
6150

6251
def get(self, ms_name: str, st_name: str) -> dict:

tests/integration_tests/performance/test_network_latency.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from framework.stats.baseline import Provider as BaselineProvider
1414
from framework.stats.metadata import DictProvider as DictMetadataProvider
1515
from framework.utils import CpuMap, DictQuery, get_kernel_version
16-
from framework.utils_cpuid import get_cpu_model_name, get_instance_type
1716
from integration_tests.performance.configs import defs
1817

1918
TEST_ID = "network_latency"
@@ -36,18 +35,8 @@ class NetLatencyBaselineProvider(BaselineProvider):
3635

3736
def __init__(self, env_id):
3837
"""Network latency baseline provider initialization."""
39-
cpu_model_name = get_cpu_model_name()
40-
baselines = list(
41-
filter(
42-
lambda cpu_baseline: cpu_baseline["model"] == cpu_model_name,
43-
CONFIG_DICT["hosts"]["instances"][get_instance_type()]["cpus"],
44-
)
45-
)
46-
47-
super().__init__(DictQuery({}))
48-
if len(baselines) > 0:
49-
super().__init__(DictQuery(baselines[0]))
50-
38+
baseline = self.read_baseline(CONFIG_DICT)
39+
super().__init__(DictQuery(baseline))
5140
self._tag = "baselines/{}/" + env_id + "/{}/ping"
5241

5342
def get(self, ms_name: str, st_name: str) -> dict:

tests/integration_tests/performance/test_network_tcp_throughput.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
get_kernel_version,
2222
run_cmd,
2323
)
24-
from framework.utils_cpuid import get_cpu_model_name, get_instance_type
2524
from integration_tests.performance.configs import defs
2625

2726
TEST_ID = "network_tcp_throughput"
@@ -56,18 +55,8 @@ class NetTCPThroughputBaselineProvider(BaselineProvider):
5655

5756
def __init__(self, env_id, iperf_id):
5857
"""Network TCP throughput baseline provider initialization."""
59-
cpu_model_name = get_cpu_model_name()
60-
baselines = list(
61-
filter(
62-
lambda cpu_baseline: cpu_baseline["model"] == cpu_model_name,
63-
CONFIG_DICT["hosts"]["instances"][get_instance_type()]["cpus"],
64-
)
65-
)
66-
67-
super().__init__(DictQuery({}))
68-
if len(baselines) > 0:
69-
super().__init__(DictQuery(baselines[0]))
70-
58+
baseline = self.read_baseline(CONFIG_DICT)
59+
super().__init__(DictQuery(baseline))
7160
self._tag = "baselines/{}/" + env_id + "/{}/" + iperf_id
7261

7362
def get(self, ms_name: str, st_name: str) -> dict:

tests/integration_tests/performance/test_snapshot_restore_performance.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from framework.stats.baseline import Provider as BaselineProvider
1717
from framework.stats.metadata import DictProvider as DictMetadataProvider
1818
from framework.utils import DictQuery, get_kernel_version
19-
from framework.utils_cpuid import get_cpu_model_name, get_instance_type
2019
from integration_tests.performance.configs import defs
2120

2221
TEST_ID = "snapshot_restore_performance"
@@ -44,18 +43,8 @@ class SnapRestoreBaselinesProvider(BaselineProvider):
4443

4544
def __init__(self, env_id, workload):
4645
"""Snapshot baseline provider initialization."""
47-
cpu_model_name = get_cpu_model_name()
48-
baselines = list(
49-
filter(
50-
lambda cpu_baseline: cpu_baseline["model"] == cpu_model_name,
51-
CONFIG_DICT["hosts"]["instances"][get_instance_type()]["cpus"],
52-
)
53-
)
54-
55-
super().__init__(DictQuery({}))
56-
if len(baselines) > 0:
57-
super().__init__(DictQuery(baselines[0]))
58-
46+
baseline = self.read_baseline(CONFIG_DICT)
47+
super().__init__(DictQuery(baseline))
5948
self._tag = "baselines/{}/" + env_id + "/{}/" + workload
6049

6150
def get(self, ms_name: str, st_name: str) -> dict:

tests/integration_tests/performance/test_vsock_throughput.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
get_kernel_version,
2121
run_cmd,
2222
)
23-
from framework.utils_cpuid import get_cpu_model_name, get_instance_type
2423
from framework.utils_vsock import VSOCK_UDS_PATH, make_host_port_path
2524
from integration_tests.performance.configs import defs
2625

@@ -55,17 +54,8 @@ class VsockThroughputBaselineProvider(BaselineProvider):
5554

5655
def __init__(self, env_id, iperf_id):
5756
"""Vsock throughput baseline provider initialization."""
58-
cpu_model_name = get_cpu_model_name()
59-
baselines = list(
60-
filter(
61-
lambda cpu_baseline: cpu_baseline["model"] == cpu_model_name,
62-
CONFIG_DICT["hosts"]["instances"][get_instance_type()]["cpus"],
63-
)
64-
)
65-
super().__init__(DictQuery({}))
66-
if len(baselines) > 0:
67-
super().__init__(DictQuery(baselines[0]))
68-
57+
baseline = self.read_baseline(CONFIG_DICT)
58+
super().__init__(DictQuery(baseline))
6959
self._tag = "baselines/{}/" + env_id + "/{}/" + iperf_id
7060

7161
def get(self, ms_name: str, st_name: str) -> dict:

0 commit comments

Comments
 (0)