Skip to content

Commit 3c34c14

Browse files
committed
Moved function to multi_aisc.py
Added more comments. Signed-off-by: anamehra <[email protected]>
1 parent 579ca2b commit 3c34c14

File tree

2 files changed

+38
-30
lines changed

2 files changed

+38
-30
lines changed

files/image_config/monit/container_checker

+7-29
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,9 @@ import docker
2020
import sys
2121

2222
import swsssdk
23-
from sonic_py_common import multi_asic, device_info, daemon_base
23+
from sonic_py_common import multi_asic, device_info
2424
from swsscommon import swsscommon
2525

26-
def get_asic_presence_list():
27-
"""
28-
@summary: This function will get the asic presence list. On Supervisor, the list includes only the asics
29-
for inserted and detected fabric cards. For non-supervisor cards, e.g. line card, the list should
30-
contain all supported asics by the card. The function gets the asic list from CHASSIS_ASIC_TABLE from
31-
CHASSIS_STATE_DB. The function assumes that the first N asic ids (asic0 to asic(N-1)) in
32-
CHASSIS_ASIC_TABLE belongs to the supervisor, where N is the max number of asics supported by the Chassis
33-
@return: List of asics present
34-
"""
35-
asics_list = []
36-
if multi_asic.is_multi_asic():
37-
if not device_info.is_supervisor():
38-
# Supervisor has FRU Fabric cards. If not supervisor, all asics
39-
# should be present. Add all asics, 0 - num_asics to the list.
40-
asics_list = list(range(0,multi_asic.get_num_asics()))
41-
else:
42-
# Get asic list from CHASSIS_ASIC_TABLE
43-
chassis_state_db = daemon_base.db_connect("CHASSIS_STATE_DB")
44-
asic_table = swsscommon.Table(chassis_state_db, 'CHASSIS_ASIC_TABLE')
45-
if asic_table:
46-
asics_presence_list = list(asic_table.getKeys())
47-
for asic in asics_presence_list:
48-
# asic is asid id: asic0, asic1.... asicN. Get the numeric value.
49-
asics_list.append(int(asic[4:]))
50-
return asics_list
51-
5226
def get_expected_running_containers():
5327
"""
5428
@summary: This function will get the expected running & always-enabled containers by following the rule:
@@ -69,10 +43,14 @@ def get_expected_running_containers():
6943

7044
# Get current asic presence list. For multi_asic system, multi instance containers
7145
# should be checked only for asics present.
72-
asics_id_presence = get_asic_presence_list()
46+
asics_id_presence = multi_asic.get_asic_presence_list()
7347

74-
# Some services, like database and bgp run all the instances irrespective of asic presence.
48+
# Some services may run all the instances irrespective of asic presence.
7549
# Add those to exception list.
50+
# database service: Currently services have dependency on all database services to
51+
# be up irrespective of asic presence.
52+
# bgp service: Currently bgp runs all instances. Once this is fixed to be config driven,
53+
# it will be removed from exception list.
7654
run_all_instance_list = ['database', 'bgp']
7755

7856
for container_name in feature_table.keys():

src/sonic-py-common/sonic_py_common/multi_asic.py

+31-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from natsort import natsorted
66
from swsscommon import swsscommon
7+
from sonic_py_common import daemon_base
78

89
from .device_info import CONTAINER_PLATFORM_PATH
910
from .device_info import HOST_DEVICE_PATH
@@ -25,7 +26,8 @@
2526
NEIGH_DEVICE_METADATA_CFG_DB_TABLE = 'DEVICE_NEIGHBOR_METADATA'
2627
DEFAULT_NAMESPACE = ''
2728
PORT_ROLE = 'role'
28-
29+
CHASSIS_STATE_DB='CHASSIS_STATE_DB'
30+
CHASSIS_ASIC_INFO_TABLE='CHASSIS_ASIC_TABLE'
2931

3032
# Dictionary to cache config_db connection handle per namespace
3133
# to prevent duplicate connections from being opened
@@ -480,3 +482,31 @@ def validate_namespace(namespace):
480482
return True
481483
else:
482484
return False
485+
486+
def get_asic_presence_list():
487+
"""
488+
@summary: This function will get the asic presence list. On Supervisor, the list includes only the asics
489+
for inserted and detected fabric cards. For non-supervisor cards, e.g. line card, the list should
490+
contain all supported asics by the card. The function gets the asic list from CHASSIS_ASIC_TABLE from
491+
CHASSIS_STATE_DB. The function assumes that the first N asic ids (asic0 to asic(N-1)) in
492+
CHASSIS_ASIC_TABLE belongs to the supervisor, where N is the max number of asics supported by the Chassis
493+
@return: List of asics present
494+
"""
495+
asics_list = []
496+
if is_multi_asic():
497+
if not is_supervisor():
498+
# This is not supervisor, all asics should be present. Assuming that asics
499+
# are not removable entity on Line Cards. Add all asics, 0 - num_asics to the list.
500+
asics_list = list(range(0,get_num_asics()))
501+
else:
502+
# This is supervisor card. Some fabric cards may not be inserted.
503+
# Get asic list from CHASSIS_ASIC_TABLE which lists only the asics
504+
# present based on Fabric card detection by the platform.
505+
db = daemon_base.db_connect(CHASSIS_STATE_DB)
506+
asic_table = swsscommon.Table(db,CHASSIS_ASIC_INFO_TABLE)
507+
if asic_table:
508+
asics_presence_list = list(asic_table.getKeys())
509+
for asic in asics_presence_list:
510+
# asic is asid id: asic0, asic1.... asicN. Get the numeric value.
511+
asics_list.append(int(asic[4:]))
512+
return asics_list

0 commit comments

Comments
 (0)