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