def test_set_fans_led(self, duthost, localhost, platform_api_conn): LED_COLOR_LIST = [ "off", "red", "amber", "green", ] for j in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, j) for i in range(num_fans): for color in LED_COLOR_LIST: result = fan_drawer_fan.set_status_led(platform_api_conn, j, i, color) if self.expect(result is not None, "Failed to perform set_status_led"): self.expect(result is True, "Failed to set status_led for fan drawer {} fan {} to {}".format(j , i, color)) color_actual = fan_drawer_fan.get_status_led(platform_api_conn, j, i) if self.expect(color_actual is not None, "Failed to retrieve status_led"): if self.expect(isinstance(color_actual, STRING_TYPE), "Status LED color appears incorrect"): self.expect(color == color_actual, "Status LED color incorrect (expected: {}, actual: {} for fan {})".format( color, color_actual, i)) self.assert_expectations()
def test_get_direction(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): # Ensure the fan speed is sane FAN_DIRECTION_LIST = [ "intake", "exhaust", "N/A", ] for j in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, j) for i in range(num_fans): direction = fan_drawer_fan.get_direction( platform_api_conn, j, i) if self.expect( direction is not None, "Unable to retrieve Fan drawer {} fan {} direction". format(j, i)): self.expect( direction in FAN_DIRECTION_LIST, "Fan drawer {} fan {} direction is not one of predefined directions" .format(j, i)) self.assert_expectations()
def test_get_fans_target_speed(self, duthost, localhost, platform_api_conn): for j in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, j) for i in range(num_fans): speed_target_val = 25 speed_set = fan_drawer_fan.set_speed(platform_api_conn, j, i, speed_target_val) target_speed = fan_drawer_fan.get_target_speed( platform_api_conn, j, i) if self.expect( target_speed is not None, "Unable to retrieve Fan drawer {} fan {} target speed". format(j, i)): if self.expect( isinstance(target_speed, int), "Fan drawer {} fan {} target speed appears incorrect" .format(j, i)): self.expect( target_speed == speed_target_val, "Fan drawer {} fan {} target speed setting is not correct, speed_target_val {} target_speed = {}" .format(j, i, speed_target_val, target_speed)) self.assert_expectations()
def test_get_position_in_parent(self, platform_api_conn): for j in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, j) for i in range(num_fans): position = fan_drawer_fan.get_position_in_parent(platform_api_conn, j, i) if self.expect(position is not None, "Failed to perform get_position_in_parent for drawer {} fan {}".format(j, i)): self.expect(isinstance(position, int), "Position value must be an integer value for drawer {} fan {}".format(j, i)) self.assert_expectations()
def test_get_num_fans(self, duthost, localhost, platform_api_conn): for i in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, i) if self.expect(num_fans is not None, "Unable to retrieve fan_drawer {} number of fans".format(i)): self.expect(isinstance(num_fans, int), "fan drawer {} number of fans appear to be incorrect".format(i)) self.compare_value_with_platform_facts('num_fans', num_fans, i) self.assert_expectations()
def test_is_replaceable(self, platform_api_conn): for j in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, j) for i in range(num_fans): replaceable = fan_drawer_fan.is_replaceable(platform_api_conn, j, i) if self.expect(replaceable is not None, "Failed to perform is_replaceable for drawer {} fan {}".format(j, i)): self.expect(isinstance(replaceable, bool), "Replaceable value must be a bool value for drawer {} fan {}".format(j, i)) self.assert_expectations()
def test_get_fans_target_speed(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): duthost = duthosts[enum_rand_one_per_hwsku_hostname] fan_drawers_skipped = 0 for j in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, j) fans_skipped = 0 for i in range(num_fans): speed_target_val = 25 speed_controllable = self.get_fan_facts( duthost, j, i, True, "speed", "controllable") if not speed_controllable: logger.info( "test_get_fans_target_speed: Skipping fandrawer {} fan {} (speed not controllable)" .format(j, i)) fans_skipped += 1 continue speed_minimum = self.get_fan_facts(duthost, j, i, 25, "speed", "minimum") speed_maximum = self.get_fan_facts(duthost, j, i, 100, "speed", "maximum") if speed_minimum > speed_target_val or speed_maximum < speed_target_val: speed_target_val = random.randint(speed_minimum, speed_maximum) speed_set = fan_drawer_fan.set_speed(platform_api_conn, j, i, speed_target_val) target_speed = fan_drawer_fan.get_target_speed( platform_api_conn, j, i) if self.expect( target_speed is not None, "Unable to retrieve Fan drawer {} fan {} target speed". format(j, i)): if self.expect( isinstance(target_speed, int), "Fan drawer {} fan {} target speed appears incorrect" .format(j, i)): self.expect( target_speed == speed_target_val, "Fan drawer {} fan {} target speed setting is not correct, speed_target_val {} target_speed = {}" .format(j, i, speed_target_val, target_speed)) if fans_skipped == num_fans: fan_drawers_skipped += 1 if fan_drawers_skipped == self.num_fan_drawers: pytest.skip( "skipped as all fandrawer fans' speed is not controllable") self.assert_expectations()
def test_get_status(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): for j in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, j) for i in range(num_fans): status = fan_drawer_fan.get_status(platform_api_conn, j, i) if self.expect(status is not None, "Unable to retrieve drawer {} fan {} status".format(j, i)): self.expect(isinstance(status, bool), "Fan drawer {} fan {} status appears incorrect".format(j, i)) self.assert_expectations()
def test_get_serial(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): for j in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, j) for i in range(num_fans): serial = fan_drawer_fan.get_serial(platform_api_conn, j ,i) if self.expect(serial is not None, "Unable to retrieve fan drawer {} fan {} serial number".format(j, i)): self.expect(isinstance(serial, STRING_TYPE), "Fan drawer {} fan {}serial number appears incorrect".format(j, i)) self.assert_expectations()
def test_get_fans_speed_tolerance(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): for j in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, j) for i in range(num_fans): speed_tolerance = fan_drawer_fan.get_speed_tolerance(platform_api_conn, j, i) if self.expect(speed_tolerance is not None, "Unable to retrieve fan drawer {} fan {} speed tolerance".format(j, i)): if self.expect(isinstance(speed_tolerance, int), "Fan drawer {} fan {} speed tolerance appears incorrect".format(j, i)): self.expect(speed_tolerance > 0 and speed_tolerance <= 100, "Fan drawer {} fan {} speed tolerance {} reading does not make sense".format(j, i, speed_tolerance)) self.assert_expectations()
def test_get_model(self, duthost, localhost, platform_api_conn): for j in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, j) for i in range(num_fans): model = fan_drawer_fan.get_model(platform_api_conn, j ,i) if self.expect(model is not None, "Unable to retrieve fan drawer {} fan {} model".format(j, i)): self.expect(isinstance(model, STRING_TYPE), "Fan drawer {} fan {} model appears incorrect".format(j, i)) self.assert_expectations()
def test_get_name(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): duthost = duthosts[enum_rand_one_per_hwsku_hostname] for j in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, j) for i in range(num_fans): name = fan_drawer_fan.get_name(platform_api_conn, j ,i) if self.expect(name is not None, "Unable to retrieve fan drawer {} fan {} name".format(j, i)): self.expect(isinstance(name, STRING_TYPE), "fan drawer {} fan {} name appears incorrect".format(j, i)) self.compare_value_with_platform_facts(duthost, 'name', name, j, i) self.assert_expectations()
def test_set_fans_speed(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): duthost = duthosts[enum_rand_one_per_hwsku_hostname] fan_drawers_skipped = 0 for j in range(self.num_fan_drawers): target_speed = random.randint(1, 100) num_fans = fan_drawer.get_num_fans(platform_api_conn, j) fans_skipped = 0 for i in range(num_fans): speed_controllable = self.get_fan_facts( duthost, j, i, True, "speed", "controllable") if not speed_controllable: logger.info( "test_set_fans_speed: Skipping fandrawer {} fan {} (speed not controllable)" .format(j, i)) fans_skipped += 1 continue speed_minimum = self.get_fan_facts(duthost, j, i, 1, "speed", "minimum") speed_maximum = self.get_fan_facts(duthost, j, i, 100, "speed", "maximum") if speed_minimum > target_speed or speed_maximum < target_speed: target_speed = random.randint(speed_minimum, speed_maximum) speed = fan_drawer_fan.get_speed(platform_api_conn, j, i) speed_tol = fan_drawer_fan.get_speed_tolerance( platform_api_conn, j, i) speed_set = fan_drawer_fan.set_speed(platform_api_conn, j, i, target_speed) time.sleep(5) act_speed = fan_drawer_fan.get_speed(platform_api_conn, j, i) self.expect( abs(act_speed - target_speed) <= speed_tol, "Fan drawer {} fan {} speed change from {} to {} is not within tolerance, actual speed {}" .format(j, i, speed, target_speed, act_speed)) if fans_skipped == num_fans: fan_drawers_skipped += 1 if fan_drawers_skipped == self.num_fan_drawers: pytest.skip( "skipped as all fandrawer fans' speed is not controllable") self.assert_expectations()
def test_get_speed(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): for j in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, j) for i in range(num_fans): # Ensure the fan speed is sane speed = fan_drawer_fan.get_speed(platform_api_conn, j, i) if self.expect(speed is not None, "Unable to retrieve Fan drawer {} fan {} speed".format(j, i)): if self.expect(isinstance(speed, int), "Fan drawer {} fan {} speed appears incorrect".format(j, i)): self.expect(speed > 0 and speed <= 100, "Fan drawer {} fan {} speed {} reading is not within range".format(j , i, speed)) self.assert_expectations()
def test_set_fans_led(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): duthost = duthosts[enum_rand_one_per_hwsku_hostname] FAULT_LED_COLOR_LIST = [STATUS_LED_COLOR_AMBER, STATUS_LED_COLOR_RED] NORMAL_LED_COLOR_LIST = [STATUS_LED_COLOR_GREEN] OFF_LED_COLOR_LIST = [STATUS_LED_COLOR_OFF] LED_COLOR_TYPES = [] LED_COLOR_TYPES.append(FAULT_LED_COLOR_LIST) LED_COLOR_TYPES.append(NORMAL_LED_COLOR_LIST) # Mellanox is not supporting set leds to 'off' if duthost.facts.get("asic_type") != "mellanox": LED_COLOR_TYPES.append(OFF_LED_COLOR_LIST) LED_COLOR_TYPES_DICT = {0: "fault", 1: "normal", 2: "off"} for j in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, j) for i in range(num_fans): for index, led_type in enumerate(LED_COLOR_TYPES): led_type_result = False for color in led_type: result = fan_drawer_fan.set_status_led( platform_api_conn, j, i, color) if self.expect(result is not None, "Failed to perform set_status_led"): led_type_result = result or led_type_result if ((result is None) or (not result)): continue color_actual = fan_drawer_fan.get_status_led( platform_api_conn, j, i) if self.expect(color_actual is not None, "Failed to retrieve status_led"): if self.expect( isinstance(color_actual, STRING_TYPE), "Status LED color appears incorrect"): self.expect( color == color_actual, "Status LED color incorrect (expected: {}, actual: {} for fan {})" .format(color, color_actual, i)) self.expect( result is True, "Failed to set status_led for fan drawer {} fan {} to {}" .format(j, i, LED_COLOR_TYPES_DICT[index])) self.assert_expectations()
def test_get_presence(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): for j in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, j) for i in range(num_fans): name = fan_drawer_fan.get_name(platform_api_conn, j ,i) presence = fan_drawer_fan.get_presence(platform_api_conn, j, i) if self.expect(presence is not None, "Unable to retrieve fan drawer {} fan {} presence".format(j, i)): if self.expect(isinstance(presence, bool), "Fan drawer {} fan {} presence appears incorrect".format(j, i)): self.expect(presence is True, "Fan {} is not present".format(j, i)) self.assert_expectations()
def test_get_num_fans(self, duthost, localhost, platform_api_conn): for i in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, i) if self.expect( num_fans is not None, "Unable to retrieve fan_drawer {} number of fans".format( i)): self.expect( isinstance(num_fans, int), "fan drawer {} number of fans appear to be incorrect". format(i)) if self.fan_drawer_truth: self.expect( name == self.fan_drawer_truth[i]['num_fans'], "Fan_drawer {} num_fans does not match, expected num_fans {}" .format(i, self.fan_drawer_truth[i]['num_fans'])) self.assert_expectations()
def test_set_fans_speed(self, duthost, localhost, platform_api_conn): for j in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, j) target_speed = random.randint(1, 100) for i in range(num_fans): speed = fan_drawer_fan.get_speed(platform_api_conn, j, i) speed_tol = fan_drawer_fan.get_speed_tolerance(platform_api_conn, j, i) speed_set = fan_drawer_fan.set_speed(platform_api_conn, j, i, target_speed) time.sleep(5) act_speed = fan_drawer_fan.get_speed(platform_api_conn, j, i) self.expect(abs(act_speed - target_speed) <= speed_tol, "Fan drawer {} fan {} speed change from {} to {} is not within tolerance, actual speed {}".format(j, i, speed, target_speed, act_speed)) self.assert_expectations()
def test_set_fans_led(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): duthost = duthosts[enum_rand_one_per_hwsku_hostname] FAULT_LED_COLOR_LIST = [STATUS_LED_COLOR_AMBER, STATUS_LED_COLOR_RED] NORMAL_LED_COLOR_LIST = [STATUS_LED_COLOR_GREEN] OFF_LED_COLOR_LIST = [STATUS_LED_COLOR_OFF] LED_COLOR_TYPES = [] LED_COLOR_TYPES.append(FAULT_LED_COLOR_LIST) LED_COLOR_TYPES.append(NORMAL_LED_COLOR_LIST) # Mellanox is not supporting set leds to 'off' if duthost.facts.get("asic_type") != "mellanox": LED_COLOR_TYPES.append(OFF_LED_COLOR_LIST) LED_COLOR_TYPES_DICT = {0: "fault", 1: "normal", 2: "off"} fan_drawers_skipped = 0 for j in range(self.num_fan_drawers): num_fans = fan_drawer.get_num_fans(platform_api_conn, j) fans_skipped = 0 for i in range(num_fans): led_controllable = self.get_fan_facts(duthost, j, i, True, "status_led", "controllable") led_supported_colors = self.get_fan_facts( duthost, j, i, None, "status_led", "colors") if led_controllable: led_type_skipped = 0 for index, led_type in enumerate(LED_COLOR_TYPES): if led_supported_colors: led_type = set(led_type) & set( led_supported_colors) if not led_type: logger.warning( "test_status_led: Skipping fandrawer {} fan {} set status_led to {} (No supported colors)" .format(j, i, LED_COLOR_TYPES_DICT[index])) led_type_skipped += 1 continue led_type_result = False for color in led_type: result = fan_drawer_fan.set_status_led( platform_api_conn, j, i, color) if self.expect(result is not None, "Failed to perform set_status_led"): led_type_result = result or led_type_result if ((result is None) or (not result)): continue color_actual = fan_drawer_fan.get_status_led( platform_api_conn, j, i) if self.expect(color_actual is not None, "Failed to retrieve status_led"): if self.expect( isinstance(color_actual, STRING_TYPE), "Status LED color appears incorrect"): self.expect( color == color_actual, "Status LED color incorrect (expected: {}, actual: {} for fan {})" .format(color, color_actual, i)) self.expect( result is True, "Failed to set status_led for fan drawer {} fan {} to {}" .format(j, i, LED_COLOR_TYPES_DICT[index])) if led_type_skipped == len(LED_COLOR_TYPES): logger.info( "test_status_led: Skipping fandrawer {} fan {} (no supported colors for all types)" .format(j, i)) fans_skipped += 1 else: logger.info( "test_status_led: Skipping fandrawer {} fan {} (LED is not controllable)" .format(j, i)) fans_skipped += 1 if fans_skipped == num_fans: fan_drawers_skipped += 1 if fan_drawers_skipped == self.num_fan_drawers: pytest.skip( "skipped as all fandrawer fans' LED is not controllable/no supported colors" ) self.assert_expectations()