Skip to content

Commit

Permalink
Update for the Procedures for insertion/hot swap of Switch Fabric Mod…
Browse files Browse the repository at this point in the history
…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
JunhongMao committed Apr 5, 2024
1 parent be01b37 commit 875f99f
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
18 changes: 18 additions & 0 deletions files/build_templates/chassis-module.service
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
1 change: 1 addition & 0 deletions files/build_templates/sonic_debian_extension.j2
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,7 @@ sudo LANG=C cp $SCRIPTS_DIR/gnmi.sh $FILESYSTEM_ROOT/usr/local/bin/gnmi.sh
sudo LANG=C cp $SCRIPTS_DIR/mgmt-framework.sh $FILESYSTEM_ROOT/usr/local/bin/mgmt-framework.sh
sudo LANG=C cp $SCRIPTS_DIR/asic_status.sh $FILESYSTEM_ROOT/usr/local/bin/asic_status.sh
sudo LANG=C cp $SCRIPTS_DIR/asic_status.py $FILESYSTEM_ROOT/usr/local/bin/asic_status.py
sudo LANG=C cp $SCRIPTS_DIR/chassis_module_config.py $FILESYSTEM_ROOT/usr/local/bin/chassis_module_config.py

# Copy sonic-netns-exec script
sudo LANG=C cp $SCRIPTS_DIR/sonic-netns-exec $FILESYSTEM_ROOT/usr/bin/sonic-netns-exec
Expand Down
80 changes: 80 additions & 0 deletions files/scripts/chassis_module_config.py
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()

0 comments on commit 875f99f

Please sign in to comment.