-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mellanox] Implementation for component version listing (#18591)
- 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
Showing
9 changed files
with
223 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
platform/mellanox/component-versions/create_component_versions.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
platform/mellanox/get_component_versions/get_component_versions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters