Skip to content

Commit

Permalink
fix behaviour of warning
Browse files Browse the repository at this point in the history
  • Loading branch information
elikoga committed Sep 10, 2024
1 parent fb7e9cf commit faeea24
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
10 changes: 6 additions & 4 deletions src/batou/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,19 +527,21 @@ class ComponentWithUpdateWithoutVerify(ConfigurationError):
sort_key = (5, "without_verify")

@classmethod
def from_context(cls, components, root):
def from_context(cls, components, roots):
self = cls()
self.components = []
for component in components:
self.components.append(repr(component.__class__.__name__))
self.root_name = root.name
self.roots = []
for root in roots:
self.roots.append(root.name)
return self

def __str__(self):
out_str = "Some components have an update method but no verify method:"
for component in self.components:
for idx, component in enumerate(self.components):
out_str += f"\n {component}"
out_str += f"\nRoot: {self.root_name}"
out_str += f"\nRoot: {self.roots[idx]}"
out_str += f"\nThe update() method may not be called by batou if the verify() method is missing."
return out_str

Expand Down
33 changes: 18 additions & 15 deletions src/batou/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ def configure(self):

while working_set:
exceptions = []
components_without_verify = []
previous_working_sets.append(working_set.copy())
retry = set()
self.resources.dirty_dependencies.clear()
Expand Down Expand Up @@ -536,26 +537,19 @@ def configure(self):
output.warn(str(unused_exception))

# 2. a component has .update() but no .verify()
components_without_verify = []

def has_original_update_method(component):
return type(component).update != Component.update
return type(component).update == Component.update

def has_original_verify_method(component):
return type(component).verify != Component.verify
return type(component).verify == Component.verify

for component in Component._instances:
if not has_original_update_method(
component
) and has_original_verify_method(component):
components_without_verify.append(component)
if components_without_verify:
component_without_verify_exception = (
ComponentWithUpdateWithoutVerify.from_context(
components_without_verify, root
)
)
output.warn(str(component_without_verify_exception))
if (
not has_original_update_method(component)
and has_original_verify_method(component)
and (component not in components_without_verify)
):
components_without_verify.append((component, root))
# configured this component successfully
# we won't have to retry it later
continue
Expand Down Expand Up @@ -598,6 +592,15 @@ def has_original_verify_method(component):

working_set = retry

# warn if a component has .update() but no .verify()
if components_without_verify:
component_without_verify_exception = (
ComponentWithUpdateWithoutVerify.from_context(
components_without_verify, root
)
)
output.warn(str(component_without_verify_exception))

# We managed to converge on a working set. However, some resource were
# provided but never used. We're rather picky here and report this as
# an error.
Expand Down

0 comments on commit faeea24

Please sign in to comment.