@@ -28,6 +28,13 @@ class Psu(PsuBase):
28
28
__sensors_info = None
29
29
__timestamp = 0
30
30
31
+ # When psud gets termination signal it starts processing last cycle.
32
+ # This cycle must be as fast as possible to be able to stop correctly,
33
+ # otherwise it will be killed, so the whole plugin must encounter
34
+ # this signal to process operations based on state, where the
35
+ # state is "termination signal got" and "no termination signal"
36
+
37
+ # State is "no termination signal"
31
38
sigterm = False
32
39
sigterm_default_handler = None
33
40
cls_inited = False
@@ -54,12 +61,15 @@ def signal_handler(cls, sig, frame):
54
61
if cls .sigterm_default_handler :
55
62
cls .sigterm_default_handler (sig , frame )
56
63
syslog .syslog (syslog .LOG_INFO , "Canceling PSU platform API calls..." )
64
+ # Changing state to "termination signal"
57
65
cls .sigterm = True
58
66
59
67
@classmethod
60
68
def __sensors_get (cls , cached = True ):
61
69
cls .__lock .acquire ()
62
- if time .time () > cls .__timestamp + 15 :
70
+ # Operation may take a few seconds to process, so if state is
71
+ # "termination signal", plugin doesn't perform this operation
72
+ if time .time () > cls .__timestamp + 15 and not Psu .sigterm :
63
73
# Update cache once per 15 seconds
64
74
try :
65
75
cls .__sensors_info = get_psu_metrics ()
@@ -83,6 +93,8 @@ def __info_get(self):
83
93
def psu_info_get (client ):
84
94
return client .pltfm_mgr .pltfm_mgr_pwr_supply_info_get (self .__index )
85
95
96
+ # Operation may take a few seconds to process, so if state is
97
+ # "termination signal", plugin doesn't perform this operation
86
98
# Update cache once per 2 seconds
87
99
if self .__ts + 2 < time .time () and not Psu .sigterm :
88
100
self .__info = None
@@ -96,6 +108,10 @@ def psu_info_get(client):
96
108
return self .__info
97
109
return self .__info
98
110
111
+ @cancel_on_sigterm
112
+ def get_metric_value (self , metric_name ):
113
+ return get_metric_value (Psu .__sensors_get (), "PSU%d " .format (self .__index ) + metric_name )
114
+
99
115
@staticmethod
100
116
def get_num_psus ():
101
117
"""
@@ -127,7 +143,7 @@ def get_voltage(self):
127
143
A float number, the output voltage in volts,
128
144
e.g. 12.1
129
145
"""
130
- return get_metric_value (Psu . __sensors_get (), "PSU%d 12V Output Voltage_in1_input" % self . __index )
146
+ return self . get_metric_value (" 12V Output Voltage_in1_input" )
131
147
132
148
def get_current (self ):
133
149
"""
@@ -136,7 +152,7 @@ def get_current(self):
136
152
Returns:
137
153
A float number, the electric current in amperes, e.g 15.4
138
154
"""
139
- return get_metric_value (Psu . __sensors_get (), "PSU%d 12V Output Current_curr2_input" % self . __index )
155
+ return self . get_metric_value (" 12V Output Current_curr2_input" )
140
156
141
157
def get_input_voltage (self ):
142
158
"""
@@ -145,15 +161,15 @@ def get_input_voltage(self):
145
161
A float number, the input voltage in volts,
146
162
e.g. 220
147
163
"""
148
- return get_metric_value (Psu . __sensors_get (), "PSU%d Input Voltage_in0_input" % self . __index )
164
+ return self . get_metric_value (" Input Voltage_in0_input" )
149
165
150
166
def get_input_current (self ):
151
167
"""
152
168
Retrieves the input current draw of the power supply
153
169
Returns:
154
170
A float number, the electric current in amperes, e.g 0.8
155
171
"""
156
- return get_metric_value (Psu . __sensors_get (), "PSU%d Input Current_curr1_input" % self . __index )
172
+ return self . get_metric_value (" Input Current_curr1_input" )
157
173
158
174
def get_power (self ):
159
175
"""
@@ -177,6 +193,9 @@ def psu_present_get(client):
177
193
return client .pltfm_mgr .pltfm_mgr_pwr_supply_present_get (self .__index )
178
194
179
195
status = False
196
+ if Psu .sigterm :
197
+ return status
198
+
180
199
try :
181
200
status = thrift_try (psu_present_get , attempts = 1 )
182
201
except Exception as e :
@@ -267,22 +286,28 @@ def get_position_in_parent(self):
267
286
"""
268
287
return self .__index
269
288
289
+ @cancel_on_sigterm
270
290
def get_temperature (self ):
271
291
"""
272
292
Retrieves current temperature reading from PSU
273
293
Returns:
274
294
A float number of current temperature in Celsius up to nearest thousandth
275
295
of one degree Celsius, e.g. 30.125
276
296
"""
297
+ # Operation may take a few seconds to process, so if state is
298
+ # "termination signal", plugin doesn't perform this operation
277
299
return self .get_thermal (0 ).get_temperature ()
278
300
301
+ @cancel_on_sigterm
279
302
def get_temperature_high_threshold (self ):
280
303
"""
281
304
Retrieves the high threshold temperature of PSU
282
305
Returns:
283
306
A float number, the high threshold temperature of PSU in Celsius
284
307
up to nearest thousandth of one degree Celsius, e.g. 30.125
285
308
"""
309
+ # Operation may take a few seconds to process, so if state is
310
+ # "termination signal", plugin doesn't perform this operation
286
311
return self .get_thermal (0 ).get_high_threshold ()
287
312
288
313
@property
0 commit comments