-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Xinting Li <[email protected]>
- Loading branch information
Xinting Li
committed
Aug 22, 2024
1 parent
19a7722
commit c7c850e
Showing
5 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.. automodule:: insights.parsers.rear_conf | ||
:members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
<class 'insights.parsers.rear_conf.ReaRLocalConf'> | ||
>>> 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |