Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions tests/platform_tests/api/test_chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,19 +447,42 @@ def test_status_led(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost,
2: "off"
}

for index, led_type in enumerate(LED_COLOR_TYPES):
led_type_result = False
for color in led_type:
result = chassis.set_status_led(platform_api_conn, 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 = chassis.get_status_led(platform_api_conn)
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: {})".format(color, color_actual))
self.expect(led_type_result is True, "Failed to set status_led to {}".format(LED_COLOR_TYPES_DICT[index]))
led_controllable = True
led_supported_colors = []
if duthost.facts.get("chassis"):
status_led = duthost.facts.get("chassis").get("status_led")
if status_led:
led_controllable = status_led.get("controllable", True)
led_supported_colors = status_led.get("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 set status_led to {} (No supported colors)".format(LED_COLOR_TYPES_DICT[index]))
led_type_skipped += 1
continue

led_type_result = False
for color in led_type:
result = chassis.set_status_led(platform_api_conn, 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 = chassis.get_status_led(platform_api_conn)
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: {})".format(color, color_actual))
self.expect(led_type_result is True, "Failed to set status_led to {}".format(LED_COLOR_TYPES_DICT[index]))

if led_type_skipped == len(LED_COLOR_TYPES):
pytest.skip("skipped as no supported colors for all types")

else:
pytest.skip("skipped as chassis's status led is not controllable")

self.assert_expectations()

Expand Down
58 changes: 58 additions & 0 deletions tests/platform_tests/api/test_chassis_fans.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ def compare_value_with_platform_facts(self, duthost, key, value, fan_idx):
self.expect(value == expected_value,
"'{}' value is incorrect. Got '{}', expected '{}' for fan {}".format(key, value, expected_value, fan_idx))

def get_fan_facts(self, duthost, fan_idx, def_value, *keys):
if duthost.facts.get("chassis"):
fans = duthost.facts.get("chassis").get("fans")
if fans:
value = fans[fan_idx]
for key in keys:
value = value.get(key)
if value is None:
return def_value

return value

return def_value

#
# Functions to test methods inherited from DeviceBase class
Expand Down Expand Up @@ -168,15 +181,32 @@ def test_get_direction(self, duthosts, enum_rand_one_per_hwsku_hostname, localho

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]
fans_skipped = 0

for i in range(self.num_fans):
speed_target_val = 25
speed_controllable = self.get_fan_facts(duthost, i, True, "speed", "controllable")
if not speed_controllable:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens with platforms that does not support the capability query? Wouldn't this cause those platforms to be skipped as well?
Am I missing something perhaps??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind my comments... I see there is a default value involved with the call so it should be fine...

logger.info("test_get_fans_target_speed: Skipping chassis fan {} (speed not controllable)".format(i))
fans_skipped += 1
continue

