Skip to content

Commit faa00aa

Browse files
authored
fix: stringfy all values in Result.data (#391)
1 parent 875d57b commit faa00aa

5 files changed

Lines changed: 60 additions & 19 deletions

File tree

aci-preupgrade-validation-script.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,13 +1333,26 @@ class Result:
13331333
"""Class to hold the result of a check."""
13341334
__slots__ = ("result", "msg", "headers", "data", "unformatted_headers", "unformatted_data", "recommended_action", "doc_url")
13351335

1336+
@staticmethod
1337+
def _stringify_table_rows(rows):
1338+
"""Convert every table cell value to string for stable sorting/printing."""
1339+
if rows is None:
1340+
return []
1341+
normalized = []
1342+
for row in rows:
1343+
if isinstance(row, (list, tuple)):
1344+
normalized.append([str(col) for col in row])
1345+
else:
1346+
normalized.append([str(row)])
1347+
return normalized
1348+
13361349
def __init__(self, result=PASS, msg="", headers=None, data=None, unformatted_headers=None, unformatted_data=None, recommended_action="", doc_url=""):
13371350
self.result = result
13381351
self.msg = msg
13391352
self.headers = headers if headers is not None else []
1340-
self.data = data if data is not None else []
1353+
self.data = self._stringify_table_rows(data)
13411354
self.unformatted_headers = unformatted_headers if unformatted_headers is not None else []
1342-
self.unformatted_data = unformatted_data if unformatted_data is not None else []
1355+
self.unformatted_data = self._stringify_table_rows(unformatted_data)
13431356
self.recommended_action = recommended_action
13441357
self.doc_url = doc_url
13451358

tests/checks/n9k_c9408_model_lem_count_check/test_n9k_c9408_model_lem_count_check.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"6.2(1g)",
7272
read_data(dir, "fabricNode_n9k_c9408.json"),
7373
script.FAIL_O,
74-
[["101", "N9K-C9408", "N9K-X9400-16W", 6]],
74+
[["101", "N9K-C9408", "N9K-X9400-16W", "6"]],
7575
"",
7676
),
7777
# Applicable mid-train version 6.1(5e), less than 6 LEMs on C9408 -> PASS
@@ -89,7 +89,7 @@
8989
"6.1(5e)",
9090
read_data(dir, "fabricNode_n9k_c9408.json"),
9191
script.FAIL_O,
92-
[["101", "N9K-C9408", "N9K-X9400-16W", 6]],
92+
[["101", "N9K-C9408", "N9K-X9400-16W", "6"]],
9393
"",
9494
),
9595
# Version not affected (fixed in 6.1(6)+)
@@ -107,7 +107,7 @@
107107
"6.1(2f)",
108108
read_data(dir, "fabricNode_n9k_c9408.json"),
109109
script.FAIL_O,
110-
[["101", "N9K-C9408", "N9K-X9400-16W", 6]],
110+
[["101", "N9K-C9408", "N9K-X9400-16W", "6"]],
111111
"",
112112
),
113113
# Count only C9408 nodes and only matching LEM model
@@ -117,8 +117,8 @@
117117
read_data(dir, "fabricNode_mixed.json"),
118118
script.FAIL_O,
119119
[
120-
["101", "N9K-C9408", "N9K-X9400-16W", 6],
121-
["102", "N9K-C9408", "N9K-X9400-16W", 6],
120+
["101", "N9K-C9408", "N9K-X9400-16W", "6"],
121+
["102", "N9K-C9408", "N9K-X9400-16W", "6"],
122122
],
123123
"",
124124
),

