mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-09 23:54:21 -07:00
* added metadata for variables in module helper
* adjustments
* added separate support for tracking changes
* rewrote the diff code
* added integration test for module_helper
* using ansible.module_utils.common.dict_transformations.dict_merge
* improved dependency management
* restore ModuleHelper to base classes of CmdStateModuleHelper
* added assertions to ensure the failing module name appears in the error messages
* added test code for state-based modules
* fixed test name
* renamed class to VarMeta
* small fixes
* fixes from the PR
* fixed VarDict.__set_attr__
* added VarDict.__getitem__()
* added changelog fragment
* adjustments per PR
* ModuleHelper.output is now aware of conflicting variable names
* Update plugins/module_utils/module_helper.py
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit d2070277e8
)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
ab391c2cfa
commit
5c8504323e
11 changed files with 572 additions and 24 deletions
3
tests/integration/targets/module_helper/tasks/main.yml
Normal file
3
tests/integration/targets/module_helper/tasks/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
- include_tasks: msimple.yml
|
||||
- include_tasks: mdepfail.yml
|
||||
- include_tasks: mstate.yml
|
14
tests/integration/targets/module_helper/tasks/mdepfail.yml
Normal file
14
tests/integration/targets/module_helper/tasks/mdepfail.yml
Normal file
|
@ -0,0 +1,14 @@
|
|||
- name: test failing dependency
|
||||
mdepfail:
|
||||
a: 123
|
||||
ignore_errors: yes
|
||||
register: result
|
||||
|
||||
- name: assert failing dependency
|
||||
assert:
|
||||
that:
|
||||
- result.failed is true
|
||||
- '"Failed to import" in result.msg'
|
||||
- '"nopackagewiththisname" in result.msg'
|
||||
- '"ModuleNotFoundError:" in result.exception'
|
||||
- '"nopackagewiththisname" in result.exception'
|
54
tests/integration/targets/module_helper/tasks/msimple.yml
Normal file
54
tests/integration/targets/module_helper/tasks/msimple.yml
Normal file
|
@ -0,0 +1,54 @@
|
|||
- name: test msimple 1
|
||||
msimple:
|
||||
a: 80
|
||||
register: simple1
|
||||
|
||||
- name: assert simple1
|
||||
assert:
|
||||
that:
|
||||
- simple1.a == 80
|
||||
- simple1.abc == "abc"
|
||||
- simple1.changed is false
|
||||
- simple1.value is none
|
||||
|
||||
- name: test msimple 2
|
||||
msimple:
|
||||
a: 101
|
||||
ignore_errors: yes
|
||||
register: simple2
|
||||
|
||||
- name: assert simple2
|
||||
assert:
|
||||
that:
|
||||
- simple2.a == 101
|
||||
- 'simple2.msg == "Module failed with exception: a >= 100"'
|
||||
- simple2.abc == "abc"
|
||||
- simple2.failed is true
|
||||
- simple2.changed is false
|
||||
- simple2.value is none
|
||||
|
||||
- name: test msimple 3
|
||||
msimple:
|
||||
a: 2
|
||||
b: potatoes
|
||||
register: simple3
|
||||
|
||||
- name: assert simple3
|
||||
assert:
|
||||
that:
|
||||
- simple3.a == 2
|
||||
- simple3.b == "potatoespotatoes"
|
||||
- simple3.c == "NoneNone"
|
||||
- simple3.changed is false
|
||||
|
||||
- name: test msimple 4
|
||||
msimple:
|
||||
c: abc change
|
||||
register: simple4
|
||||
|
||||
- name: assert simple4
|
||||
assert:
|
||||
that:
|
||||
- simple4.c == "abc change"
|
||||
- simple4.abc == "changed abc"
|
||||
- simple4.changed is true
|
79
tests/integration/targets/module_helper/tasks/mstate.yml
Normal file
79
tests/integration/targets/module_helper/tasks/mstate.yml
Normal file
|
@ -0,0 +1,79 @@
|
|||
- name: test mstate 1
|
||||
mstate:
|
||||
a: 80
|
||||
b: banana
|
||||
c: cashew
|
||||
state: nop
|
||||
register: state1
|
||||
|
||||
- name: assert state1
|
||||
assert:
|
||||
that:
|
||||
- state1.a == 80
|
||||
- state1.b == "banana"
|
||||
- state1.c == "cashew"
|
||||
- state1.result == "abc"
|
||||
- state1.changed is false
|
||||
|
||||
- name: test mstate 2
|
||||
mstate:
|
||||
a: 80
|
||||
b: banana
|
||||
c: cashew
|
||||
register: state2
|
||||
|
||||
- name: assert state2
|
||||
assert:
|
||||
that:
|
||||
- state2.a == 80
|
||||
- state2.b == "banana"
|
||||
- state2.c == "cashew"
|
||||
- state2.result == "80bananacashew"
|
||||
- state2.changed is true
|
||||
|
||||
- name: test mstate 3
|
||||
mstate:
|
||||
a: 3
|
||||
b: banana
|
||||
state: b_x_a
|
||||
register: state3
|
||||
|
||||
- name: assert state3
|
||||
assert:
|
||||
that:
|
||||
- state3.a == 3
|
||||
- state3.b == "banana"
|
||||
- state3.result == "bananabananabanana"
|
||||
- state3.changed is true
|
||||
|
||||
- name: test mstate 4
|
||||
mstate:
|
||||
a: 4
|
||||
c: cashew
|
||||
state: c_x_a
|
||||
register: state4
|
||||
|
||||
- name: assert state4
|
||||
assert:
|
||||
that:
|
||||
- state4.a == 4
|
||||
- state4.c == "cashew"
|
||||
- state4.result == "cashewcashewcashewcashew"
|
||||
- state4.changed is true
|
||||
|
||||
- name: test mstate 5
|
||||
mstate:
|
||||
a: 5
|
||||
b: foo
|
||||
c: bar
|
||||
state: both_x_a
|
||||
register: state5
|
||||
|
||||
- name: assert state5
|
||||
assert:
|
||||
that:
|
||||
- state5.a == 5
|
||||
- state5.b == "foo"
|
||||
- state5.c == "bar"
|
||||
- state5.result == "foobarfoobarfoobarfoobarfoobar"
|
||||
- state5.changed is true
|
Loading…
Add table
Add a link
Reference in a new issue