From 4047bf170ee97fca70e5455e9ad47aa55e9f5b9c Mon Sep 17 00:00:00 2001 From: vedganes Date: Mon, 5 Jul 2021 14:54:34 -0400 Subject: [PATCH 1/2] [multi-asic][cli][chassis-db] Avoiding connecting to chassis db Currently, for all the cli commands, we connect to all databases mentioned in the database_config.json. The database_config.json also includes the databases from chassis redis server from supervisor card. It is unneccessary to connect to databases from chassis redis server when cli commands are executed form linecard. But we need to allow connection to chassis databases when the cli commands are executed from supervisor card. The changes in this PR fixes this problem. This PR requires that asic.conf in supervisor card includes VOQ_SUPERVISOR with value 1 to indentify the supervisor card. The connect_to_all_dbs_for_ns() is changed to skip chassis databases form the list of collected databases if the card is not supervisor card. Signed-off-by: vedganes --- .../sonic_py_common/device_info.py | 16 ++++++++++++++++ .../sonic_py_common/multi_asic.py | 17 +++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) 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 4d1df635228..cdda1feee6f 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -374,6 +374,22 @@ def is_multi_npu(): return (num_npus > 1) +def is_voq_supervisor(): + asic_conf_file_path = get_asic_conf_file_path() + if asic_conf_file_path is None: + return False + with open(asic_conf_file_path) as asic_conf_file: + for line in asic_conf_file: + tokens = line.split('=') + if len(tokens) < 2: + continue + if tokens[0].lower() == 'voq_supervisor': + val = tokens[1].strip() + if val == '1': + return True + return False + + def get_npu_id_from_name(npu_name): if npu_name.startswith(NPU_NAME_PREFIX): return npu_name[len(NPU_NAME_PREFIX):] diff --git a/src/sonic-py-common/sonic_py_common/multi_asic.py b/src/sonic-py-common/sonic_py_common/multi_asic.py index f6daba8e84a..db9859cfa55 100644 --- a/src/sonic-py-common/sonic_py_common/multi_asic.py +++ b/src/sonic-py-common/sonic_py_common/multi_asic.py @@ -8,6 +8,7 @@ from .device_info import CONTAINER_PLATFORM_PATH from .device_info import HOST_DEVICE_PATH from .device_info import get_platform +from .device_info import is_voq_supervisor ASIC_NAME_PREFIX = 'asic' NAMESPACE_PATH_GLOB = '/run/netns/*' @@ -45,7 +46,11 @@ def connect_config_db_for_ns(namespace=DEFAULT_NAMESPACE): def connect_to_all_dbs_for_ns(namespace=DEFAULT_NAMESPACE): """ The function connects to the DBs for a given namespace and - returns the handle + returns the handle + + For voq chassis systems, the db list includes databases from + supervisor card. Avoid connecting to these databases from linecards + If no namespace is provided, it will connect to the db in the default namespace. In case of multi ASIC, the default namespace is the @@ -56,7 +61,15 @@ def connect_to_all_dbs_for_ns(namespace=DEFAULT_NAMESPACE): handle to all the dbs for a namespaces """ db = swsscommon.SonicV2Connector(namespace=namespace) - for db_id in db.get_db_list(): + db_list = list(db.get_db_list()) + if not is_voq_supervisor(): + try: + db_list.remove('CHASSIS_APP_DB') + db_list.remove('CHASSIS_STATE_DB') + except Exception: + pass + + for db_id in db_list: db.connect(db_id) return db From 11ac31c266dcc6ef562e7d8a89008b8cee31e6d9 Mon Sep 17 00:00:00 2001 From: vedganes Date: Tue, 27 Jul 2021 11:04:55 -0400 Subject: [PATCH 2/2] [multi-asic][cli][chassis-db] Review comments fix 1 - is_voq_supervisor() renamed to is_supervisor() since this API is applicable to non VOQ chassis also - Determination of supervisor card type is done using "supervisor" variable from platfrom_env.conf instead of from asic.conf - Removed changes unrelated to this fix. Signed-off-by: vedganes --- .../sonic_py_common/device_info.py | 36 +++++++++++++++---- .../sonic_py_common/multi_asic.py | 4 +-- 2 files changed, 32 insertions(+), 8 deletions(-) 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 cdda1feee6f..0b58a4231a6 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -29,6 +29,7 @@ NPU_NAME_PREFIX = "asic" NAMESPACE_PATH_GLOB = "/run/netns/*" ASIC_CONF_FILENAME = "asic.conf" +PLATFORM_ENV_CONF_FILENAME = "platform_env.conf" FRONTEND_ASIC_SUB_ROLE = "FrontEnd" BACKEND_ASIC_SUB_ROLE = "BackEnd" @@ -164,6 +165,29 @@ def get_asic_conf_file_path(): return None +def get_platform_env_conf_file_path(): + """ + Retrieves the path to the PLATFORM ENV conguration file on the device + + Returns: + A string containing the path to the PLATFORM ENV conguration file on success, + None on failure + """ + platform_env_conf_path_candidates = [] + + platform_env_conf_path_candidates.append(os.path.join(CONTAINER_PLATFORM_PATH, PLATFORM_ENV_CONF_FILENAME)) + + platform = get_platform() + if platform: + platform_env_conf_path_candidates.append(os.path.join(HOST_DEVICE_PATH, platform, PLATFORM_ENV_CONF_FILENAME)) + + for platform_env_conf_file_path in platform_env_conf_path_candidates: + if os.path.isfile(platform_env_conf_file_path): + return platform_env_conf_file_path + + return None + + def get_path_to_platform_dir(): """ Retreives the paths to the device's platform directory @@ -374,16 +398,16 @@ def is_multi_npu(): return (num_npus > 1) -def is_voq_supervisor(): - asic_conf_file_path = get_asic_conf_file_path() - if asic_conf_file_path is None: +def is_supervisor(): + platform_env_conf_file_path = get_platform_env_conf_file_path() + if platform_env_conf_file_path is None: return False - with open(asic_conf_file_path) as asic_conf_file: - for line in asic_conf_file: + with open(platform_env_conf_file_path) as platform_env_conf_file: + for line in platform_env_conf_file: tokens = line.split('=') if len(tokens) < 2: continue - if tokens[0].lower() == 'voq_supervisor': + if tokens[0].lower() == 'supervisor': val = tokens[1].strip() if val == '1': return True diff --git a/src/sonic-py-common/sonic_py_common/multi_asic.py b/src/sonic-py-common/sonic_py_common/multi_asic.py index db9859cfa55..a5b5d48bab2 100644 --- a/src/sonic-py-common/sonic_py_common/multi_asic.py +++ b/src/sonic-py-common/sonic_py_common/multi_asic.py @@ -8,7 +8,7 @@ from .device_info import CONTAINER_PLATFORM_PATH from .device_info import HOST_DEVICE_PATH from .device_info import get_platform -from .device_info import is_voq_supervisor +from .device_info import is_supervisor ASIC_NAME_PREFIX = 'asic' NAMESPACE_PATH_GLOB = '/run/netns/*' @@ -62,7 +62,7 @@ def connect_to_all_dbs_for_ns(namespace=DEFAULT_NAMESPACE): """ db = swsscommon.SonicV2Connector(namespace=namespace) db_list = list(db.get_db_list()) - if not is_voq_supervisor(): + if not is_supervisor(): try: db_list.remove('CHASSIS_APP_DB') db_list.remove('CHASSIS_STATE_DB')