Unicon and Genie Robot Framework for Network Automation – In this lesson, we will explore how to use Unicon to execute and configure network devices, and how Genie can parse and verify command outputs using structured data for easier and more reliable automated network testing and validation.

Unicon vs. Genie Robot Framework

In the previous section, we introduced the different components of the pyATS Robot Framework ecosystem — including pyATS, Unicon, Genie, and Genie APIs. We also demonstrated how the base pyATS Robot Framework can be used to load a testbed, connect to, and disconnect from devices, as well as to run external test cases. However, it’s important to note that pyATS itself cannot execute commands on devices or process command outputs.

In this section, we will focus on the Unicon Robot Framework and the Genie Robot Framework:

  • Unicon allows you to execute CLI commands, configure devices, and process raw outputs using tools like regular expressions.

  • Genie, on the other hand, not only executes commands but also structures the output into Python dictionaries, enabling much easier data extraction and validation. Genie also provides capabilities for verifying outputs using flexible, declarative conditions.

Together, these frameworks significantly extend the functionality of pyATS for automated network testing and validation.

pyATS Unicon and Genie Robot Frameworks
pyATS Unicon and Genie Robot Frameworks

🚀 Unicon Robot Framework

Unicon Robot Framework enables automated interaction with CLI-based network devices by allowing command execution, device configuration, and output handling. It supports serial and parallel command execution, making it ideal for scalable network testing and automation.

Important KeywordsDescription
execute "${command}" on device "${device}"Run a show or exec command on a device
configure "${config}" on device "${device}"Apply configuration mode commands
send "${command}" to device "${device}"Send raw command input (useful for edge cases)
execute "${command}" in parallel on devices "${devices}"Run commands concurrently across devices
enable output logging / disable output loggingTurn logging of command output on or off

Unicon Robot Framework Configuration Exmaple

In this Unicon Robot Framework example, the script connects to device R2, configures logging settings (logging buffered notifications and no logging console) using the configure keyword with a configuration list, and then verifies the changes using the execute keyword to run a show command, followed by should contain to check the output.

(majid) majid@majid-ubuntu:~/devnet/pyats$ cat 10.1.unicon_robot_keywords.robot
*** Settings ***
Library        ats.robot.pyATSRobot
Library        unicon.robot.UniconRobot

*** Variables ***
${testbed}         testbed.yaml
${device}          R2

*** Test Cases ***
Configure And Verify Logging
    use testbed "${testbed}"
    connect to device "${device}"

    # ✅ Configure logging settings
    ${config}=    Create List
    ...    logging buffered notifications
    ...    no logging console
    configure "${config}" on device "${device}"

    # ✅ Verify the applied logging config
    ${output}=    execute "show run | include logging" on device "${device}"
    log    ${output}
    should contain    ${output}    logging buffered notifications
    should contain    ${output}    no logging console

    disconnect from device "${device}"

Running the script with PYTHONPATH=. robot 10.1.unicon_robot_keywords.robot shows that the test case passes successfully, confirming that the logging configuration was applied and verified as expected.

(majid) majid@majid-ubuntu:~/devnet/pyats$ PYTHONPATH=. robot 10.1.unicon_robot_keywords.robot
==============================================================================
10.1.Unicon Robot Keywords
==============================================================================
Configure And Verify Logging                                          | PASS |
------------------------------------------------------------------------------
10.1.Unicon Robot Keywords                                            | PASS |
1 test, 1 passed, 0 failed
==============================================================================
Output:  /home/majid/devnet/pyats/output.xml
Log:     /home/majid/devnet/pyats/log.html
Report:  /home/majid/devnet/pyats/report.html

🤖 Genie Robot Framework

Genie Robot Framework provides structured parsing, learning, and verification of network device data. It enables execution of commands with output transformed into easily accessible data structures, supports running predefined triggers and verifications, and offers powerful querying and validation through DataQuery.

