Skip to content

Commit

Permalink
RHINENG-1512 add a list of failed systemd units (RedHatInsights#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
r14chandra authored Oct 9, 2023
1 parent e704b70 commit aa0a136
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/puptoo/process/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -104,6 +104,7 @@ def catch_error(parser, error):
HDBVersion,
InstalledRpms,
UnitFiles,
ListUnits,
PmLogSummary,
PsAuxcww,
DateUTC,
Expand Down Expand Up @@ -153,6 +154,7 @@ def system_profile(
hdb_version,
installed_rpms,
unit_files,
list_units,
pmlog_summary,
ps_auxcww,
date_utc,
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions tests/test_systemctl_status_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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']

0 comments on commit aa0a136

Please sign in to comment.