Skip to content

Commit

Permalink
Merge pull request #464 from flyingcircusio/463-host-requirement-erro…
Browse files Browse the repository at this point in the history
…r-message

Improve error message when host requirement not satisfied
  • Loading branch information
zagy authored Aug 6, 2024
2 parents 66552c2 + ad0c514 commit ec76991
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
## 2.5.0b4 (unreleased)
-----------------------

- Nothing changed yet.
- Fix unsatisfied resource message if a host-specific resource is not
satisfied. (#463)


## 2.5.0b3 (2024-08-05)
Expand Down
18 changes: 17 additions & 1 deletion src/batou/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,23 @@ def unused(self):

@property
def unsatisfied(self):
return set(self.strict_subscribers) - set(self.resources)
unsatisfied = set()
for key, subscribers in list(self.subscribers.items()):
if not any(s.strict for s in subscribers):
continue
if key not in self.resources:
unsatisfied.add(key)
continue
for s in subscribers:
if s.host is None:
continue
if not any(
resource_root.host is s.host
for resource_root in self.resources[key]
):
unsatisfied.add(key)
break
return unsatisfied

@property
def unsatisfied_components(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,14 @@ class Unused(Component):
class BadUnused(Component):
def configure(self):
Unused()


class Component1(Component):
def configure(self):
self.hello = self.require_one("key", host=self.host)
self.require("unrelated")


class Component2(Component):
def configure(self):
self.provide("key", "value")
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[hosts]
host1 = component1
host2 = component1, component2
6 changes: 4 additions & 2 deletions src/batou/tests/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ def test_provider_with_consumer_limited_by_host_raises_error(env):
env.add_root("provider", Host("test2", env))
env.add_root("samehostconsumer", Host("test", env))
errors = env.configure()
assert len(errors) == 1
assert isinstance(errors[0], UnusedResources)
assert len(errors) == 3
assert isinstance(errors[0], UnsatisfiedResources)
assert isinstance(errors[1], NonConvergingWorkingSet)
assert isinstance(errors[2], UnusedResources)


def test_consumer_retrieves_value_from_provider_order2(env):
Expand Down
12 changes: 12 additions & 0 deletions src/batou/tests/test_resources.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import mock

from batou import NonConvergingWorkingSet, UnsatisfiedResources
from batou.environment import Environment
from batou.resources import Resources


Expand All @@ -23,3 +25,13 @@ def test_reset_marks_depending_components_as_dirty():
assert resources.dirty_dependencies == set()
resources.reset_component_resources(root1)
assert resources.dirty_dependencies == set([root2])


def test_mentions_missing_requirement_with_host_requirement(sample_service):
e = Environment("test-resources-host")
e.load()
errors = e.configure()
assert len(errors) == 2
assert isinstance(errors[0], UnsatisfiedResources)
assert isinstance(errors[1], NonConvergingWorkingSet)
assert "key" in str(errors[0].__dict__)

0 comments on commit ec76991

Please sign in to comment.