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
3 changes: 1 addition & 2 deletions tests/tasks/cleanup.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
- name: Reset settings and provider to os default
include_role:
name: linux-system-roles.timesync
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
timesync_ntp_provider: "{{ timesync_ntp_provider_os_default }}"
timesync_ptp_domains: []
Expand Down
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.timesync.
# 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.timesync
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.timesync
tasks_from: "{{ __sr_tasks_from | default('main') }}"
public: "{{ __sr_public | default(false) }}"
when: __sr_failed_when | d(true)
6 changes: 6 additions & 0 deletions tests/tasks/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
__required_facts: "{{ __timesync_required_facts + ['default_ipv4'] }}"
__required_facts_subsets: "{{ ['!all', '!min'] + __required_facts }}"

# This var is used in several tests and must be a fact not a var due
# to the clear_facts task.
- name: Set var for default_ipv4 interface fact
set_fact:
__timesync_default_ipv4_interface: "{{ ansible_facts['default_ipv4']['interface'] }}"

- name: Debug
debug:
msg: facts {{ ansible_facts | to_nice_json }}
6 changes: 3 additions & 3 deletions tests/tests_chrony.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

tasks:
- name: Run the role
include_role:
name: linux-system-roles.timesync
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
when: not __bootc_validation | d(false)

- name: Run the role only to get vars needed for validation
Expand Down
6 changes: 3 additions & 3 deletions tests/tests_default.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Ensure that the role runs with default parameters
hosts: all
gather_facts: false
roles:
- linux-system-roles.timesync
tasks:
- name: Run linux-system-roles.timesync
include_tasks: tasks/run_role_with_clear_facts.yml
6 changes: 3 additions & 3 deletions tests/tests_default_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
hosts: all
tasks:
- name: Include the timesync role
include_role:
name: linux-system-roles.timesync
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true

- name: Check that public vars are defined
assert:
Expand Down
41 changes: 20 additions & 21 deletions tests/tests_ntp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,34 @@
timesync_ntp_hwts_interfaces: ["*"]
tasks:
- name: Run the role
include_role:
name: linux-system-roles.timesync
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true

- name: Run test
tags: tests::verify
block:
- name: Flush handlers
meta: flush_handlers
- name: Ensure services are running properly if booted
when: __timesync_is_booted
block:
- name: Flush handlers
meta: flush_handlers

- name: Wait for services to start
wait_for:
timeout: 2
when: __timesync_is_booted
- name: Wait for services to start
wait_for:
timeout: 2

- name: Get list of currently used time sources
shell: chronyc -n sources || ntpq -pn
register: sources
changed_when: false
when: __timesync_is_booted
- name: Get list of currently used time sources
shell: chronyc -n sources || ntpq -pn
register: sources
changed_when: false

- name: Check time sources
assert:
that:
- "'172.16.123.1' in sources.stdout"
- "'172.16.123.2' in sources.stdout"
- "'172.16.123.3' in sources.stdout"
when: __timesync_is_booted
- name: Check time sources
assert:
that:
- "'172.16.123.1' in sources.stdout"
- "'172.16.123.2' in sources.stdout"
- "'172.16.123.3' in sources.stdout"

- name: Fetch chrony.conf file
slurp:
Expand Down
9 changes: 7 additions & 2 deletions tests/tests_ntp_provider1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
vars:
timesync_ntp_servers:
- hostname: 172.16.123.1
roles:
- linux-system-roles.timesync

pre_tasks:
- name: Common test setup tasks
Expand All @@ -25,11 +23,18 @@
- chrony
- ntp

tasks:
- name: Run linux-system-roles.timesync
include_tasks: tasks/run_role_with_clear_facts.yml

post_tasks:
- name: Verify provider is working
tags: tests::verify
when: __timesync_is_booted
block:
- name: Flush handlers
meta: flush_handlers

- name: Wait for services to start
wait_for:
timeout: 2
Expand Down
9 changes: 7 additions & 2 deletions tests/tests_ntp_provider2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
vars:
timesync_ntp_servers:
- hostname: 172.16.123.1
roles:
- linux-system-roles.timesync

pre_tasks:
- name: Common test setup tasks
Expand Down Expand Up @@ -39,11 +37,18 @@
state: "{{ 'started' if __timesync_is_booted else omit }}"
enabled: true

tasks:
- name: Run linux-system-roles.timesync
include_tasks: tasks/run_role_with_clear_facts.yml

post_tasks:
- name: Verify chronyd running
tags: tests::verify
when: __timesync_is_booted
block:
- name: Flush handlers
meta: flush_handlers

