wait_for: add some integration tests (#25553)
This commit is contained in:
parent
cc66bd4ad0
commit
0a972ea6bf
5 changed files with 159 additions and 0 deletions
2
test/integration/targets/wait_for/aliases
Normal file
2
test/integration/targets/wait_for/aliases
Normal file
|
@ -0,0 +1,2 @@
|
|||
destructive
|
||||
posix/ci/group1
|
16
test/integration/targets/wait_for/files/testserver.py
Normal file
16
test/integration/targets/wait_for/files/testserver.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
import sys
|
||||
|
||||
if __name__ == '__main__':
|
||||
if sys.version_info[0] >= 3:
|
||||
import http.server
|
||||
import socketserver
|
||||
PORT = int(sys.argv[1])
|
||||
Handler = http.server.SimpleHTTPRequestHandler
|
||||
httpd = socketserver.TCPServer(("", PORT), Handler)
|
||||
httpd.serve_forever()
|
||||
else:
|
||||
import mimetypes
|
||||
mimetypes.init()
|
||||
mimetypes.add_type('application/json', '.json')
|
||||
import SimpleHTTPServer
|
||||
SimpleHTTPServer.test()
|
2
test/integration/targets/wait_for/meta/main.yml
Normal file
2
test/integration/targets/wait_for/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_tests
|
135
test/integration/targets/wait_for/tasks/main.yml
Normal file
135
test/integration/targets/wait_for/tasks/main.yml
Normal file
|
@ -0,0 +1,135 @@
|
|||
---
|
||||
- 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:
|
||||
path: /tmp/wait_for_file
|
||||
state: touch
|
||||
|
||||
- name: setup remove a file after 10s
|
||||
shell: sleep 10 && rm /tmp/wait_for_file
|
||||
async: 20
|
||||
poll: 0
|
||||
|
||||
- name: test for absent path
|
||||
wait_for:
|
||||
path: /tmp/wait_for_file
|
||||
state: absent
|
||||
timeout: 20
|
||||
register: waitfor
|
||||
- name: verify test for absent path
|
||||
assert:
|
||||
that:
|
||||
- waitfor|success
|
||||
- "waitfor.path == '/tmp/wait_for_file'"
|
||||
- waitfor.elapsed <= 10
|
||||
- waitfor.elapsed > 0
|
||||
|
||||
- name: setup create a file after 10s
|
||||
shell: sleep 10 && touch /tmp/wait_for_file
|
||||
async: 20
|
||||
poll: 0
|
||||
|
||||
- name: test for present path
|
||||
wait_for:
|
||||
path: /tmp/wait_for_file
|
||||
timeout: 20
|
||||
register: waitfor
|
||||
- name: verify test for absent path
|
||||
assert:
|
||||
that:
|
||||
- waitfor|success
|
||||
- "waitfor.path == '/tmp/wait_for_file'"
|
||||
- waitfor.elapsed <= 10
|
||||
- waitfor.elapsed > 0
|
||||
|
||||
- name: setup write keyword to file after 10s
|
||||
shell: rm -f /tmp/wait_for_keyword && sleep 10 && echo completed > /tmp/wait_for_keyword
|
||||
async: 20
|
||||
poll: 0
|
||||
|
||||
- name: test wait for keyword in file
|
||||
wait_for:
|
||||
path: /tmp/wait_for_keyword
|
||||
search_regex: completed
|
||||
timeout: 20
|
||||
register: waitfor
|
||||
- name: verify test wait for port timeout
|
||||
assert:
|
||||
that:
|
||||
- waitfor|success
|
||||
- "waitfor.search_regex == 'completed'"
|
||||
- waitfor.elapsed <= 10
|
||||
- waitfor.elapsed > 0
|
||||
|
||||
- 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:
|
||||
- waitfor|failed
|
||||
- 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:
|
||||
- waitfor|failed
|
||||
- waitfor.elapsed == 3
|
||||
- "waitfor.msg == 'fail with custom message'"
|
||||
|
||||
- name: setup start SimpleHTTPServer
|
||||
shell: sleep 10 && cd {{ files_dir }} && {{ ansible_python.executable }} {{ output_dir}}/testserver.py {{ http_port }}
|
||||
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:
|
||||
- waitfor|success
|
||||
- not waitfor|changed
|
||||
- "waitfor.port == {{ http_port }}"
|
||||
|
||||
# TODO: fix drain test for freebsd and macOS, ubuntu-py3
|
||||
- name: setup install psutil
|
||||
package:
|
||||
name: python-psutil
|
||||
when: ansible_system == "Linux" and not (ansible_distribution == "Ubuntu" and ansible_distribution_version == "16.04")
|
||||
|
||||
- name: test wait for port drained
|
||||
wait_for:
|
||||
port: "{{ http_port }}"
|
||||
state: drained
|
||||
register: waitfor
|
||||
when: ansible_system == "Linux" and not (ansible_distribution == "Ubuntu" and ansible_distribution_version == "16.04")
|
||||
- name: verify test wait for port
|
||||
assert:
|
||||
that:
|
||||
- waitfor|success
|
||||
- not waitfor|changed
|
||||
- "waitfor.port == {{ http_port }}"
|
||||
when: ansible_system == "Linux" and not (ansible_distribution == "Ubuntu" and ansible_distribution_version == "16.04")
|
4
test/integration/targets/wait_for/vars/main.yml
Normal file
4
test/integration/targets/wait_for/vars/main.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
http_port: 15261
|
||||
files_dir: '{{ output_dir|expanduser }}/files'
|
||||
checkout_dir: '{{ output_dir }}/git'
|
Loading…
Reference in a new issue