-
Notifications
You must be signed in to change notification settings - Fork 1k
[Platform API]: Update test cases to make use of capabilities fields in platform.json #4332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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): | ||
|
|
@@ -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: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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??
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
||
|
|
@@ -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): | ||
|
|
@@ -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: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
@@ -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() | ||
Uh oh!
There was an error while loading. Please reload this page.