Skip to content

Commit

Permalink
[Mellanox] Implementation for component version listing (#18591)
Browse files Browse the repository at this point in the history
- Why I did it
Added ability to show summary of all the component versions on the switch and a comparison between compiled versions and actual versions.
The user will be able to run the 'get_component_versions.py' script which outputs the versions table.
The versions table will also be saved in techsupport.

- How I did it
Added Make files that add a new file to the system that contains all the versions of the components available at compilation (the versions are taken from corresponding .mk files).
Added a script that outputs a table that summarizes all the component versions (compilation and actual)
  • Loading branch information
skr31 authored Apr 17, 2024
1 parent ed10a9f commit 82a222c
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 2 deletions.
3 changes: 3 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ for fw_file_name in ${!FW_FILE_MAP[@]}; do
done
sudo cp $files_path/$ISSU_VERSION_FILE $FILESYSTEM_ROOT/$PLATFORM_DIR/fw/asic/issu-version
sudo ln -s /host/image-$SONIC_IMAGE_VERSION/$PLATFORM_DIR/fw/asic/issu-version $FILESYSTEM_ROOT/etc/mlnx/issu-version
sudo cp $files_path/$COMPONENT_VERSIONS_FILE $FILESYSTEM_ROOT/etc/mlnx/component-versions
sudo cp $files_path/$MLNX_FFB_SCRIPT $FILESYSTEM_ROOT/usr/bin/mlnx-ffb.sh
sudo cp $files_path/$MLNX_ONIE_FW_UPDATE $FILESYSTEM_ROOT/usr/bin/$MLNX_ONIE_FW_UPDATE
sudo cp $files_path/$MLNX_SSD_FW_UPDATE $FILESYSTEM_ROOT/usr/bin/$MLNX_SSD_FW_UPDATE
Expand All @@ -1020,6 +1021,8 @@ sudo mkdir -p $FILESYSTEM_ROOT/etc/mlnx/cpld/
for MLNX_CPLD_ARCHIVE in $MLNX_CPLD_ARCHIVES; do
sudo cp $files_path/$MLNX_CPLD_ARCHIVE $FILESYSTEM_ROOT/etc/mlnx/cpld/
done
sudo cp platform/mellanox/get_component_versions/get_component_versions.py $FILESYSTEM_ROOT/usr/bin/get_component_versions.py
sudo chmod 755 $FILESYSTEM_ROOT/usr/bin/get_component_versions.py
j2 platform/mellanox/mlnx-fw-upgrade.j2 | sudo tee $FILESYSTEM_ROOT/usr/bin/mlnx-fw-upgrade.sh
sudo chmod 755 $FILESYSTEM_ROOT/usr/bin/mlnx-fw-upgrade.sh

Expand Down
10 changes: 10 additions & 0 deletions platform/mellanox/component-versions.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# DPKG FRK

SPATH := $($(COMPONENT_VERSIONS_FILE)_SRC_PATH)
DEP_FILES := $(SONIC_COMMON_FILES_LIST) $(PLATFORM_PATH)/component-versions.mk $(PLATFORM_PATH)/component-versions.dep
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST)
DEP_FILES += $(shell git ls-files -- $(SPATH))

$(COMPONENT_VERSIONS_FILE)_CACHE_MODE := GIT_CONTENT_SHA
$(COMPONENT_VERSIONS_FILE)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
$(COMPONENT_VERSIONS_FILE)_DEP_FILES := $(DEP_FILES)
26 changes: 26 additions & 0 deletions platform/mellanox/component-versions.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Firmware pending update checker and installer

COMPONENT_VERSIONS_FILE = component-versions
$(COMPONENT_VERSIONS_FILE)_SRC_PATH = $(PLATFORM_PATH)/component-versions

SONIC_MAKE_FILES += $(COMPONENT_VERSIONS_FILE)

MLNX_FILES += $(COMPONENT_VERSIONS_FILE)

export COMPONENT_VERSIONS_FILE
26 changes: 26 additions & 0 deletions platform/mellanox/component-versions/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

