| 1 |
--- |
| 2 |
- name: test wait_for with delegate_to |
| 3 |
wait_for: |
| 4 |
timeout: 2 |
| 5 |
delegate_to: localhost |
| 6 |
register: waitfor |
| 7 |
|
| 8 |
- assert: |
| 9 |
that: |
| 10 |
- waitfor is successful |
| 11 |
- waitfor.elapsed >= 2 |
| 12 |
|
| 13 |
- name: setup create a directory to serve files from |
| 14 |
file: |
| 15 |
dest: "{{ files_dir }}" |
| 16 |
state: directory |
| 17 |
|
| 18 |
- name: setup webserver |
| 19 |
copy: |
| 20 |
src: "testserver.py" |
| 21 |
dest: "{{ remote_tmp_dir }}/testserver.py" |
| 22 |
|
| 23 |
- name: setup a path |
| 24 |
file: |
| 25 |
path: "{{ remote_tmp_dir }}/wait_for_file" |
| 26 |
state: touch |
| 27 |
|
| 28 |
- name: setup remove a file after 3s |
| 29 |
shell: sleep 3 && rm {{ remote_tmp_dir }}/wait_for_file |
| 30 |
async: 20 |
| 31 |
poll: 0 |
| 32 |
|
| 33 |
- name: test for absent path |
| 34 |
wait_for: |
| 35 |
path: "{{ remote_tmp_dir }}/wait_for_file" |
| 36 |
state: absent |
| 37 |
timeout: 20 |
| 38 |
register: waitfor |
| 39 |
- name: verify test for absent path |
| 40 |
assert: |
| 41 |
that: |
| 42 |
- waitfor is successful |
| 43 |
- waitfor.path == (remote_tmp_dir | expanduser + "/wait_for_file") |
| 44 |
- waitfor.elapsed >= 2 |
| 45 |
- waitfor.elapsed <= 15 |
| 46 |
|
| 47 |
- name: setup create a file after 3s |
| 48 |
shell: sleep 3 && touch {{ remote_tmp_dir }}/wait_for_file |
| 49 |
async: 20 |
| 50 |
poll: 0 |
| 51 |
|
| 52 |
- name: test for present path |
| 53 |
wait_for: |
| 54 |
path: "{{ remote_tmp_dir }}/wait_for_file" |
| 55 |
timeout: 5 |
| 56 |
register: waitfor |
| 57 |
- name: verify test for absent path |
| 58 |
assert: |
| 59 |
that: |
| 60 |
- waitfor is successful |
| 61 |
- waitfor.path == (remote_tmp_dir | expanduser + "/wait_for_file") |
| 62 |
- waitfor.elapsed >= 2 |
| 63 |
- waitfor.elapsed <= 15 |
| 64 |
|
| 65 |
- name: setup write keyword to file after 3s |
| 66 |
shell: sleep 3 && echo completed > {{remote_tmp_dir}}/wait_for_keyword |
| 67 |
async: 20 |
| 68 |
poll: 0 |
| 69 |
|
| 70 |
- name: test wait for keyword in file |
| 71 |
wait_for: |
| 72 |
path: "{{remote_tmp_dir}}/wait_for_keyword" |
| 73 |
search_regex: completed |
| 74 |
timeout: 5 |
| 75 |
register: waitfor |
| 76 |
|
| 77 |
- name: verify test wait for keyword in file |
| 78 |
assert: |
| 79 |
that: |
| 80 |
- waitfor is successful |
| 81 |
- "waitfor.search_regex == 'completed'" |
| 82 |
- waitfor.elapsed >= 2 |
| 83 |
- waitfor.elapsed <= 15 |
| 84 |
|
| 85 |
- name: setup write keyword to file after 3s |
| 86 |
shell: sleep 3 && echo "completed data 123" > {{remote_tmp_dir}}/wait_for_keyword |
| 87 |
async: 20 |
| 88 |
poll: 0 |
| 89 |
|
| 90 |
- name: test wait for keyword in file with match groups |
| 91 |
wait_for: |
| 92 |
path: "{{remote_tmp_dir}}/wait_for_keyword" |
| 93 |
search_regex: completed (?P<foo>\w+) ([0-9]+) |
| 94 |
timeout: 25 |
| 95 |
register: waitfor |
| 96 |
|
| 97 |
- name: verify test wait for keyword in file with match groups |
| 98 |
assert: |
| 99 |
that: |
| 100 |
- waitfor is successful |
| 101 |
- waitfor.elapsed >= 2 |
| 102 |
- waitfor.elapsed <= 15 |
| 103 |
- waitfor['match_groupdict'] | length == 1 |
| 104 |
- waitfor['match_groupdict']['foo'] == 'data' |
| 105 |
- waitfor['match_groups'] == ['data', '123'] |
| 106 |
|
| 107 |
- name: write non-ascii file |
| 108 |
script: write_utf16.py "{{remote_tmp_dir}}/utf16.txt" |
| 109 |
args: |
| 110 |
executable: '{{ ansible_facts.python.executable }}' |
| 111 |
|
| 112 |
- name: test non-ascii file |
| 113 |
wait_for: |
| 114 |
path: "{{remote_tmp_dir}}/utf16.txt" |
| 115 |
search_regex: completed |
| 116 |
|
| 117 |
- name: test non mmapable file, skip OSs w/o /sys |
| 118 |
wait_for: |
| 119 |
path: "/sys/class/net/lo/carrier" |
| 120 |
search_regex: "1" |
| 121 |
timeout: 30 |
| 122 |
when: ansible_os_family not in ['FreeBSD', 'Darwin'] |
| 123 |
|
| 124 |
- name: test wait for port timeout |
| 125 |
wait_for: |
| 126 |
port: 12121 |
| 127 |
timeout: 3 |
| 128 |
register: waitfor |
| 129 |
ignore_errors: true |
| 130 |
- name: verify test wait for port timeout |
| 131 |
assert: |
| 132 |
that: |
| 133 |
- waitfor is failed |
| 134 |
- waitfor.elapsed == 3 |
| 135 |
- waitfor.msg is contains 'Timeout when waiting for 127.0.0.1:12121' |
| 136 |
|
| 137 |
- name: test fail with custom msg |
| 138 |
wait_for: |
| 139 |
port: 12121 |
| 140 |
msg: fail with custom message |
| 141 |
timeout: 3 |
| 142 |
register: waitfor |
| 143 |
ignore_errors: true |
| 144 |
- name: verify test fail with custom msg |
| 145 |
assert: |
| 146 |
that: |
| 147 |
- waitfor is failed |
| 148 |
- waitfor.elapsed == 3 |
| 149 |
- waitfor.msg is contains 'fail with custom message' |
| 150 |
|
| 151 |
- name: setup start SimpleHTTPServer |
| 152 |
shell: sleep 3 && cd {{ files_dir }} && {{ ansible_python.executable }} {{ remote_tmp_dir}}/testserver.py {{ http_port }} |
| 153 |
async: 120 # this test set can take ~1m to run on FreeBSD (via Shippable) |
| 154 |
poll: 0 |
| 155 |
|
| 156 |
- name: test wait for port with sleep |
| 157 |
wait_for: |
| 158 |
port: "{{ http_port }}" |
| 159 |
sleep: 3 |
| 160 |
register: waitfor |
| 161 |
- name: verify test wait for port sleep |
| 162 |
assert: |
| 163 |
that: |
| 164 |
- waitfor is successful |
| 165 |
- waitfor is not changed |
| 166 |
- waitfor.port == http_port |
| 167 |
|
| 168 |
- name: install psutil using pip (non-Linux) |
| 169 |
pip: |
| 170 |
name: psutil==5.9.8 |
| 171 |
when: ansible_system != 'Linux' |
| 172 |
|
| 173 |
- name: Copy zombie.py |
| 174 |
copy: |
| 175 |
src: zombie.py |
| 176 |
dest: "{{ remote_tmp_dir }}" |
| 177 |
|
| 178 |
- name: Create zombie process |
| 179 |
shell: "{{ ansible_python.executable }} {{ remote_tmp_dir }}/zombie" |
| 180 |
async: 90 |
| 181 |
poll: 0 |
| 182 |
|
| 183 |
- name: test wait for port drained |
| 184 |
wait_for: |
| 185 |
port: "{{ http_port }}" |
| 186 |
state: drained |
| 187 |
register: waitfor |
| 188 |
|
| 189 |
- name: verify test wait for port |
| 190 |
assert: |
| 191 |
that: |
| 192 |
- waitfor is successful |
| 193 |
- waitfor is not changed |
| 194 |
- waitfor.port == http_port |
| 195 |
|
| 196 |
- name: test wait_for with delay |
| 197 |
wait_for: |
| 198 |
timeout: 2 |
| 199 |
delay: 2 |
| 200 |
register: waitfor |
| 201 |
|
| 202 |
- name: verify test wait_for with delay |
| 203 |
assert: |
| 204 |
that: |
| 205 |
- waitfor is successful |
| 206 |
- waitfor.elapsed >= 4 |