Skip to content

Commit

Permalink
feat: add spec and parser for etc_sysconfig_kernel (#4221)
Browse files Browse the repository at this point in the history
* feat: add spec and parser for etc_sysconfig_kernel

Signed-off-by: Xiaoxue Wang <xiaoxwan@redhat.com>

* fix: test coverage to 100% for insights/specs/default.py

Signed-off-by: Xiaoxue Wang <xiaoxwan@redhat.com>
  • Loading branch information
JoySnow authored Sep 26, 2024
1 parent 50626fa commit 9baadb4
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 0 deletions.
26 changes: 26 additions & 0 deletions insights/parsers/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
KdumpSysconfig - file ``/etc/sysconfig/kdump``
----------------------------------------------
KernelSysconfig - file ``/etc/sysconfig/kernel``
------------------------------------------------
LibvirtGuestsSysconfig - file ``/etc/sysconfig/libvirt-guests``
---------------------------------------------------------------
Expand Down Expand Up @@ -350,6 +353,29 @@ def parse_content(self, content):
setattr(self, key, self.data.get(key, ''))


@parser(Specs.sysconfig_kernel)
class KernelSysconfig(SysconfigOptions):
"""
This parser reads data from the ``/etc/sysconfig/kernel`` file.
Typical content example::
# UPDATEDEFAULT specifies if new-kernel-pkg should make
# new kernels the default
UPDATEDEFAULT=yes
# DEFAULTKERNEL specifies the default kernel package type
DEFAULTKERNEL=kernel
Examples:
>>> kernel_syscfg.get('UPDATEDEFAULT')
'yes'
>>> 'DEFAULTKERNEL' in kernel_syscfg
True
"""
pass


@parser(Specs.sysconfig_libvirt_guests)
class LibvirtGuestsSysconfig(SysconfigOptions):
"""
Expand Down
1 change: 1 addition & 0 deletions insights/specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ class Specs(SpecSet):
sysconfig_httpd = RegistryPoint()
sysconfig_irqbalance = RegistryPoint()
sysconfig_kdump = RegistryPoint()
sysconfig_kernel = RegistryPoint()
sysconfig_libvirt_guests = RegistryPoint()
sysconfig_memcached = RegistryPoint()
sysconfig_mongod = RegistryPoint(multi_output=True)
Expand Down
1 change: 1 addition & 0 deletions insights/specs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ class DefaultSpecs(Specs):
sys_vmbus_device_id = glob_file('/sys/bus/vmbus/devices/*/device_id')
sysconfig_grub = simple_file("/etc/default/grub") # This is the file where the "/etc/sysconfig/grub" point to
sysconfig_kdump = simple_file("etc/sysconfig/kdump")
sysconfig_kernel = simple_file("etc/sysconfig/kernel")
sysconfig_libvirt_guests = simple_file("etc/sysconfig/libvirt-guests")
sysconfig_network = simple_file("etc/sysconfig/network")
sysconfig_nfs = simple_file("/etc/sysconfig/nfs")
Expand Down
11 changes: 11 additions & 0 deletions insights/tests/parsers/test_sysconfig_doc_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from insights.parsers import sysconfig
from insights.parsers.sysconfig import ChronydSysconfig, DockerSysconfig, DockerSysconfigStorage
from insights.parsers.sysconfig import HttpdSysconfig, IrqbalanceSysconfig
from insights.parsers.sysconfig import KernelSysconfig
from insights.parsers.sysconfig import LibvirtGuestsSysconfig, MemcachedSysconfig
from insights.parsers.sysconfig import MongodSysconfig, NtpdSysconfig
from insights.parsers.sysconfig import PrelinkSysconfig, VirtWhoSysconfig
Expand Down Expand Up @@ -236,6 +237,15 @@
#PCSD_BIND_ADDR='::'
""".strip()

KERNEL_SYSCONFIG = """
# UPDATEDEFAULT specifies if new-kernel-pkg should make
# new kernels the default
UPDATEDEFAULT=yes
# DEFAULTKERNEL specifies the default kernel package type
DEFAULTKERNEL=kernel
""".strip()


def test_sysconfig_doc():
env = {
Expand Down Expand Up @@ -266,6 +276,7 @@ def test_sysconfig_doc():
'oracleasm_syscfg': OracleasmSysconfig(context_wrap(ORACLEASM_SYSCONFIG)),
'stonith_syscfg': StonithSysconfig(context_wrap(STONITH_CONFIG)),
'pcsd_syscfg': PcsdSysconfig(context_wrap(PCSD_SYSCONFIG)),
'kernel_syscfg': KernelSysconfig(context_wrap(KERNEL_SYSCONFIG)),
}
failed, total = doctest.testmod(sysconfig, globs=env)
assert failed == 0
22 changes: 22 additions & 0 deletions insights/tests/parsers/test_sysconfig_kernel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from insights.parsers.sysconfig import KernelSysconfig
from insights.tests import context_wrap

SYSCONFIG_KERNEL = """
# UPDATEDEFAULT specifies if new-kernel-pkg should make
# new kernels the default
UPDATEDEFAULT=yes
# DEFAULTKERNEL specifies the default kernel package type
DEFAULTKERNEL=kernel
# MAKEDEBUG specifies if new-kernel-pkg should create non-default
# "debug" entries for new kernels.
MAKEDEBUG=yes
""".strip()


def test_sysconfig_nfs():
result = KernelSysconfig(context_wrap(SYSCONFIG_KERNEL))
assert result['UPDATEDEFAULT'] == 'yes'
assert result.get('DEFAULTKERNEL') == 'kernel'
assert result.get('MAKEDEBUG') == 'yes'
9 changes: 9 additions & 0 deletions insights/tests/test_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
DatasourceProvider, RegistryPoint, SpecSet, command_with_args,
foreach_collect, foreach_execute,
glob_file, simple_command, simple_file, first_file, first_of)
from insights.specs.default import _make_rpm_formatter

here = os.path.abspath(os.path.dirname(__file__))

Expand Down Expand Up @@ -436,3 +437,11 @@ def test_specs_collect(obfuscate):
dr.COMPONENTS = defaultdict(lambda: defaultdict(set))
dr.TYPE_OBSERVERS = defaultdict(set)
dr.ENABLED = defaultdict(lambda: True)


def test_specs_default_module_utils():
rpm_formatter = _make_rpm_formatter([
'"name":"%{NAME}"',
'"version":"%{VERSION}"'
])
assert ',"version":' in rpm_formatter

0 comments on commit 9baadb4

Please sign in to comment.