From aa0a136b44a7a308cc6b7baba84c2fa5684a6d48 Mon Sep 17 00:00:00 2001 From: Rohini Chandra <61837065+r14chandra@users.noreply.github.com> Date: Mon, 9 Oct 2023 14:44:50 +0530 Subject: [PATCH] RHINENG-1512 add a list of failed systemd units (#301) --- src/puptoo/process/profile.py | 8 +++++++- tests/test_systemctl_status_all.py | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/puptoo/process/profile.py b/src/puptoo/process/profile.py index b59a7b8f..28459a02 100644 --- a/src/puptoo/process/profile.py +++ b/src/puptoo/process/profile.py @@ -35,7 +35,7 @@ from insights.parsers.ros_config import RosConfig from insights.parsers.rpm_ostree_status import RpmOstreeStatus from insights.parsers.sestatus import SEStatus -from insights.parsers.systemd.unitfiles import UnitFiles +from insights.parsers.systemd.unitfiles import UnitFiles, ListUnits from insights.parsers.tuned import Tuned from insights.parsers.uname import Uname from insights.parsers.uptime import Uptime @@ -104,6 +104,7 @@ def catch_error(parser, error): HDBVersion, InstalledRpms, UnitFiles, + ListUnits, PmLogSummary, PsAuxcww, DateUTC, @@ -153,6 +154,7 @@ def system_profile( hdb_version, installed_rpms, unit_files, + list_units, pmlog_summary, ps_auxcww, date_utc, @@ -621,6 +623,10 @@ def system_profile( "jobs_queued": int(systemctl_status_all.jobs.split(" ")[0]), "failed": int(systemctl_status_all.failed.split(" ")[0]) } + if list_units: + if int(systemctl_status_all.failed.split(" ")[0]) > 0: + profile["systemd"]["failed_services"] = [svc for svc in list_units.service_names + if list_units.is_failed(svc)] if aws_public_ipv4_addresses: profile["public_ipv4_addresses"] = _remove_empty_string(aws_public_ipv4_addresses) diff --git a/tests/test_systemctl_status_all.py b/tests/test_systemctl_status_all.py index 6e581c89..4f94dccb 100644 --- a/tests/test_systemctl_status_all.py +++ b/tests/test_systemctl_status_all.py @@ -24,6 +24,17 @@ Sep 23 15:11:07 redhat.test.com systemd[1]: proc-sys-fs-binfmt_misc.automount: Got automount request for /proc/sys/fs/binfmt_mis """.strip() + +LISTUNITS = """ +sockets.target loaded active active Sockets +swap.target loaded active active Swap +systemd-shutdownd.socket loaded active listening Delayed Shutdown Socket +neutron-dhcp-agent.service loaded active running OpenStack Neutron DHCP Agent +neutron-openvswitch-agent.service loaded active running OpenStack Neutron Open vSwitch Agent +chronyd.service loaded failed failed NTP client/server +""".strip() + + def test_systemctl_status(): input_data = InputData().add(Specs.systemctl_status_all, SYSTEMCTLSTATUSALL) result = run_test(system_profile, input_data) @@ -32,3 +43,12 @@ def test_systemctl_status(): assert result['systemd']['jobs_queued'] == 0 assert result['systemd']['state'] == 'degraded' + input_data = InputData() + input_data.add(Specs.systemctl_status_all, SYSTEMCTLSTATUSALL) + input_data.add(Specs.systemctl_list_units, LISTUNITS) + result = run_test(system_profile, input_data) + + assert result['systemd']['failed'] == 2 + assert result['systemd']['jobs_queued'] == 0 + assert result['systemd']['state'] == 'degraded' + assert result['systemd']['failed_services'] == ['chronyd.service']