Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps module utils: add function failed() to retrieve dependencies check result #6383

Merged
merged 2 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/6383-deps-failed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- deps module utils - add function ``failed()`` providing the ability to check the dependency check result without triggering an exception (https://github.com/ansible-collections/community.general/pull/6383).
18 changes: 13 additions & 5 deletions plugins/module_utils/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def message(self):
def failed(self):
return self.state == 1

def verify(self, module):
def validate(self, module):
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
if self.failed:
module.fail_json(msg=self.message, exception=self.trace)

Expand All @@ -71,10 +71,10 @@ def declare(name, *args, **kwargs):
_deps[name] = dep


def validate(module, spec=None):
def _select_names(spec):
dep_names = sorted(_deps)

if spec is not None:
if spec:
if spec.startswith("-"):
spec_split = spec[1:].split(":")
for d in spec_split:
Expand All @@ -86,5 +86,13 @@ def validate(module, spec=None):
_deps[d] # ensure it exists
dep_names.append(d)

for dep in dep_names:
_deps[dep].verify(module)
return dep_names


def validate(module, spec=None):
for dep in _select_names(spec):
_deps[dep].validate(module)


def failed(spec=None):
return any(_deps[d].failed for d in _select_names(spec))