@@ -143,16 +143,7 @@ def test_update_psu_data(self):
143
143
expected_calls = [mock .call ("Failed to update PSU data - Test message" )] * 2
144
144
assert daemon_psud .log_warning .mock_calls == expected_calls
145
145
146
- @mock .patch ('psud._wrapper_get_psu_presence' , mock .MagicMock ())
147
- @mock .patch ('psud._wrapper_get_psu_status' , mock .MagicMock ())
148
- def test_update_single_psu_data (self ):
149
- psud ._wrapper_get_psu_presence .return_value = True
150
- psud ._wrapper_get_psu_status .return_value = True
151
-
152
- psu1 = MockPsu ('PSU 1' , 0 , True , 'Fake Model' , '12345678' , '1234' )
153
- psud .platform_chassis = MockChassis ()
154
- psud .platform_chassis ._psu_list .append (psu1 )
155
-
146
+ def _construct_expected_fvp (self , power = 100.0 , power_warning_suppress_threshold = 'N/A' , power_critical_threshold = 'N/A' , power_overload = False ):
156
147
expected_fvp = psud .swsscommon .FieldValuePairs (
157
148
[(psud .PSU_INFO_MODEL_FIELD , 'Fake Model' ),
158
149
(psud .PSU_INFO_SERIAL_FIELD , '12345678' ),
@@ -163,17 +154,171 @@ def test_update_single_psu_data(self):
163
154
(psud .PSU_INFO_VOLTAGE_MIN_TH_FIELD , '11.0' ),
164
155
(psud .PSU_INFO_VOLTAGE_MAX_TH_FIELD , '13.0' ),
165
156
(psud .PSU_INFO_CURRENT_FIELD , '8.0' ),
166
- (psud .PSU_INFO_POWER_FIELD , '100.0' ),
157
+ (psud .PSU_INFO_POWER_FIELD , str (power )),
158
+ (psud .PSU_INFO_POWER_WARNING_SUPPRESS_THRESHOLD , str (power_warning_suppress_threshold )),
159
+ (psud .PSU_INFO_POWER_CRITICAL_THRESHOLD , str (power_critical_threshold )),
160
+ (psud .PSU_INFO_POWER_OVERLOAD , str (power_overload )),
167
161
(psud .PSU_INFO_FRU_FIELD , 'True' ),
168
162
(psud .PSU_INFO_IN_VOLTAGE_FIELD , '220.25' ),
169
163
(psud .PSU_INFO_IN_CURRENT_FIELD , '0.72' ),
170
164
(psud .PSU_INFO_POWER_MAX_FIELD , 'N/A' ),
171
165
])
166
+ return expected_fvp
167
+
168
+ @mock .patch ('psud._wrapper_get_psu_presence' , mock .MagicMock ())
169
+ @mock .patch ('psud._wrapper_get_psu_status' , mock .MagicMock ())
170
+ def test_update_single_psu_data (self ):
171
+ psud ._wrapper_get_psu_presence .return_value = True
172
+ psud ._wrapper_get_psu_status .return_value = True
173
+
174
+ psu1 = MockPsu ('PSU 1' , 0 , True , 'Fake Model' , '12345678' , '1234' )
175
+ psud .platform_chassis = MockChassis ()
176
+ psud .platform_chassis ._psu_list .append (psu1 )
177
+
178
+ expected_fvp = self ._construct_expected_fvp ()
172
179
173
180
daemon_psud = psud .DaemonPsud (SYSLOG_IDENTIFIER )
174
181
daemon_psud .psu_tbl = mock .MagicMock ()
175
182
daemon_psud ._update_single_psu_data (1 , psu1 )
176
183
daemon_psud .psu_tbl .set .assert_called_with (psud .PSU_INFO_KEY_TEMPLATE .format (1 ), expected_fvp )
184
+ assert not daemon_psud .psu_status_dict [1 ].check_psu_power_threshold
185
+
186
+ @mock .patch ('psud.daemon_base.db_connect' , mock .MagicMock ())
187
+ def test_power_threshold (self ):
188
+ psu = MockPsu ('PSU 1' , 0 , True , 'Fake Model' , '12345678' , '1234' )
189
+ psud .platform_chassis = MockChassis ()
190
+ psud .platform_chassis ._psu_list .append (psu )
191
+
192
+ daemon_psud = psud .DaemonPsud (SYSLOG_IDENTIFIER )
193
+
194
+ daemon_psud .psu_tbl = mock .MagicMock ()
195
+ psu .get_psu_power_critical_threshold = mock .MagicMock (return_value = 120.0 )
196
+ psu .get_psu_power_warning_suppress_threshold = mock .MagicMock (return_value = 110.0 )
197
+
198
+ # Normal start. All good and all thresholds are supported
199
+ # Power is in normal range (below warning threshold)
200
+ daemon_psud ._update_single_psu_data (1 , psu )
201
+ assert daemon_psud .psu_status_dict [1 ].check_psu_power_threshold
202
+ assert not daemon_psud .psu_status_dict [1 ].power_exceeded_threshold
203
+ expected_fvp = self ._construct_expected_fvp (100.0 , 110.0 , 120.0 , False )
204
+ daemon_psud .psu_tbl .set .assert_called_with (psud .PSU_INFO_KEY_TEMPLATE .format (1 ), expected_fvp )
205
+ daemon_psud ._update_led_color ()
206
+ assert psu .STATUS_LED_COLOR_GREEN == psu .get_status_led ()
207
+
208
+ daemon_psud .first_run = False
209
+
210
+ # Power is increasing across the warning threshold
211
+ # Normal => (warning, critical)
212
+ psu .set_power (115.0 )
213
+ daemon_psud ._update_single_psu_data (1 , psu )
214
+ assert daemon_psud .psu_status_dict [1 ].check_psu_power_threshold
215
+ assert not daemon_psud .psu_status_dict [1 ].power_exceeded_threshold
216
+ expected_fvp = self ._construct_expected_fvp (115.0 , 110.0 , 120.0 , False )
217
+ daemon_psud .psu_tbl .set .assert_called_with (psud .PSU_INFO_KEY_TEMPLATE .format (1 ), expected_fvp )
218
+ daemon_psud ._update_led_color ()
219
+ assert psu .STATUS_LED_COLOR_GREEN == psu .get_status_led ()
220
+
221
+ # Power is increasing across the critical threshold. Alarm raised
222
+ # (warning, critical) => (critical, )
223
+ psu .set_power (125.0 )
224
+ daemon_psud ._update_single_psu_data (1 , psu )
225
+ assert daemon_psud .psu_status_dict [1 ].check_psu_power_threshold
226
+ assert daemon_psud .psu_status_dict [1 ].power_exceeded_threshold
227
+ expected_fvp = self ._construct_expected_fvp (125.0 , 110.0 , 120.0 , True )
228
+ daemon_psud .psu_tbl .set .assert_called_with (psud .PSU_INFO_KEY_TEMPLATE .format (1 ), expected_fvp )
229
+ daemon_psud ._update_led_color ()
230
+ assert psu .STATUS_LED_COLOR_GREEN == psu .get_status_led ()
231
+
232
+ # Power is decreasing across the critical threshold. Alarm not cleared
233
+ # (critical, ) => (warning, critical)
234
+ psu .set_power (115.0 )
235
+ daemon_psud ._update_single_psu_data (1 , psu )
236
+ assert daemon_psud .psu_status_dict [1 ].check_psu_power_threshold
237
+ assert daemon_psud .psu_status_dict [1 ].power_exceeded_threshold
238
+ expected_fvp = self ._construct_expected_fvp (115.0 , 110.0 , 120.0 , True )
239
+ daemon_psud .psu_tbl .set .assert_called_with (psud .PSU_INFO_KEY_TEMPLATE .format (1 ), expected_fvp )
240
+ daemon_psud ._update_led_color ()
241
+ assert psu .STATUS_LED_COLOR_GREEN == psu .get_status_led ()
242
+
243
+ # Power is decreasing across the warning threshold. Alarm cleared
244
+ # (warning, critical) => Normal
245
+ psu .set_power (105.0 )
246
+ daemon_psud ._update_single_psu_data (1 , psu )
247
+ assert daemon_psud .psu_status_dict [1 ].check_psu_power_threshold
248
+ assert not daemon_psud .psu_status_dict [1 ].power_exceeded_threshold
249
+ expected_fvp = self ._construct_expected_fvp (105.0 , 110.0 , 120.0 , False )
250
+ daemon_psud .psu_tbl .set .assert_called_with (psud .PSU_INFO_KEY_TEMPLATE .format (1 ), expected_fvp )
251
+ assert psu .STATUS_LED_COLOR_GREEN == psu .get_status_led ()
252
+ daemon_psud ._update_led_color ()
253
+
254
+ # Power is increasing across the critical threshold. Alarm raised
255
+ # Normal => (critical, )
256
+ psu .set_power (125.0 )
257
+ daemon_psud ._update_single_psu_data (1 , psu )
258
+ assert daemon_psud .psu_status_dict [1 ].check_psu_power_threshold
259
+ assert daemon_psud .psu_status_dict [1 ].power_exceeded_threshold
260
+ expected_fvp = self ._construct_expected_fvp (125.0 , 110.0 , 120.0 , True )
261
+ daemon_psud .psu_tbl .set .assert_called_with (psud .PSU_INFO_KEY_TEMPLATE .format (1 ), expected_fvp )
262
+ daemon_psud ._update_led_color ()
263
+ assert psu .STATUS_LED_COLOR_GREEN == psu .get_status_led ()
264
+
265
+ # Power is increasing across the critical threshold. Alarm raised
266
+ # (critical, ) => Normal
267
+ psu .set_power (105.0 )
268
+ daemon_psud ._update_single_psu_data (1 , psu )
269
+ assert daemon_psud .psu_status_dict [1 ].check_psu_power_threshold
270
+ assert not daemon_psud .psu_status_dict [1 ].power_exceeded_threshold
271
+ expected_fvp = self ._construct_expected_fvp (105.0 , 110.0 , 120.0 , False )
272
+ daemon_psud .psu_tbl .set .assert_called_with (psud .PSU_INFO_KEY_TEMPLATE .format (1 ), expected_fvp )
273
+ daemon_psud ._update_led_color ()
274
+ assert psu .STATUS_LED_COLOR_GREEN == psu .get_status_led ()
275
+
276
+ # PSU power becomes down
277
+ psu .set_status (False )
278
+ daemon_psud ._update_single_psu_data (1 , psu )
279
+ daemon_psud ._update_led_color ()
280
+ assert not daemon_psud .psu_status_dict [1 ].check_psu_power_threshold
281
+ assert not daemon_psud .psu_status_dict [1 ].power_exceeded_threshold
282
+ assert psu .STATUS_LED_COLOR_RED == psu .get_status_led ()
283
+
284
+ # PSU power becomes up
285
+ psu .set_status (True )
286
+ daemon_psud ._update_single_psu_data (1 , psu )
287
+ daemon_psud ._update_led_color ()
288
+ assert daemon_psud .psu_status_dict [1 ].check_psu_power_threshold
289
+ assert not daemon_psud .psu_status_dict [1 ].power_exceeded_threshold
290
+ assert psu .STATUS_LED_COLOR_GREEN == psu .get_status_led ()
291
+
292
+ # PSU becomes absent
293
+ psu .set_presence (False )
294
+ daemon_psud ._update_single_psu_data (1 , psu )
295
+ daemon_psud ._update_led_color ()
296
+ assert not daemon_psud .psu_status_dict [1 ].check_psu_power_threshold
297
+ assert not daemon_psud .psu_status_dict [1 ].power_exceeded_threshold
298
+ assert psu .STATUS_LED_COLOR_RED == psu .get_status_led ()
299
+
300
+ # PSU becomes present
301
+ psu .set_presence (True )
302
+ daemon_psud ._update_single_psu_data (1 , psu )
303
+ daemon_psud ._update_led_color ()
304
+ assert daemon_psud .psu_status_dict [1 ].check_psu_power_threshold
305
+ assert not daemon_psud .psu_status_dict [1 ].power_exceeded_threshold
306
+ assert psu .STATUS_LED_COLOR_GREEN == psu .get_status_led ()
307
+
308
+ # Thresholds become invalid on the fly
309
+ psu .get_psu_power_critical_threshold = mock .MagicMock (side_effect = NotImplementedError ('' ))
310
+ daemon_psud ._update_single_psu_data (1 , psu )
311
+ assert not daemon_psud .psu_status_dict [1 ].check_psu_power_threshold
312
+ assert not daemon_psud .psu_status_dict [1 ].power_exceeded_threshold
313
+ psu .get_psu_power_critical_threshold = mock .MagicMock (return_value = 120.0 )
314
+ daemon_psud .psu_status_dict [1 ].check_psu_power_threshold = True
315
+ daemon_psud ._update_single_psu_data (1 , psu )
316
+ assert daemon_psud .psu_status_dict [1 ].check_psu_power_threshold
317
+ assert not daemon_psud .psu_status_dict [1 ].power_exceeded_threshold
318
+ psu .get_psu_power_warning_suppress_threshold = mock .MagicMock (side_effect = NotImplementedError ('' ))
319
+ daemon_psud ._update_single_psu_data (1 , psu )
320
+ assert not daemon_psud .psu_status_dict [1 ].check_psu_power_threshold
321
+ assert not daemon_psud .psu_status_dict [1 ].power_exceeded_threshold
177
322
178
323
def test_set_psu_led (self ):
179
324
mock_logger = mock .MagicMock ()
0 commit comments