Skip to content

Commit 49fe806

Browse files
committed
chore(tests): simplify blockdev output checking
It doesn't end up much shorter but at least it is more readable. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 0b8c3c7 commit 49fe806

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

tests/integration_tests/functional/test_drive_virtio.py

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,15 @@ def test_non_partuuid_boot(uvm_plain_any, io_engine):
168168

169169
test_microvm.start()
170170

171-
# Prepare the input for doing the assertion
172-
assert_dict = {}
173-
# Keep an array of strings specifying the location where some string
174-
# from the output is located.
175-
# 1-0 means line 1, column 0.
176-
keys_array = ["1-0", "1-6", "2-0"]
177171
# Keep a dictionary where the keys are the location and the values
178172
# represent the input to assert against.
179-
assert_dict[keys_array[0]] = "ro"
180-
assert_dict[keys_array[1]] = "/dev/vda"
181-
assert_dict[keys_array[2]] = "ro"
182-
_check_drives(test_microvm, assert_dict, keys_array)
173+
# 1, 0 means line 1, column 0.
174+
assert_dict = {
175+
(1, 0): "ro",
176+
(1, 6): "/dev/vda",
177+
(2, 0): "ro",
178+
}
179+
_check_drives(test_microvm, assert_dict, assert_dict.keys())
183180

184181

185182
def test_partuuid_boot(uvm_plain_any, partuuid_and_disk_path_tmpfs, io_engine):
@@ -207,13 +204,13 @@ def test_partuuid_boot(uvm_plain_any, partuuid_and_disk_path_tmpfs, io_engine):
207204
)
208205
test_microvm.start()
209206

210-
assert_dict = {}
211-
keys_array = ["1-0", "1-6", "2-0", "2-6"]
212-
assert_dict[keys_array[0]] = "rw"
213-
assert_dict[keys_array[1]] = "/dev/vda"
214-
assert_dict[keys_array[2]] = "rw"
215-
assert_dict[keys_array[3]] = "/dev/vda1"
216-
_check_drives(test_microvm, assert_dict, keys_array)
207+
assert_dict = {
208+
(1, 0): "rw",
209+
(1, 6): "/dev/vda",
210+
(2, 0): "rw",
211+
(2, 6): "/dev/vda1",
212+
}
213+
_check_drives(test_microvm, assert_dict, assert_dict.keys())
217214

218215

219216
def test_partuuid_update(uvm_plain_any, io_engine):
@@ -247,11 +244,11 @@ def test_partuuid_update(uvm_plain_any, io_engine):
247244
test_microvm.start()
248245

249246
# Assert that the final booting method is from /dev/vda.
250-
assert_dict = {}
251-
keys_array = ["1-0", "1-6"]
252-
assert_dict[keys_array[0]] = "rw"
253-
assert_dict[keys_array[1]] = "/dev/vda"
254-
_check_drives(test_microvm, assert_dict, keys_array)
247+
assert_dict = {
248+
(1, 0): "rw",
249+
(1, 6): "/dev/vda",
250+
}
251+
_check_drives(test_microvm, assert_dict, assert_dict.keys())
255252

256253

257254
def test_patch_drive(uvm_plain_any, io_engine):
@@ -370,11 +367,9 @@ def _check_file_size(ssh_connection, dev_path, size):
370367

371368
def _process_blockdev_output(blockdev_out, assert_dict, keys_array):
372369
blockdev_out_lines = blockdev_out.splitlines()
373-
for key in keys_array:
374-
line = int(key.split("-")[0])
375-
col = int(key.split("-")[1])
370+
for line, col in keys_array:
376371
blockdev_out_line_cols = blockdev_out_lines[line].split()
377-
assert blockdev_out_line_cols[col] == assert_dict[key]
372+
assert blockdev_out_line_cols[col] == assert_dict[line, col]
378373

379374

380375
def _check_drives(test_microvm, assert_dict, keys_array):

0 commit comments

Comments
 (0)