FIX: renderer checks was in wrong place
This commit is contained in:
@@ -136,17 +136,11 @@ def _render_interface_configuration(interface: PlannedInterface) -> List[str]:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if interface.addressing is AddressingMode.STATIC:
|
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(
|
lines.append(
|
||||||
" _node_cmd(%s, 'ip', 'addr', 'add', %s, 'dev', %s)"
|
" _node_cmd(%s, 'ip', 'addr', 'add', %s, 'dev', %s)"
|
||||||
% (
|
% (
|
||||||
node,
|
node,
|
||||||
_python_string(interface.address),
|
repr(interface.address),
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -200,19 +194,8 @@ def _render_service_start(service: PlannedService, index: int) -> List[str]:
|
|||||||
Returns:
|
Returns:
|
||||||
Generated Python source lines that start and track the service.
|
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)
|
node = "nodes[%s]" % _python_string(service.node)
|
||||||
lease_file = "/tmp/mininet-dnsmasq-%d.leases" % index
|
lease_file = "/tmp/mininet-dnsmasq-%d.leases" % index
|
||||||
pid_file = "/tmp/mininet-dnsmasq-%d.pid" % 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)
|
rendered_args = ", ".join(_python_string(arg) for arg in args)
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
" _node_cmd(%s, 'rm', '-f', %s, %s)"
|
||||||
|
% (
|
||||||
|
node,
|
||||||
|
_python_string(lease_file),
|
||||||
|
_python_string(pid_file),
|
||||||
|
),
|
||||||
" pid = _start_background(",
|
" pid = _start_background(",
|
||||||
" %s," % node,
|
" %s," % node,
|
||||||
" [%s]," % rendered_args,
|
" [%s]," % rendered_args,
|
||||||
@@ -259,9 +248,6 @@ def render_python(plan: ExecutionPlan) -> str:
|
|||||||
Python source code that creates the network, applies configuration,
|
Python source code that creates the network, applies configuration,
|
||||||
starts services, opens the Mininet CLI, and performs structured cleanup.
|
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] = [
|
lines: List[str] = [
|
||||||
@@ -320,7 +306,7 @@ def render_python(plan: ExecutionPlan) -> str:
|
|||||||
_python_string(node.name),
|
_python_string(node.name),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif node.type is NodeType.SWITCH:
|
else:
|
||||||
lines.append(
|
lines.append(
|
||||||
" nodes[%s] = net.addSwitch(%s, failMode=%r)"
|
" nodes[%s] = net.addSwitch(%s, failMode=%r)"
|
||||||
% (
|
% (
|
||||||
@@ -329,8 +315,6 @@ def render_python(plan: ExecutionPlan) -> str:
|
|||||||
node.switch_fail_mode,
|
node.switch_fail_mode,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
raise ValueError("unsupported planned node type %r" % node.type)
|
|
||||||
|
|
||||||
lines.extend(["", " # Create links."])
|
lines.extend(["", " # Create links."])
|
||||||
for link in plan.links:
|
for link in plan.links:
|
||||||
@@ -474,6 +458,7 @@ def _self_test() -> None:
|
|||||||
assert "net.addLink(" in source
|
assert "net.addLink(" in source
|
||||||
assert "cls=TCLink" in source
|
assert "cls=TCLink" in source
|
||||||
assert "dnsmasq" in source
|
assert "dnsmasq" in source
|
||||||
|
assert "rm', '-f', '/tmp/mininet-dnsmasq-0.leases'" in source
|
||||||
assert "CLI(net)" in source
|
assert "CLI(net)" in source
|
||||||
assert "dhclient" in source
|
assert "dhclient" in source
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user