.ONESHELL:
SHELL = /bin/bash
.SHELLFLAGS += -e

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)
mv temp_versions_file $(DEST)/$(MAIN_TARGET)
23 changes: 23 additions & 0 deletions platform/mellanox/component-versions/create_component_versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

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 "MFT $5-$6" >> temp_versions_file
echo "Kernel $7" >> temp_versions_file
3 changes: 2 additions & 1 deletion platform/mellanox/fw.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2016-2023 NVIDIA CORPORATION & AFFILIATES.
# Copyright (c) 2016-2024 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -62,6 +62,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 MLNX_SPC_FW_FILE
export MLNX_SPC2_FW_FILE
export MLNX_SPC3_FW_FILE
Expand Down
130 changes: 130 additions & 0 deletions platform/mellanox/get_component_versions/get_component_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/usr/bin/env python3
#
# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import os
import subprocess
import re

from fwutil.lib import PlatformDataProvider
from sonic_py_common.general import check_output_pipe
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.]*)"],
"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.-]*)-.*"]
}

UNAVAILABLE_PLATFORM_VERSIONS = {
"SSD": "N/A",
"BIOS": "N/A",
"CPLD": "N/A"
}

UNAVAILABLE_COMPILED_VERSIONS = {
"SDK": "N/A",
"FW": "N/A",
"SAI": "N/A",
"HW-MGMT": "N/A",
"MFT": "N/A",
"Kernel": "N/A"
}


def parse_compiled_components_file():
compiled_versions = UNAVAILABLE_COMPILED_VERSIONS

if not os.path.exists(COMPONENT_VERSIONS_FILE):
return UNAVAILABLE_COMPILED_VERSIONS

with open(COMPONENT_VERSIONS_FILE, 'r') as component_versions:
for line in component_versions.readlines():
comp, version = line.split()
compiled_versions[comp] = version

return compiled_versions


def get_platform_component_versions():
pdp = PlatformDataProvider()
ccm = pdp.chassis_component_map

if not ccm:
return UNAVAILABLE_PLATFORM_VERSIONS

versions_map = None

# The first layer of the map only has one item
for key, value in ccm.items():
versions_map = value
break

if not versions_map or len(versions_map) == 0:
return UNAVAILABLE_PLATFORM_VERSIONS

platform_versions = {}
for component_name, component in versions_map.items():
platform_versions[component_name] = component.get_firmware_version()

return platform_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"


def format_output_table(table):
return tabulate(table, HEADERS)


def main():

if os.getuid() != 0:
print("Error: Root privileges are required")
return

compiled_versions = parse_compiled_components_file()
platform_versions = get_platform_component_versions()

output_table = []
for comp in compiled_versions.keys():
actual = get_current_version(comp)
output_table.append([comp, compiled_versions[comp], actual])

for comp in platform_versions.keys():
output_table.append([comp, "-", platform_versions[comp]])

print(format_output_table(output_table))


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions platform/mellanox/rules.dep
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ include $(PLATFORM_PATH)/issu-version.dep
include $(PLATFORM_PATH)/mlnx-onie-fw-update.dep
include $(PLATFORM_PATH)/mlnx-ssd-fw-update.dep
include $(PLATFORM_PATH)/install-pending-fw.dep
include $(PLATFORM_PATH)/component-versions.dep
3 changes: 2 additions & 1 deletion platform/mellanox/rules.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2016-2023 NVIDIA CORPORATION & AFFILIATES.
# Copyright (c) 2016-2024 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -34,6 +34,7 @@ include $(PLATFORM_PATH)/mlnx-ssd-fw-update.mk
include $(PLATFORM_PATH)/iproute2.mk
include $(PLATFORM_PATH)/install-pending-fw.mk
include $(PLATFORM_PATH)/integration-scripts.mk
include $(PLATFORM_PATH)/component-versions.mk

SONIC_ALL += $(SONIC_ONE_IMAGE) \
$(DOCKER_FPM)
Expand Down

0 comments on commit 82a222c

Please sign in to comment.