From 6d0c6f3b6efa04de32e14e5389de80c64de5bd02 Mon Sep 17 00:00:00 2001 From: GM Date: Tue, 13 Aug 2024 16:31:40 -0400 Subject: [PATCH] fix empty imdata result + add empty imdata test (#151) --- aci-preupgrade-validation-script.py | 24 +++++++++---------- tests/uplink_limit_check/eqptPortP_empty.json | 1 + .../test_uplink_limit_check.py | 8 +++++++ 3 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 tests/uplink_limit_check/eqptPortP_empty.json diff --git a/aci-preupgrade-validation-script.py b/aci-preupgrade-validation-script.py index 4e736c4..41d7959 100644 --- a/aci-preupgrade-validation-script.py +++ b/aci-preupgrade-validation-script.py @@ -2944,19 +2944,17 @@ def uplink_limit_check(index, total_checks, cversion, tversion, **kwargs): if cversion.older_than("6.0(1a)") and tversion.newer_than("6.0(1a)"): port_profiles = icurl('class', 'eqptPortP.json?query-target-filter=eq(eqptPortP.ctrl,"uplink")') - if not port_profiles or (len(port_profiles) < 57): - return result - - node_count = {} - for pp in port_profiles: - dn = re.search(node_regex, pp['eqptPortP']['attributes']['dn']) - node_id = dn.group("node") - node_count.setdefault(node_id, 0) - node_count[node_id] += 1 - - for node, count in node_count.items(): - if count > 56: - data.append([node, count]) + if len(port_profiles) > 56: + node_count = {} + for pp in port_profiles: + dn = re.search(node_regex, pp['eqptPortP']['attributes']['dn']) + node_id = dn.group("node") + node_count.setdefault(node_id, 0) + node_count[node_id] += 1 + + for node, count in node_count.items(): + if count > 56: + data.append([node, count]) if data: result = FAIL_O diff --git a/tests/uplink_limit_check/eqptPortP_empty.json b/tests/uplink_limit_check/eqptPortP_empty.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/tests/uplink_limit_check/eqptPortP_empty.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/uplink_limit_check/test_uplink_limit_check.py b/tests/uplink_limit_check/test_uplink_limit_check.py index 0b57985..0cf9dc8 100644 --- a/tests/uplink_limit_check/test_uplink_limit_check.py +++ b/tests/uplink_limit_check/test_uplink_limit_check.py @@ -24,6 +24,14 @@ "6.0(2h)", script.FAIL_O, ), + ( + { + eqptPortP: read_data(dir, "eqptPortP_empty.json") + }, + "5.2(3g)", + "6.0(2h)", + script.PASS, + ), ( { eqptPortP: read_data(dir, "eqptPortP_POS.json")