Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mellanox] Added simx version to Nvidia component version listing #19523

Merged
merged 12 commits into from
Jul 22, 2024
2 changes: 1 addition & 1 deletion platform/mellanox/component-versions/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions platform/mellanox/fw.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}


Expand All @@ -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
Expand All @@ -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):
Expand All @@ -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]])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
Loading