datacenter / ACI-Pre-Upgrade-Validation-Script

A script to run validations to detect potential issues that may cause an ACI fabric upgrade to fail
https://datacenter.github.io/ACI-Pre-Upgrade-Validation-Script/
Apache License 2.0
43 stars 27 forks source link

Add color to results of script output on CLI to increase awareness #158

Open jcalzad opened 2 months ago

jcalzad commented 2 months ago

(use upvote :thumbsup: for attentions) Describe the enhancement Request to colorize results of script tests on CLI. This would draw user awareness to failed tests and in turn, increase chances of remediation steps being taken prior to upgrade if needed.

Current behavior/output script results print on CLI in native terminal color

Suggested behavior/output Have results print in color:

Green DONE = 'DONE' PASS = 'PASS'

Red FAIL_O = 'FAIL - OUTAGE WARNING!!' FAIL_UF = 'FAIL - UPGRADE FAILURE!!' ERROR = 'ERROR !!'

Yellow MANUAL = 'MANUAL CHECK REQUIRED' POST = 'POST UPGRADE CHECK REQUIRED' NA = 'N/A'

To Reproduce Sample python2 script to print out color:

from __future__ import print_function

DONE = 'DONE'
PASS = 'PASS'
FAIL_O = 'FAIL - OUTAGE WARNING!!'
FAIL_UF = 'FAIL - UPGRADE FAILURE!!'
ERROR = 'ERROR !!'
MANUAL = 'MANUAL CHECK REQUIRED'
POST = 'POST UPGRADE CHECK REQUIRED'
NA = 'N/A'

# ANSI escape codes for colors
GREEN = '\033[92m'
RED = '\033[91m'
YELLOW = '\033[93m'
ENDC = '\033[0m'

# List of all status items
status_items = [DONE, PASS, FAIL_O, FAIL_UF, ERROR, MANUAL, POST, NA]

# Function to get the colored status
def get_colored_status(item):
    if item == DONE or item == PASS:
        return "{}{}{}".format(GREEN, item, ENDC)
    elif item == FAIL_O or item == FAIL_UF or item == ERROR:
        return "{}{}{}".format(RED, item, ENDC)
    else:
        return "{}{}{}".format(YELLOW, item, ENDC)

# Print all status items with appropriate colors
for item in status_items:
    print(get_colored_status(item))

Additional context N/A