Skip to main content

Architecture adapters for Network as Code (NaC) PyATS testing - auth classes, test base classes, and device resolvers

Project description

Tests Python Support

nac-test-pyats-common

⚠️ INITIAL DEVELOPMENT: This package is under active initial development and not yet ready for production use.

A shared library consolidating duplicated PyATS testing infrastructure across NAC (Network as Code) architecture repositories. This package serves as a Layer 2 adapter between architecture-specific test repositories (ACI, SD-WAN, Catalyst Center) and the core nac-test framework.

Overview

The nac-test-pyats-common package addresses the architectural challenge of duplicated pyats_common/ directories across NAC architecture repositories. It consolidates shared PyATS testing infrastructure—including authentication classes, test base classes, and device resolvers—into a centralized, maintainable package.

Problem Solved

Each NAC architecture repository previously contained duplicated PyATS infrastructure code:

  • ~90% of base test class code was identical across architectures
  • Bug fixes and improvements required manual propagation to all repos
  • Each architecture team maintained essentially the same code
  • Adding new architectures (ISE, Meraki, IOS-XE) compounded the duplication problem

Solution Architecture

┌─────────────────────────────────────────────────────────────────────┐
│               Layer 3: Architecture Repositories                     │
│     (nac-aci-terraform, nac-sdwan-terraform, nac-catc-terraform)    │
│                                                                      │
│  ┌─────────────────┐  ┌─────────────────┐                          │
│  │ Test Files      │  │ NAC Schema      │                          │
│  │ (verify_*.py)   │  │ Definitions     │                          │
│  └────────┬────────┘  └─────────────────┘                          │
│           │                                                          │
│           │ imports                                                  │
│           ▼                                                          │
└───────────┼──────────────────────────────────────────────────────────┘
            │
┌───────────▼──────────────────────────────────────────────────────────┐
│       Layer 2: nac-test-pyats-common (Architecture Adapters)        │
│                    DEPENDS ON nac-test                               │
│                                                                      │
│  • Architecture-specific authentication (APICAuth, VManageAuth)      │
│  • Architecture-specific test base classes (APICTestBase, etc.)      │
│  • Architecture-specific device resolvers (SDWANDeviceResolver)      │
│                       │                                              │
│                       │ imports NACTestBase, SSHTestBase, AuthCache │
│                       ▼                                              │
└───────────────────────┼──────────────────────────────────────────────┘
                        │
┌───────────────────────▼──────────────────────────────────────────────┐
│                Layer 1: nac-test (Core Framework)                    │
│                    Orchestration + Generic Infrastructure            │
│                                                                      │
│  • Test orchestration (discovering tests, running them)              │
│  • Testbed generation (generic device dict → PyATS YAML)            │
│  • Connection brokering (SSH connection pooling)                     │
│  • HTML report generation                                            │
│  • Generic base classes (NACTestBase, SSHTestBase)                  │
└─────────────────────────────────────────────────────────────────────┘

Supported Architectures

Currently Supported

  • ACI (Application Centric Infrastructure)

    • APICAuth - APIC authentication with cookie-based sessions
    • APICTestBase - Base class for ACI/APIC tests
    • ACIDeviceResolver - Device inventory from ACI data models
  • SD-WAN

    • VManageAuth - vManage authentication with token-based sessions
    • VManageTestBase - Base class for vManage API tests
    • SDWANSSHTestBase - Base class for SD-WAN D2D/SSH tests
    • SDWANDeviceResolver - Device inventory from sites.nac.yaml
  • Catalyst Center

    • CatalystCenterAuth - Token-based authentication (X-Auth-Token)
    • CatalystCenterTestBase - Base class for Catalyst Center API tests
    • CatalystCenterDeviceResolver - Device inventory from NAC schemas

Planned Support

  • ISE (Identity Services Engine)
  • Meraki
  • IOS-XE (Direct device access)

Installation

Python 3.10+ is required. Don't have Python 3.10 or later? See Python 3 Installation & Setup Guide.

pip install nac-test-pyats-common

This will automatically install the required dependencies:

  • nac-test~=1.1.0 - Core testing framework (brings PyATS as transitive dependency)
  • httpx>=0.28 - HTTP client for authentication

Usage

Import Pattern

Replace the old fragile imports from architecture repos:

# Old pattern (remove this)
from templates.catc.test.pyats_common.catc_base_test import CatalystCenterTestBase

# New pattern (use this)
from nac_test_pyats_common.catc import CatalystCenterTestBase

Example Test File

# In nac-catalystcenter-terraform/tests/templates/catc/test/api/verify_something.py

from nac_test_pyats_common.catc import CatalystCenterTestBase
from nac_test.pyats_core.reporting.types import ResultStatus
from pyats import aetest

