Skip to content

Commit af54e81

Browse files
style(disk_perf): sort imports and minor style fixes
Signed-off-by: Mathieu Labourier <[email protected]>
1 parent 3e8bee1 commit af54e81

File tree

3 files changed

+48
-48
lines changed

3 files changed

+48
-48
lines changed

tests/storage/benchmarks/conftest.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
import logging
22
import os
3-
import pytest
43
import tempfile
54
import urllib.request
65
from urllib.parse import urlparse
76
from uuid import uuid4
87

8+
import pytest
99

1010
from lib.commands import SSHCommandFailed
11+
1112
from .helpers import load_results_from_csv
1213

13-
MAX_LENGTH = 64 * (1024**3) # 64GiB
14+
MAX_LENGTH = 64 * (1024**3) # 64GiB
15+
1416

1517
# use vhd, qcow2, raw... when image_format support will be available
16-
@pytest.fixture(scope="module", params=['vdi'])
18+
@pytest.fixture(scope="module", params=["vdi"])
1719
def image_format(request):
1820
return request.param
1921

22+
2023
@pytest.fixture(scope="module")
2124
def running_unix_vm_with_fio(running_unix_vm):
2225
vm = running_unix_vm
2326
install_cmds = (
2427
("command -v apt", "apt update && apt install -y fio", "apt remove -y fio"),
2528
("command -v dnf", "dnf install -y fio", "dnf remove -y fio"),
2629
("command -v yum", "yum install -y fio", "yum remove -y fio"),
27-
("command -v apk", "apk add fio", "apk del fio")
30+
("command -v apk", "apk add fio", "apk del fio"),
2831
)
2932

3033
for check_cmd, install_cmd, remove in install_cmds:
@@ -59,6 +62,7 @@ def vdi_on_local_sr(host, local_sr_on_hostA1, image_format):
5962
logging.info(f"<< Destroying VDI {vdi.uuid}")
6063
vdi.destroy()
6164

65+
6266
@pytest.fixture(scope="module")
6367
def plugged_vbd(vdi_on_local_sr, running_unix_vm_with_fio):
6468
vm = running_unix_vm_with_fio
@@ -75,11 +79,13 @@ def plugged_vbd(vdi_on_local_sr, running_unix_vm_with_fio):
7579
vbd.unplug()
7680
vbd.destroy()
7781

82+
7883
@pytest.fixture(scope="module")
7984
def local_temp_dir():
8085
with tempfile.TemporaryDirectory() as tmpdir:
8186
yield tmpdir
8287

88+
8389
@pytest.fixture(scope="module")
8490
def temp_dir(running_unix_vm_with_fio):
8591
vm = running_unix_vm_with_fio
@@ -99,6 +105,7 @@ def pytest_addoption(parser):
99105
help="Path/URI to previous CSV results file for comparison",
100106
)
101107

108+
102109
@pytest.fixture(scope="session")
103110
def prev_results(pytestconfig):
104111
csv_uri = pytestconfig.getoption("--prev-csv")

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)