diff --git a/docs/shared_parsers_catalog/rear_conf.rst b/docs/shared_parsers_catalog/rear_conf.rst new file mode 100644 index 0000000000..c6460b23d7 --- /dev/null +++ b/docs/shared_parsers_catalog/rear_conf.rst @@ -0,0 +1,3 @@ +.. automodule:: insights.parsers.rear_conf + :members: + :show-inheritance: diff --git a/insights/parsers/rear_conf.py b/insights/parsers/rear_conf.py new file mode 100644 index 0000000000..0c4061f73d --- /dev/null +++ b/insights/parsers/rear_conf.py @@ -0,0 +1,37 @@ +""" +ReaRLocalConf - File /etc/rear/local.conf +========================================= +""" + +from insights.core import LegacyItemAccess, Parser +from insights.core.exceptions import SkipComponent +from insights.core.plugins import parser +from insights.parsers import get_active_lines +from insights.specs import Specs + + +@parser(Specs.rear_local_conf) +class ReaRLocalConf(Parser, LegacyItemAccess): + """ + Parses content of "/etc/rear/local.conf". + + Typical content of "/etc/rear/local.conf" is:: + + BACKUP_RESTORE_MOVE_AWAY_FILES=( /boot/grub/grubenv /boot/grub2/grubenv ) + + + Examples: + >>> type(local_conf) + + >>> local_conf[0] == 'BACKUP_RESTORE_MOVE_AWAY_FILES=( /boot/grub/grubenv /boot/grub2/grubenv )' + True + """ + + def parse_content(self, content): + _content = get_active_lines(content) + self.data = [] + for line in _content: + self.data.append(line) + + if not self.data: + raise SkipComponent diff --git a/insights/specs/__init__.py b/insights/specs/__init__.py index 1a8027545f..d9acaab888 100644 --- a/insights/specs/__init__.py +++ b/insights/specs/__init__.py @@ -622,6 +622,7 @@ class Specs(SpecSet): readlink_e_etc_mtab = RegistryPoint(no_obfuscate=['hostname', 'ip']) readlink_e_shift_cert_client = RegistryPoint(no_obfuscate=['hostname', 'ip']) readlink_e_shift_cert_server = RegistryPoint(no_obfuscate=['hostname', 'ip']) + rear_local_conf = RegistryPoint() recvq_socket_buffer = RegistryPoint() redhat_release = RegistryPoint(no_obfuscate=['hostname', 'ip']) repquota_agnpuv = RegistryPoint(no_obfuscate=['hostname', 'ip']) diff --git a/insights/specs/default.py b/insights/specs/default.py index 0a7da3a007..c5a9cb30c6 100644 --- a/insights/specs/default.py +++ b/insights/specs/default.py @@ -533,6 +533,7 @@ class DefaultSpecs(Specs): readlink_e_etc_mtab = simple_command("/usr/bin/readlink -e /etc/mtab") readlink_e_shift_cert_client = simple_command("/usr/bin/readlink -e /etc/origin/node/certificates/kubelet-client-current.pem") readlink_e_shift_cert_server = simple_command("/usr/bin/readlink -e /etc/origin/node/certificates/kubelet-server-current.pem") + rear_local_conf = simple_file("/etc/rear/local.conf") redhat_release = simple_file("/etc/redhat-release") repquota_agnpuv = simple_command("/usr/sbin/repquota -agnpuv") resolv_conf = simple_file("/etc/resolv.conf") diff --git a/insights/tests/parsers/test_rear_conf.py b/insights/tests/parsers/test_rear_conf.py new file mode 100644 index 0000000000..27fe01d73b --- /dev/null +++ b/insights/tests/parsers/test_rear_conf.py @@ -0,0 +1,51 @@ +import doctest +import pytest + +from insights.core.exceptions import SkipComponent +from insights.parsers import rear_conf +from insights.parsers.rear_conf import ReaRLocalConf +from insights.tests import context_wrap + +RDMA_CONFIG = """ +# This file etc/rear/local.conf is intended for the user's +# manual configuration of Relax-and-Recover (ReaR). +# For configuration through packages and other automated means +# we recommend a separated file named site.conf next to this file +# and leave local.conf as is (ReaR upstream will never ship a site.conf). +# The default OUTPUT=ISO creates the ReaR rescue medium as ISO image. +# You need to specify your particular backup and restore method for your data +# as the default BACKUP=REQUESTRESTORE does not really do that (see "man rear"). +# Configuration variables are documented in /usr/share/rear/conf/default.conf +# and the examples in /usr/share/rear/conf/examples/ can be used as templates. +# ReaR reads the configuration files via the bash builtin command 'source' +# so bash syntax like VARIABLE="value" (no spaces at '=') is mandatory. +# Because 'source' executes the content as bash scripts you can run commands +# within your configuration files, in particular commands to set different +# configuration values depending on certain conditions as you need like +# CONDITION_COMMAND && VARIABLE="special_value" || VARIABLE="usual_value" +# but that means CONDITION_COMMAND gets always executed when 'rear' is run +# so ensure nothing can go wrong if you run commands in configuration files. +BACKUP_RESTORE_MOVE_AWAY_FILES=( /boot/grub/grubenv /boot/grub2/grubenv ) +""".strip() + +REAR_CONF_EMPTY = """ +""".strip() + + +def test_rdma_config(): + local_conf = ReaRLocalConf(context_wrap(RDMA_CONFIG)) + assert len(local_conf.data) == 1 + assert local_conf.data[0] == "BACKUP_RESTORE_MOVE_AWAY_FILES=( /boot/grub/grubenv /boot/grub2/grubenv )" + + +def test_rdma_config_empty(): + with pytest.raises(SkipComponent): + ReaRLocalConf(context_wrap(REAR_CONF_EMPTY)) + + +def test_rdma_config_doc(): + env = { + 'local_conf': ReaRLocalConf(context_wrap(RDMA_CONFIG)), + } + failed, total = doctest.testmod(rear_conf, globs=env) + assert failed == 0