Skip to content

Fix a type mismatch in - #366

Merged
harriscr merged 1 commit into
ceph:mainfrom
harriscr:ch_wip_command_typing_fix
Sep 15, 2026
Merged

harriscr merged 1 commit into
ceph:mainfrom
harriscr:ch_wip_command_typing_fix

Conversation

@harriscr

Copy link
Copy Markdown
Contributor

As part of a code review for #359 it was noticed that in some instances the command classes were being initalised with a dict containing str, int, bool values when the constructor was explicitly expecting strings. Fix that type mis-match so that the options passed in to the *command classes are definitely in a dict[str, Union[str, list[str]] format.

The code worked as written, but the type mismatch could lead to unexpected behaviour

IBM Bob 2.0.3 was used to help with this code.

###Testing###
New unit tests were written to catch this case.
All unit tests pass:

============================= slowest 5 durations ==============================
0.07s call     tests/test_directory_comparison_plotter.py::TestDirectoryComparisonPlotter::test_draw_and_save_adds_legend
0.06s call     tests/test_time_series_plotter.py::TestTimeSeriesPlotter::test_plot_time_series_creates_all_plots
0.05s call     tests/test_monitoring_perf.py::test_perf_start_remote_node_uses_pdsh
0.01s call     tests/test_time_series_formatter.py::TestFIOTimeSeriesParser::test_format_with_all_metrics
0.01s call     tests/test_fio_log_parser.py::TestFIOLogParser::test_parse_and_combine_logs_bw
================= 985 passed, 3 skipped, 21 warnings in 1.41s ==================
Finished running tests!

Manual testing shows the code working as expected after this change

@harriscr harriscr self-assigned this Sep 15, 2026
@harriscr harriscr added the bug label Sep 15, 2026
@harriscr
harriscr requested a review from mohant-ibm September 15, 2026 15:59

@gitkenan gitkenan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small comments about the approach here, but overall looks great

Comment thread workloads/workloads.py Outdated
normalised: WorkloadType = {}
for key, value in options.items():
if isinstance(value, list):
normalised[key] = [f"{item}" for item in value]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Python:

bool("False")   # is True! Non-empty strings are always truthy.

Bob's recommendation: Either preserve bool types, convert booleans properly, or normalize boolean string handling in _parse_options() (e.g. str(value).lower() in ("true", "1")). Unconditionally formatting bool to f"{value}" breaks boolean semantics.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, will fix

Comment thread workloads/workloads.py
"""
normalised: WorkloadType = {}
for key, value in options.items():
if isinstance(value, list):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only handles 1 level of nesting (list vs non-list).

If an option is a nested dict (e.g., auth: {config: ..., s3_session_token: ...} in elbencho or prefill: {blocksize: '4M', numjobs: 1}), f"{value}" stringifies the entire dictionary into "{'blocksize': '4M', 'numjobs': 1}", which could corrupt nested configuration structures

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the time the code gets here there should be no nested options. prefill is not included in the workloads section, it is handled by the separate prefill() method, which is called at line 75 in cbt.py. Prefill should be a property of the benchmark, not the Workload. We could change this in the future, but then that change would also have to consider the changes required here to handle the new format correctly.

The type to be passed is a dict[str, WorkloadType] where WorkloadType is dict[str, Union[str, list[str]]]

The elbencho code needs to honour this type when calling _create_configurations()

As part of a code review for PR 359 it was noticed that in some instances the command classes were being initalised with a dict containing str, int, bool values when the  constructor was explicitly expecting strings.
Fix that type mis-match so that the options passed in to the *command classes are definitely in a dict[str, Union[str, list[str]] format

IBM Bob 2.0.3 was used to help with this code.

Signed-off-by: Chris Harris <harriscr@uk.ibm.com>
@harriscr
harriscr force-pushed the ch_wip_command_typing_fix branch from 6705275 to 950ffeb Compare September 15, 2026 17:34

@gitkenan gitkenan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@harriscr
harriscr merged commit 5601c69 into ceph:main Sep 15, 2026
@harriscr
harriscr deleted the ch_wip_command_typing_fix branch September 15, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants