2011-03-08 17:41:49 -05:00
|
|
|
Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
|
|
|
|
|
|
|
|
|
|
|
|
tests('success') do
|
|
|
|
pending if Fog.mocking?
|
|
|
|
|
|
|
|
tests('load_balancers') do
|
|
|
|
tests('getting a missing elb') do
|
|
|
|
returns(nil) { AWS[:elb].load_balancers.get('no-such-elb') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
elb = nil
|
|
|
|
elb_id = 'fog-test'
|
|
|
|
|
|
|
|
tests('create') do
|
|
|
|
elb = AWS[:elb].load_balancers.create(:id => elb_id)
|
|
|
|
tests("dns names is set").returns(true) { elb.dns_name.is_a?(String) }
|
2011-05-28 16:15:44 -04:00
|
|
|
tests("created_at is set").returns(true) { Time === elb.created_at }
|
2011-05-02 18:17:19 -04:00
|
|
|
tests("policies is empty").returns([]) { elb.policies }
|
2011-03-08 17:41:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('all') do
|
|
|
|
elb_ids = AWS[:elb].load_balancers.all.map{|e| e.id}
|
|
|
|
tests("contains elb").returns(true) { elb_ids.include? elb_id }
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('get') do
|
|
|
|
elb2 = AWS[:elb].load_balancers.get(elb_id)
|
|
|
|
tests('ids match').returns(elb_id) { elb2.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('createing a duplicate elb') do
|
|
|
|
raises(Fog::AWS::ELB::IdentifierTaken) do
|
|
|
|
AWS[:elb].load_balancers.create(:id => elb_id, :availability_zones => ['us-east-1d'])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('registering an invalid instance') do
|
|
|
|
raises(Fog::AWS::ELB::InvalidInstance) { elb.register_instances('i-00000000') }
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('deregistering an invalid instance') do
|
|
|
|
raises(Fog::AWS::ELB::InvalidInstance) { elb.deregister_instances('i-00000000') }
|
|
|
|
end
|
|
|
|
|
2011-06-23 14:51:31 -04:00
|
|
|
server = Compute[:aws].servers.create
|
2011-03-08 17:41:49 -05:00
|
|
|
tests('register instance') do
|
|
|
|
begin
|
|
|
|
elb.register_instances(server.id)
|
|
|
|
rescue Fog::AWS::ELB::InvalidInstance
|
|
|
|
# It may take a moment for a newly created instances to be visible to ELB requests
|
|
|
|
raise if @retried_registered_instance
|
|
|
|
@retried_registered_instance = true
|
|
|
|
sleep 1
|
|
|
|
retry
|
|
|
|
end
|
|
|
|
|
|
|
|
returns([server.id]) { elb.instances }
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('instance_health') do
|
|
|
|
returns('OutOfService') do
|
|
|
|
elb.instance_health.detect{|hash| hash['InstanceId'] == server.id}['State']
|
|
|
|
end
|
|
|
|
|
|
|
|
returns([server.id]) { elb.instances_out_of_service }
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('deregister instance') do
|
|
|
|
elb.deregister_instances(server.id)
|
|
|
|
returns([]) { elb.instances }
|
|
|
|
end
|
|
|
|
server.destroy
|
|
|
|
|
|
|
|
tests('disable_availability_zones') do
|
|
|
|
elb.disable_availability_zones(%w{us-east-1c us-east-1d})
|
|
|
|
returns(%w{us-east-1a us-east-1b}) { elb.availability_zones.sort }
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('enable_availability_zones') do
|
|
|
|
elb.enable_availability_zones(%w{us-east-1c us-east-1d})
|
|
|
|
returns(%w{us-east-1a us-east-1b us-east-1c us-east-1d}) { elb.availability_zones.sort }
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('default health check') do
|
|
|
|
default_health_check = {
|
|
|
|
"HealthyThreshold"=>10,
|
|
|
|
"Timeout"=>5,
|
|
|
|
"UnhealthyThreshold"=>2,
|
|
|
|
"Interval"=>30,
|
|
|
|
"Target"=>"TCP:80"
|
|
|
|
}
|
|
|
|
returns(default_health_check) { elb.health_check }
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('configure_health_check') do
|
|
|
|
new_health_check = {
|
|
|
|
"HealthyThreshold"=>5,
|
|
|
|
"Timeout"=>10,
|
|
|
|
"UnhealthyThreshold"=>3,
|
|
|
|
"Interval"=>15,
|
|
|
|
"Target"=>"HTTP:80/index.html"
|
|
|
|
}
|
|
|
|
elb.configure_health_check(new_health_check)
|
|
|
|
returns(new_health_check) { elb.health_check }
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('listeners') do
|
|
|
|
default_listener_description = [{"Listener"=>{"InstancePort"=>80, "Protocol"=>"HTTP", "LoadBalancerPort"=>80}, "PolicyNames"=>[]}]
|
2011-05-04 18:29:07 -04:00
|
|
|
tests('default') do
|
|
|
|
returns(1) { elb.listeners.size }
|
|
|
|
|
|
|
|
listener = elb.listeners.first
|
|
|
|
returns([80,80,'HTTP', []]) { [listener.instance_port, listener.lb_port, listener.protocol, listener.policy_names] }
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('#get') do
|
|
|
|
returns(80) { elb.listeners.get(80).lb_port }
|
|
|
|
end
|
2011-03-08 17:41:49 -05:00
|
|
|
|
|
|
|
tests('create') do
|
|
|
|
new_listener = { 'InstancePort' => 443, 'LoadBalancerPort' => 443, 'Protocol' => 'TCP'}
|
2011-05-04 18:29:07 -04:00
|
|
|
elb.listeners.create(:instance_port => 443, :lb_port => 443, :protocol => 'TCP')
|
|
|
|
returns(2) { elb.listeners.size }
|
|
|
|
returns(443) { elb.listeners.get(443).lb_port }
|
2011-03-08 17:41:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('destroy') do
|
2011-05-04 18:29:07 -04:00
|
|
|
elb.listeners.get(443).destroy
|
|
|
|
returns(nil) { elb.listeners.get(443) }
|
2011-03-08 17:41:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('policies') do
|
2011-05-02 18:17:19 -04:00
|
|
|
app_policy_id = 'my-app-policy'
|
|
|
|
|
|
|
|
tests 'are empty' do
|
|
|
|
returns([]) { elb.policies.to_a }
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('#all') do
|
|
|
|
returns([]) { elb.policies.all.to_a }
|
|
|
|
end
|
2011-03-08 17:41:49 -05:00
|
|
|
|
|
|
|
tests('create app policy') do
|
2011-05-02 18:17:19 -04:00
|
|
|
elb.policies.create(:id => app_policy_id, :cookie => 'my-app-cookie', :cookie_stickiness => :app)
|
|
|
|
returns(app_policy_id) { elb.policies.first.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('get policy') do
|
|
|
|
returns(app_policy_id) { elb.policies.get(app_policy_id).id }
|
2011-03-08 17:41:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('destroy app policy') do
|
2011-05-02 18:17:19 -04:00
|
|
|
elb.policies.first.destroy
|
|
|
|
returns([]) { elb.policies.to_a }
|
2011-03-08 17:41:49 -05:00
|
|
|
end
|
|
|
|
|
2011-05-02 18:17:19 -04:00
|
|
|
lb_policy_id = 'my-lb-policy'
|
2011-03-08 17:41:49 -05:00
|
|
|
tests('create lb policy') do
|
2011-05-02 18:17:19 -04:00
|
|
|
elb.policies.create(:id => lb_policy_id, :expiration => 600, :cookie_stickiness => :lb)
|
|
|
|
returns(lb_policy_id) { elb.policies.first.id }
|
2011-03-08 17:41:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('setting a listener policy') do
|
2011-05-02 18:17:19 -04:00
|
|
|
elb.set_listener_policy(80, lb_policy_id)
|
2011-05-04 18:29:07 -04:00
|
|
|
returns([lb_policy_id]) { elb.listeners.get(80).policy_names }
|
2011-03-08 17:41:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('unsetting a listener policy') do
|
|
|
|
elb.unset_listener_policy(80)
|
2011-05-04 18:29:07 -04:00
|
|
|
returns([]) { elb.listeners.get(80).policy_names }
|
2011-03-08 17:41:49 -05:00
|
|
|
end
|
2011-05-02 18:17:19 -04:00
|
|
|
|
|
|
|
tests('a malformed policy') do
|
|
|
|
raises(ArgumentError) { elb.policies.create(:id => 'foo', :cookie_stickiness => 'invalid stickiness') }
|
|
|
|
end
|
2011-03-08 17:41:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('destroy') do
|
|
|
|
elb.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|