Adding Documentation URLs to log.error/log.warning calls

The utils.log.error function is the main error-reporting function (warning and fatal call it, so they accept the same optional parameters). It can accept doc_url (pointer to relevant documentation) and doc_url_text (formatting of the hint text) among its many parameters. This document describes those two parameters.

The doc_url parameter points to the relevant documentation page. While you can use absolute URLs to point to non-netlab documentation, internal pointers should be relative URLs (module/stp/, not https://netlab.tools/module/stp/) and should include an anchor.

You can also add the documentation URL to attribute definitions and attribute namespaces with the _doc_url key (see Valid Data Types and Special Attribute Dictionary Keys). The attribute validation errors include the documentation URL of the attribute, which is:

  • The _doc_url value of the attribute definition

  • The documentation URL of the parent attribute (for dictionary keys, dictionary values, and list elements, including the attributes of an object referenced with _subtype)

  • The _doc_url value of the attribute namespace (for example, attributes.global or eigrp.attributes.node). An attribute from an additional namespace (for example, a link attribute used on an interface) uses the _doc_url value of the namespace defining it.

The _doc_url value of the (primary) attribute namespace is also displayed together with the invalid attribute errors. The module attributes (for example, nodes.r1.eigrp) do not inherit the documentation URL of the object (node) they’re used in.

Set the _doc_url key on the attributes using generic user-defined data types (for example, named prefixes), not on the data types. The keys, values, and elements of the data type inherit the documentation URL of the attribute.

For example, the _doc_url key of the EIGRP global namespace is used in errors reported for the eigrp.as attribute and the eigrp.af.ipv4 dictionary key (inherited through the eigrp.af attribute):

attributes:
  global:
    _doc_url: module/eigrp/#eigrp-global-params
    af:
      _list_to_dict: True
      _alt_types: [ NoneType ]
      ipv4: bool
      ipv6: bool
    as: asn

The validation code passes the documentation URL to the validation of dictionary keys, dictionary values, and list elements in the validation context (the context parameter of the validate_* functions), and to the must_be_* validation functions as their _doc_url context parameter.

The tests/check-doc-urls.py script (see below) also checks the _doc_url values in the YAML files in the netsim directory.

The defaults.const.doc_url_prefix topology default contains the netlab documentation website URL (default: https://netlab.tools/) and can be changed by the user if they use a different website (for example, https://ipspace.github.io/netlab/) or an internal mirror.

The URL anchor should be taken from the Markdown text, not from the auto-generated website anchors. Sphinx replaces underscores in the Markdown anchors with hyphens; use module/routing_protocols/#routing-router-id to point to the (routing_router_id)= anchor.

The pull request workflow builds the documentation and checks all documentation URLs used in the source code. To run the same check locally, build the documentation with PYTHONPATH=. sphinx-build -W -b html docs _build/html and run tests/check-doc-urls.py _build/html. Sphinx generates heading anchors from heading text, which can change, whereas the source anchors do not. For example, do not use module/stp/#global-parameters (generated from heading text) to point to STP global parameters. Use module/stp/#module-stp-global-params (using Markdown anchor).

Finally, the documentation pointer is displayed with the green [DOCS] marker and the intro text derived from the doc_url_text parameter. Omitting that parameter will result in the standard text:

[DOCS] See also: https://netlab.tools/module/stp/#module-stp-params

If you specify the doc_url_text parameter in log.error call (for example, See {url} for the list of supported platforms), you’ll get a customized documentation pointer, for example:

[DOCS] See https://netlab.tools/module/stp/#stp-platform for the list of supported platforms