Skip to content

Commit

Permalink
Merge pull request #175 from MatterMiners/fix/168
Browse files Browse the repository at this point in the history
Fixing rare `ValueError`s in `get_resource_ratios`
  • Loading branch information
giffels authored Mar 24, 2021
2 parents d989653 + b5fb4f5 commit b83eace
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
5 changes: 3 additions & 2 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.. Created by changelog.py at 2021-03-23, command
.. Created by changelog.py at 2021-03-24, command
'/Users/giffler/.cache/pre-commit/repor6pnmwlm/py_env-python3.9/bin/changelog docs/source/changes compile --output=docs/source/changelog.rst'
based on the format of 'https://keepachangelog.com/'
#########
CHANGELOG
#########

[Unreleased] - 2021-03-23
[Unreleased] - 2021-03-24
=========================

Added
Expand All @@ -17,6 +17,7 @@ Added
Fixed
-----

* Fixes a bug that get_resource_ratios raised a ValueError
* Fixes a bug that the drone_minimum_lifetime parameter is not working as described in the documentation
* Fixes a bug in the HTCondor Site Adapter which leads to wrong requirements when using non HTCondor OBS

Expand Down
10 changes: 10 additions & 0 deletions docs/source/changes/175.fix_resource_ratios.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
category: fixed
summary: "Fixes a bug that get_resource_ratios raised a ValueError"
description: |
In case one of the resource ratios is `undefined` or even has the value `error`
a `ValueError` or `TypeError` could occur. In case one of those errors occurs,
an empty list is returned.
pull requests:
- 175
issues:
- 168
9 changes: 4 additions & 5 deletions tardis/adapters/batchsystems/htcondor.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,13 @@ async def get_resource_ratios(self, drone_uuid: str) -> Iterable[float]:
await self._htcondor_status.update_status()
try:
htcondor_status = self._htcondor_status[drone_uuid]
except KeyError:
return {}
else:
return (
return [
float(value)
for key, value in htcondor_status.items()
if key in self.ratios.keys()
)
]
except (KeyError, ValueError, TypeError):
return []

async def get_allocation(self, drone_uuid: str) -> float:
"""
Expand Down
23 changes: 22 additions & 1 deletion tests/adapters_t/batchsystems_t/test_htcondor.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def setUp(self):
f"test_drained\tslot1@test\tDrained\tIdle\tundefined\t{self.cpu_ratio}\t{self.memory_ratio}", # noqa: B950
f"test_owner\tslot1@test\tOwner\tIdle\tundefined\t{self.cpu_ratio}\t{self.memory_ratio}", # noqa: B950
f"test_uuid_plus\tslot1@test_uuid@test\tUnclaimed\tIdle\ttest_uuid\t{self.cpu_ratio}\t{self.memory_ratio}", # noqa: B950
f"test_undefined\tslot1@test\tUnclaimed\tIdle\tundefined\tundefined\t{self.memory_ratio}", # noqa: B950
f"test_error\tslot1@test\tUnclaimed\tIdle\tundefined\terror\t{self.memory_ratio}", # noqa: B950
"exoscale-26d361290f\tslot1@exoscale-26d361290f\tUnclaimed\tIdle\tundefined\t0.125\t0.125", # noqa: B950
]
)
Expand Down Expand Up @@ -151,12 +153,31 @@ def test_get_resource_ratios(self):
[self.cpu_ratio, self.memory_ratio],
)
self.mock_async_run_command.assert_called_with(self.command)
self.mock_async_run_command.reset_mock()

self.assertEqual(
run_async(
self.htcondor_adapter.get_resource_ratios, drone_uuid="not_exists"
),
{},
[],
)
self.mock_async_run_command.assert_not_called()
self.mock_async_run_command.reset_mock()

self.assertEqual(
run_async(
self.htcondor_adapter.get_resource_ratios, drone_uuid="test_undefined"
),
[],
)
self.mock_async_run_command.assert_not_called()
self.mock_async_run_command.reset_mock()

self.assertEqual(
run_async(
self.htcondor_adapter.get_resource_ratios, drone_uuid="test_error"
),
[],
)

def test_get_resource_ratios_without_options(self):
Expand Down

0 comments on commit b83eace

Please sign in to comment.