Skip to content

Commit

Permalink
Addressed default dpu admin status for dark-mode and seamless migration
Browse files Browse the repository at this point in the history
to lightup mode
  • Loading branch information
rameshraghupathy committed Oct 29, 2024
1 parent 9a0225b commit 8f191d6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 26 deletions.
13 changes: 11 additions & 2 deletions config/chassis_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import subprocess
import utilities_common.cli as clicommon
from utilities_common.chassis import is_smartswitch

TIMEOUT_SECS = 10

Expand All @@ -27,7 +28,10 @@ def get_config_module_state(db, chassis_module_name):
config_db = db.cfgdb
fvs = config_db.get_entry('CHASSIS_MODULE', chassis_module_name)
if not fvs:
return 'up'
if is_smartswitch:
return 'down'
else:
return 'up'
else:
return fvs['admin_status']

Expand Down Expand Up @@ -143,7 +147,12 @@ def startup_chassis_module(db, chassis_module_name):
return

click.echo("Starting up chassis module {}".format(chassis_module_name))
config_db.set_entry('CHASSIS_MODULE', chassis_module_name, None)
if is_smartswitch:
fvs = {'admin_status': 'up'}
config_db.set_entry('CHASSIS_MODULE', chassis_module_name, fvs)
else:
config_db.set_entry('CHASSIS_MODULE', chassis_module_name, None)

if chassis_module_name.startswith("FABRIC-CARD"):
if not check_config_module_state_with_timeout(ctx, db, chassis_module_name, 'up'):
fabric_module_set_admin_status(db, chassis_module_name, 'up')
6 changes: 5 additions & 1 deletion show/chassis_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from natsort import natsorted
from tabulate import tabulate
from swsscommon.swsscommon import SonicV2Connector
from utilities_common.chassis import is_smartswitch

import utilities_common.cli as clicommon
from sonic_py_common import multi_asic
Expand Down Expand Up @@ -62,7 +63,10 @@ def status(db, chassis_module_name):
oper_status = data_dict[CHASSIS_MODULE_INFO_OPERSTATUS_FIELD]
serial = data_dict[CHASSIS_MODULE_INFO_SERIAL_FIELD]

admin_status = 'up'
if is_smartswitch:
admin_status = 'down'
else:
admin_status = 'up'
config_data = chassis_cfg_table.get(key_list[1])
if config_data is not None:
admin_status = config_data.get(CHASSIS_MODULE_INFO_ADMINSTATUS_FIELD)
Expand Down
45 changes: 29 additions & 16 deletions show/reboot_cause.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from swsscommon.swsscommon import SonicV2Connector
from sonic_py_common import device_info
import utilities_common.cli as clicommon
from utilities_common.chassis import is_smartswitch


PREVIOUS_REBOOT_CAUSE_FILE_PATH = "/host/reboot-cause/previous-reboot-cause.json"
Expand All @@ -25,7 +26,7 @@ def read_reboot_cause_file():


# Function to fetch reboot cause data from database
def fetch_data_from_db(module_name, fetch_history=False):
def fetch_data_from_db(module_name, fetch_history=False, use_chassis_db=False):
if module_name is None:
prefix = 'REBOOT_CAUSE|2'
elif "DPU" in module_name:
Expand All @@ -34,9 +35,14 @@ def fetch_data_from_db(module_name, fetch_history=False):
prefix = 'REBOOT_CAUSE|'

try:
rdb = SonicV2Connector(host='127.0.0.1')
rdb.connect(rdb.STATE_DB, False) # Make one attempt only
table_keys = rdb.keys(rdb.STATE_DB, prefix+'*')
if use_chassis_db:
rdb = SonicV2Connector(host='redis_chassis.server', port=6380)
rdb.connect(rdb.CHASSIS_STATE_DB)
table_keys = rdb.keys(rdb.CHASSIS_STATE_DB, prefix+'*')
else:
rdb = SonicV2Connector(host='127.0.0.1')
rdb.connect(rdb.STATE_DB, False) # Make one attempt only
table_keys = rdb.keys(rdb.STATE_DB, prefix+'*')
except Exception:
return []

Expand All @@ -48,7 +54,10 @@ def fetch_data_from_db(module_name, fetch_history=False):
for tk in table_keys:
r = []
append = False
entry = rdb.get_all(rdb.STATE_DB, tk)
if use_chassis_db:
entry = rdb.get_all(rdb.CHASSIS_STATE_DB, tk)
else:
entry = rdb.get_all(rdb.STATE_DB, tk)

