Blame SOURCES/0019-Added-chrony-lense.patch

ab36df
From f6d87cb468845c498e42e7285099d5b295ee936b Mon Sep 17 00:00:00 2001
ab36df
From: Pat Riehecky <riehecky@fnal.gov>
ab36df
Date: Wed, 12 Feb 2014 11:43:16 -0600
ab36df
Subject: [PATCH] Added chrony lense
ab36df
ab36df
(cherry picked from commit 319e30fcbea54aadc97430809cea6fb7b398b4b6)
ab36df
---
ab36df
 doc/naturaldocs/conf/lenses/Menu.txt |   2 +
ab36df
 lenses/chrony.aug                    | 266 +++++++++++++++++++++++++++++++++++
ab36df
 lenses/tests/test_chrony.aug         | 143 +++++++++++++++++++
ab36df
 tests/Makefile.am                    |   1 +
ab36df
 4 files changed, 412 insertions(+)
ab36df
 create mode 100644 lenses/chrony.aug
ab36df
 create mode 100644 lenses/tests/test_chrony.aug
ab36df
ab36df
diff --git a/doc/naturaldocs/conf/lenses/Menu.txt b/doc/naturaldocs/conf/lenses/Menu.txt
ab36df
index a6fa0f0..34e0bf6 100644
ab36df
--- a/doc/naturaldocs/conf/lenses/Menu.txt
ab36df
+++ b/doc/naturaldocs/conf/lenses/Menu.txt
ab36df
@@ -74,6 +74,7 @@ Group: Specific Modules  {
ab36df
    File: Cgconfig  (no auto-title, cgconfig.aug)
ab36df
    File: Cgrules  (no auto-title, cgrules.aug)
ab36df
    File: Channels  (channels.aug)
ab36df
+   File: Chrony  (chrony.aug)
ab36df
    File: Collectd  (collectd.aug)
ab36df
    File: Cron  (cron.aug)
ab36df
    File: Crypttab  (crypttab.aug)
ab36df
@@ -191,6 +192,7 @@ Group: Tests and Examples  {
ab36df
    File: Test_Build  (tests/test_build.aug)
ab36df
    File: Test_Carbon  (tests/test_carbon.aug)
ab36df
    File: Test_Channels  (tests/test_channels.aug)
ab36df
+   File: Test_Chrony  (tests/test_chrony.aug)
ab36df
    File: Test_Collectd  (tests/test_collectd.aug)
ab36df
    File: Test_Cups  (tests/test_cups.aug)
ab36df
    File: Test_Dovecot  (tests/test_dovecot.aug)
ab36df
diff --git a/lenses/chrony.aug b/lenses/chrony.aug
ab36df
new file mode 100644
ab36df
index 0000000..ede2c94
ab36df
--- /dev/null
ab36df
+++ b/lenses/chrony.aug
ab36df
@@ -0,0 +1,266 @@
ab36df
+(*
ab36df
+Module: Chrony
ab36df
+  Parses the chrony config file
ab36df
+
ab36df
+Author: Pat Riehecky <riehecky@fnal.gov>
ab36df
+
ab36df
+About: Reference
ab36df
+  This lens tries to keep as close as possible to chrony config syntax
ab36df
+
ab36df
+  See http://chrony.tuxfamily.org/manual.html#Configuration-file
ab36df
+
ab36df
+About: Limitations
ab36df
+  Does not (currently) support
ab36df
+    - include
ab36df
+    - manual
ab36df
+    - refclock
ab36df
+    - tempcomp
ab36df
+
ab36df
+About: License
ab36df
+  This file is licenced under the LGPL v2+, like the rest of Augeas.
ab36df
+
ab36df
+About: Lens Usage
ab36df
+  To be documented
ab36df
+
ab36df
+About: Configuration files
ab36df
+  This lens applies to /etc/chrony.conf
ab36df
+
ab36df
+  See <filter>.
ab36df
+*)
ab36df
+
ab36df
+module Chrony =
ab36df
+  autoload xfm
ab36df
+
ab36df
+(************************************************************************
ab36df
+ * Group: Import provided expressions
ab36df
+ ************************************************************************)
ab36df
+    (* View: empty *)
ab36df
+    let empty   = Util.empty
ab36df
+
ab36df
+    (* View: eol *)
ab36df
+    let eol     = Util.eol
ab36df
+
ab36df
+    (* View: space *)
ab36df
+    let space   = Sep.space
ab36df
+
ab36df
+    (* Variable: email_addr *)
ab36df
+    let email_addr = Rx.email_addr
ab36df
+
ab36df
+    (* Variable: word *)
ab36df
+    let word       = Rx.word
ab36df
+
ab36df
+    (* Variable: integer *)
ab36df
+    let integer    = Rx.integer
ab36df
+
ab36df
+    (* Variable: decimal *)
ab36df
+    let decimal    = Rx.decimal
ab36df
+
ab36df
+    (* Variable: ip *)
ab36df
+    let ip         = Rx.ip
ab36df
+
ab36df
+(************************************************************************
ab36df
+ * Group: Create required expressions
ab36df
+ ************************************************************************)
ab36df
+    (* Variable: number *)
ab36df
+    let number = integer | decimal
ab36df
+
ab36df
+    (* Variable: address_re *)
ab36df
+    let address_re = Rx.ip | Rx.hostname
ab36df
+
ab36df
+    (*
ab36df
+       View: comment
ab36df
+            from 4.2.1 of the upstream doc
ab36df
+            Chrony comments start with: ! ; # or % and must be on their own line
ab36df
+    *)
ab36df
+    let comment = Util.comment_generic /[ \t]*[!;#%][ \t]*/ "# "
ab36df
+
ab36df
+    (* Variable: no_space
ab36df
+         No spaces or comment characters
ab36df
+    *)
ab36df
+    let no_space   = /[^ \t\r\n!;#%]+/
ab36df
+
ab36df
+    (* Variable: cmd_options
ab36df
+         Server/Peer options with values
ab36df
+    *)
ab36df
+    let cmd_options = "key"
ab36df
+                    | /maxdelay((dev)?ratio)?/
ab36df
+                    | /(min|max)poll/
ab36df
+                    | "polltarget"
ab36df
+                    | "port"
ab36df
+                    | "presend"
ab36df
+
ab36df
+    (* Variable: cmd_flags
ab36df
+         Server/Peer options without values
ab36df
+    *)
ab36df
+    let cmd_flags = "auto_offline"|"iburst"|"noselect"|"offline"|"prefer"
ab36df
+
ab36df
+    (* Variable: server_peer
ab36df
+         Server/Peer key names
ab36df
+    *)
ab36df
+    let server_peer = "server"|"peer"
ab36df
+
ab36df
+    (* Variable: flags
ab36df
+         Options without values
ab36df
+    *)
ab36df
+    let flags = "dumponexit"
ab36df
+              | "generatecommandkey"
ab36df
+              | "lock_all"
ab36df
+              | "noclientlog"
ab36df
+              | "rtconutc"
ab36df
+              | "rtcsync"
ab36df
+
ab36df
+    (* Variable: log_flags
ab36df
+        log has a specific options list
ab36df
+    *)
ab36df
+    let log_flags = /measurments|statistics|tracking|rtc|refclocks|tempcomp/
ab36df
+
ab36df
+    (* Variable: simple_keys
ab36df
+         Options with single values
ab36df
+    *)
ab36df
+    let simple_keys = "acquisitionport" | "allow" | "bindaddress"
ab36df
+                    | "bindcmdaddress" | "cmdallow" | "cmddeny"
ab36df
+                    | "combinelimit" | "commandkey" | "cmdport"
ab36df
+                    | "corrtimeratio" | "deny" | "driftfile"
ab36df
+                    | "dumpdir" | "keyfile" | "leapsectz" | "linux_hz"
ab36df
+                    | "linux_freq_scale" | "logbanner" | "logchange"
ab36df
+                    | "logdir" | "maxclockerror" | "maxsamples"
ab36df
+                    | "maxupdateskew" | "minsamples" | "clientloglimit"
ab36df
+                    | "pidfile" | "port" | "reselectdist" | "rtcdevice"
ab36df
+                    | "rtcfile" | "sched_priority" | "stratumweight" | "user"
ab36df
+
ab36df
+(************************************************************************
ab36df
+ * Group: Make some sub-lenses for use in later lenses
ab36df
+ ************************************************************************)
ab36df
+    (* View: host_flags *)
ab36df
+    let host_flags = [ space . key cmd_flags ]
ab36df
+    (* View: host_options *)
ab36df
+    let host_options = [ space . key cmd_options . space . store integer ]
ab36df
+    (* View: log_flag_list *)
ab36df
+    let log_flag_list = [ space . key log_flags ]
ab36df
+    (* View: store_address *)
ab36df
+    let store_address = [ label "address" . store address_re ]
ab36df
+
ab36df
+(************************************************************************
ab36df
+ * Group: Lenses for parsing out sections
ab36df
+ ************************************************************************)
ab36df
+    (* View: all_flags
ab36df
+        match all flags using Build.flag_line
ab36df
+    *)
ab36df
+    let all_flags = Build.flag_line flags
ab36df
+
ab36df
+    (* View: kv
ab36df
+        options with only one arg can be directly mapped to key = value
ab36df
+    *)
ab36df
+    let kv = Build.key_value_line_comment simple_keys space (store no_space) comment
ab36df
+
ab36df
+    (* Property: Options with multiple values
ab36df
+    
ab36df
+      Each of these gets their own parsing block
ab36df
+      - server|peer <address> <options>
ab36df
+      - log <options>
ab36df
+      - broadcast <interval> <address> <optional port>
ab36df
+      - fallbackdrift <min> <max>
ab36df
+      - initstepslew <threshold> <addr> <optional extra addrs>
ab36df
+      - local stratum <int>
ab36df
+      - mailonchange <emailaddress> <threshold>
ab36df
+      - makestep <threshold> <limit>
ab36df
+      - maxchange <threshold> <delay> <limit>
ab36df
+    *)
ab36df
+
ab36df
+    (* View: host_list
ab36df
+        Find all ntp servers/peers and their flags/options
ab36df
+    *)
ab36df
+    let host_list = [ Util.indent . key server_peer
ab36df
+                         . space . store address_re
ab36df
+                         . ( host_flags | host_options )*
ab36df
+                         . eol ]
ab36df
+
ab36df
+    (* View: log_list
ab36df
+        log has a specific options list
ab36df
+    *)
ab36df
+    let log_list = [ Util.indent . key "log" . log_flag_list+ . eol ]
ab36df
+
ab36df
+    (* View: bcast
ab36df
+         broadcast has specific syntax
ab36df
+    *)
ab36df
+    let bcast = [ Util.indent . key "broadcast"
ab36df
+                      . space . [ label "interval" . store integer ]
ab36df
+                      . space . store_address
ab36df
+                      . ( space . [ label "port" . store integer] | eol) ]
ab36df
+
ab36df
+    (* View: fdrift
ab36df
+         fallbackdrift has specific syntax
ab36df
+    *)
ab36df
+    let fdrift = [ Util.indent . key "fallbackdrift"
ab36df
+                      . space . [ label "min" . store integer ]
ab36df
+                      . space . [ label "max" . store integer ]
ab36df
+                      . eol ]
ab36df
+
ab36df
+    (* View: istepslew
ab36df
+         initstepslew has specific syntax
ab36df
+    *)
ab36df
+    let istepslew = [ Util.indent . key "initstepslew" 
ab36df
+                         . space . [ label "threshold" . store number ]
ab36df
+                         . ( space . store_address )+
ab36df
+                         . eol ]
ab36df
+
ab36df
+    (* View: local
ab36df
+         local has specific syntax
ab36df
+    *)
ab36df
+    let local = [ Util.indent . key "local" . space
ab36df
+                     . [ key "stratum" . space . store integer ]
ab36df
+                     . eol ]
ab36df
+
ab36df
+    (* View: email
ab36df
+         mailonchange has specific syntax
ab36df
+    *)
ab36df
+    let email = [ Util.indent . key "mailonchange" . space
ab36df
+                     . [ label "emailaddress" . store email_addr ]
ab36df
+                     . space
ab36df
+                     . [ label "threshold" . store number ]
ab36df
+                     . eol ]
ab36df
+
ab36df
+    (* View: makestep
ab36df
+         makestep has specific syntax
ab36df
+    *)
ab36df
+    let makestep = [ Util.indent . key "makestep"
ab36df
+                      . space
ab36df
+                      . [ label "threshold" . store number ]
ab36df
+                      . space
ab36df
+                      . [ label "limit" . store integer ]
ab36df
+                      . eol ]
ab36df
+
ab36df
+    (* View: maxchange
ab36df
+         maxchange has specific syntax
ab36df
+    *)
ab36df
+    let maxchange = [ Util.indent . key "maxchange"
ab36df
+                      . space
ab36df
+                      . [ label "threshold" . store number ]
ab36df
+                      . space
ab36df
+                      . [ label "delay" . store integer ]
ab36df
+                      . space
ab36df
+                      . [ label "limit" . store integer ]
ab36df
+                      . eol ]
ab36df
+
ab36df
+(************************************************************************
ab36df
+ * Group: Final lense summary
ab36df
+ ************************************************************************)
ab36df
+(* View: settings
ab36df
+ *   All supported chrony settings
ab36df
+ *)
ab36df
+let settings = host_list | log_list | bcast | fdrift | istepslew
ab36df
+             | local | email | makestep | maxchange | kv | all_flags
ab36df
+
ab36df
+(*
ab36df
+ * View: lns
ab36df
+ *   The crony lens
ab36df
+ *)
ab36df
+let lns = ( empty | comment | settings )*
ab36df
+
ab36df
+(* View: filter
ab36df
+ *   The files parsed by default
ab36df
+ *)
ab36df
+let filter = incl "/etc/chrony.conf"
ab36df
+
ab36df
+let xfm = transform lns filter
ab36df
+
ab36df
diff --git a/lenses/tests/test_chrony.aug b/lenses/tests/test_chrony.aug
ab36df
new file mode 100644
ab36df
index 0000000..4917358
ab36df
--- /dev/null
ab36df
+++ b/lenses/tests/test_chrony.aug
ab36df
@@ -0,0 +1,143 @@
ab36df
+(*
ab36df
+Module: Test_Chrony
ab36df
+  Provides unit tests and examples for the <Chrony> lens.
ab36df
+*)
ab36df
+
ab36df
+module Test_Chrony =
ab36df
+
ab36df
+  let exampleconf = "# Comment
ab36df
+#Comment
ab36df
+! Comment
ab36df
+!Comment
ab36df
+; Comment
ab36df
+;Comment
ab36df
+% Comment
ab36df
+%Comment
ab36df
+
ab36df
+server ntp1.example.com
ab36df
+server ntp2.example.com iburst
ab36df
+server ntp3.example.com presend 2
ab36df
+server ntp4.example.com offline polltarget 4
ab36df
+server ntp5.example.com maxdelay 2 offline
ab36df
+server ntp6.example.com maxdelay 2 iburst presend 2
ab36df
+server ntp7.example.com iburst presend 2 offline
ab36df
+peer ntpc1.example.com
ab36df
+stratumweight 0
ab36df
+driftfile /var/lib/chrony/drift
ab36df
+rtcsync
ab36df
+makestep 10 3
ab36df
+bindcmdaddress 127.0.0.1
ab36df
+bindcmdaddress ::1
ab36df
+local stratum 10
ab36df
+keyfile /etc/chrony.keys
ab36df
+commandkey 1
ab36df
+generatecommandkey
ab36df
+noclientlog
ab36df
+logchange 0.5
ab36df
+logdir /var/log/chrony
ab36df
+log rtc
ab36df
+leapsectz right/UTC
ab36df
+broadcast 10 192.168.1.255
ab36df
+broadcast 10 192.168.100.255 123
ab36df
+fallbackdrift 16 19
ab36df
+mailonchange root@localhost 0.5
ab36df
+maxchange 1000 1 2
ab36df
+initstepslew 30 foo.bar.com
ab36df
+initstepslew 30 foo.bar.com baz.quz.com
ab36df
+"
ab36df
+
ab36df
+  test Chrony.lns get exampleconf =
ab36df
+    { "#comment" = "Comment" }
ab36df
+  { "#comment" = "Comment" }
ab36df
+  { "#comment" = "Comment" }
ab36df
+  { "#comment" = "Comment" }
ab36df
+  { "#comment" = "Comment" }
ab36df
+  { "#comment" = "Comment" }
ab36df
+  { "#comment" = "Comment" }
ab36df
+  { "#comment" = "Comment" }
ab36df
+  {  }
ab36df
+  { "server" = "ntp1.example.com" }
ab36df
+  { "server" = "ntp2.example.com"
ab36df
+    { "iburst" }
ab36df
+  }
ab36df
+  { "server" = "ntp3.example.com"
ab36df
+    { "presend" = "2" }
ab36df
+  }
ab36df
+  { "server" = "ntp4.example.com"
ab36df
+    { "offline" }
ab36df
+    { "polltarget" = "4" }
ab36df
+  }
ab36df
+  { "server" = "ntp5.example.com"
ab36df
+    { "maxdelay" = "2" }
ab36df
+    { "offline" }
ab36df
+  }
ab36df
+  { "server" = "ntp6.example.com"
ab36df
+    { "maxdelay" = "2" }
ab36df
+    { "iburst" }
ab36df
+    { "presend" = "2" }
ab36df
+  }
ab36df
+  { "server" = "ntp7.example.com"
ab36df
+    { "iburst" }
ab36df
+    { "presend" = "2" }
ab36df
+    { "offline" }
ab36df
+  }
ab36df
+  { "peer" = "ntpc1.example.com" }
ab36df
+  { "stratumweight" = "0" }
ab36df
+  { "driftfile" = "/var/lib/chrony/drift" }
ab36df
+  { "rtcsync" }
ab36df
+  { "makestep"
ab36df
+    { "threshold" = "10" }
ab36df
+    { "limit" = "3" }
ab36df
+  }
ab36df
+  { "bindcmdaddress" = "127.0.0.1" }
ab36df
+  { "bindcmdaddress" = "::1" }
ab36df
+  { "local"
ab36df
+    { "stratum" = "10" }
ab36df
+  }
ab36df
+  { "keyfile" = "/etc/chrony.keys" }
ab36df
+  { "commandkey" = "1" }
ab36df
+  { "generatecommandkey" }
ab36df
+  { "noclientlog" }
ab36df
+  { "logchange" = "0.5" }
ab36df
+  { "logdir" = "/var/log/chrony" }
ab36df
+  { "log"
ab36df
+    { "rtc" }
ab36df
+  }
ab36df
+  { "leapsectz" = "right/UTC" }
ab36df
+  { "broadcast"
ab36df
+    { "interval" = "10" }
ab36df
+    { "address" = "192.168.1.255" }
ab36df
+  }
ab36df
+  { "broadcast"
ab36df
+    { "interval" = "10" }
ab36df
+    { "address" = "192.168.100.255" }
ab36df
+    { "port" = "123" }
ab36df
+  }
ab36df
+  {  }
ab36df
+  { "fallbackdrift"
ab36df
+    { "min" = "16" }
ab36df
+    { "max" = "19" }
ab36df
+  }
ab36df
+  { "mailonchange"
ab36df
+    { "emailaddress" = "root@localhost" }
ab36df
+    { "threshold" = "0.5" }
ab36df
+  }
ab36df
+  { "maxchange"
ab36df
+    { "threshold" = "1000" }
ab36df
+    { "delay" = "1" }
ab36df
+    { "limit" = "2" }
ab36df
+  }
ab36df
+  { "initstepslew"
ab36df
+    { "threshold" = "30" }
ab36df
+    { "address" = "foo.bar.com" }
ab36df
+  }
ab36df
+  { "initstepslew"
ab36df
+    { "threshold" = "30" }
ab36df
+    { "address" = "foo.bar.com" }
ab36df
+    { "address" = "baz.quz.com" }
ab36df
+  }
ab36df
+
ab36df
+
ab36df
+(* Local Variables: *)
ab36df
+(* mode: caml       *)
ab36df
+(* End:             *)
ab36df
diff --git a/tests/Makefile.am b/tests/Makefile.am
ab36df
index 180a19d..1b79629 100644
ab36df
--- a/tests/Makefile.am
ab36df
+++ b/tests/Makefile.am
ab36df
@@ -41,6 +41,7 @@ lens_tests =			\
ab36df
   lens-cgconfig.sh		\
ab36df
   lens-cgrules.sh  		\
ab36df
   lens-channels.sh  		\
ab36df
+  lens-chrony.sh  		\
ab36df
   lens-cobblersettings.sh	\
ab36df
   lens-cobblermodules.sh	\
ab36df
   lens-collectd.sh	\