Skip to content

Commit

Permalink
Rename system_user_dirs to rpm_pkgs (#3597)
Browse files Browse the repository at this point in the history
* Rename system_user_dirs to system_user_pkgs

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

* Rename function to be more descriptive

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

* Rename whole module to be more descriptive

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

* Keep code conventions

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

Signed-off-by: Jitka Obselkova <[email protected]>
  • Loading branch information
jobselko authored Nov 17, 2022
1 parent 67c00de commit 3650732
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 70 deletions.
8 changes: 4 additions & 4 deletions docs/custom_datasources_index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ insights.specs.datasources.sys_fs_cgroup_memory_tasks_number
:show-inheritance:
:undoc-members:

insights.specs.datasources.system_user_dirs
-------------------------------------------
insights.specs.datasources.rpm_pkgs
-----------------------------------

.. automodule:: insights.specs.datasources.system_user_dirs
:members: system_user_dirs
.. automodule:: insights.specs.datasources.rpm_pkgs
:members: pkgs_with_writable_dirs
:show-inheritance:
:undoc-members:

Expand Down
3 changes: 3 additions & 0 deletions docs/shared_parsers_catalog/rpm_pkgs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. automodule:: insights.parsers.rpm_pkgs
:members:
:show-inheritance:
3 changes: 0 additions & 3 deletions docs/shared_parsers_catalog/system_user_dirs.rst

This file was deleted.

31 changes: 31 additions & 0 deletions insights/parsers/rpm_pkgs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
RpmPkgs - datasource ``rpm_pkgs``
=================================
Parser for CVE-2021-35937, CVE-2021-35938, and CVE-2021-35939.
For more information, see the ``rpm_pkgs`` datasource.
"""

from insights import Parser, parser
from insights.specs import Specs


@parser(Specs.rpm_pkgs)
class RpmPkgs(Parser):
"""
Class for enabling the data from the ``rpm_pkgs`` datasource.
Sample output of this datasource is::
["httpd-core"]
Examples:
>>> type(rpm_pkgs)
<class 'insights.parsers.rpm_pkgs.RpmPkgs'>
>>> rpm_pkgs.packages
['httpd-core']
"""

def parse_content(self, content):
self.packages = content
31 changes: 0 additions & 31 deletions insights/parsers/system_user_dirs.py

This file was deleted.

2 changes: 1 addition & 1 deletion insights/specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ class Specs(SpecSet):
route = RegistryPoint()
rpm_V_packages = RegistryPoint()
rpm_ostree_status = RegistryPoint()
rpm_pkgs = RegistryPoint()
rsyslog_conf = RegistryPoint(filterable=True, multi_output=True)
samba = RegistryPoint(filterable=True)
samba_logs = RegistryPoint(multi_output=True, filterable=True)
Expand Down Expand Up @@ -700,7 +701,6 @@ class Specs(SpecSet):
sysctl_conf_initramfs = RegistryPoint(multi_output=True)
sysctl_d_conf_etc = RegistryPoint(multi_output=True)
sysctl_d_conf_usr = RegistryPoint(multi_output=True)
system_user_dirs = RegistryPoint()
systemctl_cat_dnsmasq_service = RegistryPoint()
systemctl_cat_rpcbind_socket = RegistryPoint()
systemctl_cinder_volume = RegistryPoint()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class LocalSpecs(Specs):
"""
Local spec used only by the system_user_dirs datasource.
Local spec used only by the rpm_pkgs datasource.
"""
rpm_args = simple_command(
'rpm -qa --nosignature --qf="[%{=NAME}; %{FILENAMES}; %{FILEMODES:perms}; %{FILEUSERNAME}; %{FILEGROUPNAME}\n]"',
Expand Down Expand Up @@ -70,7 +70,7 @@ def get_groups(users):


@datasource(LocalSpecs.rpm_args, HostContext)
def system_user_dirs(broker):
def pkgs_with_writable_dirs(broker):
r"""
Custom datasource for CVE-2021-35937, CVE-2021-35938, and CVE-2021-35939.
Expand Down Expand Up @@ -115,5 +115,5 @@ def system_user_dirs(broker):

if packages:
return DatasourceProvider(
content=sorted(packages), relative_path="insights_commands/system_user_dirs"
content=sorted(packages), relative_path="insights_commands/rpm_pkgs"
)
4 changes: 2 additions & 2 deletions insights/specs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
aws, awx_manage, cloud_init, candlepin_broker, corosync as corosync_ds,
dir_list, ethernet, httpd, ipcs, kernel_module_list, lpstat, md5chk,
package_provides, ps as ps_datasource, sap, satellite_missed_queues,
semanage, ssl_certificate, sys_fs_cgroup_memory_tasks_number, system_user_dirs, user_group, yum_updates, luks_devices)
semanage, ssl_certificate, sys_fs_cgroup_memory_tasks_number, rpm_pkgs, user_group, yum_updates, luks_devices)
from insights.specs.datasources.sap import sap_hana_sid, sap_hana_sid_SID_nr
from insights.specs.datasources.pcp import pcp_enabled, pmlog_summary_args
from insights.specs.datasources.container import running_rhel_containers, containers_inspect
Expand Down Expand Up @@ -508,6 +508,7 @@ class DefaultSpecs(Specs):
ros_config = simple_file("/var/lib/pcp/config/pmlogger/config.ros")
rpm_V_packages = simple_command("/bin/rpm -V coreutils procps procps-ng shadow-utils passwd sudo chrony", keep_rc=True, signum=signal.SIGTERM)
rpm_ostree_status = simple_command("/usr/bin/rpm-ostree status --json", signum=signal.SIGTERM)
rpm_pkgs = rpm_pkgs.pkgs_with_writable_dirs
rsyslog_conf = glob_file(["/etc/rsyslog.conf", "/etc/rsyslog.d/*.conf"])
samba = simple_file("/etc/samba/smb.conf")
sap_hana_landscape = foreach_execute(sap_hana_sid_SID_nr, "/bin/su -l %sadm -c 'python /usr/sap/%s/HDB%s/exe/python_support/landscapeHostConfiguration.py'", keep_rc=True)
Expand Down Expand Up @@ -615,7 +616,6 @@ class DefaultSpecs(Specs):
sysctl_conf = simple_file("/etc/sysctl.conf")
sysctl_d_conf_etc = glob_file("/etc/sysctl.d/*.conf")
sysctl_d_conf_usr = glob_file("/usr/lib/sysctl.d/*.conf")
system_user_dirs = system_user_dirs.system_user_dirs
systemctl_cat_rpcbind_socket = simple_command("/bin/systemctl cat rpcbind.socket")
systemctl_httpd = simple_command("/bin/systemctl show httpd")
systemctl_list_unit_files = simple_command("/bin/systemctl list-unit-files")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from insights.core.dr import SkipComponent
from insights.core.spec_factory import DatasourceProvider
from insights.specs.datasources.system_user_dirs import LocalSpecs, system_user_dirs
from insights.specs.datasources.rpm_pkgs import LocalSpecs, pkgs_with_writable_dirs

