2011-03-08 17:41:49 -05:00
|
|
|
Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
|
2011-07-08 14:37:57 -04:00
|
|
|
@availability_zones = Fog::Compute[:aws].describe_availability_zones('state' => 'available').body['availabilityZoneInfo'].collect{ |az| az['zoneName'] }
|
2011-07-18 20:53:32 -04:00
|
|
|
@key_name = 'fog-test-model'
|
2011-03-08 17:41:49 -05:00
|
|
|
|
|
|
|
tests('success') do
|
|
|
|
tests('load_balancers') do
|
|
|
|
tests('getting a missing elb') do
|
2011-09-15 09:01:03 -04:00
|
|
|
returns(nil) { Fog::AWS[:elb].load_balancers.get('no-such-elb') }
|
2011-03-08 17:41:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-14 21:25:02 -04:00
|
|
|
tests('listeners') do
|
|
|
|
tests("default attributes") do
|
2011-09-15 09:01:03 -04:00
|
|
|
listener = Fog::AWS[:elb].listeners.new
|
2011-07-14 21:25:02 -04:00
|
|
|
tests('instance_port is 80').returns(80) { listener.instance_port }
|
|
|
|
tests('lb_port is 80').returns(80) { listener.lb_port }
|
|
|
|
tests('protocol is HTTP').returns('HTTP') { listener.protocol }
|
|
|
|
tests('policy_names is empty').returns([]) { listener.policy_names }
|
|
|
|
end
|
|
|
|
|
|
|
|
tests("specifying attributes") do
|
|
|
|
attributes = {:instance_port => 2000, :lb_port => 2001, :protocol => 'SSL', :policy_names => ['fake'] }
|
2011-09-15 09:01:03 -04:00
|
|
|
listener = Fog::AWS[:elb].listeners.new(attributes)
|
2011-07-14 21:25:02 -04:00
|
|
|
tests('instance_port is 2000').returns(2000) { listener.instance_port }
|
|
|
|
tests('lb_port is 2001').returns(2001) { listener.lb_port }
|
|
|
|
tests('protocol is SSL').returns('SSL') { listener.protocol }
|
|
|
|
tests('policy_names is [ fake ]').returns(['fake']) { listener.policy_names }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-08 17:41:49 -05:00
|
|
|
elb = nil
|
|
|
|
elb_id = 'fog-test'
|
|
|
|
|
|
|
|
tests('create') do
|
2011-07-14 22:18:47 -04:00
|
|
|
tests('without availability zones') do
|
2011-10-25 16:56:30 -04:00
|
|
|
elb = Fog::AWS[:elb].load_balancers.create(:id => elb_id, :availability_zones => @availability_zones)
|
2011-07-18 20:53:32 -04:00
|
|
|
tests("availability zones are correct").returns(@availability_zones.sort) { elb.availability_zones.sort }
|
2011-07-14 22:18:47 -04:00
|
|
|
tests("dns names is set").returns(true) { elb.dns_name.is_a?(String) }
|
|
|
|
tests("created_at is set").returns(true) { Time === elb.created_at }
|
|
|
|
tests("policies is empty").returns([]) { elb.policies }
|
|
|
|
tests("default listener") do
|
|
|
|
tests("1 listener").returns(1) { elb.listeners.size }
|
2011-09-15 09:01:03 -04:00
|
|
|
tests("params").returns(Fog::AWS[:elb].listeners.new.to_params) { elb.listeners.first.to_params }
|
2011-07-14 22:18:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('with availability zones') do
|
|
|
|
azs = @availability_zones[1..-1]
|
2011-09-15 09:01:03 -04:00
|
|
|
elb2 = Fog::AWS[:elb].load_balancers.create(:id => "#{elb_id}-2", :availability_zones => azs)
|
2011-07-18 20:53:32 -04:00
|
|
|
tests("availability zones are correct").returns(azs.sort) { elb2.availability_zones.sort }
|
2011-07-14 22:18:47 -04:00
|
|
|
elb2.destroy
|
|
|
|
end
|
2011-07-15 20:22:34 -04:00
|
|
|
|
2011-07-18 20:53:32 -04:00
|
|
|
# Need to sleep here for IAM changes to propgate
|
2011-07-15 20:22:34 -04:00
|
|
|
tests('with ListenerDescriptions') do
|
2011-09-15 09:01:03 -04:00
|
|
|
@certificate = Fog::AWS[:iam].upload_server_certificate(AWS::IAM::SERVER_CERT_PUBLIC_KEY, AWS::IAM::SERVER_CERT_PRIVATE_KEY, @key_name).body['Certificate']
|
2011-11-08 15:19:09 -05:00
|
|
|
sleep(10) unless Fog.mocking?
|
2011-07-15 20:22:34 -04:00
|
|
|
listeners = [{
|
2011-07-18 20:53:32 -04:00
|
|
|
'Listener' => {
|
|
|
|
'LoadBalancerPort' => 2030, 'InstancePort' => 2030, 'Protocol' => 'HTTP'
|
|
|
|
},
|
2011-07-15 20:22:34 -04:00
|
|
|
'PolicyNames' => []
|
|
|
|
}, {
|
2011-07-18 20:53:32 -04:00
|
|
|
'Listener' => {
|
|
|
|
'LoadBalancerPort' => 443, 'InstancePort' => 443, 'Protocol' => 'HTTPS',
|
|
|
|
'SSLCertificateId' => @certificate['Arn']
|
|
|
|
},
|
2011-07-15 20:22:34 -04:00
|
|
|
'PolicyNames' => []
|
|
|
|
}]
|
2011-10-25 16:56:30 -04:00
|
|
|
elb3 = Fog::AWS[:elb].load_balancers.create(:id => "#{elb_id}-3", 'ListenerDescriptions' => listeners, :availability_zones => @availability_zones)
|
2011-07-15 20:22:34 -04:00
|
|
|
tests('there are 2 listeners').returns(2) { elb3.listeners.count }
|
|
|
|
tests('instance_port is 2030').returns(2030) { elb3.listeners.first.instance_port }
|
|
|
|
tests('lb_port is 2030').returns(2030) { elb3.listeners.first.lb_port }
|
|
|
|
tests('protocol is HTTP').returns('HTTP') { elb3.listeners.first.protocol }
|
|
|
|
tests('protocol is HTTPS').returns('HTTPS') { elb3.listeners.last.protocol }
|
|
|
|
elb3.destroy
|
|
|
|
end
|
2011-07-18 20:53:32 -04:00
|
|
|
|
|
|
|
tests('with invalid Server Cert ARN').raises(Fog::AWS::IAM::NotFound) do
|
|
|
|
listeners = [{
|
|
|
|
'Listener' => {
|
|
|
|
'LoadBalancerPort' => 443, 'InstancePort' => 80, 'Protocol' => 'HTTPS', "SSLCertificateId" => "fakecert"}
|
|
|
|
}]
|
2011-10-25 16:56:30 -04:00
|
|
|
Fog::AWS[:elb].load_balancers.create(:id => "#{elb_id}-4", "ListenerDescriptions" => listeners, :availability_zones => @availability_zones)
|
2011-07-18 20:53:32 -04:00
|
|
|
end
|
2011-03-08 17:41:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('all') do
|
2011-09-15 09:01:03 -04:00
|
|
|
elb_ids = Fog::AWS[:elb].load_balancers.all.map{|e| e.id}
|
2011-03-08 17:41:49 -05:00
|
|
|
tests("contains elb").returns(true) { elb_ids.include? elb_id }
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('get') do
|
2011-09-15 09:01:03 -04:00
|
|
|
elb_get = Fog::AWS[:elb].load_balancers.get(elb_id)
|
2011-07-14 22:18:47 -04:00
|
|
|
tests('ids match').returns(elb_id) { elb_get.id }
|
2011-03-08 17:41:49 -05:00
|
|
|
end
|
|
|
|
|
2011-07-14 22:22:25 -04:00
|
|
|
tests('creating a duplicate elb') do
|
2011-03-08 17:41:49 -05:00
|
|
|
raises(Fog::AWS::ELB::IdentifierTaken) do
|
2011-09-15 09:01:03 -04:00
|
|
|
Fog::AWS[:elb].load_balancers.create(:id => elb_id, :availability_zones => ['us-east-1d'])
|
2011-03-08 17:41:49 -05:00
|
|
|
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-07-07 17:53:10 -04:00
|
|
|
server = Fog::Compute[:aws].servers.create
|
2011-09-22 20:59:11 -04:00
|
|
|
server.wait_for { ready? }
|
|
|
|
|
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
|
2011-07-08 14:37:57 -04:00
|
|
|
elb.disable_availability_zones(@availability_zones[1..-1])
|
|
|
|
returns(@availability_zones[0..0]) { elb.availability_zones.sort }
|
2011-03-08 17:41:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('enable_availability_zones') do
|
2011-07-08 14:37:57 -04:00
|
|
|
elb.enable_availability_zones(@availability_zones[1..-1])
|
|
|
|
returns(@availability_zones) { elb.availability_zones.sort }
|
2011-03-08 17:41:49 -05:00
|
|
|
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
|
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
|
2011-07-18 20:53:32 -04:00
|
|
|
|
2011-09-15 09:01:03 -04:00
|
|
|
Fog::AWS[:iam].delete_server_certificate(@key_name)
|
2011-03-08 17:41:49 -05:00
|
|
|
end
|
|
|
|
end
|