mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
supervisorctl: add integration tests
This commit is contained in:
parent
4e0ecfd553
commit
2a7481444b
23 changed files with 358 additions and 0 deletions
3
test/integration/targets/supervisorctl/aliases
Normal file
3
test/integration/targets/supervisorctl/aliases
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
destructive
|
||||||
|
posix/ci/group2
|
||||||
|
skip/python3
|
24
test/integration/targets/supervisorctl/files/sendProcessStdin.py
Executable file
24
test/integration/targets/supervisorctl/files/sendProcessStdin.py
Executable file
|
@ -0,0 +1,24 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
proc = sys.argv[1]
|
||||||
|
value = sys.argv[2]
|
||||||
|
username = sys.argv[3]
|
||||||
|
password = sys.argv[4]
|
||||||
|
|
||||||
|
if sys.version_info[0] == 2:
|
||||||
|
from xmlrpclib import ServerProxy
|
||||||
|
from urllib import quote
|
||||||
|
else:
|
||||||
|
from xmlrpc.client import ServerProxy
|
||||||
|
from urllib.parse import quote
|
||||||
|
|
||||||
|
if username:
|
||||||
|
url = 'http://%s:%s@127.0.0.1:9001/RPC2' % (quote(username, safe=''), quote(password, safe=''))
|
||||||
|
else:
|
||||||
|
url = 'http://127.0.0.1:9001/RPC2'
|
||||||
|
|
||||||
|
server = ServerProxy(url, verbose=True)
|
||||||
|
server.supervisor.sendProcessStdin(proc, 'import sys; print(%s); sys.stdout.flush();\n' % value)
|
1
test/integration/targets/supervisorctl/tasks/install_Darwin.yml
Symbolic link
1
test/integration/targets/supervisorctl/tasks/install_Darwin.yml
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
install_pip.yml
|
1
test/integration/targets/supervisorctl/tasks/install_FreeBSD.yml
Symbolic link
1
test/integration/targets/supervisorctl/tasks/install_FreeBSD.yml
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
install_pip.yml
|
|
@ -0,0 +1,10 @@
|
||||||
|
- name: install supervisor
|
||||||
|
package:
|
||||||
|
name: supervisor
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: disable supervisord system service
|
||||||
|
service:
|
||||||
|
name: '{{ supervisor_service_name }}'
|
||||||
|
state: stopped
|
||||||
|
enabled: no
|
1
test/integration/targets/supervisorctl/tasks/install_RedHat.yml
Symbolic link
1
test/integration/targets/supervisorctl/tasks/install_RedHat.yml
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
install_pip.yml
|
1
test/integration/targets/supervisorctl/tasks/install_Suse.yml
Symbolic link
1
test/integration/targets/supervisorctl/tasks/install_Suse.yml
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
install_pip.yml
|
|
@ -0,0 +1,4 @@
|
||||||
|
- name: install supervisord
|
||||||
|
pip:
|
||||||
|
name: supervisor
|
||||||
|
state: present
|
40
test/integration/targets/supervisorctl/tasks/main.yml
Normal file
40
test/integration/targets/supervisorctl/tasks/main.yml
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
- block:
|
||||||
|
# output_dir is hardcoded in test/runner/lib/executor.py and created there
|
||||||
|
# expand remote path
|
||||||
|
- command: 'echo {{ output_dir }}'
|
||||||
|
register: echo
|
||||||
|
- set_fact:
|
||||||
|
remote_dir: '{{ echo.stdout }}'
|
||||||
|
|
||||||
|
- include_vars: '{{ item }}'
|
||||||
|
with_first_found:
|
||||||
|
- files:
|
||||||
|
- '{{ ansible_distribution }}.yml'
|
||||||
|
- '{{ ansible_os_family }}.yml'
|
||||||
|
- 'defaults.yml'
|
||||||
|
|
||||||
|
- include_tasks: '{{ item }}'
|
||||||
|
with_first_found:
|
||||||
|
- files:
|
||||||
|
- 'install_{{ ansible_distribution }}.yml' # CentOS
|
||||||
|
- 'install_{{ ansible_os_family }}.yml' # RedHat
|
||||||
|
- 'install_{{ ansible_system }}.yml' # Linux
|
||||||
|
|
||||||
|
- include_tasks: test.yml
|
||||||
|
with_items:
|
||||||
|
- { username: '', password: '' }
|
||||||
|
- { username: 'testétest', password: 'passéword' } # non-ASCII credentials
|
||||||
|
loop_control:
|
||||||
|
loop_var: credentials
|
||||||
|
|
||||||
|
# setuptools is too old on RHEL/CentOS 6 (https://github.com/Supervisor/meld3/issues/23)
|
||||||
|
when: ansible_os_family != 'RedHat' or ansible_distribution_major_version|int > 6
|
||||||
|
|
||||||
|
always:
|
||||||
|
- include_tasks: '{{ item }}'
|
||||||
|
when: ansible_os_family != 'RedHat' or ansible_distribution_major_version|int > 6
|
||||||
|
with_first_found:
|
||||||
|
- files:
|
||||||
|
- 'uninstall_{{ ansible_distribution }}.yml' # CentOS
|
||||||
|
- 'uninstall_{{ ansible_os_family }}.yml' # RedHat
|
||||||
|
- 'uninstall_{{ ansible_system }}.yml' # Linux
|
|
@ -0,0 +1,9 @@
|
||||||
|
- name: start supervisord
|
||||||
|
command: 'supervisord -c {{ remote_dir }}/supervisord.conf'
|
||||||
|
|
||||||
|
- name: wait_for supervisord
|
||||||
|
wait_for:
|
||||||
|
port: 9001
|
||||||
|
host: 127.0.0.1
|
||||||
|
timeout: 15
|
||||||
|
state: started
|
|
@ -0,0 +1,2 @@
|
||||||
|
- name: stop supervisord
|
||||||
|
command: "supervisorctl -c {{ remote_dir }}/supervisord.conf {% if credentials.username %}-u {{ credentials.username }} -p {{ credentials.password }}{% endif %} shutdown"
|
12
test/integration/targets/supervisorctl/tasks/test.yml
Normal file
12
test/integration/targets/supervisorctl/tasks/test.yml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
- name: generate supervisor configuration
|
||||||
|
template:
|
||||||
|
src: supervisord.conf
|
||||||
|
dest: '{{ remote_dir }}/supervisord.conf'
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- import_tasks: start_supervisord.yml
|
||||||
|
|
||||||
|
- import_tasks: test_start.yml
|
||||||
|
- import_tasks: test_stop.yml
|
||||||
|
always:
|
||||||
|
- import_tasks: stop_supervisord.yml
|
135
test/integration/targets/supervisorctl/tasks/test_start.yml
Normal file
135
test/integration/targets/supervisorctl/tasks/test_start.yml
Normal file
|
@ -0,0 +1,135 @@
|
||||||
|
- name: start py1 service (without auth)
|
||||||
|
supervisorctl:
|
||||||
|
name: 'pys:py1'
|
||||||
|
state: started
|
||||||
|
config: '{{ remote_dir }}/supervisord.conf'
|
||||||
|
register: result
|
||||||
|
when: credentials.username == ''
|
||||||
|
|
||||||
|
- name: start py1 service (with auth)
|
||||||
|
supervisorctl:
|
||||||
|
name: 'pys:py1'
|
||||||
|
state: started
|
||||||
|
server_url: http://127.0.0.1:9001
|
||||||
|
username: '{{ credentials.username }}'
|
||||||
|
password: '{{ credentials.password }}'
|
||||||
|
register: result_with_auth
|
||||||
|
when: credentials.username != ''
|
||||||
|
|
||||||
|
- command: "supervisorctl -c {{ remote_dir }}/supervisord.conf {% if credentials.username %}-u {{ credentials.username }} -p {{ credentials.password }}{% endif %} status"
|
||||||
|
|
||||||
|
- name: check that service is started
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- (result is success and result_with_auth is skip) or (result is skip and result_with_auth is changed)
|
||||||
|
- (result is changed and result_with_auth is skip) or (result is skip and result_with_auth is changed)
|
||||||
|
|
||||||
|
- name: check that service is running (part1) # py1.log content is checked below
|
||||||
|
script: "files/sendProcessStdin.py 'pys:py1' 2 \
|
||||||
|
'{{ credentials.username }}' '{{ credentials.password }}'"
|
||||||
|
|
||||||
|
- name: try again to start py1 service (without auth)
|
||||||
|
supervisorctl:
|
||||||
|
name: pys:py1
|
||||||
|
state: started
|
||||||
|
config: '{{ remote_dir }}/supervisord.conf'
|
||||||
|
register: result
|
||||||
|
when: credentials.username == ''
|
||||||
|
|
||||||
|
- name: try again to start py1 service (with auth)
|
||||||
|
supervisorctl:
|
||||||
|
name: pys:py1
|
||||||
|
state: started
|
||||||
|
server_url: http://127.0.0.1:9001
|
||||||
|
username: '{{ credentials.username }}'
|
||||||
|
password: '{{ credentials.password }}'
|
||||||
|
register: result_with_auth
|
||||||
|
when: credentials.username != ''
|
||||||
|
|
||||||
|
- name: check that service is already running
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- (result is success and result_with_auth is skip) or (result is skip and result_with_auth is success)
|
||||||
|
- (result is not changed and result_with_auth is skip) or (result is skip and result_with_auth is not changed)
|
||||||
|
|
||||||
|
- import_tasks: stop_supervisord.yml
|
||||||
|
|
||||||
|
# supervisord has been stopped, check logfile
|
||||||
|
- name: check that service has done what it was expected (part 2)
|
||||||
|
shell: 'test "$(tail -2 {{ remote_dir }}/py1.log | head -1)" = ">>> 2"'
|
||||||
|
|
||||||
|
# restart supervisord and py1 service for next tasks
|
||||||
|
- import_tasks: start_supervisord.yml
|
||||||
|
|
||||||
|
- name: start py1 service (without auth)
|
||||||
|
supervisorctl:
|
||||||
|
name: 'pys:py1'
|
||||||
|
state: started
|
||||||
|
config: '{{ remote_dir }}/supervisord.conf'
|
||||||
|
register: result
|
||||||
|
when: credentials.username == ''
|
||||||
|
|
||||||
|
- name: start py1 service (with auth)
|
||||||
|
supervisorctl:
|
||||||
|
name: 'pys:py1'
|
||||||
|
state: started
|
||||||
|
server_url: http://127.0.0.1:9001
|
||||||
|
username: '{{ credentials.username }}'
|
||||||
|
password: '{{ credentials.password }}'
|
||||||
|
register: result_with_auth
|
||||||
|
when: credentials.username != ''
|
||||||
|
|
||||||
|
- name: check that service is started
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- (result is success and result_with_auth is skip) or (result is skip and result_with_auth is changed)
|
||||||
|
- (result is changed and result_with_auth is skip) or (result is skip and result_with_auth is changed)
|
||||||
|
|
||||||
|
#############################################################
|
||||||
|
|
||||||
|
- name: Check an error occurs when wrong credentials are used
|
||||||
|
supervisorctl:
|
||||||
|
name: pys:py1
|
||||||
|
state: started
|
||||||
|
server_url: http://127.0.0.1:9001
|
||||||
|
username: '{{ credentials.username }}wrong_creds'
|
||||||
|
password: '{{ credentials.password }}same_here'
|
||||||
|
register: result
|
||||||
|
failed_when: result is not skip and (result is success or result is not failed)
|
||||||
|
when: credentials.username != ''
|
||||||
|
|
||||||
|
- name: Check an error occurs when wrong URL is used
|
||||||
|
supervisorctl:
|
||||||
|
name: pys:py1
|
||||||
|
state: started
|
||||||
|
server_url: http://127.0.0.1:9002
|
||||||
|
register: result
|
||||||
|
failed_when: result is success or result is not failed
|
||||||
|
|
||||||
|
- name: Check an error occurs when wrong config path is used
|
||||||
|
supervisorctl:
|
||||||
|
name: 'pys:py1'
|
||||||
|
state: started
|
||||||
|
config: '{{ remote_dir }}/supervisord_not_here.conf'
|
||||||
|
register: result
|
||||||
|
failed_when: result is success or result is not failed
|
||||||
|
|
||||||
|
- name: Check an error occurs wrong name is used (without auth)
|
||||||
|
supervisorctl:
|
||||||
|
name: 'invalid'
|
||||||
|
state: started
|
||||||
|
config: '{{ remote_dir }}/supervisord.conf'
|
||||||
|
register: result
|
||||||
|
failed_when: result is skip or (result is success or result is not failed)
|
||||||
|
when: credentials.username == ''
|
||||||
|
|
||||||
|
- name: Check an error occurs wrong name is used (with auth)
|
||||||
|
supervisorctl:
|
||||||
|
name: 'invalid'
|
||||||
|
state: started
|
||||||
|
config: '{{ remote_dir }}/supervisord.conf'
|
||||||
|
username: '{{ credentials.username }}wrong_creds'
|
||||||
|
password: '{{ credentials.password }}same_here'
|
||||||
|
register: result
|
||||||
|
failed_when: result is skip or (result is success or result is not failed)
|
||||||
|
when: credentials.username != ''
|
59
test/integration/targets/supervisorctl/tasks/test_stop.yml
Normal file
59
test/integration/targets/supervisorctl/tasks/test_stop.yml
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
- name: stop py1 service
|
||||||
|
supervisorctl:
|
||||||
|
name: 'pys:py1'
|
||||||
|
state: stopped
|
||||||
|
# test with 'server_url' parameter
|
||||||
|
server_url: 'unix://{{ remote_dir }}/supervisord.sock'
|
||||||
|
register: result
|
||||||
|
when: credentials.username == ''
|
||||||
|
|
||||||
|
- name: stop py1 service
|
||||||
|
supervisorctl:
|
||||||
|
name: 'pys:py1'
|
||||||
|
state: stopped
|
||||||
|
# test with unix socket
|
||||||
|
server_url: 'unix://{{ remote_dir }}/supervisord.sock'
|
||||||
|
username: '{{ credentials.username }}'
|
||||||
|
password: '{{ credentials.password }}'
|
||||||
|
register: result_with_auth
|
||||||
|
when: credentials.username != ''
|
||||||
|
|
||||||
|
- command: "supervisorctl -c {{ remote_dir }}/supervisord.conf {% if credentials.username %}-u {{ credentials.username }} -p {{ credentials.password }}{% endif %} status"
|
||||||
|
|
||||||
|
- name: check that service is stopped
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- (result is success and result_with_auth is skip) or (result is skip and result_with_auth is success)
|
||||||
|
- (result is changed and result_with_auth is skip) or (result is skip and result_with_auth is changed)
|
||||||
|
|
||||||
|
- name: "check that service isn't running"
|
||||||
|
script: "files/sendProcessStdin.py 'pys:py1' 1 \
|
||||||
|
'{{ credentials.username }}' '{{ credentials.password }}'"
|
||||||
|
register: is_py1_alive
|
||||||
|
failed_when: is_py1_alive is success
|
||||||
|
|
||||||
|
- name: try again to stop py1 service (without auth)
|
||||||
|
supervisorctl:
|
||||||
|
name: pys:py1
|
||||||
|
state: stopped
|
||||||
|
# test with 'server_url' parameter
|
||||||
|
server_url: 'unix://{{ remote_dir }}/supervisord.sock'
|
||||||
|
register: result
|
||||||
|
when: credentials.username == ''
|
||||||
|
|
||||||
|
- name: try again to stop py1 service (with auth)
|
||||||
|
supervisorctl:
|
||||||
|
name: pys:py1
|
||||||
|
state: stopped
|
||||||
|
# test with unix socket
|
||||||
|
server_url: 'unix://{{ remote_dir }}/supervisord.sock'
|
||||||
|
username: '{{ credentials.username }}'
|
||||||
|
password: '{{ credentials.password }}'
|
||||||
|
register: result_with_auth
|
||||||
|
when: credentials.username != ''
|
||||||
|
|
||||||
|
- name: check that service is already stopped
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- (result is success and result_with_auth is skip) or (result is skip and result_with_auth is success)
|
||||||
|
- (result is not changed and result_with_auth is skip) or (result is skip and result_with_auth is not changed)
|
|
@ -0,0 +1 @@
|
||||||
|
uninstall_pip.yml
|
|
@ -0,0 +1 @@
|
||||||
|
uninstall_pip.yml
|
|
@ -0,0 +1,4 @@
|
||||||
|
- name: uninstall supervisor
|
||||||
|
package:
|
||||||
|
name: supervisor
|
||||||
|
state: absent
|
|
@ -0,0 +1 @@
|
||||||
|
uninstall_pip.yml
|
1
test/integration/targets/supervisorctl/tasks/uninstall_Suse.yml
Symbolic link
1
test/integration/targets/supervisorctl/tasks/uninstall_Suse.yml
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
uninstall_pip.yml
|
|
@ -0,0 +1,4 @@
|
||||||
|
- name: uninstall supervisord
|
||||||
|
pip:
|
||||||
|
name: supervisor
|
||||||
|
state: absent
|
|
@ -0,0 +1,42 @@
|
||||||
|
[supervisord]
|
||||||
|
pidfile={{ remote_dir }}/supervisord.pid
|
||||||
|
logfile={{ remote_dir }}/supervisord.log
|
||||||
|
|
||||||
|
[program:py1]
|
||||||
|
command={{ ansible_python.executable }} -i -u -
|
||||||
|
user={{ ansible_user }}
|
||||||
|
autostart=false
|
||||||
|
autorestart=false
|
||||||
|
stdout_logfile={{ remote_dir }}/py1.log
|
||||||
|
redirect_stderr=yes
|
||||||
|
|
||||||
|
[program:py2]
|
||||||
|
command={{ ansible_python.executable }} -i -u -
|
||||||
|
user={{ ansible_user }}
|
||||||
|
autostart=false
|
||||||
|
autorestart=false
|
||||||
|
stdout_logfile={{ remote_dir }}/py2.log
|
||||||
|
redirect_stderr=yes
|
||||||
|
|
||||||
|
[group:pys]
|
||||||
|
programs=py1,py2
|
||||||
|
|
||||||
|
[unix_http_server]
|
||||||
|
file={{ remote_dir }}/supervisord.sock
|
||||||
|
{% if credentials.username is defined and credentials.username|default(false, boolean=true) %}
|
||||||
|
username = {{ credentials.username }}
|
||||||
|
password = {{ credentials.password }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
[inet_http_server]
|
||||||
|
port=127.0.0.1:9001
|
||||||
|
{% if credentials.username is defined and credentials.username|default(false, boolean=true) %}
|
||||||
|
username = {{ credentials.username }}
|
||||||
|
password = {{ credentials.password }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
[supervisorctl]
|
||||||
|
serverurl=unix://{{ remote_dir }}/supervisord.sock
|
||||||
|
|
||||||
|
[rpcinterface:supervisor]
|
||||||
|
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
|
1
test/integration/targets/supervisorctl/vars/Debian.yml
Normal file
1
test/integration/targets/supervisorctl/vars/Debian.yml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
supervisor_service_name: supervisor
|
1
test/integration/targets/supervisorctl/vars/defaults.yml
Normal file
1
test/integration/targets/supervisorctl/vars/defaults.yml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
supervisor_service_name: supervisord
|
Loading…
Reference in a new issue