timeout if cycling a server takes longer than inservice_time_allowed
This commit is contained in:
		
							parent
							
								
									55e60a989e
								
							
						
					
					
						commit
						07fc0390f7
					
				@ -3,6 +3,7 @@
 | 
				
			|||||||
begin
 | 
					begin
 | 
				
			||||||
  require 'aws-sdk'
 | 
					  require 'aws-sdk'
 | 
				
			||||||
  require 'trollop'
 | 
					  require 'trollop'
 | 
				
			||||||
 | 
					  require 'timeout'
 | 
				
			||||||
rescue LoadError => e
 | 
					rescue LoadError => e
 | 
				
			||||||
  puts "The #{e.message.split('-').last.strip} gem must be installed."
 | 
					  puts "The #{e.message.split('-').last.strip} gem must be installed."
 | 
				
			||||||
  raise
 | 
					  raise
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +1,5 @@
 | 
				
			|||||||
 | 
					require 'timeout'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AwsHaRelease
 | 
					class AwsHaRelease
 | 
				
			||||||
  attr_reader :group
 | 
					  attr_reader :group
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -13,6 +15,7 @@ class AwsHaRelease
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @max_size_change = 0
 | 
					    @max_size_change = 0
 | 
				
			||||||
    @inservice_polling_time = 10
 | 
					    @inservice_polling_time = 10
 | 
				
			||||||
 | 
					    @opts = opts
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def execute!
 | 
					  def execute!
 | 
				
			||||||
@ -26,13 +29,15 @@ class AwsHaRelease
 | 
				
			|||||||
    @group.update(desired_capacity: @group.desired_capacity + 1)
 | 
					    @group.update(desired_capacity: @group.desired_capacity + 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @group.ec2_instances.each do |instance|
 | 
					    @group.ec2_instances.each do |instance|
 | 
				
			||||||
      until all_instances_inservice?(@group.load_balancers)
 | 
					      Timeout::timeout(@opts[:inservice_time_allowed]) do
 | 
				
			||||||
        sleep @inservice_polling_time
 | 
					        until all_instances_inservice?(@group.load_balancers)
 | 
				
			||||||
      end
 | 
					          sleep @inservice_polling_time
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      deregister_instance instance, @group.load_balancers
 | 
					        deregister_instance instance, @group.load_balancers
 | 
				
			||||||
      sleep opts[:elb_timeout]
 | 
					        sleep @opts[:elb_timeout]
 | 
				
			||||||
      instance.terminate false
 | 
					        instance.terminate false
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @group.update(desired_capacity: @group.desired_capacity - 1)
 | 
					    @group.update(desired_capacity: @group.desired_capacity - 1)
 | 
				
			||||||
 | 
				
			|||||||
@ -6,7 +6,9 @@ describe 'aws-ha-release' do
 | 
				
			|||||||
      as_group_name: 'test_group',
 | 
					      as_group_name: 'test_group',
 | 
				
			||||||
      aws_access_key: 'testaccesskey',
 | 
					      aws_access_key: 'testaccesskey',
 | 
				
			||||||
      aws_secret_key: 'testsecretkey',
 | 
					      aws_secret_key: 'testsecretkey',
 | 
				
			||||||
      region: 'test-region'
 | 
					      region: 'test-region',
 | 
				
			||||||
 | 
					      inservice_time_allowed: 300,
 | 
				
			||||||
 | 
					      elb_timeout: 0
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -48,7 +48,11 @@ module AWS
 | 
				
			|||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      def ec2_instances
 | 
					      def ec2_instances
 | 
				
			||||||
        []
 | 
					        @ec2_instances ||= [AWS::FakeEC2::Instance.new, AWS::FakeEC2::Instance.new]
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      def load_balancers
 | 
				
			||||||
 | 
					        @load_balancers ||= AWS::FakeELB::LoadBalancerCollection.new
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
				
			|||||||
@ -6,6 +6,9 @@ module AWS
 | 
				
			|||||||
    class Instance
 | 
					    class Instance
 | 
				
			||||||
      def initialize
 | 
					      def initialize
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      def terminate(decrement_desired_capacity)
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -12,6 +12,11 @@ module AWS
 | 
				
			|||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class LoadBalancerCollection < Array
 | 
				
			||||||
 | 
					      def initialize
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    class InstanceCollection < Array
 | 
					    class InstanceCollection < Array
 | 
				
			||||||
      def initialize
 | 
					      def initialize
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user