Skip to content

Commit 3ee939e

Browse files
authored
[Mellanox] Add SAI API headers versions to get_component_versions (#24662)
- Why I did it Improve get_component_versions​ to present the SAI API headers version. For debugging and compatibility validation, it is important to know:​ The SAI API version that SONiC was compiled against​. The SAI API version implemented by the vendor’s installed SAI library at runtime. - How I did it The SAI API version that SONiC was compiled against: During compilation, create_component_versions.sh extracts the version​ from src/sonic-sairedis/SAI/inc/saiversion.h and save it into temp component-versions file. The SAI API version implemented by the vendor’s installed SAI library at runtime: During runtime, using syncd:dpkg -s mlnx-sai - How to verify it run: get_component_versions.py Signed-off-by: Ben Levi <[email protected]>
1 parent 7d0cdaa commit 3ee939e

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

platform/mellanox/component-versions/create_component_versions.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#
2-
# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
2+
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
3+
# Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
34
# Apache-2.0
45
#
56
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,6 +19,21 @@
1819
echo "SDK $1" > temp_versions_file
1920
echo $2 | sed -r 's/([0-9]*)\.([0-9]*)\.([0-9]*)/FW \2\.\3/g' >> temp_versions_file
2021
echo "SAI $3" >> temp_versions_file
22+
23+
SAI_API_VERSION_PATH="../../../src/sonic-sairedis/SAI/inc/saiversion.h"
24+
if [ -f "$SAI_API_VERSION_PATH" ]; then
25+
SAI_MAJOR=$(grep "SAI_MAJOR" "$SAI_API_VERSION_PATH" | grep -oE "[0-9]+")
26+
SAI_MINOR=$(grep "SAI_MINOR" "$SAI_API_VERSION_PATH" | grep -oE "[0-9]+")
27+
SAI_REVISION=$(grep "SAI_REVISION" "$SAI_API_VERSION_PATH" | grep -oE "[0-9]+")
28+
if [ -n "$SAI_MAJOR" ] && [ -n "$SAI_MINOR" ] && [ -n "$SAI_REVISION" ]; then
29+
echo "SAI_API_HEADERS $SAI_MAJOR.$SAI_MINOR.$SAI_REVISION" >> temp_versions_file
30+
else
31+
echo "SAI_API_HEADERS N/A" >> temp_versions_file
32+
fi
33+
else
34+
echo "SAI_API_HEADERS N/A" >> temp_versions_file
35+
fi
36+
2137
echo "HW_MANAGEMENT $4" >> temp_versions_file
2238
echo "MFT $5-$6" >> temp_versions_file
2339
echo "KERNEL $7" >> temp_versions_file

platform/mellanox/get_component_versions/get_component_versions.j2

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ from tabulate import tabulate
3232

3333
COMPONENT_VERSIONS_FILE = "/etc/mlnx/component-versions"
3434
HEADERS = ["COMPONENT", "COMPILATION", "ACTUAL"]
35+
SAI_API_TABLE_HEADERS = ["COMPONENT", "SONIC_SAI", "VENDOR_SAI"]
3536

3637
{% if sonic_asic_platform == "mellanox" %}
3738

@@ -40,6 +41,7 @@ COMMANDS_FOR_ACTUAL = {
4041
"HW_MANAGEMENT": [["dpkg", "-l"], ["grep", "hw"], ".*1\\.mlnx\\.([0-9.]*)"],
4142
"SDK": [["docker", "exec", "-it", "syncd", "bash", "-c", 'dpkg -l | grep sdk'], ".*1\\.mlnx\\.([0-9.]*)"],
4243
"SAI": [["docker", "exec", "-it", "syncd", "bash", "-c", 'dpkg -l | grep mlnx-sai'], ".*1\\.mlnx\\.([A-Za-z0-9.]*)"],
44+
"SAI_API_HEADERS": [["docker", "exec", "syncd", "dpkg", "-s", "mlnx-sai"], "X-Sai-Headers-Version: ([0-9.]+)"],
4345
"FW": [["mlxfwmanager", "--query"], "FW * [0-9]{2}\\.([0-9.]*)"],
4446
"KERNEL": [["uname", "-r"], "([0-9][0-9.-]*)-.*"]
4547
}
@@ -48,6 +50,7 @@ UNAVAILABLE_COMPILED_VERSIONS = {
4850
"SDK": "N/A",
4951
"FW": "N/A",
5052
"SAI": "N/A",
53+
"SAI_API_HEADERS": "N/A",
5154
"HW_MANAGEMENT": "N/A",
5255
"MFT": "N/A",
5356
"KERNEL": "N/A",
@@ -146,8 +149,8 @@ def get_current_version(comp):
146149
return "N/A"
147150

148151

149-
def format_output_table(table):
150-
return tabulate(table, HEADERS)
152+
def format_output_table(table, headers=HEADERS):
153+
return tabulate(table, headers)
151154

152155

153156
def main():
@@ -159,6 +162,14 @@ def main():
159162
compiled_versions = parse_compiled_components_file()
160163
simx_compiled_ver = compiled_versions.pop("SIMX")
161164

165+
# Handle SAI_API_HEADERS versions
166+
sai_api_headers_table = []
167+
if "SAI_API_HEADERS" in compiled_versions:
168+
sai_api_version_in_sai = get_current_version("SAI_API_HEADERS")
169+
sai_api_version_in_sonic = compiled_versions["SAI_API_HEADERS"]
170+
sai_api_headers_table.append(["SAI_API_HEADERS", sai_api_version_in_sonic, sai_api_version_in_sai])
171+
compiled_versions.pop("SAI_API_HEADERS")
172+
162173
# Add compiled versions to table
163174
output_table = []
164175
for comp in compiled_versions.keys():
@@ -179,6 +190,10 @@ def main():
179190

180191
print(format_output_table(output_table))
181192

193+
if sai_api_headers_table:
194+
print("\n")
195+
print(format_output_table(sai_api_headers_table, SAI_API_TABLE_HEADERS))
196+
182197

183198
if __name__ == "__main__":
184199
main()

0 commit comments

Comments
 (0)