Debugging netlab
This document describes the debugging flags, options, and techniques available in netlab for troubleshooting issues and understanding internal behavior.
Command-Line Debugging Flags
Primary Debug Flag (--debug)
The main debugging flag in netlab is --debug [choices...]. You can specify multiple choices separated by commas.
The following commands have built-in --debug support:
Command |
Description |
|---|---|
Creates configuration files |
|
Start a lab |
|
Deploy initial device configurations |
|
Deploy custom configuration template to network devices |
|
Run validation tests specified in the lab topology |
You can specify these categories with the --debug flag (most categories are recognized by netlab create and netlab up commands, other commands implement a smaller subset of debugging options):
Choice |
Description |
|---|---|
|
Enable all debugging flags |
|
Debug addressing pools |
|
Debug IPAM logic |
|
Debug CLI actions |
|
Debug user/system defaults |
|
Debug netlab group processing |
|
Debug the core link transformation code |
|
Debug generic configuration module routines |
|
Debug plugin loading process and plugin calls |
|
Debug common Jinja2 templating routines |
|
Debug the data validation logic |
|
Debug VLAN module |
|
Debug VRF module |
|
Debug invocation of external programs |
|
Debug libvirt provider |
|
Debug containerlab provider |
|
Debug the ‘lab status’ code |
|
Debug device quirks code |
|
Debug search paths (helps troubleshoot custom templates) |
|
Debug loadable modules |
|
Debug LAG (Link Aggregation) functionality |
Usage Examples:
# Enable all debugging
netlab create --debug all topology.yml
# Debug specific areas
netlab up --debug cli,links
netlab initial --debug template -vv
# Debug addressing issues
netlab create --debug addressing,vlan
Verbose Flag (-v, --verbose)
The verbose flag is countable - you can use it multiple times for increased verbosity.
Level |
Usage |
Description |
|---|---|---|
Basic |
|
Basic verbose output |
Extra |
|
Extra verbose (prints command execution details) |
netlab up -v # Basic verbose
netlab up -vv # More verbose
netlab up -vvv # Extra verbose (shows command execution)
Other Useful Flags
Flag |
Description |
|---|---|
|
Enable basic logging |
|
Report only major errors, suppress most output |
|
Print commands that would be executed without running them |
# Dry run mode
netlab up --dry-run
netlab down --dry-run
netlab connect --dry-run host
Environment Variables
NETLAB_FAST_CONFIG
Enable fast configuration mode:
export NETLAB_FAST_CONFIG=1
ANSIBLE_STDOUT_CALLBACK
Control Ansible output format:
export ANSIBLE_STDOUT_CALLBACK=selective # Used for quiet mode
export ANSIBLE_STDOUT_CALLBACK=dense # Used for collect/tarball commands
Device-Specific Debugging
Cisco IOS/IOS XE
Add debug commands to execute during initial configuration:
nodes:
router1:
device: ios
ios.debug:
- ip routing
- bgp ipv4 unicast updates
FRRouting
Enable debug conditions:
nodes:
router1:
device: frr
frr.debug:
- bgp ipv4 unicast updates
Special Debugging Commands
Debug Command
Load and execute a command module without exception handling (useful for debugging module import errors):
netlab debug <command> <parameters>
Status Debugging
Show detailed lab status information, including logs:
netlab status --log
Validation Debugging
Generate debugging printouts for validation tests:
netlab validate -vv
Internal Debugging Flags
These flags are primarily used for internal testing and CI:
Flag |
Purpose |
|---|---|
|
Disable error header printing (internal testing) |
|
Raise warnings instead of printing them (CI flag) |
|
Raise exceptions instead of aborting (CI flag) |
Logging Configuration
netlab uses several logging levels and flags:
VERBOSE: Integer level (0-3+), controls verbosity of output
LOGGING: Boolean, enables basic logging
DEBUG: List of active debug flags
QUIET: Boolean, suppresses most output
You can programmatically check the above flags in your plugins as netsim.utils.log.flag. You can also check if a debug flag is active using:
from netsim.utils import log
if log.debug_active('cli'):
print("CLI debugging is active")
Getting Help
If you encounter issues that the above debugging tips can’t help you resolve:
Check the GitHub Issues and Discussions for similar problems
Create a new issue and follow the instructions in the issue template.