From ddd954f1bf76e3b5616f49f38d2bf32b25ebcdbe Mon Sep 17 00:00:00 2001 From: Chris <156943338+ccroy-arista@users.noreply.github.com> Date: Tue, 12 Nov 2024 19:34:32 -0800 Subject: [PATCH] Fix asic identification (#15297) * sonic-mgmt: improve asic identification Device ASIC identification is achieved by whole line matches from the output of lspci, which is excessive and subject to fail due to unforeseeable changes in such output. This change reduces the string matching to specific unique differentiators in the output from lspci, while also future-proofing against similar changes in the lspci that could foreseeably occur. * sonic-mgmt: add th4/th5 asic identification Add token matches for identifying the TH4 and TH5 ASICs from the output of lspci. * sonic-mgmt: fix pre-commit issue Fix pre-commit error introduced within the prior two commits. --- tests/common/devices/sonic.py | 37 +++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/tests/common/devices/sonic.py b/tests/common/devices/sonic.py index f5450ec737f..79ef9311c1e 100644 --- a/tests/common/devices/sonic.py +++ b/tests/common/devices/sonic.py @@ -32,6 +32,7 @@ "orchagent": "swss", "syncd": "syncd" } +UNKNOWN_ASIC = "unknown" class SonicHost(AnsibleHostBase): @@ -1735,28 +1736,34 @@ def run_redis_cli_cmd(self, redis_cmd): cmd = "/usr/bin/redis-cli {}".format(redis_cmd) return self.command(cmd, verbose=False) + def _try_get_brcm_asic_name(self, output): + search_sets = { + "td2": {"b85", "BCM5685"}, + "td3": {"b87", "BCM5687"}, + "th": {"b96", "BCM5696"}, + "th2": {"b97", "BCM5697"}, + "th3": {"b98", "BCM5698"}, + "th4": {"b99", "BCM5699"}, + "th5": {"f90", "BCM7890"}, + } + for asic in search_sets.keys(): + for search_term in search_sets[asic]: + if search_term in output: + return asic + return UNKNOWN_ASIC + def get_asic_name(self): - asic = "unknown" + asic = UNKNOWN_ASIC output = self.shell("lspci", module_ignore_errors=True)["stdout"] - if ("Broadcom Limited Device b960" in output or - "Broadcom Limited Broadcom BCM56960" in output): - asic = "th" - elif "Device b971" in output: - asic = "th2" - elif ("Broadcom Limited Device b850" in output or - "Broadcom Limited Broadcom BCM56850" in output or - "Broadcom Inc. and subsidiaries Broadcom BCM56850" in output): - asic = "td2" - elif ("Broadcom Limited Device b870" in output or - "Broadcom Inc. and subsidiaries Device b870" in output): - asic = "td3" - elif "Broadcom Limited Device b980" in output: - asic = "th3" + if "Broadcom" in output: + asic = self._try_get_brcm_asic_name(output) elif "Cisco Systems Inc Device a001" in output: asic = "gb" elif "Mellanox Technologies" in output: asic = "spc" + logger.info("asic: {}".format(asic)) + return asic def is_nvidia_platform(self):