From be19cbf28afd0b774ca5090dda40e3e9541aec5d Mon Sep 17 00:00:00 2001 From: Gonzalo Rafuls Date: Fri, 27 Oct 2023 16:20:32 +0200 Subject: [PATCH 1/7] fix: non blocking or failing on --host-list closes: https://github.com/redhat-performance/badfish/issues/388 --- src/badfish/main.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/badfish/main.py b/src/badfish/main.py index 01a2539..fd1263c 100755 --- a/src/badfish/main.py +++ b/src/badfish/main.py @@ -649,7 +649,11 @@ async def get_power_consumed_watts(self): data = json.loads(raw.strip()) except ValueError: raise BadfishException("Power value outside operating range.") - self.logger.info(f"Current watts consumed: {data['PowerControl'][0]['PowerConsumedWatts']}") + try: + cwc = {data['PowerControl'][0]['PowerConsumedWatts']} + except IndexError: + cwc = "N/A. Try to `--racreset`." + self.logger.info(f"Current watts consumed: {cwc}") return async def change_boot(self, host_type, interfaces_path, pxe=False): @@ -2689,10 +2693,13 @@ def main(argv=None): result = True bfl.logger.info("RESULTS:") for res in results: - if len(res) > 1 and res[1]: - bfl.logger.info(f"{res[0]}: SUCCESSFUL") - else: - bfl.logger.info(f"{res[0]}: FAILED") + try: + if len(res) > 1 and res[1]: + bfl.logger.info(f"{res[0]}: SUCCESSFUL") + else: + bfl.logger.info(f"{res[0]}: FAILED") + except Exception as ex: + bfl.logger.debug(str(ex)) result = False elif not host: bfl.logger.error("You must specify at least either a host (-H) or a host list (--host-list).") From ad5e8924706f164926e56cb2b65ccaee9c5daf68 Mon Sep 17 00:00:00 2001 From: Gonzalo Rafuls Date: Fri, 27 Oct 2023 16:26:24 +0200 Subject: [PATCH 2/7] fix: string formatting on power consumed --- src/badfish/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/badfish/main.py b/src/badfish/main.py index fd1263c..876fc02 100755 --- a/src/badfish/main.py +++ b/src/badfish/main.py @@ -650,7 +650,7 @@ async def get_power_consumed_watts(self): except ValueError: raise BadfishException("Power value outside operating range.") try: - cwc = {data['PowerControl'][0]['PowerConsumedWatts']} + cwc = data['PowerControl'][0]['PowerConsumedWatts'] except IndexError: cwc = "N/A. Try to `--racreset`." self.logger.info(f"Current watts consumed: {cwc}") From 782901de25b0fa6e5d4e81a7fdb00739e1baff9f Mon Sep 17 00:00:00 2001 From: Gonzalo Rafuls Date: Fri, 27 Oct 2023 16:38:11 +0200 Subject: [PATCH 3/7] tests: added no power avaiable --- tests/config.py | 2 ++ tests/test_power_consumed_watts.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/config.py b/tests/config.py index f8d385c..a3379a5 100644 --- a/tests/config.py +++ b/tests/config.py @@ -170,7 +170,9 @@ def render_device_dict(index, device): ) # test_power_consumed_watts POWER_CONSUMED_RESP = '{"PowerControl":[{"PowerConsumedWatts":"69"}]}' +NO_POWER = '{}' RESPONSE_POWER_CONSUMED_OK = '- INFO - Current watts consumed: 69\n' +RESPONSE_NO_POWER_CONSUMED = '- INFO - Current watts consumed: N/A. Try to `--racreset`.\n' RESPONSE_POWER_CONSUMED_404 = '- ERROR - Operation not supported by vendor.\n' RESPONSE_POWER_CONSUMED_VAL_ERR = '- ERROR - Power value outside operating range.\n' # test_reset_%s diff --git a/tests/test_power_consumed_watts.py b/tests/test_power_consumed_watts.py index 636a3f3..a68b5f7 100644 --- a/tests/test_power_consumed_watts.py +++ b/tests/test_power_consumed_watts.py @@ -1,6 +1,6 @@ from asynctest import patch from tests.config import ( - INIT_RESP, POWER_CONSUMED_RESP, RESPONSE_POWER_CONSUMED_OK, RESPONSE_POWER_CONSUMED_404, + INIT_RESP, NO_POWER, POWER_CONSUMED_RESP, RESPONSE_NO_POWER_CONSUMED, RESPONSE_POWER_CONSUMED_OK, RESPONSE_POWER_CONSUMED_404, RESPONSE_POWER_CONSUMED_VAL_ERR, ) @@ -31,6 +31,17 @@ def test_power_consumed_404(self, mock_get, mock_post, mock_delete): _, err = self.badfish_call() assert err == RESPONSE_POWER_CONSUMED_404 + @patch("aiohttp.ClientSession.delete") + @patch("aiohttp.ClientSession.post") + @patch("aiohttp.ClientSession.get") + def test_no_power(self, mock_get, mock_post, mock_delete): + responses = INIT_RESP + [NO_POWER] + self.set_mock_response(mock_get,[200,200,200,200,200,404], responses) + self.set_mock_response(mock_post, 200, "OK", True) + self.set_mock_response(mock_delete, 200, "OK") + _, err = self.badfish_call() + assert err == RESPONSE_NO_POWER_CONSUMED + @patch("aiohttp.ClientSession.delete") @patch("aiohttp.ClientSession.post") @patch("aiohttp.ClientSession.get") From 6f4b11cc50561846fec7fe9b794f34b8ce2944a2 Mon Sep 17 00:00:00 2001 From: Gonzalo Rafuls Date: Fri, 27 Oct 2023 16:45:07 +0200 Subject: [PATCH 4/7] tests: fix for test_no_power --- tests/config.py | 2 +- tests/test_power_consumed_watts.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/config.py b/tests/config.py index a3379a5..08685e8 100644 --- a/tests/config.py +++ b/tests/config.py @@ -170,7 +170,7 @@ def render_device_dict(index, device): ) # test_power_consumed_watts POWER_CONSUMED_RESP = '{"PowerControl":[{"PowerConsumedWatts":"69"}]}' -NO_POWER = '{}' +NO_POWER = '{"PowerControl":[]}' RESPONSE_POWER_CONSUMED_OK = '- INFO - Current watts consumed: 69\n' RESPONSE_NO_POWER_CONSUMED = '- INFO - Current watts consumed: N/A. Try to `--racreset`.\n' RESPONSE_POWER_CONSUMED_404 = '- ERROR - Operation not supported by vendor.\n' diff --git a/tests/test_power_consumed_watts.py b/tests/test_power_consumed_watts.py index a68b5f7..eb515d7 100644 --- a/tests/test_power_consumed_watts.py +++ b/tests/test_power_consumed_watts.py @@ -25,7 +25,7 @@ def test_power_consumed(self, mock_get, mock_post, mock_delete): @patch("aiohttp.ClientSession.get") def test_power_consumed_404(self, mock_get, mock_post, mock_delete): responses = INIT_RESP + [POWER_CONSUMED_RESP] - self.set_mock_response(mock_get,[200,200,200,200,200,404], responses) + self.set_mock_response(mock_get, [200,200,200,200,200,404], responses) self.set_mock_response(mock_post, 200, "OK", True) self.set_mock_response(mock_delete, 200, "OK") _, err = self.badfish_call() @@ -36,7 +36,7 @@ def test_power_consumed_404(self, mock_get, mock_post, mock_delete): @patch("aiohttp.ClientSession.get") def test_no_power(self, mock_get, mock_post, mock_delete): responses = INIT_RESP + [NO_POWER] - self.set_mock_response(mock_get,[200,200,200,200,200,404], responses) + self.set_mock_response(mock_get, 200, responses) self.set_mock_response(mock_post, 200, "OK", True) self.set_mock_response(mock_delete, 200, "OK") _, err = self.badfish_call() @@ -48,7 +48,7 @@ def test_no_power(self, mock_get, mock_post, mock_delete): def test_power_consumed_value_error(self, mock_get, mock_post, mock_delete): responses_add = [""] responses = INIT_RESP + responses_add - self.set_mock_response(mock_get,200, responses) + self.set_mock_response(mock_get, 200, responses) self.set_mock_response(mock_post, 200, "OK", True) self.set_mock_response(mock_delete, 200, "OK") _, err = self.badfish_call() From 88acd3d5cb2efbf26fe8bb84ee1111c0c25c2dff Mon Sep 17 00:00:00 2001 From: Gonzalo Rafuls Date: Tue, 31 Oct 2023 13:34:22 +0100 Subject: [PATCH 5/7] fix: removed try catch --- src/badfish/main.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/badfish/main.py b/src/badfish/main.py index 876fc02..cb91626 100755 --- a/src/badfish/main.py +++ b/src/badfish/main.py @@ -2693,13 +2693,10 @@ def main(argv=None): result = True bfl.logger.info("RESULTS:") for res in results: - try: - if len(res) > 1 and res[1]: - bfl.logger.info(f"{res[0]}: SUCCESSFUL") - else: - bfl.logger.info(f"{res[0]}: FAILED") - except Exception as ex: - bfl.logger.debug(str(ex)) + if len(res) > 1 and res[1]: + bfl.logger.info(f"{res[0]}: SUCCESSFUL") + else: + bfl.logger.info(f"{res[0]}: FAILED") result = False elif not host: bfl.logger.error("You must specify at least either a host (-H) or a host list (--host-list).") From 428a233b76371728048420e28597b5c4bbbf6ec1 Mon Sep 17 00:00:00 2001 From: Gonzalo Rafuls Date: Tue, 31 Oct 2023 13:44:51 +0100 Subject: [PATCH 6/7] fix: moved pr template to the correct dir --- .../pull_request_template.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{ISSUE_TEMPLATE => PULL_REQUEST_TEMPLATE}/pull_request_template.md (100%) diff --git a/.github/ISSUE_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md similarity index 100% rename from .github/ISSUE_TEMPLATE/pull_request_template.md rename to .github/PULL_REQUEST_TEMPLATE/pull_request_template.md From d055a8301dbeec7f1d09f00534fc3d930beb95cf Mon Sep 17 00:00:00 2001 From: Gonzalo Rafuls Date: Tue, 31 Oct 2023 13:55:08 +0100 Subject: [PATCH 7/7] fix: codecov tokenized --- .github/workflows/codecov.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index a3ec604..ebd375f 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -24,6 +24,7 @@ jobs: - name: Upload coverage to Codecov uses: codecov/codecov-action@v2 with: + token: ${{ secrets.CODECOV_TOKEN }} files: ./coverage.xml env_vars: PYTHON flags: unittests