lbspec 0.0.6 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +35 -3
- data/lib/lbspec/transfer.rb +14 -4
- data/lib/lbspec/util.rb +9 -0
- data/lib/lbspec/version.rb +1 -1
- data/spec/lbspec_transfer_spec.rb +9 -12
- metadata +3 -3
data/README.md
CHANGED
@@ -19,6 +19,33 @@ Or install it yourself as:
|
|
19
19
|
|
20
20
|
$ gem install lbspec
|
21
21
|
|
22
|
+
## Functions
|
23
|
+
You can use lbspec to test load balancers.
|
24
|
+
|
25
|
+
### #transfer
|
26
|
+
`#transfer` tests if a virtual host on a load balancer transfer requests to target nodes.
|
27
|
+
|
28
|
+
#### chains
|
29
|
+
You can use following chains with `#transfer`.
|
30
|
+
|
31
|
+
- port
|
32
|
+
- Tests if a virtual host transfers requests to specified port on target nodes.
|
33
|
+
- tcp
|
34
|
+
- Tests with tcp packets for the virtual host.
|
35
|
+
- udp
|
36
|
+
- Tests with udp packets for the virtual host.
|
37
|
+
- http
|
38
|
+
- Tests with an http request for the virtual host.
|
39
|
+
- https
|
40
|
+
- Tests with an https request for the virtual host.
|
41
|
+
- path
|
42
|
+
- Specifies a path for http or https requests.
|
43
|
+
- from
|
44
|
+
- Specifies which host sends to the virtual host.
|
45
|
+
- options
|
46
|
+
- Options which can be used in http or https request commands.
|
47
|
+
- You can use `options` if you configure request commands or capture commands.
|
48
|
+
|
22
49
|
## Requires
|
23
50
|
* Users need to be able to login with ssh to the target nodes.
|
24
51
|
* Users need to be able to `sudo` on the target nodes.
|
@@ -73,6 +100,10 @@ describe 'vhost_c:443' do
|
|
73
100
|
end
|
74
101
|
end
|
75
102
|
|
103
|
+
describe 'vhost_c:80' do
|
104
|
+
it { should transfer('node_c').http.path('/test/').from('node_a') }
|
105
|
+
end
|
106
|
+
|
76
107
|
```
|
77
108
|
## How it works
|
78
109
|
### #transfer
|
@@ -84,9 +115,10 @@ end
|
|
84
115
|
|
85
116
|
![#tranfer works][1]
|
86
117
|
|
118
|
+
|
87
119
|
## Configuration
|
88
120
|
### #transfer
|
89
|
-
You can change how to capture probes and access to `vhost` with probes. You can replace default procedures to your procedures in spec_helpers or .spec files as follows.
|
121
|
+
You can change how to capture probes and access to `vhost` with probes. You can replace default procedures to your procedures in spec_helpers or .spec files as follows. If you use `Lbspec::Util.exec_command()`, you can specify the node which generate request.
|
90
122
|
```ruby
|
91
123
|
RSpec.configuration.lbspec_capture_command =
|
92
124
|
lambda do |port, prove|
|
@@ -97,7 +129,7 @@ end
|
|
97
129
|
RSpec.configuration.lbspec_https_request_command =
|
98
130
|
lambda do |addr, port, path, prove|
|
99
131
|
uri = 'https://' + "#{addr}:#{port}#{path}?#{prove}"
|
100
|
-
|
132
|
+
Lbspec::Util.exec_command("curl -o /dev/null -sk #{uri}", @request_node)
|
101
133
|
end
|
102
134
|
```
|
103
135
|
You can also use the procedures with `options` with a chain `options`.
|
@@ -106,7 +138,7 @@ RSpec.configuration.lbspec_https_request_command =
|
|
106
138
|
lambda do |addr, port, path, prove|
|
107
139
|
opt = @options[:timeout] ? " -m #{@options[:timeout]}" : ''
|
108
140
|
opt << (@options[:ignore_valid_ssl] ? ' -k' : '')
|
109
|
-
|
141
|
+
Lbspec::Util.exec_command("curl -o /dev/null -s #{opt} #{uri}", @request_node)
|
110
142
|
end
|
111
143
|
```
|
112
144
|
|
data/lib/lbspec/transfer.rb
CHANGED
@@ -22,6 +22,7 @@ RSpec::Matchers.define :transfer do |nodes|
|
|
22
22
|
@http_path = '/'
|
23
23
|
@vhost_port = 80
|
24
24
|
@node_port = 0
|
25
|
+
@request_node = nil
|
25
26
|
@options = {}
|
26
27
|
|
27
28
|
@capture_command = lambda do |port, prove|
|
@@ -30,21 +31,25 @@ RSpec::Matchers.define :transfer do |nodes|
|
|
30
31
|
end
|
31
32
|
|
32
33
|
@udp_request_command = lambda do |addr, port, prove|
|
33
|
-
|
34
|
+
Lbspec::Util
|
35
|
+
.exec_command("echo #{prove} | nc -u #{addr} #{port}", @request_node)
|
34
36
|
end
|
35
37
|
@tcp_request_command = lambda do |addr, port, prove|
|
36
|
-
|
38
|
+
Lbspec::Util
|
39
|
+
.exec_command("echo #{prove} | nc #{addr} #{port}", @request_node)
|
37
40
|
end
|
38
41
|
@http_request_command = lambda do |addr, port, path, prove|
|
39
42
|
opt = @options[:timeout] ? " -m #{@options[:timeout]}" : ''
|
40
43
|
uri = 'http://' + "#{addr}:#{port}#{path}?#{prove}"
|
41
|
-
|
44
|
+
Lbspec::Util
|
45
|
+
.exec_command("curl -o /dev/null -s #{opt} #{uri}", @request_node)
|
42
46
|
end
|
43
47
|
@https_request_command = lambda do |addr, port, path, prove|
|
44
48
|
opt = @options[:timeout] ? " -m #{@options[:timeout]}" : ''
|
45
49
|
opt << (@options[:ignore_valid_ssl] ? ' -k' : '')
|
46
50
|
uri = 'https://' + "#{addr}:#{port}#{path}?#{prove}"
|
47
|
-
|
51
|
+
Lbspec::Util
|
52
|
+
.exec_command("curl -o /dev/null -sk #{opt} #{uri}", @request_node)
|
48
53
|
end
|
49
54
|
|
50
55
|
@result = false
|
@@ -92,6 +97,11 @@ RSpec::Matchers.define :transfer do |nodes|
|
|
92
97
|
@chain_str << " via #{path}"
|
93
98
|
end
|
94
99
|
|
100
|
+
chain :from do |from|
|
101
|
+
@request_node = from
|
102
|
+
@chain_str << " from #{from}"
|
103
|
+
end
|
104
|
+
|
95
105
|
chain :options do |options|
|
96
106
|
@options = options
|
97
107
|
end
|
data/lib/lbspec/util.rb
CHANGED
@@ -14,5 +14,14 @@ module Lbspec
|
|
14
14
|
port = splits.last.to_i if /\d+/ =~ splits.last
|
15
15
|
{ addr: addr, port: port }
|
16
16
|
end
|
17
|
+
def self.exec_command(command, node = nil)
|
18
|
+
if node
|
19
|
+
Net::SSH.start(node, nil, config: true) do |ssh|
|
20
|
+
ssh.exec!(command)
|
21
|
+
end
|
22
|
+
else
|
23
|
+
system(command)
|
24
|
+
end
|
25
|
+
end
|
17
26
|
end
|
18
27
|
end
|
data/lib/lbspec/version.rb
CHANGED
@@ -15,6 +15,7 @@ describe Lbspec do
|
|
15
15
|
ssh_connected.stub(:open_channel).and_yield(channel_connected)
|
16
16
|
ssh_connected.stub(:closed?).and_return(false)
|
17
17
|
ssh_connected.stub(:close)
|
18
|
+
ssh_connected.stub(:exec!).and_return(true)
|
18
19
|
Net::SSH.stub(:start).and_yield(ssh_connected).and_return(ssh_connected)
|
19
20
|
Kernel.stub(:system).and_return true
|
20
21
|
end
|
@@ -49,19 +50,15 @@ describe Lbspec do
|
|
49
50
|
it 'should test transfer vhost:443 and a node with https /test' do
|
50
51
|
'vhost_a:443'.should transfer('node_a').https.path('/test')
|
51
52
|
end
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
it 'should test transfer vhost:443 with options for requests' do
|
54
|
+
'vhost_a:443'.should transfer('node_a').https.path('/test')
|
55
|
+
.options(ignore_valid_ssl: true)
|
56
|
+
'vhost_a:443'.should transfer('node_a').https.path('/test')
|
57
|
+
.options(ignore_valid_ssl: false, timeout: 5)
|
55
58
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
.options(ignore_valid_ssl: true)
|
60
|
-
end
|
61
|
-
it do
|
62
|
-
should transfer('node_a').https.path('/test')
|
63
|
-
.options(ignore_valid_ssl: false, timeout: 5)
|
64
|
-
end
|
59
|
+
it 'should test transfer vhost:443 requests from specified host' do
|
60
|
+
'vhost_a:443'.should transfer('node_a')
|
61
|
+
.https.path('/test').from('node_a')
|
65
62
|
end
|
66
63
|
end
|
67
64
|
end
|
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -200,7 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
200
200
|
version: '0'
|
201
201
|
segments:
|
202
202
|
- 0
|
203
|
-
hash: -
|
203
|
+
hash: -1732435815710576022
|
204
204
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
205
|
none: false
|
206
206
|
requirements:
|
@@ -209,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
209
|
version: '0'
|
210
210
|
segments:
|
211
211
|
- 0
|
212
|
-
hash: -
|
212
|
+
hash: -1732435815710576022
|
213
213
|
requirements: []
|
214
214
|
rubyforge_project:
|
215
215
|
rubygems_version: 1.8.21
|