Skip to content

Commit

Permalink
Global switch_version attribute created and used by telemetryStatsSer…
Browse files Browse the repository at this point in the history
…verP check (#106)

* Introduced global switch_version attribute for all checks. This is now used correctly for telemetryStatsServerP check.

* Changed versions to use set for uniqueness and renamed global variable to sw_cversion
  • Loading branch information
wilsonbc2 authored May 1, 2024
1 parent 0c8437b commit bef55f7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
29 changes: 24 additions & 5 deletions aci-preupgrade-validation-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ def get_credentials():

def get_current_version():
""" Returns: AciVersion instance """
prints("Checking current APIC version (switch nodes are assumed to be on the same version)...", end='')
prints("Checking current APIC version...", end='')
firmwares = icurl('class', 'firmwareCtrlrRunning.json')
for firmware in firmwares:
if 'node-1' in firmware['firmwareCtrlrRunning']['attributes']['dn']:
Expand Down Expand Up @@ -691,6 +691,24 @@ def get_vpc_nodes(**kwargs):

return vpc_nodes

def get_switch_version(**kwargs):
""" Returns lowest switch version as AciVersion instance """
prints("Gathering Lowest Switch Version from Firmware Repository...", end='')
firmwares = icurl('class', 'firmwareRunning.json')
lowest_sw_ver = None
versions = set()

for firmware in firmwares:
versions.add(firmware['firmwareRunning']['attributes']['peVer'])

lowest_sw_ver = AciVersion(versions.pop())
for version in versions:
version = AciVersion(version)
if lowest_sw_ver.newer_than(str(version)):
lowest_sw_ver = version

prints('%s\n' % lowest_sw_ver)
return lowest_sw_ver

def apic_cluster_health_check(index, total_checks, cversion, **kwargs):
title = 'APIC Cluster is Fully-Fit'
Expand Down Expand Up @@ -2472,7 +2490,7 @@ def llfc_susceptibility_check(index, total_checks, cversion=None, tversion=None,
return result


def telemetryStatsServerP_object_check(index, total_checks, cversion=None, tversion=None, **kwargs):
def telemetryStatsServerP_object_check(index, total_checks, sw_cversion=None, tversion=None, **kwargs):
title = 'telemetryStatsServerP Object'
result = PASS
msg = ''
Expand All @@ -2486,12 +2504,12 @@ def telemetryStatsServerP_object_check(index, total_checks, cversion=None, tvers
print_result(title, MANUAL, 'Target version not supplied. Skipping.')
return MANUAL

if cversion.older_than("4.2(4d)") and tversion.newer_than("5.2(2d)"):
if sw_cversion.older_than("4.2(4d)") and tversion.newer_than("5.2(2d)"):
telemetryStatsServerP_json = icurl('class', 'telemetryStatsServerP.json')
for serverp in telemetryStatsServerP_json:
if serverp["telemetryStatsServerP"]["attributes"].get("collectorLocation") == "apic":
result = FAIL_O
data.append([str(cversion), str(tversion), 'telemetryStatsServerP.collectorLocation = "apic" Found'])
data.append([str(sw_cversion), str(tversion), 'telemetryStatsServerP.collectorLocation = "apic" Found'])

print_result(title, result, msg, headers, data, recommended_action=recommended_action, doc_url=doc_url)
return result
Expand Down Expand Up @@ -2915,6 +2933,7 @@ def access_untagged_check(index, total_checks, **kwargs):
cversion = get_current_version()
tversion = get_target_version()
vpc_nodes = get_vpc_nodes()
sw_cversion = get_switch_version()
except Exception as e:
prints('')
err = 'Error: %s' % e
Expand All @@ -2925,7 +2944,7 @@ def access_untagged_check(index, total_checks, **kwargs):
sys.exit()
inputs = {'username': username, 'password': password,
'cversion': cversion, 'tversion': tversion,
'vpc_node_ids': vpc_nodes}
'vpc_node_ids': vpc_nodes, 'sw_cversion':sw_cversion}
json_log = {"name": "PreupgradeCheck", "method": "standalone script", "datetime": ts + tz,
"script_version": str(SCRIPT_VERSION), "check_details": [],
'cversion': str(cversion), 'tversion': str(tversion)}
Expand Down
8 changes: 6 additions & 2 deletions docs/docs/validations.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Items | This Script
[g1]: #compatibility-target-aci-version
[g2]: #compatibility-cimc-version
[g3]: #compatibility-switch-hardware
[g4]: #compatibility-switch-hardware-gen1
[g4]: #compatibility-switch-hardware---gen1
[g5]: #compatibility-remote-leaf-switch
[g6]: #apic-target-version-image-and-md5-hash
[g7]: #apic-cluster-is-fully-fit
Expand Down Expand Up @@ -140,7 +140,7 @@ Items | Defect | This Script
[d1]: #ep-announce-compatibility
[d2]: #eventmgr-db-size
[d3]: #contract-port-22
[d4]: #telemetry-stats
[d4]: #telemetrystatsserverp-object
[d5]: #link-level-flow-control
[d6]: #internal-vlan-pool
[d7]: #apic-ca-cert-validation
Expand Down Expand Up @@ -1473,7 +1473,9 @@ Due to the defect CSCvt47850, if the switches are still on an older version than
To avoid this issue, change the `collectorLocation` type to `none` through the API to prevent the object from being automatically deleted post upgrade.

1. If `telemetryStatsServerP` exists with `collectorLocation="apic"`, use the API to change the `collectorLocation` type to `none`.

!!! example
`collectorLocation` is set to `apic` so this fabric is susceptible to CSCvt47850. Use icurl to change `collectorLocation` to `none`.
```
apic# moquery -c telemetryStatsServerP
# telemetry.StatsServerP
Expand All @@ -1488,7 +1490,9 @@ To avoid this issue, change the `collectorLocation` type to `none` through the A
2. Upgrade both Cisco APICs and switches to the target version.

3. After validating that all switches have been upgraded successfully, delete the `telemetryStatsSeverP` managed object.

!!! example
Object can safely be removed from the fabric.
```
apic# bash
apic:~> icurl -kX POST "http://localhost:7777/api/mo/uni/fabric/servers/stserverp-default.xml" -d '<telemetryStatsServerP status="deleted"/>'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


@pytest.mark.parametrize(
"icurl_outputs, cversion, tversion, expected_result",
"icurl_outputs, sw_cversion, tversion, expected_result",
[
(
{telemetryStatsServerPs: []},
Expand Down Expand Up @@ -79,11 +79,11 @@
),
],
)
def test_logic(mock_icurl, cversion, tversion, expected_result):
def test_logic(mock_icurl, sw_cversion, tversion, expected_result):
result = script.telemetryStatsServerP_object_check(
1,
1,
script.AciVersion(cversion),
script.AciVersion(sw_cversion),
script.AciVersion(tversion) if tversion else None,
)
assert result == expected_result

0 comments on commit bef55f7

Please sign in to comment.