2011-07-28 14:37:21 -04:00
|
|
|
module Shindo
|
|
|
|
class Tests
|
2013-01-10 16:48:30 -05:00
|
|
|
|
2011-07-28 14:37:21 -04:00
|
|
|
def given_a_load_balancer_service(&block)
|
2011-08-04 17:21:22 -04:00
|
|
|
@service = Fog::Rackspace::LoadBalancers.new
|
2011-07-28 14:37:21 -04:00
|
|
|
instance_eval(&block)
|
|
|
|
end
|
2013-01-10 16:48:30 -05:00
|
|
|
|
2011-07-28 14:37:21 -04:00
|
|
|
def given_a_load_balancer(&block)
|
|
|
|
@lb = @service.load_balancers.create({
|
|
|
|
:name => ('fog' + Time.now.to_i.to_s),
|
|
|
|
:protocol => 'HTTP',
|
|
|
|
:port => 80,
|
|
|
|
:virtual_ips => [{ :type => 'PUBLIC'}],
|
2012-05-15 17:38:45 -04:00
|
|
|
:nodes => [{ :address => '1.1.1.1', :port => 80, :condition => 'ENABLED'}]
|
2011-07-28 14:37:21 -04:00
|
|
|
})
|
|
|
|
@lb.wait_for { ready? }
|
|
|
|
begin
|
|
|
|
instance_eval(&block)
|
|
|
|
ensure
|
|
|
|
@lb.wait_for { ready? }
|
|
|
|
@lb.destroy
|
|
|
|
end
|
|
|
|
end
|
2013-01-10 16:48:30 -05:00
|
|
|
|
|
|
|
def wait_for_server_state(service, server_id, state, error_states=nil)
|
|
|
|
current_state = nil
|
|
|
|
until current_state == state
|
|
|
|
current_state = service.get_server(server_id).body['server']['status']
|
|
|
|
if error_states
|
2013-01-14 09:36:21 -05:00
|
|
|
error_states = Array(error_states)
|
|
|
|
raise "ERROR! Server should have transitioned to '#{state}' not '#{current_state}'" if error_states.include?(current_state)
|
2013-01-10 16:48:30 -05:00
|
|
|
end
|
2013-01-14 12:28:59 -05:00
|
|
|
sleep 10 unless Fog.mocking?
|
2013-01-10 16:48:30 -05:00
|
|
|
end
|
2013-01-14 12:28:59 -05:00
|
|
|
sleep 30 unless Fog.mocking?
|
2013-01-10 16:48:30 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2011-07-28 14:37:21 -04:00
|
|
|
end
|