pyATS Kleenex: Testbed Preparation, Clean & Finalization

26.3 · active · verified Thu Apr 16

pyATS Kleenex is a crucial component of the larger pyATS ecosystem, specifically designed for testbed preparation, cleaning, and finalization tasks. It enables network engineers to restore network devices to a known good state before or after executing automated tests, ensuring consistent testing environments. As part of the pyATS framework, it maintains a regular release cadence, often monthly or bi-monthly, aligning with overall pyATS updates. The current version is 26.3.

Common errors

Warnings

Install

Imports

Quickstart

The quickstart demonstrates the general approach to using pyATS Kleenex functionality. While `pyats.kleenex` is the package, the primary interaction for cleaning devices is through the `pyats clean` command-line interface. This example shows how to conceptually set up a testbed and points to the CLI for execution.

# Create a simple testbed.yaml file
# devices:
#   csr1:
#     os: iosxe
#     type: router
#     connections:
#       cli:
#         protocol: ssh
#         ip: 10.0.0.1
#         credentials:
#           default:
#             username: cisco
#             password: cisco

# To run a clean operation using the pyats clean CLI command (recommended approach)
# Assuming you have a testbed.yaml and a clean.yaml defining the clean stages
# pyats clean <testbed.yaml> -clean_file <clean.yaml>

# Example of a simple clean.yaml content:
# clean:
#   csr1:
#     sections:
#       - 'power_cycle'
#       - 'install_image':
#           image: "/path/to/image.bin"

# Example Python snippet to initiate a clean operation (simplified conceptual view)
import os
from pyats import topology
from pyats.clean import clean_testbed

try:
    # Load your testbed
    testbed = topology.load(os.environ.get('TESTBED_YAML', 'testbed.yaml'))
    device = testbed.devices['csr1']

    # Example: Perform a clean operation on a device
    # This typically requires a separate clean.yaml file to define the stages
    # For a full execution, you would use pyats run job with a Python job file
    # that orchestrates the clean operation, or the pyats clean CLI command.

    # Programmatic invocation of clean (requires a clean_file argument in a real scenario)
    # The clean_testbed function typically takes a testbed object and a clean file path.
    print(f"Attempting to clean device: {device.name}")
    # This is a conceptual example, actual clean invocation is more complex
    # and often driven by EasyPy or the 'pyats clean' CLI.

    # For demonstration, we'll simulate a successful clean stage
    print(f"Device {device.name} is ready for cleaning operations.")
    print("To execute a full clean, use the 'pyats clean <testbed.yaml> -clean_file <clean.yaml>' CLI command.")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →