From d52fa975992dc122bfa30f51b44f24f49ae72ded Mon Sep 17 00:00:00 2001 From: takishida <38262981+takishida@users.noreply.github.com> Date: Fri, 19 Apr 2024 20:40:23 -0700 Subject: [PATCH] Pytest cleanup (#97) * Update pytest for eventmgr_db_defect_check * Update pytest for encap_already_in_use_check * Update pytest for apic_ca_cert_validation * Update pytest for vpc_paired_switches_check * Update pytest for llfc_susceptibility_check * Update pytest for telemetryStatsServerP_object_check * Update pytest for isis_redis_metric_mpod_msite_check * Update pytest for switch_bootflash_usage_check * Update pytest for contract_22_defect_check * Update pytest for internal_vlanpool_check * Update pytest for bgp_golf_route_target_type_check * Remove unnecessary path setting in test_IPAddress * Update pytest for Aciversion * Update pytest for get_vpc_node() --- aci-preupgrade-validation-script.py | 91 +---- .../NEG_certreq.txt | 0 .../POS_certreq.txt | 0 .../test_apic_ca_cert_validation.py | 32 ++ .../fvCtx_pos.json | 50 +++ .../test_bgp_golf_route_target_type_check.py | 71 ++++ .../test_contract_22_defect_check.py | 30 ++ .../faultInst-encap-neg.json | 1 + .../faultInst-encap-pos.json | 18 + .../encap_already_in_use_check/fvIfConn.json | 50 +++ .../test_encap_already_in_use_check.py | 41 ++ tests/eqptcapacityFSPartition.json_pos | 181 --------- tests/ethpmFcot.json_pos | 49 --- .../test_eventmgr_db_defect_check.py | 28 ++ tests/fabricNodePEp.json_pos | 37 -- tests/faultInst-encap-neg.json | 4 - tests/faultInst-encap-pos.json | 21 - tests/fvCtx.json_pos | 53 --- tests/fvFabricExtConnP.json_pos1 | 37 -- tests/fvFabricExtConnP.json_pos2 | 26 -- tests/fvFabricExtConnP.json_pos3 | 27 -- tests/fvIfConn.json | 53 --- tests/fvnsVlanInstP.json_neg | 209 ---------- tests/fvnsVlanInstP.json_pos | 89 ----- .../fvnsVlanInstP_neg.json | 206 ++++++++++ .../fvnsVlanInstP_pos.json | 86 +++++ .../test_internal_vlanpool_check.py | 105 +++++ .../internal_vlanpool_check/vmmDomP_neg.json | 84 ++++ .../internal_vlanpool_check/vmmDomP_pos.json | 84 ++++ tests/isisDomP-default.json_missing | 12 - tests/isisDomP-default.json_neg | 13 - tests/isisDomP-default.json_pos | 13 - .../fvFabricExtConnP_pos1.json | 34 ++ .../fvFabricExtConnP_pos2.json | 23 ++ .../fvFabricExtConnP_pos3.json | 24 ++ .../isisDomP-default_missing.json | 9 + .../isisDomP-default_neg.json | 10 + .../isisDomP-default_pos.json | 10 + ...test_isis_redis_metric_mpod_msite_check.py | 60 +++ .../llfc_susceptibility_check/ethpmFcot.json | 46 +++ .../test_llfc_susceptibility_check.py | 86 +++++ .../eqptcapacityFSPartition_pos.json | 178 +++++++++ .../test_switch_bootflash_usage_check.py | 28 ++ tests/telemetryStatsServerP.json_neg | 20 - tests/telemetryStatsServerP.json_pos | 20 - .../telemetryStatsServerP_neg.json | 17 + .../telemetryStatsServerP_pos.json | 17 + ...test_telemetryStatsServerP_object_check.py | 89 +++++ tests/test_AciVersion.py | 70 ++++ tests/test_IPAddress.py | 6 - tests/test_get_vpc_node.py | 55 +++ tests/test_logic.py | 361 ------------------ tests/topSystem.json_pos | 137 ------- tests/vmmDomP.json_neg | 87 ----- tests/vmmDomP.json_pos | 87 ----- .../test_vpc_paired_switches_check.py | 36 ++ .../vpc_paired_switches_check/topSystem.json | 134 +++++++ 57 files changed, 1833 insertions(+), 1612 deletions(-) rename tests/{ => apic_ca_cert_validation}/NEG_certreq.txt (100%) rename tests/{ => apic_ca_cert_validation}/POS_certreq.txt (100%) create mode 100644 tests/apic_ca_cert_validation/test_apic_ca_cert_validation.py create mode 100644 tests/bgp_golf_route_target_type_check/fvCtx_pos.json create mode 100644 tests/bgp_golf_route_target_type_check/test_bgp_golf_route_target_type_check.py create mode 100644 tests/contract_22_defect_check/test_contract_22_defect_check.py create mode 100644 tests/encap_already_in_use_check/faultInst-encap-neg.json create mode 100644 tests/encap_already_in_use_check/faultInst-encap-pos.json create mode 100644 tests/encap_already_in_use_check/fvIfConn.json create mode 100644 tests/encap_already_in_use_check/test_encap_already_in_use_check.py delete mode 100644 tests/eqptcapacityFSPartition.json_pos delete mode 100644 tests/ethpmFcot.json_pos create mode 100644 tests/eventmgr_db_defect_check/test_eventmgr_db_defect_check.py delete mode 100644 tests/fabricNodePEp.json_pos delete mode 100644 tests/faultInst-encap-neg.json delete mode 100644 tests/faultInst-encap-pos.json delete mode 100644 tests/fvCtx.json_pos delete mode 100644 tests/fvFabricExtConnP.json_pos1 delete mode 100644 tests/fvFabricExtConnP.json_pos2 delete mode 100644 tests/fvFabricExtConnP.json_pos3 delete mode 100644 tests/fvIfConn.json delete mode 100644 tests/fvnsVlanInstP.json_neg delete mode 100644 tests/fvnsVlanInstP.json_pos create mode 100644 tests/internal_vlanpool_check/fvnsVlanInstP_neg.json create mode 100644 tests/internal_vlanpool_check/fvnsVlanInstP_pos.json create mode 100644 tests/internal_vlanpool_check/test_internal_vlanpool_check.py create mode 100644 tests/internal_vlanpool_check/vmmDomP_neg.json create mode 100644 tests/internal_vlanpool_check/vmmDomP_pos.json delete mode 100644 tests/isisDomP-default.json_missing delete mode 100644 tests/isisDomP-default.json_neg delete mode 100644 tests/isisDomP-default.json_pos create mode 100644 tests/isis_redis_metric_mpod_msite_check/fvFabricExtConnP_pos1.json create mode 100644 tests/isis_redis_metric_mpod_msite_check/fvFabricExtConnP_pos2.json create mode 100644 tests/isis_redis_metric_mpod_msite_check/fvFabricExtConnP_pos3.json create mode 100644 tests/isis_redis_metric_mpod_msite_check/isisDomP-default_missing.json create mode 100644 tests/isis_redis_metric_mpod_msite_check/isisDomP-default_neg.json create mode 100644 tests/isis_redis_metric_mpod_msite_check/isisDomP-default_pos.json create mode 100644 tests/isis_redis_metric_mpod_msite_check/test_isis_redis_metric_mpod_msite_check.py create mode 100644 tests/llfc_susceptibility_check/ethpmFcot.json create mode 100644 tests/llfc_susceptibility_check/test_llfc_susceptibility_check.py create mode 100644 tests/switch_bootflash_usage_check/eqptcapacityFSPartition_pos.json create mode 100644 tests/switch_bootflash_usage_check/test_switch_bootflash_usage_check.py delete mode 100644 tests/telemetryStatsServerP.json_neg delete mode 100644 tests/telemetryStatsServerP.json_pos create mode 100644 tests/telemetryStatsServerP_object_check/telemetryStatsServerP_neg.json create mode 100644 tests/telemetryStatsServerP_object_check/telemetryStatsServerP_pos.json create mode 100644 tests/telemetryStatsServerP_object_check/test_telemetryStatsServerP_object_check.py create mode 100644 tests/test_AciVersion.py create mode 100644 tests/test_get_vpc_node.py delete mode 100644 tests/test_logic.py delete mode 100644 tests/topSystem.json_pos delete mode 100644 tests/vmmDomP.json_neg delete mode 100644 tests/vmmDomP.json_pos create mode 100644 tests/vpc_paired_switches_check/test_vpc_paired_switches_check.py create mode 100644 tests/vpc_paired_switches_check/topSystem.json diff --git a/aci-preupgrade-validation-script.py b/aci-preupgrade-validation-script.py index 80761e7..3a1608e 100644 --- a/aci-preupgrade-validation-script.py +++ b/aci-preupgrade-validation-script.py @@ -992,10 +992,7 @@ def switch_bootflash_usage_check(index, total_checks, **kwargs): data = [] print_title(title, index, total_checks) - response_json = kwargs.get("eqptcapacityFSPartition.json") - - if not response_json: - response_json = icurl('class', + response_json = icurl('class', 'eqptcapacityFSPartition.json?query-target-filter=eq(eqptcapacityFSPartition.path,"/bootflash")') if not response_json: result = ERROR @@ -1179,18 +1176,13 @@ def encap_already_in_use_check(index, total_checks, **kwargs): recommended_action = 'Resolve the overlapping encap configuration prior to upgrade' print_title(title, index, total_checks) - faultInsts = kwargs.get("faultInst") - fvIfConns = kwargs.get("fvIfConn") - desc_regex = r'Encap is already in use by (?P.+);' nwissues_dn_regex = node_regex + r'/.*epp/fv-\[(?P.*)\]/node.*' - if "pytest" not in sys.modules: - faultInsts = icurl('class', + faultInsts = icurl('class', 'faultInst.json?&query-target-filter=wcard(faultInst.descr,"encap-already-in-use")') if faultInsts: - if "pytest" not in sys.modules: - fvIfConns = icurl('class', 'fvIfConn.json') + fvIfConns = icurl('class', 'fvIfConn.json') for faultInst in faultInsts: desc_array = re.search(desc_regex, faultInst['faultInst']['attributes']['descr']) @@ -1218,11 +1210,10 @@ def encap_already_in_use_check(index, total_checks, **kwargs): overlapping_encaps = [x for x in in_use_epg_encaps if x in faulted_epg_encaps] data.append([faulted_epg_dn, in_use_epg_dn, nodeId, ','.join(overlapping_encaps)]) else: - unformatted_data.append( - [faultInst['faultInst']['attributes']['descr']]) + unformatted_data.append([faultInst['faultInst']['attributes']['descr']]) if not data and not unformatted_data: result = PASS - print_result(title, result, msg, headers, data, + print_result(title, result, msg, headers, data, unformatted_headers, unformatted_data, recommended_action=recommended_action) return result @@ -2048,7 +2039,7 @@ def vmm_controller_adj_check(index, total_checks, **kwargs): return result -def vpc_paired_switches_check(index, total_checks, vpc_node_ids=[], **kwargs): +def vpc_paired_switches_check(index, total_checks, vpc_node_ids=None, **kwargs): title = 'VPC-paired Leaf switches' result = FAIL_O msg = '' @@ -2058,15 +2049,11 @@ def vpc_paired_switches_check(index, total_checks, vpc_node_ids=[], **kwargs): doc_url = 'https://datacenter.github.io/ACI-Pre-Upgrade-Validation-Script/validations/#vpc-paired-leaf-switches' print_title(title, index, total_checks) - if not vpc_node_ids: - vpc_node_ids = kwargs.get("vpc_node_ids", []) - if not vpc_node_ids: msg = 'No VPC definitions found!' + vpc_node_ids = [] - top_system = kwargs.get("topSystem.json") - if not top_system: - top_system = icurl('class', 'topSystem.json') + top_system = icurl('class', 'topSystem.json') for node in top_system: node_id = node['topSystem']['attributes']['id'] @@ -2163,17 +2150,13 @@ def isis_redis_metric_mpod_msite_check(index, total_checks, **kwargs): title = 'ISIS Redistribution metric for MPod/MSite' result = FAIL_O msg = '' - headers = ["ISIS Redistribution Metric", "MPod Deployment", "MSite Deployment","Recommendation" ] + headers = ["ISIS Redistribution Metric", "MPod Deployment", "MSite Deployment", "Recommendation"] data = [] recommended_action = None doc_url = '"ISIS Redistribution Metric" from ACI Best Practices Quick Summary - http://cs.co/9001zNNr7' print_title(title, index, total_checks) - isis_mo = kwargs.get("uni/fabric/isisDomP-default.json", None) - mpod_msite_mo = kwargs.get("fvFabricExtConnP.json?query-target=children", None) - - if not isis_mo: - isis_mo = icurl('mo', 'uni/fabric/isisDomP-default.json') + isis_mo = icurl('mo', 'uni/fabric/isisDomP-default.json') redistribMetric = isis_mo[0]['isisDomPol']['attributes'].get('redistribMetric') msite = False @@ -2186,8 +2169,7 @@ def isis_redis_metric_mpod_msite_check(index, total_checks, **kwargs): recommended_action = 'Change ISIS Redistribution Metric to less than 63' if recommended_action: - if not mpod_msite_mo: - mpod_msite_mo = icurl('class','fvFabricExtConnP.json?query-target=children') + mpod_msite_mo = icurl('class', 'fvFabricExtConnP.json?query-target=children') if mpod_msite_mo: pods_list = [] @@ -2211,25 +2193,18 @@ def bgp_golf_route_target_type_check(index, total_checks, cversion=None, tversio title = 'BGP route target type for GOLF over L2EVPN' result = FAIL_O msg = '' - headers = ["VRF DN","Global Name", "Route Target", "Recommendation" ] + headers = ["VRF DN", "Global Name", "Route Target", "Recommendation"] data = [] recommended_action = "Reconfigure extended: RT with prefix route-target: " doc_url = 'https://bst.cloudapps.cisco.com/bugsearch/bug/CSCvm23100' print_title(title, index, total_checks) - if not cversion: - cversion = kwargs.get("cversion", None) - if not tversion: - tversion = kwargs.get("tversion", None) - if not tversion: print_result(title, MANUAL, 'Target version not supplied. Skipping.') return MANUAL if cversion.older_than("4.2(1a)") and tversion.newer_than("4.2(1a)"): - fvctx_mo = kwargs.get("fvCtx.json", None) - if not fvctx_mo: - fvctx_mo = icurl('class', 'fvCtx.json?rsp-subtree=full&rsp-subtree-class=l3extGlobalCtxName,bgpRtTarget&rsp-subtree-include=required') + fvctx_mo = icurl('class', 'fvCtx.json?rsp-subtree=full&rsp-subtree-class=l3extGlobalCtxName,bgpRtTarget&rsp-subtree-include=required') if fvctx_mo: for vrf in fvctx_mo: @@ -2382,7 +2357,7 @@ def contract_22_defect_check(index, total_checks, cversion, tversion, **kwargs): return result -def llfc_susceptibility_check(index, total_checks, cversion=None, tversion=None, vpc_node_ids=[], **kwargs): +def llfc_susceptibility_check(index, total_checks, cversion=None, tversion=None, vpc_node_ids=None, **kwargs): title = 'Link Level Flow Control' result = PASS msg = '' @@ -2393,18 +2368,10 @@ def llfc_susceptibility_check(index, total_checks, cversion=None, tversion=None, doc_url = 'https://bst.cloudapps.cisco.com/bugsearch/bug/CSCvo27498' print_title(title, index, total_checks) - if not cversion: - cversion = kwargs.get("cversion", None) - if not tversion: - tversion = kwargs.get("tversion", None) - if not tversion: print_result(title, MANUAL, 'Target version not supplied. Skipping.') return MANUAL - if not vpc_node_ids: - vpc_node_ids = kwargs.get("vpc_node_ids", []) - if not vpc_node_ids: print_result(title, result, 'No VPC Nodes found. Not susceptible.') return result @@ -2418,9 +2385,7 @@ def llfc_susceptibility_check(index, total_checks, cversion=None, tversion=None, t_affected = True if sx_affected or t_affected: - ethpmFcot = kwargs.get("ethpmFcot.json") - if not ethpmFcot: - ethpmFcot = icurl('class', 'ethpmFcot.json?query-target-filter=and(eq(ethpmFcot.type,"sfp"),eq(ethpmFcot.state,"inserted"))') + ethpmFcot = icurl('class', 'ethpmFcot.json?query-target-filter=and(eq(ethpmFcot.type,"sfp"),eq(ethpmFcot.state,"inserted"))') for fcot in ethpmFcot: typeName = fcot['ethpmFcot']['attributes']['typeName'] @@ -2454,19 +2419,12 @@ def telemetryStatsServerP_object_check(index, total_checks, cversion=None, tvers doc_url = 'https://bst.cloudapps.cisco.com/bugsearch/bug/CSCvt47850' print_title(title, index, total_checks) - telemetryStatsServerP_json = kwargs.get("telemetryStatsServerP.json", None) - if not cversion: - cversion = kwargs.get("cversion", None) - if not tversion: - tversion = kwargs.get("tversion", None) - if not tversion: 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 not isinstance(telemetryStatsServerP_json, list): - telemetryStatsServerP_json = icurl('class', 'telemetryStatsServerP.json') + telemetryStatsServerP_json = icurl('class', 'telemetryStatsServerP.json') for serverp in telemetryStatsServerP_json: if serverp["telemetryStatsServerP"]["attributes"].get("collectorLocation") == "apic": result = FAIL_O @@ -2486,18 +2444,12 @@ def internal_vlanpool_check(index, total_checks, tversion=None, **kwargs): doc_url = 'https://bst.cloudapps.cisco.com/bugsearch/bug/CSCvw33061' print_title(title, index, total_checks) - fvnsVlanInstP_json = kwargs.get("fvnsVlanInstP.json", None) - vmmDomP_json = kwargs.get("vmmDomP.json", None) - if not tversion: - tversion = kwargs.get("tversion", None) - if not tversion: print_result(title, MANUAL, 'Target version not supplied. Skipping.') return MANUAL if tversion.newer_than("4.2(6a)"): - if not isinstance(fvnsVlanInstP_json, list): - fvnsVlanInstP_json = icurl('class', 'fvnsVlanInstP.json?rsp-subtree=children&rsp-subtree-class=fvnsRtVlanNs,fvnsEncapBlk&rsp-subtree-include=required') + fvnsVlanInstP_json = icurl('class', 'fvnsVlanInstP.json?rsp-subtree=children&rsp-subtree-class=fvnsRtVlanNs,fvnsEncapBlk&rsp-subtree-include=required') # Dict with key = vlan pool name, values = list of associated domains dom_rel = {} # List of vlanInstP which contain fvnsEncapBlk.role = "internal" @@ -2529,8 +2481,7 @@ def internal_vlanpool_check(index, total_checks, tversion=None, **kwargs): if [vlanInstP_name, ', '.join(encap_blk_dict[vlanInstP_name]), dom["dn"], 'VLANs in this Block will be removed from switch Front-Panel if not corrected'] not in data: data.append([vlanInstP_name, ', '.join(encap_blk_dict[vlanInstP_name]), dom["dn"], 'VLANs in this Block will be removed from switch Front-Panel if not corrected']) assoc_doms.append(dom["dn"]) - if not isinstance(vmmDomP_json, list): - vmmDomP_json = icurl('class', 'vmmDomP.json') + vmmDomP_json = icurl('class', 'vmmDomP.json') for vmmDomP in vmmDomP_json: if vmmDomP["vmmDomP"]["attributes"]["dn"] in assoc_doms: if vmmDomP["vmmDomP"]["attributes"]["enableAVE"] != "yes": @@ -2559,7 +2510,7 @@ def apic_ca_cert_validation(index, total_checks, **kwargs): certreq_out = kwargs.get("certreq_out") if not certreq_out: - pki_fabric_ca_mo = icurl('class','pkiFabricSelfCAEp.json') + pki_fabric_ca_mo = icurl('class', 'pkiFabricSelfCAEp.json') if pki_fabric_ca_mo: # Prep csr passphrase = pki_fabric_ca_mo[0]['pkiFabricSelfCAEp']['attributes']['currCertReqPassphrase'] @@ -2604,8 +2555,8 @@ def apic_ca_cert_validation(index, total_checks, **kwargs): # Perform test certreq url = 'https://127.0.0.1/raca/certreq.json' payload = '{"aaaCertGenReq":{"attributes":{"type":"csvc","hmac":"%s", "certreq": "%s", ' \ - '"podip": "None", "podmac": "None", "podname": "None"}}}' % (hmac, certreq) - cmd = 'icurl -kX POST %s -d \' %s \'' %(url,payload) + '"podip": "None", "podmac": "None", "podname": "None"}}}' % (hmac, certreq) + cmd = 'icurl -kX POST %s -d \' %s \'' % (url, payload) logging.debug('cmd = ' + ''.join(cmd)) certreq_proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) certreq_out = certreq_proc.communicate()[0].strip() diff --git a/tests/NEG_certreq.txt b/tests/apic_ca_cert_validation/NEG_certreq.txt similarity index 100% rename from tests/NEG_certreq.txt rename to tests/apic_ca_cert_validation/NEG_certreq.txt diff --git a/tests/POS_certreq.txt b/tests/apic_ca_cert_validation/POS_certreq.txt similarity index 100% rename from tests/POS_certreq.txt rename to tests/apic_ca_cert_validation/POS_certreq.txt diff --git a/tests/apic_ca_cert_validation/test_apic_ca_cert_validation.py b/tests/apic_ca_cert_validation/test_apic_ca_cert_validation.py new file mode 100644 index 0000000..d76d955 --- /dev/null +++ b/tests/apic_ca_cert_validation/test_apic_ca_cert_validation.py @@ -0,0 +1,32 @@ +import os +import pytest +import logging +import importlib + +script = importlib.import_module("aci-preupgrade-validation-script") + +log = logging.getLogger(__name__) +dir = os.path.dirname(os.path.abspath(__file__)) + + +@pytest.mark.parametrize( + "certreq_out_file, expected_result", + [ + # FAIL - certreq returns error + ( + "POS_certreq.txt", + script.FAIL_O, + ), + # PASS - certreq returns cert info + ( + "NEG_certreq.txt", + script.PASS, + ), + ], +) +def test_logic(certreq_out_file, expected_result): + data_path = os.path.join("tests", dir, certreq_out_file) + with open(data_path, "r") as file: + certreq_out = file.read() + result = script.apic_ca_cert_validation(1, 1, certreq_out=certreq_out) + assert result == expected_result diff --git a/tests/bgp_golf_route_target_type_check/fvCtx_pos.json b/tests/bgp_golf_route_target_type_check/fvCtx_pos.json new file mode 100644 index 0000000..29bdeb0 --- /dev/null +++ b/tests/bgp_golf_route_target_type_check/fvCtx_pos.json @@ -0,0 +1,50 @@ +[ + { + "fvCtx": { + "attributes": { + "annotation": "orchestrator:msc-shadow:no", + "bdEnforcedEnable": "no", + "dn": "uni/tn-welkin/ctx-qa", + "knwMcastAct": "permit", + "monPolDn": "uni/tn-common/monepg-default", + "name": "qa", + "pcEnfDir": "ingress", + "pcEnfDirUpdated": "yes", + "pcEnfPref": "enforced", + "pcTag": "16386", + "scope": "3080192", + "seg": "3080192" + }, + "children": [ + { + "l3extGlobalCtxName": { + "attributes": { + "name": "welkinqa", + "rn": "globalctxname" + } + } + }, + { + "bgpRtTargetP": { + "attributes": { + "af": "ipv4-ucast", + "rn": "rtp-ipv4-ucast" + }, + "children": [ + { + "bgpRtTarget": { + "attributes": { + "rn": "rt-[extended:as2-nn2:100:2000]-import", + "rt": "extended:as2-nn2:100:2000", + "targetAf": "l2vpn-evpn", + "type": "import" + } + } + } + ] + } + } + ] + } + } +] diff --git a/tests/bgp_golf_route_target_type_check/test_bgp_golf_route_target_type_check.py b/tests/bgp_golf_route_target_type_check/test_bgp_golf_route_target_type_check.py new file mode 100644 index 0000000..2fc2e58 --- /dev/null +++ b/tests/bgp_golf_route_target_type_check/test_bgp_golf_route_target_type_check.py @@ -0,0 +1,71 @@ +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 +fvCtxs = 'fvCtx.json?rsp-subtree=full&rsp-subtree-class=l3extGlobalCtxName,bgpRtTarget&rsp-subtree-include=required' + + +@pytest.mark.parametrize( + "icurl_outputs, cversion, tversion, expected_result", + [ + ( + {fvCtxs: read_data(dir, "fvCtx_pos.json")}, + "4.2(1b)", + "5.2(2a)", + script.PASS, + ), + ( + {fvCtxs: read_data(dir, "fvCtx_pos.json")}, + "3.2(1a)", + "4.2(4d)", + script.FAIL_O, + ), + ( + {fvCtxs: read_data(dir, "fvCtx_pos.json")}, + "3.2(1a)", + "5.2(6a)", + script.FAIL_O, + ), + ( + {fvCtxs: read_data(dir, "fvCtx_pos.json")}, + "4.2(3a)", + "4.2(7d)", + script.PASS, + ), + ( + {fvCtxs: read_data(dir, "fvCtx_pos.json")}, + "2.2(3a)", + "2.2(4r)", + script.PASS, + ), + ( + {fvCtxs: read_data(dir, "fvCtx_pos.json")}, + "5.2(1a)", + None, + script.MANUAL, + ), + ( + {fvCtxs: read_data(dir, "fvCtx_pos.json")}, + "4.1(1a)", + "5.2(7f)", + script.FAIL_O, + ), + ], +) +def test_logic(mock_icurl, cversion, tversion, expected_result): + result = script.bgp_golf_route_target_type_check( + 1, + 1, + script.AciVersion(cversion), + script.AciVersion(tversion) if tversion else None, + ) + assert result == expected_result diff --git a/tests/contract_22_defect_check/test_contract_22_defect_check.py b/tests/contract_22_defect_check/test_contract_22_defect_check.py new file mode 100644 index 0000000..1c9e174 --- /dev/null +++ b/tests/contract_22_defect_check/test_contract_22_defect_check.py @@ -0,0 +1,30 @@ +import os +import pytest +import logging +import importlib + +script = importlib.import_module("aci-preupgrade-validation-script") + +log = logging.getLogger(__name__) +dir = os.path.dirname(os.path.abspath(__file__)) + + +@pytest.mark.parametrize( + "cversion, tversion, expected_result", + [ + ("4.2(1b)", "5.2(2a)", script.FAIL_O), + ("3.2(1a)", "4.2(4d)", script.PASS), + ("3.2(1a)", "5.2(6a)", script.PASS), + ("4.2(3a)", "4.2(7d)", script.PASS), + ("2.2(3a)", "2.2(4r)", script.PASS), + ("5.2(1a)", None, script.MANUAL), + ], +) +def test_logic(mock_icurl, cversion, tversion, expected_result): + result = script.contract_22_defect_check( + 1, + 1, + script.AciVersion(cversion), + script.AciVersion(tversion) if tversion else None, + ) + assert result == expected_result diff --git a/tests/encap_already_in_use_check/faultInst-encap-neg.json b/tests/encap_already_in_use_check/faultInst-encap-neg.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/tests/encap_already_in_use_check/faultInst-encap-neg.json @@ -0,0 +1 @@ +[] diff --git a/tests/encap_already_in_use_check/faultInst-encap-pos.json b/tests/encap_already_in_use_check/faultInst-encap-pos.json new file mode 100644 index 0000000..22c1f60 --- /dev/null +++ b/tests/encap_already_in_use_check/faultInst-encap-pos.json @@ -0,0 +1,18 @@ +[ + { + "faultInst": { + "attributes": { + "descr": "Configuration failed for uni/tn-bw/ap-mcast/epg-mcast1 node 104 bw-9k-L103-104-eth1-1 due to Encap Already Used in Another EPG, debug message: encap-already-in-use: Encap is already in use by bw:physical:phys3;", + "dn": "topology/pod-1/node-104/local/svc-policyelem-id-0/uni/epp/fv-[uni/tn-bw/ap-mcast/epg-mcast1]/node-104/stpathatt-[bw-9k-L103-104-eth1-1]/nwissues/fault-F0467" + } + } + }, + { + "faultInst": { + "attributes": { + "descr": "Configuration failed for uni/tn-test/ap-app/epg-epg1 node 101 L101-eth1-1 due to Encap Already Used in Another EPG, debug message: encap-already-in-use: Encap is already in use by test2:app2:epg2;", + "dn": "topology/pod-1/node-101/local/svc-policyelem-id-0/uni/epp/fv-[uni/tn-test/ap-app/epg-epg1]/node-101/stpathatt-[L101-eth1-1]/nwissues/fault-F0467" + } + } + } +] diff --git a/tests/encap_already_in_use_check/fvIfConn.json b/tests/encap_already_in_use_check/fvIfConn.json new file mode 100644 index 0000000..2a9eb49 --- /dev/null +++ b/tests/encap_already_in_use_check/fvIfConn.json @@ -0,0 +1,50 @@ +[ + { + "fvIfConn": { + "attributes": { + "dn": "uni/epp/fv-[uni/tn-bw/ap-physical/epg-phys3]/node-104/stpathatt-[eth1/2]/conndef/conn-[vlan-101]-[0.0.0.0]", + "encap": "vlan-101" + } + } + }, + { + "fvIfConn": { + "attributes": { + "dn": "uni/epp/fv-[uni/tn-bw/ap-mcast/epg-mcast1]/node-104/stpathatt-[bw-9k-L103-104-eth1-1]/conndef/conn-[vlan-101]-[0.0.0.0]", + "encap": "vlan-101" + } + } + }, + { + "fvIfConn": { + "attributes": { + "dn": "uni/epp/fv-[uni/tn-test/ap-app/epg-epg1]/node-101/stpathatt-[L101-eth1-1]/conndef/conn-[vlan-777]-[0.0.0.0]", + "encap": "vlan-777" + } + } + }, + { + "fvIfConn": { + "attributes": { + "dn": "uni/epp/fv-[uni/tn-test2/ap-app2/epg-epg2]/node-101/stpathatt-[eth1/2]/conndef/conn-[vlan-777]-[0.0.0.0]", + "encap": "vlan-777" + } + } + }, + { + "fvIfConn": { + "attributes": { + "dn": "uni/epp/fv-[uni/tn-test/ap-app/epg-epg1]/node-102/stpathatt-[L102-eth1-1]/conndef/conn-[vlan-778]-[0.0.0.0]", + "encap": "vlan-778" + } + } + }, + { + "fvIfConn": { + "attributes": { + "dn": "uni/epp/fv-[uni/tn-test2/ap-app2/epg-epg2]/node-102/stpathatt-[eth1/2]/conndef/conn-[vlan-778]-[0.0.0.0]", + "encap": "vlan-778" + } + } + } +] diff --git a/tests/encap_already_in_use_check/test_encap_already_in_use_check.py b/tests/encap_already_in_use_check/test_encap_already_in_use_check.py new file mode 100644 index 0000000..de7dda4 --- /dev/null +++ b/tests/encap_already_in_use_check/test_encap_already_in_use_check.py @@ -0,0 +1,41 @@ +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 +faultInsts = ( + 'faultInst.json?&query-target-filter=wcard(faultInst.descr,"encap-already-in-use")' +) +fvIfConns = "fvIfConn.json" + + +@pytest.mark.parametrize( + "icurl_outputs, expected_result", + [ + ( + { + faultInsts: read_data(dir, "faultInst-encap-pos.json"), + fvIfConns: read_data(dir, "fvIfConn.json"), + }, + script.FAIL_O, + ), + ( + { + faultInsts: read_data(dir, "faultInst-encap-neg.json"), + fvIfConns: read_data(dir, "fvIfConn.json"), + }, + script.PASS, + ), + ], +) +def test_logic(mock_icurl, expected_result): + result = script.encap_already_in_use_check(1, 1) + assert result == expected_result diff --git a/tests/eqptcapacityFSPartition.json_pos b/tests/eqptcapacityFSPartition.json_pos deleted file mode 100644 index b5c5b79..0000000 --- a/tests/eqptcapacityFSPartition.json_pos +++ /dev/null @@ -1,181 +0,0 @@ -{ - "imdata": [ - { - "eqptcapacityFSPartition": { - "attributes": { - "avail": "6160040", - "childAction": "", - "dn": "topology/pod-1/node-102/sys/eqptcapacity/fspartition-bootflash", - "memAlert": "normal", - "modTs": "never", - "monPolDn": "uni/fabric/monfab-default", - "name": "bootflash", - "path": "/bootflash", - "status": "", - "used": "5374088" - } - } - }, - { - "eqptcapacityFSPartition": { - "attributes": { - "avail": "6643924", - "childAction": "", - "dn": "topology/pod-1/node-103/sys/eqptcapacity/fspartition-bootflash", - "memAlert": "normal", - "modTs": "never", - "monPolDn": "uni/fabric/monfab-default", - "name": "bootflash", - "path": "/bootflash", - "status": "", - "used": "4332192" - } - } - }, - { - "eqptcapacityFSPartition": { - "attributes": { - "avail": "6916228", - "childAction": "", - "dn": "topology/pod-2/node-205/sys/eqptcapacity/fspartition-bootflash", - "memAlert": "normal", - "modTs": "never", - "monPolDn": "uni/fabric/monfab-default", - "name": "bootflash", - "path": "/bootflash", - "status": "", - "used": "4059888" - } - } - }, - { - "eqptcapacityFSPartition": { - "attributes": { - "avail": "7261676", - "childAction": "", - "dn": "topology/pod-2/node-206/sys/eqptcapacity/fspartition-bootflash", - "memAlert": "normal", - "modTs": "never", - "monPolDn": "uni/fabric/monfab-default", - "name": "bootflash", - "path": "/bootflash", - "status": "", - "used": "3714440" - } - } - }, - { - "eqptcapacityFSPartition": { - "attributes": { - "avail": "7422756", - "childAction": "", - "dn": "topology/pod-1/node-1002/sys/eqptcapacity/fspartition-bootflash", - "memAlert": "normal", - "modTs": "never", - "monPolDn": "uni/fabric/monfab-default", - "name": "bootflash", - "path": "/bootflash", - "status": "", - "used": "4111372" - } - } - }, - { - "eqptcapacityFSPartition": { - "attributes": { - "avail": "5980968", - "childAction": "", - "dn": "topology/pod-1/node-1001/sys/eqptcapacity/fspartition-bootflash", - "memAlert": "normal", - "modTs": "never", - "monPolDn": "uni/fabric/monfab-default", - "name": "bootflash", - "path": "/bootflash", - "status": "", - "used": "4995148" - } - } - }, - { - "eqptcapacityFSPartition": { - "attributes": { - "avail": "16712928", - "childAction": "", - "dn": "topology/pod-2/node-2002/sys/eqptcapacity/fspartition-bootflash", - "memAlert": "normal", - "modTs": "never", - "monPolDn": "uni/fabric/monfab-default", - "name": "bootflash", - "path": "/bootflash", - "status": "", - "used": "6502564" - } - } - }, - { - "eqptcapacityFSPartition": { - "attributes": { - "avail": "16923436", - "childAction": "", - "dn": "topology/pod-2/node-2003/sys/eqptcapacity/fspartition-bootflash", - "memAlert": "normal", - "modTs": "never", - "monPolDn": "uni/fabric/monfab-default", - "name": "bootflash", - "path": "/bootflash", - "status": "", - "used": "6292056" - } - } - }, - { - "eqptcapacityFSPartition": { - "attributes": { - "avail": "6438436", - "childAction": "", - "dn": "topology/pod-2/node-2001/sys/eqptcapacity/fspartition-bootflash", - "memAlert": "normal", - "modTs": "never", - "monPolDn": "uni/fabric/monfab-default", - "name": "bootflash", - "path": "/bootflash", - "status": "", - "used": "4537680" - } - } - }, - { - "eqptcapacityFSPartition": { - "attributes": { - "avail": "8031460", - "childAction": "", - "dn": "topology/pod-2/node-2010/sys/eqptcapacity/fspartition-bootflash", - "memAlert": "normal", - "modTs": "never", - "monPolDn": "uni/fabric/monfab-default", - "name": "bootflash", - "path": "/bootflash", - "status": "", - "used": "4127820" - } - } - }, - { - "eqptcapacityFSPartition": { - "attributes": { - "avail": "5347648", - "childAction": "", - "dn": "topology/pod-1/node-101/sys/eqptcapacity/fspartition-bootflash", - "memAlert": "normal", - "modTs": "never", - "monPolDn": "uni/fabric/monfab-default", - "name": "bootflash", - "path": "/bootflash", - "status": "", - "used": "5628468" - } - } - } - ], - "totalCount": "11" -} \ No newline at end of file diff --git a/tests/ethpmFcot.json_pos b/tests/ethpmFcot.json_pos deleted file mode 100644 index 25d77d4..0000000 --- a/tests/ethpmFcot.json_pos +++ /dev/null @@ -1,49 +0,0 @@ -{ - "totalCount": "4", - "imdata": [ - { - "ethpmFcot": { - "attributes": { - "actualType": "sfp", - "dn": "topology/pod-1/node-101/sys/phys-[eth1/6]/phys/fcot", - "state": "inserted", - "type": "sfp", - "typeName": "1000base-T" - } - } - }, - { - "ethpmFcot": { - "attributes": { - "actualType": "sfp", - "dn": "topology/pod-1/node-103/sys/phys-[eth1/6]/phys/fcot", - "state": "inserted", - "type": "sfp", - "typeName": "1000base-T" - } - } - }, - { - "ethpmFcot": { - "attributes": { - "actualType": "sfp", - "dn": "topology/pod-1/node-101/sys/phys-[eth1/7]/phys/fcot", - "state": "inserted", - "type": "sfp", - "typeName": "1000base-SX" - } - } - }, - { - "ethpmFcot": { - "attributes": { - "actualType": "sfp", - "dn": "topology/pod-1/node-103/sys/phys-[eth1/7]/phys/fcot", - "state": "inserted", - "type": "sfp", - "typeName": "1000base-SX" - } - } - } - ] -} \ No newline at end of file diff --git a/tests/eventmgr_db_defect_check/test_eventmgr_db_defect_check.py b/tests/eventmgr_db_defect_check/test_eventmgr_db_defect_check.py new file mode 100644 index 0000000..bbd5a8d --- /dev/null +++ b/tests/eventmgr_db_defect_check/test_eventmgr_db_defect_check.py @@ -0,0 +1,28 @@ +import os +import pytest +import logging +import importlib + +script = importlib.import_module("aci-preupgrade-validation-script") + +log = logging.getLogger(__name__) +dir = os.path.dirname(os.path.abspath(__file__)) + + +@pytest.mark.parametrize( + "cversion, expected_result", + [ + # Non-affected version + ("3.2(5e)", script.PASS), + ("3.2(10g)", script.PASS), + ("4.1(2a)", script.PASS), + # Affected version + ("3.2(4a)", script.FAIL_UF), + ("4.0(1a)", script.FAIL_UF), + ], +) +def test_logic(mock_icurl, cversion, expected_result): + result = script.eventmgr_db_defect_check( + 1, 1, script.AciVersion(cversion) + ) + assert result == expected_result diff --git a/tests/fabricNodePEp.json_pos b/tests/fabricNodePEp.json_pos deleted file mode 100644 index 772ce46..0000000 --- a/tests/fabricNodePEp.json_pos +++ /dev/null @@ -1,37 +0,0 @@ -{ - "totalCount": "4", - "imdata": [ - { - "fabricNodePEp": { - "attributes": { - "dn": "uni/fabric/protpol/expgep-101-103/nodepep-101", - "id": "101" - } - } - }, - { - "fabricNodePEp": { - "attributes": { - "dn": "uni/fabric/protpol/expgep-204-206/nodepep-206", - "id": "206" - } - } - }, - { - "fabricNodePEp": { - "attributes": { - "dn": "uni/fabric/protpol/expgep-101-103/nodepep-103", - "id": "103" - } - } - }, - { - "fabricNodePEp": { - "attributes": { - "dn": "uni/fabric/protpol/expgep-204-206/nodepep-204", - "id": "204" - } - } - } - ] -} \ No newline at end of file diff --git a/tests/faultInst-encap-neg.json b/tests/faultInst-encap-neg.json deleted file mode 100644 index 6cc0e51..0000000 --- a/tests/faultInst-encap-neg.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "totalCount": "0", - "imdata": [] -} \ No newline at end of file diff --git a/tests/faultInst-encap-pos.json b/tests/faultInst-encap-pos.json deleted file mode 100644 index 4438ef9..0000000 --- a/tests/faultInst-encap-pos.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "totalCount": "1", - "imdata": [ - { - "faultInst": { - "attributes": { - "descr": "Configuration failed for uni/tn-bw/ap-mcast/epg-mcast1 node 104 bw-9k-L103-104-eth1-1 due to Encap Already Used in Another EPG, debug message: encap-already-in-use: Encap is already in use by bw:physical:phys3;", - "dn": "topology/pod-1/node-104/local/svc-policyelem-id-0/uni/epp/fv-[uni/tn-bw/ap-mcast/epg-mcast1]/node-104/stpathatt-[bw-9k-L103-104-eth1-1]/nwissues/fault-F0467" - } - } - }, - { - "faultInst": { - "attributes": { - "descr": "Configuration failed for uni/tn-test/ap-app/epg-epg1 node 101 L101-eth1-1 due to Encap Already Used in Another EPG, debug message: encap-already-in-use: Encap is already in use by test2:app2:epg2;", - "dn": "topology/pod-1/node-101/local/svc-policyelem-id-0/uni/epp/fv-[uni/tn-test/ap-app/epg-epg1]/node-101/stpathatt-[L101-eth1-1]/nwissues/fault-F0467" - } - } - } - ] -} \ No newline at end of file diff --git a/tests/fvCtx.json_pos b/tests/fvCtx.json_pos deleted file mode 100644 index ef3b6f7..0000000 --- a/tests/fvCtx.json_pos +++ /dev/null @@ -1,53 +0,0 @@ -{ - "totalCount": "1", - "imdata": [ - { - "fvCtx": { - "attributes": { - "annotation": "orchestrator:msc-shadow:no", - "bdEnforcedEnable": "no", - "dn": "uni/tn-welkin/ctx-qa", - "knwMcastAct": "permit", - "monPolDn": "uni/tn-common/monepg-default", - "name": "qa", - "pcEnfDir": "ingress", - "pcEnfDirUpdated": "yes", - "pcEnfPref": "enforced", - "pcTag": "16386", - "scope": "3080192", - "seg": "3080192" - }, - "children": [ - { - "l3extGlobalCtxName": { - "attributes": { - "name": "welkinqa", - "rn": "globalctxname" - } - } - }, - { - "bgpRtTargetP": { - "attributes": { - "af": "ipv4-ucast", - "rn": "rtp-ipv4-ucast" - }, - "children": [ - { - "bgpRtTarget": { - "attributes": { - "rn": "rt-[extended:as2-nn2:100:2000]-import", - "rt": "extended:as2-nn2:100:2000", - "targetAf": "l2vpn-evpn", - "type": "import" - } - } - } - ] - } - } - ] - } - } - ] -} \ No newline at end of file diff --git a/tests/fvFabricExtConnP.json_pos1 b/tests/fvFabricExtConnP.json_pos1 deleted file mode 100644 index 551cce0..0000000 --- a/tests/fvFabricExtConnP.json_pos1 +++ /dev/null @@ -1,37 +0,0 @@ -{ - "totalCount": "3", - "imdata": [ - { - "fvPodConnP": { - "attributes": { - "annotation": "", - "assocIntersitePodId": "0", - "dn": "uni/tn-infra/fabricExtConnP-1/podConnP-1", - "id": "1" - - } - } - }, - { - "fvPodConnP": { - "attributes": { - "annotation": "", - "assocIntersitePodId": "0", - "dn": "uni/tn-infra/fabricExtConnP-1/podConnP-2", - "id": "2" - } - } - }, - { - "fvSiteConnP": { - "attributes": { - "annotation": "orchestrator:msc", - "bgpAsn": "65001", - "dn": "uni/tn-infra/fabricExtConnP-1/siteConnP-2", - "id": "2", - "name": "Calo-d" - } - } - } - ] -} \ No newline at end of file diff --git a/tests/fvFabricExtConnP.json_pos2 b/tests/fvFabricExtConnP.json_pos2 deleted file mode 100644 index 0e3b41f..0000000 --- a/tests/fvFabricExtConnP.json_pos2 +++ /dev/null @@ -1,26 +0,0 @@ -{ - "totalCount": "3", - "imdata": [ - { - "fvPodConnP": { - "attributes": { - "annotation": "", - "assocIntersitePodId": "0", - "dn": "uni/tn-infra/fabricExtConnP-1/podConnP-1", - "id": "1" - - } - } - }, - { - "fvPodConnP": { - "attributes": { - "annotation": "", - "assocIntersitePodId": "0", - "dn": "uni/tn-infra/fabricExtConnP-1/podConnP-2", - "id": "2" - } - } - } - ] -} \ No newline at end of file diff --git a/tests/fvFabricExtConnP.json_pos3 b/tests/fvFabricExtConnP.json_pos3 deleted file mode 100644 index 782aad6..0000000 --- a/tests/fvFabricExtConnP.json_pos3 +++ /dev/null @@ -1,27 +0,0 @@ -{ - "totalCount": "3", - "imdata": [ - { - "fvPodConnP": { - "attributes": { - "annotation": "", - "assocIntersitePodId": "0", - "dn": "uni/tn-infra/fabricExtConnP-1/podConnP-1", - "id": "1" - - } - } - }, - { - "fvSiteConnP": { - "attributes": { - "annotation": "orchestrator:msc", - "bgpAsn": "65001", - "dn": "uni/tn-infra/fabricExtConnP-1/siteConnP-2", - "id": "2", - "name": "Calo-d" - } - } - } - ] -} \ No newline at end of file diff --git a/tests/fvIfConn.json b/tests/fvIfConn.json deleted file mode 100644 index 2e8ca61..0000000 --- a/tests/fvIfConn.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "totalCount": "5", - "imdata": [ - { - "fvIfConn": { - "attributes": { - "dn": "uni/epp/fv-[uni/tn-bw/ap-physical/epg-phys3]/node-104/stpathatt-[eth1/2]/conndef/conn-[vlan-101]-[0.0.0.0]", - "encap": "vlan-101" - } - } - }, - { - "fvIfConn": { - "attributes": { - "dn": "uni/epp/fv-[uni/tn-bw/ap-mcast/epg-mcast1]/node-104/stpathatt-[bw-9k-L103-104-eth1-1]/conndef/conn-[vlan-101]-[0.0.0.0]", - "encap": "vlan-101" - } - } - }, - { - "fvIfConn": { - "attributes": { - "dn": "uni/epp/fv-[uni/tn-test/ap-app/epg-epg1]/node-101/stpathatt-[L101-eth1-1]/conndef/conn-[vlan-777]-[0.0.0.0]", - "encap": "vlan-777" - } - } - }, - { - "fvIfConn": { - "attributes": { - "dn": "uni/epp/fv-[uni/tn-test2/ap-app2/epg-epg2]/node-101/stpathatt-[eth1/2]/conndef/conn-[vlan-777]-[0.0.0.0]", - "encap": "vlan-777" - } - } - }, - { - "fvIfConn": { - "attributes": { - "dn": "uni/epp/fv-[uni/tn-test/ap-app/epg-epg1]/node-102/stpathatt-[L102-eth1-1]/conndef/conn-[vlan-778]-[0.0.0.0]", - "encap": "vlan-778" - } - } - }, - { - "fvIfConn": { - "attributes": { - "dn": "uni/epp/fv-[uni/tn-test2/ap-app2/epg-epg2]/node-102/stpathatt-[eth1/2]/conndef/conn-[vlan-778]-[0.0.0.0]", - "encap": "vlan-778" - } - } - } - ] -} \ No newline at end of file diff --git a/tests/fvnsVlanInstP.json_neg b/tests/fvnsVlanInstP.json_neg deleted file mode 100644 index 3fc0d15..0000000 --- a/tests/fvnsVlanInstP.json_neg +++ /dev/null @@ -1,209 +0,0 @@ -{ - "totalCount": "2", - "imdata": [ - { - "fvnsVlanInstP": { - "attributes": { - "allocMode": "static", - "annotation": "", - "childAction": "", - "configIssues": "", - "descr": "", - "dn": "uni/infra/vlanns-[bw-physical]-static", - "extMngdBy": "", - "lcOwn": "local", - "modTs": "2022-07-26T08:49:00.456-05:00", - "monPolDn": "uni/fabric/monfab-default", - "name": "bw-physical", - "nameAlias": "", - "ownerKey": "", - "ownerTag": "", - "status": "", - "uid": "15374", - "userdom": "all" - }, - "children": [ - { - "fvnsRtVlanNs": { - "attributes": { - "childAction": "", - "lcOwn": "local", - "modTs": "2022-07-26T08:49:01.581-05:00", - "rn": "rtinfraVlanNs-[uni/l3dom-bw-l3out]", - "status": "", - "tCl": "l3extDomP", - "tDn": "uni/l3dom-bw-l3out" - } - } - }, - { - "fvnsRtVlanNs": { - "attributes": { - "childAction": "", - "lcOwn": "local", - "modTs": "2022-07-26T08:49:01.165-05:00", - "rn": "rtinfraVlanNs-[uni/phys-bw-phys]", - "status": "", - "tCl": "physDomP", - "tDn": "uni/phys-bw-phys" - } - } - }, - { - "fvnsEncapBlk": { - "attributes": { - "allocMode": "inherit", - "annotation": "", - "childAction": "", - "descr": "", - "extMngdBy": "", - "from": "vlan-3000", - "lcOwn": "local", - "modTs": "2022-07-26T08:49:00.456-05:00", - "monPolDn": "uni/fabric/monfab-default", - "name": "", - "nameAlias": "", - "rn": "from-[vlan-3000]-to-[vlan-4000]", - "role": "external", - "status": "", - "to": "vlan-4000", - "uid": "15374", - "userdom": "all" - } - } - }, - { - "fvnsEncapBlk": { - "attributes": { - "allocMode": "static", - "annotation": "", - "childAction": "", - "descr": "", - "extMngdBy": "", - "from": "vlan-1", - "lcOwn": "local", - "modTs": "2022-07-26T08:49:00.456-05:00", - "monPolDn": "uni/fabric/monfab-default", - "name": "", - "nameAlias": "", - "rn": "from-[vlan-1]-to-[vlan-1000]", - "role": "external", - "status": "", - "to": "vlan-1000", - "uid": "15374", - "userdom": "all" - } - } - }, - { - "fvnsEncapBlk": { - "attributes": { - "allocMode": "static", - "annotation": "", - "childAction": "", - "descr": "", - "extMngdBy": "", - "from": "vlan-2000", - "lcOwn": "local", - "modTs": "2022-07-26T08:49:00.456-05:00", - "monPolDn": "uni/fabric/monfab-default", - "name": "", - "nameAlias": "", - "rn": "from-[vlan-2000]-to-[vlan-2099]", - "role": "external", - "status": "", - "to": "vlan-2099", - "uid": "15374", - "userdom": "all" - } - } - } - ] - } - }, - { - "fvnsVlanInstP": { - "attributes": { - "allocMode": "dynamic", - "annotation": "", - "childAction": "", - "configIssues": "", - "descr": "", - "dn": "uni/infra/vlanns-[jr-dynamic-pool]-dynamic", - "extMngdBy": "", - "lcOwn": "local", - "modTs": "2020-02-24T15:11:05.768-05:00", - "monPolDn": "uni/fabric/monfab-default", - "name": "jr-dynamic-pool", - "nameAlias": "", - "ownerKey": "", - "ownerTag": "", - "status": "", - "uid": "15374", - "userdom": "all" - }, - "children": [ - { - "fvnsRtVlanNs": { - "attributes": { - "childAction": "", - "lcOwn": "local", - "modTs": "2020-07-29T19:55:45.118-05:00", - "rn": "rtinfraVlanNs-[uni/vmmp-VMware/dom-jr-dvs]", - "status": "", - "tCl": "vmmDomP", - "tDn": "uni/vmmp-VMware/dom-jr-ave" - } - } - }, - { - "fvnsEncapBlk": { - "attributes": { - "allocMode": "inherit", - "annotation": "", - "childAction": "", - "descr": "", - "extMngdBy": "", - "from": "vlan-3100", - "lcOwn": "local", - "modTs": "2020-04-30T10:32:16.290-05:00", - "monPolDn": "uni/fabric/monfab-default", - "name": "", - "nameAlias": "", - "rn": "from-[vlan-3100]-to-[vlan-3200]", - "role": "internal", - "status": "", - "to": "vlan-3200", - "uid": "15374", - "userdom": "all" - } - } - }, - { - "fvnsEncapBlk": { - "attributes": { - "allocMode": "inherit", - "annotation": "", - "childAction": "", - "descr": "", - "extMngdBy": "", - "from": "vlan-2000", - "lcOwn": "local", - "modTs": "2020-02-24T15:11:05.768-05:00", - "monPolDn": "uni/fabric/monfab-default", - "name": "", - "nameAlias": "", - "rn": "from-[vlan-2000]-to-[vlan-2099]", - "role": "external", - "status": "", - "to": "vlan-2099", - "uid": "15374", - "userdom": "all" - } - } - } - ] - } - } - ] -} \ No newline at end of file diff --git a/tests/fvnsVlanInstP.json_pos b/tests/fvnsVlanInstP.json_pos deleted file mode 100644 index 71f302f..0000000 --- a/tests/fvnsVlanInstP.json_pos +++ /dev/null @@ -1,89 +0,0 @@ -{ - "totalCount": "1", - "imdata": [ - { - "fvnsVlanInstP": { - "attributes": { - "allocMode": "dynamic", - "annotation": "", - "childAction": "", - "configIssues": "", - "descr": "", - "dn": "uni/infra/vlanns-[jr-dynamic-pool]-dynamic", - "extMngdBy": "", - "lcOwn": "local", - "modTs": "2020-02-24T15:11:05.768-05:00", - "monPolDn": "uni/fabric/monfab-default", - "name": "jr-dynamic-pool", - "nameAlias": "", - "ownerKey": "", - "ownerTag": "", - "status": "", - "uid": "15374", - "userdom": "all" - }, - "children": [ - { - "fvnsRtVlanNs": { - "attributes": { - "childAction": "", - "lcOwn": "local", - "modTs": "2020-07-29T19:55:45.118-05:00", - "rn": "rtinfraVlanNs-[uni/vmmp-VMware/dom-jr-dvs]", - "status": "", - "tCl": "vmmDomP", - "tDn": "uni/vmmp-VMware/dom-jr-dvs" - } - } - }, - { - "fvnsEncapBlk": { - "attributes": { - "allocMode": "inherit", - "annotation": "", - "childAction": "", - "descr": "", - "extMngdBy": "", - "from": "vlan-3100", - "lcOwn": "local", - "modTs": "2020-04-30T10:32:16.290-05:00", - "monPolDn": "uni/fabric/monfab-default", - "name": "", - "nameAlias": "", - "rn": "from-[vlan-3100]-to-[vlan-3200]", - "role": "internal", - "status": "", - "to": "vlan-3200", - "uid": "15374", - "userdom": "all" - } - } - }, - { - "fvnsEncapBlk": { - "attributes": { - "allocMode": "inherit", - "annotation": "", - "childAction": "", - "descr": "", - "extMngdBy": "", - "from": "vlan-2000", - "lcOwn": "local", - "modTs": "2020-02-24T15:11:05.768-05:00", - "monPolDn": "uni/fabric/monfab-default", - "name": "", - "nameAlias": "", - "rn": "from-[vlan-2000]-to-[vlan-2099]", - "role": "external", - "status": "", - "to": "vlan-2099", - "uid": "15374", - "userdom": "all" - } - } - } - ] - } - } - ] -} \ No newline at end of file diff --git a/tests/internal_vlanpool_check/fvnsVlanInstP_neg.json b/tests/internal_vlanpool_check/fvnsVlanInstP_neg.json new file mode 100644 index 0000000..686efdc --- /dev/null +++ b/tests/internal_vlanpool_check/fvnsVlanInstP_neg.json @@ -0,0 +1,206 @@ +[ + { + "fvnsVlanInstP": { + "attributes": { + "allocMode": "static", + "annotation": "", + "childAction": "", + "configIssues": "", + "descr": "", + "dn": "uni/infra/vlanns-[bw-physical]-static", + "extMngdBy": "", + "lcOwn": "local", + "modTs": "2022-07-26T08:49:00.456-05:00", + "monPolDn": "uni/fabric/monfab-default", + "name": "bw-physical", + "nameAlias": "", + "ownerKey": "", + "ownerTag": "", + "status": "", + "uid": "15374", + "userdom": "all" + }, + "children": [ + { + "fvnsRtVlanNs": { + "attributes": { + "childAction": "", + "lcOwn": "local", + "modTs": "2022-07-26T08:49:01.581-05:00", + "rn": "rtinfraVlanNs-[uni/l3dom-bw-l3out]", + "status": "", + "tCl": "l3extDomP", + "tDn": "uni/l3dom-bw-l3out" + } + } + }, + { + "fvnsRtVlanNs": { + "attributes": { + "childAction": "", + "lcOwn": "local", + "modTs": "2022-07-26T08:49:01.165-05:00", + "rn": "rtinfraVlanNs-[uni/phys-bw-phys]", + "status": "", + "tCl": "physDomP", + "tDn": "uni/phys-bw-phys" + } + } + }, + { + "fvnsEncapBlk": { + "attributes": { + "allocMode": "inherit", + "annotation": "", + "childAction": "", + "descr": "", + "extMngdBy": "", + "from": "vlan-3000", + "lcOwn": "local", + "modTs": "2022-07-26T08:49:00.456-05:00", + "monPolDn": "uni/fabric/monfab-default", + "name": "", + "nameAlias": "", + "rn": "from-[vlan-3000]-to-[vlan-4000]", + "role": "external", + "status": "", + "to": "vlan-4000", + "uid": "15374", + "userdom": "all" + } + } + }, + { + "fvnsEncapBlk": { + "attributes": { + "allocMode": "static", + "annotation": "", + "childAction": "", + "descr": "", + "extMngdBy": "", + "from": "vlan-1", + "lcOwn": "local", + "modTs": "2022-07-26T08:49:00.456-05:00", + "monPolDn": "uni/fabric/monfab-default", + "name": "", + "nameAlias": "", + "rn": "from-[vlan-1]-to-[vlan-1000]", + "role": "external", + "status": "", + "to": "vlan-1000", + "uid": "15374", + "userdom": "all" + } + } + }, + { + "fvnsEncapBlk": { + "attributes": { + "allocMode": "static", + "annotation": "", + "childAction": "", + "descr": "", + "extMngdBy": "", + "from": "vlan-2000", + "lcOwn": "local", + "modTs": "2022-07-26T08:49:00.456-05:00", + "monPolDn": "uni/fabric/monfab-default", + "name": "", + "nameAlias": "", + "rn": "from-[vlan-2000]-to-[vlan-2099]", + "role": "external", + "status": "", + "to": "vlan-2099", + "uid": "15374", + "userdom": "all" + } + } + } + ] + } + }, + { + "fvnsVlanInstP": { + "attributes": { + "allocMode": "dynamic", + "annotation": "", + "childAction": "", + "configIssues": "", + "descr": "", + "dn": "uni/infra/vlanns-[jr-dynamic-pool]-dynamic", + "extMngdBy": "", + "lcOwn": "local", + "modTs": "2020-02-24T15:11:05.768-05:00", + "monPolDn": "uni/fabric/monfab-default", + "name": "jr-dynamic-pool", + "nameAlias": "", + "ownerKey": "", + "ownerTag": "", + "status": "", + "uid": "15374", + "userdom": "all" + }, + "children": [ + { + "fvnsRtVlanNs": { + "attributes": { + "childAction": "", + "lcOwn": "local", + "modTs": "2020-07-29T19:55:45.118-05:00", + "rn": "rtinfraVlanNs-[uni/vmmp-VMware/dom-jr-dvs]", + "status": "", + "tCl": "vmmDomP", + "tDn": "uni/vmmp-VMware/dom-jr-ave" + } + } + }, + { + "fvnsEncapBlk": { + "attributes": { + "allocMode": "inherit", + "annotation": "", + "childAction": "", + "descr": "", + "extMngdBy": "", + "from": "vlan-3100", + "lcOwn": "local", + "modTs": "2020-04-30T10:32:16.290-05:00", + "monPolDn": "uni/fabric/monfab-default", + "name": "", + "nameAlias": "", + "rn": "from-[vlan-3100]-to-[vlan-3200]", + "role": "internal", + "status": "", + "to": "vlan-3200", + "uid": "15374", + "userdom": "all" + } + } + }, + { + "fvnsEncapBlk": { + "attributes": { + "allocMode": "inherit", + "annotation": "", + "childAction": "", + "descr": "", + "extMngdBy": "", + "from": "vlan-2000", + "lcOwn": "local", + "modTs": "2020-02-24T15:11:05.768-05:00", + "monPolDn": "uni/fabric/monfab-default", + "name": "", + "nameAlias": "", + "rn": "from-[vlan-2000]-to-[vlan-2099]", + "role": "external", + "status": "", + "to": "vlan-2099", + "uid": "15374", + "userdom": "all" + } + } + } + ] + } + } +] diff --git a/tests/internal_vlanpool_check/fvnsVlanInstP_pos.json b/tests/internal_vlanpool_check/fvnsVlanInstP_pos.json new file mode 100644 index 0000000..2564692 --- /dev/null +++ b/tests/internal_vlanpool_check/fvnsVlanInstP_pos.json @@ -0,0 +1,86 @@ +[ + { + "fvnsVlanInstP": { + "attributes": { + "allocMode": "dynamic", + "annotation": "", + "childAction": "", + "configIssues": "", + "descr": "", + "dn": "uni/infra/vlanns-[jr-dynamic-pool]-dynamic", + "extMngdBy": "", + "lcOwn": "local", + "modTs": "2020-02-24T15:11:05.768-05:00", + "monPolDn": "uni/fabric/monfab-default", + "name": "jr-dynamic-pool", + "nameAlias": "", + "ownerKey": "", + "ownerTag": "", + "status": "", + "uid": "15374", + "userdom": "all" + }, + "children": [ + { + "fvnsRtVlanNs": { + "attributes": { + "childAction": "", + "lcOwn": "local", + "modTs": "2020-07-29T19:55:45.118-05:00", + "rn": "rtinfraVlanNs-[uni/vmmp-VMware/dom-jr-dvs]", + "status": "", + "tCl": "vmmDomP", + "tDn": "uni/vmmp-VMware/dom-jr-dvs" + } + } + }, + { + "fvnsEncapBlk": { + "attributes": { + "allocMode": "inherit", + "annotation": "", + "childAction": "", + "descr": "", + "extMngdBy": "", + "from": "vlan-3100", + "lcOwn": "local", + "modTs": "2020-04-30T10:32:16.290-05:00", + "monPolDn": "uni/fabric/monfab-default", + "name": "", + "nameAlias": "", + "rn": "from-[vlan-3100]-to-[vlan-3200]", + "role": "internal", + "status": "", + "to": "vlan-3200", + "uid": "15374", + "userdom": "all" + } + } + }, + { + "fvnsEncapBlk": { + "attributes": { + "allocMode": "inherit", + "annotation": "", + "childAction": "", + "descr": "", + "extMngdBy": "", + "from": "vlan-2000", + "lcOwn": "local", + "modTs": "2020-02-24T15:11:05.768-05:00", + "monPolDn": "uni/fabric/monfab-default", + "name": "", + "nameAlias": "", + "rn": "from-[vlan-2000]-to-[vlan-2099]", + "role": "external", + "status": "", + "to": "vlan-2099", + "uid": "15374", + "userdom": "all" + } + } + } + ] + } + } +] diff --git a/tests/internal_vlanpool_check/test_internal_vlanpool_check.py b/tests/internal_vlanpool_check/test_internal_vlanpool_check.py new file mode 100644 index 0000000..6d16279 --- /dev/null +++ b/tests/internal_vlanpool_check/test_internal_vlanpool_check.py @@ -0,0 +1,105 @@ +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 +fvnsVlanInstPs = "fvnsVlanInstP.json?rsp-subtree=children&rsp-subtree-class=fvnsRtVlanNs,fvnsEncapBlk&rsp-subtree-include=required" +vmmDomPs = "vmmDomP.json" + + +@pytest.mark.parametrize( + "icurl_outputs, tversion, expected_result", + [ + ( + { + fvnsVlanInstPs: read_data(dir, "fvnsVlanInstP_pos.json"), + vmmDomPs: read_data(dir, "vmmDomP_pos.json"), + }, + "5.2(2a)", + script.FAIL_O, + ), + ( + { + fvnsVlanInstPs: read_data(dir, "fvnsVlanInstP_pos.json"), + vmmDomPs: read_data(dir, "vmmDomP_pos.json"), + }, + "4.2(4d)", + script.PASS, + ), + ( + { + fvnsVlanInstPs: read_data(dir, "fvnsVlanInstP_pos.json"), + vmmDomPs: read_data(dir, "vmmDomP_pos.json"), + }, + "5.2(6a)", + script.FAIL_O, + ), + ( + { + fvnsVlanInstPs: read_data(dir, "fvnsVlanInstP_pos.json"), + vmmDomPs: read_data(dir, "vmmDomP_pos.json"), + }, + "4.2(7d)", + script.FAIL_O, + ), + ( + { + fvnsVlanInstPs: read_data(dir, "fvnsVlanInstP_pos.json"), + vmmDomPs: read_data(dir, "vmmDomP_pos.json"), + }, + "2.2(4r)", + script.PASS, + ), + ( + { + fvnsVlanInstPs: read_data(dir, "fvnsVlanInstP_neg.json"), + vmmDomPs: read_data(dir, "vmmDomP_neg.json"), + }, + "5.2(2a)", + script.PASS, + ), + ( + { + fvnsVlanInstPs: read_data(dir, "fvnsVlanInstP_neg.json"), + vmmDomPs: read_data(dir, "vmmDomP_neg.json"), + }, + "4.2(4d)", + script.PASS, + ), + ( + { + fvnsVlanInstPs: read_data(dir, "fvnsVlanInstP_neg.json"), + vmmDomPs: read_data(dir, "vmmDomP_neg.json"), + }, + "5.2(6a)", + script.PASS, + ), + ( + { + fvnsVlanInstPs: read_data(dir, "fvnsVlanInstP_neg.json"), + vmmDomPs: read_data(dir, "vmmDomP_neg.json"), + }, + "4.2(7d)", + script.PASS, + ), + ( + { + fvnsVlanInstPs: read_data(dir, "fvnsVlanInstP_neg.json"), + vmmDomPs: read_data(dir, "vmmDomP_neg.json"), + }, + "2.2(4r)", + script.PASS, + ), + ], +) +def test_logic(mock_icurl, tversion, expected_result): + result = script.internal_vlanpool_check(1, 1, script.AciVersion(tversion)) + assert result == expected_result diff --git a/tests/internal_vlanpool_check/vmmDomP_neg.json b/tests/internal_vlanpool_check/vmmDomP_neg.json new file mode 100644 index 0000000..2662d00 --- /dev/null +++ b/tests/internal_vlanpool_check/vmmDomP_neg.json @@ -0,0 +1,84 @@ +[ + { + "vmmDomP": { + "attributes": { + "accessMode": "read-write", + "annotation": "", + "arpLearning": "", + "aveTimeOut": "30", + "childAction": "", + "configInfraPg": "no", + "configIssues": "", + "ctrlKnob": "epDpVerify", + "delimiter": "", + "dn": "uni/vmmp-VMware/dom-jr-ave", + "enableAVE": "yes", + "enableTag": "no", + "enableVmFolder": "no", + "encapMode": "vxlan", + "enfPref": "sw", + "epInventoryType": "on-link", + "epRetTime": "0", + "extMngdBy": "", + "hvAvailMonitor": "yes", + "lagPolicyName": "", + "lcOwn": "local", + "mcastAddr": "239.1.1.1", + "modTs": "2021-04-20T14:52:27.404-05:00", + "mode": "default", + "monPolDn": "uni/fabric/monfab-default", + "name": "jr-ave", + "nameAlias": "", + "ownerKey": "", + "ownerTag": "", + "prefEncapMode": "vxlan", + "status": "", + "txId": "3458764513832453119", + "uid": "15374", + "uniqueId": "6909", + "userdom": "all" + } + } + }, + { + "vmmDomP": { + "attributes": { + "accessMode": "read-write", + "annotation": "", + "arpLearning": "", + "aveTimeOut": "30", + "childAction": "", + "configInfraPg": "no", + "configIssues": "", + "ctrlKnob": "epDpVerify", + "delimiter": "", + "dn": "uni/vmmp-VMware/dom-jr-dvs", + "enableAVE": "no", + "enableTag": "no", + "enableVmFolder": "no", + "encapMode": "unknown", + "enfPref": "hw", + "epInventoryType": "on-link", + "epRetTime": "0", + "extMngdBy": "", + "hvAvailMonitor": "no", + "lagPolicyName": "", + "lcOwn": "local", + "mcastAddr": "0.0.0.0", + "modTs": "2021-07-19T22:31:58.605-05:00", + "mode": "default", + "monPolDn": "uni/fabric/monfab-default", + "name": "jr-dvs", + "nameAlias": "", + "ownerKey": "", + "ownerTag": "", + "prefEncapMode": "unspecified", + "status": "", + "txId": "13835058055287371636", + "uid": "15374", + "uniqueId": "8595", + "userdom": "all" + } + } + } +] diff --git a/tests/internal_vlanpool_check/vmmDomP_pos.json b/tests/internal_vlanpool_check/vmmDomP_pos.json new file mode 100644 index 0000000..be5caf6 --- /dev/null +++ b/tests/internal_vlanpool_check/vmmDomP_pos.json @@ -0,0 +1,84 @@ +[ + { + "vmmDomP": { + "attributes": { + "accessMode": "read-write", + "annotation": "", + "arpLearning": "", + "aveTimeOut": "30", + "childAction": "", + "configInfraPg": "no", + "configIssues": "", + "ctrlKnob": "epDpVerify", + "delimiter": "", + "dn": "uni/vmmp-VMware/dom-jr-ave", + "enableAVE": "no", + "enableTag": "no", + "enableVmFolder": "no", + "encapMode": "vxlan", + "enfPref": "sw", + "epInventoryType": "on-link", + "epRetTime": "0", + "extMngdBy": "", + "hvAvailMonitor": "yes", + "lagPolicyName": "", + "lcOwn": "local", + "mcastAddr": "239.1.1.1", + "modTs": "2021-04-20T14:52:27.404-05:00", + "mode": "default", + "monPolDn": "uni/fabric/monfab-default", + "name": "jr-ave", + "nameAlias": "", + "ownerKey": "", + "ownerTag": "", + "prefEncapMode": "vxlan", + "status": "", + "txId": "3458764513832453119", + "uid": "15374", + "uniqueId": "6909", + "userdom": "all" + } + } + }, + { + "vmmDomP": { + "attributes": { + "accessMode": "read-write", + "annotation": "", + "arpLearning": "", + "aveTimeOut": "30", + "childAction": "", + "configInfraPg": "no", + "configIssues": "", + "ctrlKnob": "epDpVerify", + "delimiter": "", + "dn": "uni/vmmp-VMware/dom-jr-dvs", + "enableAVE": "no", + "enableTag": "no", + "enableVmFolder": "no", + "encapMode": "unknown", + "enfPref": "hw", + "epInventoryType": "on-link", + "epRetTime": "0", + "extMngdBy": "", + "hvAvailMonitor": "no", + "lagPolicyName": "", + "lcOwn": "local", + "mcastAddr": "0.0.0.0", + "modTs": "2021-07-19T22:31:58.605-05:00", + "mode": "default", + "monPolDn": "uni/fabric/monfab-default", + "name": "jr-dvs", + "nameAlias": "", + "ownerKey": "", + "ownerTag": "", + "prefEncapMode": "unspecified", + "status": "", + "txId": "13835058055287371636", + "uid": "15374", + "uniqueId": "8595", + "userdom": "all" + } + } + } +] diff --git a/tests/isisDomP-default.json_missing b/tests/isisDomP-default.json_missing deleted file mode 100644 index 4b65555..0000000 --- a/tests/isisDomP-default.json_missing +++ /dev/null @@ -1,12 +0,0 @@ -{ - "totalCount": "1", - "imdata": [ - { - "isisDomPol": { - "attributes": { - "dn": "uni/fabric/isisDomP-default" - } - } - } - ] -} \ No newline at end of file diff --git a/tests/isisDomP-default.json_neg b/tests/isisDomP-default.json_neg deleted file mode 100644 index cc76ba6..0000000 --- a/tests/isisDomP-default.json_neg +++ /dev/null @@ -1,13 +0,0 @@ -{ - "totalCount": "1", - "imdata": [ - { - "isisDomPol": { - "attributes": { - "dn": "uni/fabric/isisDomP-default", - "redistribMetric": "62" - } - } - } - ] -} \ No newline at end of file diff --git a/tests/isisDomP-default.json_pos b/tests/isisDomP-default.json_pos deleted file mode 100644 index fcaf9fc..0000000 --- a/tests/isisDomP-default.json_pos +++ /dev/null @@ -1,13 +0,0 @@ -{ - "totalCount": "1", - "imdata": [ - { - "isisDomPol": { - "attributes": { - "dn": "uni/fabric/isisDomP-default", - "redistribMetric": "63" - } - } - } - ] -} \ No newline at end of file diff --git a/tests/isis_redis_metric_mpod_msite_check/fvFabricExtConnP_pos1.json b/tests/isis_redis_metric_mpod_msite_check/fvFabricExtConnP_pos1.json new file mode 100644 index 0000000..7c75031 --- /dev/null +++ b/tests/isis_redis_metric_mpod_msite_check/fvFabricExtConnP_pos1.json @@ -0,0 +1,34 @@ +[ + { + "fvPodConnP": { + "attributes": { + "annotation": "", + "assocIntersitePodId": "0", + "dn": "uni/tn-infra/fabricExtConnP-1/podConnP-1", + "id": "1" + + } + } + }, + { + "fvPodConnP": { + "attributes": { + "annotation": "", + "assocIntersitePodId": "0", + "dn": "uni/tn-infra/fabricExtConnP-1/podConnP-2", + "id": "2" + } + } + }, + { + "fvSiteConnP": { + "attributes": { + "annotation": "orchestrator:msc", + "bgpAsn": "65001", + "dn": "uni/tn-infra/fabricExtConnP-1/siteConnP-2", + "id": "2", + "name": "Calo-d" + } + } + } +] diff --git a/tests/isis_redis_metric_mpod_msite_check/fvFabricExtConnP_pos2.json b/tests/isis_redis_metric_mpod_msite_check/fvFabricExtConnP_pos2.json new file mode 100644 index 0000000..ff88b61 --- /dev/null +++ b/tests/isis_redis_metric_mpod_msite_check/fvFabricExtConnP_pos2.json @@ -0,0 +1,23 @@ +[ + { + "fvPodConnP": { + "attributes": { + "annotation": "", + "assocIntersitePodId": "0", + "dn": "uni/tn-infra/fabricExtConnP-1/podConnP-1", + "id": "1" + + } + } + }, + { + "fvPodConnP": { + "attributes": { + "annotation": "", + "assocIntersitePodId": "0", + "dn": "uni/tn-infra/fabricExtConnP-1/podConnP-2", + "id": "2" + } + } + } +] diff --git a/tests/isis_redis_metric_mpod_msite_check/fvFabricExtConnP_pos3.json b/tests/isis_redis_metric_mpod_msite_check/fvFabricExtConnP_pos3.json new file mode 100644 index 0000000..0f33b03 --- /dev/null +++ b/tests/isis_redis_metric_mpod_msite_check/fvFabricExtConnP_pos3.json @@ -0,0 +1,24 @@ +[ + { + "fvPodConnP": { + "attributes": { + "annotation": "", + "assocIntersitePodId": "0", + "dn": "uni/tn-infra/fabricExtConnP-1/podConnP-1", + "id": "1" + + } + } + }, + { + "fvSiteConnP": { + "attributes": { + "annotation": "orchestrator:msc", + "bgpAsn": "65001", + "dn": "uni/tn-infra/fabricExtConnP-1/siteConnP-2", + "id": "2", + "name": "Calo-d" + } + } + } +] diff --git a/tests/isis_redis_metric_mpod_msite_check/isisDomP-default_missing.json b/tests/isis_redis_metric_mpod_msite_check/isisDomP-default_missing.json new file mode 100644 index 0000000..29b0664 --- /dev/null +++ b/tests/isis_redis_metric_mpod_msite_check/isisDomP-default_missing.json @@ -0,0 +1,9 @@ +[ + { + "isisDomPol": { + "attributes": { + "dn": "uni/fabric/isisDomP-default" + } + } + } +] diff --git a/tests/isis_redis_metric_mpod_msite_check/isisDomP-default_neg.json b/tests/isis_redis_metric_mpod_msite_check/isisDomP-default_neg.json new file mode 100644 index 0000000..bddcfdf --- /dev/null +++ b/tests/isis_redis_metric_mpod_msite_check/isisDomP-default_neg.json @@ -0,0 +1,10 @@ +[ + { + "isisDomPol": { + "attributes": { + "dn": "uni/fabric/isisDomP-default", + "redistribMetric": "62" + } + } + } +] diff --git a/tests/isis_redis_metric_mpod_msite_check/isisDomP-default_pos.json b/tests/isis_redis_metric_mpod_msite_check/isisDomP-default_pos.json new file mode 100644 index 0000000..79aa8f6 --- /dev/null +++ b/tests/isis_redis_metric_mpod_msite_check/isisDomP-default_pos.json @@ -0,0 +1,10 @@ +[ + { + "isisDomPol": { + "attributes": { + "dn": "uni/fabric/isisDomP-default", + "redistribMetric": "63" + } + } + } +] diff --git a/tests/isis_redis_metric_mpod_msite_check/test_isis_redis_metric_mpod_msite_check.py b/tests/isis_redis_metric_mpod_msite_check/test_isis_redis_metric_mpod_msite_check.py new file mode 100644 index 0000000..153c248 --- /dev/null +++ b/tests/isis_redis_metric_mpod_msite_check/test_isis_redis_metric_mpod_msite_check.py @@ -0,0 +1,60 @@ +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 +isisDomPs = "uni/fabric/isisDomP-default.json" +fvFabricExtConnPs = "fvFabricExtConnP.json?query-target=children" + + +@pytest.mark.parametrize( + "icurl_outputs, expected_result", + [ + ( + { + isisDomPs: read_data(dir, "isisDomP-default_pos.json"), + fvFabricExtConnPs: read_data(dir, "fvFabricExtConnP_pos1.json"), + }, + script.FAIL_O, + ), + ( + { + isisDomPs: read_data(dir, "isisDomP-default_pos.json"), + fvFabricExtConnPs: read_data(dir, "fvFabricExtConnP_pos2.json"), + }, + script.FAIL_O, + ), + ( + { + isisDomPs: read_data(dir, "isisDomP-default_pos.json"), + fvFabricExtConnPs: read_data(dir, "fvFabricExtConnP_pos3.json"), + }, + script.FAIL_O, + ), + ( + { + isisDomPs: read_data(dir, "isisDomP-default_neg.json"), + fvFabricExtConnPs: read_data(dir, "fvFabricExtConnP_pos1.json"), + }, + script.PASS, + ), + ( + { + isisDomPs: read_data(dir, "isisDomP-default_missing.json"), + fvFabricExtConnPs: read_data(dir, "fvFabricExtConnP_pos1.json"), + }, + script.FAIL_O, + ), + ], +) +def test_logic(mock_icurl, expected_result): + result = script.isis_redis_metric_mpod_msite_check(1, 1) + assert result == expected_result diff --git a/tests/llfc_susceptibility_check/ethpmFcot.json b/tests/llfc_susceptibility_check/ethpmFcot.json new file mode 100644 index 0000000..34d7cdc --- /dev/null +++ b/tests/llfc_susceptibility_check/ethpmFcot.json @@ -0,0 +1,46 @@ +[ + { + "ethpmFcot": { + "attributes": { + "actualType": "sfp", + "dn": "topology/pod-1/node-101/sys/phys-[eth1/6]/phys/fcot", + "state": "inserted", + "type": "sfp", + "typeName": "1000base-T" + } + } + }, + { + "ethpmFcot": { + "attributes": { + "actualType": "sfp", + "dn": "topology/pod-1/node-103/sys/phys-[eth1/6]/phys/fcot", + "state": "inserted", + "type": "sfp", + "typeName": "1000base-T" + } + } + }, + { + "ethpmFcot": { + "attributes": { + "actualType": "sfp", + "dn": "topology/pod-1/node-101/sys/phys-[eth1/7]/phys/fcot", + "state": "inserted", + "type": "sfp", + "typeName": "1000base-SX" + } + } + }, + { + "ethpmFcot": { + "attributes": { + "actualType": "sfp", + "dn": "topology/pod-1/node-103/sys/phys-[eth1/7]/phys/fcot", + "state": "inserted", + "type": "sfp", + "typeName": "1000base-SX" + } + } + } +] diff --git a/tests/llfc_susceptibility_check/test_llfc_susceptibility_check.py b/tests/llfc_susceptibility_check/test_llfc_susceptibility_check.py new file mode 100644 index 0000000..c86b745 --- /dev/null +++ b/tests/llfc_susceptibility_check/test_llfc_susceptibility_check.py @@ -0,0 +1,86 @@ +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 +ethpmFcots = 'ethpmFcot.json?query-target-filter=and(eq(ethpmFcot.type,"sfp"),eq(ethpmFcot.state,"inserted"))' + + +@pytest.mark.parametrize( + "icurl_outputs, cversion, tversion, vpc_node_ids, expected_result", + [ + ( + {ethpmFcots: read_data(dir, "ethpmFcot.json")}, + "4.2(1b)", + "5.2(2a)", + ["101", "103", "204", "206"], + script.MANUAL, + ), + ( + {ethpmFcots: read_data(dir, "ethpmFcot.json")}, + "3.2(1a)", + "4.2(4d)", + ["101", "103", "204", "206"], + script.MANUAL, + ), + ( + {ethpmFcots: read_data(dir, "ethpmFcot.json")}, + "3.2(1a)", + "5.2(6a)", + ["101", "103", "204", "206"], + script.MANUAL, + ), + ( + {ethpmFcots: read_data(dir, "ethpmFcot.json")}, + "4.2(3a)", + "4.2(7d)", + ["101", "103", "204", "206"], + script.MANUAL, + ), + ( + {ethpmFcots: read_data(dir, "ethpmFcot.json")}, + "2.2(3a)", + "2.2(4r)", + ["101", "103", "204", "206"], + script.PASS, + ), + ( + {ethpmFcots: read_data(dir, "ethpmFcot.json")}, + "5.2(1a)", + None, + ["101", "103", "204", "206"], + script.MANUAL, + ), + ( + {ethpmFcots: read_data(dir, "ethpmFcot.json")}, + "4.1(1a)", + "5.2(7f)", + ["101", "103", "204", "206"], + script.MANUAL, + ), + ( + {ethpmFcots: read_data(dir, "ethpmFcot.json")}, + "4.1(1a)", + "5.2(7f)", + [], + script.PASS, + ), + ], +) +def test_logic(mock_icurl, cversion, tversion, vpc_node_ids, expected_result): + result = script.llfc_susceptibility_check( + 1, + 1, + script.AciVersion(cversion), + script.AciVersion(tversion) if tversion else None, + vpc_node_ids=vpc_node_ids, + ) + assert result == expected_result diff --git a/tests/switch_bootflash_usage_check/eqptcapacityFSPartition_pos.json b/tests/switch_bootflash_usage_check/eqptcapacityFSPartition_pos.json new file mode 100644 index 0000000..e107096 --- /dev/null +++ b/tests/switch_bootflash_usage_check/eqptcapacityFSPartition_pos.json @@ -0,0 +1,178 @@ +[ + { + "eqptcapacityFSPartition": { + "attributes": { + "avail": "6160040", + "childAction": "", + "dn": "topology/pod-1/node-102/sys/eqptcapacity/fspartition-bootflash", + "memAlert": "normal", + "modTs": "never", + "monPolDn": "uni/fabric/monfab-default", + "name": "bootflash", + "path": "/bootflash", + "status": "", + "used": "5374088" + } + } + }, + { + "eqptcapacityFSPartition": { + "attributes": { + "avail": "6643924", + "childAction": "", + "dn": "topology/pod-1/node-103/sys/eqptcapacity/fspartition-bootflash", + "memAlert": "normal", + "modTs": "never", + "monPolDn": "uni/fabric/monfab-default", + "name": "bootflash", + "path": "/bootflash", + "status": "", + "used": "4332192" + } + } + }, + { + "eqptcapacityFSPartition": { + "attributes": { + "avail": "6916228", + "childAction": "", + "dn": "topology/pod-2/node-205/sys/eqptcapacity/fspartition-bootflash", + "memAlert": "normal", + "modTs": "never", + "monPolDn": "uni/fabric/monfab-default", + "name": "bootflash", + "path": "/bootflash", + "status": "", + "used": "4059888" + } + } + }, + { + "eqptcapacityFSPartition": { + "attributes": { + "avail": "7261676", + "childAction": "", + "dn": "topology/pod-2/node-206/sys/eqptcapacity/fspartition-bootflash", + "memAlert": "normal", + "modTs": "never", + "monPolDn": "uni/fabric/monfab-default", + "name": "bootflash", + "path": "/bootflash", + "status": "", + "used": "3714440" + } + } + }, + { + "eqptcapacityFSPartition": { + "attributes": { + "avail": "7422756", + "childAction": "", + "dn": "topology/pod-1/node-1002/sys/eqptcapacity/fspartition-bootflash", + "memAlert": "normal", + "modTs": "never", + "monPolDn": "uni/fabric/monfab-default", + "name": "bootflash", + "path": "/bootflash", + "status": "", + "used": "4111372" + } + } + }, + { + "eqptcapacityFSPartition": { + "attributes": { + "avail": "5980968", + "childAction": "", + "dn": "topology/pod-1/node-1001/sys/eqptcapacity/fspartition-bootflash", + "memAlert": "normal", + "modTs": "never", + "monPolDn": "uni/fabric/monfab-default", + "name": "bootflash", + "path": "/bootflash", + "status": "", + "used": "4995148" + } + } + }, + { + "eqptcapacityFSPartition": { + "attributes": { + "avail": "16712928", + "childAction": "", + "dn": "topology/pod-2/node-2002/sys/eqptcapacity/fspartition-bootflash", + "memAlert": "normal", + "modTs": "never", + "monPolDn": "uni/fabric/monfab-default", + "name": "bootflash", + "path": "/bootflash", + "status": "", + "used": "6502564" + } + } + }, + { + "eqptcapacityFSPartition": { + "attributes": { + "avail": "16923436", + "childAction": "", + "dn": "topology/pod-2/node-2003/sys/eqptcapacity/fspartition-bootflash", + "memAlert": "normal", + "modTs": "never", + "monPolDn": "uni/fabric/monfab-default", + "name": "bootflash", + "path": "/bootflash", + "status": "", + "used": "6292056" + } + } + }, + { + "eqptcapacityFSPartition": { + "attributes": { + "avail": "6438436", + "childAction": "", + "dn": "topology/pod-2/node-2001/sys/eqptcapacity/fspartition-bootflash", + "memAlert": "normal", + "modTs": "never", + "monPolDn": "uni/fabric/monfab-default", + "name": "bootflash", + "path": "/bootflash", + "status": "", + "used": "4537680" + } + } + }, + { + "eqptcapacityFSPartition": { + "attributes": { + "avail": "8031460", + "childAction": "", + "dn": "topology/pod-2/node-2010/sys/eqptcapacity/fspartition-bootflash", + "memAlert": "normal", + "modTs": "never", + "monPolDn": "uni/fabric/monfab-default", + "name": "bootflash", + "path": "/bootflash", + "status": "", + "used": "4127820" + } + } + }, + { + "eqptcapacityFSPartition": { + "attributes": { + "avail": "5347648", + "childAction": "", + "dn": "topology/pod-1/node-101/sys/eqptcapacity/fspartition-bootflash", + "memAlert": "normal", + "modTs": "never", + "monPolDn": "uni/fabric/monfab-default", + "name": "bootflash", + "path": "/bootflash", + "status": "", + "used": "5628468" + } + } + } +] diff --git a/tests/switch_bootflash_usage_check/test_switch_bootflash_usage_check.py b/tests/switch_bootflash_usage_check/test_switch_bootflash_usage_check.py new file mode 100644 index 0000000..c69cb4d --- /dev/null +++ b/tests/switch_bootflash_usage_check/test_switch_bootflash_usage_check.py @@ -0,0 +1,28 @@ +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 +partitions = 'eqptcapacityFSPartition.json?query-target-filter=eq(eqptcapacityFSPartition.path,"/bootflash")' + + +@pytest.mark.parametrize( + "icurl_outputs, expected_result", + [ + ( + {partitions: read_data(dir, "eqptcapacityFSPartition_pos.json")}, + script.FAIL_UF, + ), + ], +) +def test_logic(mock_icurl, expected_result): + result = script.switch_bootflash_usage_check(1, 1) + assert result == expected_result diff --git a/tests/telemetryStatsServerP.json_neg b/tests/telemetryStatsServerP.json_neg deleted file mode 100644 index d3a6eb2..0000000 --- a/tests/telemetryStatsServerP.json_neg +++ /dev/null @@ -1,20 +0,0 @@ -{ - "totalCount": "1", - "imdata": [ - { - "telemetryStatsServerP": { - "attributes": { - "name": "default", - "collectorLocation": "none", - "dn": "uni/fabric/servers/stserverp-default", - "dstAddr": "kafka.service.apic.local", - "dstPort": "9092", - "ip": "0.0.0.0", - "isSecure": "yes", - "modTs": "2022-09-23T10:42:34.737-04:00", - "rn": "stserverp-default" - } - } - } - ] -} \ No newline at end of file diff --git a/tests/telemetryStatsServerP.json_pos b/tests/telemetryStatsServerP.json_pos deleted file mode 100644 index cc3572c..0000000 --- a/tests/telemetryStatsServerP.json_pos +++ /dev/null @@ -1,20 +0,0 @@ -{ - "totalCount": "1", - "imdata": [ - { - "telemetryStatsServerP": { - "attributes": { - "name": "default", - "collectorLocation": "apic", - "dn": "uni/fabric/servers/stserverp-default", - "dstAddr": "kafka.service.apic.local", - "dstPort": "9092", - "ip": "0.0.0.0", - "isSecure": "yes", - "modTs": "2022-09-23T10:42:34.737-04:00", - "rn": "stserverp-default" - } - } - } - ] -} \ No newline at end of file diff --git a/tests/telemetryStatsServerP_object_check/telemetryStatsServerP_neg.json b/tests/telemetryStatsServerP_object_check/telemetryStatsServerP_neg.json new file mode 100644 index 0000000..f10d787 --- /dev/null +++ b/tests/telemetryStatsServerP_object_check/telemetryStatsServerP_neg.json @@ -0,0 +1,17 @@ +[ + { + "telemetryStatsServerP": { + "attributes": { + "name": "default", + "collectorLocation": "none", + "dn": "uni/fabric/servers/stserverp-default", + "dstAddr": "kafka.service.apic.local", + "dstPort": "9092", + "ip": "0.0.0.0", + "isSecure": "yes", + "modTs": "2022-09-23T10:42:34.737-04:00", + "rn": "stserverp-default" + } + } + } +] diff --git a/tests/telemetryStatsServerP_object_check/telemetryStatsServerP_pos.json b/tests/telemetryStatsServerP_object_check/telemetryStatsServerP_pos.json new file mode 100644 index 0000000..186ef32 --- /dev/null +++ b/tests/telemetryStatsServerP_object_check/telemetryStatsServerP_pos.json @@ -0,0 +1,17 @@ +[ + { + "telemetryStatsServerP": { + "attributes": { + "name": "default", + "collectorLocation": "apic", + "dn": "uni/fabric/servers/stserverp-default", + "dstAddr": "kafka.service.apic.local", + "dstPort": "9092", + "ip": "0.0.0.0", + "isSecure": "yes", + "modTs": "2022-09-23T10:42:34.737-04:00", + "rn": "stserverp-default" + } + } + } +] diff --git a/tests/telemetryStatsServerP_object_check/test_telemetryStatsServerP_object_check.py b/tests/telemetryStatsServerP_object_check/test_telemetryStatsServerP_object_check.py new file mode 100644 index 0000000..ec92ceb --- /dev/null +++ b/tests/telemetryStatsServerP_object_check/test_telemetryStatsServerP_object_check.py @@ -0,0 +1,89 @@ +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 +telemetryStatsServerPs = "telemetryStatsServerP.json" + + +@pytest.mark.parametrize( + "icurl_outputs, cversion, tversion, expected_result", + [ + ( + {telemetryStatsServerPs: []}, + "4.2(1b)", + "5.2(2a)", + script.PASS, + ), + ( + {telemetryStatsServerPs: []}, + "3.2(1a)", + "4.2(4d)", + script.PASS, + ), + ( + {telemetryStatsServerPs: read_data(dir, "telemetryStatsServerP_neg.json")}, + "3.2(1a)", + "5.2(6a)", + script.PASS, + ), + ( + {telemetryStatsServerPs: read_data(dir, "telemetryStatsServerP_neg.json")}, + "4.2(3a)", + "4.2(7d)", + script.PASS, + ), + ( + {telemetryStatsServerPs: read_data(dir, "telemetryStatsServerP_neg.json")}, + "2.2(3a)", + "2.2(4r)", + script.PASS, + ), + ( + {telemetryStatsServerPs: read_data(dir, "telemetryStatsServerP_neg.json")}, + "5.2(1a)", + None, + script.MANUAL, + ), + ( + {telemetryStatsServerPs: read_data(dir, "telemetryStatsServerP_pos.json")}, + "4.2(1b)", + "5.2(2a)", + script.PASS, + ), + ( + {telemetryStatsServerPs: read_data(dir, "telemetryStatsServerP_pos.json")}, + "3.2(1a)", + "4.2(4d)", + script.PASS, + ), + ( + {telemetryStatsServerPs: read_data(dir, "telemetryStatsServerP_pos.json")}, + "3.2(1a)", + "5.2(6a)", + script.FAIL_O, + ), + ( + {telemetryStatsServerPs: read_data(dir, "telemetryStatsServerP_pos.json")}, + "4.2(3a)", + "4.2(7d)", + script.PASS, + ), + ], +) +def test_logic(mock_icurl, cversion, tversion, expected_result): + result = script.telemetryStatsServerP_object_check( + 1, + 1, + script.AciVersion(cversion), + script.AciVersion(tversion) if tversion else None, + ) + assert result == expected_result diff --git a/tests/test_AciVersion.py b/tests/test_AciVersion.py new file mode 100644 index 0000000..77f7f10 --- /dev/null +++ b/tests/test_AciVersion.py @@ -0,0 +1,70 @@ +import pytest +import importlib + +script = importlib.import_module("aci-preupgrade-validation-script") + + +@pytest.mark.parametrize( + "input, major1, major2, maint, patch", + [ + # APIC version format + ("5.2(7f)", "5", "2", "7", "f"), + ("5.2.7f", "5", "2", "7", "f"), + ("5.2(7.123a)", "5", "2", "7", "123a"), + ("5.2.7.123a", "5", "2", "7", "123a"), + ("aci-apic-dk9.5.2.7f.iso", "5", "2", "7", "f"), + # Switch version format + ("15.2(7f)", "5", "2", "7", "f"), + ("15.2.7f", "5", "2", "7", "f"), + ("15.2(7.123a)", "5", "2", "7", "123a"), + ("15.2.7.123a", "5", "2", "7", "123a"), + ("aci-n9000-dk9.15.2.7f.bin", "5", "2", "7", "f"), + ], +) +def test_basic(input, major1, major2, maint, patch): + v = script.AciVersion(input) + assert ( + v.major1 == major1 + and v.major2 == major2 + and v.maint == maint + and v.patch == patch + ) + + +@pytest.mark.parametrize( + "ver1, ver2, older_than, newer_than, same_as", + [ + # APIC version format + ("5.2(7f)", "5.2(7f)", False, False, True), + ("5.2(7f)", "5.2(7g)", True, False, False), + ("5.2(7f)", "5.2(7e)", False, True, False), + ("5.2(7f)", "5.2(10f)", True, False, False), + ("5.2(7f)", "5.2(1f)", False, True, False), + ("5.2(7f)", "5.1(2a)", False, True, False), + ("5.2(7f)", "5.3(2a)", True, False, False), + ("5.2(7f)", "4.2(7l)", False, True, False), + ("5.2(7f)", "6.0(2h)", True, False, False), + # Switch version format + ("15.2(7f)", "15.2(7f)", False, False, True), + ("15.2(7f)", "15.2(7g)", True, False, False), + ("15.2(7f)", "15.2(7e)", False, True, False), + ("15.2(7f)", "15.2(10f)", True, False, False), + ("15.2(7f)", "15.2(1f)", False, True, False), + ("15.2(7f)", "15.1(2a)", False, True, False), + ("15.2(7f)", "15.3(2a)", True, False, False), + ("15.2(7f)", "14.2(7l)", False, True, False), + ("15.2(7f)", "16.0(2h)", True, False, False), + ], +) +class TestComparison: + def test_older_than(self, ver1, ver2, older_than, newer_than, same_as): + v = script.AciVersion(ver1) + assert v.older_than(ver2) == older_than + + def test_newer_than(self, ver1, ver2, older_than, newer_than, same_as): + v = script.AciVersion(ver1) + assert v.newer_than(ver2) == newer_than + + def test_same_as(self, ver1, ver2, older_than, newer_than, same_as): + v = script.AciVersion(ver1) + assert v.same_as(ver2) == same_as diff --git a/tests/test_IPAddress.py b/tests/test_IPAddress.py index 1c6320b..35842f1 100644 --- a/tests/test_IPAddress.py +++ b/tests/test_IPAddress.py @@ -1,12 +1,6 @@ -import os -import sys import pytest import importlib -TEST_DIR = os.path.dirname(os.path.abspath(__file__)) -PROJECT_DIR = os.path.dirname(TEST_DIR) -sys.path.append(PROJECT_DIR) - script = importlib.import_module("aci-preupgrade-validation-script") diff --git a/tests/test_get_vpc_node.py b/tests/test_get_vpc_node.py new file mode 100644 index 0000000..428cab1 --- /dev/null +++ b/tests/test_get_vpc_node.py @@ -0,0 +1,55 @@ +import pytest +import importlib + +script = importlib.import_module("aci-preupgrade-validation-script") + +# icurl queries +fabricNodePEps = "fabricNodePEp.json" + +data = [ + { + "fabricNodePEp": { + "attributes": { + "dn": "uni/fabric/protpol/expgep-101-103/nodepep-101", + "id": "101" + } + } + }, + { + "fabricNodePEp": { + "attributes": { + "dn": "uni/fabric/protpol/expgep-204-206/nodepep-206", + "id": "206" + } + } + }, + { + "fabricNodePEp": { + "attributes": { + "dn": "uni/fabric/protpol/expgep-101-103/nodepep-103", + "id": "103" + } + } + }, + { + "fabricNodePEp": { + "attributes": { + "dn": "uni/fabric/protpol/expgep-204-206/nodepep-204", + "id": "204" + } + } + } +] + + +@pytest.mark.parametrize( + "icurl_outputs, expected_result", + [ + ( + {fabricNodePEps: data}, + ["101", "103", "204", "206"] + ) + ] +) +def test_get_vpc_nodes(mock_icurl, expected_result): + assert set(script.get_vpc_nodes()) == set(expected_result) diff --git a/tests/test_logic.py b/tests/test_logic.py deleted file mode 100644 index 8c3a74b..0000000 --- a/tests/test_logic.py +++ /dev/null @@ -1,361 +0,0 @@ -# content of test_class_demo.py -import os -import sys -import pytest -import json -import re - -TEST_DIR = os.path.dirname(os.path.abspath(__file__)) -PROJECT_DIR = os.path.dirname(TEST_DIR) -sys.path.append(PROJECT_DIR) - -import importlib -script = importlib.import_module("aci-preupgrade-validation-script") - - -@pytest.fixture -def upgradePaths(): - return [{"cversion": script.AciVersion("4.2(1b)"), "tversion": script.AciVersion("5.2(2a)")}, - {"cversion": script.AciVersion("3.2(1a)"), "tversion": script.AciVersion("4.2(4d)")}, - {"cversion": script.AciVersion("3.2(1a)"), "tversion": script.AciVersion("5.2(6a)")}, - {"cversion": script.AciVersion("4.2(3a)"), "tversion": script.AciVersion("4.2(7d)")}, - {"cversion": script.AciVersion("2.2(3a)"), "tversion": script.AciVersion("2.2(4r)")}, - {"cversion": script.AciVersion("5.2(1a)"), "tversion": None}, - {"cversion": script.AciVersion("4.1(1a)"), "tversion": script.AciVersion("5.2(7f)")}] - - -def test_aciversion(upgradePaths): - for i, testdata in enumerate(upgradePaths): - cfw = testdata.get("cversion", None) - pathnum = i+1 - if pathnum == 1: # cfw = 4.2(1a) - assert cfw.older_than("4.1(10b)") == False - assert cfw.older_than("4.2(1a)") == False - assert cfw.older_than("4.2(1b)") == False # Same - assert cfw.older_than("4.2(3b)") == True - assert cfw.older_than("5.0(1b)") == True - assert cfw.older_than("5.1(1b)") == True - assert cfw.older_than("5.2(1b)") == True - - assert cfw.newer_than("4.1(10b)") == True - assert cfw.newer_than("4.2(1a)") == True - assert cfw.newer_than("4.2(1b)") == False # Same - assert cfw.newer_than("4.2(3b)") == False - assert cfw.newer_than("5.0(1b)") == False - assert cfw.newer_than("5.1(1b)") == False - assert cfw.newer_than("5.2(1b)") == False - - assert cfw.same_as("4.2(1b)") == True # Same - - -def test_get_vpc_nodes(): - script.prints("=====Starting test_get_vpc_nodes\n") - - with open("tests/fabricNodePEp.json_pos","r") as file: - testdata = {"fabricNodePEp.json": json.loads(file.read())['imdata']} - - assert set(script.get_vpc_nodes(**testdata)) == set(["101", "103", "204", "206"]) - - -@pytest.mark.parametrize( - "cversion,tversion,expected_fail_type", - [ - # Non-affected version combination - ("3.2(5e)", "4.2(4r)", script.PASS), - ("3.2(10g)", "4.2(4r)", script.PASS), - ("4.1(2a)", "4.2(7a)", script.PASS), - # Affected versio combination - ("3.2(4a)", "5.2(2a)", script.FAIL_UF), - ("4.0(1a)", "5.2(3a)", script.FAIL_UF), - ], -) -def test_defect_eventmgr_db(cversion, tversion, expected_fail_type): - script.prints("=====Starting test_defect_eventmgr_db\n") - testdata = { - "cversion": script.AciVersion(cversion), - "tversion": script.AciVersion(tversion) - } - assert script.eventmgr_db_defect_check(1, 1, **testdata) == expected_fail_type - - - - -@pytest.mark.parametrize( - "faultInst,fvIfConn,expected_fail_type", - [ - # FAIL - certreq returns error - ( "faultInst-encap-pos.json", "fvIfConn.json", script.FAIL_O), - # PASS - certreq returns cert info - ("faultInst-encap-neg.json", "fvIfConn.json", script.PASS) - ], -) -def test_encap_already_in_use_check(faultInst, fvIfConn, expected_fail_type): - script.prints("=====Starting encap_already_in_use_check\n") - testdata = { - "faultInst": faultInst, - "fvIfConn": fvIfConn, - } - with open("tests/"+faultInst,"r") as file: - testdata.update({"faultInst": json.loads(file.read())['imdata']}) - with open("tests/"+fvIfConn,"r") as file: - testdata.update({"fvIfConn": json.loads(file.read())['imdata']}) - assert script.encap_already_in_use_check(1, 1, **testdata) == expected_fail_type - - - -@pytest.mark.parametrize( - "cversion,tversion,certreq_resp,expected_fail_type", - [ - # FAIL - certreq returns error - ("4.2(5e)", "5.2(6e)", "POS_certreq.txt", script.FAIL_O), - # PASS - certreq returns cert info - ("4.2(4a)", "5.2(2a)", "NEG_certreq.txt",script.PASS) - ], -) -def test_apic_ca_cert_validation(cversion, tversion, certreq_resp, expected_fail_type): - script.prints("=====Starting apic_ca_cert_validation\n") - testdata = { - "cversion": script.AciVersion(cversion), - "tversion": script.AciVersion(tversion) - } - with open("tests/"+certreq_resp,"r") as file: - testdata.update({"certreq_out": file.read()}) - assert script.apic_ca_cert_validation(1, 1, **testdata) == expected_fail_type - - -def test_vpc_paired_switches_check(upgradePaths): - script.prints("=====Starting vpc_paired_switches_check\n") - pathlen = len(upgradePaths) - - for i, testdata in enumerate(upgradePaths): - with open("tests/topSystem.json_pos","r") as file: - testdata.update({"topSystem.json": json.loads(file.read())['imdata']}) - pathnum = i+1 - if pathnum == 1: - testdata.update({"vpc_node_ids": ["101", "102", "103", "204", "206"]}) - assert script.vpc_paired_switches_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 2: - testdata.update({"vpc_node_ids": ["101", "103", "204", "206"]}) - assert script.vpc_paired_switches_check(pathnum, pathlen, **testdata) == script.MANUAL - - -def test_llfc_susceptibility_check(upgradePaths): - script.print_title("Starting test_llfc_susceptibility_check\n") - pathlen = len(upgradePaths) - - for i, testdata in enumerate(upgradePaths): - testdata.update({"vpc_node_ids": ["101", "103", "204", "206"]}) - - with open("tests/ethpmFcot.json_pos","r") as file: - testdata.update({"ethpmFcot.json": json.loads(file.read())['imdata']}) - - pathnum = i+1 - if pathnum == 1: - assert script.llfc_susceptibility_check(pathnum, pathlen, **testdata) == script.MANUAL - if pathnum == 2: - assert script.llfc_susceptibility_check(pathnum, pathlen, **testdata) == script.MANUAL - if pathnum == 3: - assert script.llfc_susceptibility_check(pathnum, pathlen, **testdata) == script.MANUAL - if pathnum == 4: - assert script.llfc_susceptibility_check(pathnum, pathlen, **testdata) == script.MANUAL - if pathnum == 5: - assert script.llfc_susceptibility_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 6: - assert script.llfc_susceptibility_check(pathnum, pathlen, **testdata) == script.MANUAL - if pathnum == 7: - assert script.llfc_susceptibility_check(pathnum, pathlen, **testdata) == script.MANUAL - - -def test_pos_telemetryStatsServerP_object_check(upgradePaths): - script.prints("=====Starting test_pos_telemetryStatsServerP_object_check\n") - pathlen = len(upgradePaths) - for i, testdata in enumerate(upgradePaths): - with open("tests/telemetryStatsServerP.json_pos","r") as file: - testdata.update({"telemetryStatsServerP.json": json.loads(file.read())['imdata']}) - pathnum = i+1 - if pathnum == 1: - assert script.telemetryStatsServerP_object_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 2: - assert script.telemetryStatsServerP_object_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 3: - assert script.telemetryStatsServerP_object_check(pathnum, pathlen, **testdata) == script.FAIL_O - if pathnum == 4: - assert script.telemetryStatsServerP_object_check(pathnum, pathlen, **testdata) == script.PASS - - -def test_neg_telemetryStatsServerP_object_check(upgradePaths): - script.prints("=====Starting Negative stale_nir_object_check\n") - pathlen = len(upgradePaths) - for i, testdata in enumerate(upgradePaths): - pathnum = i+1 - if pathnum == 1: - neg_json = {"totalCount":"0","imdata":[]} - testdata.update({"telemetryStatsServerP.json": neg_json['imdata']}) - assert script.telemetryStatsServerP_object_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 2: - assert script.telemetryStatsServerP_object_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 3: - with open("tests/telemetryStatsServerP.json_neg","r") as file: - testdata.update({"telemetryStatsServerP.json": json.loads(file.read())['imdata']}) - assert script.telemetryStatsServerP_object_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 4: - assert script.telemetryStatsServerP_object_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 5: - assert script.telemetryStatsServerP_object_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 6: - assert script.telemetryStatsServerP_object_check(pathnum, pathlen, **testdata) == script.MANUAL - - -def test_pos_isis_redis_metric_mpod_msite_check(upgradePaths): - script.prints("=====Starting test_pos_isis_redis_metric_mpod_msite_check\n") - pathlen = len(upgradePaths) - for i, testdata in enumerate(upgradePaths): - with open("tests/isisDomP-default.json_pos","r") as file: - testdata.update({"uni/fabric/isisDomP-default.json": json.loads(file.read())['imdata']}) - - pathnum = i+1 - if pathnum == 1: - with open("tests/fvFabricExtConnP.json_pos1","r") as file: - testdata.update({"fvFabricExtConnP.json?query-target=children": json.loads(file.read())['imdata']}) - assert script.isis_redis_metric_mpod_msite_check(pathnum, pathlen, **testdata) == script.FAIL_O - if pathnum == 2: - with open("tests/fvFabricExtConnP.json_pos2","r") as file: - testdata.update({"fvFabricExtConnP.json?query-target=children": json.loads(file.read())['imdata']}) - assert script.isis_redis_metric_mpod_msite_check(pathnum, pathlen, **testdata) == script.FAIL_O - if pathnum == 3: - with open("tests/fvFabricExtConnP.json_pos3","r") as file: - testdata.update({"fvFabricExtConnP.json?query-target=children": json.loads(file.read())['imdata']}) - assert script.isis_redis_metric_mpod_msite_check(pathnum, pathlen, **testdata) == script.FAIL_O - if pathnum == 4: - with open("tests/fvFabricExtConnP.json_pos1","r") as file: - testdata.update({"fvFabricExtConnP.json?query-target=children": json.loads(file.read())['imdata']}) - assert script.isis_redis_metric_mpod_msite_check(pathnum, pathlen, **testdata) == script.FAIL_O - - -def test_neg_isis_redis_metric_mpod_msite_check(upgradePaths): - script.prints("=====Starting test_neg_isis_redis_metric_mpod_msite_check\n") - pathlen = len(upgradePaths) - for i, testdata in enumerate(upgradePaths): - - with open("tests/isisDomP-default.json_neg","r") as file: - testdata.update({"uni/fabric/isisDomP-default.json": json.loads(file.read())['imdata']}) - with open("tests/fvFabricExtConnP.json_pos1","r") as file: - testdata.update({"fvFabricExtConnP.json?query-target=children": json.loads(file.read())['imdata']}) - - pathnum = i+1 - if pathnum == 1: - assert script.isis_redis_metric_mpod_msite_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 2: - assert script.isis_redis_metric_mpod_msite_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 3: - assert script.isis_redis_metric_mpod_msite_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 4: - assert script.isis_redis_metric_mpod_msite_check(pathnum, pathlen, **testdata) == script.PASS - - -def test_missing_isis_redis_metric_mpod_msite_check(upgradePaths): - script.prints("=====Starting test_missing_isis_redis_metric_mpod_msite_check\n") - pathlen = len(upgradePaths) - for i, testdata in enumerate(upgradePaths): - - with open("tests/isisDomP-default.json_missing","r") as file: - testdata.update({"uni/fabric/isisDomP-default.json": json.loads(file.read())['imdata']}) - with open("tests/fvFabricExtConnP.json_pos1","r") as file: - testdata.update({"fvFabricExtConnP.json?query-target=children": json.loads(file.read())['imdata']}) - - pathnum = i+1 - if pathnum == 5: - assert script.isis_redis_metric_mpod_msite_check(pathnum, pathlen, **testdata) == script.FAIL_O - - -def test_switch_bootflash_usage_check_new(): - script.prints("=====Starting test_switch_bootflash_usage_check_new\n") - with open("tests/eqptcapacityFSPartition.json_pos","r") as file: - testdata = {"eqptcapacityFSPartition.json": json.loads(file.read())['imdata']} - res = script.switch_bootflash_usage_check(1, 1, **testdata) - assert res == script.FAIL_UF - - -def test_contract_22_defect_check(upgradePaths): - script.prints("=====Starting test_llfc_susceptibility_check\n") - pathlen = len(upgradePaths) - for i, testdata in enumerate(upgradePaths): - pathnum = i+1 - if pathnum == 1: - assert script.contract_22_defect_check(pathnum, pathlen, **testdata) == script.FAIL_O - if pathnum == 2: - assert script.contract_22_defect_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 3: - assert script.contract_22_defect_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 4: - assert script.contract_22_defect_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 5: - assert script.contract_22_defect_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 6: - assert script.contract_22_defect_check(pathnum, pathlen, **testdata) == script.MANUAL - - -def test_pos_internal_vlanpool_check(upgradePaths): - script.prints("=====Starting Positive internal_vlanpool_check\n") - pathlen = len(upgradePaths) - for i, testdata in enumerate(upgradePaths): - with open("tests/fvnsVlanInstP.json_pos","r") as file: - testdata.update({"fvnsVlanInstP.json": json.loads(file.read())['imdata']}) - with open("tests/vmmDomP.json_pos","r") as file: - testdata.update({"vmmDomP.json": json.loads(file.read())['imdata']}) - pathnum = i+1 - if pathnum == 1: - assert script.internal_vlanpool_check(pathnum, pathlen, **testdata) == script.FAIL_O - if pathnum == 2: - assert script.internal_vlanpool_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 3: - assert script.internal_vlanpool_check(pathnum, pathlen, **testdata) == script.FAIL_O - if pathnum == 4: - assert script.internal_vlanpool_check(pathnum, pathlen, **testdata) == script.FAIL_O - if pathnum == 5: - assert script.internal_vlanpool_check(pathnum, pathlen, **testdata) == script.PASS - - -def test_neg_internal_vlanpool_check(upgradePaths): - script.prints("=====Starting Negative internal_vlanpool_check\n") - pathlen = len(upgradePaths) - for i, testdata in enumerate(upgradePaths): - with open("tests/fvnsVlanInstP.json_neg","r") as file: - testdata.update({"fvnsVlanInstP.json": json.loads(file.read())['imdata']}) - with open("tests/vmmDomP.json_neg","r") as file: - testdata.update({"vmmDomP.json": json.loads(file.read())['imdata']}) - pathnum = i+1 - - if pathnum == 1: - assert script.internal_vlanpool_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 2: - assert script.internal_vlanpool_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 3: - assert script.internal_vlanpool_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 4: - assert script.internal_vlanpool_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 5: - assert script.internal_vlanpool_check(pathnum, pathlen, **testdata) == script.PASS - - -def test_bgp_golf_route_target_type_check(upgradePaths): - script.prints("=====Starting bgp_golf_route_target_type_check tests\n") - pathlen = len(upgradePaths) - for i, testdata in enumerate(upgradePaths): - with open("tests/fvCtx.json_pos","r") as file: - testdata.update({"fvCtx.json": json.loads(file.read())['imdata']}) - pathnum = i+1 - if pathnum == 1: - assert script.bgp_golf_route_target_type_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 2: - assert script.bgp_golf_route_target_type_check(pathnum, pathlen, **testdata) == script.FAIL_O - if pathnum == 3: - assert script.bgp_golf_route_target_type_check(pathnum, pathlen, **testdata) == script.FAIL_O - if pathnum == 4: - assert script.bgp_golf_route_target_type_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 5: - assert script.bgp_golf_route_target_type_check(pathnum, pathlen, **testdata) == script.PASS - if pathnum == 6: - assert script.bgp_golf_route_target_type_check(pathnum, pathlen, **testdata) == script.MANUAL - if pathnum == 7: - assert script.bgp_golf_route_target_type_check(pathnum, pathlen, **testdata) == script.FAIL_O diff --git a/tests/topSystem.json_pos b/tests/topSystem.json_pos deleted file mode 100644 index 1d1d806..0000000 --- a/tests/topSystem.json_pos +++ /dev/null @@ -1,137 +0,0 @@ -{ - "totalCount": "11", - "imdata": [ - { - "topSystem": { - "attributes": { - "dn": "topology/pod-1/node-1/sys", - "id": "1", - "name": "apic1", - "podId": "1", - "role": "controller" - } - } - }, - { - "topSystem": { - "attributes": { - "dn": "topology/pod-2/node-3/sys", - "id": "3", - "name": "apic3", - "podId": "2", - "role": "controller" - } - } - }, - { - "topSystem": { - "attributes": { - "dn": "topology/pod-1/node-2/sys", - "id": "2", - "name": "apic2", - "podId": "1", - "role": "controller" - } - } - }, - { - "topSystem": { - "attributes": { - "dn": "topology/pod-1/node-101/sys", - "id": "101", - "name": "leaf101", - "podId": "1", - "role": "leaf" - } - } - }, - { - "topSystem": { - "attributes": { - "dn": "topology/pod-1/node-102/sys", - "id": "102", - "name": "leaf102", - "podId": "1", - "role": "leaf" - } - } - }, - { - "topSystem": { - "attributes": { - "dn": "topology/pod-1/node-103/sys", - "id": "103", - "name": "leaf103", - "podId": "1", - "role": "leaf" - } - } - }, - { - "topSystem": { - "attributes": { - "dn": "topology/pod-2/node-204/sys", - "id": "204", - "name": "leaf204", - "podId": "2", - "role": "leaf" - } - } - }, - { - "topSystem": { - "attributes": { - "dn": "topology/pod-2/node-206/sys", - "id": "206", - "name": "leaf206", - "podId": "2", - "role": "leaf" - } - } - }, - { - "topSystem": { - "attributes": { - "dn": "topology/pod-2/node-2002/sys", - "id": "2002", - "name": "spine2002", - "podId": "2", - "role": "spine" - } - } - }, - { - "topSystem": { - "attributes": { - "dn": "topology/pod-2/node-2001/sys", - "id": "2001", - "name": "spine2001", - "podId": "2", - "role": "spine" - } - } - }, - { - "topSystem": { - "attributes": { - "dn": "topology/pod-1/node-1002/sys", - "id": "1002", - "name": "spine1002", - "podId": "1", - "role": "spine" - } - } - }, - { - "topSystem": { - "attributes": { - "dn": "topology/pod-1/node-1001/sys", - "id": "1001", - "name": "spine1001", - "podId": "1", - "role": "spine" - } - } - } - ] -} \ No newline at end of file diff --git a/tests/vmmDomP.json_neg b/tests/vmmDomP.json_neg deleted file mode 100644 index 71b0648..0000000 --- a/tests/vmmDomP.json_neg +++ /dev/null @@ -1,87 +0,0 @@ -{ - "totalCount": "2", - "imdata": [ - { - "vmmDomP": { - "attributes": { - "accessMode": "read-write", - "annotation": "", - "arpLearning": "", - "aveTimeOut": "30", - "childAction": "", - "configInfraPg": "no", - "configIssues": "", - "ctrlKnob": "epDpVerify", - "delimiter": "", - "dn": "uni/vmmp-VMware/dom-jr-ave", - "enableAVE": "yes", - "enableTag": "no", - "enableVmFolder": "no", - "encapMode": "vxlan", - "enfPref": "sw", - "epInventoryType": "on-link", - "epRetTime": "0", - "extMngdBy": "", - "hvAvailMonitor": "yes", - "lagPolicyName": "", - "lcOwn": "local", - "mcastAddr": "239.1.1.1", - "modTs": "2021-04-20T14:52:27.404-05:00", - "mode": "default", - "monPolDn": "uni/fabric/monfab-default", - "name": "jr-ave", - "nameAlias": "", - "ownerKey": "", - "ownerTag": "", - "prefEncapMode": "vxlan", - "status": "", - "txId": "3458764513832453119", - "uid": "15374", - "uniqueId": "6909", - "userdom": "all" - } - } - }, - { - "vmmDomP": { - "attributes": { - "accessMode": "read-write", - "annotation": "", - "arpLearning": "", - "aveTimeOut": "30", - "childAction": "", - "configInfraPg": "no", - "configIssues": "", - "ctrlKnob": "epDpVerify", - "delimiter": "", - "dn": "uni/vmmp-VMware/dom-jr-dvs", - "enableAVE": "no", - "enableTag": "no", - "enableVmFolder": "no", - "encapMode": "unknown", - "enfPref": "hw", - "epInventoryType": "on-link", - "epRetTime": "0", - "extMngdBy": "", - "hvAvailMonitor": "no", - "lagPolicyName": "", - "lcOwn": "local", - "mcastAddr": "0.0.0.0", - "modTs": "2021-07-19T22:31:58.605-05:00", - "mode": "default", - "monPolDn": "uni/fabric/monfab-default", - "name": "jr-dvs", - "nameAlias": "", - "ownerKey": "", - "ownerTag": "", - "prefEncapMode": "unspecified", - "status": "", - "txId": "13835058055287371636", - "uid": "15374", - "uniqueId": "8595", - "userdom": "all" - } - } - } - ] -} \ No newline at end of file diff --git a/tests/vmmDomP.json_pos b/tests/vmmDomP.json_pos deleted file mode 100644 index 13190d8..0000000 --- a/tests/vmmDomP.json_pos +++ /dev/null @@ -1,87 +0,0 @@ -{ - "totalCount": "2", - "imdata": [ - { - "vmmDomP": { - "attributes": { - "accessMode": "read-write", - "annotation": "", - "arpLearning": "", - "aveTimeOut": "30", - "childAction": "", - "configInfraPg": "no", - "configIssues": "", - "ctrlKnob": "epDpVerify", - "delimiter": "", - "dn": "uni/vmmp-VMware/dom-jr-ave", - "enableAVE": "no", - "enableTag": "no", - "enableVmFolder": "no", - "encapMode": "vxlan", - "enfPref": "sw", - "epInventoryType": "on-link", - "epRetTime": "0", - "extMngdBy": "", - "hvAvailMonitor": "yes", - "lagPolicyName": "", - "lcOwn": "local", - "mcastAddr": "239.1.1.1", - "modTs": "2021-04-20T14:52:27.404-05:00", - "mode": "default", - "monPolDn": "uni/fabric/monfab-default", - "name": "jr-ave", - "nameAlias": "", - "ownerKey": "", - "ownerTag": "", - "prefEncapMode": "vxlan", - "status": "", - "txId": "3458764513832453119", - "uid": "15374", - "uniqueId": "6909", - "userdom": "all" - } - } - }, - { - "vmmDomP": { - "attributes": { - "accessMode": "read-write", - "annotation": "", - "arpLearning": "", - "aveTimeOut": "30", - "childAction": "", - "configInfraPg": "no", - "configIssues": "", - "ctrlKnob": "epDpVerify", - "delimiter": "", - "dn": "uni/vmmp-VMware/dom-jr-dvs", - "enableAVE": "no", - "enableTag": "no", - "enableVmFolder": "no", - "encapMode": "unknown", - "enfPref": "hw", - "epInventoryType": "on-link", - "epRetTime": "0", - "extMngdBy": "", - "hvAvailMonitor": "no", - "lagPolicyName": "", - "lcOwn": "local", - "mcastAddr": "0.0.0.0", - "modTs": "2021-07-19T22:31:58.605-05:00", - "mode": "default", - "monPolDn": "uni/fabric/monfab-default", - "name": "jr-dvs", - "nameAlias": "", - "ownerKey": "", - "ownerTag": "", - "prefEncapMode": "unspecified", - "status": "", - "txId": "13835058055287371636", - "uid": "15374", - "uniqueId": "8595", - "userdom": "all" - } - } - } - ] -} \ No newline at end of file diff --git a/tests/vpc_paired_switches_check/test_vpc_paired_switches_check.py b/tests/vpc_paired_switches_check/test_vpc_paired_switches_check.py new file mode 100644 index 0000000..3619137 --- /dev/null +++ b/tests/vpc_paired_switches_check/test_vpc_paired_switches_check.py @@ -0,0 +1,36 @@ +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 +topSystems = "topSystem.json" + + +@pytest.mark.parametrize( + "icurl_outputs, vpc_node_ids, expected_result", + [ + # all leaf switches are in vPC + ( + {topSystems: read_data(dir, "topSystem.json")}, + ["101", "102", "103", "204", "206"], + script.PASS, + ), + # not all leaf switches are in vPC + ( + {topSystems: read_data(dir, "topSystem.json")}, + ["101", "103", "204", "206"], + script.MANUAL, + ), + ], +) +def test_logic(mock_icurl, vpc_node_ids, expected_result): + result = script.vpc_paired_switches_check(1, 1, vpc_node_ids=vpc_node_ids) + assert result == expected_result diff --git a/tests/vpc_paired_switches_check/topSystem.json b/tests/vpc_paired_switches_check/topSystem.json new file mode 100644 index 0000000..39faf83 --- /dev/null +++ b/tests/vpc_paired_switches_check/topSystem.json @@ -0,0 +1,134 @@ +[ + { + "topSystem": { + "attributes": { + "dn": "topology/pod-1/node-1/sys", + "id": "1", + "name": "apic1", + "podId": "1", + "role": "controller" + } + } + }, + { + "topSystem": { + "attributes": { + "dn": "topology/pod-2/node-3/sys", + "id": "3", + "name": "apic3", + "podId": "2", + "role": "controller" + } + } + }, + { + "topSystem": { + "attributes": { + "dn": "topology/pod-1/node-2/sys", + "id": "2", + "name": "apic2", + "podId": "1", + "role": "controller" + } + } + }, + { + "topSystem": { + "attributes": { + "dn": "topology/pod-1/node-101/sys", + "id": "101", + "name": "leaf101", + "podId": "1", + "role": "leaf" + } + } + }, + { + "topSystem": { + "attributes": { + "dn": "topology/pod-1/node-102/sys", + "id": "102", + "name": "leaf102", + "podId": "1", + "role": "leaf" + } + } + }, + { + "topSystem": { + "attributes": { + "dn": "topology/pod-1/node-103/sys", + "id": "103", + "name": "leaf103", + "podId": "1", + "role": "leaf" + } + } + }, + { + "topSystem": { + "attributes": { + "dn": "topology/pod-2/node-204/sys", + "id": "204", + "name": "leaf204", + "podId": "2", + "role": "leaf" + } + } + }, + { + "topSystem": { + "attributes": { + "dn": "topology/pod-2/node-206/sys", + "id": "206", + "name": "leaf206", + "podId": "2", + "role": "leaf" + } + } + }, + { + "topSystem": { + "attributes": { + "dn": "topology/pod-2/node-2002/sys", + "id": "2002", + "name": "spine2002", + "podId": "2", + "role": "spine" + } + } + }, + { + "topSystem": { + "attributes": { + "dn": "topology/pod-2/node-2001/sys", + "id": "2001", + "name": "spine2001", + "podId": "2", + "role": "spine" + } + } + }, + { + "topSystem": { + "attributes": { + "dn": "topology/pod-1/node-1002/sys", + "id": "1002", + "name": "spine1002", + "podId": "1", + "role": "spine" + } + } + }, + { + "topSystem": { + "attributes": { + "dn": "topology/pod-1/node-1001/sys", + "id": "1001", + "name": "spine1001", + "podId": "1", + "role": "spine" + } + } + } +]