Skip to content
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
37 changes: 37 additions & 0 deletions tests/tasks/run_role_with_clear_facts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
# Task file: clear_facts, run linux-system-roles.rhc.
# Include this with include_tasks or import_tasks
# Input:
# - __sr_tasks_from: tasks_from to run - same as tasks_from in include_role
# - __sr_public: export private vars from role - same as public in include_role
# - __sr_failed_when: set to false to ignore role errors - same as failed_when in include_role
- name: Clear facts
meta: clear_facts

# note that you can use failed_when with import_role but not with include_role
# so this simulates the __sr_failed_when false case
# Q: Why do we need a separate task to run the role normally? Why not just
# run the role in the block and rethrow the error in the rescue block?
# A: Because you cannot rethrow the error in exactly the same way as the role does.
# It might be possible to exactly reconstruct ansible_failed_result but it's not worth the effort.
- name: Run the role with __sr_failed_when false
when:
- __sr_failed_when is defined
- not __sr_failed_when
block:
- name: Run the role
include_role:
name: linux-system-roles.rhc
tasks_from: "{{ __sr_tasks_from | default('main') }}"
public: "{{ __sr_public | default(false) }}"
rescue:
- name: Ignore the failure when __sr_failed_when is false
debug:
msg: Ignoring failure when __sr_failed_when is false

- name: Run the role normally
include_role:
name: linux-system-roles.rhc
tasks_from: "{{ __sr_tasks_from | default('main') }}"
public: "{{ __sr_public | default(false) }}"
when: __sr_failed_when | d(true)
4 changes: 1 addition & 3 deletions tests/tests_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
---
- name: Ensure that the role runs with default parameters
hosts: all
gather_facts: false
tasks:
- name: Verify that by default the role fails without credentials
block:
- name: Run the role with default parameters
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Unreachable task
fail:
Expand Down
10 changes: 3 additions & 7 deletions tests/tests_environments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
---
- name: Basic repository enablement/disablement test
hosts: all
gather_facts: false
become: true
tags:
- tests::slow
Expand Down Expand Up @@ -33,8 +32,7 @@
- name: Try to register (wrong environment)
block:
- name: Register (wrong environment)
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_auth:
login:
Expand Down Expand Up @@ -64,8 +62,7 @@
- name: Test environments on registration
block:
- name: Register (with existing environments)
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_auth:
login:
Expand Down Expand Up @@ -105,8 +102,7 @@

always:
- name: Unregister
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_state: absent
always:
Expand Down
27 changes: 9 additions & 18 deletions tests/tests_insights_ansible_host.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
---
- name: Insights ansible host test
hosts: all
gather_facts: false
become: true

tasks:
Expand All @@ -12,10 +11,9 @@
- name: Test ansible_host
block:
- name: Add ansible_host and register insights
include_role:
name: linux-system-roles.rhc
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
rhc_auth:
login:
username: "{{ lsr_rhc_test_data.reg_username }}"
Expand All @@ -41,8 +39,7 @@
- name: Test ansible_host changed value after registration
block:
- name: Change ansible host to 'new-host'
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_insights:
ansible_host: new-host
Expand All @@ -52,8 +49,7 @@
grep -ixq "^ansible_host=new-host" {{ __rhc_insights_conf }}
changed_when: false
- name: Change ansible host to a null value (noop)
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_insights:
ansible_host: null
Expand All @@ -63,8 +59,7 @@
grep -ixq "^ansible_host=new-host" {{ __rhc_insights_conf }}
changed_when: false
- name: Change ansible host to an empty string (noop)
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_insights:
ansible_host: ""
Expand All @@ -77,8 +72,7 @@
- name: Test ansible_host set to an absent value
block:
- name: Set ansible host to an absent value
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_insights:
ansible_host: {state: absent}
Expand All @@ -95,8 +89,7 @@
- name: Test ansible_host is removed during insights unregistration
block:
- name: Set ansible_host in config file
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_insights:
ansible_host: unreg-test
Expand All @@ -106,8 +99,7 @@
grep -ixq "^ansible_host=unreg-test" {{ __rhc_insights_conf }}
changed_when: false
- name: Unregister insights to remove ansible_host in config file
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_insights:
state: absent
Expand All @@ -122,7 +114,6 @@

always:
- name: Unregister
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_state: absent
15 changes: 5 additions & 10 deletions tests/tests_insights_autoupdate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
---
- name: Basic insights autoupdate test
hosts: all
gather_facts: false
become: true

tasks:
Expand All @@ -12,10 +11,9 @@
- name: Test autoupdate
block:
- name: Add autoupdate and register insights
include_role:
name: linux-system-roles.rhc
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
rhc_auth:
login:
username: "{{ lsr_rhc_test_data.reg_username }}"
Expand All @@ -39,16 +37,14 @@
changed_when: false

- name: Disable autoupdate
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_insights:
autoupdate: false
remediation: absent

- name: Disable autoupdate (noop)
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_insights:
autoupdate: false
Expand All @@ -61,7 +57,6 @@

always:
- name: Unregister
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_state: absent
19 changes: 6 additions & 13 deletions tests/tests_insights_client_register.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
---
- name: Basic insights-client register/unregister
hosts: all
gather_facts: false

tasks:
- name: Setup Insights
Expand All @@ -11,8 +10,7 @@
- name: Test Insights registration
block:
- name: Register insights
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_auth:
login:
Expand All @@ -31,8 +29,7 @@
rhc_proxy: "{{ rhc_external_proxy | default({}) }}"

- name: Register insights (noop)
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_auth:
login:
Expand All @@ -58,8 +55,7 @@
test_insights_uuid_before: "{{ test_insights_uuid }}"

- name: Register (force)
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_auth:
login:
Expand Down Expand Up @@ -94,22 +90,19 @@
or test_insights_uuid_after == test_rhsm_uuid

- name: Unregister insights
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_insights:
state: absent

- name: Unregister insights (noop)
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_insights:
state: absent

always:
- name: Unregister
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_state: absent
24 changes: 8 additions & 16 deletions tests/tests_insights_display_name.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
---
- name: Insights display name test
hosts: all
gather_facts: false
become: true

tasks:
Expand All @@ -12,10 +11,9 @@
- name: Test display_name
block:
- name: Add display_name and register insights
include_role:
name: linux-system-roles.rhc
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
rhc_auth:
login:
username: "{{ lsr_rhc_test_data.reg_username }}"
Expand All @@ -41,8 +39,7 @@
- name: Test display_name changed value after registration
block:
- name: Change display name to 'new-name'
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_insights:
display_name: new-name
Expand All @@ -52,8 +49,7 @@
grep -ixq "^display_name=new-name" {{ __rhc_insights_conf }}
changed_when: false
- name: Change display name to a null value (noop)
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_insights:
display_name: null
Expand All @@ -63,8 +59,7 @@
grep -ixq "^display_name=new-name" {{ __rhc_insights_conf }}
changed_when: false
- name: Change display name to an empty string (noop)
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_insights:
display_name: ""
Expand All @@ -77,8 +72,7 @@
- name: Test display_name is removed during insights unregistration
block:
- name: Set display_name in config file
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_insights:
display_name: unreg-test
Expand All @@ -88,8 +82,7 @@
grep -ixq "^display_name=unreg-test" {{ __rhc_insights_conf }}
changed_when: false
- name: Unregister insights to remove display_name in config file
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_insights:
state: absent
Expand All @@ -104,7 +97,6 @@

always:
- name: Unregister
include_role:
name: linux-system-roles.rhc
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
rhc_state: absent
Loading
Loading