Skip to content

Commit 8f50787

Browse files
authored
Fix Connection class byte string handling in py3 (#238)
* Decode the SSH output as "utf-8" in class `Connection` * Change the result to `ERROR` from `FAIL_UF` when the SSH connection check on at least one APIC resulted in `ERROR`
1 parent 46526d4 commit 8f50787

3 files changed

Lines changed: 35 additions & 13 deletions

File tree

aci-preupgrade-validation-script.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def cmd(self, command, **kargs):
360360
time.sleep(self.force_wait)
361361

362362
result = self.__expect(matches, timeout)
363-
self.output = "%s%s" % (self.child.before, self.child.after)
363+
self.output = "%s%s" % (self.child.before.decode("utf-8"), self.child.after.decode("utf-8"))
364364
if result == "eof" or result == "timeout":
365365
logging.warning("unexpected %s occurred" % result)
366366
return result
@@ -1958,6 +1958,7 @@ def apic_ssd_check(index, total_checks, cversion, **kwargs):
19581958
recommended_action = "Contact TAC for replacement"
19591959
print_title(title, index, total_checks)
19601960

1961+
has_error = False
19611962
dn_regex = node_regex + r'/.+p-\[(?P<storage>.+)\]-f'
19621963
faultInsts = icurl('class', 'faultInst.json?query-target-filter=eq(faultInst.code,"F2731")')
19631964
adjust_title = False
@@ -1988,13 +1989,15 @@ def apic_ssd_check(index, total_checks, cversion, **kwargs):
19881989
except Exception as e:
19891990
data.append([attr['id'], attr['name'], '-', '-', '-', e])
19901991
print_result(node_title, ERROR)
1992+
has_error = True
19911993
continue
19921994
try:
19931995
c.cmd(
19941996
'grep -oE "SSD Wearout Indicator is [0-9]+" /var/log/dme/log/svc_ifc_ae.bin.log | tail -1')
19951997
except Exception as e:
19961998
data.append([attr['id'], attr['name'], '-', '-', '-', e])
19971999
print_result(node_title, ERROR)
2000+
has_error = True
19982001
continue
19992002

20002003
wearout_ind = re.search(r'SSD Wearout Indicator is (?P<wearout>[0-9]+)', c.output)
@@ -2023,7 +2026,9 @@ def apic_ssd_check(index, total_checks, cversion, **kwargs):
20232026
else:
20242027
unformatted_data.append(
20252028
['F2731', faultInst['faultInst']['attributes']['dn'], lifetime_remaining, recommended_action])
2026-
if not data and not unformatted_data:
2029+
if has_error:
2030+
result = ERROR
2031+
elif not data and not unformatted_data:
20272032
result = PASS
20282033
print_result(title, result, msg, headers, data, unformatted_headers, unformatted_data, adjust_title=adjust_title)
20292034
return result
@@ -2591,7 +2596,6 @@ def lldp_with_infra_vlan_mismatch_check(index, total_checks, **kwargs):
25912596

25922597

25932598
def apic_version_md5_check(index, total_checks, tversion, username, password, **kwargs):
2594-
# TODO: 'unexpected output when checking md5sum file' may be cuasing stdout print issue
25952599
title = 'APIC Target version image and MD5 hash'
25962600
result = FAIL_UF
25972601
msg = ''
@@ -2621,6 +2625,7 @@ def apic_version_md5_check(index, total_checks, tversion, username, password, **
26212625
md5s = []
26222626
md5_names = []
26232627

2628+
has_error = False
26242629
prints('')
26252630
nodes_response_json = icurl('class', 'topSystem.json')
26262631
for node in nodes_response_json:
@@ -2638,6 +2643,7 @@ def apic_version_md5_check(index, total_checks, tversion, username, password, **
26382643
except Exception as e:
26392644
data.append([apic_name, '-', '-', e, '-'])
26402645
print_result(node_title, ERROR)
2646+
has_error = True
26412647
continue
26422648

26432649
try:
@@ -2647,6 +2653,7 @@ def apic_version_md5_check(index, total_checks, tversion, username, password, **
26472653
data.append([apic_name, '-', '-',
26482654
'ls command via ssh failed due to:{}'.format(e), '-'])
26492655
print_result(node_title, ERROR)
2656+
has_error = True
26502657
continue
26512658
if "No such file or directory" in c.output:
26522659
data.append([apic_name, str(tversion), '-', 'image not found', recommended_action])
@@ -2660,6 +2667,7 @@ def apic_version_md5_check(index, total_checks, tversion, username, password, **
26602667
data.append([apic_name, str(tversion), '-',
26612668
'failed to check md5sum via ssh due to:{}'.format(e), '-'])
26622669
print_result(node_title, ERROR)
2670+
has_error = True
26632671
continue
26642672
if "No such file or directory" in c.output:
26652673
data.append([apic_name, str(tversion), '-', 'md5sum file not found', recommended_action])
@@ -2677,13 +2685,16 @@ def apic_version_md5_check(index, total_checks, tversion, username, password, **
26772685
else:
26782686
data.append([apic_name, str(tversion), '-', 'unexpected output when checking md5sum file', recommended_action])
26792687
print_result(node_title, ERROR)
2688+
has_error = True
26802689
continue
26812690

26822691
print_result(node_title, DONE)
26832692
if len(set(md5s)) > 1:
26842693
for name, md5 in zip(md5_names, md5s):
26852694
data.append([name, str(tversion), md5, 'md5sum do not match on all APICs', recommended_action])
2686-
if not data:
2695+
if has_error:
2696+
result = ERROR
2697+
elif not data:
26872698
result = PASS
26882699
print_result(title, result, msg, headers, data, adjust_title=True)
26892700
return result
@@ -2699,6 +2710,7 @@ def standby_apic_disk_space_check(index, total_checks, **kwargs):
26992710
threshold = 75 # usage (%)
27002711
print_title(title, index, total_checks)
27012712

2713+
has_error = False
27022714
checked_stby = []
27032715
infraSnNodes = icurl('class', 'infraSnNode.json?query-target-filter=eq(infraSnNode.cntrlSbstState,"approved")')
27042716
for stby_apic in infraSnNodes:
@@ -2713,12 +2725,14 @@ def standby_apic_disk_space_check(index, total_checks, **kwargs):
27132725
c.connect()
27142726
except Exception as e:
27152727
data.append([stb['mbSn'], stb['oobIpAddr'], '-', '-', e])
2728+
has_error = True
27162729
continue
27172730

27182731
try:
27192732
c.cmd("df -h")
27202733
except Exception as e:
27212734
data.append([stb['mbSn'], stb['oobIpAddr'], '-', '-', e])
2735+
has_error = True
27222736
continue
27232737

27242738
for line in c.output.split("\n"):
@@ -2733,6 +2747,8 @@ def standby_apic_disk_space_check(index, total_checks, **kwargs):
27332747
if not infraSnNodes:
27342748
result = NA
27352749
msg = 'No standby APIC found'
2750+
elif has_error:
2751+
result = ERROR
27362752
elif not data:
27372753
result = PASS
27382754
msg = 'all below {}%'.format(threshold)
@@ -4999,6 +5015,7 @@ def observer_db_size_check(index, total_checks, username, password, **kwargs):
49995015
if not controllers:
50005016
print_result(title, ERROR, 'topSystem response empty. Is the cluster healthy?')
50015017
return ERROR
5018+
has_error = False
50025019
prints('')
50035020
for apic in controllers:
50045021
attr = apic['topSystem']['attributes']
@@ -5013,13 +5030,15 @@ def observer_db_size_check(index, total_checks, username, password, **kwargs):
50135030
except Exception as e:
50145031
data.append([attr['id'], attr['name'], e])
50155032
print_result(node_title, ERROR)
5033+
has_error = True
50165034
continue
50175035
try:
50185036
cmd = r"ls -lh /data2/dbstats | awk '{print $5, $9}'"
50195037
c.cmd(cmd)
50205038
if "No such file or directory" in c.output:
50215039
data.append([attr['id'], '/data2/dbstats/ not found', "Check user permissions or retry as 'apic#fallback\\\\admin'"])
5022-
print_result(node_title, FAIL_UF)
5040+
print_result(node_title, ERROR)
5041+
has_error = True
50235042
continue
50245043
dbstats = c.output.split("\n")
50255044
for line in dbstats:
@@ -5033,8 +5052,11 @@ def observer_db_size_check(index, total_checks, username, password, **kwargs):
50335052
except Exception as e:
50345053
data.append([attr['id'], attr['name'], e])
50355054
print_result(node_title, ERROR)
5055+
has_error = True
50365056
continue
5037-
if data:
5057+
if has_error:
5058+
result = ERROR
5059+
elif data:
50385060
result = FAIL_UF
50395061
print_result(title, result, msg, headers, data, recommended_action=recommended_action, doc_url=doc_url, adjust_title=True)
50405062
return result

tests/apic_version_md5_check/test_apic_version_md5_check.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
True,
7474
[],
7575
"6.0(5h)",
76-
script.FAIL_UF,
76+
script.ERROR,
7777
),
7878
# Exception failure at the ls command
7979
(
@@ -93,7 +93,7 @@
9393
for apic_ip in apic_ips
9494
},
9595
"6.0(5h)",
96-
script.FAIL_UF,
96+
script.ERROR,
9797
),
9898
# No such file output from the ls command
9999
(
@@ -138,7 +138,7 @@
138138
for apic_ip in apic_ips
139139
},
140140
"6.0(5h)",
141-
script.FAIL_UF,
141+
script.ERROR,
142142
),
143143
# No such file output from the cat command
144144
(
@@ -188,7 +188,7 @@
188188
for apic_ip in apic_ips
189189
},
190190
"6.0(5h)",
191-
script.FAIL_UF,
191+
script.ERROR,
192192
),
193193
# Failure because md5sum on each APIC do not match
194194
(

tests/observer_db_size_check/test_observer_db_size_check.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
{topSystem_api: read_data(dir, "topSystem.json")},
4949
True,
5050
[],
51-
script.FAIL_UF,
51+
script.ERROR,
5252
),
5353
# Simulatated exception at `ls` command
5454
(
@@ -64,7 +64,7 @@
6464
]
6565
for apic_ip in apic_ips
6666
},
67-
script.FAIL_UF,
67+
script.ERROR,
6868
),
6969
# dbstats dir not found/not accessible
7070
(
@@ -80,7 +80,7 @@
8080
]
8181
for apic_ip in apic_ips
8282
},
83-
script.FAIL_UF,
83+
script.ERROR,
8484
),
8585
# dbstats dir found, all DBs under 1G
8686
(

0 commit comments

Comments
 (0)