From ba333a3205324a7b0489d93b67317c72b76fe8bf Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Wed, 12 Dec 2018 13:54:06 +0100 Subject: [PATCH] New lens: Anaconda (#597) Introduce a new lens to parse the INI-like `/etc/sysconfig/anaconda` instead of using `Shellvars`. --- lenses/anaconda.aug | 30 +++++++++++ lenses/shellvars.aug | 1 + lenses/tests/test_anaconda.aug | 89 +++++++++++++++++++++++++++++++ tests/Makefile.am | 1 + tests/root/etc/sysconfig/anaconda | 5 ++ 5 files changed, 126 insertions(+) create mode 100644 lenses/anaconda.aug create mode 100644 lenses/tests/test_anaconda.aug create mode 100644 tests/root/etc/sysconfig/anaconda diff --git a/lenses/anaconda.aug b/lenses/anaconda.aug new file mode 100644 index 00000000..8f618db2 --- /dev/null +++ b/lenses/anaconda.aug @@ -0,0 +1,30 @@ +(* +Module: Anaconda + Parses Anaconda's user interaction configuration files. + +Author: Pino Toscano + +About: Reference + https://anaconda-installer.readthedocs.io/en/latest/user-interaction-config-file-spec.html + +About: Configuration file + This lens applies to /etc/sysconfig/anaconda. + +About: License + This file is licensed under the LGPL v2+, like the rest of Augeas. +*) +module Anaconda = +autoload xfm + +let comment = IniFile.comment "#" "#" +let sep = IniFile.sep "=" "=" + +let entry = IniFile.entry IniFile.entry_re sep comment +let title = IniFile.title IniFile.record_re +let record = IniFile.record title entry + +let lns = IniFile.lns record comment + +let filter = incl "/etc/sysconfig/anaconda" + +let xfm = transform lns filter diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug index 25bb82b9..03ab921b 100644 --- a/lenses/shellvars.aug +++ b/lenses/shellvars.aug @@ -198,6 +198,7 @@ module Shellvars = let filter_sysconfig = sc_incl "*" . + sc_excl "anaconda" . sc_excl "bootloader" . sc_excl "hw-uuid" . sc_excl "hwconf" . diff --git a/lenses/tests/test_anaconda.aug b/lenses/tests/test_anaconda.aug new file mode 100644 index 00000000..50b0ac22 --- /dev/null +++ b/lenses/tests/test_anaconda.aug @@ -0,0 +1,89 @@ +(* +Module: Test_Anaconda + Provides unit tests and examples for the lens. + + - 'exampleN' snippets are taken from the documentation: + https://anaconda-installer.readthedocs.io/en/latest/user-interaction-config-file-spec.html + - 'installedN' snippets are taken from the resulting files after + a successful installation +*) + +module Test_Anaconda = + +let example1 = "# comment example - before the section headers + +[section_1] +# comment example - inside section 1 +key_a_in_section1=some_value +key_b_in_section1=some_value + +[section_2] +# comment example - inside section 2 +key_a_in_section2=some_value +" + +test Anaconda.lns get example1 = + { "#comment" = "comment example - before the section headers" } + { } + { "section_1" + { "#comment" = "comment example - inside section 1" } + { "key_a_in_section1" = "some_value" } + { "key_b_in_section1" = "some_value" } + { } + } + { "section_2" + { "#comment" = "comment example - inside section 2" } + { "key_a_in_section2" = "some_value" } + } + +let example2 = "# this is the user interaction config file + +[General] +post_install_tools_disabled=0 + +[DatetimeSpoke] +# the date and time spoke has been visited +visited=1 +changed_timezone=1 +changed_ntp=0 +changed_timedate=1 + +[KeyboardSpoke] +# the keyboard spoke has not been visited +visited=0 +" + +test Anaconda.lns get example2 = + { "#comment" = "this is the user interaction config file" } + { } + { "General" + { "post_install_tools_disabled" = "0" } + { } + } + { "DatetimeSpoke" + { "#comment" = "the date and time spoke has been visited" } + { "visited" = "1" } + { "changed_timezone" = "1" } + { "changed_ntp" = "0" } + { "changed_timedate" = "1" } + { } + } + { "KeyboardSpoke" + { "#comment" = "the keyboard spoke has not been visited" } + { "visited" = "0" } + } + +let installed1 = "# This file has been generated by the Anaconda Installer 21.48.22.134-1 + +[ProgressSpoke] +visited = 1 + +" + +test Anaconda.lns get installed1 = + { "#comment" = "This file has been generated by the Anaconda Installer 21.48.22.134-1" } + { } + { "ProgressSpoke" + { "visited" = "1" } + { } + } diff --git a/tests/Makefile.am b/tests/Makefile.am index 4d2b2605..08d5dc59 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -22,6 +22,7 @@ lens_tests = \ lens-activemq_xml.sh \ lens-afs_cellalias.sh \ lens-aliases.sh \ + lens-anaconda.sh \ lens-anacron.sh \ lens-approx.sh \ lens-apt_update_manager.sh \ diff --git a/tests/root/etc/sysconfig/anaconda b/tests/root/etc/sysconfig/anaconda new file mode 100644 index 00000000..73318cf6 --- /dev/null +++ b/tests/root/etc/sysconfig/anaconda @@ -0,0 +1,5 @@ +# This file has been generated by the Anaconda Installer 21.48.22.134-1 + +[ProgressSpoke] +visited = 1 + -- 2.17.2