1
1
import itertools
2
- import os
3
2
import json
4
- import statistics
5
- import pytest
6
3
import logging
4
+ import os
5
+ import statistics
7
6
from datetime import datetime
8
7
8
+ import pytest
9
+
9
10
from lib .commands import SSHCommandFailed
11
+
10
12
from .helpers import load_results_from_csv , log_result_csv , mean
11
13
12
14
# Tests default settings #
22
24
23
25
# Tests parameters #
24
26
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" )
26
28
27
29
block_sizes = ("4k" , "16k" , "64k" , "1M" )
28
30
file_sizes = ("1G" , "4G" , f"{ int ((system_memory // (1024. ** 3 )) * 2 )} G" )
29
31
30
- modes = (
31
- "read" ,
32
- "randread" ,
33
- "write" ,
34
- "randwrite"
35
- )
32
+ modes = ("read" , "randread" , "write" , "randwrite" )
36
33
37
34
# End of tests parameters #
38
35
36
+
39
37
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 = "" ,
50
48
):
51
49
json_output_path = os .path .join (temp_dir , f"{ test_name } .json" )
52
50
local_json_path = os .path .join (local_temp_dir , f"{ test_name } .json" )
@@ -66,7 +64,7 @@ def run_fio(
66
64
f"--numjobs={ numjobs } " ,
67
65
"--group_reporting" ,
68
66
"--output-format=json" ,
69
- f"--output={ json_output_path } "
67
+ f"--output={ json_output_path } " ,
70
68
]
71
69
logging .debug (f"Running { fio_cmd } " )
72
70
try :
@@ -78,6 +76,7 @@ def run_fio(
78
76
with open (local_json_path ) as f :
79
77
return json .load (f )
80
78
79
+
81
80
def assert_performance_not_degraded (current , previous , threshold = 10 ):
82
81
diffs = {}
83
82
for metric in ("bw_MBps" , "IOPS" , "latency" ):
@@ -88,8 +87,9 @@ def assert_performance_not_degraded(current, previous, threshold=10):
88
87
logging .info (f"Missing metric ({ metric } ), skipping comparison" )
89
88
continue
90
89
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 } %)"
93
93
diffs [metric ] = diff
94
94
95
95
logging .info ("Performance difference summary:" )
@@ -103,26 +103,21 @@ class TestDiskPerf:
103
103
104
104
@pytest .mark .parametrize ("block_size,file_size,rw_mode" , test_cases )
105
105
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 ,
116
116
):
117
117
vm = running_unix_vm_with_fio
118
118
vbd = plugged_vbd
119
119
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 )
126
121
127
122
for i in range (DEFAULT_SAMPLES_NUM ):
128
123
result = run_fio (
@@ -133,7 +128,7 @@ def test_disk_benchmark(
133
128
local_temp_dir ,
134
129
file_path = device ,
135
130
bs = block_size ,
136
- size = file_size
131
+ size = file_size ,
137
132
)
138
133
summary = log_result_csv (test_type , rw_mode , result , CSV_FILE )
139
134
assert summary ["IOPS" ] > 0
0 commit comments