lbspec 0.0.1
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/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +57 -0
- data/Rakefile +6 -0
- data/lbspec.gemspec +27 -0
- data/lib/lbspec/transfer.rb +74 -0
- data/lib/lbspec/version.rb +3 -0
- data/lib/lbspec.rb +5 -0
- data/sample/lb_spec.rb +6 -0
- data/sample/spec_helper.rb +1 -0
- data/spec/lbspec_spec.rb +11 -0
- data/spec/lbspec_transfer_spec.rb +12 -0
- data/spec/spec_helper.rb +2 -0
- metadata +146 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 OTA Hiroshi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 OTA Hiroshi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Lbspec
|
2
|
+
|
3
|
+
Lbspec is an RSpec plugin for easy Loadbalancer testing.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'lbspec'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install lbspec
|
18
|
+
|
19
|
+
## Requires
|
20
|
+
* Users need to be able to login with ssh to the target nodes.
|
21
|
+
* Users need to be able to `sudo` on the target nodes.
|
22
|
+
* netcat and ngrep are needed to be installed.
|
23
|
+
|
24
|
+
## Limitations
|
25
|
+
* Lbspec uses only ssh configuration in ~/.ssh/config
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Lbspec is best described by example. First, require `lbspec` in your `spec_helper.rb`:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
# spec/spec_helper.rb
|
33
|
+
require 'rspec'
|
34
|
+
require 'lbspec'
|
35
|
+
```
|
36
|
+
|
37
|
+
Then, create a spec like this:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require_relative 'spec_helper'
|
41
|
+
|
42
|
+
describe 'vhost_a' do
|
43
|
+
it { should transfer('node_a') }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'vhost_b' do
|
47
|
+
it { should transfer(['node_b','node_c']) }
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it ( http://github.com/otahi/lbspec/fork )
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lbspec.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lbspec/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lbspec"
|
8
|
+
spec.version = Lbspec::VERSION
|
9
|
+
spec.authors = ["OTA Hiroshi"]
|
10
|
+
spec.email = ["ota_h@nifty.com"]
|
11
|
+
spec.summary = "Easily test your Loadbalancers with RSpec."
|
12
|
+
spec.description = "Lbspec is an RSpec plugin for easy Loadbalancer testing."
|
13
|
+
spec.homepage = "https://github.com/otahi/lbspec"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "rspec"
|
26
|
+
spec.add_runtime_dependency "net-ssh"
|
27
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
require 'rspec/expectations'
|
3
|
+
|
4
|
+
RSpec::Matchers.define :transfer do |nodes|
|
5
|
+
@ssh = []
|
6
|
+
@threads = []
|
7
|
+
@nodes_connected = []
|
8
|
+
@result = false
|
9
|
+
|
10
|
+
match do |vhost|
|
11
|
+
gen_keyword
|
12
|
+
connect_nodes nodes
|
13
|
+
wait_nodes_connected nodes
|
14
|
+
send_request(vhost, 80)
|
15
|
+
disconnect_nodes
|
16
|
+
is_ok?
|
17
|
+
end
|
18
|
+
|
19
|
+
def gen_keyword
|
20
|
+
t = Time.now
|
21
|
+
@keyword = t.to_i.to_s + t.nsec.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def wait_nodes_connected(nodes)
|
25
|
+
nodes_length = 1
|
26
|
+
nodes_length = nodes.length if nodes.respond_to? :each
|
27
|
+
|
28
|
+
until (@nodes_connected.length == nodes_length) do
|
29
|
+
sleep 0.5
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def connect_nodes(nodes)
|
34
|
+
if nodes.respond_to? :each
|
35
|
+
nodes.each do |node|
|
36
|
+
@threads << Thread.new { connect_node(node) }
|
37
|
+
end
|
38
|
+
else
|
39
|
+
@threads << Thread.new { connect_node(nodes) }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def connect_node(node)
|
44
|
+
@ssh.push = Net::SSH.start(node, nil, :config => true) do |ssh|
|
45
|
+
ssh.open_channel do |ch|
|
46
|
+
ch.request_pty do |ch, success|
|
47
|
+
raise "Could not obtain pty " if !success
|
48
|
+
@nodes_connected.push(true)
|
49
|
+
ch.exec "sudo ngrep #{@keyword}" do |ch, stream, data|
|
50
|
+
ch.on_data do |c, data|
|
51
|
+
@result = true if /#{@keyword}/ === data
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def disconnect_nodes
|
60
|
+
@threads.each do |t|
|
61
|
+
t.kill
|
62
|
+
end
|
63
|
+
@ssh.each do |ssh|
|
64
|
+
ssh.close if ! ssh.closed?
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def send_request(vhost, port)
|
69
|
+
system("echo #{@keyword} | nc #{vhost} #{port}")
|
70
|
+
end
|
71
|
+
def is_ok?
|
72
|
+
@result
|
73
|
+
end
|
74
|
+
end
|
data/lib/lbspec.rb
ADDED
data/sample/lb_spec.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'lbspec'
|
data/spec/lbspec_spec.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lbspec do
|
4
|
+
describe '#transfer' do
|
5
|
+
it 'should test transfer a node' do
|
6
|
+
'vhost_a'.should transfer('node_a')
|
7
|
+
end
|
8
|
+
it 'should test transfer nodes' do
|
9
|
+
'vhost_a'.should transfer(['node_a','node_b'])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lbspec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- OTA Hiroshi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.5'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.5'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: net-ssh
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Lbspec is an RSpec plugin for easy Loadbalancer testing.
|
95
|
+
email:
|
96
|
+
- ota_h@nifty.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- .rspec
|
103
|
+
- .travis.yml
|
104
|
+
- Gemfile
|
105
|
+
- LICENSE
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- lbspec.gemspec
|
110
|
+
- lib/lbspec.rb
|
111
|
+
- lib/lbspec/transfer.rb
|
112
|
+
- lib/lbspec/version.rb
|
113
|
+
- sample/lb_spec.rb
|
114
|
+
- sample/spec_helper.rb
|
115
|
+
- spec/lbspec_spec.rb
|
116
|
+
- spec/lbspec_transfer_spec.rb
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
homepage: https://github.com/otahi/lbspec
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 1.8.21
|
140
|
+
signing_key:
|
141
|
+
specification_version: 3
|
142
|
+
summary: Easily test your Loadbalancers with RSpec.
|
143
|
+
test_files:
|
144
|
+
- spec/lbspec_spec.rb
|
145
|
+
- spec/lbspec_transfer_spec.rb
|
146
|
+
- spec/spec_helper.rb
|