|
| 1 | +import pytest |
| 2 | +import subprocess |
| 3 | + |
| 4 | +from lib.netutil import wrap_ip |
| 5 | + |
| 6 | +# This test installs netdata and netdata-ui packages, verifies the service status, |
| 7 | +# checks that the configuration is only accessible from the host, and verifies that |
| 8 | +# the web UI is accessible through port 19999. |
| 9 | +# |
| 10 | +# Requirements: |
| 11 | +# - an XCP-ng host |
| 12 | + |
| 13 | +@pytest.mark.usefixtures("host_with_netdata") |
| 14 | +class TestsNetdata: |
| 15 | + def __get_headers(host, port, path=None): |
| 16 | + url = f"http://{wrap_ip(host.hostname_or_ip)}:{port}" |
| 17 | + if path is not None: |
| 18 | + url += f"/{path}" |
| 19 | + process = subprocess.Popen( |
| 20 | + ["curl", "-XGET", "-k", "-I", "-s", url], |
| 21 | + stdout=subprocess.PIPE, |
| 22 | + stderr=subprocess.PIPE |
| 23 | + ) |
| 24 | + stdout, _ = process.communicate() |
| 25 | + return stdout.decode().splitlines() |
| 26 | + |
| 27 | + # Verify the ActiveState for the netdata service |
| 28 | + def test_netdata_service(self, host_with_netdata): |
| 29 | + host_with_netdata.ssh(['systemctl', 'is-active', 'netdata.service']) |
| 30 | + |
| 31 | + # Netdata configuration should be accessible only from the host |
| 32 | + def test_netdata_conf(self, host_with_netdata): |
| 33 | + host = host_with_netdata |
| 34 | + lines = TestsNetdata.__get_headers(host, 19999, "netdata.conf") |
| 35 | + assert lines[0].strip() == "HTTP/1.1 403 Forbidden" |
| 36 | + |
| 37 | + stdout = host.ssh(['curl', "-XGET", "-k", "-I", '-s', 'localhost:19999/netdata.conf']) |
| 38 | + lines = stdout.splitlines() |
| 39 | + assert lines[0].strip() == "HTTP/1.1 200 OK" |
| 40 | + |
| 41 | + # Verify the web UI is accessible. i.e. port 19999 is opened |
| 42 | + def test_netdata_webui(self, host_with_netdata): |
| 43 | + host = host_with_netdata |
| 44 | + lines = TestsNetdata.__get_headers(host, 19999) |
| 45 | + assert lines[0].strip() == "HTTP/1.1 200 OK" |
0 commit comments