Skip to content

Commit 622befa

Browse files
authored
fix: Add default reason(msg) for AciResult for failed checks (#290)
* fix: Always populate msg/reason when a rule did not pass * fix: add header to failureDetails
1 parent 34c3dbd commit 622befa

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

aci-preupgrade-validation-script.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,11 +918,11 @@ def is_firstver_gt_secondver(first_ver, second_ver):
918918

919919
class AciResult:
920920
"""
921-
APIC uses an object called `AciResult` to store the results of
922-
each rule/check in the pre-upgrade validation which is run during the upgrade
921+
APIC uses an object called `syntheticMaintPValidate` to store the results of
922+
each rule/check in the pre-upgrade validation which runs during the upgrade
923923
workflow in the APIC GUI. When this script is invoked during the workflow, it
924924
is expected to write the results of each rule/check to a JSON file (one per rule)
925-
in a specific format.
925+
in a specific format compliant with `syntheticMaintPValidate`.
926926
"""
927927
# Expected keys in the JSON file
928928
__slots__ = (
@@ -992,7 +992,10 @@ def updateWithResults(self, result, recommended_action, msg, doc_url, headers, d
992992
self.ruleStatus = AciResult.PASS
993993
if result not in [NA, PASS]:
994994
self.ruleStatus = AciResult.FAIL
995+
if not self.reason:
996+
self.reason = "See Failure Details"
995997
self.failureDetails["failType"] = result
998+
self.failureDetails["header"] = headers
996999
self.failureDetails["data"] = self.craftData(headers, data)
9971000
if unformatted_headers and unformatted_data:
9981001
self.failureDetails["unformatted_data"] = self.craftData(unformatted_headers, unformatted_data)

tests/test_run_checks.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,15 @@ def test_run_checks(capsys, caplog):
158158
# reason
159159
if result == script.ERROR:
160160
assert data["reason"].endswith(err_msg)
161-
elif others.get("unformatted_data"):
162-
assert data["reason"] == others.get("msg", "") + (
163-
"\n"
164-
"Parse failure occurred, the provided data may not be complete. "
165-
"Please contact Cisco TAC to identify the missing data."
166-
)
161+
elif result not in [script.PASS, script.NA]:
162+
msg = others.get("msg", "See Failure Details")
163+
if others.get("unformatted_data"):
164+
msg += (
165+
"\n"
166+
"Parse failure occurred, the provided data may not be complete. "
167+
"Please contact Cisco TAC to identify the missing data."
168+
)
169+
assert data["reason"] == msg
167170
else:
168171
assert data["reason"] == others.get("msg", "")
169172
# failureDetails.failType

0 commit comments

Comments
 (0)