Genie Libs SDK: Triggers and Verifications

26.3 · active · verified Thu Apr 16

Genie.libs.sdk is a sub-component of the Cisco pyATS and Genie framework, providing a rich library of pre-built 'Triggers' and 'Verifications'. These are reusable test cases and automation actions designed to facilitate rapid development, simplify test automation, and validate network device states. The library is actively maintained by Cisco Systems Inc., with frequent releases aligning with the broader pyATS/Genie ecosystem (typically monthly or bi-monthly major versions, currently at 26.3).

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load a testbed and execute a pre-built 'Trigger' from `genie.libs.sdk` using the `gRun` function from `genie.harness.main`. It includes a minimal `testbed.yaml` example and uses `TriggerReload` as a representative trigger. For actual execution, ensure a reachable network device configured in the testbed and necessary environment variables for credentials.

import os
from genie.testbed import load
from genie.harness.main import gRun
from genie.libs.sdk.triggers.template.trigger_reload import TriggerReload

# Create a dummy testbed.yaml for demonstration purposes
# In a real scenario, this would be a network device testbed file.
# Ensure your environment variables are set for device credentials.
# E.g., export PYATS_USERNAME=admin, export PYATS_PASSWORD=Cisco123
testbed_content = '''
devices:
  R1:
    os: iosxe
    type: router
    connections:
      cli:
        protocol: ssh
        ip: 127.0.0.1
        port: 2222 # Use a mock SSH server or a reachable device
    credentials:
      default:
        username: ${PYATS_USERNAME}
        password: ${PYATS_PASSWORD}
'''

with open('testbed.yaml', 'w') as f:
    f.write(testbed_content)

# Set dummy environment variables if not already set
os.environ.setdefault('PYATS_USERNAME', 'mockuser')
os.environ.setdefault('PYATS_PASSWORD', 'mockpass')

def main():
    # Load the testbed from the YAML file
    testbed = load('testbed.yaml')

    # Define the trigger to run
    # In a real scenario, this would target a specific device and its OS
    # For this example, we assume R1 is the 'uut' (unit under test) by default for TriggerReload
    # A custom datafile might be needed for specific trigger parameters or device mappings
    
    # Execute the trigger using gRun. 
    # The TriggerReload acts as a placeholder for demonstration.
    # For a true reload, 'R1' would need to be a real device and reachable.
    try:
        print("\n--- Running TriggerReload on R1 ---")
        gRun(testbed=testbed, trigger_uids=["TriggerReload"], trigger_datafile="""
extends: "%CALLABLE{genie.libs.sdk.genie_yamls.datafile(trigger)}"
TriggerReload:
  devices:
    R1:
      command: 'reload'
        """
        )
        print("TriggerReload completed (or skipped if no real device was found).")
    except Exception as e:
        print(f"An error occurred during gRun: {e}")

if __name__ == '__main__':
    main()

view raw JSON →