2017-06-09 19:35:10 +00:00
|
|
|
---
|
|
|
|
- name: setup create a directory to serve files from
|
|
|
|
file:
|
|
|
|
dest: "{{ files_dir }}"
|
|
|
|
state: directory
|
|
|
|
|
|
|
|
- name: setup webserver
|
|
|
|
copy:
|
|
|
|
src: "testserver.py"
|
|
|
|
dest: "{{ output_dir }}/testserver.py"
|
|
|
|
|
|
|
|
- name: setup a path
|
|
|
|
file:
|
2018-11-20 19:19:17 +00:00
|
|
|
path: "{{ output_dir }}/wait_for_file"
|
2017-06-09 19:35:10 +00:00
|
|
|
state: touch
|
|
|
|
|
2018-11-20 19:19:17 +00:00
|
|
|
- name: setup remove a file after 3s
|
|
|
|
shell: sleep 3 && rm {{ output_dir }}/wait_for_file
|
2017-06-09 19:35:10 +00:00
|
|
|
async: 20
|
|
|
|
poll: 0
|
|
|
|
|
|
|
|
- name: test for absent path
|
|
|
|
wait_for:
|
2018-11-20 19:19:17 +00:00
|
|
|
path: "{{ output_dir }}/wait_for_file"
|
2017-06-09 19:35:10 +00:00
|
|
|
state: absent
|
|
|
|
timeout: 20
|
|
|
|
register: waitfor
|
|
|
|
- name: verify test for absent path
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- waitfor is successful
|
2018-11-20 19:19:17 +00:00
|
|
|
- waitfor.path == "{{ output_dir | expanduser }}/wait_for_file"
|
|
|
|
- waitfor.elapsed >= 2
|
2017-07-06 02:00:13 +00:00
|
|
|
- waitfor.elapsed <= 15
|
2017-06-09 19:35:10 +00:00
|
|
|
|
2018-11-20 19:19:17 +00:00
|
|
|
- name: setup create a file after 3s
|
|
|
|
shell: sleep 3 && touch {{ output_dir }}/wait_for_file
|
2017-06-09 19:35:10 +00:00
|
|
|
async: 20
|
|
|
|
poll: 0
|
|
|
|
|
|
|
|
- name: test for present path
|
|
|
|
wait_for:
|
2018-11-20 19:19:17 +00:00
|
|
|
path: "{{ output_dir }}/wait_for_file"
|
|
|
|
timeout: 5
|
2017-06-09 19:35:10 +00:00
|
|
|
register: waitfor
|
|
|
|
- name: verify test for absent path
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- waitfor is successful
|
2018-11-20 19:19:17 +00:00
|
|
|
- waitfor.path == "{{ output_dir | expanduser }}/wait_for_file"
|
|
|
|
- waitfor.elapsed >= 2
|
2017-07-06 02:00:13 +00:00
|
|
|
- waitfor.elapsed <= 15
|
2017-06-09 19:35:10 +00:00
|
|
|
|
2018-11-20 19:19:17 +00:00
|
|
|
- name: setup write keyword to file after 3s
|
|
|
|
shell: sleep 3 && echo completed > {{output_dir}}/wait_for_keyword
|
2017-06-09 19:35:10 +00:00
|
|
|
async: 20
|
|
|
|
poll: 0
|
|
|
|
|
|
|
|
- name: test wait for keyword in file
|
|
|
|
wait_for:
|
2018-11-20 19:19:17 +00:00
|
|
|
path: "{{output_dir}}/wait_for_keyword"
|
2017-06-09 19:35:10 +00:00
|
|
|
search_regex: completed
|
2018-11-20 19:19:17 +00:00
|
|
|
timeout: 5
|
2017-06-09 19:35:10 +00:00
|
|
|
register: waitfor
|
2018-11-20 19:19:17 +00:00
|
|
|
|
|
|
|
- name: verify test wait for keyword in file
|
2017-06-09 19:35:10 +00:00
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- waitfor is successful
|
2017-06-09 19:35:10 +00:00
|
|
|
- "waitfor.search_regex == 'completed'"
|
2018-11-20 19:19:17 +00:00
|
|
|
- waitfor.elapsed >= 2
|
2017-07-06 02:00:13 +00:00
|
|
|
- waitfor.elapsed <= 15
|
2017-06-09 19:35:10 +00:00
|
|
|
|
2018-11-20 19:19:17 +00:00
|
|
|
- name: setup write keyword to file after 3s
|
|
|
|
shell: sleep 3 && echo "completed data 123" > {{output_dir}}/wait_for_keyword
|
|
|
|
async: 20
|
|
|
|
poll: 0
|
|
|
|
|
|
|
|
- name: test wait for keyword in file with match groups
|
|
|
|
wait_for:
|
|
|
|
path: "{{output_dir}}/wait_for_keyword"
|
|
|
|
search_regex: completed (?P<foo>\w+) ([0-9]+)
|
|
|
|
timeout: 5
|
|
|
|
register: waitfor
|
|
|
|
|
|
|
|
- name: verify test wait for keyword in file with match groups
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- waitfor is successful
|
|
|
|
- waitfor.elapsed >= 2
|
|
|
|
- waitfor.elapsed <= 15
|
|
|
|
- waitfor['match_groupdict'] | length == 1
|
|
|
|
- waitfor['match_groupdict']['foo'] == 'data'
|
|
|
|
- waitfor['match_groups'] == ['data', '123']
|
|
|
|
|
2017-06-09 19:35:10 +00:00
|
|
|
- name: test wait for port timeout
|
|
|
|
wait_for:
|
|
|
|
port: 12121
|
|
|
|
timeout: 3
|
|
|
|
register: waitfor
|
|
|
|
ignore_errors: true
|
|
|
|
- name: verify test wait for port timeout
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- waitfor is failed
|
2017-06-09 19:35:10 +00:00
|
|
|
- waitfor.elapsed == 3
|
|
|
|
- "waitfor.msg == 'Timeout when waiting for 127.0.0.1:12121'"
|
|
|
|
|
|
|
|
- name: test fail with custom msg
|
|
|
|
wait_for:
|
|
|
|
port: 12121
|
|
|
|
msg: fail with custom message
|
|
|
|
timeout: 3
|
|
|
|
register: waitfor
|
|
|
|
ignore_errors: true
|
|
|
|
- name: verify test fail with custom msg
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- waitfor is failed
|
2017-06-09 19:35:10 +00:00
|
|
|
- waitfor.elapsed == 3
|
|
|
|
- "waitfor.msg == 'fail with custom message'"
|
|
|
|
|
|
|
|
- name: setup start SimpleHTTPServer
|
2018-11-20 19:19:17 +00:00
|
|
|
shell: sleep 3 && cd {{ files_dir }} && {{ ansible_python.executable }} {{ output_dir}}/testserver.py {{ http_port }}
|
2017-06-09 19:35:10 +00:00
|
|
|
async: 120 # this test set can take ~1m to run on FreeBSD (via Shippable)
|
|
|
|
poll: 0
|
|
|
|
|
|
|
|
- name: test wait for port with sleep
|
|
|
|
wait_for:
|
|
|
|
port: "{{ http_port }}"
|
|
|
|
sleep: 3
|
|
|
|
register: waitfor
|
|
|
|
- name: verify test wait for port sleep
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- waitfor is successful
|
|
|
|
- waitfor is not changed
|
2017-06-09 19:35:10 +00:00
|
|
|
- "waitfor.port == {{ http_port }}"
|
|
|
|
|
2017-07-06 02:00:13 +00:00
|
|
|
- name: install psutil using pip (non-Linux only)
|
|
|
|
pip:
|
|
|
|
name: psutil
|
|
|
|
when: ansible_system != 'Linux'
|
2017-06-09 19:35:10 +00:00
|
|
|
|
|
|
|
- name: test wait for port drained
|
|
|
|
wait_for:
|
|
|
|
port: "{{ http_port }}"
|
|
|
|
state: drained
|
|
|
|
register: waitfor
|
2017-07-06 02:00:13 +00:00
|
|
|
|
2017-06-09 19:35:10 +00:00
|
|
|
- name: verify test wait for port
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- waitfor is successful
|
|
|
|
- waitfor is not changed
|
2017-06-09 19:35:10 +00:00
|
|
|
- "waitfor.port == {{ http_port }}"
|