pyATS Blitz is a YAML-driven automation tool that enables network engineers to create and execute test cases without requiring extensive programming knowledge. In this section, we will explore the structure of Blitz and walk through a practical example.

pyATS Blitz Overview

pyATS Blitz is a feature of the Cisco pyATS framework that enables network engineers to automate network testing through a low-code, YAML-based approach. It allows users to define test cases using human-readable YAML files, eliminating the need for extensive programming knowledge.

Blitz YAML File Structure

A Blitz YAML file follows a structured format:

# Name of the testcase
Testcase1:
  # Leave this as is for most use cases
  source: pkg: genie.libs.sdk
  class: triggers.blitz.blitz.Blitz

  # Field containing all the sections
  test_sections:
    # Section name - Can be any name, it will show as the first section
    # of the testcase
    section_one:
      - ">>>> <ACTION> <<<<"
      - ">>>> <ACTION> <<<<"
      - ">>>> <ACTION> <<<<"

    section_two:
      - ">>>> <ACTION> <<<<"
      - ">>>> <ACTION> <<<<"

Testcases: The top-level structure, consisting of one or more test sections.

Test Sections: Contain a sequence of actions, which are the core tasks executed during testing (e.g., sending commands, parsing output).

pyATS Blitz File Structure
pyATS Blitz File Structure

Common Actions

Actions are the core components of Blitz and define the operations performed during a test. Some of the most commonly used actions include:

execute: Runs CLI commands on a device.

configure: Applies configuration commands.

parse: Parses command output using pre-defined parsers.

learn: Gathers operational data using the Genie learn feature.

api: Gathers operational data or configure devices using pyATS pre-defined APIs.

diff: Compares current data with previously saved snapshots.

Output Filtering and Reuse

The output of each action can be filtered and reused in the same or other test sections. Blitz supports several filtering methods to extract specific information:

Dq Filter: Extracts values from structured data such as dictionaries or parsed JSON.

RegEx Filter: Extracts string patterns using regular expressions.

List Filter: Targets and selects specific elements from a list.

These filters help refine action outputs for validation, comparisons, or to pass values into other actions.

Advanced Actions and Capabilities

In addition to basic actions, Blitz supports advanced features for more dynamic and powerful test automation:

Parallel Execution: Runs multiple actions simultaneously to improve test efficiency.

Looping: Repeats actions based on items in a list, dictionary, or evaluated condition.

Run Conditions: Executes actions conditionally based on logical evaluations or previous results.

Prompt Handling: Automates responses to interactive device prompts (e.g., confirmation messages).

pyATS Blitz Example

To better understand how pyATS Blitz works, let’s walk through a practical example. In the next lesson, we’ll explore additional examples to deepen the understanding.

This Blitz YAML defines a test case named Testcase1. It performs the following steps:

(majid) majid@majid-ubuntu:~/devnet/pyats$ cat 9.2.blitz_execute.yaml
Testcase1:
  source:
    pkg: genie.libs.sdk
    class: triggers.blitz.blitz.Blitz
  trigger_uids:
    - Testcase1
  test_sections:
    - execute_commands:
        - execute:
            device: R1
            command: show ip interface brief
            save:
              - variable_name: IPs
                regex_findall: (\d+\.\d+\.\d+\.\d+)
              - variable_name: execute_output
        - print:
            item:
              value:
                - "!!!! IP addresses: %VARIABLES{IPs}"
                - "!!!! show ip interface brief: %VARIABLES{execute_output}"
  • Execute a CLI command on device R1:

    • Command: show ip interface brief
    • The command output is:
      • Saved in a variable called execute_output
      • Filtered using RegEx to extract all IP addresses (\d+\.\d+\.\d+\.\d+), which are saved in the IPs variable

    Print extracted values:

    • Prints a message displaying the list of extracted IP addresses:
      “!!!! IP addresses: %VARIABLES{IPs}”
    • Prints the full command output:
      “!!!! show ip interface brief: %VARIABLES{execute_output}”

Run Blitz YAML file using “pyats run genie” command

A Blitz YAML file can be executed using the “pyats run genie” command directly, or by referencing it within a Genie job file for more advanced control and customization.

(majid) majid@majid-ubuntu:~/devnet/pyats$ pyats run genie --testbed-file testbed.yaml --trigger-datafile 9.2.blitz_execute.yaml --trigger-uids Testcase1

