|SUCCESS| [v2] dts: fix port info getter when port is not found
dpdklab at iol.unh.edu
dpdklab at iol.unh.edu
Wed Apr 22 22:40:29 CEST 2026
Test-Label: ai-code-review
Test-Status: SUCCESS
https://dpdk.org/patch/163237
_AI Code Review_
=== Patch Review: series.patch (via Claude) ===
Review date: 2026-04-22
Reviewing patch: dts: fix port info getter when port is not found
commit a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0
Author: Riley Fletcher <rileyf at linux.ibm.com>
dts: fix port info getter when port is not found
This patch fixes a bug in the DTS framework where providing a
nonexistent PCI address results in a StopIteration error instead of the
expected ConfigurationError.
> diff --git a/dts/framework/testbed_model/linux_session.py b/dts/framework/testbed_model/linux_session.py
> index ee943462c2..3de92b549e 100644
> --- a/dts/framework/testbed_model/linux_session.py
> +++ b/dts/framework/testbed_model/linux_session.py
> @@ -168,7 +168,7 @@ def get_port_info(self, pci_address: str) -> PortInfo:
> ConfigurationError: If the port could not be found.
> """
> bus_info = f"pci@{pci_address}"
> - port = next(port for port in self._lshw_net_info if port.get("businfo") == bus_info)
> + port = next((port for port in self._lshw_net_info if port.get("businfo") == bus_info), None)
The fix correctly adds a default value of None to the next() call to
prevent StopIteration when no matching port is found. However, there is
a subtle issue with the parentheses placement.
Does this code properly preserve the generator expression? The new code
wraps the generator in an extra set of parentheses, which changes the
call signature from next(generator) to next((generator), None). While
this happens to work correctly, the preferred style would be:
port = next((port for port in self._lshw_net_info
if port.get("businfo") == bus_info), None)
or alternatively without the outer parentheses around the generator:
port = next(
(port for port in self._lshw_net_info
if port.get("businfo") == bus_info),
None
)
The current formatting is acceptable but may cause confusion since both
the generator and None are arguments to next(), not a tuple.
> if port is None:
> raise ConfigurationError(f"Port {pci_address} could not be found on the node.")
The error handling logic is correct and properly raises the expected
ConfigurationError when the port is not found.
More information about the test-report
mailing list