Skip to content

Commit

Permalink
[chassis]
Browse files Browse the repository at this point in the history
don't initialize sfp_event until it is called
deinitialize sfp_event when chassis destructed so that sdk resources can be correctly released.
  • Loading branch information
Stephen Sun committed Aug 26, 2019
1 parent 2d48e54 commit 38aa635
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,14 @@ def __init__(self):
# move the initialization of each components to their dedicated initializer
# which will be called from platform
self.sfp_module_initialized = False
self.sfp_event_initialized = False
self.reboot_cause_initialized = False
logger.log_info("Chassis loaded successfully")

def __del__(self):
if self.sfp_event_initialized:
self.sfp_event.deinitialize()

def initialize_psu(self):
from sonic_platform.psu import Psu
# Initialize PSU list
Expand Down Expand Up @@ -104,7 +109,7 @@ def initialize_fan(self):

def initialize_sfp(self):
from sonic_platform.sfp import SFP
from sonic_platform.sfp_event import sfp_event

self.sfp_module = SFP

# Initialize SFP list
Expand All @@ -121,11 +126,6 @@ def initialize_sfp(self):
sfp_module = SFP(index, 'SFP')
self._sfp_list.append(sfp_module)

# Initialize SFP event
self.sfp_event = sfp_event()
self.sfp_event.initialize()
self.MAX_SELECT_EVENT_RETURNED = self.PORT_END

self.sfp_module_initialized = True

def initialize_thermals(self):
Expand Down Expand Up @@ -488,6 +488,14 @@ def get_change_event(self, timeout=0):
indicates that fan 0 has been removed, fan 2
has been inserted and sfp 11 has been removed.
"""
# Initialize SFP event first
if not self.sfp_event_initialized:
from sonic_platform.sfp_event import sfp_event
self.sfp_event = sfp_event()
self.sfp_event.initialize()
self.MAX_SELECT_EVENT_RETURNED = self.PORT_END
self.sfp_event_initialized = True

wait_for_ever = (timeout == 0)
port_dict = {}
if wait_for_ever:
Expand Down

0 comments on commit 38aa635

Please sign in to comment.