Skip to content

Commit f456ead

Browse files
authored
Merge pull request #230 from xcp-ng/netdata
Add test for netdata packages
2 parents 9cf622c + 798e1bf commit f456ead

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

tests/packages/netdata/__init__.py

Whitespace-only changes.

tests/packages/netdata/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pytest
2+
3+
# Explicitly import package-scoped fixtures (see explanation in pkgfixtures.py)
4+
from pkgfixtures import host_with_saved_yum_state
5+
6+
@pytest.fixture(scope="package")
7+
def host_with_netdata(host_with_saved_yum_state):
8+
host = host_with_saved_yum_state
9+
# Installing netdata-ui also installs netdata and all required dependencies
10+
host.yum_install(['netdata-ui'])
11+
yield host
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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

Comments
 (0)