From 8777be40d2f0d07d3c2e55dd66d8aa6f86fb827c Mon Sep 17 00:00:00 2001 From: Ivan Pepelnjak Date: Thu, 26 Nov 2026 16:56:53 +0100 Subject: [PATCH] Add documentation URLs to common topology error messages Add 'doc_url' parameter to 20 log.error calls in node, link, group, lag, gateway, vlan and vrf transformation code. All URLs use existing MyST anchors. Explain the errors in the target documentation sections: * Link types: number of nodes must match explicit link type * Loopback links: single node, not all devices support loopbacks * Interface names: explicit ifname needed for virtual interfaces on devices without an interface name template Update the expected error test outputs and add the "add doc_url to new error messages" guideline to AGENTS.md Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 1 + docs/links.md | 11 +++++++++++ netsim/augment/groups.py | 14 +++++++++----- netsim/augment/links.py | 18 ++++++++++++------ netsim/augment/nodes.py | 6 ++++-- netsim/modules/gateway.py | 6 ++++-- netsim/modules/lag.py | 6 ++++-- netsim/modules/vlan.py | 6 ++++-- netsim/modules/vrf.py | 3 ++- tests/coverage/errors/device-image-missing.log | 1 + .../errors/group-device-no-members.log | 1 + tests/errors/bgp-auto-group.log | 1 + tests/errors/groups-recursive.log | 1 + tests/errors/invalid-group-member-element.log | 1 + tests/errors/invalid-group-member.log | 1 + tests/errors/node-no-device.log | 1 + tests/errors/node-unmanaged-device-type.log | 1 + tests/errors/node-wrong-device.log | 1 + tests/errors/vlan-link-error.log | 1 + 19 files changed, 61 insertions(+), 20 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 22e777ee91..16b68e8a66 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -73,6 +73,7 @@ pip3 install -e . - `IncorrectAttr`, `IncorrectType`, `IncorrectValue` for validation errors - `MissingValue` for required but missing data - Use `log.fatal()`, `log.error()`, `log.warning()` for user-facing messages +- Add a `doc_url` parameter to every new `log.error()`/`log.warning()` call that has relevant user documentation (see `docs/dev/error-doc-url.md`). Use relative URLs with existing MyST anchors (for example, `doc_url='links/#links-types'`); add a new anchor only when absolutely necessary. If the target section does not explain why the error could happen, add a short caveat to it - Never use `print()` in library code (allowed in CLI modules) ### File Structure Patterns diff --git a/docs/links.md b/docs/links.md index 3b5a23814b..302738c1f7 100644 --- a/docs/links.md +++ b/docs/links.md @@ -132,6 +132,10 @@ Lab topology could contain *lan*, *p2p*, *stub*, *loopback*, *lag*, and *tunnel* The only reason to change the link types for a regular link is to force a Linux bridge to be used between two *libvirt* nodes to enable [packet capture](libvirt-capture). You do have to set the link **type** attribute to create [additional loopbacks](links-loopback) and [tunnels](links-tunnel). +```{warning} +_netlab_ checks whether the number of nodes attached to a link matches the link **type**: a *p2p* link must have exactly two nodes, and a *stub* or *loopback* link must have a single node. If you get an error because you added a node to a link with an explicit **type**, remove the **type** attribute (and let _netlab_ select the link type) or change it to *lan*. +``` + (links-default-pools)= ## Default Link Prefix Allocation @@ -159,6 +163,11 @@ defaults: devices.eos.features.stub_loopback: True ``` +```{warning} +* A loopback link must have a single node attached to it. +* Not all devices support additional loopback interfaces; check the *Additional loopbacks* column in the [interface parameters table](platform-initial-interfaces). _netlab_ reports an error when you add a loopback link (or turn a stub link into a loopback with the **stub_loopback** setting) to a device that does not support loopback interfaces. +``` + To turn stub links into loopback interfaces on all lab devices apart from Cisco IOSv routers, set the global default to *True* and the IOSv parameter to *False*: ``` @@ -498,6 +507,8 @@ There are two mechanisms to change an interface name in the lab topology: * The **ifname** interface parameter specifies the desired interface name. You can use it with virtual interfaces (for example, loopbacks or tunnels) or when [configuring physical devices with _netlab_](lab-external). Do not use the **ifname** parameter to change the Ethernet interface names on virtual machines or containers. * Use the **ifindex** interface parameter to change the Ethernet interface names. The final interface name is derived from the **ifindex** parameter using the device-specific interface naming scheme[^INS]. Do not use the **ifindex** parameter on virtual interfaces (tunnels, loopbacks, VLANs, LAGs) +_netlab_ generates the names of virtual interfaces from device-specific interface name templates. Many devices do not have templates for all virtual interface types (for example, most devices do not define the tunnel interface name template). You must set the **ifname** parameter on [tunnel interfaces](links-tunnel) and other virtual interfaces of such devices; _netlab_ reports an error if it cannot generate the interface name. + [^INS]: Many devices use **ifindex** in interface name. For example, **ifindex** set to three might result in the interface name **GigabitEthernet3**. Some devices use the `slot/port` naming convention; **ifindex** set to seven might result in the interface name **GigabitEthernet1/3**. You don't have to use a contiguous range of **ifindex** values or sort them. *netlab* sorts the interfaces based on their **ifindex** parameter and adjusts the virtualization provider configuration to match the virtual NICs to the specified **ifindex** values: diff --git a/netsim/augment/groups.py b/netsim/augment/groups.py index 0f2382fb30..c31de56001 100644 --- a/netsim/augment/groups.py +++ b/netsim/augment/groups.py @@ -202,7 +202,8 @@ def expand_group_members( log.error( f'Member {m_id} of group {g_name} is not a valid {g_type} or group name', category=log.IncorrectValue, - module='groups') + module='groups', + doc_url='groups/#groups-members') return members @@ -440,7 +441,7 @@ def check_recursive_chain(topology: Box, chain: list, group: str) -> typing.Opti for m in topology.groups[group].members: if m in chain: chain = chain + [ m ] - log.error(f'Recursive group definition chain {chain}', log.IncorrectValue, 'groups') + log.error(f'Recursive group definition chain {chain}', log.IncorrectValue, 'groups', doc_url='groups/#groups-hierarchy') return chain if m in topology.groups: if check_recursive_chain(topology,chain,m): @@ -492,7 +493,8 @@ def copy_group_device_module(topology: Box) -> None: log.error( f'Cannot use "device" attribute in group {grp} that has no direct or indirect members', log.IncorrectValue, - 'groups') + 'groups', + doc_url='groups/#groups-device-module') continue for name in g_members: # Iterate over group members @@ -518,7 +520,8 @@ def copy_group_device_module(topology: Box) -> None: log.error( f'Cannot use "module" attribute in group {grp} that has no direct or indirect members', log.IncorrectValue, - 'groups') + 'groups', + doc_url='groups/#groups-device-module') continue for name in g_members: # Iterate over group members @@ -636,7 +639,8 @@ def create_bgp_autogroups(topology: Box) -> None: log.error( f'BGP AS group {gname} should not have static members', log.IncorrectValue, - 'groups') + 'groups', + doc_url='groups/#groups-bgp') for n_name,n_data in topology.nodes.items(): # Now iterate over nodes # diff --git a/netsim/augment/links.py b/netsim/augment/links.py index 66f1ad3fdc..74f773d165 100644 --- a/netsim/augment/links.py +++ b/netsim/augment/links.py @@ -413,13 +413,15 @@ def create_virtual_interface(node: Box, ifdata: Box, defaults: Box) -> None: log.error( f'Device {node.device}/node {node.name} does not support loopback links', log.IncorrectValue, - 'links') + 'links', + doc_url='links/#links-loopback') else: log.error( f'Need explicit interface name (ifname) for {devtype} interface on node {node.name} ({node.device})', category=log.IncorrectValue, more_data=str(ifdata), - module='links') + module='links', + doc_url='links/#links-ifname') def add_node_interface(node: Box, ifdata: Box, defaults: Box) -> Box: if ifdata.get('type',None) in VIRTUAL_INTERFACE_TYPES: @@ -542,7 +544,8 @@ def assign_link_prefix( log.error( f'Unknown address pool {link.pool} used in {link_path}', log.IncorrectValue, - 'links') + 'links', + doc_url='links/#links-custom-pools') pools = [ link.pool ] + pools else: if must_be_string(link,'role',link_path): @@ -1106,7 +1109,8 @@ def check_link_type(data: Box) -> bool: f'More than one node connected to a stub link {data._linkname}', category=log.IncorrectValue, more_data=[ str(data) ], - module='links') + module='links', + doc_url='links/#links-types') return False if link_type == 'p2p' and node_cnt != 2: @@ -1114,7 +1118,8 @@ def check_link_type(data: Box) -> bool: f'Point-to-point link {data._linkname} needs exactly two nodes', category=log.IncorrectValue, more_data=[ str(data) ], - module='links') + module='links', + doc_url='links/#links-types') return False if link_type == 'loopback' and node_cnt != 1: @@ -1122,7 +1127,8 @@ def check_link_type(data: Box) -> bool: f'Loopback link {data._linkname} can have a single node attached', more_data=[ str(data) ], category=log.IncorrectValue, - module='links') + module='links', + doc_url='links/#links-loopback') return False return True diff --git a/netsim/augment/nodes.py b/netsim/augment/nodes.py index 121a6da3bd..c9e1856adf 100644 --- a/netsim/augment/nodes.py +++ b/netsim/augment/nodes.py @@ -354,7 +354,8 @@ def find_node_device(n: Box, topology: Box) -> bool: f'No device type specified for {"unmanaged " if u_node else ""}node {n.name} and there is no default device type', log.MissingValue, 'nodes', - hint='unmanaged_device' if u_node else None) + hint='unmanaged_device' if u_node else None, + doc_url='defaults/#default-device-type') return False try: @@ -423,7 +424,8 @@ def find_node_image(n: Box, topology: Box) -> bool: log.error( f'No image specified for device {n.device} (provider {provider}) used by node {n.name}', log.MissingValue, - 'nodes') + 'nodes', + doc_url='defaults/#default-device-image') return False diff --git a/netsim/modules/gateway.py b/netsim/modules/gateway.py index 201fd8d99c..4531df4ebc 100644 --- a/netsim/modules/gateway.py +++ b/netsim/modules/gateway.py @@ -44,7 +44,8 @@ def check_protocol_support(node: Box, topology: Box) -> bool: log.error( f'Node {node.name} ({node.device}) does not support gateway protocol {gw_proto}', log.IncorrectValue, - 'gateway') + 'gateway', + doc_url='module/gateway/#gateway-support') return OK @@ -152,7 +153,8 @@ def module_init(self, topology: Box) -> None: log.error( f'Global/default gateway parameters are missing. We need at least a gateway ID', log.IncorrectType, - 'gateway') + 'gateway', + doc_url='module/gateway/#gateway-global') return check_gw_protocol(gw,'topology.gateway',topology) diff --git a/netsim/modules/lag.py b/netsim/modules/lag.py index fb70b18dfa..9eddb73be9 100644 --- a/netsim/modules/lag.py +++ b/netsim/modules/lag.py @@ -62,7 +62,8 @@ def check_lag_config(node: str, linkname: str, topology: Box) -> bool: if 'lag' not in features: log.error(f'Node {_n.name} ({_n.device}) does not support lag module, cannot be part of LAG {linkname}', category=log.IncorrectAttr, - module='lag') + module='lag', + doc_url='module/lag/#lag-platform') return False if 'lag' not in _n.get('module',[]): log.error(f'lag module not enabled for node {_n.name}, cannot be part of LAG {linkname}', @@ -541,6 +542,7 @@ def node_post_transform(self, node: Box, topology: Box) -> None: if uses_mlag and not (has_peerlink or uses_esi_lag): log.error(f'Node {node.name} uses MLAG but has no peerlink (lag with {PEERLINK_ID_ATT}) or ESI-LAG configured', category=log.IncorrectAttr, - module='lag') + module='lag', + doc_url='module/lag/#lag-mlag') node.pop('_lag_ifindex',None) # Cleanup diff --git a/netsim/modules/vlan.py b/netsim/modules/vlan.py index 350ccf8d61..c9bfca9b62 100644 --- a/netsim/modules/vlan.py +++ b/netsim/modules/vlan.py @@ -213,7 +213,8 @@ def check_link_vlan_attributes(obj: Box, link: Box, v_attr: Box, topology: Box) text=f'VLAN {vname} used in vlan.{attr}{node_error} is not defined', more_data=f'{link}', category=log.IncorrectValue, - module='vlan') + module='vlan', + doc_url='module/vlan/#module-vlan-definition') link_ok = False return link_ok @@ -368,7 +369,8 @@ def check_link_interface_attributes(link: Box, intf: Box, topology: Box) -> None f"Link {link._linkname}, node {intf.node}, vlan {intf.vlan.access}", f"Interface VLAN forwarding mode: {vlan_mode}, unexpected attributes {','.join(invalid)}", f"{intf}" ], category=log.IncorrectValue, - module='vlan') + module='vlan', + doc_url='module/vlan/#vlan-interface-parameters') """ validate_trunk_vlan_list -- validate that the nodes connected to a VLAN trunk have at least some common VLANs diff --git a/netsim/modules/vrf.py b/netsim/modules/vrf.py index 09aa5b89f2..72277445ef 100644 --- a/netsim/modules/vrf.py +++ b/netsim/modules/vrf.py @@ -541,7 +541,8 @@ def node_post_link_transform(self, node: Box, topology: Box) -> None: log.error( f'VRF {ifdata.vrf} used on an interface in {node.name} is not defined in the node or globally', log.MissingValue, - 'vrf') + 'vrf', + doc_url='module/vrf/#module-vrf-definition') continue if not ifdata.vrf in node.vrfs: # Local VRF not present, mark as required diff --git a/tests/coverage/errors/device-image-missing.log b/tests/coverage/errors/device-image-missing.log index 0c4691118b..157015c82b 100644 --- a/tests/coverage/errors/device-image-missing.log +++ b/tests/coverage/errors/device-image-missing.log @@ -1,2 +1,3 @@ MissingValue in nodes: No image specified for device fake (provider libvirt) used by node r1 +... See also: https://netlab.tools/defaults/#default-device-image Fatal error in netlab: Cannot proceed beyond this point due to errors, exiting diff --git a/tests/coverage/errors/group-device-no-members.log b/tests/coverage/errors/group-device-no-members.log index b3a78fc3f2..fa115be57e 100644 --- a/tests/coverage/errors/group-device-no-members.log +++ b/tests/coverage/errors/group-device-no-members.log @@ -1,2 +1,3 @@ IncorrectValue in groups: Cannot use "device" attribute in group g2 that has no direct or indirect members +... See also: https://netlab.tools/groups/#groups-device-module Fatal error in netlab: Cannot proceed beyond this point due to errors, exiting diff --git a/tests/errors/bgp-auto-group.log b/tests/errors/bgp-auto-group.log index 306bcfdc90..2290182371 100644 --- a/tests/errors/bgp-auto-group.log +++ b/tests/errors/bgp-auto-group.log @@ -1,2 +1,3 @@ IncorrectValue in groups: BGP AS group as65005 should not have static members +... See also: https://netlab.tools/groups/#groups-bgp Fatal error in netlab: Cannot proceed beyond this point due to errors, exiting diff --git a/tests/errors/groups-recursive.log b/tests/errors/groups-recursive.log index f4c2e40087..d867293499 100644 --- a/tests/errors/groups-recursive.log +++ b/tests/errors/groups-recursive.log @@ -1,2 +1,3 @@ IncorrectValue in groups: Recursive group definition chain ['g1', 'g2', 'g1'] +... See also: https://netlab.tools/groups/#groups-hierarchy Fatal error in netlab: Cannot proceed beyond this point due to errors, exiting diff --git a/tests/errors/invalid-group-member-element.log b/tests/errors/invalid-group-member-element.log index d49807e116..0a9274766e 100644 --- a/tests/errors/invalid-group-member-element.log +++ b/tests/errors/invalid-group-member-element.log @@ -1,2 +1,3 @@ IncorrectValue in groups: Member wrong of group g1 is not a valid node or group name +... See also: https://netlab.tools/groups/#groups-members Fatal error in netlab: Cannot proceed beyond this point due to errors, exiting diff --git a/tests/errors/invalid-group-member.log b/tests/errors/invalid-group-member.log index 8f13306f3b..59e839b5e7 100644 --- a/tests/errors/invalid-group-member.log +++ b/tests/errors/invalid-group-member.log @@ -1,2 +1,3 @@ IncorrectValue in groups: Member a3 of group g1 is not a valid node or group name +... See also: https://netlab.tools/groups/#groups-members Fatal error in netlab: Cannot proceed beyond this point due to errors, exiting diff --git a/tests/errors/node-no-device.log b/tests/errors/node-no-device.log index 364821cf9a..7d765a0e93 100644 --- a/tests/errors/node-no-device.log +++ b/tests/errors/node-no-device.log @@ -1,3 +1,4 @@ MissingValue in nodes: No device type specified for node r1 and there is no default device type +... See also: https://netlab.tools/defaults/#default-device-type MissingValue in nodes: No device type specified for node r2 and there is no default device type Fatal error in netlab: Cannot proceed beyond this point due to errors, exiting diff --git a/tests/errors/node-unmanaged-device-type.log b/tests/errors/node-unmanaged-device-type.log index 906e8b7ec2..910316bf29 100644 --- a/tests/errors/node-unmanaged-device-type.log +++ b/tests/errors/node-unmanaged-device-type.log @@ -1,4 +1,5 @@ MissingValue in nodes: No device type specified for unmanaged node sw and there is no default device type +... See also: https://netlab.tools/defaults/#default-device-type ... Netlab uses the node device type for unmanaged nodes to figure out what features the node supports. If you're using a device that is not supported by netlab, set the device type to 'none'. diff --git a/tests/errors/node-wrong-device.log b/tests/errors/node-wrong-device.log index 9bb21b0f19..176c125a2b 100644 --- a/tests/errors/node-wrong-device.log +++ b/tests/errors/node-wrong-device.log @@ -1,4 +1,5 @@ MissingValue in nodes: No device type specified for node r1 and there is no default device type +... See also: https://netlab.tools/defaults/#default-device-type IncorrectValue in nodes: attribute 'nodes.r2.device' must be known device type identifier (got wtf) ... Use 'netlab show devices' to display a list of valid devices Fatal error in netlab: Cannot proceed beyond this point due to errors, exiting diff --git a/tests/errors/vlan-link-error.log b/tests/errors/vlan-link-error.log index b74e2df4bb..79bd54a6b2 100644 --- a/tests/errors/vlan-link-error.log +++ b/tests/errors/vlan-link-error.log @@ -1,6 +1,7 @@ IncorrectValue in vlan: VLAN wtf used in vlan.access in link links[1] is not defined ... {'_linkname': 'links[1]', 'vlan': {'access': 'wtf'}, 'interfaces': [{'node': ... 'n1'}, {'node': 'n2'}], 'linkindex': 1} +... See also: https://netlab.tools/module/vlan/#module-vlan-definition IncorrectValue in vlan: VLAN wtf used in vlan.access in node n1 on link links[7] is not defined ... {'_linkname': 'links[7]', 'interfaces': [{'vlan': {'access': 'wtf'}, 'node': ... 'n1'}, {'node': 'n2'}], 'linkindex': 7}