Permalink
Browse files

haproxy lens fixes

    * normalize option / no option handling
    * add unit test for haproxy lens
  • Loading branch information...
Bryon Roche
Bryon Roche committed Dec 16, 2011
1 parent f1ff534 commit 0a453cf9fbd6ef9f4b49f613a4887701610b0ed3
Showing with 184 additions and 2 deletions.
  1. +3 −2 files/haproxy.aug
  2. +181 −0 files/test_haproxy.aug
View
@@ -3,6 +3,7 @@
Haproxy module for Augeas
Author: Francois Deppierraz <francois.deppierraz@camptocamp.com>
+ Fix and Tests: Bryon Roche <bryon@gogrid.com>
About: License
This file is licensed under the LGPL
@@ -34,8 +35,8 @@ let words = /[^# \t\n]+([ \t]+[^# \t\n]+)*/
*)
-let option_re = ( /option[ \t]+/ . word ) |
- ( word - /option/ )
+let option_re = ( /(no option|option)[ \t]+/ . word ) |
+ ( word - /option|no/ )
let option = key option_re . ( spc . store words ) ?
View
@@ -0,0 +1,181 @@
+(*
+ Test for haproxy lens
+
+ Author: Bryon Roche <bryon@gogrid.com>
+
+ About: License
+ This file is licensed under the LGPL
+
+ We test a config parse, then a section removal, then a section add.
+*)
+
+module Test_haproxy =
+
+ let conf = "# this config needs haproxy-1.1.28 or haproxy-1.2.1
+
+global
+ #log 127.0.0.1 local0
+ #log 127.0.0.1 local1 notice
+ #log loghost local0 info
+ log 192.168.7.22 local0
+ maxconn 4096
+ #chroot /usr/share/haproxy
+ user haproxy
+ group haproxy
+ daemon
+ #debug
+ #quiet
+
+defaults
+ log global
+ mode http
+ option httplog
+ option dontlognull
+ retries 3
+ option redispatch
+ maxconn 2000
+ contimeout 5000
+ clitimeout 50000
+ srvtimeout 50000
+
+
+listen proxy1 0.0.0.0:80
+ mode http
+ log global
+ cookie SERVERID insert indirect
+ balance roundrobin
+ redispatch
+ option forwardfor
+ no option httplog
+ option dontlognull
+ maxconn 60000
+ retries 3
+ grace 3000
+ server lb1 192.168.7.122:80 cookie cookie1 inter 300
+ server lb2 192.168.7.123:80 cookie cookie1 inter 300
+ server lb3 192.168.7.124:80 cookie cookie1 inter 300
+"
+
+ let confrmtest ="# this config needs haproxy-1.1.28 or haproxy-1.2.1
+
+global
+ #log 127.0.0.1 local0
+ #log 127.0.0.1 local1 notice
+ #log loghost local0 info
+ log 192.168.7.22 local0
+ maxconn 4096
+ #chroot /usr/share/haproxy
+ user haproxy
+ group haproxy
+ daemon
+ #debug
+ #quiet
+
+listen proxy1 0.0.0.0:80
+ mode http
+ log global
+ cookie SERVERID insert indirect
+ balance roundrobin
+ redispatch
+ option forwardfor
+ no option httplog
+ option dontlognull
+ maxconn 60000
+ retries 3
+ grace 3000
+ server lb1 192.168.7.122:80 cookie cookie1 inter 300
+ server lb2 192.168.7.123:80 cookie cookie1 inter 300
+ server lb3 192.168.7.124:80 cookie cookie1 inter 300
+"
+
+ let confredeftest ="# this config needs haproxy-1.1.28 or haproxy-1.2.1
+
+global
+ #log 127.0.0.1 local0
+ #log 127.0.0.1 local1 notice
+ #log loghost local0 info
+ log 192.168.7.22 local0
+ maxconn 4096
+ #chroot /usr/share/haproxy
+ user haproxy
+ group haproxy
+ daemon
+ #debug
+ #quiet
+
+defaults
+ log global
+listen proxy1 0.0.0.0:80
+ mode http
+ log global
+ cookie SERVERID insert indirect
+ balance roundrobin
+ redispatch
+ option forwardfor
+ no option httplog
+ option dontlognull
+ maxconn 60000
+ retries 3
+ grace 3000
+ server lb1 192.168.7.122:80 cookie cookie1 inter 300
+ server lb2 192.168.7.123:80 cookie cookie1 inter 300
+ server lb3 192.168.7.124:80 cookie cookie1 inter 300
+"
+
+ test Haproxy.lns get conf =
+ { "#comment" = "this config needs haproxy-1.1.28 or haproxy-1.2.1" }
+ {}
+ { "global"
+ { "#comment" = "log 127.0.0.1 local0" }
+ { "#comment" = "log 127.0.0.1 local1 notice" }
+ { "#comment" = "log loghost local0 info" }
+ { "log" = "192.168.7.22 local0" }
+ { "maxconn" = "4096" }
+ { "#comment" = "chroot /usr/share/haproxy" }
+ { "user" = "haproxy" }
+ { "group" = "haproxy" }
+ { "daemon" }
+ { "#comment" = "debug" }
+ { "#comment" = "quiet" }
+ {}
+ }
+ { "defaults"
+ { "log" = "global" }
+ { "mode" = "http" }
+ { "option httplog" }
+ { "option dontlognull" }
+ { "retries" = "3" }
+ { "option redispatch" }
+ { "maxconn" = "2000" }
+ { "contimeout" = "5000" }
+ { "clitimeout" = "50000" }
+ { "srvtimeout" = "50000" }
+ {}
+ {}
+ }
+ { "listen"
+ { "proxy1" = "0.0.0.0:80"
+ { "mode" = "http" }
+ { "log" = "global" }
+ { "cookie" = "SERVERID insert indirect" }
+ { "balance" = "roundrobin" }
+ { "redispatch" }
+ { "option forwardfor" }
+ { "no option httplog" }
+ { "option dontlognull" }
+ { "maxconn" = "60000" }
+ { "retries" = "3" }
+ { "grace" = "3000" }
+ { "server" = "lb1 192.168.7.122:80 cookie cookie1 inter 300" }
+ { "server" = "lb2 192.168.7.123:80 cookie cookie1 inter 300" }
+ { "server" = "lb3 192.168.7.124:80 cookie cookie1 inter 300" }
+ }
+ }
+
+ test Haproxy.lns put conf after rm "/defaults" = confrmtest
+
+ test Haproxy.lns put confrmtest after insa "defaults" "/global" ; set "/defaults/log" "global" = confredeftest
+
+
+
+

0 comments on commit 0a453cf

Please sign in to comment.