|
12 | 12 | return_content: true |
13 | 13 | register: response |
14 | 14 |
|
| 15 | + - name: Show Timezone |
| 16 | + ansible.builtin.debug: |
| 17 | + msg: Timezone is {{ response.content }} |
| 18 | + |
| 19 | + # ansible_date_time is incremented for a few second for each next task. |
| 20 | + # Store value, so we have a stable value. |
| 21 | + - name: Store current time |
| 22 | + ansible.builtin.set_fact: |
| 23 | + current_date_time: "{{ ansible_date_time }}" |
| 24 | + |
| 25 | + - name: Show current time |
| 26 | + ansible.builtin.debug: |
| 27 | + msg: current_date_time={{ current_date_time }} TZ={{ current_date_time.tz }} hour={{ current_date_time.hour }} |
| 28 | + |
| 29 | + # The scheduled integration tests run near 3.00 UTC (5:00 CEST). |
| 30 | + # ansible_date_time.hour is reported in local timezone. |
| 31 | + # It should be safe to add/subtract 1 hour to prevent occasional test failures, |
| 32 | + # if scheduled test is run near x:59:59. |
| 33 | + |
| 34 | + # Manual testing - can be run at arbitrary time, can always be a problem. So extra assert |
| 35 | + - name: Check "current_date_time.hour +/- 1" is still a valid hour |
| 36 | + ansible.builtin.assert: |
| 37 | + that: |
| 38 | + - 1 <= (current_date_time.hour | int) |
| 39 | + - (current_date_time.hour | int) <= 22 |
| 40 | + |
| 41 | + # ------------------------------------------------------------------------------ |
15 | 42 | - name: Check that local time meets required time interval |
16 | 43 | ansible.builtin.include_role: |
17 | 44 | name: scale_computing.hypercore.check_local_time |
18 | 45 | vars: |
19 | 46 | time_zone: "{{ response.content }}" # ansible_date_time.tz returns CEST which is not a valid tz for env var TZ |
20 | | - time_interval: "{{ ansible_date_time.hour }}:00-{{ ansible_date_time.hour }}:59" |
| 47 | + time_interval: "{{ (current_date_time.hour | int) - 1 }}:00-{{ (current_date_time.hour | int) + 1 }}:59" |
21 | 48 |
|
22 | | - # it can fail when run near x:59 |
23 | | - - ansible.builtin.assert: |
| 49 | + - name: Check local_time_msg for passed case |
| 50 | + ansible.builtin.assert: |
24 | 51 | that: |
25 | 52 | - >- |
26 | | - "'Local time for time zone {{ response.content }} is in required time interval |
27 | | - {{ ansible_date_time.hour }}:00-{{ ansible_date_time.hour }}:59' in local_time_msg" |
| 53 | + 'Local time for time zone {{ response.content }} is in required time interval |
| 54 | + {{ (current_date_time.hour | int) - 1 }}:00-{{ (current_date_time.hour | int) + 1 }}:59' in local_time_msg |
28 | 55 |
|
| 56 | + # ------------------------------------------------------------------------------ |
29 | 57 | - name: Check that local time doesn't meet required time interval |
30 | 58 | ansible.builtin.include_role: |
31 | 59 | name: scale_computing.hypercore.check_local_time |
32 | 60 | apply: |
33 | 61 | ignore_errors: True |
34 | 62 | vars: |
35 | 63 | time_zone: "{{ response.content }}" |
36 | | - time_interval: "{{ ansible_date_time.hour }}:00-{{ ansible_date_time.hour }}:01" |
| 64 | + time_interval: "{{ (current_date_time.hour | int) - 1 }}:00-{{ (current_date_time.hour | int) - 1 }}:01" |
37 | 65 |
|
38 | | - # it can fail when run near x:00 |
39 | | - - ansible.builtin.assert: |
| 66 | + - name: Check local_time_msg for failed case |
| 67 | + ansible.builtin.assert: |
40 | 68 | that: |
41 | 69 | - >- |
42 | | - "'Local time for time zone {{ response.content }} is not in required time interval |
43 | | - {{ ansible_date_time.hour }}:00-{{ ansible_date_time.hour }}:01' in local_time_msg" |
| 70 | + 'Local time for time zone {{ response.content }} is not in required time interval |
| 71 | + {{ (current_date_time.hour | int) - 1 }}:00-{{ (current_date_time.hour | int) - 1 }}:01' in local_time_msg |
0 commit comments