Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New specs for systemd ls output and modification of existing parser #3424

Merged
merged 2 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/shared_parsers_catalog/ls_run_systemd.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. automodule:: insights.parsers.ls_run_systemd
:members:
:show-inheritance:
3 changes: 0 additions & 3 deletions docs/shared_parsers_catalog/ls_run_systemd_generator.rst

This file was deleted.

77 changes: 77 additions & 0 deletions insights/parsers/ls_run_systemd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""
LsRunSystemd - command ``ls -lanRL /run/systemd``
=================================================
The ``ls -lanRL /run/systemd`` command provides information for the listing of the ``/run/systemd`` directory.
Sample input is shown in the Examples. See ``FileListing`` class for
additional information.
Sample output of ``ls -lanRL /run/systemd`` command is::
/run/systemd:
total 0
drwxr-xr-x. 16 0 0 400 May 25 09:03 .
drwxr-xr-x. 33 0 0 940 May 25 09:03 ..
srwx------. 1 0 0 0 May 25 09:03 cgroups-agent
srw-------. 1 0 0 0 May 25 09:03 coredump
drwxr-xr-x. 4 0 0 140 May 25 09:03 generator
d---------. 3 0 0 160 May 25 09:03 inaccessible
srwxrwxrwx. 1 0 0 0 May 25 09:03 notify
srwxrwxrwx. 1 0 0 0 May 25 09:03 private
drwxr-xr-x. 2 0 0 40 May 25 09:03 system
drwxr-xr-x. 2 0 0 100 May 25 09:17 transient
/run/systemd/generator:
total 12
drwxr-xr-x. 4 0 0 140 May 25 09:03 .
drwxr-xr-x. 16 0 0 400 May 25 09:03 ..
-rw-r--r--. 1 0 0 254 May 25 09:03 boot.mount
-rw-r--r--. 1 0 0 230 May 25 09:03 dev-mapper-rhel\x2dswap.swap
drwxr-xr-x. 2 0 0 80 May 25 09:03 local-fs.target.requires
-rw-r--r--. 1 0 0 217 May 25 09:03 -.mount
drwxr-xr-x. 2 0 0 60 May 25 09:03 swap.target.requires
/run/systemd/generator/local-fs.target.requires:
total 8
drwxr-xr-x. 2 0 0 80 May 25 09:03 .
drwxr-xr-x. 4 0 0 140 May 25 09:03 ..
-rw-r--r--. 1 0 0 254 May 25 09:03 boot.mount
-rw-r--r--. 1 0 0 217 May 25 09:03 -.mount
/run/systemd/generator/swap.target.requires:
total 4
drwxr-xr-x. 2 0 0 60 May 25 09:03 .
drwxr-xr-x. 4 0 0 140 May 25 09:03 ..
-rw-r--r--. 1 0 0 230 May 25 09:03 dev-mapper-rhel\x2dswap.swap
/run/systemd/system:
total 0
drwxr-xr-x. 2 0 0 40 May 25 09:03 .
drwxr-xr-x. 16 0 0 400 May 25 09:03 ..
/run/systemd/transient:
total 12
drwxr-xr-x. 2 0 0 100 May 25 09:17 .
drwxr-xr-x. 16 0 0 400 May 25 09:03 ..
-rw-r--r--. 1 0 0 275 May 25 09:04 session-6.scope
-rw-r--r--. 1 0 0 275 May 25 09:17 session-7.scope
-rw-r--r--. 1 0 0 275 May 25 09:17 session-8.scope
Examples:
>>> type(ls_run_systemd)
<class 'insights.parsers.ls_run_systemd.LsRunSystemd'>
>>> ls_run_systemd.files_of("/run/systemd/generator") == ['boot.mount', 'dev-mapper-rhel-swap.swap', '-.mount']
True
>>> ls_run_systemd.dir_entry("/run/systemd/generator", "-.mount")["perms"]
'rw-r--r--.'
"""

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


@parser(Specs.ls_run_systemd)
class LsRunSystemd(CommandParser, FileListing):
"""Parses output of ``ls -lanRL /run/systemd`` command."""
pass
43 changes: 0 additions & 43 deletions insights/parsers/ls_run_systemd_generator.py

This file was deleted.

5 changes: 4 additions & 1 deletion insights/specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,16 @@ class Specs(SpecSet):
ls_ocp_cni_openshift_sdn = RegistryPoint()
ls_origin_local_volumes_pods = RegistryPoint()
ls_osroot = RegistryPoint()
ls_run_systemd_generator = RegistryPoint()
ls_run_systemd = RegistryPoint()
ls_R_var_lib_nova_instances = RegistryPoint()
ls_sys_firmware = 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
5 changes: 4 additions & 1 deletion insights/specs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,16 @@ def httpd_cmd(broker):
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_generator = simple_command("/bin/ls -lan /run/systemd/generator")
ls_run_systemd = simple_command("/bin/ls -lanRL /run/systemd")
xiangce marked this conversation as resolved.
Show resolved Hide resolved
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_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")
xiangce marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 1 addition & 1 deletion insights/specs/insights_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class InsightsArchiveSpecs(Specs):
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_generator = simple_file("insights_commands/ls_-lan_.run.systemd.generator")
ls_run_systemd = simple_file("insights_commands/ls_-lanRL_.run.systemd")
xiangce marked this conversation as resolved.
Show resolved Hide resolved
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_tmp = simple_file("insights_commands/ls_-la_.tmp")
Expand Down
83 changes: 83 additions & 0 deletions insights/tests/parsers/test_ls_run_systemd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import doctest

from insights.parsers import ls_run_systemd
from insights.parsers.ls_run_systemd import LsRunSystemd
from insights.tests import context_wrap


# command output is shortened
LS_RUN_SYSTEMD = """
/run/systemd:
total 0
drwxr-xr-x. 16 0 0 400 May 25 09:03 .
drwxr-xr-x. 33 0 0 940 May 25 09:03 ..
srwx------. 1 0 0 0 May 25 09:03 cgroups-agent
srw-------. 1 0 0 0 May 25 09:03 coredump
drwxr-xr-x. 4 0 0 140 May 25 09:03 generator
d---------. 3 0 0 160 May 25 09:03 inaccessible
srwxrwxrwx. 1 0 0 0 May 25 09:03 notify
srwxrwxrwx. 1 0 0 0 May 25 09:03 private
drwxr-xr-x. 2 0 0 40 May 25 09:03 system
drwxr-xr-x. 2 0 0 100 May 25 09:17 transient
/run/systemd/generator:
total 12
drwxr-xr-x. 4 0 0 140 May 25 09:03 .
drwxr-xr-x. 16 0 0 400 May 25 09:03 ..
-rw-r--r--. 1 0 0 254 May 25 09:03 boot.mount
-rw-r--r--. 1 0 0 230 May 25 09:03 dev-mapper-rhel\x2dswap.swap
drwxr-xr-x. 2 0 0 80 May 25 09:03 local-fs.target.requires
-rw-r--r--. 1 0 0 217 May 25 09:03 -.mount
drwxr-xr-x. 2 0 0 60 May 25 09:03 swap.target.requires
/run/systemd/generator/local-fs.target.requires:
total 8
drwxr-xr-x. 2 0 0 80 May 25 09:03 .
drwxr-xr-x. 4 0 0 140 May 25 09:03 ..
-rw-r--r--. 1 0 0 254 May 25 09:03 boot.mount
-rw-r--r--. 1 0 0 217 May 25 09:03 -.mount
/run/systemd/generator/swap.target.requires:
total 4
drwxr-xr-x. 2 0 0 60 May 25 09:03 .
drwxr-xr-x. 4 0 0 140 May 25 09:03 ..
-rw-r--r--. 1 0 0 230 May 25 09:03 dev-mapper-rhel\x2dswap.swap
/run/systemd/system:
total 0
drwxr-xr-x. 2 0 0 40 May 25 09:03 .
drwxr-xr-x. 16 0 0 400 May 25 09:03 ..
/run/systemd/transient:
total 12
drwxr-xr-x. 2 0 0 100 May 25 09:17 .
drwxr-xr-x. 16 0 0 400 May 25 09:03 ..
-rw-r--r--. 1 0 0 275 May 25 09:04 session-6.scope
-rw-r--r--. 1 0 0 275 May 25 09:17 session-7.scope
-rw-r--r--. 1 0 0 275 May 25 09:17 session-8.scope
""".strip()


def test_ls_run_systemd():
run_systemd = LsRunSystemd(context_wrap(LS_RUN_SYSTEMD))
assert run_systemd
assert len(run_systemd.listings) == 6
assert run_systemd.dirs_of("/run/systemd/generator") == [
'.', '..', 'local-fs.target.requires', 'swap.target.requires'
]
assert run_systemd.files_of("/run/systemd/generator") == [
'boot.mount', 'dev-mapper-rhel-swap.swap', '-.mount'
]
assert run_systemd.listing_of("/run/systemd/generator")['-.mount'] == {
'date': 'May 25 09:03', 'dir': '/run/systemd/generator', 'group': '0', 'links': 1,
'name': '-.mount', 'owner': '0', 'perms': 'rw-r--r--.',
'raw_entry': '-rw-r--r--. 1 0 0 217 May 25 09:03 -.mount', 'size': 217, 'type': '-'
}


def test_ls_osroot_doc_examples():
env = {
'ls_run_systemd': LsRunSystemd(context_wrap(LS_RUN_SYSTEMD))
}
failed, total = doctest.testmod(ls_run_systemd, globs=env)
assert failed == 0
46 changes: 0 additions & 46 deletions insights/tests/parsers/test_ls_run_systemd_generator.py

This file was deleted.