if module_name is not None:
if 'device' in entry:
Expand Down Expand Up @@ -100,13 +109,21 @@ def fetch_reboot_cause_from_db(module_name):
r.append(reboot_user if reboot_user else "")
table.append(r)

table += fetch_data_from_db(module_name, fetch_history=False)
table += fetch_data_from_db(module_name, fetch_history=False, use_chassis_db=True)
return table


# Function to fetch reboot cause history data from database
def fetch_reboot_cause_history_from_db(module_name):
return fetch_data_from_db(module_name, fetch_history=True)
if module_name == "all":
# Combine data from both Redis containers for "all" modules
data_switch = fetch_data_from_db(module_name, fetch_history=True, use_chassis_db=False)
data_dpu = fetch_data_from_db(module_name, fetch_history=True, use_chassis_db=True)
return data_switch + data_dpu
elif module_name is None or module_name == "SWITCH":
return fetch_data_from_db(module_name, fetch_history=True, use_chassis_db=False)
else:
return fetch_data_from_db(module_name, fetch_history=True, use_chassis_db=True)

#
# 'reboot-cause' group ("show reboot-cause")
Expand Down Expand Up @@ -146,14 +163,10 @@ def reboot_cause(ctx):
click.echo(reboot_cause_str)


def is_smartswitch():
return hasattr(device_info, 'is_smartswitch') and device_info.is_smartswitch()


# 'all' command within 'reboot-cause'
@reboot_cause.command()
def all():
if not is_smartswitch():
if not is_smartswitch:
return
"""Show cause of most recent reboot"""
reboot_cause_data = fetch_reboot_cause_from_db("all")
Expand All @@ -166,7 +179,7 @@ def all():
def get_all_dpus():
dpu_list = []

if not is_smartswitch():
if not is_smartswitch:
return dpu_list

# Load platform.json
Expand Down Expand Up @@ -199,14 +212,14 @@ def get_all_dpus():
@click.argument(
'module_name',
required=False,
type=click.Choice(get_all_dpus(), case_sensitive=False) if is_smartswitch() else None
type=click.Choice(get_all_dpus(), case_sensitive=False) if is_smartswitch else None
)
def history(module_name=None):
"""Show history of reboot-cause"""
if not is_smartswitch() and module_name:
if not is_smartswitch and module_name:
return
reboot_cause_history = fetch_reboot_cause_history_from_db(module_name)
if is_smartswitch() and module_name:
if is_smartswitch and module_name:
header = ['Device', 'Name', 'Cause', 'Time', 'User', 'Comment']
else:
header = ['Name', 'Cause', 'Time', 'User', 'Comment']
Expand Down
11 changes: 4 additions & 7 deletions show/system_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from swsscommon.swsscommon import SonicV2Connector
from natsort import natsorted
from sonic_py_common import device_info
from utilities_common.chassis import is_smartswitch

DPU_STATE = 'DPU_STATE'
CHASSIS_SERVER = 'redis_chassis.server'
Expand Down Expand Up @@ -170,10 +171,6 @@ def sysready_status_detail():
click.echo("Exception: {}".format(str(e)))


def is_smartswitch():
return hasattr(device_info, 'is_smartswitch') and device_info.is_smartswitch()


def show_dpu_state(module_name):
chassis_state_db = SonicV2Connector(host=CHASSIS_SERVER, port=CHASSIS_SERVER_PORT)
chassis_state_db.connect(chassis_state_db.CHASSIS_STATE_DB)
Expand Down Expand Up @@ -244,7 +241,7 @@ def populate_row(row, key, value, table):
def get_all_dpus():
dpu_list = []

if not is_smartswitch():
if not is_smartswitch:
return dpu_list

# Load platform.json
Expand Down Expand Up @@ -275,10 +272,10 @@ def get_all_dpus():
@system_health.command()
@click.argument('module_name',
required=True,
type=click.Choice(get_all_dpus(), case_sensitive=False) if is_smartswitch() else None
type=click.Choice(get_all_dpus(), case_sensitive=False) if is_smartswitch else None
)
def dpu(module_name):
"""Show system-health dpu information"""
if not is_smartswitch():
if not is_smartswitch:
return
show_dpu_state(module_name)
3 changes: 3 additions & 0 deletions utilities_common/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ def get_chassis_local_interfaces():
lst = data[1].split(",")
return lst
return lst

def is_smartswitch():
return hasattr(device_info, 'is_smartswitch') and device_info.is_smartswitch()

0 comments on commit 8f191d6

Please sign in to comment.