[Day #74 PyATS Series] Validate Redundant Power Supply and Fans Status Using pyATS for Cisco [Python for Network Engineer]

[Day #74 PyATS Series] Validate Redundant Power Supply and Fans Status Using pyATS for Cisco [Python for Network Engineer]


Introduction on the Key Points

In any enterprise-grade network deployment, hardware reliability is critical. Redundant power supplies and functional fans are essential to ensure high availability and prevent unexpected downtime in switches, routers, and firewalls.

Today, l will deep-dive into automating the validation of redundant power supply and fan status using pyATS, specifically focused on Cisco devices, although the methodology is vendor-agnostic and adaptable to other platforms like Arista, Juniper, and FortiGate.

This workflow enables network engineers to shift from manual CLI checks—such as show environment power and show environment fan—to a scalable, automated framework that performs periodic health audits. We’ll combine CLI and GUI validations where applicable, extract relevant outputs, normalize them, and check against expected states.

If you’re building automation skills in Python for Network Engineer roles, this masterclass Article is a powerful real-world example you can use as a template in your projects.


Topology Overview

We’ll set up a lab with the following topology focused solely on monitoring health and not data flow:

  • Cisco Catalyst 9300: Key device with dual redundant power supplies and multiple cooling fans.
  • Automation Server: Runs pyATS automation, connects via SSH and API to Cisco device.

Objective:

  • Check redundancy of power supply units (PSUs).
  • Check operational status of cooling fans.
  • Report any failures or non-optimal statuses with clear PASS/FAIL results.

Topology & Communications

Management Protocols:

  • CLI (SSH) for environmental status commands.
  • HTTPs GUI (optional) for extracting environmental summary via web interface screenshots.

Communication Flow:

  1. pyATS connects to the Cisco device using credentials from testbed.yml.
  2. Runs environmental commands to fetch PSU and fan status.
  3. Parses the CLI output into a structured dictionary.
  4. Validates status against expected “OK” values.
  5. Optionally captures GUI screenshots for visual verification.

Workflow Script

from genie.testbed import load
from pyats.aetest import Testcase, test, main
import re

EXPECTED_POWER_STATUS = ['OK', 'Normal']
EXPECTED_FAN_STATUS = ['OK', 'Normal']

class HardwareHealthValidation(Testcase):

    @test
    def connect_and_extract(self, testbed):
        self.env_status = {}
        device = testbed.devices['catalyst9300']
        device.connect(log_stdout=False)

        # Extract Power Supply Status
        psu_output = device.execute('show environment power')
        self.env_status['power'] = psu_output

        # Extract Fan Status
        fan_output = device.execute('show environment fan')
        self.env_status['fan'] = fan_output

        # Optionally, capture GUI Screenshot (if integrated)
        # device.api.take_screenshot('/tmp/env_status.png')

    @test
    def validate_power_status(self):
        print("\n--- Validating Power Supply Status ---")
        psu_output = self.env_status.get('power', '')

        for line in psu_output.splitlines():
            match = re.search(r'Power Supply\s+(\S+)\s+Status:\s+(\S+)', line)
            if match:
                psu, status = match.groups()
                print(f"Checking PSU {psu}: Status = {status}")
                assert status in EXPECTED_POWER_STATUS, f"FAIL: PSU {psu} status is {status}"

    @test
    def validate_fan_status(self):
        print("\n--- Validating Fan Status ---")
        fan_output = self.env_status.get('fan', '')

        for line in fan_output.splitlines():
            match = re.search(r'Fan\s+(\S+)\s+Status:\s+(\S+)', line)
            if match:
                fan, status = match.groups()
                print(f"Checking Fan {fan}: Status = {status}")
                assert status in EXPECTED_FAN_STATUS, f"FAIL: Fan {fan} status is {status}"

if __name__ == '__main__':
    main()

Explanation by Line

  • EXPECTED_POWER_STATUS / EXPECTED_FAN_STATUS: Define the acceptable health states for PSU and Fans.
  • connect_and_extract(): Connects to the device, executes environment status commands (show environment power, show environment fan), and stores outputs.
  • validate_power_status(): Iterates through the CLI output, applies regex parsing to extract PSU name and status, validates against the expected states, and raises assertion failure if mismatch.
  • validate_fan_status(): Same approach as power but for fans.
  • Optionally: Integrate GUI screenshot capture APIs to visually document status.

testbed.yml Example

testbed:
  name: hw_health_testbed
  credentials:
    default:
      username: admin
      password: Cisco123

devices:
  catalyst9300:
    os: iosxe
    type: switch
    connections:
      cli:
        protocol: ssh
        ip: 192.168.100.10

Post-validation CLI (Real expected output)

Example PSU Output (Cisco Catalyst 9300):

Switch# show environment power
Power Supply 1 Status: OK
Power Supply 2 Status: OK

Example Fan Output:

Switch# show environment fan
Fan 1 Status: OK
Fan 2 Status: OK
Fan 3 Status: OK

Sample Automation Output:

--- Validating Power Supply Status ---
Checking PSU 1: Status = OK
Checking PSU 2: Status = OK

--- Validating Fan Status ---
Checking Fan 1: Status = OK
Checking Fan 2: Status = OK
Checking Fan 3: Status = OK

All hardware health checks PASSED!

Optional GUI Screenshot Example (if implemented):

  • Screenshot file: /tmp/env_status.png
    Contains a visual dashboard showing the same data.

FAQs

Q1. Why is validating redundant power supplies and fans important in network devices?
A1. Redundant power supplies and fans are critical for high availability in data center and enterprise networks. Validating their status ensures hardware redundancy is operational, preventing device failure due to power or cooling issues, and reducing downtime.


Q2. How does pyATS help in automating power supply and fan status validation?
A2. pyATS enables automation of device health checks by connecting to devices via CLI or API, retrieving hardware status, parsing outputs, and generating structured test results. This removes the need for manual CLI checks across multiple devices.


Q3. What commands are typically used to check power supply and fan status on Cisco devices?
A3. Common Cisco CLI commands include:

  • show environment power
  • show environment fan
    These commands display real-time status of power supplies, fan units, and any fault indications.

Q4. Can pyATS handle multi-vendor power and fan validation?
A4. Yes. By using vendor-specific parsers or platform-agnostic abstractions, pyATS can execute equivalent commands on Arista, Juniper, or other devices, ensuring consistent validation across the network.


Q5. How are validation results reported in pyATS?
A5. Validation results are captured in structured formats like JSON or HTML. They provide detailed information about each power supply and fan unit’s health, including operational status, redundancy status, and any fault indicators.


Q6. Can pyATS automatically raise alerts on failures?
A6. While pyATS itself focuses on validation and reporting, it can easily be integrated with external alerting systems (e.g., email, Slack, PagerDuty) by triggering alerts when tests fail, enabling proactive maintenance.


Q7. How does this automated approach improve over manual checks?
A7. Automation ensures consistency, scalability, and repeatability. Instead of manually logging into each device, network engineers can run a single pyATS job to validate all devices, saving time and reducing human error, especially in large-scale deployments.


YouTube Link

Watch the Complete Python for Network Engineer: Validate Redundant Power Supply and Fans Status Using pyATS for Cisco [Python for Network Engineer] Lab Demo & Explanation on our channel:

Master Python Network Automation, Ansible, REST API & Cisco DevNet
Master Python Network Automation, Ansible, REST API & Cisco DevNet
Master Python Network Automation, Ansible, REST API & Cisco DevNet
Why Robot Framework for Network Automation?

Join Our Training

This was a deep-dive, hands-on masterclass Article on automating hardware health validations using pyATS, focusing on Cisco Catalyst devices. You now have the complete, reusable template to automate PSU and fan status audits and easily adapt it for other vendors.

But don’t stop here.

Trainer Sagar Dhawan’s 3-month Instructor-Led Training offers a comprehensive curriculum designed specifically for network engineers who want to master Python for Network Engineer automation roles. Learn real-world skills in Python, Ansible, and API integrations while automating tasks across multi-vendor environments.

Full course outline here:
Python Ansible API Cisco DevNet for Network Engineers – 3-Month Training

Join us today to future-proof your career, boost productivity, and automate complex network tasks confidently.

Enroll Now & Future‑Proof Your Career
Emailinfo@networkjourney.com
WhatsApp / Call: +91 97395 21088