[augeas-devel] augeas: master - Ntp: enhance lens
David Lutterkort
lutter at fedoraproject.org
Tue Feb 17 16:42:57 UTC 2009
Gitweb: http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=ef01e1507886f5c57e104b3a13851dc6eb762666
Commit: ef01e1507886f5c57e104b3a13851dc6eb762666
Parent: 07ffaf070a8e2be452238b80b4431fa5fc88994c
Author: David Lutterkort <lutter at redhat.com>
AuthorDate: Mon Feb 16 15:07:06 2009 -0800
Committer: David Lutterkort <lutter at redhat.com>
CommitterDate: Tue Feb 17 08:41:32 2009 -0800
Ntp: enhance lens
These enhancements are needed to make the Ntp.lns process the default
/etc/ntp.conf on Fedora
---
lenses/ntp.aug | 22 ++++++++++++------
lenses/tests/test_ntp.aug | 53 ++++++++++++++++++++++++++++++++++++++++----
2 files changed, 63 insertions(+), 12 deletions(-)
diff --git a/lenses/ntp.aug b/lenses/ntp.aug
index 1a46ac1..86bd69d 100644
--- a/lenses/ntp.aug
+++ b/lenses/ntp.aug
@@ -9,14 +9,16 @@ module Ntp =
(* Define useful shortcuts *)
- let eol = Util.del_str "\n"
+ let eol = del /[ \t]*/ "" . [ label "#comment" . store /#.*/]?
+ . Util.del_str "\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 +26,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 +38,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 +68,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..862491d 100644
--- a/lenses/tests/test_ntp.aug
+++ b/lenses/tests/test_ntp.aug
@@ -27,9 +27,9 @@ filegen clockstats file clockstats type day enable nolink
"
test Ntp.lns get conf =
- { "comment" = "" }
- { "comment" = "Fichier genere par puppet" }
- { "comment" = "Environnement: development" }
+ { "#comment" = "" }
+ { "#comment" = "Fichier genere par puppet" }
+ { "#comment" = "Environnement: development" }
{}
{ "server" = "dns01.echo-net.net"
{ "version" = "3" } }
@@ -41,11 +41,11 @@ filegen clockstats file clockstats type day enable nolink
{ "restrict" = "default"
{ "action" = "ignore" } }
{}
- { "comment" = "server dns01.echo-net.net" }
+ { "#comment" = "server dns01.echo-net.net" }
{ "restrict" = "192.168.0.150"
{ "action" = "nomodify" } }
{}
- { "comment" = "allow everything from localhost" }
+ { "#comment" = "allow everything from localhost" }
{ "restrict" = "127.0.0.1" }
{}
{ "logfile" = "/var/log/ntpd" }
@@ -69,3 +69,46 @@ 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"
+ { "#comment" = "# added by /sbin/dhclient-script" } }
+
+ 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" }
More information about the augeas-devel
mailing list