tests/checks/r_leaf_compatibility_check/test_r_leaf_compatibility_check.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"4.1(2a)",
5454
"4.2(2a)",
5555
script.FAIL_O,
56-
[["4.2(2a)", "Present", True]],
56+
[["4.2(2a)", "Present", "True"]],
5757
),
5858
# PASS - bug version upgrade, no RL
5959
(
@@ -80,7 +80,7 @@
8080
"4.2(3a)",
8181
"5.2(3a)",
8282
script.FAIL_O,
83-
[["5.2(3a)", "Present", False]],
83+
[["5.2(3a)", "Present", "False"]],
8484
),
8585
# PASS - Fix ver to 5.x, no RL
8686
(

tests/checks/rogue_ep_coop_exception_mac_check/test_rogue_ep_coop_exception_mac_check.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@
6666
"6.0(3e)",
6767
"5.2(3e)",
6868
script.FAIL_O,
69-
[[5, "N/A"]],
69+
[["5", "N/A"]],
7070
),
7171
(
7272
{exception_mac_api: read_data(dir, "rogue_mac_response.json")},
7373
"6.1(3g)",
7474
"5.2(3e)",
7575
script.FAIL_O,
76-
[[5, "N/A"]],
76+
[["5", "N/A"]],
7777
),
7878
# Affected (post-APIC upgrade, pre-switch upgrade) cases
7979
# tversion == cversion (affected target), no exception MACs
@@ -121,7 +121,7 @@
121121
"6.0(3e)",
122122
"6.0(3e)",
123123
script.FAIL_O,
124-
[[5, "only 31 found out of 32"]],
124+
[["5", "only 31 found out of 32"]],
125125
),
126126
(
127127
{
@@ -131,7 +131,7 @@
131131
"6.1(3g)",
132132
"6.1(3g)",
133133
script.FAIL_O,
134-
[[5, "only 31 found out of 32"]],
134+
[["5", "only 31 found out of 32"]],
135135
),
136136
(
137137
{
@@ -141,7 +141,7 @@
141141
"6.0(3e)",
142142
"6.0(3e)",
143143
script.FAIL_O,
144-
[[5, "only 27 found out of 32"]],
144+
[["5", "only 27 found out of 32"]],
145145
),
146146
(
147147
{
@@ -151,7 +151,7 @@
151151
"6.1(3g)",
152152
"6.1(3g)",
153153
script.FAIL_O,
154-
[[5, "only 27 found out of 32"]],
154+
[["5", "only 27 found out of 32"]],
155155
),
156156
(
157157
{
@@ -161,7 +161,7 @@
161161
"6.0(3e)",
162162
"6.0(3e)",
163163
script.FAIL_O,
164-
[[5, "only 1 found out of 32"]],
164+
[["5", "only 1 found out of 32"]],
165165
),
166166
(
167167
{
@@ -171,7 +171,7 @@
171171
"6.1(3g)",
172172
"6.1(3g)",
173173
script.FAIL_O,
174-
[[5, "only 1 found out of 32"]],
174+
[["5", "only 1 found out of 32"]],
175175
),
176176
(
177177
{
@@ -181,7 +181,7 @@
181181
"6.0(3e)",
182182
"6.0(3e)",
183183
script.FAIL_O,
184-
[[5, "only 0 found out of 32"]],
184+
[["5", "only 0 found out of 32"]],
185185
),
186186
(
187187
{
@@ -191,7 +191,7 @@
191191
"6.1(3g)",
192192
"6.1(3g)",
193193
script.FAIL_O,
194-
[[5, "only 0 found out of 32"]],
194+
[["5", "only 0 found out of 32"]],
195195
),
196196
],
197197
)

tests/test_Result.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import importlib
2+
3+
script = importlib.import_module("aci-preupgrade-validation-script")
4+
5+
6+
def test_print_result_handles_mixed_type_rows_without_error():
7+
# Verify that Result stringifies all cell values, so data.sort() in print_result never fails.
8+
r = script.Result(
9+
result=script.FAIL_O,
10+
headers=["col1"],
11+
data=[[1], ["2"]],
12+
unformatted_headers=["col1"],
13+
unformatted_data=[[3], ["4"]],
14+
)
15+
# All values must already be strings after construction.
16+
assert r.data == [["1"], ["2"]]
17+
assert r.unformatted_data == [["3"], ["4"]]
18+
# print_result must not raise.
19+
script.print_result(
20+
index=1,
21+
total=1,
22+
title="Mixed type table",
23+
result=script.FAIL_O,
24+
headers=r.headers,
25+
data=r.data,
26+
unformatted_headers=r.unformatted_headers,
27+
unformatted_data=r.unformatted_data,
28+
)

0 commit comments

Comments
 (0)