Skip to content

Commit 577eff2

Browse files
feat(disk_perf): add support of uri for previous csv file
- style(disk_perf): sort imports and minor style fixes Signed-off-by: Mathieu Labourier <[email protected]>
1 parent f43d5eb commit 577eff2

File tree

3 files changed

+66
-57
lines changed

3 files changed

+66
-57
lines changed

tests/storage/benchmarks/conftest.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
1-
import pytest
2-
import tempfile
3-
import os
41
import logging
2+
import os
3+
import tempfile
4+
import urllib.request
5+
from urllib.parse import urlparse
6+
from uuid import uuid4
7+
8+
import pytest
59

610
from lib.commands import SSHCommandFailed
11+
712
from .helpers import load_results_from_csv
813

9-
MAX_LENGTH = 64 * (1024**3) # 64GiB
14+
MAX_LENGTH = 64 * (1024**3) # 64GiB
15+
1016

1117
# use vhd, qcow2, raw... when image_format support will be available
12-
@pytest.fixture(scope="module", params=['vdi'])
18+
@pytest.fixture(scope="module", params=["vdi"])
1319
def image_format(request):
1420
return request.param
1521

22+
1623
@pytest.fixture(scope="module")
1724
def running_unix_vm_with_fio(running_unix_vm):
1825
vm = running_unix_vm
1926
install_cmds = (
2027
("command -v apt", "apt update && apt install -y fio", "apt remove -y fio"),
2128
("command -v dnf", "dnf install -y fio", "dnf remove -y fio"),
2229
("command -v yum", "yum install -y fio", "yum remove -y fio"),
23-
("command -v apk", "apk add fio", "apk del fio")
30+
("command -v apk", "apk add fio", "apk del fio"),
2431
)
2532

2633
for check_cmd, install_cmd, remove in install_cmds:
@@ -55,6 +62,7 @@ def vdi_on_local_sr(host, local_sr_on_hostA1, image_format):
5562
logging.info(f"<< Destroying VDI {vdi.uuid}")
5663
vdi.destroy()
5764

65+
5866
@pytest.fixture(scope="module")
5967
def plugged_vbd(vdi_on_local_sr, running_unix_vm_with_fio):
6068
vm = running_unix_vm_with_fio
@@ -71,11 +79,13 @@ def plugged_vbd(vdi_on_local_sr, running_unix_vm_with_fio):
7179
vbd.unplug()
7280
vbd.destroy()
7381

82+
7483
@pytest.fixture(scope="module")
7584
def local_temp_dir():
7685
with tempfile.TemporaryDirectory() as tmpdir:
7786
yield tmpdir
7887

88+
7989
@pytest.fixture(scope="module")
8090
def temp_dir(running_unix_vm_with_fio):
8191
vm = running_unix_vm_with_fio
@@ -92,13 +102,19 @@ def pytest_addoption(parser):
92102
"--prev-csv",
93103
action="store",
94104
default=None,
95-
help="Path to previous CSV results file for comparison",
105+
help="Path/URI to previous CSV results file for comparison",
96106
)
97107

108+
98109
@pytest.fixture(scope="session")
99-
def prev_results(request):
100-
csv_path = request.config.getoption("--prev-csv")
101-
results = {}
102-
if csv_path and os.path.exists(csv_path):
103-
load_results_from_csv(csv_path)
104-
return results
110+
def prev_results(pytestconfig):
111+
csv_uri = pytestconfig.getoption("--prev-csv")
112+
if not csv_uri:
113+
return {}
114+
csv_path = csv_uri
115+
if urlparse(csv_uri).scheme != "":
116+
csv_path = f"{uuid4()}.csv"
117+
urllib.request.urlretrieve(csv_uri, csv_path)
118+
if not os.path.exists(csv_path):
119+
raise FileNotFoundError(csv_path)
120+
return load_results_from_csv(csv_path)

tests/storage/benchmarks/helpers.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import csv
12
import os
23
import statistics
3-
import csv
44
from datetime import datetime
55

66

@@ -43,6 +43,4 @@ def load_results_from_csv(csv_path):
4343

4444

4545
def mean(data, key):
46-
return statistics.mean(
47-
[float(x[key]) for x in data if key in x]
48-
)
46+
return statistics.mean([float(x[key]) for x in data if key in x])

tests/storage/benchmarks/test_disk_perf.py

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import itertools
2-
import os
32
import json
4-
import statistics
5-
import pytest
63
import logging
4+
import os
5+
import statistics
76
from datetime import datetime
87

