Skip to content

Commit

Permalink
[show][platform] Revise chassis info fallback to only fall back on pm…
Browse files Browse the repository at this point in the history
…on 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.
  • Loading branch information
alexrallen authored and judyjoseph committed Sep 14, 2021
1 parent 2630ac1 commit 3bf962c
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions show/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@

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

chassis_info = device_info.get_chassis_info()
required_keys = ['serial', 'model', 'revision']
failed_vals = ['', 'N/A']
platform_chassis = None
keys = ["serial", "model", "revision"]

for k in required_keys:
if chassis_info.get(k, '') in failed_vals:
if platform_chassis is None:
def try_get(platform, attr, fallback):
try:
if platform["chassis"] is None:
import sonic_platform
platform_chassis = sonic_platform.platform.Platform().get_chassis()
try:
chassis_info[k] = getattr(platform_chassis, "get_".format(k))()
except AttributeError:
chassis_info[k] = 'N/A'
platform["chassis"] = sonic_platform.platform.Platform().get_chassis()
return getattr(platform["chassis"], "get_{}".format(attr))()
except Exception:
return 'N/A'

chassis_info = device_info.get_chassis_info()

if all(v is None for k, v in chassis_info.items()):
platform_cache = {"chassis": None}
chassis_info = {k:try_get(platform_cache, k, "N/A") for k in keys}

return chassis_info

Expand Down

0 comments on commit 3bf962c

Please sign in to comment.