diff --git a/platform/mellanox/component-versions/Makefile b/platform/mellanox/component-versions/Makefile index 6a240bd02e53..095aad7902a7 100644 --- a/platform/mellanox/component-versions/Makefile +++ b/platform/mellanox/component-versions/Makefile @@ -22,5 +22,5 @@ SHELL = /bin/bash MAIN_TARGET = component-versions $(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% : - ./create_component_versions.sh $(MLNX_SDK_VERSION) $(MLNX_SPC_FW_VERSION) $(MLNX_SAI_VERSION) $(MLNX_HW_MANAGEMENT_VERSION) $(MFT_VERSION) $(MFT_REVISION) $(KVERSION_SHORT) + ./create_component_versions.sh $(MLNX_SDK_VERSION) $(MLNX_SPC_FW_VERSION) $(MLNX_SAI_VERSION) $(MLNX_HW_MANAGEMENT_VERSION) $(MFT_VERSION) $(MFT_REVISION) $(KVERSION_SHORT) $(SIMX_VERSION) mv temp_versions_file $(DEST)/$(MAIN_TARGET) diff --git a/platform/mellanox/component-versions/create_component_versions.sh b/platform/mellanox/component-versions/create_component_versions.sh index 109242de9a0e..b523c0308d85 100755 --- a/platform/mellanox/component-versions/create_component_versions.sh +++ b/platform/mellanox/component-versions/create_component_versions.sh @@ -18,6 +18,7 @@ echo "SDK $1" > temp_versions_file echo $2 | sed -r 's/([0-9]*)\.([0-9]*)\.([0-9]*)/FW \2\.\3/g' >> temp_versions_file echo "SAI $3" >> temp_versions_file -echo "HW-MGMT $4" >> temp_versions_file +echo "HW_MANAGEMENT $4" >> temp_versions_file echo "MFT $5-$6" >> temp_versions_file -echo "Kernel $7" >> temp_versions_file +echo "KERNEL $7" >> temp_versions_file +echo "SIMX $8" >> temp_versions_file diff --git a/platform/mellanox/fw.mk b/platform/mellanox/fw.mk index 2b6931d5e440..c1f1311d84f7 100644 --- a/platform/mellanox/fw.mk +++ b/platform/mellanox/fw.mk @@ -63,6 +63,7 @@ endif MLNX_FILES += $(MLNX_FW_FILES) export MLNX_SPC_FW_VERSION MLNX_SPC2_FW_VERSION MLNX_SPC3_FW_VERSION MLNX_SPC4_FW_VERSION +export SIMX_VERSION export MLNX_SPC_FW_FILE export MLNX_SPC2_FW_FILE export MLNX_SPC3_FW_FILE diff --git a/platform/mellanox/get_component_versions/get_component_versions.py b/platform/mellanox/get_component_versions/get_component_versions.py index 8e900eb0ca08..ba75bd8a215b 100644 --- a/platform/mellanox/get_component_versions/get_component_versions.py +++ b/platform/mellanox/get_component_versions/get_component_versions.py @@ -20,22 +20,28 @@ import subprocess import re -from fwutil.lib import PlatformDataProvider +try: + from fwutil.lib import PlatformDataProvider +except Exception: + PlatformDataProvider = None + from sonic_py_common.general import check_output_pipe +from sonic_platform.device_data import DeviceDataManager from tabulate import tabulate COMPONENT_VERSIONS_FILE = "/etc/mlnx/component-versions" HEADERS = ["COMPONENT", "COMPILATION", "ACTUAL"] COMMANDS_FOR_ACTUAL = { "MFT": [["dpkg", "-l"], ["grep", "mft "], "mft *([0-9.-]*)"], - "HW-MGMT": [["dpkg", "-l"], ["grep", "hw"], ".*1\\.mlnx\\.([0-9.]*)"], + "HW_MANAGEMENT": [["dpkg", "-l"], ["grep", "hw"], ".*1\\.mlnx\\.([0-9.]*)"], "SDK": [["docker", "exec", "-it", "syncd", "bash", "-c", 'dpkg -l | grep sdk'], ".*1\\.mlnx\\.([0-9.]*)"], "SAI": [["docker", "exec", "-it", "syncd", "bash", "-c", 'dpkg -l | grep mlnx-sai'], ".*1\\.mlnx\\.([A-Za-z0-9.]*)"], "FW": [["mlxfwmanager", "--query"], "FW * [0-9]{2}\\.([0-9.]*)"], - "Kernel": [["uname", "-r"], "([0-9][0-9.-]*)-.*"] + "KERNEL": [["uname", "-r"], "([0-9][0-9.-]*)-.*"] } UNAVAILABLE_PLATFORM_VERSIONS = { + "ONIE": "N/A", "SSD": "N/A", "BIOS": "N/A", "CPLD": "N/A" @@ -45,9 +51,9 @@ "SDK": "N/A", "FW": "N/A", "SAI": "N/A", - "HW-MGMT": "N/A", + "HW_MANAGEMENT": "N/A", "MFT": "N/A", - "Kernel": "N/A" + "KERNEL": "N/A" } @@ -59,15 +65,21 @@ def parse_compiled_components_file(): with open(COMPONENT_VERSIONS_FILE, 'r') as component_versions: for line in component_versions.readlines(): - comp, version = line.split() - compiled_versions[comp] = version + try: + comp, version = line.split() + compiled_versions[comp] = version + except ValueError: + continue return compiled_versions def get_platform_component_versions(): - pdp = PlatformDataProvider() - ccm = pdp.chassis_component_map + ccm = None + + if PlatformDataProvider: + pdp = PlatformDataProvider() + ccm = pdp.chassis_component_map if not ccm: return UNAVAILABLE_PLATFORM_VERSIONS @@ -91,15 +103,18 @@ def get_platform_component_versions(): def get_current_version(comp): version = "" - # If there's only one command - if len(COMMANDS_FOR_ACTUAL[comp]) == 2: - version = subprocess.run(COMMANDS_FOR_ACTUAL[comp][0], shell=False, stdout=subprocess.PIPE, text=True) - version = str(version.stdout) - #If there are two commands and we need a pipe - elif len(COMMANDS_FOR_ACTUAL[comp]) == 3: - version = check_output_pipe(COMMANDS_FOR_ACTUAL[comp][0], COMMANDS_FOR_ACTUAL[comp][1]) - parsed_version = re.search(COMMANDS_FOR_ACTUAL[comp][-1], version) - return parsed_version.group(1) if parsed_version else "N/A" + try: + # If there's only one command + if len(COMMANDS_FOR_ACTUAL[comp]) == 2: + version = subprocess.run(COMMANDS_FOR_ACTUAL[comp][0], shell=False, stdout=subprocess.PIPE, text=True) + version = str(version.stdout) + #If there are two commands and we need a pipe + elif len(COMMANDS_FOR_ACTUAL[comp]) == 3: + version = check_output_pipe(COMMANDS_FOR_ACTUAL[comp][0], COMMANDS_FOR_ACTUAL[comp][1]) + parsed_version = re.search(COMMANDS_FOR_ACTUAL[comp][-1], version) + return parsed_version.group(1) if parsed_version else "N/A" + except Exception: + return "N/A" def format_output_table(table): @@ -113,13 +128,23 @@ def main(): return compiled_versions = parse_compiled_components_file() - platform_versions = get_platform_component_versions() + simx_compiled_ver = compiled_versions.pop("SIMX") + # Add compiled versions to table output_table = [] for comp in compiled_versions.keys(): actual = get_current_version(comp) output_table.append([comp, compiled_versions[comp], actual]) + # Handle if SIMX + if DeviceDataManager.is_simx_platform(): + simx_actual_ver = DeviceDataManager.get_simx_version() + output_table.append(["SIMX", simx_compiled_ver, simx_actual_ver]) + platform_versions = UNAVAILABLE_PLATFORM_VERSIONS + else: + platform_versions = get_platform_component_versions() + + # Add actual versions to table for comp in platform_versions.keys(): output_table.append([comp, "-", platform_versions[comp]]) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/device_data.py b/platform/mellanox/mlnx-platform-api/sonic_platform/device_data.py index 1f2b3164a64d..ba2a1ee45dc4 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/device_data.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/device_data.py @@ -18,8 +18,10 @@ import glob import os import time +import re from . import utils +from sonic_py_common.general import check_output_pipe DEFAULT_WD_PERIOD = 65535 @@ -166,6 +168,13 @@ def is_simx_platform(cls): platform_name = cls.get_platform_name() return platform_name and 'simx' in platform_name + @classmethod + @utils.read_only_cache() + def get_simx_version(cls): + version = check_output_pipe(["lspci", "-vv"], ["grep", "SimX"]) + parsed_version = re.search("([0-9]+\\.[0-9]+-[0-9]+)", version) + return parsed_version.group(1) if parsed_version else "N/A" + @classmethod @utils.read_only_cache() def get_fan_drawer_count(cls):