- name: Wait for services to start
wait_for:
timeout: 2
Expand Down
9 changes: 7 additions & 2 deletions tests/tests_ntp_provider3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
vars:
timesync_ntp_servers:
- hostname: 172.16.123.1
roles:
- linux-system-roles.timesync

pre_tasks:
- name: Common test setup tasks
Expand Down Expand Up @@ -39,11 +37,18 @@
state: "{{ 'started' if __timesync_is_booted else omit }}"
enabled: true

tasks:
- name: Run linux-system-roles.timesync
include_tasks: tasks/run_role_with_clear_facts.yml

post_tasks:
- name: Verify ntpd is running
tags: tests::verify
when: __timesync_is_booted
block:
- name: Flush handlers
meta: flush_handlers

- name: Wait for services to start
wait_for:
timeout: 2
Expand Down
9 changes: 6 additions & 3 deletions tests/tests_ntp_provider4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
- name: Run the test
block:
- name: Run the role
include_role:
name: linux-system-roles.timesync
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true

- name: Verify chronyd is running
tags: tests::verify
when: __timesync_is_booted
block:
- name: Flush handlers
meta: flush_handlers

- name: Wait for services to start
wait_for:
timeout: 2
Expand Down
9 changes: 6 additions & 3 deletions tests/tests_ntp_provider5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
- name: Run test
block:
- name: Run the role
include_role:
name: linux-system-roles.timesync
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true

- name: Verify ntpd service
tags: tests::verify
when: __timesync_is_booted
block:
- name: Flush handlers
meta: flush_handlers

- name: Wait for services to start
wait_for:
timeout: 2
Expand Down
14 changes: 8 additions & 6 deletions tests/tests_ntp_provider6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Configure NTP with OS release non-default provider and
then change it to the default provider
hosts: all
gather_facts: true
vars:
is_ntp_default: "{{ ansible_facts['distribution'] in ['RedHat', 'CentOS']
and ansible_facts['distribution_version'] is version('7.0', '<') }}"
Expand Down Expand Up @@ -52,10 +51,9 @@
- ntp

- name: Call role to change provider
include_role:
name: linux-system-roles.timesync
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
# ntp is the default choice for RedHat and CentOS
# version < 7.0 - reverse it
timesync_ntp_provider: "{{ 'chrony' if is_ntp_default else 'ntp' }}"
Expand Down Expand Up @@ -87,14 +85,18 @@
changed_when: false

- name: Call role to reset default provider
include_role:
name: linux-system-roles.timesync
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
timesync_ntp_provider: "{{ timesync_ntp_provider_os_default }}"

- name: Verify provider set correctly - 2
tags: tests::verify
when: __timesync_is_booted
block:
- name: Flush handlers
meta: flush_handlers

- name: Wait for services to start
wait_for:
timeout: 2
Expand Down
20 changes: 9 additions & 11 deletions tests/tests_ntp_ptp.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
- name: Configure time synchronization with NTP servers and PTP domains
hosts: all
gather_facts: true
vars:
timesync_ntp_servers:
- hostname: 172.16.123.1
Expand All @@ -12,10 +11,10 @@
maxpoll: 2
timesync_ptp_domains:
- number: 0
interfaces: "{{ [ ansible_facts['default_ipv4']['interface'] ] }}"
interfaces: "{{ [ __timesync_default_ipv4_interface ] }}"
delay: 0.0001
- number: 1
interfaces: "{{ [ ansible_facts['default_ipv4']['interface'] ] }}"
interfaces: "{{ [ __timesync_default_ipv4_interface ] }}"
delay: 0.0001
timesync_step_threshold: 0.001
timesync_dhcp_ntp_servers: false
Expand All @@ -28,13 +27,9 @@
include_tasks: tasks/setup.yml

- name: Run role
include_role:
name: linux-system-roles.timesync
public: true

- name: Flush handlers
meta: flush_handlers
when: __timesync_is_booted
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true

- name: Ensure ethtool is installed
package:
Expand All @@ -44,7 +39,7 @@
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"

- name: Check if SW/HW timestamping is supported
command: ethtool -T {{ ansible_facts['default_ipv4']['interface'] | quote }}
command: ethtool -T {{ __timesync_default_ipv4_interface | quote }}
register: ethtool
ignore_errors: true # noqa ignore-errors
changed_when: false
Expand All @@ -54,6 +49,9 @@
- __timesync_is_booted
- "'ware-transmit' in ethtool.stdout"
block:
- name: Flush handlers
meta: flush_handlers

- name: Wait for services to start
wait_for:
timeout: 2
Expand Down
Loading
Loading