pyATS AEreport

26.3 · active · verified Thu Apr 16

pyATS AEreport is a sub-component of the Cisco pyATS (Python Automated Test System) ecosystem, specializing in result collection and reporting for network test automation. It integrates seamlessly with pyATS test runs to generate comprehensive HTML reports and other artifacts. pyATS, including AEreport, maintains a rapid release cadence, with updates often occurring monthly to introduce new features, parsers, and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic pyATS AEtest script that, when executed, implicitly uses pyATS AEreport to collect and format test results. The `pyats logs view --latest` command can then be used in the terminal to open the generated HTML report in a web browser, showcasing AEreport's output.

import os
import logging
from pyats import aetest
from genie.testbed import load

# Configure logging for better visibility
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

# Define a simple pyATS AEtest script
class CommonSetup(aetest.CommonSetup):
    @aetest.subsection
    def connect_to_devices(self, testbed):
        try:
            testbed.connect()
            logger.info("Successfully connected to devices.")
        except Exception as e:
            logger.error(f"Failed to connect to one or more devices: {e}")

class MyTestcase(aetest.Testcase):
    @aetest.test
    def verify_connectivity(self, testbed):
        for device in testbed.devices:
            if device.is_connected():
                self.passed(f"Device {device.name} is connected.")
            else:
                self.failed(f"Device {device.name} is NOT connected.")

class CommonCleanup(aetest.CommonCleanup):
    @aetest.subsection
    def disconnect_from_devices(self, testbed):
        for device in testbed.devices:
            if device.is_connected():
                device.disconnect()
                logger.info(f"Disconnected from device {device.name}.")

if __name__ == '__main__':
    # Example Testbed file content (save as 'testbed.yaml')
    # devices:
    #   router1:
    #     connections:
    #       cli:
    #         class: unicon.Unicon
    #         protocol: ssh
    #         ip: 10.0.0.1 # Replace with your device IP
    #     credentials:
    #       default:
    #         username: cisco
    #         password: cisco # Use environment variable or pyats secret for production

    # Create a dummy testbed.yaml for demonstration if it doesn't exist
    testbed_content = """
devices:
  loopback_device:
    type: linux
    connections:
      defaults:
        class: unicon.Unicon
        protocol: ssh
        # For a truly runnable example without a real device, mock or avoid connection.
        # This example assumes a simple mock or a non-connect test for quick demo.
        # In a real scenario, you'd point to a reachable device or a mocked one.
    credentials:
      default:
        username: {}
        password: {}
""".format(os.environ.get('TEST_USERNAME', 'mockuser'), os.environ.get('TEST_PASSWORD', 'mockpass'))

    with open('testbed.yaml', 'w') as f:
        f.write(testbed_content)

    # Load the testbed (dummy for this example)
    testbed = load('testbed.yaml')

    # Run the AEtest job. AEreport automatically collects results.
    aetest.main(testbed=testbed, ) # You would typically use pyats run job <script.py> for reporting
    
    # To view the generated report, run in your terminal:
    # pyats logs view --latest

view raw JSON →