forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mellanox] run module initialization when any SFP related API is called
- Loading branch information
1 parent
bf592f6
commit c7d3ded
Showing
6 changed files
with
1,210 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
platform/mellanox/mlnx-platform-api/sonic_platform/module_host_mgmt_initializer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
from .device_data import DeviceDataManager | ||
from . import utils | ||
from sonic_py_common.logger import Logger | ||
|
||
import atexit | ||
import os | ||
import sys | ||
import threading | ||
|
||
MODULE_READY_MAX_WAIT_TIME = 300 | ||
MODULE_READY_CHECK_INTERVAL = 5 | ||
MODULE_READY_CONTAINER_FILE = '/tmp/module_host_mgmt_ready' | ||
MODULE_READY_HOST_FILE = '/tmp/nv-syncd-shared/module_host_mgmt_ready' | ||
DEDICATE_INIT_DAEMON = 'xcvrd' | ||
initialization_owner = False | ||
|
||
logger = Logger() | ||
|
||
|
||
class ModuleHostMgmtInitializer: | ||
def __init__(self): | ||
self.initialized = False | ||
self.lock = threading.Lock() | ||
|
||
def initialize(self, chassis): | ||
global initialization_owner | ||
if self.initialized: | ||
return | ||
|
||
if utils.is_host(): | ||
self.wait_module_ready() | ||
else: | ||
cmd = os.path.basename(sys.argv[0]) | ||
if DEDICATE_INIT_DAEMON in cmd: | ||
if not self.initialized: | ||
with self.lock: | ||
if not self.initialized: | ||
logger.log_notice('Starting module initialization for module host management...') | ||
initialization_owner = True | ||
self.remove_module_ready_file() | ||
|
||
chassis.initialize_sfp() | ||
|
||
from .sfp import SFP | ||
SFP.initialize_sfp_modules(chassis._sfp_list) | ||
|
||
self.create_module_ready_file() | ||
self.initialized = True | ||
logger.log_notice('Module initialization for module host management done') | ||
else: | ||
self.wait_module_ready() | ||
|
||
@classmethod | ||
def create_module_ready_file(cls): | ||
with open(MODULE_READY_CONTAINER_FILE, 'w'): | ||
pass | ||
|
||
@classmethod | ||
def remove_module_ready_file(cls): | ||
if os.path.exists(MODULE_READY_CONTAINER_FILE): | ||
os.remove(MODULE_READY_CONTAINER_FILE) | ||
|
||
def wait_module_ready(self): | ||
if utils.is_host(): | ||
module_ready_file = MODULE_READY_HOST_FILE | ||
else: | ||
module_ready_file = MODULE_READY_CONTAINER_FILE | ||
|
||
if os.path.exists(module_ready_file): | ||
self.initialized = True | ||
return | ||
else: | ||
print('Waiting module to be initialized...') | ||
|
||
if utils.wait_until(os.path.exists, MODULE_READY_MAX_WAIT_TIME, MODULE_READY_CHECK_INTERVAL, module_ready_file): | ||
self.initialized = True | ||
else: | ||
logger.log_error('Module initialization timeout', True) | ||
|
||
|
||
@atexit.register | ||
def clean_up(): | ||
if initialization_owner: | ||
ModuleHostMgmtInitializer.remove_module_ready_file() |
Oops, something went wrong.