test: ensure role gathers the facts it uses by having test clear_facts before include_role#404
Conversation
Reviewer's GuideThis PR refactors the MSSQL role tests to run the role through a new helper task file that clears Ansible facts before each invocation, and restructures conditional logic that depended on ansible_facts to avoid undefined-variable errors when facts are cleared. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[citest] |
|
@spetrosi are these errors expected? They don't look like they are related to clearing facts. |
|
There is a bunch of failures that are caused by issues in mssql packages from Microsoft. I reported them and had a reply that they are looking into them but still no result. However, CentOS-7 tests should pass. tests_tls fail there, maybe it requires public in every role invocation. |
spetrosi
left a comment
There was a problem hiding this comment.
fix tests_tls, should pass on CentOS 7.
|
[citest] |
|
[citest_bad] |
spetrosi
left a comment
There was a problem hiding this comment.
fix tests_tls, should pass on CentOS 7.
|
All of the centos7 tests pass, but TF is reporting an error for some reason |
|
[citest_bad] |
|
[citest] |
|
[citest] |
…s before include_role The role gathers the facts it uses. For example, if the user uses `ANSIBLE_GATHERING=explicit`, the role uses the `setup` module with the facts and subsets it requires. This change allows us to test this. Before every role invocation, the test will use `meta: clear_facts` so that the role starts with no facts. Create a task file tests/tasks/run_role_with_clear_facts.yml to do the tasks to clear the facts and run the role. Note that this means we don't need to use `gather_facts` for the tests. Some vars defined using `ansible_facts` have been changed to be defined with `set_fact` instead. This is because of the fact that `vars` are lazily evaluated - the var might be referenced when the facts have been cleared, and will issue an error like `ansible_facts["distribution"] is undefined`. This is typically done for blocks that have a `when` condition that uses `ansible_facts` and the block has a role invocation using run_role_with_clear_facts.yml These have been rewritten to define the `when` condition using `set_fact`. This is because the `when` condition is evaluated every time a task is invoked in the block, and if the facts are cleared, this will raise an undefined variable error. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
|
[citest] |
The role gathers the facts it uses. For example, if the user uses
ANSIBLE_GATHERING=explicit, the role uses thesetupmodule with thefacts and subsets it requires.
This change allows us to test this. Before every role invocation, the test
will use
meta: clear_factsso that the role starts with no facts.Create a task file tests/tasks/run_role_with_clear_facts.yml to do the tasks
to clear the facts and run the role. Note that this means we don't need to
use
gather_factsfor the tests.Some vars defined using
ansible_factshave been changed to be defined withset_factinstead. This is because of the fact thatvarsare lazilyevaluated - the var might be referenced when the facts have been cleared, and
will issue an error like
ansible_facts["distribution"] is undefined. This istypically done for blocks that have a
whencondition that usesansible_factsand the block has a role invocation using run_role_with_clear_facts.yml
These have been rewritten to define the
whencondition usingset_fact. Thisis because the
whencondition is evaluated every time a task is invoked in theblock, and if the facts are cleared, this will raise an undefined variable error.
Signed-off-by: Rich Megginson rmeggins@redhat.com
Summary by Sourcery
Introduce a shared test helper that clears Ansible facts before each role invocation and update tests to use it so the mssql role is exercised with explicit fact gathering.
Bug Fixes:
Enhancements:
Tests: