diff --git a/tests/group_vars/group01.yml b/tests/group_vars/group01.yml index 490697a..699d03e 100644 --- a/tests/group_vars/group01.yml +++ b/tests/group_vars/group01.yml @@ -2,4 +2,7 @@ nginx_extra_servers_path: "{{ playbook_dir }}/files" nginx_extra_servers_template_path: "{{ playbook_dir }}/templates" web2_port: 8888 -nginx_prometheus_metrics_port: 9888 \ No newline at end of file +nginx_prometheus_metrics_port: 9888 +nginx_prometheus_metrics_path: /mymetrics + +hostname: nginx \ No newline at end of file diff --git a/tests/test_ansible.py b/tests/test_ansible.py index 59a1bc0..f01d7bc 100644 --- a/tests/test_ansible.py +++ b/tests/test_ansible.py @@ -1,4 +1,5 @@ import pytest +import urllib2 @pytest.fixture() @@ -58,13 +59,16 @@ def test_nginx_service(File, Service, Socket, AnsibleVars): assert Service("nginx").is_enabled assert Service("nginx").is_running assert Socket("tcp://0.0.0.0:9999").is_listening - assert Socket("tcp://0.0.0.0:" + str(web2_port)).is_listening + assert Socket("tcp://0.0.0.0:{0}".format(web2_port)).is_listening def test_nginx_prometheus_service(File, Service, Socket, AnsibleVars): metrics_port = AnsibleVars["nginx_prometheus_metrics_port"] + metrics_path = AnsibleVars["nginx_prometheus_metrics_path"] + hostname = AnsibleVars["hostname"] assert File("/lib/systemd/system/nginx.service").exists assert Service("nginx").is_enabled assert Service("nginx").is_running assert Socket("tcp://0.0.0.0:9999").is_listening - assert Socket("tcp://0.0.0.0:" + str(metrics_port)).is_listening + assert Socket("tcp://0.0.0.0:{0}".format(metrics_port)).is_listening + assert 200 == urllib2.urlopen('http://{0}:{1}{2}'.format(hostname, metrics_port, metrics_path)).getcode()