Skip to content

Commit c55c5ad

Browse files
committed
CI try to fix check_local_time integ test
Jobs https://github.com/ScaleComputing/HyperCoreAnsibleCollection/actions/runs/4675127388/jobs/8279941573#step:8:52 and https://github.com/ScaleComputing/HyperCoreAnsibleCollection/actions/runs/4675127388/jobs/8279941761#step:8:52 failed Extra debug print added. It is not clear what were input values, and what went wrong. Tested interval is also changed, this should make test more reliable. Downside is test cannot work 2 hours in a day - there is extra assert just to fail early when this happens. It should not happen during scheduled CI jobs. Removed the extra "" in asserts. We were checking string is not empty, but we need to let assert evaluate string. Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
1 parent 3e87c2b commit c55c5ad

File tree

1 file changed

+38
-10
lines changed
  • tests/integration/targets/role_check_local_time/tasks

1 file changed

+38
-10
lines changed

tests/integration/targets/role_check_local_time/tasks/main.yml

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,60 @@
1212
return_content: true
1313
register: response
1414

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+
# ------------------------------------------------------------------------------
1542
- name: Check that local time meets required time interval
1643
ansible.builtin.include_role:
1744
name: scale_computing.hypercore.check_local_time
1845
vars:
1946
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"
2148

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:
2451
that:
2552
- >-
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
2855
56+
# ------------------------------------------------------------------------------
2957
- name: Check that local time doesn't meet required time interval
3058
ansible.builtin.include_role:
3159
name: scale_computing.hypercore.check_local_time
3260
apply:
3361
ignore_errors: True
3462
vars:
3563
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"
3765

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:
4068
that:
4169
- >-
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

Comments
 (0)