fix: use bound-method param count for Dynamips create_nio detection

The inspect check tested unbound function signatures (3 params unbound vs
2 unbound) but node.manager.create_nio is a bound method — inspect
excludes 'self'.  Dynamips bound = 2 (node + nio_settings), standard
bound = 1 (nio_settings).  The old '== 3' never matched, so the extra
'node' arg was never passed.  Switch to '>= 2' and rewrite the test to
exercise the actual bound-method scenario.
This commit is contained in:
YueGuobin 2026-08-11 00:58:08 +08:00
parent e56488c2f7
commit 09a9555d02
No known key found for this signature in database
2 changed files with 19 additions and 14 deletions

View File

@ -191,8 +191,12 @@ async def create_batch_nios(
nio_settings = jsonable_encoder(entry.nio, exclude_unset=True)
# Dynamips.create_nio takes an extra positional `node` argument that
# the base signature does not include. Detect it via parameter count.
# Dynamips.create_nio(self, node, nio_settings) exposes one extra
# positional on the bound method compared to the standard signature
# (self, nio_settings). Detect it: standard == 1 bound param,
# Dynamips == 2 bound params (node + nio_settings).
sig = inspect.signature(node.manager.create_nio)
if len(sig.parameters) == 3:
if len(sig.parameters) >= 2:
nio = node.manager.create_nio(node, nio_settings)
else:
nio = node.manager.create_nio(nio_settings)

View File

@ -260,24 +260,25 @@ class TestBatchNIOEdgeCases:
@pytest.mark.asyncio
async def test_dynamips_create_nio_passes_node_arg(self):
"""
Dynamips.create_nio(self, node, nio_settings) takes an extra 'node'
positional; the batch handler detects this via parameter count.
Dynamips.create_nio(self, node, nio_settings) exposes 2 bound-method
params vs. the standard 1. The batch handler detects this via the
parameter count on the bound method and passes the extra 'node'
argument.
"""
import inspect
# Dynamips-style 3-param signature (self + node + nio_settings)
async def create_nio_with_node(self, node, nio_settings):
pass
class _FakeDynamips:
async def create_nio(self, node, nio_settings):
pass
sig = inspect.signature(create_nio_with_node)
assert len(sig.parameters) == 3
class _FakeBase:
async def create_nio(self, nio_settings):
pass
# Standard base 2-param signature (self + nio_settings)
async def create_nio_base(self, nio_settings):
pass
sig2 = inspect.signature(create_nio_base)
assert len(sig2.parameters) == 2
dyn = _FakeDynamips()
base = _FakeBase()
assert len(inspect.signature(dyn.create_nio).parameters) == 2 # Dynamips
assert len(inspect.signature(base.create_nio).parameters) == 1 # standard
@pytest.mark.asyncio
async def test_qemu_dispatch_to_adapter_add_nio_binding(self):