From 2a7481444bc28638aa8d291c288ac7326dfe6c1f Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Mon, 12 Feb 2018 12:42:18 +0100 Subject: [PATCH] supervisorctl: add integration tests --- .../integration/targets/supervisorctl/aliases | 3 + .../supervisorctl/files/sendProcessStdin.py | 24 ++++ .../supervisorctl/tasks/install_Darwin.yml | 1 + .../supervisorctl/tasks/install_FreeBSD.yml | 1 + .../supervisorctl/tasks/install_Linux.yml | 10 ++ .../supervisorctl/tasks/install_RedHat.yml | 1 + .../supervisorctl/tasks/install_Suse.yml | 1 + .../supervisorctl/tasks/install_pip.yml | 4 + .../targets/supervisorctl/tasks/main.yml | 40 ++++++ .../supervisorctl/tasks/start_supervisord.yml | 9 ++ .../supervisorctl/tasks/stop_supervisord.yml | 2 + .../targets/supervisorctl/tasks/test.yml | 12 ++ .../supervisorctl/tasks/test_start.yml | 135 ++++++++++++++++++ .../targets/supervisorctl/tasks/test_stop.yml | 59 ++++++++ .../supervisorctl/tasks/uninstall_Darwin.yml | 1 + .../supervisorctl/tasks/uninstall_FreeBSD.yml | 1 + .../supervisorctl/tasks/uninstall_Linux.yml | 4 + .../supervisorctl/tasks/uninstall_RedHat.yml | 1 + .../supervisorctl/tasks/uninstall_Suse.yml | 1 + .../supervisorctl/tasks/uninstall_pip.yml | 4 + .../supervisorctl/templates/supervisord.conf | 42 ++++++ .../targets/supervisorctl/vars/Debian.yml | 1 + .../targets/supervisorctl/vars/defaults.yml | 1 + 23 files changed, 358 insertions(+) create mode 100644 test/integration/targets/supervisorctl/aliases create mode 100755 test/integration/targets/supervisorctl/files/sendProcessStdin.py create mode 120000 test/integration/targets/supervisorctl/tasks/install_Darwin.yml create mode 120000 test/integration/targets/supervisorctl/tasks/install_FreeBSD.yml create mode 100644 test/integration/targets/supervisorctl/tasks/install_Linux.yml create mode 120000 test/integration/targets/supervisorctl/tasks/install_RedHat.yml create mode 120000 test/integration/targets/supervisorctl/tasks/install_Suse.yml create mode 100644 test/integration/targets/supervisorctl/tasks/install_pip.yml create mode 100644 test/integration/targets/supervisorctl/tasks/main.yml create mode 100644 test/integration/targets/supervisorctl/tasks/start_supervisord.yml create mode 100644 test/integration/targets/supervisorctl/tasks/stop_supervisord.yml create mode 100644 test/integration/targets/supervisorctl/tasks/test.yml create mode 100644 test/integration/targets/supervisorctl/tasks/test_start.yml create mode 100644 test/integration/targets/supervisorctl/tasks/test_stop.yml create mode 120000 test/integration/targets/supervisorctl/tasks/uninstall_Darwin.yml create mode 120000 test/integration/targets/supervisorctl/tasks/uninstall_FreeBSD.yml create mode 100644 test/integration/targets/supervisorctl/tasks/uninstall_Linux.yml create mode 120000 test/integration/targets/supervisorctl/tasks/uninstall_RedHat.yml create mode 120000 test/integration/targets/supervisorctl/tasks/uninstall_Suse.yml create mode 100644 test/integration/targets/supervisorctl/tasks/uninstall_pip.yml create mode 100644 test/integration/targets/supervisorctl/templates/supervisord.conf create mode 100644 test/integration/targets/supervisorctl/vars/Debian.yml create mode 100644 test/integration/targets/supervisorctl/vars/defaults.yml diff --git a/test/integration/targets/supervisorctl/aliases b/test/integration/targets/supervisorctl/aliases new file mode 100644 index 0000000000..4a181a1ef2 --- /dev/null +++ b/test/integration/targets/supervisorctl/aliases @@ -0,0 +1,3 @@ +destructive +posix/ci/group2 +skip/python3 diff --git a/test/integration/targets/supervisorctl/files/sendProcessStdin.py b/test/integration/targets/supervisorctl/files/sendProcessStdin.py new file mode 100755 index 0000000000..4237339ae5 --- /dev/null +++ b/test/integration/targets/supervisorctl/files/sendProcessStdin.py @@ -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) diff --git a/test/integration/targets/supervisorctl/tasks/install_Darwin.yml b/test/integration/targets/supervisorctl/tasks/install_Darwin.yml new file mode 120000 index 0000000000..7fe8a88f08 --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/install_Darwin.yml @@ -0,0 +1 @@ +install_pip.yml \ No newline at end of file diff --git a/test/integration/targets/supervisorctl/tasks/install_FreeBSD.yml b/test/integration/targets/supervisorctl/tasks/install_FreeBSD.yml new file mode 120000 index 0000000000..7fe8a88f08 --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/install_FreeBSD.yml @@ -0,0 +1 @@ +install_pip.yml \ No newline at end of file diff --git a/test/integration/targets/supervisorctl/tasks/install_Linux.yml b/test/integration/targets/supervisorctl/tasks/install_Linux.yml new file mode 100644 index 0000000000..af1790ccad --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/install_Linux.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 diff --git a/test/integration/targets/supervisorctl/tasks/install_RedHat.yml b/test/integration/targets/supervisorctl/tasks/install_RedHat.yml new file mode 120000 index 0000000000..7fe8a88f08 --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/install_RedHat.yml @@ -0,0 +1 @@ +install_pip.yml \ No newline at end of file diff --git a/test/integration/targets/supervisorctl/tasks/install_Suse.yml b/test/integration/targets/supervisorctl/tasks/install_Suse.yml new file mode 120000 index 0000000000..7fe8a88f08 --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/install_Suse.yml @@ -0,0 +1 @@ +install_pip.yml \ No newline at end of file diff --git a/test/integration/targets/supervisorctl/tasks/install_pip.yml b/test/integration/targets/supervisorctl/tasks/install_pip.yml new file mode 100644 index 0000000000..dba18a8311 --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/install_pip.yml @@ -0,0 +1,4 @@ +- name: install supervisord + pip: + name: supervisor + state: present diff --git a/test/integration/targets/supervisorctl/tasks/main.yml b/test/integration/targets/supervisorctl/tasks/main.yml new file mode 100644 index 0000000000..b93b1ccbb9 --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/main.yml @@ -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 diff --git a/test/integration/targets/supervisorctl/tasks/start_supervisord.yml b/test/integration/targets/supervisorctl/tasks/start_supervisord.yml new file mode 100644 index 0000000000..49559cf07d --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/start_supervisord.yml @@ -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 diff --git a/test/integration/targets/supervisorctl/tasks/stop_supervisord.yml b/test/integration/targets/supervisorctl/tasks/stop_supervisord.yml new file mode 100644 index 0000000000..1bf48f2139 --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/stop_supervisord.yml @@ -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" diff --git a/test/integration/targets/supervisorctl/tasks/test.yml b/test/integration/targets/supervisorctl/tasks/test.yml new file mode 100644 index 0000000000..bfd2a06e17 --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/test.yml @@ -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 diff --git a/test/integration/targets/supervisorctl/tasks/test_start.yml b/test/integration/targets/supervisorctl/tasks/test_start.yml new file mode 100644 index 0000000000..cc56ac5a99 --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/test_start.yml @@ -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 != '' diff --git a/test/integration/targets/supervisorctl/tasks/test_stop.yml b/test/integration/targets/supervisorctl/tasks/test_stop.yml new file mode 100644 index 0000000000..faf6d79358 --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/test_stop.yml @@ -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) diff --git a/test/integration/targets/supervisorctl/tasks/uninstall_Darwin.yml b/test/integration/targets/supervisorctl/tasks/uninstall_Darwin.yml new file mode 120000 index 0000000000..577ca5abbf --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/uninstall_Darwin.yml @@ -0,0 +1 @@ +uninstall_pip.yml \ No newline at end of file diff --git a/test/integration/targets/supervisorctl/tasks/uninstall_FreeBSD.yml b/test/integration/targets/supervisorctl/tasks/uninstall_FreeBSD.yml new file mode 120000 index 0000000000..577ca5abbf --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/uninstall_FreeBSD.yml @@ -0,0 +1 @@ +uninstall_pip.yml \ No newline at end of file diff --git a/test/integration/targets/supervisorctl/tasks/uninstall_Linux.yml b/test/integration/targets/supervisorctl/tasks/uninstall_Linux.yml new file mode 100644 index 0000000000..300239730b --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/uninstall_Linux.yml @@ -0,0 +1,4 @@ +- name: uninstall supervisor + package: + name: supervisor + state: absent diff --git a/test/integration/targets/supervisorctl/tasks/uninstall_RedHat.yml b/test/integration/targets/supervisorctl/tasks/uninstall_RedHat.yml new file mode 120000 index 0000000000..577ca5abbf --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/uninstall_RedHat.yml @@ -0,0 +1 @@ +uninstall_pip.yml \ No newline at end of file diff --git a/test/integration/targets/supervisorctl/tasks/uninstall_Suse.yml b/test/integration/targets/supervisorctl/tasks/uninstall_Suse.yml new file mode 120000 index 0000000000..577ca5abbf --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/uninstall_Suse.yml @@ -0,0 +1 @@ +uninstall_pip.yml \ No newline at end of file diff --git a/test/integration/targets/supervisorctl/tasks/uninstall_pip.yml b/test/integration/targets/supervisorctl/tasks/uninstall_pip.yml new file mode 100644 index 0000000000..5bb5ee130e --- /dev/null +++ b/test/integration/targets/supervisorctl/tasks/uninstall_pip.yml @@ -0,0 +1,4 @@ +- name: uninstall supervisord + pip: + name: supervisor + state: absent diff --git a/test/integration/targets/supervisorctl/templates/supervisord.conf b/test/integration/targets/supervisorctl/templates/supervisord.conf new file mode 100644 index 0000000000..5ad95ebadc --- /dev/null +++ b/test/integration/targets/supervisorctl/templates/supervisord.conf @@ -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 diff --git a/test/integration/targets/supervisorctl/vars/Debian.yml b/test/integration/targets/supervisorctl/vars/Debian.yml new file mode 100644 index 0000000000..d4b1bdcca9 --- /dev/null +++ b/test/integration/targets/supervisorctl/vars/Debian.yml @@ -0,0 +1 @@ +supervisor_service_name: supervisor diff --git a/test/integration/targets/supervisorctl/vars/defaults.yml b/test/integration/targets/supervisorctl/vars/defaults.yml new file mode 100644 index 0000000000..fc3aa0a81c --- /dev/null +++ b/test/integration/targets/supervisorctl/vars/defaults.yml @@ -0,0 +1 @@ +supervisor_service_name: supervisord