Skip to content

Commit

Permalink
feat: Parser for "ls systemd units" (#3451)
Browse files Browse the repository at this point in the history
* Create a new file for ls systemd units parsers

Signed-off-by: Jitka Obselkova <[email protected]>

* Remove separate files for ls systemd units parsers

Signed-off-by: Jitka Obselkova <[email protected]>

* Remove unused specs

Signed-off-by: Jitka Obselkova <[email protected]>

* Rework parsers into one

Signed-off-by: Jitka Obselkova <[email protected]>

* Update insights_archive

Signed-off-by: Jitka Obselkova <[email protected]>
(cherry picked from commit bc6fff8)
  • Loading branch information
jobselko authored and xiangce committed Jun 30, 2022
1 parent 80e5510 commit 43d90b6
Show file tree
Hide file tree
Showing 12 changed files with 1,177 additions and 441 deletions.
3 changes: 0 additions & 3 deletions docs/shared_parsers_catalog/ls_run_systemd.rst

This file was deleted.

3 changes: 0 additions & 3 deletions docs/shared_parsers_catalog/ls_systemd.rst

This file was deleted.

3 changes: 3 additions & 0 deletions docs/shared_parsers_catalog/ls_systemd_units.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. automodule:: insights.parsers.ls_systemd_units
:members:
:show-inheritance:
77 changes: 0 additions & 77 deletions insights/parsers/ls_run_systemd.py

This file was deleted.

124 changes: 0 additions & 124 deletions insights/parsers/ls_systemd.py

This file was deleted.

85 changes: 85 additions & 0 deletions insights/parsers/ls_systemd_units.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"""
LsSystemdUnits - command ``/bin/ls -lanRL /etc/systemd /run/systemd /usr/lib/systemd /usr/local/lib/systemd``
=============================================================================================================
This parser provides file listing for Systemd Units gathered from
the ``/bin/ls -lanRL /etc/systemd /run/systemd /usr/lib/systemd /usr/local/lib/systemd`` command.
The paths ``/usr/local/share/systemd`` and ``/usr/share/systemd`` were also checked,
but no results were found for them.
The shortened sample output of the command is::
/etc/systemd:
total 40
drwxr-xr-x. 4 0 0 150 Apr 4 2019 .
drwxr-xr-x. 88 0 0 8192 Jun 28 06:56 ..
-rw-r--r--. 1 0 0 615 Jun 22 2018 coredump.conf
-rw-r--r--. 1 0 0 1027 Jun 22 2018 journald.conf
-rw-r--r--. 1 0 0 1052 Apr 4 2019 logind.conf
-rw-r--r--. 1 0 0 631 Feb 26 2019 resolved.conf
drwxr-xr-x. 17 0 0 4096 Apr 4 2019 system
-rw-r--r--. 1 0 0 1682 Feb 26 2019 system.conf
drwxr-xr-x. 2 0 0 6 Feb 26 2019 user
-rw-r--r--. 1 0 0 1130 Jun 22 2018 user.conf
/etc/systemd/system:
total 28
drwxr-xr-x. 17 0 0 4096 Apr 4 2019 .
drwxr-xr-x. 4 0 0 150 Apr 4 2019 ..
drwxr-xr-x. 2 0 0 31 Apr 4 2019 basic.target.wants
-rw-r--r--. 1 0 0 1341 Feb 8 2019 dbus-org.freedesktop.NetworkManager.service
-rw-r--r--. 1 0 0 353 Feb 8 2019 dbus-org.freedesktop.nm-dispatcher.service
-rw-r--r--. 1 0 0 238 Nov 7 2017 dbus-org.freedesktop.timedate1.service
-rw-r--r--. 1 0 0 532 Jun 22 2018 default.target
drwxr-xr-x. 2 0 0 32 Apr 4 2019 getty.target.wants
drwxr-xr-x. 2 0 0 4096 Apr 4 2019 multi-user.target.wants
drwxr-xr-x. 2 0 0 48 Apr 4 2019 network-online.target.wants
drwxr-xr-x. 2 0 0 33 Apr 4 2019 nfs-blkmap.service.requires
drwxr-xr-x. 2 0 0 33 Apr 4 2019 nfs-idmapd.service.requires
drwxr-xr-x. 2 0 0 33 Apr 4 2019 nfs-mountd.service.requires
drwxr-xr-x. 2 0 0 33 Apr 4 2019 nfs-server.service.requires
drwxr-xr-x. 2 0 0 31 Apr 4 2019 remote-fs.target.wants
drwxr-xr-x. 2 0 0 33 Apr 4 2019 rpc-gssd.service.requires
drwxr-xr-x. 2 0 0 33 Apr 4 2019 rpc-statd-notify.service.requires
drwxr-xr-x. 2 0 0 33 Apr 4 2019 rpc-statd.service.requires
drwxr-xr-x. 2 0 0 51 Apr 4 2019 sockets.target.wants
drwxr-xr-x. 2 0 0 151 Apr 4 2019 sysinit.target.wants
-rw-r--r--. 1 0 0 583 Dec 17 2018 syslog.service
crw-rw-rw-. 1 0 0 1, 3 Jun 28 06:56 systemd-timedated.service
drwxr-xr-x. 2 0 0 34 Apr 4 2019 timers.target.wants
/etc/systemd/system/basic.target.wants:
total 8
drwxr-xr-x. 2 0 0 31 Apr 4 2019 .
drwxr-xr-x. 17 0 0 4096 Apr 4 2019 ..
-rw-r--r--. 1 0 0 284 Nov 6 2018 microcode.service
Examples:
>>> type(ls_systemd_units)
<class 'insights.parsers.ls_systemd_units.LsSystemdUnits'>
>>> ls_systemd_units.dirs_of("/etc/systemd")
['.', '..', 'system', 'user']
>>> ls_systemd_units.files_of("/etc/systemd/system/basic.target.wants")
['microcode.service']
>>> ls_systemd_units.specials_of("/etc/systemd/system")
['systemd-timedated.service']
>>> ls_systemd_units.dir_contains("/etc/systemd/system", "default.target")
True
>>> ls_systemd_units.dir_entry("/etc/systemd/system", "syslog.service")["perms"]
'rw-r--r--.'
"""

from insights.core import CommandParser, FileListing
from insights.core.plugins import parser
from insights.specs import Specs


@parser(Specs.ls_systemd_units)
class LsSystemdUnits(CommandParser, FileListing):
"""
Class for parsing the ``/bin/ls -lanRL /etc/systemd /run/systemd /usr/lib/systemd /usr/local/lib/systemd`` command.
For more information, see the ``FileListing`` class.
"""
pass
7 changes: 1 addition & 6 deletions insights/specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,22 +322,17 @@ class Specs(SpecSet):
ls_docker_volumes = RegistryPoint()
ls_edac_mc = RegistryPoint()
ls_etc = RegistryPoint()
ls_etc_systemd = RegistryPoint()
ls_ipa_idoverride_memberof = RegistryPoint()
ls_lib_firmware = RegistryPoint()
ls_ocp_cni_openshift_sdn = RegistryPoint()
ls_origin_local_volumes_pods = RegistryPoint()
ls_osroot = RegistryPoint()
ls_run_systemd = RegistryPoint()
ls_R_var_lib_nova_instances = RegistryPoint()
ls_sys_firmware = RegistryPoint()
ls_systemd_units = RegistryPoint()
ls_usr_bin = RegistryPoint(filterable=True)
ls_usr_lib64 = RegistryPoint(filterable=True)
ls_usr_lib_systemd = RegistryPoint()
ls_usr_local_lib_systemd = RegistryPoint()
ls_usr_local_share_systemd = RegistryPoint()
ls_usr_sbin = RegistryPoint(filterable=True)
ls_usr_share_systemd = RegistryPoint()
ls_var_cache_pulp = RegistryPoint()
ls_var_lib_mongodb = RegistryPoint()
ls_var_lib_nova_instances = RegistryPoint()
Expand Down
9 changes: 3 additions & 6 deletions insights/specs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,22 +323,19 @@ class DefaultSpecs(Specs):
"/etc/pki/ovirt-vmconsole", "/etc/nova/migration", "/etc/sysconfig",
"/etc/cloud/cloud.cfg.d", "/etc/rc.d/init.d"])
ls_etc = simple_command("/bin/ls -lan {0}".format(' '.join(etc_and_sub_dirs)), keep_rc=True)
ls_etc_systemd = simple_command("/bin/ls -lanRL /etc/systemd")
ls_ipa_idoverride_memberof = simple_command("/bin/ls -lan /usr/share/ipa/ui/js/plugins/idoverride-memberof")
ls_lib_firmware = simple_command("/bin/ls -lanR /lib/firmware")
ls_ocp_cni_openshift_sdn = simple_command("/bin/ls -l /var/lib/cni/networks/openshift-sdn")
ls_origin_local_volumes_pods = simple_command("/bin/ls -l /var/lib/origin/openshift.local.volumes/pods")
ls_osroot = simple_command("/bin/ls -lan /")
ls_run_systemd = simple_command("/bin/ls -lanRL /run/systemd")
ls_R_var_lib_nova_instances = simple_command("/bin/ls -laR /var/lib/nova/instances")
ls_sys_firmware = simple_command("/bin/ls -lanR /sys/firmware")
ls_systemd_units = simple_command(
"/bin/ls -lanRL /etc/systemd /run/systemd /usr/lib/systemd /usr/local/lib/systemd", keep_rc=True
)
ls_tmp = simple_command("/bin/ls -la /tmp")
ls_usr_bin = simple_command("/bin/ls -lan /usr/bin")
ls_usr_lib64 = simple_command("/bin/ls -lan /usr/lib64")
ls_usr_lib_systemd = simple_command("/bin/ls -lanRL /usr/lib/systemd")
ls_usr_local_lib_systemd = simple_command("/bin/ls -lanRL /usr/local/lib/systemd")
ls_usr_local_share_systemd = simple_command("/bin/ls -lanRL /usr/local/share/systemd")
ls_usr_share_systemd = simple_command("/bin/ls -lanRL /usr/share/systemd")
ls_var_cache_pulp = simple_command("/bin/ls -lan /var/cache/pulp")
ls_var_lib_mongodb = simple_command("/bin/ls -la /var/lib/mongodb")
ls_var_lib_nova_instances = simple_command("/bin/ls -laRZ /var/lib/nova/instances")
Expand Down
4 changes: 1 addition & 3 deletions insights/specs/insights_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,17 @@ class InsightsArchiveSpecs(Specs):
ls_disk = simple_file("insights_commands/ls_-lanR_.dev.disk")
ls_edac_mc = simple_file("insights_commands/ls_-lan_.sys.devices.system.edac.mc")
ls_etc = simple_file("insights_commands/ls_-lan_.etc_.etc.cloud.cloud.cfg.d_.etc.nova.migration_.etc.pki.ovirt-vmconsole_.etc.pki.tls.certs_.etc.pki.tls.private_.etc.rc.d.init.d_.etc.sysconfig")
ls_etc_systemd = simple_file("insights_commands/ls_-lanRL_.etc.systemd")
ls_ipa_idoverride_memberof = simple_file("insights_commands/ls_-lan_.usr.share.ipa.ui.js.plugins.idoverride-memberof")
ls_lib_firmware = simple_file("insights_commands/ls_-lanR_.lib.firmware")
ls_ocp_cni_openshift_sdn = simple_file("insights_commands/ls_-l_.var.lib.cni.networks.openshift-sdn")
ls_origin_local_volumes_pods = simple_file("insights_commands/ls_-l_.var.lib.origin.openshift.local.volumes.pods")
ls_osroot = simple_file("insights_commands/ls_-lan")
ls_run_systemd = simple_file("insights_commands/ls_-lanRL_.run.systemd")
ls_R_var_lib_nova_instances = simple_file("insights_commands/ls_-laR_.var.lib.nova.instances")
ls_sys_firmware = simple_file("insights_commands/ls_-lanR_.sys.firmware")
ls_systemd_units = simple_file("insights_commands/ls_-lanRL_.etc.systemd_.run.systemd_.usr.lib.systemd_.usr.local.lib.systemd")
ls_tmp = simple_file("insights_commands/ls_-la_.tmp")
ls_usr_bin = simple_file("insights_commands/ls_-lan_.usr.bin")
ls_usr_lib64 = simple_file("insights_commands/ls_-lan_.usr.lib64")
ls_usr_lib_systemd = simple_file("insights_commands/ls_-lanRL_.usr.lib.systemd")
ls_var_cache_pulp = simple_file("insights_commands/ls_-lan_.var.cache.pulp")
ls_var_lib_mongodb = simple_file("insights_commands/ls_-la_.var.lib.mongodb")
ls_var_lib_nova_instances = simple_file("insights_commands/ls_-laRZ_.var.lib.nova.instances")
Expand Down
Loading

0 comments on commit 43d90b6

Please sign in to comment.