Skip to content

aacarter1/brkato-1009

Repository files navigation

Network Automation Test Suite - Generated with GitHub Copilot

This repository contains a network automation test suite that was created during BRKATO-1009 at Cisco Live 2025. It is a session on code generation using GitHub Copilot and executing the test in CX Test Automation Manager (CXTM). The code demonstrates how generative AI can accelerate network automation development by creating Python helper functions and Robot Framework test cases. Also, the code is executed in CXTM to show how to streamline a centralized location to execute tests.

📁 Repository Contents

helper.py - Network Device Helper Functions

A Python module containing utility functions for network device automation using Cisco's pyATS/Genie framework:

  • connect_device(testbed_file, device_name) - Loads testbed configuration and establishes device connection
  • disconnect_device(device) - Cleanly disconnects from network device
  • parse_or_execute_command(device, command, parse) - Executes or parses commands based on flag
  • get_show_version(testbed_file, device_name) - Retrieves and parses device version information
  • get_bgp_summary(testbed_file, device_name) - Gets BGP summary for all VRFs
  • shutdown_interface(testbed_file, device_name, interface) - Administratively shuts down specified interface
  • clear_ip_bgp(testbed_file, device_name) - Clears BGP sessions

keywords.robot - Robot Framework Keywords

Robot Framework resource file that wraps Python helper functions into reusable keywords:

  • Run Show Version on Device - Executes show version and returns software version
  • Run BGP Show - Retrieves BGP summary status
  • Shut Interface - Shuts down the configured interface (eth1/1)
  • Run BGP Reset - Clears all BGP sessions

network_tests.robot - Test Cases

Robot Framework test suite containing network validation tests:

  • Validate Show Version on Device - Verifies device is running expected software version (10.3(1))
  • Validate BGP Status - Ensures BGP neighbors are not in Idle state
  • Test Shut Interface - Tests interface shutdown and BGP impact
  • BGP Reset - Tests BGP session reset functionality

testbed.yaml - Device Configuration

pyATS testbed file defining the target network device:

  • Device: Spine-1 (Nexus OS router)
  • Connection: SSH to 198.18.134.101
  • Credentials: admin/cisco

username_password.py - Secure Credential Management Example

Python module demonstrating secure credential input using the getpass module:

  • get_username_password() - Securely prompts for user credentials
    • Uses standard input() for username (visible)
    • Uses getpass.getpass() for password (hidden input)
    • Returns tuple of (username, password)
    • Prevents password from appearing in terminal or logs

This example shows how to:

  • Securely prompt users for credentials without exposing passwords
  • Use Python's built-in getpass module for hidden password input
  • Avoid hardcoding credentials in source code
  • Implement secure credential collection for network automation scripts

keys_secrets.py - Secure Key and Secret Storage Example

Python module demonstrating secure handling of API keys and secrets:

  • store_secrets_and_keys(secrets, keys) - Securely stores secrets using SHA-256 hashing
    • Takes lists of secrets and corresponding keys
    • Returns dictionary mapping keys to hashed secrets
    • Generates SHA-256 hash of the entire dictionary for integrity verification
    • Uses JSON serialization with sorted keys for consistent hashing

This example shows how to:

  • Hash sensitive data before storage
  • Create secure mappings between identifiers and secrets
  • Generate integrity checksums for stored data
  • Follow security best practices for credential management

🤖 GitHub Copilot Code Generation

This entire codebase was generated using GitHub Copilot prompts during a Cisco Live demonstration. The generation process showcased how AI can accelerate network automation development:

Generation Approach

  1. Comment-Driven Development - Each function was generated by writing descriptive comments first
  2. Incremental Building - Started with basic connectivity functions, then built more complex operations
  3. Framework Integration - Leveraged Copilot's knowledge of pyATS/Genie and Robot Framework patterns

Example Prompts Used

The comments in the code show the exact prompts used to generate each function:

# Write a method to load the testbed file, connect to the device passed in and return the device object
# Write a method called parse_or_execute_command that takes in the device object, command and parse flag...
# write a method called get_bgp_summary that takes in the testbed_file and device_name...

Benefits Demonstrated

  • Rapid Prototyping - Complete test suite generated in minutes
  • Best Practices - Copilot incorporated proper error handling and pyATS patterns
  • Documentation - Self-documenting code through descriptive function names and comments

🚀 Usage

Prerequisites

pip install pyats[full] genie robotframework

Running Tests

# Run all tests
robot network_tests.robot

# Run specific test
robot -t "Validate Show Version on Device" network_tests.robot

Using Helper Functions

from helper import get_show_version, get_bgp_summary

# Get device version
version = get_show_version('testbed.yaml', 'Spine-1')

# Check BGP status
bgp_status = get_bgp_summary('testbed.yaml', 'Spine-1')

🎯 Key Takeaways

This repository demonstrates how GitHub Copilot can:

  • Generate complete network automation workflows from natural language prompts
  • Integrate multiple frameworks (pyATS, Robot Framework) seamlessly
  • Produce production-ready code with proper error handling
  • Accelerate the development of network testing suites
  • Streamline the workflow from test case generation to execution in CX Test Automation Manager (CXTM)

The code serves as a practical example of AI-assisted network automation development, showing how generative AI tools can significantly reduce development time while maintaining code quality and best practices. This creates a streamlined process where test cases are generated with AI assistance and then executed centrally through CXTM for comprehensive network validation.


Generated during Cisco Live session on AI-powered code generation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors