pyATS Reporter

26.3 · active · verified Thu Apr 16

pyATS Reporter is a sub-component of the broader pyATS (Python Automated Test System) ecosystem, specializing in result collection and reporting for network automation tests. The pyATS framework itself is an end-to-end testing solution developed by Cisco Systems Inc., designed for data-driven, reusable, and scalable testing, suitable for Agile development iterations. The library is actively maintained with frequent updates, with the current version being 26.3, and requires Python 3.8 or higher.

Common errors

Warnings

Install

Imports

Quickstart

The pyATS Reporter primarily functions as part of a larger pyATS test execution. This quickstart demonstrates how to set up and run a minimal pyATS job, which will automatically generate a report using `pyats-reporter` capabilities. The output can then be viewed through the `pyats logs view` command-line tool. A placeholder IP is used; replace with a reachable device or use pyATS mocking for actual execution without a physical device. Make sure to set `PYATS_TESTBED_PASSWORD` environment variable for the testbed credentials if running against a real device.

import os
import time
from pyats import aetest
from pyats.topology import loader

# Create a dummy testbed.yaml file for demonstration
with open('testbed.yaml', 'w') as f:
    f.write('''
# Sample Testbed for pyATS Reporter Quickstart
testbed:
  name: my_testbed
  credentials:
    default:
      username: admin
      password: ${PYATS_TESTBED_PASSWORD}
  devices:
    R1:
      type: router
      os: iosxe
      connections:
        cli:
          protocol: ssh
          ip: 10.1.1.1 # Placeholder IP, replace with a reachable device or mock
''')

# Create a simple AEtest job file
with open('my_test_job.py', 'w') as f:
    f.write('''
from pyats import aetest
from pyats.topology import loader

class CommonSetup(aetest.CommonSetup):
    @aetest.subsection
    def connect_to_devices(self, testbed):
        aetest.loop.mark(self.parent.testcases.test_basic_connectivity, device=testbed.devices.values())
        for device in testbed.devices.values():
            self.parent.parameters.update(device=device)
            print(f"Attempting to connect to {device.name}")
            # In a real scenario, this would attempt a connection.
            # For quickstart, we'll simulate success.
            # device.connect()
            print(f"Simulated connection to {device.name} successful.")

class TestBasicConnectivity(aetest.Testcase):
    @aetest.test
    def test_ping_loopback(self, device):
        print(f"Testing connectivity for {device.name}")
        # In a real scenario, this would execute a command like `device.ping('1.1.1.1')`
        # For quickstart, we'll simulate a passing test.
        if device.name == 'R1':
            self.passed(f"Simulated ping successful on {device.name}")
        else:
            self.failed(f"Simulated ping failed on {device.name}")

class CommonCleanup(aetest.CommonCleanup):
    @aetest.subsection
    def disconnect_from_devices(self, testbed):
        for device in testbed.devices.values():
            print(f"Simulated disconnection from {device.name}")
            # In a real scenario: device.disconnect()
''')

# Set a dummy password for the quickstart's testbed if not already set
os.environ['PYATS_TESTBED_PASSWORD'] = os.environ.get('PYATS_TESTBED_PASSWORD', 'your_password_here')

print("Running pyATS job... This will generate a report.")
# To run the job and generate a report, use the pyats CLI command
# In a real environment, you'd run this from your terminal:
# pyats run job my_test_job.py --testbed-file testbed.yaml
# For this quickstart, we'll just demonstrate the files are set up.

print("A testbed.yaml and my_test_job.py have been created.")
print("To run the test and generate a report, execute in your terminal:")
print("  pyats run job my_test_job.py --testbed-file testbed.yaml")
print("After running, view the report with:")
print("  pyats logs view")
print("Cleanup: Remove 'testbed.yaml' and 'my_test_job.py' if desired.")

view raw JSON →