Skip to content

Commit

Permalink
FEAT: new custom filter 'fstab_mounted.dirs' to ls_lan spec (#4255)
Browse files Browse the repository at this point in the history
Signed-off-by: Xinting Li <[email protected]>
  • Loading branch information
TZ3070 authored Nov 7, 2024
1 parent 5c68edd commit 2c292ce
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
4 changes: 4 additions & 0 deletions insights/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@
enabled: true
- name: insights.components.selinux.SELinuxEnabled
enabled: true
# needed for the 'fstab_mounted.dirs' to the 'ls_lan' spec
- name: insights.parsers.fstab.FSTab
enabled: true
""".strip()

EXCEPTIONS_TO_REPORT = set([
Expand Down
27 changes: 17 additions & 10 deletions insights/specs/datasources/ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from insights.core.exceptions import SkipComponent
from insights.core.filters import get_filters
from insights.core.plugins import datasource
from insights.parsers.fstab import FSTab
from insights.specs import Specs
import os


def _list_items(spec):
Expand Down Expand Up @@ -36,50 +38,55 @@ def _list_items(spec):
==============================================================
"""
filters.append('_non_existing_')
return ' '.join(filters)
return filters
raise SkipComponent


@datasource(HostContext)
def list_with_la(broker):
return _list_items(Specs.ls_la_dirs)
return ' '.join(_list_items(Specs.ls_la_dirs))


@datasource(HostContext)
def list_with_la_filtered(broker):
return _list_items(Specs.ls_la_filtered_dirs)
return ' '.join(_list_items(Specs.ls_la_filtered_dirs))


@datasource(HostContext)
def list_with_lan(broker):
return _list_items(Specs.ls_lan_dirs)
filters = set(_list_items(Specs.ls_lan_dirs))
if 'fstab_mounted.dirs' in filters and FSTab in broker:
for mntp in broker[FSTab].mounted_on.keys():
mnt_point = os.path.dirname(mntp)
filters.add(mnt_point) if mnt_point else None
return ' '.join(sorted(filters))


@datasource(HostContext)
def list_with_lan_filtered(broker):
return _list_items(Specs.ls_lan_filtered_dirs)
return ' '.join(_list_items(Specs.ls_lan_filtered_dirs))


@datasource(HostContext)
def list_with_lanL(broker):
return _list_items(Specs.ls_lanL_dirs)
return ' '.join(_list_items(Specs.ls_lanL_dirs))


@datasource(HostContext)
def list_with_lanR(broker):
return _list_items(Specs.ls_lanR_dirs)
return ' '.join(_list_items(Specs.ls_lanR_dirs))


@datasource(HostContext)
def list_with_lanRL(broker):
return _list_items(Specs.ls_lanRL_dirs)
return ' '.join(_list_items(Specs.ls_lanRL_dirs))


@datasource(HostContext)
def list_with_laRZ(broker):
return _list_items(Specs.ls_laRZ_dirs)
return ' '.join(_list_items(Specs.ls_laRZ_dirs))


@datasource(HostContext)
def list_with_laZ(broker):
return _list_items(Specs.ls_laZ_dirs)
return ' '.join(_list_items(Specs.ls_laZ_dirs))
23 changes: 23 additions & 0 deletions insights/tests/datasources/test_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@

from insights.core import filters
from insights.core.exceptions import SkipComponent
from insights.parsers.fstab import FSTab
from insights.specs import Specs
from insights.specs.datasources.ls import (
list_with_la, list_with_la_filtered,
list_with_lan, list_with_lan_filtered,
list_with_lanL, list_with_lanR, list_with_lanRL,
list_with_laRZ, list_with_laZ)
from insights.tests import context_wrap


FSTAB_CONTEXT = """
/dev/mapper/rhel_rhel8-root / xfs defaults 0 0
/dev/vda1 /boot xfs defaults 0 0
/dev/mapper/rhel_rhel8-swap none swap defaults 0 0
/dev/mapper/rhel_rhel7-hana1 /hana/data/rhel7-hana1 xfs defaults 0 0
/dev/mapper/rhel_rhel7-hana2 /hana/data/rhel7-hana2 xfs defaults 0 0
/dev/mapper/rhel_rhel7-hana3 /hana/data/rhel7-hana3 xfs defaults 0 0
""".strip()


def setup_function(func):
Expand All @@ -33,6 +45,8 @@ def setup_function(func):
filters.add_filter(Specs.ls_laRZ_dirs, ['/boot'])
if func is test_lanZ:
filters.add_filter(Specs.ls_laZ_dirs, ["/", '/mnt'])
if func is test_lan_with_fstab_mounted_filter:
filters.add_filter(Specs.ls_lan_dirs, ["/", '/boot', 'fstab_mounted.dirs'])


def teardown_function(func):
Expand Down Expand Up @@ -88,3 +102,12 @@ def test_lanRZ():
def test_lanZ():
ret = list_with_laZ({})
assert ret == '/ /mnt'


def test_lan_with_fstab_mounted_filter():
fstab = FSTab(context_wrap(FSTAB_CONTEXT))
broker = {
FSTab: fstab
}
ret = list_with_lan(broker)
assert ret == '/ /boot /hana/data fstab_mounted.dirs'

0 comments on commit 2c292ce

Please sign in to comment.