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

fix: Update the spec "du_dirs" to filterable #3384

Merged
merged 3 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions docs/custom_datasources_index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ insights.specs.datasources.ethernet
:show-inheritance:
:undoc-members:

insights.specs.datasources.get_dirs
-----------------------------------

.. automodule:: insights.specs.datasources.get_dirs
:members: du_dirs_list
:show-inheritance:
:undoc-members:

insights.specs.datasources.ipcs
-------------------------------

Expand Down
2 changes: 1 addition & 1 deletion insights/specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class Specs(SpecSet):
doveconf = RegistryPoint(filterable=True)
dracut_kdump_capture_service = RegistryPoint()
dse_ldif = RegistryPoint(multi_output=True, filterable=True)
du_dirs = RegistryPoint(multi_output=True)
du_dirs = RegistryPoint(multi_output=True, filterable=True)
dumpe2fs_h = RegistryPoint(multi_output=True)
engine_config_all = RegistryPoint()
engine_db_query_vdsm_version = RegistryPoint()
Expand Down
15 changes: 15 additions & 0 deletions insights/specs/datasources/get_dirs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Custom datasources to get a list of directories to check disk size.
"""

from insights.core.context import HostContext
from insights.core.plugins import datasource
from insights.core.filters import get_filters
from insights.specs import Specs


@datasource(HostContext)
def du_dirs_list(broker):
""" Return a list of directories from the spec filter """
filters = get_filters(Specs.du_dirs)
xiangce marked this conversation as resolved.
Show resolved Hide resolved
return list(filters)
12 changes: 4 additions & 8 deletions insights/specs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
from insights.combiners.satellite_version import SatelliteVersion, CapsuleVersion
from insights.specs import Specs
from insights.specs.datasources import (
awx_manage, cloud_init, candlepin_broker, ethernet, get_running_commands, ipcs, lpstat, package_provides,
ps as ps_datasource, sap, satellite_missed_queues, ssl_certificate, yum_updates)
awx_manage, cloud_init, candlepin_broker, ethernet, get_dirs,
get_running_commands, ipcs, lpstat, package_provides, ps as ps_datasource,
sap, satellite_missed_queues, ssl_certificate, yum_updates)
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

Expand Down Expand Up @@ -210,12 +211,7 @@ def corosync_cmapctl_cmd_list(broker):
docker_sysconfig = simple_file("/etc/sysconfig/docker")
dotnet_version = simple_command("/usr/bin/dotnet --version")
dracut_kdump_capture_service = simple_file("/usr/lib/dracut/modules.d/99kdumpbase/kdump-capture.service")

@datasource(HostContext)
def du_dirs_list(broker):
""" Provide a list of directorys for the ``du_dirs`` spec to scan """
return ['/var/lib/candlepin/activemq-artemis']
du_dirs = foreach_execute(du_dirs_list, "/bin/du -s -k %s")
du_dirs = foreach_execute(get_dirs.du_dirs_list, "/bin/du -s -k %s")
engine_db_query_vdsm_version = simple_command('engine-db-query --statement "SELECT vs.vds_name, rpm_version FROM vds_dynamic vd, vds_static vs WHERE vd.vds_id = vs.vds_id" --json')
engine_log = simple_file("/var/log/ovirt-engine/engine.log")
etc_journald_conf = simple_file(r"etc/systemd/journald.conf")
Expand Down
29 changes: 29 additions & 0 deletions insights/tests/datasources/test_get_dirs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from insights.specs import Specs
from insights.core import filters
from insights.specs.datasources.get_dirs import du_dirs_list


def setup_function(func):
if Specs.du_dirs in filters._CACHE:
del filters._CACHE[Specs.du_dirs]
if Specs.du_dirs in filters.FILTERS:
del filters.FILTERS[Specs.du_dirs]

if func is test_du_dirs_list:
filters.add_filter(Specs.du_dirs, ["/var/lib/pulp", "/etc/httpd"])
if func is test_du_dirs_list_no_filter:
filters.add_filter(Specs.du_dirs, [])


def test_du_dirs_list():
broker = {}
result = du_dirs_list(broker)
assert len(result) == 2
assert '/var/lib/pulp' in result
assert '/etc/httpd' in result


def test_du_dirs_list_no_filter():
broker = {}
result = du_dirs_list(broker)
assert not result