Skip to content

Commit

Permalink
#57 fabricName check - v1.5.0 (#62)
Browse files Browse the repository at this point in the history
* issue 57 fabricName check + pytests

* bump to v1.5.0
  • Loading branch information
monrog2 authored Jul 28, 2023
1 parent ba263d7 commit 72ff6c3
Show file tree
Hide file tree
Showing 6 changed files with 339 additions and 96 deletions.
191 changes: 96 additions & 95 deletions README.md

Large diffs are not rendered by default.

39 changes: 38 additions & 1 deletion aci-preupgrade-validation-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import os
import re

SCRIPT_VERSION = "v1.4.0"
SCRIPT_VERSION = "v1.5.0"
DONE = 'DONE'
PASS = 'PASS'
FAIL_O = 'FAIL - OUTAGE WARNING!!'
Expand Down Expand Up @@ -2640,6 +2640,42 @@ def apic_ca_cert_validation(index, total_checks, **kwargs):
return result


def fabricdomain_name_check(index, total_checks, cversion=None, tversion=None, **kwargs):
title = 'FabricDomain Name Check'
result = FAIL_O
msg = ''
headers = ["FabricDomain", "Reason"]
data = []
recommended_action = "Do not upgrade to 6.0(2)"
doc_url = 'https://bst.cloudapps.cisco.com/bugsearch/bug/CSCwf80352'

print_title(title, index, total_checks)

if not tversion:
print_result(title, MANUAL, 'Target version not supplied. Skipping.')
return MANUAL

cfw = AciVersion(cversion)
tfw = AciVersion(tversion)

if tfw.same_as("6.0(2h)"):
controller = icurl('class', 'topSystem.json?query-target-filter=eq(topSystem.role,"controller")')
print(controller)
if not controller:
print_result(title, ERROR, 'topSystem response empty. Is the cluster healthy?')
return ERROR

fabricDomain = controller['imdata'][0]['topSystem']['attributes']['fabricDomain']
if re.search(r'#|;', fabricDomain):
data.append([fabricDomain, "Contains a special character"])


if not data:
result = PASS
print_result(title, result, msg, headers, data, recommended_action=recommended_action, doc_url=doc_url)
return result


if __name__ == "__main__":
prints(' ==== %s%s, Script Version %s ====\n' % (ts, tz, SCRIPT_VERSION))
prints('!!!! Check https://github.com/datacenter/ACI-Pre-Upgrade-Validation-Script for Latest Release !!!!\n')
Expand Down Expand Up @@ -2714,6 +2750,7 @@ def apic_ca_cert_validation(index, total_checks, **kwargs):
llfc_susceptibility_check,
internal_vlanpool_check,
apic_ca_cert_validation,
fabricdomain_name_check
]
summary = {PASS: 0, FAIL_O: 0, FAIL_UF: 0, ERROR: 0, MANUAL: 0, NA: 0, 'TOTAL': len(checks)}
for idx, check in enumerate(checks):
Expand Down
91 changes: 91 additions & 0 deletions tests/fabricdomain_name_check/test_fabricdomain_name_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import os
import pytest
import logging
import importlib
from helpers.utils import read_data
script = importlib.import_module("aci-preupgrade-validation-script")

log = logging.getLogger(__name__)
dir = os.path.dirname(os.path.abspath(__file__))


# icurl queries
topSystem = 'topSystem.json?query-target-filter=eq(topSystem.role,"controller")'

@pytest.mark.parametrize(
"icurl_outputs, cversion, tversion, expected_result",
[
# # char test
(
{
topSystem: read_data(dir, "topSystem_1POS.json")
},
"5.2(3g)",
"6.0(2h)",
script.FAIL_O,
),
(
{
topSystem: read_data(dir, "topSystem_1POS.json")
},
"6.0(3a)",
"6.0(2h)",
script.FAIL_O,
),
# ; char test
(
{
topSystem: read_data(dir, "topSystem_2POS.json")
},
"5.2(3g)",
"6.0(2h)",
script.FAIL_O,
),
(
{
topSystem: read_data(dir, "topSystem_2POS.json")
},
"6.0(3a)",
"6.0(2h)",
script.FAIL_O,
),
# Neither ; or # in fabricDomain
(
{
topSystem: read_data(dir, "topSystem_NEG.json")
},
"5.2(3g)",
"6.0(2h)",
script.PASS,
),
# only affected 6.0(2h), regardless of special chars
(
{
topSystem: read_data(dir, "topSystem_1POS.json")
},
"5.2(3g)",
"6.0(1j)",
script.PASS,
),
# Eventual 6.0(3) has fix
(
{
topSystem: read_data(dir, "topSystem_1POS.json")
},
"5.2(3g)",
"6.0(3a)",
script.PASS,
),
(
{
topSystem: read_data(dir, "topSystem_1POS.json")
},
"6.0(3a)",
"6.0(4a)",
script.PASS,
),
],
)
def test_logic(mock_icurl, cversion, tversion, expected_result):
result = script.fabricdomain_name_check(1, 1, cversion, tversion)
assert result == expected_result
38 changes: 38 additions & 0 deletions tests/fabricdomain_name_check/topSystem_1POS.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"totalCount": "3",
"imdata": [
{
"topSystem": {
"attributes": {
"address": "10.0.0.1",
"fabricId": "1",
"id": "1",
"fabricDomain": "fabric;4",
"role": "controller"
}
}
},
{
"topSystem": {
"attributes": {
"address": "10.0.0.2",
"fabricId": "1",
"id": "2",
"fabricDomain": "fabric;4",
"role": "controller"
}
}
},
{
"topSystem": {
"attributes": {
"address": "10.0.0.3",
"fabricId": "1",
"id": "3",
"fabricDomain": "fabric;4",
"role": "controller"
}
}
}
]
}
38 changes: 38 additions & 0 deletions tests/fabricdomain_name_check/topSystem_2POS.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"totalCount": "3",
"imdata": [
{
"topSystem": {
"attributes": {
"address": "10.0.0.1",
"fabricId": "1",
"id": "1",
"fabricDomain": "fabric#4",
"role": "controller"
}
}
},
{
"topSystem": {
"attributes": {
"address": "10.0.0.2",
"fabricId": "1",
"id": "2",
"fabricDomain": "fabric#4",
"role": "controller"
}
}
},
{
"topSystem": {
"attributes": {
"address": "10.0.0.3",
"fabricId": "1",
"id": "3",
"fabricDomain": "fabric#4",
"role": "controller"
}
}
}
]
}
38 changes: 38 additions & 0 deletions tests/fabricdomain_name_check/topSystem_NEG.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"totalCount": "3",
"imdata": [
{
"topSystem": {
"attributes": {
"address": "10.0.0.1",
"fabricId": "1",
"id": "1",
"fabricDomain": "fabric4",
"role": "controller"
}
}
},
{
"topSystem": {
"attributes": {
"address": "10.0.0.2",
"fabricId": "1",
"id": "2",
"fabricDomain": "fabric4",
"role": "controller"
}
}
},
{
"topSystem": {
"attributes": {
"address": "10.0.0.3",
"fabricId": "1",
"id": "3",
"fabricDomain": "fabric4",
"role": "controller"
}
}
}
]
}

0 comments on commit 72ff6c3

Please sign in to comment.