Debian Codegraph @

ansible_collections/community/zabbix/molecule/zabbix_web/tests/test_default.py

raw
1 import os
2 import pytest
3
4 import testinfra.utils.ansible_runner
5
6 testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
7 os.environ["MOLECULE_INVENTORY_FILE"]
8 ).get_hosts("all")
9
10
11 def test_zabbix_package(host):
12 ansible_data = host.ansible.get_variables()
13 version = ansible_data['zabbix_web_version']
14 webserver = ansible_data['zabbix_web_http_server']
15
16 package_name = f'zabbix-{webserver}-conf'
17 if host.system_info.distribution == "opensuse-leap" and version == 7.0:
18 package_name = f'zabbix-{webserver}-conf-php8'
19
20 zabbix_web = host.package(package_name)
21 assert str(version) in zabbix_web.version
22
23
24 def test_zabbix_web(host):
25 zabbix_web = host.file("/etc/zabbix/web/zabbix.conf.php")
26 ansible_variables = host.ansible.get_variables()
27 zabbix_websrv = str(ansible_variables["zabbix_web_http_server"])
28
29 if host.system_info.distribution in ["debian", "ubuntu"]:
30 assert zabbix_web.user == "www-data"
31 assert zabbix_web.group == "www-data"
32 elif host.system_info.distribution == "centos":
33 if zabbix_websrv == "apache":
34 assert zabbix_web.user == "apache"
35 assert zabbix_web.group == "apache"
36 elif zabbix_websrv == "nginx":
37 assert zabbix_web.user == "nginx"
38 assert zabbix_web.group == "nginx"
39 elif host.system_info.distribution == "opensuse-leap":
40 if zabbix_websrv == "apache":
41 assert zabbix_web.user == "wwwrun"
42 assert zabbix_web.group == "wwwrun"
43 elif zabbix_websrv == "nginx":
44 assert zabbix_web.user == "nginx"
45 assert zabbix_web.group == "nginx"
46 assert zabbix_web.mode == 0o640
47
48
49 def test_zabbix_api(host):
50 my_host = host.ansible.get_variables()
51 version = my_host['zabbix_web_version']
52 zabbix_api_server_url = str(my_host["zabbix_api_server_url"])
53 hostname = "http://" + zabbix_api_server_url + "/api_jsonrpc.php"
54 if version <= 7.0:
55 post_data = '{"jsonrpc": "2.0", "method": "user.login", "params": { "username": "Admin", "password": "zabbix" }, "id": 1, "auth": null}'
56 else:
57 post_data = '{"jsonrpc": "2.0", "method": "user.login", "params": { "username": "Admin", "password": "zabbix" }, "id": 1}'
58
59 headers = "Content-Type: application/json-rpc"
60 command = (
61 "curl -XPOST -H '"
62 + str(headers)
63 + "' -d '"
64 + str(post_data)
65 + "' '"
66 + hostname
67 + "'"
68 )
69
70 cmd = host.run(command)
71 assert '"jsonrpc":"2.0","result":"' in cmd.stdout