-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update for the Procedures for insertion/hot swap of Switch Fabric Mod…
…ule (SFM) 1. Add chassis_module_config.py and its service. 2. When the cli command "sudo config chassis modules startup/shutdown" runs, calls chassis_module_set_admin_state.py to do the ralated operations.
- Loading branch information
1 parent
be01b37
commit 875f99f
Showing
3 changed files
with
99 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[Unit] | ||
Description=Chassis module up & down operation | ||
ConditionPathExists=/etc/sonic/chassisdb.conf | ||
Requires=database.service updategraph.service | ||
After=database.service updategraph.service | ||
StartLimitIntervalSec=1200 | ||
StartLimitBurst=3 | ||
BindsTo=sonic.target | ||
After=sonic.target | ||
|
||
[Service] | ||
User=root | ||
ExecStart=/usr/bin/python3 /usr/local/bin/chassis_module_config.py | ||
ExecStop=/bin/kill -SIGINT $MAINPID | ||
RestartSec=30 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
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
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,80 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
Chassis module config | ||
""" | ||
try: | ||
import sys | ||
import os | ||
import subprocess | ||
from sonic_py_common import daemon_base | ||
from swsscommon import swsscommon | ||
from sonic_py_common.logger import Logger | ||
except ImportError as e: | ||
raise ImportError(str(e) + " - required module wasn't found") | ||
|
||
# | ||
# Constants ==================================================================== | ||
# | ||
SYSLOG_IDENTIFIER = 'chassis_module_config.py' | ||
CHASSIS_MODULE= 'CHASSIS_MODULE' | ||
SELECT_TIMEOUT_MSECS = 5000 | ||
CHASSIS_MODULE_SET_ADMIN_STATE = '/usr/local/bin/chassis_module_set_admin_state.py' | ||
|
||
def main(): | ||
logger = Logger(SYSLOG_IDENTIFIER) | ||
logger.set_min_log_priority_info() | ||
|
||
# dict | ||
current_module_state = dict() | ||
|
||
# Connect to STATE_DB and subscribe to chassis-module table notifications | ||
cfg_db = daemon_base.db_connect("CONFIG_DB") | ||
|
||
sel = swsscommon.Select() | ||
sst = swsscommon.SubscriberStateTable(cfg_db, CHASSIS_MODULE) | ||
sel.addSelectable(sst) | ||
|
||
while True: | ||
(state, c) = sel.select(SELECT_TIMEOUT_MSECS) | ||
if state == swsscommon.Select.TIMEOUT: | ||
continue | ||
|
||
(module_name, module_op, module_fvp) = sst.pop() | ||
|
||
state = current_module_state.get(module_name) | ||
module_fvs = dict(module_fvp) | ||
new_state = module_fvs.get('admin_status') | ||
|
||
if module_op == 'SET': | ||
if new_state is None: | ||
continue | ||
|
||
if state != new_state: | ||
if new_state == "down": | ||
current_module_state[module_name] = "down" | ||
else: | ||
current_module_state.pop(module_name, None) | ||
|
||
if os.path.exists(CHASSIS_MODULE_SET_ADMIN_STATE): | ||
subprocess.run(['python3', CHASSIS_MODULE_SET_ADMIN_STATE, module_name, new_state]) | ||
else: | ||
logger.log_error("{} doesn't exist.".format(CHASSIS_MODULE_SET_ADMIN_STATE)) | ||
|
||
elif module_op == 'DEL': | ||
if new_state is None: | ||
new_state = 'up' | ||
|
||
if state != new_state: | ||
if new_state == "up": | ||
current_module_state[module_name] = "up" | ||
else: | ||
current_module_state.pop(module_name, None) | ||
|
||
if os.path.exists(CHASSIS_MODULE_SET_ADMIN_STATE): | ||
subprocess.run(['python3', CHASSIS_MODULE_SET_ADMIN_STATE, module_name, new_state]) | ||
else: | ||
logger.log_error("{} doesn't exist.".format(CHASSIS_MODULE_SET_ADMIN_STATE)) | ||
|
||
if __name__ == "__main__": | ||
main() |