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