Lbspec
Lbspec is an RSpec plugin for easy Loadbalancer testing.
Installation
Add this line to your application's Gemfile:
gem 'lbspec'
And then execute:
$ bundle
Or install it yourself as:
$ gem install lbspec
Functions
You can use lbspec to test load balancers.
#transfer
#transfer tests if a virtual host on a load balancer transfer requests to target nodes.
chains
You can use following chains with #transfer.
- port
- Tests if a virtual host transfers requests to specified port on target nodes.
- include
- Tests if requests a virtual host transferred include string or are matched with regular expression.
- tcp
- Tests with tcp packets for the virtual host.
- udp
- Tests with udp packets for the virtual host.
- http
- Tests with an http request for the virtual host.
- https
- Tests with an https request for the virtual host.
- from
- Specifies which host sends to the virtual host.
- path
- Specifies a path for http or https requests.
- options
- Options which can be used in http or https request commands.
- You can use
optionsif you configure request commands or capture commands.
#respond
#respond tests if a virtual host on a load balancer respond as same as expected.
You can use both a string and a regular expression as a expectation.
chains
You can use following chains with #respond.
- tcp
- Tests with tcp packets for the virtual host.
- udp
- Tests with udp packets for the virtual host.
- http
- Tests with an http request for the virtual host.
- https
- Tests with an https request for the virtual host.
- from
- Specifies which host sends to the virtual host.
- path
- Specifies a path for http or https requests.
- with
- Specifies a string included in requests.
- options
- Options which can be used in http or https request commands.
- You can use
optionsif you configure request commands or capture commands.
Requires
- Users need to be able to login with ssh to the target nodes.
- Users need to be able to
sudoon the target nodes. - Netcat and curl are needed on requesting host.
- Grep and ngrep are needed on capturing host.
Limitations
- Lbspec uses only ssh configuration in ~/.ssh/config
Usage
Lbspec is best described by example. First, require lbspec in your spec_helper.rb:
# spec/spec_helper.rb
require 'rspec'
require 'lbspec'
Then, create a spec like this:
require_relative 'spec_helper'
describe 'vhost_a' do
it { should transfer('node_a') }
it { should respond('200 OK') }
end
describe 'vhost_b' do
it { should transfer(['node_b','node_c']) }
it { should respond('200 OK') }
end
describe 'vhost_c:80' do
it { should transfer(['node_b','node_c']).port(80) }
it { should respond('404') }
end
describe 'vhost_c:80' do
it { should transfer(['node_b','node_c']).port(53).udp }
end
describe 'vhost_c:80/test/' do
it { should transfer('node_c').http }
it { should respond('200 OK').http }
end
describe 'vhost_c:443' do
it { should transfer(['node_b','node_c']).port(80).https.path('/test/' }
it { should respond('200 OK').https.path('/test/') }
end
describe 'vhost_c:443/test/' do
it do
should transfer(['node_b','node_c']).port(80).https
.options(ignore_valid_ssl: true)
end
it do should respond('200 OK').path('/test/').https
.options(ignore_valid_ssl: true)
end
end
describe 'vhost_c:80/test/' do
it { should transfer('node_c').http.from('node_a') }
end
How it works
#transfer
- ssh to nodes
- ssh to the nodes which receive requests via the target virtual host
- capture probe
- capture packets on the nodes
- access to the nodes with probe
- netcat or curl to the virtual host with prove
- judge
- judge if expected request are captured on the capturing nodes

Contributing
- Fork it ( http://github.com/otahi/lbspec/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request


