1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[PR #6383/e7cc9964 backport][stable-6] deps module utils: add function failed() to retrieve dependencies check result (#6399)

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

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

* add changelog frag

(cherry picked from commit e7cc996470)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2023-04-23 14:53:38 +02:00 committed by GitHub
parent 957f3e6eca
commit 60fe6ebc3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View file

@ -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).

View file

@ -50,7 +50,7 @@ class _Dependency(object):
def failed(self): def failed(self):
return self.state == 1 return self.state == 1
def verify(self, module): def validate(self, module):
if self.failed: if self.failed:
module.fail_json(msg=self.message, exception=self.trace) module.fail_json(msg=self.message, exception=self.trace)
@ -71,10 +71,10 @@ def declare(name, *args, **kwargs):
_deps[name] = dep _deps[name] = dep
def validate(module, spec=None): def _select_names(spec):
dep_names = sorted(_deps) dep_names = sorted(_deps)
if spec is not None: if spec:
if spec.startswith("-"): if spec.startswith("-"):
spec_split = spec[1:].split(":") spec_split = spec[1:].split(":")
for d in spec_split: for d in spec_split:
@ -86,5 +86,13 @@ def validate(module, spec=None):
_deps[d] # ensure it exists _deps[d] # ensure it exists
dep_names.append(d) dep_names.append(d)
for dep in dep_names: return dep_names
_deps[dep].verify(module)
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))