lbspec 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -1
- data/lib/lbspec/transfer.rb +31 -13
- data/lib/lbspec/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -29,7 +29,9 @@ You can use lbspec to test load balancers.
|
|
29
29
|
You can use following chains with `#transfer`.
|
30
30
|
|
31
31
|
- port
|
32
|
-
|
32
|
+
- Tests if a virtual host transfers requests to specified port on target nodes.
|
33
|
+
- include
|
34
|
+
- Tests if a virtual host transfers requests include string.
|
33
35
|
- tcp
|
34
36
|
- Tests with tcp packets for the virtual host.
|
35
37
|
- udp
|
data/lib/lbspec/transfer.rb
CHANGED
@@ -25,11 +25,12 @@ RSpec::Matchers.define :transfer do |nodes|
|
|
25
25
|
@request_node = nil
|
26
26
|
@include_str = nil
|
27
27
|
@output_request = ''
|
28
|
+
@output_capture = []
|
28
29
|
@options = {}
|
29
30
|
|
30
31
|
@capture_command = lambda do |port, prove|
|
31
32
|
port_str = port > 0 ? "port #{port}" : ''
|
32
|
-
"sudo ngrep #{prove} #{port_str} | grep -v \"match:\""
|
33
|
+
"sudo ngrep -W byline #{prove} #{port_str} | grep -v \"match:\""
|
33
34
|
end
|
34
35
|
|
35
36
|
@udp_request_command = lambda do |addr, port, prove|
|
@@ -140,21 +141,31 @@ RSpec::Matchers.define :transfer do |nodes|
|
|
140
141
|
@threads << Thread.new do
|
141
142
|
Net::SSH.start(node, nil, config: true) do |ssh|
|
142
143
|
@ssh << ssh
|
143
|
-
ssh.open_channel
|
144
|
+
ssh.open_channel do |channel|
|
145
|
+
output = run_check channel
|
146
|
+
@output_capture.push(node: node, output: output)
|
147
|
+
end
|
144
148
|
end
|
145
149
|
end
|
146
150
|
end
|
147
151
|
|
148
152
|
def run_check(channel)
|
153
|
+
output = ''
|
149
154
|
channel.request_pty do |chan, success|
|
150
155
|
fail 'Could not obtain pty' unless success
|
151
156
|
@nodes_connected.push(true)
|
152
|
-
exec_capture(chan)
|
157
|
+
output = exec_capture(chan)
|
153
158
|
end
|
159
|
+
output
|
154
160
|
end
|
155
161
|
|
156
162
|
def exec_capture(channel)
|
157
163
|
command = capture_command(@node_port, @prove)
|
164
|
+
output = exec_capture_command(channel, command)
|
165
|
+
command + "\n" + output
|
166
|
+
end
|
167
|
+
|
168
|
+
def exec_capture_command(channel, command)
|
158
169
|
channel.exec command do |ch, stream, data|
|
159
170
|
whole_data = ''
|
160
171
|
ch.on_data do |c, d|
|
@@ -163,6 +174,7 @@ RSpec::Matchers.define :transfer do |nodes|
|
|
163
174
|
patterns << @include_str if @include_str
|
164
175
|
@result = match_all?(whole_data, patterns)
|
165
176
|
end
|
177
|
+
whole_data
|
166
178
|
end
|
167
179
|
end
|
168
180
|
|
@@ -225,19 +237,25 @@ RSpec::Matchers.define :transfer do |nodes|
|
|
225
237
|
|
226
238
|
failure_message_for_should do |vhost|
|
227
239
|
result = "expected #{vhost} to transfer requests to"
|
228
|
-
result <<
|
229
|
-
|
230
|
-
result << ", but did not.\n"
|
231
|
-
result << "requested:\n"
|
232
|
-
result << @output_request
|
240
|
+
result <<
|
241
|
+
result_string(nodes, @chain_str, @output_request, @output_capture)
|
233
242
|
end
|
234
243
|
|
235
244
|
failure_message_for_should_not do |vhost|
|
236
245
|
result = "expected #{vhost} not to transfer requests to"
|
237
|
-
result <<
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
246
|
+
result <<
|
247
|
+
result_string(nodes, @chain_str, @output_request, @output_capture)
|
248
|
+
end
|
249
|
+
|
250
|
+
def result_string(nodes, chain_str, request_str, capture_str)
|
251
|
+
result = nodes.to_s + chain_str
|
252
|
+
result << ", but did.\n" + "requested:\n"
|
253
|
+
result << request_str.gsub(/^/, ' ')
|
254
|
+
result << "\ncaptured:\n"
|
255
|
+
@output_capture.each do |o|
|
256
|
+
result << o[:node].gsub(/^/, ' ') + "\n"
|
257
|
+
result << o[:output].gsub(/^/, ' ') + "\n"
|
258
|
+
end
|
259
|
+
result
|
242
260
|
end
|
243
261
|
end
|
data/lib/lbspec/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lbspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -184,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
184
184
|
version: '0'
|
185
185
|
segments:
|
186
186
|
- 0
|
187
|
-
hash:
|
187
|
+
hash: 2692456461482340401
|
188
188
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
189
|
none: false
|
190
190
|
requirements:
|
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
193
|
version: '0'
|
194
194
|
segments:
|
195
195
|
- 0
|
196
|
-
hash:
|
196
|
+
hash: 2692456461482340401
|
197
197
|
requirements: []
|
198
198
|
rubyforge_project:
|
199
199
|
rubygems_version: 1.8.21
|