Skip to content

Commit 32e9af1

Browse files
mike-nguyenMicah Abbott
authored and
Micah Abbott
committed
Fix race condition in reboot flag test
PR projectatomic#368 added a check for a boot_id to confirm reboots in the reboot role. This caused a race condition in the rpm_ostree_install and rpm_ostree_uninstall roles when using the reboot flag. The reboot role has an option to not perform a reboot and just check that the system comes down and back up. This was leverage by rpm_ostree_install and rpm_ostree_uninstall roles to fire the the respective commands with the -r flag. The -r flag causes a reboot to occur when the command executes but requires to be run asychronously (the command won't return when the system goes down and will cause Ansible to fail). When rpm_ostree_install/rpm_ostree_uninstall was called with the -r flag it calls the reboot role. If the reboot role can execute before the reboot occurs, it will successfully execute. If the system goes down before the reboot role can grab the boot_id, it will fail. This PR modifies the reboot_flag test to not use the reboot role. It copies most of the logic from the reboot role into the test itself. Since this was a corner case for the -r flag, I felt like it was an appropriate exception to not re-use the role.
1 parent 3d83c27 commit 32e9af1

File tree

1 file changed

+67
-10
lines changed

1 file changed

+67
-10
lines changed

tests/pkg-layering/reboot_flag.yml

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,81 @@
11
---
22
# set ft=ansible
33
#
4+
- set_fact:
5+
real_ansible_host: "{{ ansible_host }}"
6+
timeout: "{{ cli_reboot_timeout | default('300') }}"
47

5-
- import_role:
6-
name: rpm_ostree_install
7-
vars:
8-
roi_packages: "{{ g_pkg1 }}"
9-
roi_reboot: true
8+
# Have to account for both because Fedora STR uses the old version of these
9+
# inventory values for some reason.
10+
- when: ansible_port is defined
11+
set_fact:
12+
real_ansible_port: "{{ ansible_port }}"
13+
14+
- when: ansible_ssh_port is defined
15+
set_fact:
16+
real_ansible_port: "{{ ansible_ssh_port }}"
17+
18+
- name: Get original bootid
19+
command: cat /proc/sys/kernel/random/boot_id
20+
register: orig_bootid
21+
22+
- name: Package layer {{ g_pkg1 }} with reboot flag
23+
command: rpm-ostree install {{ g_pkg1 | quote }} -r
24+
async: 60
25+
poll: 0
26+
ignore_errors: true
27+
28+
- name: wait for hosts to come back up
29+
local_action:
30+
wait_for host={{ real_ansible_host }}
31+
port={{ real_ansible_port | default('22') }}
32+
state=started
33+
delay=30
34+
timeout={{ timeout }}
35+
search_regex="OpenSSH"
36+
become: false
37+
38+
# I'm not sure the retries are even necessary, but I'm keeping them in
39+
- name: Wait until bootid changes
40+
command: cat /proc/sys/kernel/random/boot_id
41+
register: new_bootid
42+
until: new_bootid.stdout != orig_bootid.stdout
43+
retries: 6
44+
delay: 10
1045

1146
- import_role:
1247
name: rpm_ostree_install_verify
1348
vars:
1449
roiv_package_name: "{{ g_pkg1 }}"
1550
roiv_binary_name: "{{ g_pkg1 }}"
1651

17-
- import_role:
18-
name: rpm_ostree_uninstall
19-
vars:
20-
rou_packages: "{{ g_pkg1 }}"
21-
rou_reboot: true
52+
- name: Get original bootid
53+
command: cat /proc/sys/kernel/random/boot_id
54+
register: orig_bootid
55+
56+
- name: Remove {{ g_pkg1 }} with reboot flag
57+
command: rpm-ostree uninstall {{ g_pkg1 | quote }} -r
58+
async: 60
59+
poll: 0
60+
ignore_errors: true
61+
62+
- name: wait for hosts to come back up
63+
local_action:
64+
wait_for host={{ real_ansible_host }}
65+
port={{ real_ansible_port | default('22') }}
66+
state=started
67+
delay=30
68+
timeout={{ timeout }}
69+
search_regex="OpenSSH"
70+
become: false
71+
72+
# I'm not sure the retries are even necessary, but I'm keeping them in
73+
- name: Wait until bootid changes
74+
command: cat /proc/sys/kernel/random/boot_id
75+
register: new_bootid
76+
until: new_bootid.stdout != orig_bootid.stdout
77+
retries: 6
78+
delay: 10
2279

2380
- import_role:
2481
name: rpm_ostree_uninstall_verify

0 commit comments

Comments
 (0)