haproxy-tools 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.rdoc +13 -0
- data/Gemfile +4 -6
- data/README.rdoc +42 -1
- data/Rakefile +1 -0
- data/TODO +29 -0
- data/VERSION +1 -1
- data/docs/haproxy-1.3-configuration.txt +6668 -0
- data/docs/haproxy-1.4-configuration.txt +8566 -0
- data/haproxy-tools.gemspec +83 -0
- data/lib/haproxy/config.rb +54 -17
- data/lib/haproxy/parser.rb +119 -69
- data/lib/haproxy/renderer.rb +111 -0
- data/lib/haproxy/treetop/config.treetop +189 -0
- data/lib/haproxy/treetop/nodes.rb +174 -0
- data/lib/haproxy_tools.rb +10 -0
- data/spec/fixtures/simple.haproxy.cfg +2 -1
- data/spec/haproxy/config_spec.rb +99 -0
- data/spec/haproxy/parser_spec.rb +50 -29
- data/spec/haproxy/treetop/config_parser_spec.rb +95 -0
- metadata +62 -26
data/spec/haproxy/parser_spec.rb
CHANGED
@@ -1,31 +1,32 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "HAProxy::Parser" do
|
4
|
+
|
4
5
|
context 'multi-pool config file' do
|
5
6
|
before(:each) do
|
6
7
|
@parser = HAProxy::Parser.new
|
7
|
-
@config = @parser.
|
8
|
+
@config = @parser.parse_file('spec/fixtures/multi-pool.haproxy.cfg')
|
8
9
|
end
|
9
10
|
|
10
|
-
it "parses a named
|
11
|
-
@config.backends.size.should ==
|
11
|
+
it "parses a named backend from a config file" do
|
12
|
+
@config.backends.size.should == 2
|
12
13
|
logs_backend = @config.backend('logs')
|
13
14
|
|
14
15
|
logs_backend.servers.size.should == 3
|
15
16
|
|
16
17
|
server1 = logs_backend.servers['prd_log_1']
|
17
18
|
server1.name.should == 'prd_log_1'
|
18
|
-
server1.
|
19
|
+
server1.host.should == '10.245.174.75'
|
19
20
|
server1.port.should == '8000'
|
20
21
|
|
21
22
|
server2 = logs_backend.servers['fake_logger']
|
22
23
|
server2.name.should == 'fake_logger'
|
23
|
-
server2.
|
24
|
+
server2.host.should == '127.0.0.1'
|
24
25
|
server2.port.should == '9999'
|
25
26
|
|
26
27
|
server3 = logs_backend.servers['prd_log_2']
|
27
28
|
server3.name.should == 'prd_log_2'
|
28
|
-
server3.
|
29
|
+
server3.host.should == '10.215.157.10'
|
29
30
|
server3.port.should == '8000'
|
30
31
|
end
|
31
32
|
end
|
@@ -33,48 +34,68 @@ describe "HAProxy::Parser" do
|
|
33
34
|
context 'basic config file' do
|
34
35
|
before(:each) do
|
35
36
|
@parser = HAProxy::Parser.new
|
36
|
-
@config = @parser.
|
37
|
+
@config = @parser.parse_file('spec/fixtures/simple.haproxy.cfg')
|
37
38
|
end
|
38
39
|
|
39
40
|
it "parses global variables from a config file" do
|
40
41
|
@config.global.size.should == 3
|
41
|
-
@config.global['maxconn'].should ==
|
42
|
-
@config.global['daemon'].should ==
|
43
|
-
@config.global['nbproc'].should ==
|
42
|
+
@config.global['maxconn'].should == '4096'
|
43
|
+
@config.global['daemon'].should == nil
|
44
|
+
@config.global['nbproc'].should == '4'
|
44
45
|
end
|
45
46
|
|
46
|
-
it "parses default
|
47
|
-
@config.defaults.size.should ==
|
48
|
-
|
49
|
-
@config.defaults
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
47
|
+
it "parses a default set from a config file" do
|
48
|
+
@config.defaults.size.should == 1
|
49
|
+
|
50
|
+
defaults = @config.defaults.first
|
51
|
+
defaults.config['mode'].should == 'http'
|
52
|
+
defaults.config['clitimeout'].should == '60000'
|
53
|
+
defaults.config['srvtimeout'].should == '30000'
|
54
|
+
defaults.config['contimeout'].should == '4000'
|
55
|
+
|
56
|
+
defaults.options.size.should == 1
|
57
|
+
defaults.options.should include('httpclose')
|
55
58
|
end
|
56
59
|
|
57
|
-
it
|
58
|
-
@config.
|
60
|
+
it 'parses a listener from a config file' do
|
61
|
+
@config.listeners.size.should == 1
|
59
62
|
|
60
|
-
|
63
|
+
listener = @config.listener('http_proxy')
|
64
|
+
listener.name.should == 'http_proxy'
|
65
|
+
listener.host.should == '55.55.55.55'
|
66
|
+
listener.port.should == '80'
|
67
|
+
listener.config['balance'].should == 'roundrobin'
|
61
68
|
|
62
|
-
|
69
|
+
listener.options.size.should == 2
|
70
|
+
listener.options.should include('httpchk')
|
71
|
+
listener.options.should include('forwardfor')
|
63
72
|
|
64
|
-
|
73
|
+
listener.servers.size.should == 3
|
74
|
+
|
75
|
+
server1 = listener.servers['web1']
|
65
76
|
server1.name.should == 'web1'
|
66
|
-
server1.
|
77
|
+
server1.host.should == '66.66.66.66'
|
67
78
|
server1.port.should == '80'
|
79
|
+
server1.attributes['weight'].should == '1'
|
80
|
+
server1.attributes['maxconn'].should == '512'
|
81
|
+
server1.attributes['check'].should == true
|
68
82
|
|
69
|
-
server2 =
|
83
|
+
server2 = listener.servers['web2']
|
70
84
|
server2.name.should == 'web2'
|
71
|
-
server2.
|
85
|
+
server2.host.should == '77.77.77.77'
|
72
86
|
server2.port.should == '80'
|
87
|
+
server2.attributes['weight'].should == '1'
|
88
|
+
server2.attributes['maxconn'].should == '512'
|
89
|
+
server2.attributes['check'].should == true
|
73
90
|
|
74
|
-
server3 =
|
91
|
+
server3 = listener.servers['web3']
|
75
92
|
server3.name.should == 'web3'
|
76
|
-
server3.
|
93
|
+
server3.host.should == '88.88.88.88'
|
77
94
|
server3.port.should == '80'
|
95
|
+
server3.attributes['weight'].should == '1'
|
96
|
+
server3.attributes['maxconn'].should == '512'
|
97
|
+
server3.attributes['check'].should == true
|
78
98
|
end
|
79
99
|
end
|
80
100
|
end
|
101
|
+
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HAProxy::Treetop::ConfigParser do
|
4
|
+
before(:each) do
|
5
|
+
@parser = HAProxy::Treetop::ConfigParser.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def parse_file(filename)
|
9
|
+
@result = @parser.parse(File.read(filename))
|
10
|
+
if @result.nil?
|
11
|
+
puts
|
12
|
+
puts "Failure Reason: #{@parser.failure_reason}"
|
13
|
+
end
|
14
|
+
|
15
|
+
# HAProxy::Treetop.print_node(@result, 0, :max_depth => 3)
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_single_pool
|
19
|
+
parse_file('spec/fixtures/simple.haproxy.cfg')
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_multi_pool
|
23
|
+
parse_file('spec/fixtures/multi-pool.haproxy.cfg')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "can parse servers from a backend server block" do
|
27
|
+
parse_multi_pool
|
28
|
+
|
29
|
+
backend = @result.backends.first
|
30
|
+
backend.servers.size.should == 4
|
31
|
+
backend.servers[0].name.should == 'prd_www_1'
|
32
|
+
backend.servers[0].host.should == '10.214.78.95'
|
33
|
+
backend.servers[0].port.should == '8000'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'can parse a service address from a frontend header' do
|
37
|
+
parse_multi_pool
|
38
|
+
|
39
|
+
frontend = @result.frontends.first
|
40
|
+
frontend.frontend_header.service_address.host.content.should == '*'
|
41
|
+
frontend.frontend_header.service_address.port.content.should == '85'
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'can parse a service address from a listen header' do
|
45
|
+
parse_single_pool
|
46
|
+
|
47
|
+
listener = @result.listeners.first
|
48
|
+
listener.listen_header.service_address.host.content.should == '55.55.55.55'
|
49
|
+
listener.listen_header.service_address.port.content.should == '80'
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'can parse a file with a listen section' do
|
53
|
+
parse_single_pool
|
54
|
+
|
55
|
+
@result.class.should == HAProxy::Treetop::ConfigurationFile
|
56
|
+
@result.elements.size.should == 4
|
57
|
+
|
58
|
+
@result.global.should == @result.elements[1]
|
59
|
+
@result.elements[1].class.should == HAProxy::Treetop::GlobalSection
|
60
|
+
|
61
|
+
@result.defaults[0].should == @result.elements[2]
|
62
|
+
@result.elements[2].class.should == HAProxy::Treetop::DefaultsSection
|
63
|
+
|
64
|
+
@result.listeners[0].should == @result.elements[3]
|
65
|
+
@result.elements[3].class.should == HAProxy::Treetop::ListenSection
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'can parse a file with frontend/backend sections' do
|
69
|
+
parse_multi_pool
|
70
|
+
|
71
|
+
@result.class.should == HAProxy::Treetop::ConfigurationFile
|
72
|
+
@result.elements.size.should == 5
|
73
|
+
|
74
|
+
@result.global.should == @result.elements[0]
|
75
|
+
@result.elements[0].class.should == HAProxy::Treetop::GlobalSection
|
76
|
+
|
77
|
+
@result.defaults[0].should == @result.elements[1]
|
78
|
+
@result.elements[1].class.should == HAProxy::Treetop::DefaultsSection
|
79
|
+
|
80
|
+
@result.frontends[0].should == @result.elements[2]
|
81
|
+
@result.elements[2].class.should == HAProxy::Treetop::FrontendSection
|
82
|
+
|
83
|
+
@result.backends[0].should == @result.elements[3]
|
84
|
+
@result.backends[1].should == @result.elements[4]
|
85
|
+
@result.elements[3].class.should == HAProxy::Treetop::BackendSection
|
86
|
+
@result.elements[4].class.should == HAProxy::Treetop::BackendSection
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'can parse userlist sections'
|
90
|
+
it 'can parse valid units of time'
|
91
|
+
it 'can parse strings with escaped spaces'
|
92
|
+
it 'can parse files with escaped quotes'
|
93
|
+
it 'can parse keywords with hyphens'
|
94
|
+
end
|
95
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haproxy-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jason Wadsworth
|
@@ -15,62 +15,74 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-04-24 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
prerelease: false
|
23
|
-
name:
|
24
|
-
type: :
|
23
|
+
name: net-scp
|
24
|
+
type: :runtime
|
25
25
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
26
|
none: false
|
27
27
|
requirements:
|
28
|
-
- -
|
28
|
+
- - ">="
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
hash:
|
30
|
+
hash: 3
|
31
31
|
segments:
|
32
|
-
- 2
|
33
|
-
- 7
|
34
32
|
- 0
|
35
|
-
version:
|
33
|
+
version: "0"
|
36
34
|
requirement: *id001
|
37
35
|
- !ruby/object:Gem::Dependency
|
38
36
|
prerelease: false
|
39
|
-
name:
|
40
|
-
type: :
|
37
|
+
name: orderedhash
|
38
|
+
type: :runtime
|
41
39
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
42
40
|
none: false
|
43
41
|
requirements:
|
44
|
-
- -
|
42
|
+
- - ">="
|
45
43
|
- !ruby/object:Gem::Version
|
46
44
|
hash: 3
|
47
45
|
segments:
|
48
46
|
- 0
|
49
|
-
|
50
|
-
- 0
|
51
|
-
version: 0.7.0
|
47
|
+
version: "0"
|
52
48
|
requirement: *id002
|
53
49
|
- !ruby/object:Gem::Dependency
|
54
50
|
prerelease: false
|
55
|
-
name:
|
51
|
+
name: rspec
|
56
52
|
type: :development
|
57
53
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
58
54
|
none: false
|
59
55
|
requirements:
|
60
56
|
- - ~>
|
61
57
|
- !ruby/object:Gem::Version
|
62
|
-
hash:
|
58
|
+
hash: 19
|
63
59
|
segments:
|
64
|
-
-
|
65
|
-
-
|
60
|
+
- 2
|
61
|
+
- 7
|
66
62
|
- 0
|
67
|
-
version:
|
63
|
+
version: 2.7.0
|
68
64
|
requirement: *id003
|
69
65
|
- !ruby/object:Gem::Dependency
|
70
66
|
prerelease: false
|
71
|
-
name:
|
67
|
+
name: yard
|
72
68
|
type: :development
|
73
69
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
- 7
|
78
|
+
- 0
|
79
|
+
version: 0.7.0
|
80
|
+
requirement: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
prerelease: false
|
83
|
+
name: jeweler
|
84
|
+
type: :development
|
85
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
74
86
|
none: false
|
75
87
|
requirements:
|
76
88
|
- - ~>
|
@@ -81,12 +93,12 @@ dependencies:
|
|
81
93
|
- 6
|
82
94
|
- 4
|
83
95
|
version: 1.6.4
|
84
|
-
requirement: *
|
96
|
+
requirement: *id005
|
85
97
|
- !ruby/object:Gem::Dependency
|
86
98
|
prerelease: false
|
87
99
|
name: rcov
|
88
100
|
type: :development
|
89
|
-
version_requirements: &
|
101
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
90
102
|
none: false
|
91
103
|
requirements:
|
92
104
|
- - ">="
|
@@ -95,7 +107,21 @@ dependencies:
|
|
95
107
|
segments:
|
96
108
|
- 0
|
97
109
|
version: "0"
|
98
|
-
requirement: *
|
110
|
+
requirement: *id006
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
prerelease: false
|
113
|
+
name: treetop
|
114
|
+
type: :development
|
115
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
requirement: *id007
|
99
125
|
description: Ruby tools for HAProxy, including config file management.
|
100
126
|
email: jdwadsworth@gmail.com
|
101
127
|
executables: []
|
@@ -105,22 +131,32 @@ extensions: []
|
|
105
131
|
extra_rdoc_files:
|
106
132
|
- LICENSE.txt
|
107
133
|
- README.rdoc
|
134
|
+
- TODO
|
108
135
|
files:
|
109
136
|
- .document
|
110
137
|
- .rspec
|
138
|
+
- CHANGES.rdoc
|
111
139
|
- Gemfile
|
112
140
|
- LICENSE.txt
|
113
141
|
- README.rdoc
|
114
142
|
- Rakefile
|
143
|
+
- TODO
|
115
144
|
- VERSION
|
145
|
+
- docs/haproxy-1.3-configuration.txt
|
146
|
+
- docs/haproxy-1.4-configuration.txt
|
147
|
+
- haproxy-tools.gemspec
|
116
148
|
- lib/haproxy-tools.rb
|
117
149
|
- lib/haproxy/config.rb
|
118
150
|
- lib/haproxy/parser.rb
|
151
|
+
- lib/haproxy/renderer.rb
|
152
|
+
- lib/haproxy/treetop/config.treetop
|
153
|
+
- lib/haproxy/treetop/nodes.rb
|
119
154
|
- lib/haproxy_tools.rb
|
120
155
|
- spec/fixtures/multi-pool.haproxy.cfg
|
121
156
|
- spec/fixtures/simple.haproxy.cfg
|
122
157
|
- spec/haproxy/config_spec.rb
|
123
158
|
- spec/haproxy/parser_spec.rb
|
159
|
+
- spec/haproxy/treetop/config_parser_spec.rb
|
124
160
|
- spec/spec_helper.rb
|
125
161
|
has_rdoc: true
|
126
162
|
homepage: http://github.com/subakva/haproxy-tools
|