class TestCatalystCenterFeature(CatalystCenterTestBase):
    """Test class for Catalyst Center feature verification."""

    @aetest.test
    def verify_feature(self):
        """Verify feature configuration."""
        # self.client is already configured with auth headers
        response = self.client.get("/api/v1/feature")

        if response.status_code == 200:
            self.result = ResultStatus.PASS
        else:
            self.result = ResultStatus.FAIL

API Structure

Authentication Classes

Each architecture provides an authentication class that handles controller-specific authentication:

from nac_test_pyats_common.aci import APICAuth
from nac_test_pyats_common.sdwan import VManageAuth
from nac_test_pyats_common.catc import CatalystCenterAuth

# Authentication is handled automatically when using test base classes
# But can be used directly if needed:
auth_data = CatalystCenterAuth.get_auth()  # Uses AuthCache internally

Test Base Classes

Test base classes extend NACTestBase from nac-test with architecture-specific setup:

from nac_test_pyats_common.catc import CatalystCenterTestBase

class MyTest(CatalystCenterTestBase):
    """Your test class."""

    @aetest.setup
    def setup(self):
        """Setup is handled by base class."""
        super().setup()
        # self.client is now available with auth headers configured
        # self.auth_data contains authentication tokens/cookies

Device Resolvers

Device resolvers parse NAC schemas to provide device inventory for SSH tests:

from nac_test_pyats_common.sdwan import SDWANDeviceResolver

# Used by nac-test orchestrator internally
devices = SDWANDeviceResolver.get_ssh_device_inventory(data_model)

Environment Variables

Each architecture requires specific environment variables for authentication:

Catalyst Center

  • CC_URL - Controller URL
  • CC_USERNAME - Username
  • CC_PASSWORD - Password
  • CC_INSECURE - Skip SSL verification (optional, default: "True")

SD-WAN

  • VMANAGE_URL - vManage URL
  • VMANAGE_USERNAME - Username
  • VMANAGE_PASSWORD - Password
  • VMANAGE_INSECURE - Skip SSL verification (optional, default: "True")

ACI

  • APIC_URL - APIC URL
  • APIC_USERNAME - Username
  • APIC_PASSWORD - Password
  • APIC_INSECURE - Skip SSL verification (optional, default: "True")

Development

Local Development Setup

# Clone the repository
git clone https://github.com/netascode/nac-test-pyats-common.git
cd nac-test-pyats-common

# Install in editable mode with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/unit/ -v
pytest tests/integration/ -v  # Requires nac-test

# Type checking
mypy --strict src/

# Linting
ruff check src/

Contributing

When contributing, understand which repository to modify:

Change Type Repository Example
Auth endpoint change nac-test-pyats-common Catalyst Center adds new auth API
Test base setup logic nac-test-pyats-common Add new setup step for all CC tests
Generic orchestration nac-test Change how tests are discovered/run
HTML report format nac-test Modify report template
Test file (verify_*.py) Architecture repo Add new verification test

Dependencies

  • nac-test~=1.1.0 - Core testing framework
    • Provides: NACTestBase, SSHTestBase, AuthCache, orchestration
    • Brings PyATS as transitive dependency
  • httpx>=0.28 - Modern async-capable HTTP client

Versioning

This package follows Semantic Versioning 2.0.0:

  • MAJOR: Breaking API changes
  • MINOR: New features, backward compatible
  • PATCH: Bug fixes, backward compatible

Compatibility Matrix

nac-test-pyats-common nac-test Required Notes
1.0.x ~=1.1.0 Initial release
1.1.x ~=1.1.0 New architecture added
2.0.x ~=2.0.0 Breaking changes

License

This project is licensed under the Mozilla Public License 2.0 (MPL-2.0) - see the LICENSE file for details.

Support

For issues, questions, or contributions, please visit the GitHub repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nac_test_pyats_common-0.3.0.tar.gz (56.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nac_test_pyats_common-0.3.0-py3-none-any.whl (55.8 kB view details)

Uploaded Python 3

File details

Details for the file nac_test_pyats_common-0.3.0.tar.gz.

File metadata

  • Download URL: nac_test_pyats_common-0.3.0.tar.gz
  • Upload date:
  • Size: 56.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for nac_test_pyats_common-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a53d1bb12e247c832efe66945a7042ef4e1e33b8d5276afb375ad91f227b8748
MD5 8c7c31b25099763fb4ca6a828c4f4724
BLAKE2b-256 baaffa4ea391ebb43feb108bf39e008268815b19c24bece741d098349ec034c0

See more details on using hashes here.

File details

Details for the file nac_test_pyats_common-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: nac_test_pyats_common-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 55.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for nac_test_pyats_common-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20f67cf19a100258b3e66af1196e5c8cfc98d9b726d8770d3065084c4a450ee6
MD5 cd332b3ed80ba4b721eb28de11673b11
BLAKE2b-256 e3c4157014d4b67de1598b1bc6533f6e71807d710a2ecc1758b95d7a13d4bbca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page