speed_minimum = self.get_fan_facts(duthost, i, 25, "speed", "minimum")
speed_maximum = self.get_fan_facts(duthost, 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.set_speed(platform_api_conn, i, speed_target_val)
target_speed = fan.get_target_speed(platform_api_conn, i)
if self.expect(target_speed is not None, "Unable to retrieve Fan {} target speed".format(i)):
if self.expect(isinstance(target_speed, int), "Fan {} target speed appears incorrect".format(i)):
self.expect(target_speed == speed_target_val, "Fan {} target speed setting is not correct, speed_target_val {} target_speed = {}".format(
i, speed_target_val, target_speed))

if fans_skipped == self.num_fans:
pytest.skip("skipped as all chassis fans' speed is not controllable")

self.assert_expectations()

def test_get_fans_speed_tolerance(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn):
Expand All @@ -190,13 +220,26 @@ def test_get_fans_speed_tolerance(self, duthosts, enum_rand_one_per_hwsku_hostna
self.assert_expectations()

def test_set_fans_speed(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn):

fans_skipped = 0
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
if duthost.facts["asic_type"] in ["cisco-8000"]:
target_speed = random.randint(40, 60)
else:
target_speed = random.randint(1, 100)

for i in range(self.num_fans):
speed_controllable = self.get_fan_facts(duthost, i, True, "speed", "controllable")
if not speed_controllable:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as my previous comment for platforms that does not support capability what happens? it will also be skipped? then that would be wrong right? it should check if platform does not support capability query yet should not be skipped??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind my comments... I see there is a default value involved with the call so it should be fine...

logger.info("test_set_fans_speed: Skipping chassis fan {} (speed not controllable)".format(i))
fans_skipped += 1
continue

speed_minimum = self.get_fan_facts(duthost, i, 1, "speed", "minimum")
speed_maximum = self.get_fan_facts(duthost, i, 100, "speed", "maximum")
if speed_minimum > target_speed or speed_maximum < target_speed:
target_speed = random.randint(speed_minimum, speed_maximum)

speed = fan.get_speed(platform_api_conn, i)
speed_tol = fan.get_speed_tolerance(platform_api_conn, i)

Expand All @@ -207,6 +250,9 @@ def test_set_fans_speed(self, duthosts, enum_rand_one_per_hwsku_hostname, localh
self.expect(abs(act_speed - target_speed) <= speed_tol,
"Fan {} speed change from {} to {} is not within tolerance, actual speed {}".format(i, speed, target_speed, act_speed))

if fans_skipped == self.num_fans:
pytest.skip("skipped as all chassis fans' speed is not controllable")

self.assert_expectations()

def test_set_fans_led(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn):
Expand All @@ -216,8 +262,17 @@ def test_set_fans_led(self, duthosts, enum_rand_one_per_hwsku_hostname, localhos
"amber",
"green",
]
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
fans_skipped = 0

for i in range(self.num_fans):
led_controllable = self.get_fan_facts(duthost, i, True, "status_led", "controllable")
if not led_controllable:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for platform that does not support capability query this check will cause their tests be skipped as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind my comments... I see there is a default value involved with the call so it should be fine...

logger.info("test_set_fans_led: Skipping chassis fan {} (LED not controllable)".format(i))
fans_skipped += 1
continue

LED_COLOR_LIST = self.get_fan_facts(duthost, i, LED_COLOR_LIST, "status_led", "colors")
for color in LED_COLOR_LIST:

result = fan.set_status_led(platform_api_conn, i, color)
Expand All @@ -231,4 +286,7 @@ def test_set_fans_led(self, duthosts, enum_rand_one_per_hwsku_hostname, localhos
self.expect(color == color_actual, "Status LED color incorrect (expected: {}, actual: {} for fan {})".format(
color, color_actual, i))

if fans_skipped == self.num_fans:
pytest.skip("skipped as all chassis fans' LED is not controllable")

self.assert_expectations()
67 changes: 53 additions & 14 deletions tests/platform_tests/api/test_fan_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ def compare_value_with_platform_facts(self, duthost, key, value, fan_drawer_idx)
self.expect(value == expected_value,
"'{}' value is incorrect. Got '{}', expected '{}' for fan drawer {}".format(key, value, expected_value, fan_drawer_idx))

def get_fan_drawer_facts(self, duthost, fan_drawer_idx, def_value, *keys):
if duthost.facts.get("chassis"):
fan_drawers = duthost.facts.get("chassis").get("fan_drawers")
if fan_drawers:
value = fan_drawers[fan_drawer_idx]
for key in keys:
value = value.get(key)
if value is None:
return def_value

return value

return def_value

#
# Functions to test methods inherited from DeviceBase class
#
Expand Down Expand Up @@ -185,21 +199,46 @@ def test_set_fan_drawers_led(self, duthosts, enum_rand_one_per_hwsku_hostname, l
2: "off"
}

fan_drawers_skipped = 0
for i in range(self.num_fan_drawers):
for index, led_type in enumerate(LED_COLOR_TYPES):
led_type_result = False
for color in led_type:
result = fan_drawer.set_status_led(platform_api_conn, 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.get_status_led(platform_api_conn, 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_drawer {})".format(
color, color_actual, i))
self.expect(led_type_result is True, "Failed to set status_led for fan_drawer {} to {}".format(i, LED_COLOR_TYPES_DICT[index]))
led_controllable = self.get_fan_drawer_facts(duthost, i, True, "status_led", "controllable")
led_supported_colors = self.get_fan_drawer_facts(duthost, 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 {} set status_led to {} (No supported colors)".format(i, LED_COLOR_TYPES_DICT[index]))
led_type_skipped += 1
continue

led_type_result = False
for color in led_type:
result = fan_drawer.set_status_led(platform_api_conn, 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.get_status_led(platform_api_conn, 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_drawer {})".format(
color, color_actual, i))
self.expect(led_type_result is True, "Failed to set status_led for fan_drawer {} to {}".format(i, LED_COLOR_TYPES_DICT[index]))

if led_type_skipped == len(LED_COLOR_TYPES):
logger.info("test_status_led: Skipping fandrawer {} (no supported colors for all types)".format(i))
fan_drawers_skipped += 1

else:
logger.info("test_status_led: Skipping fandrawer {} (LED is not controllable)".format(i))
fan_drawers_skipped += 1

if fan_drawers_skipped == self.num_fan_drawers:
pytest.skip("skipped as all fandrawers' LED is not controllable/no supported colors")

self.assert_expectations()

def test_get_maximum_consumed_power(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn):
Expand Down
Loading