10
10
"""
11
11
12
12
try :
13
- import sys
14
13
import signal
14
+ import sys
15
15
import threading
16
+
17
+ from sonic_py_common import daemon_base
16
18
from swsscommon import swsscommon
17
- from sonic_daemon_base import daemon_base
18
- from sonic_daemon_base .daemon_base import Logger
19
- from sonic_daemon_base .daemon_base import DaemonBase
20
19
except ImportError , e :
21
20
raise ImportError (str (e ) + " - required module not found" )
22
21
@@ -49,8 +48,6 @@ PSU_INFO_UPDATE_PERIOD_SECS = 3
49
48
50
49
PSUUTIL_LOAD_ERROR = 1
51
50
52
- logger = Logger (SYSLOG_IDENTIFIER )
53
-
54
51
platform_psuutil = None
55
52
platform_chassis = None
56
53
@@ -119,9 +116,9 @@ def log_on_status_changed(normal_status, normal_log, abnormal_log):
119
116
:return:
120
117
"""
121
118
if normal_status :
122
- logger .log_notice (normal_log )
119
+ self .log_notice (normal_log )
123
120
else :
124
- logger .log_warning (abnormal_log )
121
+ self .log_warning (abnormal_log )
125
122
126
123
#
127
124
# PSU status ===================================================================
@@ -162,7 +159,7 @@ class PsuStatus(object):
162
159
def set_voltage (self , voltage , high_threshold , low_threshold ):
163
160
if not voltage or not high_threshold or not low_threshold :
164
161
if self .voltage_good is not True :
165
- logger .log_warning ('PSU voltage or high_threshold or low_threshold become unavailable, '
162
+ self .log_warning ('PSU voltage or high_threshold or low_threshold become unavailable, '
166
163
'voltage={}, high_threshold={}, low_threshold={}' .format (voltage , high_threshold , low_threshold ))
167
164
self .voltage_good = True
168
165
return False
@@ -177,7 +174,7 @@ class PsuStatus(object):
177
174
def set_temperature (self , temperature , high_threshold ):
178
175
if not temperature or not high_threshold :
179
176
if self .temperature_good is not True :
180
- logger .log_warning ('PSU temperature or high_threshold become unavailable, '
177
+ self .log_warning ('PSU temperature or high_threshold become unavailable, '
181
178
'temperature={}, high_threshold={}' .format (temperature , high_threshold ))
182
179
self .temperature_good = True
183
180
return False
@@ -196,46 +193,46 @@ class PsuStatus(object):
196
193
# Daemon =======================================================================
197
194
#
198
195
199
- class DaemonPsud (DaemonBase ):
200
- def __init__ (self ):
201
- DaemonBase .__init__ (self )
196
+ class DaemonPsud (daemon_base . DaemonBase ):
197
+ def __init__ (self , log_identifier ):
198
+ super ( DaemonPsud , self ) .__init__ (log_identifier )
202
199
203
200
self .stop = threading .Event ()
204
201
self .psu_status_dict = {}
205
202
206
203
# Signal handler
207
204
def signal_handler (self , sig , frame ):
208
205
if sig == signal .SIGHUP :
209
- logger .log_info ("Caught SIGHUP - ignoring..." )
206
+ self .log_info ("Caught SIGHUP - ignoring..." )
210
207
elif sig == signal .SIGINT :
211
- logger .log_info ("Caught SIGINT - exiting..." )
208
+ self .log_info ("Caught SIGINT - exiting..." )
212
209
self .stop .set ()
213
210
elif sig == signal .SIGTERM :
214
- logger .log_info ("Caught SIGTERM - exiting..." )
211
+ self .log_info ("Caught SIGTERM - exiting..." )
215
212
self .stop .set ()
216
213
else :
217
- logger .log_warning ("Caught unhandled signal '" + sig + "'" )
214
+ self .log_warning ("Caught unhandled signal '" + sig + "'" )
218
215
219
216
# Run daemon
220
217
def run (self ):
221
218
global platform_psuutil
222
219
global platform_chassis
223
220
224
- logger .log_info ("Starting up..." )
221
+ self .log_info ("Starting up..." )
225
222
226
223
# Load new platform api class
227
224
try :
228
225
import sonic_platform .platform
229
226
platform_chassis = sonic_platform .platform .Platform ().get_chassis ()
230
227
except Exception as e :
231
- logger .log_warning ("Failed to load chassis due to {}" .format (repr (e )))
228
+ self .log_warning ("Failed to load chassis due to {}" .format (repr (e )))
232
229
233
230
# Load platform-specific psuutil class
234
231
if platform_chassis is None :
235
232
try :
236
233
platform_psuutil = self .load_platform_util (PLATFORM_SPECIFIC_MODULE_NAME , PLATFORM_SPECIFIC_CLASS_NAME )
237
234
except Exception as e :
238
- logger .log_error ("Failed to load psuutil: %s" % (str (e )), True )
235
+ self .log_error ("Failed to load psuutil: %s" % (str (e )), True )
239
236
sys .exit (PSUUTIL_LOAD_ERROR )
240
237
241
238
# Connect to STATE_DB and create psu/chassis info tables
@@ -249,22 +246,22 @@ class DaemonPsud(DaemonBase):
249
246
chassis_tbl .set (CHASSIS_INFO_KEY_TEMPLATE .format (1 ), fvs )
250
247
251
248
# Start main loop
252
- logger .log_info ("Start daemon main loop" )
249
+ self .log_info ("Start daemon main loop" )
253
250
254
251
while not self .stop .wait (PSU_INFO_UPDATE_PERIOD_SECS ):
255
252
psu_db_update (psu_tbl , psu_num )
256
253
self .update_psu_data (psu_tbl )
257
254
self ._update_led_color (psu_tbl )
258
255
259
- logger .log_info ("Stop daemon main loop" )
256
+ self .log_info ("Stop daemon main loop" )
260
257
261
258
# Delete all the information from DB and then exit
262
259
for psu_index in range (1 , psu_num + 1 ):
263
260
psu_tbl ._del (PSU_INFO_KEY_TEMPLATE .format (psu_index ))
264
261
265
262
chassis_tbl ._del (CHASSIS_INFO_KEY_TEMPLATE .format (1 ))
266
263
267
- logger .log_info ("Shutting down..." )
264
+ self .log_info ("Shutting down..." )
268
265
269
266
def update_psu_data (self , psu_tbl ):
270
267
if not platform_chassis :
@@ -274,7 +271,7 @@ class DaemonPsud(DaemonBase):
274
271
try :
275
272
self ._update_single_psu_data (index + 1 , psu , psu_tbl )
276
273
except Exception as e :
277
- logger .log_warning ("Failed to update PSU data - {}" .format (e ))
274
+ self .log_warning ("Failed to update PSU data - {}" .format (e ))
278
275
279
276
def _update_single_psu_data (self , index , psu , psu_tbl ):
280
277
name = try_get (psu .get_name )
@@ -358,7 +355,7 @@ class DaemonPsud(DaemonBase):
358
355
('led_status' , str (try_get (psu_status .psu .get_status_led )))
359
356
])
360
357
except Exception as e :
361
- logger .log_warning ('Failed to get led status for psu {}' .format (index ))
358
+ self .log_warning ('Failed to get led status for psu {}' .format (index ))
362
359
fvs = swsscommon .FieldValuePairs ([
363
360
('led_status' , NOT_AVAILABLE )
364
361
])
@@ -368,7 +365,7 @@ class DaemonPsud(DaemonBase):
368
365
#
369
366
370
367
def main ():
371
- psud = DaemonPsud ()
368
+ psud = DaemonPsud (SYSLOG_IDENTIFIER )
372
369
psud .run ()
373
370
374
371
if __name__ == '__main__' :
0 commit comments