diff --git a/bin/aws-ha-release.rb b/bin/aws-ha-release.rb index 11f2d6b..6de3663 100755 --- a/bin/aws-ha-release.rb +++ b/bin/aws-ha-release.rb @@ -3,6 +3,7 @@ begin require 'aws-sdk' require 'trollop' + require 'timeout' rescue LoadError => e puts "The #{e.message.split('-').last.strip} gem must be installed." raise diff --git a/lib/aws-missing-tools/aws-ha-release/aws-ha-release.rb b/lib/aws-missing-tools/aws-ha-release/aws-ha-release.rb index 98a3c9a..946853a 100755 --- a/lib/aws-missing-tools/aws-ha-release/aws-ha-release.rb +++ b/lib/aws-missing-tools/aws-ha-release/aws-ha-release.rb @@ -1,3 +1,5 @@ +require 'timeout' + class AwsHaRelease attr_reader :group @@ -13,6 +15,7 @@ class AwsHaRelease @max_size_change = 0 @inservice_polling_time = 10 + @opts = opts end def execute! @@ -26,13 +29,15 @@ class AwsHaRelease @group.update(desired_capacity: @group.desired_capacity + 1) @group.ec2_instances.each do |instance| - until all_instances_inservice?(@group.load_balancers) - sleep @inservice_polling_time - end + Timeout::timeout(@opts[:inservice_time_allowed]) do + until all_instances_inservice?(@group.load_balancers) + sleep @inservice_polling_time + end - deregister_instance instance, @group.load_balancers - sleep opts[:elb_timeout] - instance.terminate false + deregister_instance instance, @group.load_balancers + sleep @opts[:elb_timeout] + instance.terminate false + end end @group.update(desired_capacity: @group.desired_capacity - 1) diff --git a/spec/aws-missing-tools/aws-ha-release/aws-ha-release_spec.rb b/spec/aws-missing-tools/aws-ha-release/aws-ha-release_spec.rb index d77c132..3865459 100644 --- a/spec/aws-missing-tools/aws-ha-release/aws-ha-release_spec.rb +++ b/spec/aws-missing-tools/aws-ha-release/aws-ha-release_spec.rb @@ -6,7 +6,9 @@ describe 'aws-ha-release' do as_group_name: 'test_group', aws_access_key: 'testaccesskey', aws_secret_key: 'testsecretkey', - region: 'test-region' + region: 'test-region', + inservice_time_allowed: 300, + elb_timeout: 0 } end diff --git a/spec/support/fake_auto_scaling.rb b/spec/support/fake_auto_scaling.rb index 3eae479..92d42d8 100644 --- a/spec/support/fake_auto_scaling.rb +++ b/spec/support/fake_auto_scaling.rb @@ -48,7 +48,11 @@ module AWS end 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 diff --git a/spec/support/fake_ec2.rb b/spec/support/fake_ec2.rb index 8420241..65b57c2 100644 --- a/spec/support/fake_ec2.rb +++ b/spec/support/fake_ec2.rb @@ -6,6 +6,9 @@ module AWS class Instance def initialize end + + def terminate(decrement_desired_capacity) + end end end end diff --git a/spec/support/fake_elb.rb b/spec/support/fake_elb.rb index 6713c2c..466e266 100644 --- a/spec/support/fake_elb.rb +++ b/spec/support/fake_elb.rb @@ -12,6 +12,11 @@ module AWS end end + class LoadBalancerCollection < Array + def initialize + end + end + class InstanceCollection < Array def initialize end