Skip to content

Commit 8e234f0

Browse files
committed
Update for the procedures for insertion/hot swap of Switch Fabric Module(SFM) by using "config chassis modules shutdown/startup" commands
1 parent 2ac9986 commit 8e234f0

File tree

2 files changed

+119
-2
lines changed

2 files changed

+119
-2
lines changed

config/chassis_modules.py

100644100755
Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/sbin/env python
22

33
import click
4-
4+
import time
55
import utilities_common.cli as clicommon
6+
from .fabric_module_set_admin_status import fabric_module_set_admin_status
67

78
#
89
# 'chassis_modules' group ('config chassis_modules ...')
@@ -17,6 +18,26 @@ def modules():
1718
"""Configure chassis modules"""
1819
pass
1920

21+
def get_config_module_state(db, chassis_module_name):
22+
config_db = db.cfgdb
23+
fvs = config_db.get_entry('CHASSIS_MODULE', chassis_module_name)
24+
return fvs['admin_status']
25+
26+
TIMEOUT_SECS = 10
27+
28+
# Name: get_config_module_state_timeout
29+
# return: True: timeout, False: not timeout
30+
def get_config_module_state_timeout(ctx, db, chassis_module_name, state):
31+
counter = 0
32+
while get_config_module_state(db, chassis_module_name) != state:
33+
time.sleep(1)
34+
counter += 1
35+
if counter >= TIMEOUT_SECS:
36+
ctx.fail("get_config_module_state {} timeout".format(chassis_module_name))
37+
return True
38+
break
39+
return False
40+
2041
#
2142
# 'shutdown' subcommand ('config chassis_modules shutdown ...')
2243
#
@@ -36,6 +57,9 @@ def shutdown_chassis_module(db, chassis_module_name):
3657
fvs = {'admin_status': 'down'}
3758
config_db.set_entry('CHASSIS_MODULE', chassis_module_name, fvs)
3859

60+
if not get_config_module_state_timeout(ctx, db, chassis_module_name, 'down'):
61+
fabric_module_set_admin_status(chassis_module_name, 'down')
62+
3963
#
4064
# 'startup' subcommand ('config chassis_modules startup ...')
4165
#
@@ -45,5 +69,9 @@ def shutdown_chassis_module(db, chassis_module_name):
4569
def startup_chassis_module(db, chassis_module_name):
4670
"""Chassis-module startup of module"""
4771
config_db = db.cfgdb
48-
72+
ctx = click.get_current_context()
73+
4974
config_db.set_entry('CHASSIS_MODULE', chassis_module_name, None)
75+
76+
if not get_config_module_state_timeout(ctx, db, chassis_module_name, 'up'):
77+
fabric_module_set_admin_status(chassis_module_name, 'up')
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright (c) 2024, Nokia
4+
# All rights reserved.
5+
6+
import re
7+
import subprocess
8+
import time
9+
from swsscommon.swsscommon import SonicV2Connector
10+
from sonic_py_common.logger import Logger
11+
from platform_ndk import nokia_common
12+
13+
sfm_hw_slot_mapping = {
14+
0: 15,
15+
1: 16,
16+
2: 17,
17+
3: 18,
18+
4: 19,
19+
5: 20,
20+
6: 21,
21+
7: 22
22+
}
23+
24+
# Name: fabric_module_set_admin_status.py, version: 1.0
25+
# Syntax: fabric_module_set_admin_status <module_name> <up/down>
26+
def fabric_module_set_admin_status(module, state):
27+
logger = Logger("fabric_module_set_admin_status.py")
28+
logger.set_min_log_priority_info()
29+
30+
if not module.startswith("FABRIC-CARD"):
31+
logger.log_warning("Failed to set {} state. Admin state can only be set on Fabric module.".format(module))
32+
return
33+
34+
if (state != "up" and state != "down"):
35+
logger.log_warning("Failed to set {}. Admin state can only be set to up or down.".format(state))
36+
return
37+
38+
num = int(re.search(r"(\d+)$", module).group())
39+
chassisdb = SonicV2Connector(host="127.0.0.1")
40+
chassisdb.connect("CHASSIS_STATE_DB")
41+
42+
if state == "down":
43+
services_list = chassisdb.keys("CHASSIS_STATE_DB", "CHASSIS_FABRIC_ASIC_TABLE*")
44+
asic_list = []
45+
for service in services_list:
46+
name = chassisdb.get("CHASSIS_STATE_DB",service,"name")
47+
if name == module:
48+
asic_id = int(re.search(r"(\d+)$", service).group())
49+
asic_list.append(asic_id)
50+
51+
logger.log_info("Shutting down chassis module {}".format(module))
52+
53+
for asic in asic_list:
54+
logger.log_info("Stopping swss@{} and syncd@{} ...".format(asic, asic))
55+
process = subprocess.Popen(['sudo', 'systemctl', 'stop', 'swss@{}.service'.format(asic)],
56+
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
57+
stdout, stderr = process.communicate()
58+
outstr = stdout.decode('ascii')
59+
# wait for service is down
60+
time.sleep(2)
61+
62+
logger.log_info("Power off {} module ...".format(module))
63+
hw_slot = sfm_hw_slot_mapping[num]
64+
nokia_common._power_onoff_SFM(hw_slot,False)
65+
logger.log_info("Chassis module {} shutdown completed".format(module))
66+
else:
67+
logger.log_info("Starting up chassis module {}".format(module))
68+
hw_slot = sfm_hw_slot_mapping[num]
69+
nokia_common._power_onoff_SFM(hw_slot,True)
70+
# wait SFM HW init done.
71+
time.sleep(15)
72+
73+
services_list = chassisdb.keys("CHASSIS_STATE_DB", "CHASSIS_FABRIC_ASIC_TABLE*")
74+
asic_list = []
75+
for service in services_list:
76+
name = chassisdb.get("CHASSIS_STATE_DB",service,"name")
77+
if name == module:
78+
asic_id = int(re.search(r"(\d+)$", service).group())
79+
asic_list.append(asic_id)
80+
81+
for asic in asic_list:
82+
logger.log_info("Start swss@{} and syncd@{} ...".format(asic, asic))
83+
# Process state
84+
process = subprocess.Popen(['sudo', 'systemctl', 'start', 'swss@{}.service'.format(asic)],
85+
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
86+
stdout, stderr = process.communicate()
87+
outstr = stdout.decode('ascii')
88+
logger.log_info("Chassis module {} startup completed".format(module))
89+
return

0 commit comments

Comments
 (0)