From b6908ce349ee88c3d1a0a5bc56570f8d3d3e3ea9 Mon Sep 17 00:00:00 2001 From: Sophie Kravitz Date: Mon, 19 Aug 2024 11:07:05 +0300 Subject: [PATCH 1/3] fixed sai xml name format --- platform/mellanox/cmis_host_mgmt/cmis_host_mgmt.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/platform/mellanox/cmis_host_mgmt/cmis_host_mgmt.py b/platform/mellanox/cmis_host_mgmt/cmis_host_mgmt.py index aaedbe4a57ba..970358e9ecfc 100644 --- a/platform/mellanox/cmis_host_mgmt/cmis_host_mgmt.py +++ b/platform/mellanox/cmis_host_mgmt/cmis_host_mgmt.py @@ -21,6 +21,7 @@ import re import os import subprocess +import glob class CMISHostMgmtActivator: @@ -137,8 +138,15 @@ def enable(args): if not CMISHostMgmtActivator.is_spc_supported(sku_num): print("Error: unsupported platform - feature is supported on SPC3 and higher.") - - CMISHostMgmtActivator.PARAMS["sai_xml"]["file_name"] = "sai_{0}.xml".format(sku_num) + + # Find sai_*.xml, assume there can only be one in the directory + sai_xml_list = glob.glob(os.path.join(sku_path + "/sai*.xml")) + sai_xml_name = sai_xml_list[0] + if sai_xml_name: + sai_xml_name = sai_xml_name.split('/')[-1] + CMISHostMgmtActivator.PARAMS["sai_xml"]["file_name"] = sai_xml_name + else: + print("Error: no sai_*.xml file present") CMISHostMgmtActivator.copy_file(args[0], sku_path) CMISHostMgmtActivator.copy_file(args[1], sku_path) From ccfbaccf0d9b281d156886787b0850c37e55f896 Mon Sep 17 00:00:00 2001 From: Sophie Kravitz Date: Mon, 19 Aug 2024 11:52:57 +0300 Subject: [PATCH 2/3] fixed new line issue --- platform/mellanox/cmis_host_mgmt/cmis_host_mgmt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/mellanox/cmis_host_mgmt/cmis_host_mgmt.py b/platform/mellanox/cmis_host_mgmt/cmis_host_mgmt.py index 970358e9ecfc..654bc04313e9 100644 --- a/platform/mellanox/cmis_host_mgmt/cmis_host_mgmt.py +++ b/platform/mellanox/cmis_host_mgmt/cmis_host_mgmt.py @@ -61,7 +61,7 @@ def change_param(param, path, action): if param == "sai_profile" and not re.search(CMISHostMgmtActivator.PARAMS[param]["disabled_param"], lines): if not re.search(CMISHostMgmtActivator.PARAMS[param]["enabled_param"], lines): with open(file_path, 'a') as param_file: - param_file.write(CMISHostMgmtActivator.PARAMS[param]["enabled_param"]) + param_file.write(CMISHostMgmtActivator.PARAMS[param]["enabled_param"] + '\n') return lines = re.sub(CMISHostMgmtActivator.PARAMS[param]["disabled_param"], From 5e9fa77d8b0414658b755c5df61f7a13032626fb Mon Sep 17 00:00:00 2001 From: Sophie Kravitz Date: Mon, 19 Aug 2024 14:03:17 +0300 Subject: [PATCH 3/3] changed the sai xml path to be read from sai.profile --- .../mellanox/cmis_host_mgmt/cmis_host_mgmt.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/platform/mellanox/cmis_host_mgmt/cmis_host_mgmt.py b/platform/mellanox/cmis_host_mgmt/cmis_host_mgmt.py index 654bc04313e9..a1011d244b94 100644 --- a/platform/mellanox/cmis_host_mgmt/cmis_host_mgmt.py +++ b/platform/mellanox/cmis_host_mgmt/cmis_host_mgmt.py @@ -22,6 +22,7 @@ import os import subprocess import glob +from pathlib import Path class CMISHostMgmtActivator: @@ -139,11 +140,15 @@ def enable(args): if not CMISHostMgmtActivator.is_spc_supported(sku_num): print("Error: unsupported platform - feature is supported on SPC3 and higher.") - # Find sai_*.xml, assume there can only be one in the directory - sai_xml_list = glob.glob(os.path.join(sku_path + "/sai*.xml")) - sai_xml_name = sai_xml_list[0] - if sai_xml_name: - sai_xml_name = sai_xml_name.split('/')[-1] + sai_profile_file = '{}/{}'.format(sku_path, CMISHostMgmtActivator.PARAMS["sai_profile"]["file_name"]) + lines = None + with open(sai_profile_file, 'r') as saiprofile: + lines = saiprofile.read() + + sai_xml_path = re.search("SAI_INIT_CONFIG_FILE.*", lines).group() + + if sai_xml_path: + sai_xml_name = Path(sai_xml_path).name CMISHostMgmtActivator.PARAMS["sai_xml"]["file_name"] = sai_xml_name else: print("Error: no sai_*.xml file present")