[augeas-devel] [PATCH] Ntp: enhance lens

David Lutterkort lutter at redhat.com
Mon Feb 16 23:11:16 UTC 2009


These enhancements are needed to make the Ntp.lns process the default
/etc/ntp.conf on Fedora
---
 lenses/ntp.aug            |   21 ++++++++++++++-------
 lenses/tests/test_ntp.aug |   42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 7 deletions(-)

diff --git a/lenses/ntp.aug b/lenses/ntp.aug
index 1a46ac1..7383acc 100644
--- a/lenses/ntp.aug
+++ b/lenses/ntp.aug
@@ -9,14 +9,15 @@ module Ntp =
 
     (* Define useful shortcuts *)
 
-    let eol = Util.del_str "\n"
+    let eol = del /[ \t]*(#.*)?\n/ "\n"
     let sep_spc = Util.del_ws_spc
     let word = /[^,# \n\t]+/
     let num  = /[0-9]+/
 
 
     (* define comments and empty lines *)
-    let comment = [ label "comment" . del /#[ \t]*/ "#" .  store /([^ \t\n][^\n]*)?/ . eol ]
+    let comment = [ label "comment" . del /#[ \t]*/ "#" .
+                    store /([^ \t\n][^\n]*)?/ . del "\n" "\n" ]
     let empty   = [ del /[ \t]*\n/ "\n" ]
 
 
@@ -24,8 +25,9 @@ module Ntp =
     let record (kw:string) (value:lens) = [ key kw . sep_spc . store word . value . eol ]
 
     (* Define a server record *)
-    let version  = [ sep_spc . key "version" . sep_spc . store word ]
-    let server_record   = record "server" version
+    let server_opt = [ sep_spc . key "version" . sep_spc . store word ]
+                   | [ sep_spc . key "dynamic" ]
+    let server_record   = record "server" server_opt?
 
     (* Define simple settings *)
     let simple_setting (kw:string) = [ key kw . sep_spc . store word . eol ]
@@ -35,8 +37,11 @@ module Ntp =
 			| simple_setting "statsdir"
     
     (* Define restrict *)
-    let action    = [ label "action" . sep_spc . store word ]
-    let restrict_record   = record "restrict" action?
+    let restrict_record   =
+      let action    = [ label "action" . sep_spc . store word ] in
+      [ key "restrict" . sep_spc .
+          [ label "ipv6" . Util.del_str "-6" . sep_spc ]? .
+          store (word - "-6") . action* . eol ]
 
     (* Define statistics *)
     let statistics_flag (kw:string) = [ sep_spc . key kw ]
@@ -62,10 +67,12 @@ module Ntp =
 
     let filegen_record = [ label "filegen" . filegen . filegen_opts* . eol ]
 
+    (* Includefile/keys *)
+    let files = [ key /includefile|keys/ . sep_spc . store word . eol ]
 
     (* Define lens *)
 
-    let lns = ( comment | empty | server_record | restrict_record | simple_settings | statistics_record | filegen_record )*
+    let lns = ( comment | empty | server_record | restrict_record | simple_settings | statistics_record | filegen_record | files)*
 
     let filter = (incl "/etc/ntp.conf")
         . Util.stdexcl
diff --git a/lenses/tests/test_ntp.aug b/lenses/tests/test_ntp.aug
index fa72547..b460cdf 100644
--- a/lenses/tests/test_ntp.aug
+++ b/lenses/tests/test_ntp.aug
@@ -69,3 +69,45 @@ filegen clockstats file clockstats type day enable nolink
 	 { "type" = "day" }
          { "enable" = "enable" }
 	 { "link" = "nolink" } }
+
+  (* Some things needed to process the default ntp.conf on Fedora *)
+  test Ntp.lns get
+    "server 66.187.233.4  # added by /sbin/dhclient-script\n" =
+    { "server" = "66.187.233.4" }
+
+  test Ntp.lns get
+    "server 0.fedora.pool.ntp.org dynamic\n" =
+    { "server" = "0.fedora.pool.ntp.org" { "dynamic" } }
+
+  test Ntp.lns get
+    "restrict 127.0.0.1 \n" =
+    { "restrict" = "127.0.0.1" }
+
+  test Ntp.lns get
+    "restrict default kod nomodify notrap nopeer noquery\n" =
+    { "restrict" = "default"
+      { "action" = "kod" }
+      { "action" = "nomodify" }
+      { "action" = "notrap" }
+      { "action" = "nopeer" }
+      { "action" = "noquery" } }
+
+  test Ntp.lns put
+    "restrict default kod nomodify notrap nopeer noquery\n"
+  after
+    insb "ipv6" "restrict/action[1]" =
+    "restrict -6 default kod nomodify notrap nopeer noquery\n"
+
+  test Ntp.lns get
+    "restrict -6 default kod nomodify notrap nopeer noquery\n" =
+    { "restrict" = "default"
+      { "ipv6" }
+      { "action" = "kod" }
+      { "action" = "nomodify" }
+      { "action" = "notrap" }
+      { "action" = "nopeer" }
+      { "action" = "noquery" } }
+
+  test Ntp.lns get
+    "includefile /etc/ntp/crypto/pw\n" =
+    { "includefile" = "/etc/ntp/crypto/pw" }
-- 
1.6.0.6




More information about the augeas-devel mailing list