Skip to content

Commit 579ca2b

Browse files
authored
container_checker on RP should check containers based on asic presence
On Supervisor/RP card, some application containers may not run if the asic is not present due to a missing Fabric card. The container checker should skip those container instances. Container instances which run only if asic present: swss, syncd, lldp, teamd Exception: All instances of database and bgp containers run irrespective of asic presence. Signed-off-by: anamehra anamehra@cisco.com
1 parent 850e456 commit 579ca2b

1 file changed

Lines changed: 40 additions & 4 deletions

File tree

files/image_config/monit/container_checker

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,34 @@ import docker
2020
import sys
2121

2222
import swsssdk
23-
from sonic_py_common import multi_asic, device_info
23+
from sonic_py_common import multi_asic, device_info, daemon_base
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
2651

2752
def get_expected_running_containers():
2853
"""
@@ -41,7 +66,15 @@ def get_expected_running_containers():
4166

4267
expected_running_containers = set()
4368
always_running_containers = set()
44-
69+
70+
# Get current asic presence list. For multi_asic system, multi instance containers
71+
# should be checked only for asics present.
72+
asics_id_presence = get_asic_presence_list()
73+
74+
# Some services, like database and bgp run all the instances irrespective of asic presence.
75+
# Add those to exception list.
76+
run_all_instance_list = ['database', 'bgp']
77+
4578
for container_name in feature_table.keys():
4679
if feature_table[container_name]["state"] not in ["disabled", "always_disabled"]:
4780
if multi_asic.is_multi_asic():
@@ -50,7 +83,8 @@ def get_expected_running_containers():
5083
if feature_table[container_name]["has_per_asic_scope"] == "True":
5184
num_asics = multi_asic.get_num_asics()
5285
for asic_id in range(num_asics):
53-
expected_running_containers.add(container_name + str(asic_id))
86+
if asic_id in asics_id_presence or container_name in run_all_instance_list:
87+
expected_running_containers.add(container_name + str(asic_id))
5488
else:
5589
expected_running_containers.add(container_name)
5690
if feature_table[container_name]["state"] == 'always_enabled':
@@ -60,9 +94,11 @@ def get_expected_running_containers():
6094
if feature_table[container_name]["has_per_asic_scope"] == "True":
6195
num_asics = multi_asic.get_num_asics()
6296
for asic_id in range(num_asics):
63-
always_running_containers.add(container_name + str(asic_id))
97+
if asic_id in asics_id_presence or container_name in run_all_instance_list:
98+
always_running_containers.add(container_name + str(asic_id))
6499
else:
65100
always_running_containers.add(container_name)
101+
66102
if device_info.is_supervisor():
67103
always_running_containers.add("database-chassis")
68104
return expected_running_containers, always_running_containers

0 commit comments

Comments
 (0)