Skip to content

Commit 9395ebd

Browse files
authored
[show][platform] Revise chassis info fallback to only fall back on pmon crash (#1751)
What I did Changed the behavior of the get_chassis_info() function which is used by show version and show platform summary to report the serial / model / revision of the switch to only attempt to call the platform API if pmon completely failed to provision STATE_DB with CHASSIS_INFO How I did it Altered get_chassis_info() according to the above behavior. See changelog for details. How to verify it Verify show platform summary and show version correctly report chassis info. Delete the CHASSIS_INFO table from STATE_DB Verify show platform summary and show version still correctly report the info.
1 parent 29f4a16 commit 9395ebd

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

show/platform.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,27 @@
1212

1313
def get_chassis_info():
1414
"""
15-
Attempts to get the chassis info via STATE_DB and falls back to direct Platform API calls.
15+
Attempts to retrieve chassis information from CHASSIS_INFO table in STATE_DB if this table does
16+
not exist then we assume pmon has crashed and will attempt to call the platform API directly. If this
17+
call fails we simply return N/A.
1618
"""
1719

18-
chassis_info = device_info.get_chassis_info()
19-
required_keys = ['serial', 'model', 'revision']
20-
failed_vals = ['', 'N/A']
21-
platform_chassis = None
20+
keys = ["serial", "model", "revision"]
2221

23-
for k in required_keys:
24-
if chassis_info.get(k, '') in failed_vals:
25-
if platform_chassis is None:
22+
def try_get(platform, attr, fallback):
23+
try:
24+
if platform["chassis"] is None:
2625
import sonic_platform
27-
platform_chassis = sonic_platform.platform.Platform().get_chassis()
28-
try:
29-
chassis_info[k] = getattr(platform_chassis, "get_".format(k))()
30-
except AttributeError:
31-
chassis_info[k] = 'N/A'
26+
platform["chassis"] = sonic_platform.platform.Platform().get_chassis()
27+
return getattr(platform["chassis"], "get_{}".format(attr))()
28+
except Exception:
29+
return 'N/A'
30+
31+
chassis_info = device_info.get_chassis_info()
32+
33+
if all(v is None for k, v in chassis_info.items()):
34+
platform_cache = {"chassis": None}
35+
chassis_info = {k:try_get(platform_cache, k, "N/A") for k in keys}
3236

3337
return chassis_info
3438

0 commit comments

Comments
 (0)