From b817d8ee4a26f849721356f98647a3d26e19829a Mon Sep 17 00:00:00 2001 From: smagarwal Date: Mon, 9 Sep 2024 15:52:17 +0000 Subject: [PATCH 1/6] Retry test_power calculated power above 10% If the test fails on `abs(power - (voltage*current)) < power*0.1` then retry the test. Test is repeated for a maximum of three times until it passes, else it is failed. This change is introduced to account for the stringent tolerance level of 10% and the errors that might be caused due to time differences reading each of the parameters. --- tests/platform_tests/api/test_psu.py | 129 ++++++++++++++------------- 1 file changed, 69 insertions(+), 60 deletions(-) diff --git a/tests/platform_tests/api/test_psu.py b/tests/platform_tests/api/test_psu.py index 877187b40d..00330eb15d 100644 --- a/tests/platform_tests/api/test_psu.py +++ b/tests/platform_tests/api/test_psu.py @@ -32,6 +32,7 @@ STATUS_LED_COLOR_AMBER = "amber" STATUS_LED_COLOR_RED = "red" STATUS_LED_COLOR_OFF = "off" +MAX_ATTEMPTS = 3 class TestPsuApi(PlatformApiTestBase): @@ -206,66 +207,74 @@ def test_power(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, plat skip_release_for_platform(duthost, ["202012", "201911", "201811"], ["arista"]) for psu_id in range(self.num_psus): - name = psu.get_name(platform_api_conn, psu_id) - if name in self.psu_skip_list: - logger.info("skipping check for {}".format(name)) - else: - voltage = None - voltage_supported = self.get_psu_facts(duthost, psu_id, True, "voltage") - if voltage_supported: - voltage = psu.get_voltage(platform_api_conn, psu_id) - if self.expect(voltage is not None, "Failed to retrieve voltage of PSU {}".format(psu_id)): - self.expect(isinstance(voltage, float), "PSU {} voltage appears incorrect".format(psu_id)) - current = None - current_supported = self.get_psu_facts(duthost, psu_id, True, "current") - if current_supported: - current = psu.get_current(platform_api_conn, psu_id) - if self.expect(current is not None, "Failed to retrieve current of PSU {}".format(psu_id)): - self.expect(isinstance(current, float), "PSU {} current appears incorrect".format(psu_id)) - power = None - power_supported = self.get_psu_facts(duthost, psu_id, True, "power") - if power_supported: - power = psu.get_power(platform_api_conn, psu_id) - if self.expect(power is not None, "Failed to retrieve power of PSU {}".format(psu_id)): - self.expect(isinstance(power, float), "PSU {} power appears incorrect".format(psu_id)) - max_supp_power = None - max_power_supported = self.get_psu_facts(duthost, psu_id, True, "max_power") - if max_power_supported: - max_supp_power = psu.get_maximum_supplied_power(platform_api_conn, psu_id) - if self.expect(max_supp_power is not None, - "Failed to retrieve maximum supplied power power of PSU {}".format(psu_id)): - self.expect(isinstance(max_supp_power, float), - "PSU {} maximum supplied power appears incorrect".format(psu_id)) - - if current is not None and voltage is not None and power is not None: - self.expect(abs(power - (voltage*current)) < power*0.1, "PSU {} reading does not make sense \ - (power:{}, voltage:{}, current:{})".format(psu_id, power, voltage, current)) - - powergood_status = psu.get_powergood_status(platform_api_conn, psu_id) - if self.expect(powergood_status is not None, - "Failed to retrieve operational status of PSU {}".format(psu_id)): - self.expect(powergood_status is True, "PSU {} is not operational".format(psu_id)) - - high_threshold = None - voltage_high_threshold_supported = self.get_psu_facts(duthost, psu_id, True, "voltage_high_threshold") - if voltage_high_threshold_supported: - high_threshold = psu.get_voltage_high_threshold(platform_api_conn, psu_id) - if self.expect(high_threshold is not None, - "Failed to retrieve the high voltage threshold of PSU {}".format(psu_id)): - self.expect(isinstance(high_threshold, float), - "PSU {} voltage high threshold appears incorrect".format(psu_id)) - low_threshold = None - voltage_low_threshold_supported = self.get_psu_facts(duthost, psu_id, True, "voltage_low_threshold") - if voltage_low_threshold_supported: - low_threshold = psu.get_voltage_low_threshold(platform_api_conn, psu_id) - if self.expect(low_threshold is not None, - "Failed to retrieve the low voltage threshold of PSU {}".format(psu_id)): - self.expect(isinstance(low_threshold, float), - "PSU {} voltage low threshold appears incorrect".format(psu_id)) - if high_threshold is not None and low_threshold is not None: - self.expect(voltage < high_threshold and voltage > low_threshold, - "Voltage {} of PSU {} is not in between {} and {}" - .format(voltage, psu_id, low_threshold, high_threshold)) + for i in range(0,MAX_ATTEMPTS): + name = psu.get_name(platform_api_conn, psu_id) + if name in self.psu_skip_list: + logger.info("skipping check for {}".format(name)) + else: + voltage = None + voltage_supported = self.get_psu_facts(duthost, psu_id, True, "voltage") + if voltage_supported: + voltage = psu.get_voltage(platform_api_conn, psu_id) + if self.expect(voltage is not None, "Failed to retrieve voltage of PSU {}".format(psu_id)): + self.expect(isinstance(voltage, float), "PSU {} voltage appears incorrect".format(psu_id)) + current = None + current_supported = self.get_psu_facts(duthost, psu_id, True, "current") + if current_supported: + current = psu.get_current(platform_api_conn, psu_id) + if self.expect(current is not None, "Failed to retrieve current of PSU {}".format(psu_id)): + self.expect(isinstance(current, float), "PSU {} current appears incorrect".format(psu_id)) + power = None + power_supported = self.get_psu_facts(duthost, psu_id, True, "power") + if power_supported: + power = psu.get_power(platform_api_conn, psu_id) + if self.expect(power is not None, "Failed to retrieve power of PSU {}".format(psu_id)): + self.expect(isinstance(power, float), "PSU {} power appears incorrect".format(psu_id)) + max_supp_power = None + max_power_supported = self.get_psu_facts(duthost, psu_id, True, "max_power") + if max_power_supported: + max_supp_power = psu.get_maximum_supplied_power(platform_api_conn, psu_id) + if self.expect(max_supp_power is not None, + "Failed to retrieve maximum supplied power of PSU {}".format(psu_id)): + self.expect(isinstance(max_supp_power, float), + "PSU {} maximum supplied power appears incorrect".format(psu_id)) + + if current is not None and voltage is not None and power is not None: + is_within_tolerance = abs(power - (voltage*current)) < power*0.1 + if not is_within_tolerance and i < MAX_ATTEMPTS - 1: + logger.info("Retrying test for {} as readings not within tolerance level".format(name)) + continue + self.expect(is_within_tolerance, "PSU {} reading does not make sense \ + (power:{}, voltage:{}, current:{})".format(psu_id, power, voltage, current)) + + powergood_status = psu.get_powergood_status(platform_api_conn, psu_id) + if self.expect(powergood_status is not None, + "Failed to retrieve operational status of PSU {}".format(psu_id)): + self.expect(powergood_status is True, "PSU {} is not operational".format(psu_id)) + + high_threshold = None + voltage_high_threshold_supported = self.get_psu_facts(duthost, psu_id, True, "voltage_high_threshold") + if voltage_high_threshold_supported: + high_threshold = psu.get_voltage_high_threshold(platform_api_conn, psu_id) + if self.expect(high_threshold is not None, + "Failed to retrieve the high voltage threshold of PSU {}".format(psu_id)): + self.expect(isinstance(high_threshold, float), + "PSU {} voltage high threshold appears incorrect".format(psu_id)) + low_threshold = None + voltage_low_threshold_supported = self.get_psu_facts(duthost, psu_id, True, "voltage_low_threshold") + if voltage_low_threshold_supported: + low_threshold = psu.get_voltage_low_threshold(platform_api_conn, psu_id) + if self.expect(low_threshold is not None, + "Failed to retrieve the low voltage threshold of PSU {}".format(psu_id)): + self.expect(isinstance(low_threshold, float), + "PSU {} voltage low threshold appears incorrect".format(psu_id)) + if high_threshold is not None and low_threshold is not None: + self.expect(voltage < high_threshold and voltage > low_threshold, + "Voltage {} of PSU {} is not in between {} and {}" + .format(voltage, psu_id, low_threshold, high_threshold)) + + break + self.assert_expectations() def test_temperature(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): From e1aa4d5e2a58e5111c13f5cc8edd3cc5222a04ee Mon Sep 17 00:00:00 2001 From: smagarwal Date: Mon, 9 Sep 2024 15:52:17 +0000 Subject: [PATCH 2/6] Retry test_power.py::TestPsuApi::test_power if power above tolerance If the test fails on `abs(power - (voltage*current)) < power*0.1` then retry the test. The test is repeated for a maximum of three times until it passes. This change is introduced to account for the stringent tolerance level of 10% and the errors that might be caused due to time differences in reading each of the parameters. --- tests/platform_tests/api/test_psu.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/platform_tests/api/test_psu.py b/tests/platform_tests/api/test_psu.py index 00330eb15d..42cc56025d 100644 --- a/tests/platform_tests/api/test_psu.py +++ b/tests/platform_tests/api/test_psu.py @@ -207,7 +207,7 @@ def test_power(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, plat skip_release_for_platform(duthost, ["202012", "201911", "201811"], ["arista"]) for psu_id in range(self.num_psus): - for i in range(0,MAX_ATTEMPTS): + for i in range(0, MAX_ATTEMPTS): name = psu.get_name(platform_api_conn, psu_id) if name in self.psu_skip_list: logger.info("skipping check for {}".format(name)) @@ -235,7 +235,7 @@ def test_power(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, plat if max_power_supported: max_supp_power = psu.get_maximum_supplied_power(platform_api_conn, psu_id) if self.expect(max_supp_power is not None, - "Failed to retrieve maximum supplied power of PSU {}".format(psu_id)): + "Failed to retrieve maximum supplied power of PSU {}".format(psu_id)): self.expect(isinstance(max_supp_power, float), "PSU {} maximum supplied power appears incorrect".format(psu_id)) @@ -249,15 +249,16 @@ def test_power(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, plat powergood_status = psu.get_powergood_status(platform_api_conn, psu_id) if self.expect(powergood_status is not None, - "Failed to retrieve operational status of PSU {}".format(psu_id)): + "Failed to retrieve operational status of PSU {}".format(psu_id)): self.expect(powergood_status is True, "PSU {} is not operational".format(psu_id)) high_threshold = None - voltage_high_threshold_supported = self.get_psu_facts(duthost, psu_id, True, "voltage_high_threshold") + voltage_high_threshold_supported = self.get_psu_facts(duthost, psu_id, True, + "voltage_high_threshold") if voltage_high_threshold_supported: high_threshold = psu.get_voltage_high_threshold(platform_api_conn, psu_id) if self.expect(high_threshold is not None, - "Failed to retrieve the high voltage threshold of PSU {}".format(psu_id)): + "Failed to retrieve the high voltage threshold of PSU {}".format(psu_id)): self.expect(isinstance(high_threshold, float), "PSU {} voltage high threshold appears incorrect".format(psu_id)) low_threshold = None @@ -265,16 +266,16 @@ def test_power(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, plat if voltage_low_threshold_supported: low_threshold = psu.get_voltage_low_threshold(platform_api_conn, psu_id) if self.expect(low_threshold is not None, - "Failed to retrieve the low voltage threshold of PSU {}".format(psu_id)): + "Failed to retrieve the low voltage threshold of PSU {}".format(psu_id)): self.expect(isinstance(low_threshold, float), "PSU {} voltage low threshold appears incorrect".format(psu_id)) if high_threshold is not None and low_threshold is not None: self.expect(voltage < high_threshold and voltage > low_threshold, "Voltage {} of PSU {} is not in between {} and {}" .format(voltage, psu_id, low_threshold, high_threshold)) - + break - + self.assert_expectations() def test_temperature(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): From caacd065c9bd2746751499f4ca980a0eaf916b9e Mon Sep 17 00:00:00 2001 From: smagarwal Date: Tue, 8 Oct 2024 15:10:18 +0000 Subject: [PATCH 3/6] Add check to detect occurrence of a failure before power calculation --- tests/platform_tests/api/platform_api_test_base.py | 3 +++ tests/platform_tests/api/test_psu.py | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/platform_tests/api/platform_api_test_base.py b/tests/platform_tests/api/platform_api_test_base.py index 0550242eaa..cb183d1adc 100644 --- a/tests/platform_tests/api/platform_api_test_base.py +++ b/tests/platform_tests/api/platform_api_test_base.py @@ -30,3 +30,6 @@ def assert_expectations(self): # TODO: When we move to Python 3.3+, we can use self.failed_expectations.clear() instead del self.failed_expectations[:] pytest_assert(False, err_msg) + + def get_len_failed_expectations(self): + return len(self.failed_expectations) diff --git a/tests/platform_tests/api/test_psu.py b/tests/platform_tests/api/test_psu.py index 42cc56025d..f3c63c7e87 100644 --- a/tests/platform_tests/api/test_psu.py +++ b/tests/platform_tests/api/test_psu.py @@ -207,6 +207,8 @@ def test_power(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, plat skip_release_for_platform(duthost, ["202012", "201911", "201811"], ["arista"]) for psu_id in range(self.num_psus): + failure_count = self.get_len_failed_expectations() + failure_occured = False for i in range(0, MAX_ATTEMPTS): name = psu.get_name(platform_api_conn, psu_id) if name in self.psu_skip_list: @@ -238,10 +240,12 @@ def test_power(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, plat "Failed to retrieve maximum supplied power of PSU {}".format(psu_id)): self.expect(isinstance(max_supp_power, float), "PSU {} maximum supplied power appears incorrect".format(psu_id)) + + failure_occured = self.get_len_failed_expectations() > failure_count if current is not None and voltage is not None and power is not None: is_within_tolerance = abs(power - (voltage*current)) < power*0.1 - if not is_within_tolerance and i < MAX_ATTEMPTS - 1: + if not failure_occured and not is_within_tolerance and i < MAX_ATTEMPTS - 1: logger.info("Retrying test for {} as readings not within tolerance level".format(name)) continue self.expect(is_within_tolerance, "PSU {} reading does not make sense \ From 6928d80cf5c07bb92919d61a6c84973d2269993d Mon Sep 17 00:00:00 2001 From: smagarwal Date: Tue, 8 Oct 2024 15:45:03 +0000 Subject: [PATCH 4/6] Resolve pre-commit check issue --- tests/platform_tests/api/test_psu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/platform_tests/api/test_psu.py b/tests/platform_tests/api/test_psu.py index f3c63c7e87..c1a39b704b 100644 --- a/tests/platform_tests/api/test_psu.py +++ b/tests/platform_tests/api/test_psu.py @@ -240,7 +240,7 @@ def test_power(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, plat "Failed to retrieve maximum supplied power of PSU {}".format(psu_id)): self.expect(isinstance(max_supp_power, float), "PSU {} maximum supplied power appears incorrect".format(psu_id)) - + failure_occured = self.get_len_failed_expectations() > failure_count if current is not None and voltage is not None and power is not None: From 8b85062b1d46f20e35969b3e2a199005a69264ae Mon Sep 17 00:00:00 2001 From: smagarwal Date: Thu, 17 Oct 2024 14:56:26 +0000 Subject: [PATCH 5/6] Refactor test_power function to improve readability --- tests/platform_tests/api/test_psu.py | 71 ++++++++++------------------ 1 file changed, 26 insertions(+), 45 deletions(-) diff --git a/tests/platform_tests/api/test_psu.py b/tests/platform_tests/api/test_psu.py index c1a39b704b..fa87454a19 100644 --- a/tests/platform_tests/api/test_psu.py +++ b/tests/platform_tests/api/test_psu.py @@ -90,6 +90,16 @@ def skip_absent_psu(self, psu_num, platform_api_conn): return True return False + def get_psu_parameter(self, psu_info, psu_parameter, get_data, message): + data = None + is_supported = self.get_psu_facts(psu_info["duthost"], psu_info["psu_id"], True, psu_parameter) + if is_supported: + data = get_data(psu_info["api"], psu_info["psu_id"]) + if self.expect(data is not None, "Failed to retrieve {} of PSU {}".format(message, psu_info["psu_id"])): + self.expect(isinstance(data, float), "PSU {} {} appears incorrect".format(psu_info["psu_id"], message)) + + return data + # # Functions to test methods inherited from DeviceBase class # @@ -205,44 +215,24 @@ def test_power(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, plat ''' PSU power test ''' duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012", "201911", "201811"], ["arista"]) - for psu_id in range(self.num_psus): failure_count = self.get_len_failed_expectations() failure_occured = False + psu_info = { + "duthost": duthost, + "api": platform_api_conn, + "psu_id": psu_id + } for i in range(0, MAX_ATTEMPTS): name = psu.get_name(platform_api_conn, psu_id) if name in self.psu_skip_list: logger.info("skipping check for {}".format(name)) else: - voltage = None - voltage_supported = self.get_psu_facts(duthost, psu_id, True, "voltage") - if voltage_supported: - voltage = psu.get_voltage(platform_api_conn, psu_id) - if self.expect(voltage is not None, "Failed to retrieve voltage of PSU {}".format(psu_id)): - self.expect(isinstance(voltage, float), "PSU {} voltage appears incorrect".format(psu_id)) - current = None - current_supported = self.get_psu_facts(duthost, psu_id, True, "current") - if current_supported: - current = psu.get_current(platform_api_conn, psu_id) - if self.expect(current is not None, "Failed to retrieve current of PSU {}".format(psu_id)): - self.expect(isinstance(current, float), "PSU {} current appears incorrect".format(psu_id)) - power = None - power_supported = self.get_psu_facts(duthost, psu_id, True, "power") - if power_supported: - power = psu.get_power(platform_api_conn, psu_id) - if self.expect(power is not None, "Failed to retrieve power of PSU {}".format(psu_id)): - self.expect(isinstance(power, float), "PSU {} power appears incorrect".format(psu_id)) - max_supp_power = None - max_power_supported = self.get_psu_facts(duthost, psu_id, True, "max_power") - if max_power_supported: - max_supp_power = psu.get_maximum_supplied_power(platform_api_conn, psu_id) - if self.expect(max_supp_power is not None, - "Failed to retrieve maximum supplied power of PSU {}".format(psu_id)): - self.expect(isinstance(max_supp_power, float), - "PSU {} maximum supplied power appears incorrect".format(psu_id)) + voltage = self.get_psu_parameter(psu_info, "voltage", psu.get_voltage, "voltage") + current = self.get_psu_parameter(psu_info, "current", psu.get_current, "current") + power = self.get_psu_parameter(psu_info, "power", psu.get_power, "power") failure_occured = self.get_len_failed_expectations() > failure_count - if current is not None and voltage is not None and power is not None: is_within_tolerance = abs(power - (voltage*current)) < power*0.1 if not failure_occured and not is_within_tolerance and i < MAX_ATTEMPTS - 1: @@ -251,28 +241,19 @@ def test_power(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, plat self.expect(is_within_tolerance, "PSU {} reading does not make sense \ (power:{}, voltage:{}, current:{})".format(psu_id, power, voltage, current)) + self.get_psu_parameter(psu_info, "max_power", psu.get_maximum_supplied_power, + "maximum supplied power") + powergood_status = psu.get_powergood_status(platform_api_conn, psu_id) if self.expect(powergood_status is not None, "Failed to retrieve operational status of PSU {}".format(psu_id)): self.expect(powergood_status is True, "PSU {} is not operational".format(psu_id)) - high_threshold = None - voltage_high_threshold_supported = self.get_psu_facts(duthost, psu_id, True, - "voltage_high_threshold") - if voltage_high_threshold_supported: - high_threshold = psu.get_voltage_high_threshold(platform_api_conn, psu_id) - if self.expect(high_threshold is not None, - "Failed to retrieve the high voltage threshold of PSU {}".format(psu_id)): - self.expect(isinstance(high_threshold, float), - "PSU {} voltage high threshold appears incorrect".format(psu_id)) - low_threshold = None - voltage_low_threshold_supported = self.get_psu_facts(duthost, psu_id, True, "voltage_low_threshold") - if voltage_low_threshold_supported: - low_threshold = psu.get_voltage_low_threshold(platform_api_conn, psu_id) - if self.expect(low_threshold is not None, - "Failed to retrieve the low voltage threshold of PSU {}".format(psu_id)): - self.expect(isinstance(low_threshold, float), - "PSU {} voltage low threshold appears incorrect".format(psu_id)) + high_threshold = self.get_psu_parameter(psu_info, "voltage_high_threshold", + psu.get_voltage_high_threshold, "high voltage threshold") + low_threshold = self.get_psu_parameter(psu_info, "voltage_low_threshold", + psu.get_voltage_low_threshold, "low voltage threshold") + if high_threshold is not None and low_threshold is not None: self.expect(voltage < high_threshold and voltage > low_threshold, "Voltage {} of PSU {} is not in between {} and {}" From c52c7a78b268b7ad8005c96b7f418e11d25e6d51 Mon Sep 17 00:00:00 2001 From: smagarwal Date: Wed, 6 Nov 2024 17:25:41 +0000 Subject: [PATCH 6/6] Use wait_until function for retry --- tests/platform_tests/api/test_psu.py | 98 +++++++++++++++------------- 1 file changed, 53 insertions(+), 45 deletions(-) diff --git a/tests/platform_tests/api/test_psu.py b/tests/platform_tests/api/test_psu.py index fa87454a19..b9ad83b1ea 100644 --- a/tests/platform_tests/api/test_psu.py +++ b/tests/platform_tests/api/test_psu.py @@ -6,7 +6,7 @@ from tests.common.utilities import skip_release from tests.platform_tests.cli.util import get_skip_mod_list from .platform_api_test_base import PlatformApiTestBase -from tests.common.utilities import skip_release_for_platform +from tests.common.utilities import skip_release_for_platform, wait_until ################################################### @@ -32,7 +32,6 @@ STATUS_LED_COLOR_AMBER = "amber" STATUS_LED_COLOR_RED = "red" STATUS_LED_COLOR_OFF = "off" -MAX_ATTEMPTS = 3 class TestPsuApi(PlatformApiTestBase): @@ -215,51 +214,60 @@ def test_power(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, plat ''' PSU power test ''' duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012", "201911", "201811"], ["arista"]) + voltage = current = power = None + psu_info = { + "duthost": duthost, + "api": platform_api_conn, + "psu_id": None + } + + def check_psu_power(failure_count): + nonlocal voltage + nonlocal current + nonlocal power + voltage = self.get_psu_parameter(psu_info, "voltage", psu.get_voltage, "voltage") + current = self.get_psu_parameter(psu_info, "current", psu.get_current, "current") + power = self.get_psu_parameter(psu_info, "power", psu.get_power, "power") + + failure_occured = self.get_len_failed_expectations() > failure_count + if current and voltage and power: + is_within_tolerance = abs(power - (voltage*current)) < power*0.1 + if not failure_occured and not is_within_tolerance: + return False + + self.expect(is_within_tolerance, "PSU {} reading does not make sense \ + (power:{}, voltage:{}, current:{})".format(psu_id, power, voltage, current)) + + return True + for psu_id in range(self.num_psus): failure_count = self.get_len_failed_expectations() - failure_occured = False - psu_info = { - "duthost": duthost, - "api": platform_api_conn, - "psu_id": psu_id - } - for i in range(0, MAX_ATTEMPTS): - name = psu.get_name(platform_api_conn, psu_id) - if name in self.psu_skip_list: - logger.info("skipping check for {}".format(name)) - else: - voltage = self.get_psu_parameter(psu_info, "voltage", psu.get_voltage, "voltage") - current = self.get_psu_parameter(psu_info, "current", psu.get_current, "current") - power = self.get_psu_parameter(psu_info, "power", psu.get_power, "power") - - failure_occured = self.get_len_failed_expectations() > failure_count - if current is not None and voltage is not None and power is not None: - is_within_tolerance = abs(power - (voltage*current)) < power*0.1 - if not failure_occured and not is_within_tolerance and i < MAX_ATTEMPTS - 1: - logger.info("Retrying test for {} as readings not within tolerance level".format(name)) - continue - self.expect(is_within_tolerance, "PSU {} reading does not make sense \ - (power:{}, voltage:{}, current:{})".format(psu_id, power, voltage, current)) - - self.get_psu_parameter(psu_info, "max_power", psu.get_maximum_supplied_power, - "maximum supplied power") - - powergood_status = psu.get_powergood_status(platform_api_conn, psu_id) - if self.expect(powergood_status is not None, - "Failed to retrieve operational status of PSU {}".format(psu_id)): - self.expect(powergood_status is True, "PSU {} is not operational".format(psu_id)) - - high_threshold = self.get_psu_parameter(psu_info, "voltage_high_threshold", - psu.get_voltage_high_threshold, "high voltage threshold") - low_threshold = self.get_psu_parameter(psu_info, "voltage_low_threshold", - psu.get_voltage_low_threshold, "low voltage threshold") - - if high_threshold is not None and low_threshold is not None: - self.expect(voltage < high_threshold and voltage > low_threshold, - "Voltage {} of PSU {} is not in between {} and {}" - .format(voltage, psu_id, low_threshold, high_threshold)) - - break + psu_info['psu_id'] = psu_id + name = psu.get_name(platform_api_conn, psu_id) + if name in self.psu_skip_list: + logger.info("skipping check for {}".format(name)) + else: + check_result = wait_until(30, 10, 0, check_psu_power, failure_count) + self.expect(check_result, "PSU {} reading does not make sense \ + (power:{}, voltage:{}, current:{})".format(psu_id, power, voltage, current)) + + self.get_psu_parameter(psu_info, "max_power", psu.get_maximum_supplied_power, + "maximum supplied power") + + powergood_status = psu.get_powergood_status(platform_api_conn, psu_id) + if self.expect(powergood_status is not None, + "Failed to retrieve operational status of PSU {}".format(psu_id)): + self.expect(powergood_status is True, "PSU {} is not operational".format(psu_id)) + + high_threshold = self.get_psu_parameter(psu_info, "voltage_high_threshold", + psu.get_voltage_high_threshold, "high voltage threshold") + low_threshold = self.get_psu_parameter(psu_info, "voltage_low_threshold", + psu.get_voltage_low_threshold, "low voltage threshold") + + if high_threshold and low_threshold: + self.expect(voltage < high_threshold and voltage > low_threshold, + "Voltage {} of PSU {} is not in between {} and {}" + .format(voltage, psu_id, low_threshold, high_threshold)) self.assert_expectations()