Skip to content

Commit

Permalink
[Mellanox] Fixed sai xml name format bug (#19967)
Browse files Browse the repository at this point in the history
- Why I did it
Fixed the name that the script looks for when checking sai_*.xml

- How I did it
Instead of searching with a general regex, the name of sai*.xml is taken from a variable in sai.profile.
  • Loading branch information
skr31 authored Aug 21, 2024
1 parent c5a620b commit 3d14306
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions platform/mellanox/cmis_host_mgmt/cmis_host_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import re
import os
import subprocess
import glob
from pathlib import Path


class CMISHostMgmtActivator:
Expand Down Expand Up @@ -60,7 +62,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"],
Expand Down Expand Up @@ -137,8 +139,19 @@ 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)

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")

CMISHostMgmtActivator.copy_file(args[0], sku_path)
CMISHostMgmtActivator.copy_file(args[1], sku_path)
Expand Down

0 comments on commit 3d14306

Please sign in to comment.