pyATS Reporter
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
-
Failed while bringing device to "any" state
cause This usually indicates a connectivity issue (e.g., SSH unreachable, incorrect credentials, firewall blocking).fixFirst, verify basic network connectivity (ping, telnet/ssh). Then, double-check testbed file (IPs, credentials, OS/platform settings) and ensure SSH access is fully functional and not blocked by firewalls. -
ERROR: Command '['pyats', 'run', 'job', ...]']' failed with exit code 1. Check logs for details.
cause A generic error indicating a failure during job execution, which could be due to issues in the test script, testbed, or environment. The Reporter component will capture more specific details.fixAlways check the detailed logs generated by pyATS in the run directory (usually `archive/<timestamp>/<job_name>/log/`). Use `pyats logs view` to open the interactive HTML report, which provides comprehensive information on failures. -
Command failed: pip install pyats[full] ERROR: zsh: no matches found: pyats[full]
cause This error occurs when using Zsh shell on macOS or Linux, as the `[` and `]` characters are treated as special characters for globbing.fixQuote the package name to prevent shell interpretation: `pip install 'pyats[full]'`.
Warnings
- breaking Python 3.6 reached End-of-Life. pyATS and pyats-reporter no longer support Python 3.6 after April 2022. Users must upgrade to Python 3.8 or newer.
- gotcha pyATS, including pyats-reporter, does not officially support Windows operating systems. It is designed for Linux and macOS environments.
- gotcha Testbed YAML files are strict. Common mistakes include incorrect indentation, mismatching device names in the YAML with the actual device hostnames, or improper credential handling.
- deprecated As of pyATS 22.3, ReporterServer was modified to only generate `reporter.log` when running in verbose mode with the `-v` option.
Install
-
pip install pyats-reporter -
pip install pyats[full]
Imports
- Reporter
from pyats.reporter import Reporter
Quickstart
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.")