Skip to content

Fix ethtool channel parser stripping whitespace from values - #4735

Open
paxue wants to merge 3 commits into
mainfrom
bugfix/ethtool-channel-parser_280926_213501
Open

paxue wants to merge 3 commits into
mainfrom
bugfix/ethtool-channel-parser_280926_213501

Conversation

@paxue

@paxue paxue commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Description

Fix parsing issue in ethtool channel info where regex-captured values with trailing whitespace caused int() conversion to fail.

Root Cause

The DeviceChannel class in ethtool.py parsed device channel info using regex patterns that captured values with potential trailing whitespace. When converting these values to integers using int(), the whitespace caused a ValueError.

Changes

  • Added .strip() to remove leading/trailing whitespace before converting regex group values to integers
  • Modified lines 116-117 in lisa/tools/ethtool.py

Testing

  • Black: PASSED
  • Flake8: PASSED
  • Pylint: PASSED
  • Mypy: PASSED

Fixes

  • Fixes parsing failures in verify_cpu_offline_channel_add test
  • Ensures ethtool channel parsing works reliably with various output formats

Related Tests

  • verify_cpu_offline_channel_add
  • verify_cpu_hot_plug
  • verify_cpu_offline_storage_workload
  • verify_cpu_offline_network_workload

Copilot AI balanced review requested due to automatic review settings September 29, 2026 05:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The proposed stripping cannot resolve the described failure because int() already accepts surrounding whitespace.

Key Test Cases:
verify_cpu_offline_channel_add

Impacted LISA Features:
NetworkInterface

Tested Azure Marketplace Images:

  • canonical 0001-com-ubuntu-server-jammy 22_04-lts-gen2 latest

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Updates ethtool channel parsing by trimming captured values before integer conversion.

Changes:

  • Strips whitespace from current and maximum channel values.
File Description
lisa/​tools/​ethtool.py Adjusts channel-value conversion.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lisa/tools/ethtool.py Outdated
@LiliDeng

Copy link
Copy Markdown
Collaborator

AI Test Case Selection

Selected 4 test case(s): verify_device_channels_change,verify_device_enabled_features,verify_device_statistics,verify_device_gro_lro_settings_change

Marketplace image: canonical 0001-com-ubuntu-server-jammy 22_04-lts-gen2 latest

Result: Succeeded

View full logs in Azure DevOps

@LiliDeng

Copy link
Copy Markdown
Collaborator

paxue Please provide test matrix which can repro this issue, and provide the results of before and after the fix.

@paxue
paxue force-pushed the bugfix/ethtool-channel-parser_280926_213501 branch from bd2e71a to 1e14684 Compare September 29, 2026 23:49
Copilot AI balanced review requested due to automatic review settings September 29, 2026 23:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The parser now silently accepts malformed numeric prefixes, while the whitespace test does not reproduce the reported failure.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
Resolved since last review (1)

Comment thread lisa/tools/ethtool.py Outdated
# Combined: 1
_channel_count_param_pattern = re.compile(
r"(?P<param>Combined):[ \t]*(?P<value>.*)$", re.MULTILINE
r"(?P<param>Combined):[ \t]*(?P<value>\d+)", re.MULTILINE
Comment thread selftests/test_ethtool_parser.py Outdated
Comment on lines +29 to +37
def test_device_channel_parsing_with_trailing_spaces(self) -> None:
"""Test parsing when output has trailing spaces."""
raw_output = (
"Channel parameters for eth0:\nPre-set maximums:\n"
"RX: 0\nTX: 0\nOther: 0\n"
"Combined: 32 \n"
"Current hardware settings:\n"
"RX: 0\nTX: 0\nOther: 0\n"
"Combined: 2 " # noqa: W291
@LiliDeng

Copy link
Copy Markdown
Collaborator

AI Test Case Selection

Selected 5 test case(s): verify_device_channels_change,verify_device_enabled_features,verify_device_gro_lro_settings_change,verify_device_rss_hash_key_change,verify_device_rx_hash_level_change

Marketplace image: canonical 0001-com-ubuntu-server-jammy 22_04-lts-gen2 latest

Result: Succeeded

View full logs in Azure DevOps

Comment thread selftests/test_ethtool_parser.py Outdated
@@ -0,0 +1,105 @@
# Copyright (c) Microsoft Corporation.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

remove this, no need to add selftests for each PR

Copilot AI balanced review requested due to automatic review settings October 2, 2026 22:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 3 Medium severity · 1 Low severity

Open (4)

Comment thread lisa/tools/ethtool.py
Comment on lines +90 to +91
r"(?P<param>Combined):[ \t]*(?P<value>\d+)[ \t]*\r?$",
re.MULTILINE,
Comment thread lisa/tools/ethtool.py
# Combined: 1
_channel_count_param_pattern = re.compile(
r"(?P<param>Combined):[ \t]*(?P<value>.*)$", re.MULTILINE
r"(?P<param>Combined):[ \t]*(?P<value>\d+)[ \t]*\r?$",
@LiliDeng

Copy link
Copy Markdown
Collaborator

paxue Please keep the PR updated in a timely manner and provide the test matrix that this PR is intended to fix. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants