diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index 4e1dc32872..7d6cff9519 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -240,12 +240,19 @@ 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'` # Run clean up only in swss running for voq switches if is_chassis_supervisor || [[ $switch_type != 'voq' ]]; then return fi + chassis_config="/usr/share/sonic/device/$platform/chassisdb.conf" + if [ ! -e $chassis_config ]; then + debug "No chassis config found" + return + fi + until [[ $($SONIC_DB_CLI CHASSIS_APP_DB PING | grep -c True) -gt 0 ]]; do sleep 1 done diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index 47409eb18c..89848e9027 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -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" @@ -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 @@ -590,9 +614,19 @@ def is_multi_npu(): return (num_npus > 1) +def is_chassis_config_absent(): + 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_chassis_config_absent() + + return bool(switch_type and (switch_type == 'voq' or switch_type == 'fabric') and not single_voq) def is_packet_chassis(): diff --git a/src/sonic-py-common/tests/device_info_test.py b/src/sonic-py-common/tests/device_info_test.py index 8dc4f0c51d..de3a618efc 100644 --- a/src/sonic-py-common/tests/device_info_test.py +++ b/src/sonic-py-common/tests/device_info_test.py @@ -120,29 +120,41 @@ 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_chassis_config_absent") @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_chassis_config_absent): mock_platform_info.return_value = {"switch_type": "npu"} mock_is_disaggregated_chassis.return_value = False + mock_is_chassis_config_absent.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_chassis_config_absent.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_chassis_config_absent.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_chassis_config_absent.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_chassis_config_absent.return_value = False assert device_info.is_voq_chassis() == False assert device_info.is_packet_chassis() == True assert device_info.is_chassis() == True @@ -150,6 +162,7 @@ def test_is_chassis(self, mock_is_disaggregated_chassis, mock_platform_info): mock_platform_info.return_value = {"switch_type": "dummy-sup", "asic_type": "vs"} mock_is_disaggregated_chassis.return_value = False + mock_is_chassis_config_absent.return_value = False assert device_info.is_voq_chassis() == False assert device_info.is_packet_chassis() == False assert device_info.is_virtual_chassis() == True @@ -157,6 +170,7 @@ def test_is_chassis(self, mock_is_disaggregated_chassis, mock_platform_info): mock_platform_info.return_value = {} mock_is_disaggregated_chassis.return_value = False + mock_is_chassis_config_absent.return_value = False assert device_info.is_voq_chassis() == False assert device_info.is_packet_chassis() == False assert device_info.is_chassis() == False