Skip to content

Commit

Permalink
Merge pull request #390 from redhat-performance/development
Browse files Browse the repository at this point in the history
* Sync latest fixes for power management consumption
* Add more testing coverage
* Fix for PR template
  • Loading branch information
sadsfae authored Nov 2, 2023
2 parents 15ce5c9 + 4b62063 commit c2d4696
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/badfish/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions tests/test_power_consumed_watts.py
Original file line number Diff line number Diff line change
@@ -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,

)
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions tests/test_scp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit c2d4696

Please sign in to comment.