[augeas-devel] augeas: master - /etc/ethers: new lens and test
David Lutterkort
lutter at fedoraproject.org
Tue Oct 6 20:45:59 UTC 2009
Gitweb: http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=e3fad9d55d1bd626f5342fc68715948c57331d1a
Commit: e3fad9d55d1bd626f5342fc68715948c57331d1a
Parent: f1ef951acce6537efdbc3e41ceee48951981f928
Author: Satoru SATOH <satoru.satoh at gmail.com>
AuthorDate: Tue Oct 6 13:44:11 2009 -0700
Committer: David Lutterkort <lutter at redhat.com>
CommitterDate: Tue Oct 6 13:44:11 2009 -0700
/etc/ethers: new lens and test
The followings adds a new lens for /etc/ethers and associated test.
---
lenses/ethers.aug | 25 +++++++++++++++++
lenses/tests/test_ethers.aug | 61 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 86 insertions(+), 0 deletions(-)
diff --git a/lenses/ethers.aug b/lenses/ethers.aug
new file mode 100644
index 0000000..9cb633b
--- /dev/null
+++ b/lenses/ethers.aug
@@ -0,0 +1,25 @@
+(* Parsing /etc/ethers *)
+
+module Ethers =
+ autoload xfm
+
+ let sep_tab = Util.del_ws_tab
+
+ let eol = del /[ \t]*\n/ "\n"
+ let indent = del /[ \t]*/ ""
+
+ let comment = Util.comment
+ let empty = [ del /[ \t]*#?[ \t]*\n/ "\n" ]
+
+ let word = /[^# \n\t]+/
+ let address =
+ let hex = /[0-9a-fA-F][0-9a-fA-F]?/ in
+ hex . ":" . hex . ":" . hex . ":" . hex . ":" . hex . ":" . hex
+
+ let record = [ seq "ether" . indent .
+ [ label "mac" . store address ] . sep_tab .
+ [ label "ip" . store word ] . eol ]
+
+ let lns = ( empty | comment | record ) *
+
+ let xfm = transform lns (incl "/etc/ethers")
diff --git a/lenses/tests/test_ethers.aug b/lenses/tests/test_ethers.aug
new file mode 100644
index 0000000..7209c1b
--- /dev/null
+++ b/lenses/tests/test_ethers.aug
@@ -0,0 +1,61 @@
+(* Tests for the Ethers module *)
+
+module Test_ethers =
+
+(*
+ let empty_entries = "# see man ethers for syntax\n"
+
+ test Ethers.record get empty_entries =
+ { "#comment" = "see man ethers for syntax" }
+*)
+
+ let three_entries = "54:52:00:01:00:01 192.168.1.1
+# \tcomment\t
+54:52:00:01:00:02 foo.example.com
+00:16:3e:01:fe:03 bar
+"
+
+ test Ethers.lns get three_entries =
+ { "1" { "mac" = "54:52:00:01:00:01" }
+ { "ip" = "192.168.1.1" } }
+ { "#comment" = "comment" }
+ { "2" { "mac" = "54:52:00:01:00:02" }
+ { "ip" = "foo.example.com" } }
+ { "3" { "mac" = "00:16:3e:01:fe:03" }
+ { "ip" = "bar" } }
+
+ (* Deleting the 'ip' node violates the schema *)
+ test Ethers.lns put three_entries after
+ rm "/1/ip"
+ = *
+
+ test Ethers.lns put three_entries after
+ set "/2/ip" "192.168.1.2" ;
+ set "/3/ip" "baz"
+ = "54:52:00:01:00:01 192.168.1.1
+# \tcomment\t
+54:52:00:01:00:02 192.168.1.2
+00:16:3e:01:fe:03 baz
+"
+
+ test Ethers.lns put three_entries after
+ rm "/3"
+ = "54:52:00:01:00:01 192.168.1.1
+# \tcomment\t
+54:52:00:01:00:02 foo.example.com
+"
+
+ (* Make sure blank and indented lines get through *)
+ test Ethers.lns get "54:52:00:01:00:01\tfoo \n \n\n
+54:52:00:01:00:02 bar\n" =
+ { "1" { "mac" = "54:52:00:01:00:01" }
+ { "ip" = "foo" } }
+ {} {} {}
+ { "2" { "mac" = "54:52:00:01:00:02" }
+ { "ip" = "bar" } }
+
+(* Local Variables: *)
+(* mode: caml *)
+(* End: *)
+
+
More information about the augeas-devel
mailing list