Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions files/scripts/swss.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ function clean_up_chassis_db_tables()
{

switch_type=`$SONIC_DB_CLI CONFIG_DB hget 'DEVICE_METADATA|localhost' 'switch_type'`
platform=`$SONIC_DB_CLI CONFIG_DB hget 'DEVICE_METADATA|localhost' 'platform'`
chassis_config="/usr/share/sonic/device/$platform/chassisdb.conf"
if [ ! -e $chassis_config ]; then
debug "No chassis config found"
return
fi

# Run clean up only in swss running for voq switches
if is_chassis_supervisor || [[ $switch_type != 'voq' ]]; then
Expand Down
36 changes: 35 additions & 1 deletion src/sonic-py-common/sonic_py_common/device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
NAMESPACE_PATH_GLOB = "/run/netns/*"
ASIC_CONF_FILENAME = "asic.conf"
PLATFORM_ENV_CONF_FILENAME = "platform_env.conf"
CHASSIS_DB_CONF_FILENAME = "chassisdb.conf"
FRONTEND_ASIC_SUB_ROLE = "FrontEnd"
BACKEND_ASIC_SUB_ROLE = "BackEnd"
VS_PLATFORM = "x86_64-kvm_x86_64-r0"
Expand Down Expand Up @@ -243,6 +244,29 @@ def get_platform_env_conf_file_path():
return None


def get_chassis_db_conf_file_path():
"""
Retrieves the path to the Chassis DB configuration file on the device

Returns:
A string containing the path to the Chassis DB configuration file on success,
None on failure
"""
chassis_db_conf_path_candidates = []

chassis_db_conf_path_candidates.append(os.path.join(CONTAINER_PLATFORM_PATH, CHASSIS_DB_CONF_FILENAME))

platform = get_platform()
if platform:
chassis_db_conf_path_candidates.append(os.path.join(HOST_DEVICE_PATH, platform, CHASSIS_DB_CONF_FILENAME))

for chassis_db_conf_file_path in chassis_db_conf_path_candidates:
if os.path.isfile(chassis_db_conf_file_path):
return chassis_db_conf_file_path

return None


def get_path_to_platform_dir():
"""
Retreives the paths to the device's platform directory
Expand Down Expand Up @@ -590,9 +614,19 @@ def is_multi_npu():
return (num_npus > 1)


def is_single_voq():
chassis_db_conf_file_path = get_chassis_db_conf_file_path()
if chassis_db_conf_file_path is None:
return True

return False


def is_voq_chassis():
switch_type = get_platform_info().get('switch_type')
return True if switch_type and (switch_type == 'voq' or switch_type == 'fabric') else False
single_voq = is_single_voq()

return bool(switch_type and (switch_type == 'voq' or switch_type == 'fabric') and not single_voq)


def is_packet_chassis():
Expand Down
16 changes: 15 additions & 1 deletion src/sonic-py-common/tests/device_info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,43 +120,57 @@ def test_get_sonic_version(self, mock_isfile):
# Assert the file was read only once
open_mocked.assert_called_once_with(device_info.SONIC_VERSION_YAML_PATH)

@mock.patch("sonic_py_common.device_info.is_single_voq")
@mock.patch("sonic_py_common.device_info.get_platform_info")
@mock.patch("sonic_py_common.device_info.is_disaggregated_chassis")
def test_is_chassis(self, mock_is_disaggregated_chassis, mock_platform_info):
def test_is_chassis(self, mock_is_disaggregated_chassis, mock_platform_info, mock_is_single_voq):
mock_platform_info.return_value = {"switch_type": "npu"}
mock_is_disaggregated_chassis.return_value = False
mock_is_single_voq.return_value = False
assert device_info.is_chassis() == False
assert device_info.is_voq_chassis() == False
assert device_info.is_packet_chassis() == False

mock_platform_info.return_value = {"switch_type": "voq"}
mock_is_disaggregated_chassis.return_value = False
mock_is_single_voq.return_value = False
assert device_info.is_voq_chassis() == True
assert device_info.is_packet_chassis() == False
assert device_info.is_chassis() == True

mock_platform_info.return_value = {"switch_type": "voq"}
mock_is_disaggregated_chassis.return_value = True
mock_is_single_voq.return_value = False
assert device_info.is_voq_chassis() == True
assert device_info.is_packet_chassis() == False
assert device_info.is_chassis() == False

mock_platform_info.return_value = {"switch_type": "voq"}
mock_is_disaggregated_chassis.return_value = False
mock_is_single_voq.return_value = True
assert device_info.is_voq_chassis() == False
assert device_info.is_packet_chassis() == False
assert device_info.is_chassis() == False

mock_platform_info.return_value = {"switch_type": "chassis-packet"}
mock_is_disaggregated_chassis.return_value = False
mock_is_single_voq.return_value = False
assert device_info.is_voq_chassis() == False
assert device_info.is_packet_chassis() == True
assert device_info.is_chassis() == True

mock_platform_info.return_value = {"switch_type": "dummy-sup",
"asic_type": "vs"}
mock_is_disaggregated_chassis.return_value = False
mock_is_single_voq.return_value = False
assert device_info.is_voq_chassis() == False
assert device_info.is_packet_chassis() == False
assert device_info.is_virtual_chassis() == True
assert device_info.is_chassis() == True

mock_platform_info.return_value = {}
mock_is_disaggregated_chassis.return_value = False
mock_is_single_voq.return_value = False
assert device_info.is_voq_chassis() == False
assert device_info.is_packet_chassis() == False
assert device_info.is_chassis() == False
Expand Down
Loading