RPM_CMD = """
httpd-core; /usr/share/doc/httpd-core; drwxr-xr-x; apache; root
Expand All @@ -21,7 +21,7 @@

RPM_EMPTY_CMD = ""

RELATIVE_PATH = "insights_commands/system_user_dirs"
RELATIVE_PATH = "insights_commands/rpm_pkgs"


def get_users():
Expand All @@ -32,14 +32,14 @@ def get_groups(users):
return ["apache", "postgres"]


@mock.patch("insights.specs.datasources.system_user_dirs.get_users", get_users)
@mock.patch("insights.specs.datasources.system_user_dirs.get_groups", get_groups)
@mock.patch("insights.specs.datasources.rpm_pkgs.get_users", get_users)
@mock.patch("insights.specs.datasources.rpm_pkgs.get_groups", get_groups)
def test_rpm():
rpm_args = Mock()
rpm_args.content = RPM_CMD.splitlines()
broker = {LocalSpecs.rpm_args: rpm_args}

result = system_user_dirs(broker)
result = pkgs_with_writable_dirs(broker)
expected = DatasourceProvider(content=RPM_EXPECTED, relative_path=RELATIVE_PATH)
assert result
assert isinstance(result, DatasourceProvider)
Expand All @@ -54,4 +54,4 @@ def test_no_rpm(no_rpm):
broker = {LocalSpecs.rpm_args: rpm_args}

with pytest.raises(SkipComponent):
system_user_dirs(broker)
pkgs_with_writable_dirs(broker)
20 changes: 20 additions & 0 deletions insights/tests/parsers/test_rpm_pkgs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import doctest

from insights.parsers import rpm_pkgs
from insights.parsers.rpm_pkgs import RpmPkgs
from insights.tests import context_wrap

PACKAGES = ["httpd-core"]


def test_system_user_dirs():
test = RpmPkgs(context_wrap(PACKAGES))
assert test.packages == PACKAGES


def test_doc_examples():
env = {
"rpm_pkgs": RpmPkgs(context_wrap(PACKAGES))
}
failed, total = doctest.testmod(rpm_pkgs, globs=env)
assert failed == 0
20 changes: 0 additions & 20 deletions insights/tests/parsers/test_system_user_dirs.py

This file was deleted.

0 comments on commit 3650732

Please sign in to comment.