Skip to content

Commit

Permalink
fix: Update the spec "du_dirs" to filterable (#3384)
Browse files Browse the repository at this point in the history
* fix: Update the spec "du_dirs" to filterable

Signed-off-by: Huanhuan Li <[email protected]>

* Move the "du_dirs_list" datasource to the datasource directory

Signed-off-by: Huanhuan Li <[email protected]>

* Rename to "dir_list"

* Also raise SkipComponent if there are no filters

Signed-off-by: Huanhuan Li <[email protected]>
  • Loading branch information
huali027 authored Apr 18, 2022
1 parent 0af60e5 commit 7d78fc5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 9 deletions.
8 changes: 8 additions & 0 deletions docs/custom_datasources_index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ insights.specs.datasources.cloud_init
:show-inheritance:
:undoc-members:

insights.specs.datasources.dir_list
-----------------------------------

.. automodule:: insights.specs.datasources.dir_list
:members: du_dir_list
:show-inheritance:
:undoc-members:

insights.specs.datasources.ethernet
-------------------------------------

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
18 changes: 18 additions & 0 deletions insights/specs/datasources/dir_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Custom datasources to get a list of directories to check disk size.
"""

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


@datasource(HostContext)
def du_dir_list(broker):
""" Return a list of directories from the spec filter """
filters = list(get_filters(Specs.du_dirs))
if filters:
return filters
raise SkipComponent
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, dir_list, ethernet,
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(dir_list.du_dir_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
32 changes: 32 additions & 0 deletions insights/tests/datasources/test_dir_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest

from insights.specs import Specs
from insights.core import filters
from insights.specs.datasources.dir_list import du_dir_list
from insights.core.dr import SkipComponent


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_dir_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 = {}
with pytest.raises(SkipComponent):
du_dir_list(broker)

0 comments on commit 7d78fc5

Please sign in to comment.