Important KeywordsPurpose
parse "${parser}" on device "${device}"Structured parsing of command output
learn "${feature}" on device "${device}"Learn device state (e.g., BGP, OSPF, etc.)
run trigger "${name}" on device "${device}"Run predefined triggers
run verification "${name}" on device "${device}"Run built-in verifications
dq queryQuery structured output with DataQuery
verify count "${number}" "${structure}"Assert counts in learned/parsed structures

Genie Robot Framework Configuration Exmaple

This Genie Robot Framework script demonstrates how to automate network device interactions by connecting to devices R1 and R2 using the connect to devices keyword. It uses the parse keyword to run and parse the output of show version on R1, then applies dq query to extract and log the software version from the parsed data. The script further uses the learn keyword to retrieve structured BGP information from R1 and performs verification checks with verify count to ensure the expected number of BGP neighbors and routes are present. Finally, it cleanly disconnects from both devices using disconnect from device.

(majid) majid@majid-ubuntu:~/devnet/pyats$ cat 10.3.pyats_robot_genie_keywords.robot
*** Settings ***
Library        ats.robot.pyATSRobot
Library        genie.libs.robot.GenieRobot
Library        unicon.robot.UniconRobot

*** Variables ***
${testbed}         testbed.yaml

*** Test Cases ***
Connect to Devices
    use genie testbed "${testbed}"
    connect to devices "R1;R2"

Parse Show Version
    ${output}=    parse "show version" on device "R1"
    Log    ${output}
    Set Suite Variable    ${parsed_output}    ${output}

Verify Version Info
    ${result}=    dq query    data=${parsed_output}    filters=contains('version').get_values('version')('version')
    Log    Version extracted: ${result}

Learn BGP on R1
    ${bgp_data}=    learn "bgp" on device "R1"
    Log    ${bgp_data}

Verify BGP Neighbor Count
    verify count "1" "bgp neighbors" on device "R1"

Verify BGP Routes Count
    verify count "0" "bgp routes" on device "R1"

Disconnect from Devices
    disconnect from device "R1"
    disconnect from device "R2"

# pyats run robot 10.2.pyats_robot_genie_keywords.robot

The script executed successfully with most test steps passing, including device connection, parsing of show version output, version verification, learning BGP data, and verifying BGP neighbor count. The only failure occurred during verification of BGP routes count, where the expected value was 0 but the actual count was 1. Devices were disconnected cleanly at the end

(majid) majid@majid-ubuntu:~/devnet/pyats$ PYTHONPATH=. robot 10.3.pyats_robot_genie_keywords.robot
==============================================================================
10.3.Pyats Robot Genie Keywords
==============================================================================
[ WARN ] Could not load the trigger datafile correctly, did you specify 'uut' device alias?
Connect to Devices                                                    | PASS |
------------------------------------------------------------------------------
Parse Show Version                                                    | PASS |
------------------------------------------------------------------------------
Verify Version Info                                                   | PASS |
------------------------------------------------------------------------------
Learn BGP on R1                                                       /home/majid/lib/python3.12/site-packages/genie/abstract/magic.py:334: UserWarning: Abstract values defined under "custom" for device R1
  warnings.warn('Abstract values defined under "custom" for '
Learn BGP on R1                                                       | PASS |
------------------------------------------------------------------------------
Verify BGP Neighbor Count                                             | PASS |
------------------------------------------------------------------------------
Verify BGP Routes Count                                               | FAIL |
Expected '0', but found '1'
------------------------------------------------------------------------------
Disconnect from Devices                                               | PASS |
------------------------------------------------------------------------------
10.3.Pyats Robot Genie Keywords                                       | FAIL |
7 tests, 6 passed, 1 failed
==============================================================================
Output:  /home/majid/devnet/pyats/output.xml
Log:     /home/majid/devnet/pyats/log.html
Report:  /home/majid/devnet/pyats/report.html
Back to: Network Automation with pyATS & Genie (in Progress) > pyATS Robot Framework

Leave a Reply

Your email address will not be published. Required fields are marked *


Post comment