FIX: renderer checks was in wrong place

This commit is contained in:
2026-09-26 20:34:56 +03:00
parent 92a322eedb
commit 89c151c720
+9 -24
View File
@@ -136,17 +136,11 @@ def _render_interface_configuration(interface: PlannedInterface) -> List[str]:
)
if interface.addressing is AddressingMode.STATIC:
if interface.address is None:
raise ValueError(
"planned static interface %s:%s has no address"
% (interface.node, interface.logical_interface)
)
lines.append(
" _node_cmd(%s, 'ip', 'addr', 'add', %s, 'dev', %s)"
% (
node,
_python_string(interface.address),
repr(interface.address),
name,
)
)
@@ -200,19 +194,8 @@ def _render_service_start(service: PlannedService, index: int) -> List[str]:
Returns:
Generated Python source lines that start and track the service.
Raises:
ValueError: If the plan contains an unsupported service type or
incompatible settings object.
"""
if service.type is not ServiceType.DHCP_SERVER:
raise ValueError(
"unsupported planned service type %r" % service.type.value
)
if not isinstance(service.settings, PlannedDHCPServerSettings):
raise ValueError("DHCP service has incompatible planned settings")
node = "nodes[%s]" % _python_string(service.node)
lease_file = "/tmp/mininet-dnsmasq-%d.leases" % index
pid_file = "/tmp/mininet-dnsmasq-%d.pid" % index
@@ -240,6 +223,12 @@ def _render_service_start(service: PlannedService, index: int) -> List[str]:
rendered_args = ", ".join(_python_string(arg) for arg in args)
return [
" _node_cmd(%s, 'rm', '-f', %s, %s)"
% (
node,
_python_string(lease_file),
_python_string(pid_file),
),
" pid = _start_background(",
" %s," % node,
" [%s]," % rendered_args,
@@ -259,9 +248,6 @@ def render_python(plan: ExecutionPlan) -> str:
Python source code that creates the network, applies configuration,
starts services, opens the Mininet CLI, and performs structured cleanup.
Raises:
ValueError: If the supplied plan contains an operation that this
renderer cannot serialize.
"""
lines: List[str] = [
@@ -320,7 +306,7 @@ def render_python(plan: ExecutionPlan) -> str:
_python_string(node.name),
)
)
elif node.type is NodeType.SWITCH:
else:
lines.append(
" nodes[%s] = net.addSwitch(%s, failMode=%r)"
% (
@@ -329,8 +315,6 @@ def render_python(plan: ExecutionPlan) -> str:
node.switch_fail_mode,
)
)
else:
raise ValueError("unsupported planned node type %r" % node.type)
lines.extend(["", " # Create links."])
for link in plan.links:
@@ -474,6 +458,7 @@ def _self_test() -> None:
assert "net.addLink(" in source
assert "cls=TCLink" in source
assert "dnsmasq" in source
assert "rm', '-f', '/tmp/mininet-dnsmasq-0.leases'" in source
assert "CLI(net)" in source
assert "dhclient" in source