fix: await Dynamips.create_nio (it is async, unlike sync base)

Dynamips.create_nio is async def while BaseManager.create_nio is a sync
def.  The previous fix only added the extra 'node' argument but did not
await the resulting coroutine, causing 'was never awaited' warnings and
passing a coroutine object instead of an NIO instance to the binding
dispatch.  Add 'await' on the Dynamips branch.  Test updated to verify
both the async nature and the parameter count.
This commit is contained in:
YueGuobin committed 2026-08-11 01:00:01 +08:00
1 parent 09a9555d02
commit 4e30b6905a
2 files changed
+19 -15

No files matched your search

+4 -7
View File
@@ -189,15 +189,12 @@ async def create_batch_nios(
for entry in batch.nios:
node = project.get_node(entry.node_id)
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).
# Dynamips.create_nio(self, node, nio_settings) is async and takes an
# extra positional 'node'. Detect via bound-method parameter count:
# standard == 1, Dynamips == 2. Await the async variant.
sig = inspect.signature(node.manager.create_nio)
if len(sig.parameters) >= 2:
nio = node.manager.create_nio(node, nio_settings)
nio = await node.manager.create_nio(node, nio_settings)
else:
nio = node.manager.create_nio(nio_settings)
await _add_nio_binding(node, entry.adapter_number, entry.port_number, nio)