Skip to content

Commit

Permalink
[Mellanox] Fix timing issue in lpmode change
Browse files Browse the repository at this point in the history
  • Loading branch information
noaOrMlnx committed Feb 25, 2024
1 parent 54c1a49 commit fa6c0a8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import ctypes
import subprocess
import os
import time
import threading
from sonic_py_common.logger import Logger
from sonic_py_common.general import check_output_pipe
Expand Down Expand Up @@ -620,6 +621,18 @@ def _set_lpmode_raw(cls, sdk_handle, sdk_index, slot_id, ports, attr_type, power

return result

def check_lpmode(self, desired_lpmode, api):
return api.get_lpmode() == desired_lpmode


def wait_until(self, timeout, poll_interval, desired_lpmode, api):
start_time = time.time()
while not self.check_lpmode(desired_lpmode, api):
if time.time() - start_time >= timeout:
return False
time.sleep(poll_interval)
return True


def set_lpmode(self, lpmode):
"""
Expand All @@ -640,7 +653,7 @@ def set_lpmode(self, lpmode):
if api.get_lpmode() == lpmode:
return True
api.set_lpmode(lpmode)
return api.get_lpmode() == lpmode
return self.wait_until(timeout=2, poll_interval=0.5, desired_lpmode=lpmode, api=api)
elif DeviceDataManager.is_independent_mode():
# FW control under CMIS host management mode.
# Currently, we don't support set LPM under this mode.
Expand Down

0 comments on commit fa6c0a8

Please sign in to comment.