Devnet
pyATS
4 Network Automation Testing Lab Part 1

Network Automation Testing with pyATS

pyATS (Python Automated Test Systems) provides a powerful platform for automating network tests. Originally developed by Cisco Engineering using Python 3, pyATS has evolved into a widely adopted tool with thousands of test developers and extensive libraries.

The framework of pyATS is designed to support agile, data-driven, and reusable testing, making it suitable for various development cycles. Its flexibility allows developers to scale from simple, linear test cases to complex, asynchronous test suites.

Scenario

Imagine you're tasked with managing and testing your company's network configuration. Leveraging pyATS for automation, you aim to streamline testing processes, benefitting from structured data output and seamless integration with existing CI/CD and reporting tools. As you delve into pyATS, you'll first explore how to define devices and connectivity using pyATS objects.

Activity Objective

The objective of this activity is to familiarize yourself with pyATS by understanding how it defines devices and connectivity. You'll create a custom testbed file and scripts, run jobs, and validate testbed parameters and topology.

Describe pyATS Topology Objects and Devices

In pyATS, topology information is represented using objects, facilitating a more intuitive and flexible approach. Let's explore the main blocks in the testbed schema:

Testbed Block

The testbed block holds common details across the testbed, including naming conventions and credentials.

testbed:
  name: pyATS_IOS_Example_Testbed
  credentials:
    default:
      username: cisco
      password: cisco

Devices Block

Devices are defined within the devices block, specifying connection methods, addressing, OS types, and other specifics.

devices:
  R1:
    connections:
      defaults:
        class: 'unicon.Unicon'
      a:
        protocol: ssh
        ip: 172.21.1.21
        port: 22
    type: iosxe
    os: iosxe

Topology Block

The topology block describes device interconnections and interfaces.

topology:
  R1:
    interfaces:
      GigabitEthernet1:
        ipv4: 172.21.1.21/24
        link: n1
        type: ethernet

Ensure device names match configured hostnames and adhere to case sensitivity.

Activity Verification

Upon completion:

  • You've identified and understood the main blocks in the testbed YAML schema.
  • You're able to describe the functions of the testbed, devices, and topology block.

Create a Topology with the Topology Module and Classes

Now, let's delve into creating a custom testbed file and scripts using pyATS technology:

Part 1: Manually Create Testbed File

  1. Activate the virtual environment.
  2. Use pyats create command to interactively create the testbed file.
  3. Enter device details for R1, R2, and R3.
  4. Open and modify the testbed file in Visual Studio Code.
  5. Review and complete the testbed file, ensuring accuracy and completeness.

Part 2: Relate Testscript Functions

Review the demonstration testscript (my_pyats_script.py) to understand its structure and function. Note the use of the testbed parameter and topology loader.

  1. Open my_pyats_script.py and review its contents.
  2. Familiarize yourself with the preamble and testing sections.
  3. Review the Common Setup Section and its subsections, noting dependencies.
  4. Understand how the testscript interacts with the testbed parameter and topology loader.

Upon completion:

  • You've successfully reviewed the testscript and understood its relation to the testbed parameter and topology loader.
  • You're ready to run the testscript and validate its functionality.

Stay tuned for Part 2 of this activity, where we'll run the testscript and observe testcase execution in standalone mode.