(majid) majid@majid-ubuntu:~/devnet/pyats$ pyats run genie –testbed-file testbed.yaml –trigger-datafile 9.2.blitz_execute.yaml –trigger-uids Testcase1

–testbed-file: Specifies the testbed file with device info.

–trigger-datafile: Points to the Blitz YAML file containing test actions.

–trigger-uids: Runs only the specified test case or section (Testcase1).

(majid) majid@majid-ubuntu:~/devnet/pyats$ pyats run genie --testbed-file testbed.yaml --trigger-datafile 9.2.blitz_execute.yaml --trigger-uids Testcase1
...
2025-06-13T15:47:41: %AETEST-INFO: |                      Starting section execute_commands                       |
2025-06-13T15:47:41: %AETEST-INFO: +------------------------------------------------------------------------------+
2025-06-13T15:47:41: %AETEST-INFO: +..............................................................................+
2025-06-13T15:47:41: %AETEST-INFO: :           Starting STEP 1: Starting action execute on device 'R1'            :
2025-06-13T15:47:41: %AETEST-INFO: +..............................................................................+
2025-06-13T15:47:41: %AETEST-INFO: +..............................................................................+
2025-06-13T15:47:41: %AETEST-INFO: :        Starting STEP 1.1: Executing 'show ip interface brief' on 'R1'        :
2025-06-13T15:47:41: %AETEST-INFO: +..............................................................................+

2025-06-13 15:47:41,936: %UNICON-INFO: +++ R1 with via 'cli': executing command 'show ip interface brief' +++
show ip interface brief
Interface              IP-Address      OK? Method Status                Protocol
GigabitEthernet1       10.13.14.16     YES NVRAM  up                    up
GigabitEthernet2       10.13.15.16     YES NVRAM  up                    up
GigabitEthernet3       192.168.172.1   YES manual up                    up
Loopback0              1.1.1.1         YES NVRAM  up                    up
Loopback10             10.10.10.10     YES NVRAM  up                    up
Loopback100            10.10.100.100   YES manual up                    up
Loopback101            192.168.173.1   YES manual up                    up
R1#
2025-06-13T15:47:42: %AETEST-INFO: The result of STEP 1.1: Executing 'show ip interface brief' on 'R1' is => PASSED
...
2025-06-13T15:47:42: %AETEST-INFO: The result of STEP 1: Starting action execute on device 'R1' is => PASSED
2025-06-13T15:47:42: %AETEST-INFO: +..............................................................................+
2025-06-13T15:47:42: %AETEST-INFO: :                    Starting STEP 2: Starting action print                    :
2025-06-13T15:47:42: %AETEST-INFO: +..............................................................................+
2025-06-13T15:47:42: %GENIE-INFO: The value of item: ["!!!! IP addresses: ['10.13.14.16', '10.13.15.16', '192.168.172.1', '1.1.1.1', '10.10.10.10', '10.10.100.100', '192.168.173.1']", '!!!! show ip interface brief: Interface              IP-Address      OK? Method Status                Protocol\r\nGigabitEthernet1       10.13.14.16     YES NVRAM  up                    up      \r\nGigabitEthernet2       10.13.15.16     YES NVRAM  up                    up      \r\nGigabitEthernet3       192.168.172.1   YES manual up                    up      \r\nLoopback0              1.1.1.1         YES NVRAM  up                    up      \r\nLoopback10             10.10.10.10     YES NVRAM  up                    up      \r\nLoopback100            10.10.100.100   YES manual up                    up      \r\nLoopback101            192.168.173.1   YES manual up                    up']
2025-06-13T15:47:42: %AETEST-INFO: The result of STEP 2: Starting action print is => PASSED
...

Run Blitz YAML file using Genie Job File

This is a Genie job file used to run a Blitz test programmatically. It does the following:

(majid) majid@majid-ubuntu:~/devnet/pyats$ cat 9.run_blitz.py
import os
from genie.harness.main import gRun

def main(runtime):
    gRun(
        trigger_datafile='9.2.blitz_execute.yaml',
        testbed='testbed.yaml',
        trigger_uids=['Testcase1']
    )
(majid) majid@majid-ubuntu:~/devnet/pyats$ pyats run job 9.run_blitz.py
Back to: Network Automation with pyATS & Genie (in Progress) > pyATS Blitz

Leave a Reply

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


Post comment