4
4
import logging
5
5
import time
6
6
from pkg_resources import parse_version
7
- from tests .platform_tests .thermal_control_test_helper import *
7
+ from tests .platform_tests .thermal_control_test_helper import mocker , FanStatusMocker , ThermalStatusMocker , \
8
+ SingleFanMocker
8
9
from tests .common .mellanox_data import get_platform_data
9
10
from minimum_table import get_min_table
10
11
96
97
}
97
98
}
98
99
100
+
99
101
class SysfsNotExistError (Exception ):
100
102
"""
101
103
Exception when sys fs not exist.
@@ -138,7 +140,6 @@ def __init__(self, dut):
138
140
:param dut: DUT object representing a SONiC switch under test.
139
141
"""
140
142
self .dut = dut
141
- #self.unlink_file_list = {}
142
143
self ._extract_num_of_fans_and_fan_drawers ()
143
144
self .deinit_retry = 5
144
145
@@ -289,7 +290,7 @@ def deinit(self):
289
290
for file_path , link_target in self .unlink_file_list .items ():
290
291
try :
291
292
self .dut .command ('ln -f -s {} {}' .format (link_target , file_path ))
292
- except Exception as e :
293
+ except Exception :
293
294
# Catch any exception for later retry
294
295
failed_recover_links [file_path ] = link_target
295
296
@@ -300,7 +301,7 @@ def deinit(self):
300
301
self .dut .shell ('rm -f {}' .format (file_path ))
301
302
else :
302
303
self .dut .shell ('echo \' {}\' > {}' .format (value , file_path ))
303
- except Exception as e :
304
+ except Exception :
304
305
# Catch any exception for later retry
305
306
failed_recover_files [file_path ] = value
306
307
@@ -417,7 +418,7 @@ def mock_fan_direction_fan_dir_per_fan(self, direction):
417
418
"""
418
419
try :
419
420
_ = int (self .helper .read_value (FanDrawerData .FAN_DIR_PATH_PER_FAN .format (self .index )))
420
- except SysfsNotExistError as e :
421
+ except SysfsNotExistError :
421
422
self .mocked_direction = NOT_AVAILABLE
422
423
return
423
424
@@ -438,7 +439,7 @@ def mock_fan_direction_fan_dir_for_all_fans(self, direction):
438
439
"""
439
440
try :
440
441
fan_dir_bits = int (self .helper .read_value (FanDrawerData .FAN_DIR_PATH_ALL_FANS ))
441
- except SysfsNotExistError as e :
442
+ except SysfsNotExistError :
442
443
self .mocked_direction = NOT_AVAILABLE
443
444
return
444
445
@@ -479,6 +480,7 @@ def get_expect_led_color(self):
479
480
480
481
return 'green'
481
482
483
+
482
484
class FanData :
483
485
"""
484
486
Data mocker of a FAN.
@@ -713,7 +715,7 @@ def check_result(self, actual_data):
713
715
mismatch_in_actual_data = []
714
716
for actual_data_item in actual_data :
715
717
primary = actual_data_item [self .primary_field ]
716
- if not primary in expected :
718
+ if primary not in expected :
717
719
extra_in_actual_data .append (actual_data_item )
718
720
else :
719
721
for field in actual_data_item .keys ():
@@ -726,16 +728,16 @@ def check_result(self, actual_data):
726
728
727
729
result = True
728
730
if len (extra_in_actual_data ) > 0 :
729
- logging .error ('Found extra data in actual_data: {}' \
730
- .format (json .dumps (extra_in_actual_data , indent = 2 )))
731
+ logging .error ('Found extra data in actual_data: {}'
732
+ .format (json .dumps (extra_in_actual_data , indent = 2 )))
731
733
result = False
732
734
if len (mismatch_in_actual_data ) > 0 :
733
- logging .error ('Found mismatch data in actual_data: {}' \
734
- .format (json .dumps (mismatch_in_actual_data , indent = 2 )))
735
+ logging .error ('Found mismatch data in actual_data: {}'
736
+ .format (json .dumps (mismatch_in_actual_data , indent = 2 )))
735
737
result = False
736
738
if len (expected .keys ()) > 0 :
737
- logging .error ('Expected data not found in actual_data: {}' \
738
- .format (json .dumps (expected , indent = 2 )))
739
+ logging .error ('Expected data not found in actual_data: {}'
740
+ .format (json .dumps (expected , indent = 2 )))
739
741
result = False
740
742
741
743
return result
@@ -761,7 +763,7 @@ def __init__(self, dut):
761
763
self .expected_data = {}
762
764
self .expected_data_headers = ['drawer' , 'led' , 'fan' , 'speed' , 'direction' , 'presence' , 'status' ]
763
765
self .primary_field = 'fan'
764
- self .excluded_fields = ['timestamp' ,]
766
+ self .excluded_fields = ['timestamp' , ]
765
767
766
768
def deinit (self ):
767
769
"""
@@ -779,12 +781,11 @@ def mock_data(self):
779
781
drawer_index = 1
780
782
drawer_data = None
781
783
presence = 0
782
- direction = NOT_AVAILABLE
783
784
naming_rule = FAN_NAMING_RULE ['fan' ]
784
785
# All system fan is controlled to have the same speed, so only
785
786
# get a random value once here
786
787
speed = random .randint (60 , 100 )
787
- FanData .mock_cooling_cur_state (self .mock_helper , speed / 10 )
788
+ FanData .mock_cooling_cur_state (self .mock_helper , speed / 10 )
788
789
while fan_index <= MockerHelper .FAN_NUM :
789
790
try :
790
791
if (fan_index - 1 ) % MockerHelper .FAN_NUM_PER_DRAWER == 0 :
@@ -806,7 +807,7 @@ def mock_data(self):
806
807
fan_data .mock_target_speed (speed )
807
808
self .expected_data [fan_data .name ] = [
808
809
drawer_data .name ,
809
- 'N/A' , # update this value later
810
+ 'N/A' , # update this value later
810
811
fan_data .name ,
811
812
'{}%' .format (fan_data .mocked_speed ),
812
813
drawer_data .mocked_direction ,
@@ -894,9 +895,10 @@ def __init__(self, dut):
894
895
ThermalStatusMocker .__init__ (self , dut )
895
896
self .mock_helper = MockerHelper (dut )
896
897
self .expected_data = {}
897
- self .expected_data_headers = ['sensor' , 'temperature' , 'high th' , 'low th' , 'crit high th' , 'crit low th' , 'warning' ]
898
+ self .expected_data_headers = ['sensor' , 'temperature' , 'high th' , 'low th' , 'crit high th' , 'crit low th' ,
899
+ 'warning' ]
898
900
self .primary_field = 'sensor'
899
- self .excluded_fields = ['timestamp' ,]
901
+ self .excluded_fields = ['timestamp' , ]
900
902
901
903
def deinit (self ):
902
904
"""
@@ -1097,7 +1099,8 @@ def mock_over_speed(self):
1097
1099
Change the mocked FAN speed to faster than target speed and exceed speed tolerance.
1098
1100
:return:
1099
1101
"""
1100
- self .fan_data .mock_speed (AbnormalFanMocker .TARGET_SPEED_VALUE * (100 + AbnormalFanMocker .SPEED_TOLERANCE ) / 100 + 10 )
1102
+ self .fan_data .mock_speed (
1103
+ AbnormalFanMocker .TARGET_SPEED_VALUE * (100 + AbnormalFanMocker .SPEED_TOLERANCE ) / 100 + 10 )
1101
1104
self .fan_data .mock_target_speed (AbnormalFanMocker .TARGET_SPEED_VALUE )
1102
1105
self .expect_led_color = 'red'
1103
1106
@@ -1106,7 +1109,8 @@ def mock_under_speed(self):
1106
1109
Change the mocked FAN speed to slower than target speed and exceed speed tolerance.
1107
1110
:return:
1108
1111
"""
1109
- self .fan_data .mock_speed (AbnormalFanMocker .TARGET_SPEED_VALUE * (100 - AbnormalFanMocker .SPEED_TOLERANCE ) / 100 - 10 )
1112
+ self .fan_data .mock_speed (
1113
+ AbnormalFanMocker .TARGET_SPEED_VALUE * (100 - AbnormalFanMocker .SPEED_TOLERANCE ) / 100 - 10 )
1110
1114
self .fan_data .mock_target_speed (AbnormalFanMocker .TARGET_SPEED_VALUE )
1111
1115
self .expect_led_color = 'red'
1112
1116
@@ -1237,7 +1241,7 @@ def mock_power_threshold(self, number_psus):
1237
1241
if not max_power :
1238
1242
power = int (self .mock_helper .read_value (self .PSU_POWER .format (i + 1 )))
1239
1243
# Round up to 100 watt and then double it to avoid noise when power fluctuate
1240
- max_power = int (round (power / 100000000.0 )) * 100000000 * 2
1244
+ max_power = int (round (power / 100000000.0 )) * 100000000 * 2
1241
1245
self .mock_helper .mock_value (self .PSU_POWER_CAPACITY .format (i + 1 ), max_power , True )
1242
1246
1243
1247
# Also mock ambient temperatures
@@ -1273,3 +1277,25 @@ def read_port_ambient_thermal(self):
1273
1277
1274
1278
def read_fan_ambient_thermal (self ):
1275
1279
return int (self .mock_helper .read_value (self .FAN_AMBIENT_TEMP ))
1280
+
1281
+
1282
+ @mocker ('RebootCauseMocker' )
1283
+ class RebootCauseMocker (object ):
1284
+ RESET_RELOAD_BIOS = '/var/run/hw-management/system/reset_reload_bios'
1285
+ RESET_FROM_COMEX = '/var/run/hw-management/system/reset_from_comex'
1286
+ RESET_FROM_ASIC = '/var/run/hw-management/system/reset_from_asic'
1287
+
1288
+ def __init__ (self , dut ):
1289
+ self .mock_helper = MockerHelper (dut )
1290
+
1291
+ def deinit (self ):
1292
+ self .mock_helper .deinit ()
1293
+
1294
+ def mock_reset_reload_bios (self ):
1295
+ self .mock_helper .mock_value (self .RESET_RELOAD_BIOS , 1 )
1296
+
1297
+ def mock_reset_from_comex (self ):
1298
+ self .mock_helper .mock_value (self .RESET_FROM_COMEX , 1 )
1299
+
1300
+ def mock_reset_from_asic (self ):
1301
+ self .mock_helper .mock_value (self .RESET_FROM_ASIC , 1 )
0 commit comments