8+
import pytest
9+
910
from lib.commands import SSHCommandFailed
11+
1012
from .helpers import load_results_from_csv, log_result_csv, mean
1113

1214
# Tests default settings #
@@ -22,31 +24,27 @@
2224

2325
# Tests parameters #
2426

25-
system_memory = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES')
27+
system_memory = os.sysconf("SC_PAGE_SIZE") * os.sysconf("SC_PHYS_PAGES")
2628

2729
block_sizes = ("4k", "16k", "64k", "1M")
2830
file_sizes = ("1G", "4G", f"{int((system_memory // (1024.**3)) * 2)}G")
2931

30-
modes = (
31-
"read",
32-
"randread",
33-
"write",
34-
"randwrite"
35-
)
32+
modes = ("read", "randread", "write", "randwrite")
3633

3734
# End of tests parameters #
3835

36+
3937
def run_fio(
40-
vm,
41-
test_name,
42-
rw_mode,
43-
temp_dir,
44-
local_temp_dir,
45-
bs=DEFAULT_BS,
46-
iodepth=DEFAULT_IODEPTH,
47-
size=DEFAULT_SIZE,
48-
numjobs=DEFAULT_NUMJOBS,
49-
file_path="",
38+
vm,
39+
test_name,
40+
rw_mode,
41+
temp_dir,
42+
local_temp_dir,
43+
bs=DEFAULT_BS,
44+
iodepth=DEFAULT_IODEPTH,
45+
size=DEFAULT_SIZE,
46+
numjobs=DEFAULT_NUMJOBS,
47+
file_path="",
5048
):
5149
json_output_path = os.path.join(temp_dir, f"{test_name}.json")
5250
local_json_path = os.path.join(local_temp_dir, f"{test_name}.json")
@@ -66,7 +64,7 @@ def run_fio(
6664
f"--numjobs={numjobs}",
6765
"--group_reporting",
6866
"--output-format=json",
69-
f"--output={json_output_path}"
67+
f"--output={json_output_path}",
7068
]
7169
logging.debug(f"Running {fio_cmd}")
7270
try:
@@ -78,6 +76,7 @@ def run_fio(
7876
with open(local_json_path) as f:
7977
return json.load(f)
8078

79+
8180
def assert_performance_not_degraded(current, previous, threshold=10):
8281
diffs = {}
8382
for metric in ("bw_MBps", "IOPS", "latency"):
@@ -88,8 +87,9 @@ def assert_performance_not_degraded(current, previous, threshold=10):
8887
logging.info(f"Missing metric ({metric}), skipping comparison")
8988
continue
9089
diff = (curr - prev if metric == "latency" else prev - curr) / (prev * 100)
91-
assert diff <= threshold, \
92-
f"{metric} changed by {diff:.2f}% (allowed {threshold}%)"
90+
assert (
91+
diff <= threshold
92+
), f"{metric} changed by {diff:.2f}% (allowed {threshold}%)"
9393
diffs[metric] = diff
9494

9595
logging.info("Performance difference summary:")
@@ -103,26 +103,21 @@ class TestDiskPerf:
103103

104104
@pytest.mark.parametrize("block_size,file_size,rw_mode", test_cases)
105105
def test_disk_benchmark(
106-
self,
107-
temp_dir,
108-
local_temp_dir,
109-
prev_results,
110-
block_size,
111-
file_size,
112-
rw_mode,
113-
running_unix_vm_with_fio,
114-
plugged_vbd,
115-
image_format
106+
self,
107+
temp_dir,
108+
local_temp_dir,
109+
prev_results,
110+
block_size,
111+
file_size,
112+
rw_mode,
113+
running_unix_vm_with_fio,
114+
plugged_vbd,
115+
image_format,
116116
):
117117
vm = running_unix_vm_with_fio
118118
vbd = plugged_vbd
119119
device = f"/dev/{vbd.param_get(param_name='device')}"
120-
test_type = "{}-{}-{}-{}".format(
121-
block_size,
122-
file_size,
123-
rw_mode,
124-
image_format
125-
)
120+
test_type = "{}-{}-{}-{}".format(block_size, file_size, rw_mode, image_format)
126121

127122
for i in range(DEFAULT_SAMPLES_NUM):
128123
result = run_fio(
@@ -133,7 +128,7 @@ def test_disk_benchmark(
133128
local_temp_dir,
134129
file_path=device,
135130
bs=block_size,
136-
size=file_size
131+
size=file_size,
137132
)
138133
summary = log_result_csv(test_type, rw_mode, result, CSV_FILE)
139134
assert summary["IOPS"] > 0

0 commit comments

Comments
 (0)