From 4ad068df0c9acf6e8ca5698e71f4fda7c37b5a5f Mon Sep 17 00:00:00 2001 From: Thierry Escande Date: Wed, 14 Aug 2024 14:39:18 +0200 Subject: [PATCH 1/3] Add test for failed systemd units This change adds a test for systemd units and verifies that no unit is in failed state. Signed-off-by: Thierry Escande --- tests/system/test_systemd.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/system/test_systemd.py diff --git a/tests/system/test_systemd.py b/tests/system/test_systemd.py new file mode 100644 index 000000000..010a9cd86 --- /dev/null +++ b/tests/system/test_systemd.py @@ -0,0 +1,15 @@ +import logging +import pytest +import re + +# Requirements: +# - an XCP-ng host (--hosts) >= 8.2 + +pytest.fixture(scope='module') +def test_failed_units(host): + failed_services = host.ssh(['systemctl', '--state=failed', '--full', '--all', + '--no-pager', '--no-legend']) + for unit in failed_services.splitlines(): + logging.error(f"Unit {unit.split()[0]} failed") + + assert not failed_services From b9a95729ff58e83ec8774039f5032eddefdb27e0 Mon Sep 17 00:00:00 2001 From: Thierry Escande Date: Wed, 14 Aug 2024 14:40:20 +0200 Subject: [PATCH 2/3] Add test for systemd default target This test uses 'systemd-analyze verify default.target' and check for unknown issues. Known issues reported by systemd-analyze are listed in a white list array. Anything else is reported as error. Signed-off-by: Thierry Escande --- tests/system/test_systemd.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/system/test_systemd.py b/tests/system/test_systemd.py index 010a9cd86..3b00d48b8 100644 --- a/tests/system/test_systemd.py +++ b/tests/system/test_systemd.py @@ -13,3 +13,19 @@ def test_failed_units(host): logging.error(f"Unit {unit.split()[0]} failed") assert not failed_services + +white_list_issues = [ + "Cannot add dependency job for unit getty@tty1.service, ignoring: Unit is masked.", + "Cannot add dependency job for unit display-manager.service, ignoring: Unit not found.", +] + +pytest.fixture(scope='module') +def test_verify_default_target(host): + analyse = host.ssh(['systemd-analyze', 'verify', 'default.target']) + err = False + for line in analyse.splitlines(): + if line not in white_list_issues: + logging.error(f"{line}") + err = True + + assert not err From 9d2cf44ca89cfac9c58c18476ee15b0256ae0d49 Mon Sep 17 00:00:00 2001 From: Thierry Escande Date: Wed, 31 Jul 2024 11:28:34 +0200 Subject: [PATCH 3/3] jobs.py: Add tests/system to main tests This adds tests/systemd/test_systemd.py to the JOBS main entry. This will not add test_irqbalance.py which is marked as flaky. Signed-off-by: Thierry Escande --- jobs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jobs.py b/jobs.py index b458f72d6..82e80cb82 100755 --- a/jobs.py +++ b/jobs.py @@ -26,6 +26,7 @@ "tests/migration", "tests/network", "tests/snapshot", + "tests/system", "tests/xapi", "tests/xapi-plugins", ],