Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bobber/lib/analysis/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def fio_command_details(log_contents: str, old_reads: dict,
"""
commands = re.findall(r'/usr/bin/fio --rw.*', log_contents)
if len(commands) < 2:
raise ValueError(f'FIO command not found in {log} file!')
raise ValueError('FIO command not found in the log file!')

for command in commands:
if '--rw=read' in command:
Expand Down
32 changes: 32 additions & 0 deletions tests/test_fio_command_nameerror.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SPDX-License-Identifier: MIT
"""Regression test for the FIO command NameError bug.

When a FIO log does not contain at least two ``/usr/bin/fio --rw...``
command lines, ``fio_command_details()`` must raise a clear ``ValueError``.
Before the fix, the error message referenced an undefined variable ``log``,
so callers instead got ``NameError: name 'log' is not defined``.
"""
import os
import sys

import pytest

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from bobber.lib.analysis.common import fio_command_details # noqa: E402


def test_missing_fio_commands_raises_valueerror_not_nameerror():
with pytest.raises(ValueError, match='FIO command not found'):
fio_command_details('no fio commands here', {}, {})


def test_valid_fio_log_still_parses():
log_contents = (
'/usr/bin/fio --rw=read --bs=1M --size=1G --name=read_test\n'
'some output\n'
'/usr/bin/fio --rw=write --bs=1M --size=1G --name=write_test\n'
)
reads, writes = fio_command_details(log_contents, {}, {})
assert reads['rw'] == 'read'
assert writes['rw'] == 'write'