Genie API Robot Framework is the latest pyATS Robot framework for automating network test cases. Building on previous lessons covering pyATS, Unicon, and Genie Robot Frameworks, this framework provides numerous keywords to retrieve information and configure devices across different operating systems, including IOS, IOS XE, NX-OS, and IOS XR. In this lesson, we will use basic APIs to get interface details and BGP routes from devices, demonstrating the core principles of working with Genie APIs in practice.
pyATS Genie API Robot Framework Fundamental
pyATS Robot Frameworks Overview
As discussed in previous lessons, there are four pyATS Robot Frameworks: pyATS, Unicon, Genie, and Genie API.
pyATS allows you to load testbeds, connect or disconnect devices, and run test cases.
Unicon enables you to send CLI commands and configure devices.
Genie can parse CLI command outputs into structured data or learn a feature in a structured way, which can then be easily processed and filtered using the
dq
filter.
These three frameworks were covered in the previous lesson.
In this lesson, we will focus on the Genie API Robot Framework, which enables communication with devices via APIs instead of the CLI. This approach allows you to send commands or configure devices through a single API that works across multiple operating systems, including IOS, IOS XE, IOS XR, and NX-OS.
Framework | Main Purpose | Key Capabilities |
---|---|---|
pyATS | Testbed & Testcases | Load testbeds, connect/disconnect devices, run test cases |
Unicon | CLI Control | Send CLI commands, configure devices |
Genie | Parsing & Learning | Parse CLI output into structured data, learn features, filter with dq |
Genie API | API-Based Control | Send commands and configure devices via API |
Genie API Robot Framework Fundamental
There is a comprehensive list of keywords supported by the Genie API Robot Framework at the following link. These keywords can be used to monitor, troubleshoot, configure network devices, or even delete configurations:
Genie API Robot Framework Keywords
To show how these keywords can be used in practice, I have selected a few examples and demonstrated their use in a real testcase.
The following sample script illustrates the use of three Genie API keywords:
Get Interface Names
– Retrieves the names of all interfaces on the device.Get Interface Information
– Retrieves detailed information for a specified list of interfaces.Get Bgp Best Routes
– Retrieves the best BGP routes to a neighbor.
This simple script demonstrates how these keywords can be applied in a real-world scenario.
(majid) majid@majid-ubuntu:~/devnet/pyats$ cat 10.4.pyats_genie_api_robot_keywords.robot *** Settings *** Library ats.robot.pyATSRobot #Library unicon.robot.UniconRobot Library genie.libs.robot.GenieRobot Library genie.libs.robot.GenieRobotApis *** Variables *** ${testbed} testbed.yaml ${neighbor_ip} 1.1.1.1 *** Test Cases *** Connect to Devices use genie testbed "${testbed}" connect to device "R2" *** Test Cases *** Verify Interfaces Names With Genie API Log To Console \n=== Starting Interfaces Check === ${interfaces}= Get Interface Names device=R2 Set Suite Variable ${interfaces} Log To Console \nInterfaces:\n${interfaces} Verify Interfaces Info With Genie API Log To Console \n=== Starting Interfaces Info Check === ${info}= Get Interface Information device=R2 interface_list=${interfaces} FOR ${name} ${data} IN &{info} Run Keyword If '${data.oper_status}' != 'up' or '${data.line_protocol}' != 'up' Fail Interface ${name} is down (oper_status=${data.oper_status}, line_protocol=${data.line_protocol}) END Log To Console All interfaces are UP Verify BGP Routes With Genie API Log To Console \n=== Starting BGP Route Check === ${routes}= Get Bgp Best Routes device=R2 neighbor_address=${neighbor_ip} Log To Console \nBGP Best Routes for neighbor ${neighbor_ip}:\n${routes}
Get Interface Names
The first Genie API keyword used in the sample script is “Get Interface Names”, which retrieves the names of all interfaces on the device.
To get the interface names of a device, I used the keyword "${interfaces}= Get Interface Names device=R2".
I found the syntax for this keyword by checking “Get Interface Names” in the Genie API portal. From there, I was directed to the detailed API documentation, which explains that this API supports both IOS XE and NX-OS platforms.
By clicking “View Source”, I could view the related function, which shows that the only required argument is the device name.
The retrieved interface names are stored in the variable ${interfaces}
, which will later be used in the testcase to gather detailed information for each interface.
def get_interface_names(device): """Gets the names of all interfaces on the device Args: device (obj): Device object Returns: list: List of interface names """
Get Interface Information
The second Genie API keyword used in the sample script is “Get Interface Information”, which retrieves detailed information for a specified list of interfaces.
To do this, I used the keyword "${info}= Get Interface Information device=R2 interface_list=${interfaces}".
I found the syntax for this keyword by checking “Get Interface Information” in the Genie API portal. From there, I was directed to the detailed API documentation, which explains that this API supports IOS, IOS XE, IOS XR, and NX-OS platforms.
By clicking “View Source”, I could view the related function. The function shows that there are two required arguments: the device name and the list of interfaces. The list of interfaces is obtained from the previous step, and the device name is manually set as "R2"
.
The retrieved interface information is stored in the variable ${info}
, which will later be used to determine whether the interfaces are up or down.
def get_interface_information(device, interface_list): """ Get interface information from device for a list of interfaces Args: List['string']: Interfaces to query information on device ('obj'): Device object Returns: List containing Dictionaries for sucesses """
Get Bgp Best Routes
Similarly, the third Genie API keyword used in the sample script is “Get Bgp Best Routes”, which retrieves the best BGP routes to a specified neighbor.
To do this, I used the keyword "${routes}= Get Bgp Best Routes device=R2 neighbor_address=${neighbor_ip}".
I found the syntax for this keyword by checking “Get Bgp Best Routes” in the Genie API portal. From there, I was directed to the detailed API documentation, which explains that this API supports only the IOS XE platform.
By clicking “View Source”, I could view the related function. The function shows that there are two required arguments: the device name and the BGP neighbor address. In this case, both values are provided manually — the device name as "R2"
and the neighbor address as a variable ${neighbor_ip}
, which is defined as "1.1.1.1"
.
The retrieved route information is stored in the variable ${routes}
, which will be displayed in the output.
def get_bgp_best_routes( device, neighbor_address, rd=None, address_family=None, vrf=None ):
Verify Genie API Sample Script
To verify the operation of the script, we executed it and confirmed that all steps completed successfully:
Connect to Devices – Establishes a connection to the target device (
R2
) before running any tests.Verify Interfaces Names With Genie API – Uses the Get Interface Names keyword to retrieve all interface names from the device. In this run, the returned interfaces included
GigabitEthernet1
,GigabitEthernet2
, and several loopbacks.Verify Interfaces Info With Genie API – Uses the Get Interface Information keyword to check the operational status of each interface. All interfaces were confirmed to be UP.
Verify BGP Routes With Genie API – Uses the Get Bgp Best Routes keyword to retrieve the best BGP routes to the neighbor
1.1.1.1
. In this run, the returned routes were10.10.10.10/32
(twice).
(majid) majid@majid-ubuntu:~/devnet/pyats$ PYTHONPATH=. robot 10.4.pyats_genie_api_robot_keywords.robot ============================================================================== 10.4.Pyats Genie Api Robot Keywords ============================================================================== [ WARN ] Could not load the trigger datafile correctly, did you specify 'uut' device alias? Connect to Devices | PASS | ------------------------------------------------------------------------------ Verify Interfaces Names With Genie API === Starting Interfaces Check === ... Interfaces: ['GigabitEthernet1', 'GigabitEthernet2', 'GigabitEthernet3', 'Loopback0', 'Loopback2', 'Loopback3', 'Loopback100', 'Loopback101', 'NVI0'] Verify Interfaces Names With Genie API | PASS | ------------------------------------------------------------------------------ Verify Interfaces Info With Genie API === Starting Interfaces Info Check === ...All interfaces are UP Verify Interfaces Info With Genie API | PASS | ------------------------------------------------------------------------------ Verify BGP Routes With Genie API === Starting BGP Route Check === .. BGP Best Routes for neighbor 1.1.1.1: ['10.10.10.10/32', '10.10.10.10/32'] Verify BGP Routes With Genie API | PASS | ------------------------------------------------------------------------------ 10.4.Pyats Genie Api Robot Keywords | PASS | 4 tests, 4 passed, 0 failed ============================================================================== Output: /home/majid/devnet/pyats/output.xml Log: /home/majid/devnet/pyats/log.html Report: /home/majid/devnet/pyats/report.html