Skip to content

Commit 61b87bc

Browse files
Add tests/integration/test_system_load.py to assert sar output
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
1 parent 723218e commit 61b87bc

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""tests/integration/test_system_load.py: Test xen-bugtool --entries=system-load"""
2+
import os
3+
4+
from utils import check_file, run_bugtool_entry, assert_content_from_dom0_template
5+
6+
7+
# In this test case we need to sleep for 1 sec, and it is sufficient
8+
# to test to only with zip archives to keep the test duration short:
9+
def test_system_load(output_archive_type="zip"):
10+
"""Test xen-bugtool --entries=system-load in test jail created by auto-fixtures in conftest.py"""
11+
entry = "system-load"
12+
13+
# Create test input files:
14+
os.mkdir("/var/log")
15+
os.mkdir("/var/log/sa")
16+
with open("/var/log/sa/sa01", "w") as sa01:
17+
sa01.write("sa01 test data")
18+
with open("/var/log/sa/sar31", "w") as sar31:
19+
sar31.write("sar31 test data")
20+
21+
# Create a dummy sar script to assert that xen-bugtool captures its output:
22+
os.environ["PATH"] = "/var:" + os.environ["PATH"]
23+
with open("/var/sar", "w") as sar:
24+
sar.write("#!/bin/sh\nsleep 1;cat /etc/xensource-inventory\n")
25+
os.chmod("/var/sar", 0o777)
26+
27+
run_bugtool_entry(output_archive_type, entry)
28+
29+
assert_content_from_dom0_template("sar-A.out", "etc/xensource-inventory")
30+
assert check_file("var/log/sa/sa01") == "sa01 test data"
31+
assert check_file("var/log/sa/sar31") == "sar31 test data"

tests/integration/test_xenserver_config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@
77
def test_xenserver_config(output_archive_type):
88
"""Test xen-bugtool --entries=xenserver-config in test jail created by auto-fixtures in conftest.py"""
99
entry = "xenserver-config"
10+
1011
run_bugtool_entry(output_archive_type, entry)
12+
13+
# Assert that the bugtool output archive of --entries=xenserver-config matches our expectations for it:
1114
assert check_file("ls-lR-%opt%xensource.out").splitlines()[0] == "/opt/xensource:"
1215
assert check_file("ls-lR-%etc%xensource%static-vdis.out") == ""
1316
assert check_file("static-vdis-list.out") == "list"
17+
18+
# Assert the contents of the extracted etc/systemd.tar
1419
os.chdir("..")
20+
# etc/systemd.tar's toplevel directory is os.environ["XENRT_BUGTOOL_BASENAME"] (= entries for the test)
1521
assert_cmd(["tar", "xvf", entry + "/etc/systemd.tar"], entry + "/etc/systemd.tar")
22+
1623
os.chdir(entry)
1724
assert_content_from_dom0_template("etc/systemd")
1825
assert_content_from_dom0_template("etc/xensource-inventory")

0 commit comments

Comments
 (0)