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 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 diff --git a/src/badfish/main.py b/src/badfish/main.py index 01a2539..ac51379 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): diff --git a/tests/config.py b/tests/config.py index f8d385c..08685e8 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 = '{"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' 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..eb515d7 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, ) @@ -25,19 +25,30 @@ 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() 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, 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") 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() diff --git a/tests/test_scp.py b/tests/test_scp.py index 2d0bc73..272ce37 100644 --- a/tests/test_scp.py +++ b/tests/test_scp.py @@ -113,6 +113,7 @@ class TestExportSCP(TestBase): tests_dir = os.path.dirname(__file__) example_path = os.path.join(tests_dir, "fixtures/example_scp.json") + @patch("badfish.helpers.get_now", fixed_datetime) @patch("aiohttp.ClientSession.delete") @patch("aiohttp.ClientSession.post") @patch("aiohttp.ClientSession.get")