diff --git a/aci-preupgrade-validation-script.py b/aci-preupgrade-validation-script.py index 698b0e3..ee9d40c 100644 --- a/aci-preupgrade-validation-script.py +++ b/aci-preupgrade-validation-script.py @@ -9542,6 +9542,66 @@ def app_center_deprecation_check(cversion, tversion, **kwargs): return Result(result=result, headers=headers, data=data, recommended_action=recommended_action, doc_url=doc_url) +@check_wrapper(check_title='SPAN Destination Port with EPG Usage') +def span_destination_epg_conflict_check(tversion, **kwargs): + result = PASS + headers = ["Pod", "Node", "Port", "SPAN Destination Group", "SPAN Mode", "Usage"] + data = [] + recommended_action = 'Remove the SPAN destination configuration or the EPG/L3Out/infra VLAN deployment from each listed port before upgrading the switch.' + doc_url = 'https://datacenter.github.io/ACI-Pre-Upgrade-Validation-Script/validations/#span-destination-port-with-epg-usage' + + if not tversion: + return Result(result=MANUAL, msg=TVER_MISSING, doc_url=doc_url) + + if tversion.older_than("6.1(3a)"): + return Result(result=NA, msg=VER_NOT_AFFECTED, doc_url=doc_url) + + src_grp_api = 'spanSrcGrp.json?query-target-filter=eq(spanSrcGrp.adminSt,"enabled")' + src_groups = icurl('class', src_grp_api) + enabled_src_groups = set(src_group['spanSrcGrp']['attributes']['dn'] for src_group in src_groups) + active_dest_groups = set() + if not enabled_src_groups: + return Result(result=result, headers=headers, data=data, recommended_action=recommended_action, doc_url=doc_url) + + span_labels = icurl('class', 'spanSpanLbl.json') + for span_label in span_labels: + attributes = span_label['spanSpanLbl']['attributes'] + match = re.match(r'^(uni/infra/srcgrp-[^/]+)/spanlbl-', attributes['dn']) + if match and match.group(1) in enabled_src_groups: + active_dest_groups.add(attributes['name']) + + if not active_dest_groups: + return Result(result=result, headers=headers, data=data, recommended_action=recommended_action, doc_url=doc_url) + + destinations = {} + dest_paths = icurl('class', 'spanRsDestPathEp.json') + for dest_path in dest_paths: + attributes = dest_path['spanRsDestPathEp']['attributes'] + group_match = re.match(r'^uni/infra/destgrp-([^/]+)/', attributes['dn']) + path_match = re.match( + r'^topology/pod-(\d+)/paths-(\d+)/pathep-\[(eth\d+/\d+(?:/\d+)?)\]$', + attributes['tDn'] + ) + if not group_match or not path_match or group_match.group(1) not in active_dest_groups: + continue + destinations.setdefault(path_match.groups(), set()).add(group_match.group(1)) + + for (pod, node, port), groups in sorted(destinations.items()): + phys_if_api = 'topology/pod-{}/node-{}/sys/phys-[{}].json'.format(pod, node, port) + phys_ifs = icurl('mo', phys_if_api) + for phys_if in phys_ifs: + attributes = phys_if['l1PhysIf']['attributes'] + usage = [value.strip() for value in attributes.get('usage', '').split(',')] + if 'epg' in usage: + data.append([pod, node, port, ', '.join(sorted(groups)), + attributes.get('spanMode', ''), attributes.get('usage', '')]) + + if data: + result = FAIL_O + + return Result(result=result, headers=headers, data=data, recommended_action=recommended_action, doc_url=doc_url) + + class CheckManager: """Central managing point of all checks. Highlevel flows: @@ -9678,6 +9738,7 @@ class CheckManager: nxos_ipn_multicast_rpf_defect_check, vzany_svcgraph_stretched_vrf_check, app_center_deprecation_check, + span_destination_epg_conflict_check, ] ssh_checks = [ # General diff --git a/docs/docs/validations.md b/docs/docs/validations.md index 749851e..816c846 100644 --- a/docs/docs/validations.md +++ b/docs/docs/validations.md @@ -231,6 +231,7 @@ Items | Defect | This Script [APIC Connected Port VLAN Override][d44] | CSCwn64461 | :white_check_mark: | :no_entry_sign: [NX-OS IPN Multicast RPF Defect][d45] | CSCwt59437 | :white_check_mark: | :no_entry_sign: [vzAny Service Graph on Stretched VRF][d46] | CSCwt14573 | :white_check_mark: | :no_entry_sign: +[SPAN Destination Port with EPG Usage][d47] | CSCvz62374 | :white_check_mark: | :no_entry_sign: [d1]: #ep-announce-compatibility [d2]: #eventmgr-db-size-defect-susceptibility @@ -278,6 +279,7 @@ Items | Defect | This Script [d44]: #apic-connected-port-vlan-override [d45]: #nx-os-ipn-multicast-rpf-defect-cscwt59437 [d46]: #vzany-service-graph-on-stretched-vrf +[d47]: #span-destination-port-with-epg-usage ## General Check Details @@ -3093,6 +3095,16 @@ The graph instance may be scoped to a VRF, a tenant, or globally (`uni`). Tenant Recommended action: Migrate the vzAny service graph configuration to NDO before upgrade using brownfield import. NDO 4.2(3e) or later is required for vzAny PBR support on stretched VRFs. This is tracked under [CSCwt14573][91]. +### SPAN Destination Port with EPG Usage + +Starting with switch release 16.1(3), local SPAN destination and EPG/L3Out/infra VLAN deployment are mutually exclusive on a physical port ([CSCvz62374][95]). An upgrade or reload can change which configuration is deployed, affecting traffic or SPAN monitoring on a port with both configurations. + +This check applies to target versions 6.1(3) and later (switch 16.1(3) and later). It reports single-port destinations referenced by enabled access SPAN sessions when the port's `l1PhysIf.usage` contains `epg`, including destinations configured but not currently deployed. Port-channel, vPC, FEX, CPU and fabric SPAN destinations are excluded. + +The check uses reported interface usage and cannot detect EPG configurations that have not deployed, including EPG deployment blocked by SPAN or awaiting on-demand deployment. Missing interface objects are skipped; a pass means no conflict was found among the available objects. + +Remove either the SPAN destination configuration or the EPG/L3Out/infra VLAN deployment from each listed port before upgrading the switch. + ### App Center deprecation when crossing 6.1(2) Starting with APIC release 6.1(2), App Center and its applications can no longer be hosted on APIC because the APIC App Infrastructure is removed. When an upgrade crosses from a release before 6.1(2) to 6.1(2) or later, this check inventories all installed App Center applications, including inactive applications, and returns `MANUAL CHECK REQUIRED` when any are found. @@ -3201,3 +3213,4 @@ This validation is not applicable when the current APIC release is already 6.1(2 [92]: https://bst.cloudapps.cisco.com/bugsearch/bug/CSCwn95571 [93]: https://dcappcenter.cisco.com/elam-assistant.html [94]: https://www.cisco.com/c/en/us/td/docs/dcn/aci/apic/all/elam-assistant-user-guide/elam-assistant-user-guide/m-overview.html +[95]: https://bst.cloudapps.cisco.com/bugsearch/bug/CSCvz62374 diff --git a/tests/checks/span_destination_epg_conflict_check/baseline.json b/tests/checks/span_destination_epg_conflict_check/baseline.json new file mode 100644 index 0000000..d05ab8d --- /dev/null +++ b/tests/checks/span_destination_epg_conflict_check/baseline.json @@ -0,0 +1,41 @@ +{ + "spanSrcGrp.json?query-target-filter=eq(spanSrcGrp.adminSt,\"enabled\")": [ + { + "spanSrcGrp": { + "attributes": { + "dn": "uni/infra/srcgrp-Source1" + } + } + } + ], + "spanSpanLbl.json": [ + { + "spanSpanLbl": { + "attributes": { + "dn": "uni/infra/srcgrp-Source1/spanlbl-Destination1", + "name": "Destination1" + } + } + } + ], + "spanRsDestPathEp.json": [ + { + "spanRsDestPathEp": { + "attributes": { + "dn": "uni/infra/destgrp-Destination1/dest-Destination1/rsdestPathEp", + "tDn": "topology/pod-1/paths-101/pathep-[eth1/10]" + } + } + } + ], + "topology/pod-1/node-101/sys/phys-[eth1/10].json": [ + { + "l1PhysIf": { + "attributes": { + "usage": "epg,span", + "spanMode": "span-dest" + } + } + } + ] +} diff --git a/tests/checks/span_destination_epg_conflict_check/shared.json b/tests/checks/span_destination_epg_conflict_check/shared.json new file mode 100644 index 0000000..a07f601 --- /dev/null +++ b/tests/checks/span_destination_epg_conflict_check/shared.json @@ -0,0 +1,75 @@ +{ + "spanSrcGrp.json?query-target-filter=eq(spanSrcGrp.adminSt,\"enabled\")": [ + { + "spanSrcGrp": { + "attributes": { + "dn": "uni/infra/srcgrp-Source1" + } + } + } + ], + "spanSpanLbl.json": [ + { + "spanSpanLbl": { + "attributes": { + "dn": "uni/infra/srcgrp-Source1/spanlbl-Destination1", + "name": "Destination1" + } + } + }, + { + "spanSpanLbl": { + "attributes": { + "dn": "uni/infra/srcgrp-Source1/spanlbl-Destination2", + "name": "Destination2" + } + } + } + ], + "spanRsDestPathEp.json": [ + { + "spanRsDestPathEp": { + "attributes": { + "dn": "uni/infra/destgrp-Destination1/dest-Destination1/rsdestPathEp", + "tDn": "topology/pod-1/paths-101/pathep-[eth1/10]" + } + } + }, + { + "spanRsDestPathEp": { + "attributes": { + "dn": "uni/infra/destgrp-Destination2/dest-Destination2/rsdestPathEp", + "tDn": "topology/pod-1/paths-101/pathep-[eth1/10]" + } + } + }, + { + "spanRsDestPathEp": { + "attributes": { + "dn": "uni/infra/destgrp-Destination2/dest-Destination3/rsdestPathEp", + "tDn": "topology/pod-2/paths-201/pathep-[eth1/10]" + } + } + } + ], + "topology/pod-1/node-101/sys/phys-[eth1/10].json": [ + { + "l1PhysIf": { + "attributes": { + "usage": "epg,span", + "spanMode": "span-dest" + } + } + } + ], + "topology/pod-2/node-201/sys/phys-[eth1/10].json": [ + { + "l1PhysIf": { + "attributes": { + "usage": "epg,span", + "spanMode": "span-dest" + } + } + } + ] +} diff --git a/tests/checks/span_destination_epg_conflict_check/test_span_destination_epg_conflict_check.py b/tests/checks/span_destination_epg_conflict_check/test_span_destination_epg_conflict_check.py new file mode 100644 index 0000000..71a5aa4 --- /dev/null +++ b/tests/checks/span_destination_epg_conflict_check/test_span_destination_epg_conflict_check.py @@ -0,0 +1,355 @@ +import importlib +import os +from helpers.utils import read_data +import pytest + +script = importlib.import_module("aci-preupgrade-validation-script") +dir = os.path.dirname(os.path.abspath(__file__)) +test_function = "span_destination_epg_conflict_check" + +src_grp_api = 'spanSrcGrp.json?query-target-filter=eq(spanSrcGrp.adminSt,"enabled")' +label_api = 'spanSpanLbl.json' +dest_api = 'spanRsDestPathEp.json' +phys_api = 'topology/pod-1/node-101/sys/phys-[eth1/10].json' + + +@pytest.mark.parametrize( + "icurl_outputs, tversion, expected_result, expected_count", + [ + ( + read_data(dir, "baseline.json"), + None, + script.MANUAL, + 0, + ), + ( + read_data(dir, "baseline.json"), + "5.2(8i)", + script.NA, + 0, + ), + ( + read_data(dir, "baseline.json"), + "6.0(9e)", + script.NA, + 0, + ), + ( + read_data(dir, "baseline.json"), + "6.1(2g)", + script.NA, + 0, + ), + ( + read_data(dir, "baseline.json"), + "6.1(3a)", + script.FAIL_O, + 1, + ), + ( + read_data(dir, "baseline.json"), + "6.1(3f)", + script.FAIL_O, + 1, + ), + ( + read_data(dir, "baseline.json"), + "6.1(5e)", + script.FAIL_O, + 1, + ), + ( + read_data(dir, "baseline.json"), + "6.2(3g)", + script.FAIL_O, + 1, + ), + ( + read_data(dir, "baseline.json"), + "16.1(2g)", + script.NA, + 0, + ), + ( + read_data(dir, "baseline.json"), + "16.1(3f)", + script.FAIL_O, + 1, + ), + ], +) +def test_version_gate(run_check, mock_icurl, tversion, expected_result, expected_count): + result = run_check(tversion=script.AciVersion(tversion) if tversion else None) + assert result.result == expected_result + assert len(result.data) == expected_count + + +@pytest.mark.parametrize( + "icurl_outputs, usage, span_mode, expected_result, expected_data", + [ + ( + read_data(dir, "baseline.json"), + "epg,span", + "span-dest", + script.FAIL_O, + [["1", "101", "eth1/10", "Destination1", "span-dest", "epg,span"]], + ), + ( + read_data(dir, "baseline.json"), + "epg", + "not-a-span-dest", + script.FAIL_O, + [["1", "101", "eth1/10", "Destination1", "not-a-span-dest", "epg"]], + ), + ( + read_data(dir, "baseline.json"), + "controller,epg,infra", + "not-a-span-dest", + script.FAIL_O, + [["1", "101", "eth1/10", "Destination1", "not-a-span-dest", "controller,epg,infra"]], + ), + ( + read_data(dir, "baseline.json"), + "span, epg ", + "span-dest", + script.FAIL_O, + [["1", "101", "eth1/10", "Destination1", "span-dest", "span, epg "]], + ), + ( + read_data(dir, "baseline.json"), + "span", + "span-dest", + script.PASS, + [], + ), + ( + read_data(dir, "baseline.json"), + "", + "not-a-span-dest", + script.PASS, + [], + ), + ( + read_data(dir, "baseline.json"), + "epgOther,span", + "span-dest", + script.PASS, + [], + ), + ( + read_data(dir, "baseline.json"), + "infra", + "not-a-span-dest", + script.PASS, + [], + ), + ], +) +def test_usage(run_check, mock_icurl, icurl_outputs, usage, span_mode, expected_result, expected_data): + icurl_outputs[phys_api][0]['l1PhysIf']['attributes'] = {'usage': usage, 'spanMode': span_mode} + result = run_check(tversion=script.AciVersion("6.1(3f)")) + assert result.result == expected_result + assert result.data == expected_data + + +@pytest.mark.parametrize( + "icurl_outputs, query", + [ + ( + read_data(dir, "baseline.json"), + src_grp_api, + ), + ( + read_data(dir, "baseline.json"), + label_api, + ), + ( + read_data(dir, "baseline.json"), + dest_api, + ), + ( + read_data(dir, "baseline.json"), + phys_api, + ), + ], +) +def test_missing_objects(run_check, mock_icurl, icurl_outputs, query): + icurl_outputs[query] = [] + result = run_check(tversion=script.AciVersion("6.1(3f)")) + assert result.result == script.PASS + assert result.data == [] + + +@pytest.mark.parametrize( + "icurl_outputs, source_dn, label_dn, label_name, dest_dn", + [ + ( + read_data(dir, "baseline.json"), + "uni/infra/srcgrp-Unmatched1", + "uni/infra/srcgrp-Source1/spanlbl-Destination1", + "Destination1", + "uni/infra/destgrp-Destination1/dest-Destination1/rsdestPathEp", + ), + ( + read_data(dir, "baseline.json"), + "uni/fabric/srcgrp-Source1", + "uni/fabric/srcgrp-Source1/spanlbl-Destination1", + "Destination1", + "uni/infra/destgrp-Destination1/dest-Destination1/rsdestPathEp", + ), + ( + read_data(dir, "baseline.json"), + "uni/infra/srcgrp-Source1", + "uni/infra/srcgrp-Source1/spanlbl-Other", + "Other", + "uni/infra/destgrp-Destination1/dest-Destination1/rsdestPathEp", + ), + ( + read_data(dir, "baseline.json"), + "uni/infra/srcgrp-Source1", + "uni/infra/srcgrp-Source1/spanlbl-Destination1", + "Destination1", + "uni/fabric/destgrp-Destination1/dest-Destination1/rsdestPathEp", + ), + ( + read_data(dir, "baseline.json"), + "uni/infra/srcgrp-Source1", + "uni/infra/srcgrp-Source10/spanlbl-Destination1", + "Destination1", + "uni/infra/destgrp-Destination1/dest-Destination1/rsdestPathEp", + ), + ( + read_data(dir, "baseline.json"), + "uni/tn-Tenant1/srcgrp-Source1", + "uni/tn-Tenant1/srcgrp-Source1/spanlbl-Destination1", + "Destination1", + "uni/infra/destgrp-Destination1/dest-Destination1/rsdestPathEp", + ), + ( + read_data(dir, "baseline.json"), + "uni/infra/srcgrp-Source1", + "uni/infra/srcgrp-Source1/spanlbl-Destination1", + "Destination1", + "uni/tn-Tenant1/destgrp-Destination1/dest-Destination1/rsdestPathEp", + ), + ], +) +def test_access_session_scope(run_check, mock_icurl, icurl_outputs, source_dn, label_dn, label_name, dest_dn): + icurl_outputs[src_grp_api][0]['spanSrcGrp']['attributes']['dn'] = source_dn + icurl_outputs[label_api][0]['spanSpanLbl']['attributes'] = {'dn': label_dn, 'name': label_name} + icurl_outputs[dest_api][0]['spanRsDestPathEp']['attributes']['dn'] = dest_dn + result = run_check(tversion=script.AciVersion("6.1(3f)")) + assert result.result == script.PASS + assert result.data == [] + + +@pytest.mark.parametrize( + "icurl_outputs, path, expected_result, expected_ports", + [ + ( + read_data(dir, "baseline.json"), + "topology/pod-1/paths-101/pathep-[eth1/10]", + script.FAIL_O, + [["1", "101", "eth1/10"]], + ), + ( + read_data(dir, "baseline.json"), + "topology/pod-2/paths-201/pathep-[eth1/10/2]", + script.FAIL_O, + [["2", "201", "eth1/10/2"]], + ), + ( + read_data(dir, "baseline.json"), + "topology/pod-1/paths-101/pathep-[PortChannel1]", + script.PASS, + [], + ), + ( + read_data(dir, "baseline.json"), + "topology/pod-1/protpaths-101-102/pathep-[Vpc1]", + script.PASS, + [], + ), + ( + read_data(dir, "baseline.json"), + "topology/pod-1/paths-101/extpaths-112/pathep-[eth1/10]", + script.PASS, + [], + ), + ( + read_data(dir, "baseline.json"), + "topology/pod-1/paths-101/pathep-[sup-eth0]", + script.PASS, + [], + ), + ( + read_data(dir, "baseline.json"), + "", + script.PASS, + [], + ), + ( + read_data(dir, "baseline.json"), + "topology/pod-1/paths-101/pathep-[eth1/10]/extra", + script.PASS, + [], + ), + ], +) +def test_destination_paths(run_check, mock_icurl, icurl_outputs, path, expected_result, expected_ports): + icurl_outputs[dest_api][0]['spanRsDestPathEp']['attributes']['tDn'] = path + icurl_outputs['topology/pod-2/node-201/sys/phys-[eth1/10/2].json'] = icurl_outputs[phys_api] + result = run_check(tversion=script.AciVersion("6.1(3f)")) + assert result.result == expected_result + assert [row[:3] for row in result.data] == expected_ports + + +@pytest.mark.parametrize( + "icurl_outputs", + [read_data(dir, "shared.json")], +) +def test_shared_destination_and_multiple_ports(run_check, mock_icurl, icurl_outputs): + result = run_check(tversion=script.AciVersion("6.1(3f)")) + assert result.result == script.FAIL_O + assert [row[:4] for row in result.data] == [ + ['1', '101', 'eth1/10', 'Destination1, Destination2'], + ['2', '201', 'eth1/10', 'Destination2'], + ] + + +@pytest.mark.parametrize( + "icurl_outputs", + [read_data(dir, "baseline.json")], +) +def test_api_error(run_check, mock_icurl, icurl_outputs): + icurl_outputs[phys_api] = { + 'totalCount': '1', + 'imdata': [ + { + 'error': { + 'attributes': { + 'code': '503', + 'text': 'Unable to deliver the message, Resolve timeout', + }, + }, + }, + ], + } + result = run_check(tversion=script.AciVersion("6.1(3f)")) + assert result.result == script.ERROR + + +@pytest.mark.parametrize( + "icurl_outputs", + [ + {src_grp_api: []}, + { + src_grp_api: read_data(dir, "baseline.json")[src_grp_api], + label_api: [], + }, + ], +) +def test_no_session_skips_downstream_queries(run_check, mock_icurl): + result = run_check(tversion=script.AciVersion("6.1(3f)")) + assert result.result == script.PASS + assert result.data == []