1515 import os
1616 from swsscommon import swsscommon
1717 from sonic_py_common import daemon_base , logger
18+ from sonic_platform_base .device_base import DeviceBase
1819 from sonic_platform_base .module_base import ModuleBase
1920 from sonic_py_common .task_base import ProcessTaskBase
2021except ImportError , e :
@@ -42,7 +43,7 @@ CHASSIS_MODULE_INFO_OPERSTATUS_FIELD = 'oper_status'
4243CHASSIS_INFO_UPDATE_PERIOD_SECS = 10
4344
4445CHASSIS_LOAD_ERROR = 1
45- CHASSIS_NOT_AVAIL = 2
46+ CHASSIS_NOT_SUPPORTED = 2
4647
4748platform_chassis = None
4849
@@ -61,20 +62,29 @@ def get_module_info(module_index):
6162 """
6263 module_info_dict = {}
6364 module_info_dict = dict .fromkeys (info_dict_keys , 'N/A' )
64- module_info_dict [CHASSIS_MODULE_INFO_NAME_FIELD ] = str (platform_chassis .get_module (module_index - 1 ).get_name ())
65- module_info_dict [CHASSIS_MODULE_INFO_DESC_FIELD ] = str (platform_chassis .get_module (module_index - 1 ).get_description ())
66- module_info_dict [CHASSIS_MODULE_INFO_SLOT_FIELD ] = str (platform_chassis .get_module (module_index - 1 ).get_slot ())
67- module_info_dict [CHASSIS_MODULE_INFO_OPERSTATUS_FIELD ] = str (platform_chassis .get_module (module_index - 1 ).get_status ())
65+ module_info_dict [CHASSIS_MODULE_INFO_NAME_FIELD ] = str (platform_chassis .get_module (module_index ).get_name ())
66+ module_info_dict [CHASSIS_MODULE_INFO_DESC_FIELD ] = str (platform_chassis .get_module (module_index ).get_description ())
67+ module_info_dict [CHASSIS_MODULE_INFO_SLOT_FIELD ] = str (platform_chassis .get_module (module_index ).get_slot ())
68+ module_info_dict [CHASSIS_MODULE_INFO_OPERSTATUS_FIELD ] = str (platform_chassis .get_module (module_index ).get_status ())
6869 return module_info_dict
6970
70- def module_db_update (config_tbl , module_tbl , num_modules ):
71- for module_index in range (1 , num_modules + 1 ):
71+ def module_db_update (logger , module_tbl , num_modules ):
72+ for module_index in range (0 , num_modules ):
7273 module_info_dict = get_module_info (module_index )
7374 if module_info_dict is not None :
75+ key = module_info_dict [CHASSIS_MODULE_INFO_NAME_FIELD ]
76+
77+ if not key .startswith (ModuleBase .MODULE_TYPE_SUPERVISOR ) and \
78+ not key .startswith (ModuleBase .MODULE_TYPE_LINE ) and \
79+ not key .startswith (ModuleBase .MODULE_TYPE_FABRIC ):
80+ (logger .log_error ("Incorrect module-name {}. Should start with {} or {} or {}" .format (\
81+ ModuleBase .MODULE_TYPE_SUPERVISOR , ModuleBase .MODULE_TYPE_LINE , ModuleBase .MODULE_TYPE_FABRIC )))
82+ continue
83+
7484 fvs = swsscommon .FieldValuePairs ([(CHASSIS_MODULE_INFO_DESC_FIELD , module_info_dict [CHASSIS_MODULE_INFO_DESC_FIELD ]),
7585 (CHASSIS_MODULE_INFO_SLOT_FIELD , module_info_dict [CHASSIS_MODULE_INFO_SLOT_FIELD ]),
7686 (CHASSIS_MODULE_INFO_OPERSTATUS_FIELD , module_info_dict [CHASSIS_MODULE_INFO_OPERSTATUS_FIELD ])])
77- module_tbl .set (module_info_dict [ CHASSIS_MODULE_INFO_NAME_FIELD ] , fvs )
87+ module_tbl .set (key , fvs )
7888
7989#
8090# Config Handling task ========================================================
@@ -109,8 +119,11 @@ class config_handling_task(ProcessTaskBase):
109119
110120 (key , op , fvp ) = sst .pop ()
111121
112- if not key .startswith (ModuleBase .MODULE_TYPE_CONTROL ) and not key .startswith (ModuleBase .MODULE_TYPE_LINE ) and not key .startswith (ModuleBase .MODULE_TYPE_FABRIC ):
113- self .logger .log_warning ("Incorrect module-name {}. Should start with {} or {} or {}" .format (key , ModuleBase .MODULE_TYPE_CONTROL , ModuleBase .MODULE_TYPE_LINE , ModuleBase .MODULE_TYPE_FABRIC ))
122+ if not key .startswith (ModuleBase .MODULE_TYPE_SUPERVISOR ) and \
123+ not key .startswith (ModuleBase .MODULE_TYPE_LINE ) and \
124+ not key .startswith (ModuleBase .MODULE_TYPE_FABRIC ):
125+ (self .logger .log_error ("Incorrect module-name {}. Should start with {} or {} or {}" .format (\
126+ ModuleBase .MODULE_TYPE_SUPERVISOR , ModuleBase .MODULE_TYPE_LINE , ModuleBase .MODULE_TYPE_FABRIC )))
114127 continue
115128
116129 fvp_dict = dict (fvp )
@@ -188,6 +201,10 @@ class ChassisdDaemon(daemon_base.DaemonBase):
188201 if num_modules == 0 :
189202 self .log_error ("Chassisd has no modules available" )
190203
204+ if platform_chassis .get_my_slot == DeviceBase .NotImplementedInt :
205+ self .log_error ("Chassisd not supported for this platform" )
206+ sys .exit (CHASSIS_NOT_SUPPORTED )
207+
191208 #Start configuration handling task on control module
192209 if platform_chassis .get_controlcard_slot () == platform_chassis .get_my_slot ():
193210 config_update = config_handling_task ()
@@ -197,7 +214,7 @@ class ChassisdDaemon(daemon_base.DaemonBase):
197214 self .log_info ("Start daemon main loop" )
198215
199216 while not self .stop .wait (CHASSIS_INFO_UPDATE_PERIOD_SECS ):
200- module_db_update (config_tbl , module_tbl , num_modules )
217+ module_db_update (self , module_tbl , num_modules )
201218
202219 self .log_info ("Stop daemon main loop" )
203220
0 commit comments