From c493f2e188aadce72bf81c5440d17f177f792957 Mon Sep 17 00:00:00 2001 From: Anuj Biyani Date: Mon, 10 Jun 2013 14:04:15 -0700 Subject: [PATCH 1/7] use fake time instead of real time when measuring against inservice_time_allowed --- .../aws-ha-release/aws-ha-release.rb | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) 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 0996bce..1f6a028 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 @@ -97,33 +97,30 @@ module AwsMissingTools @group.auto_scaling_instances.each do |instance| time_taken = 0 - begin - Timeout::timeout(@opts[:inservice_time_allowed]) do + until all_instances_inservice_for_time_period?(@group.load_balancers, INSERVICE_POLLING_TIME) + puts "#{time_taken} seconds have elapsed while waiting for all instances to be InService for a minimum of #{@opts[:min_inservice_time]} seconds." - until all_instances_inservice_for_time_period?(@group.load_balancers, INSERVICE_POLLING_TIME) - puts "#{time_taken} seconds have elapsed while waiting for all instances to be InService for a minimum of #{@opts[:min_inservice_time]} seconds." + if time_taken >= @opts[:inservice_time_allowed] + puts "\nDuring the last #{time_taken} seconds, a new AutoScaling instance failed to become healthy." + puts "The following settings were changed and will not be changed back by this script:\n" - time_taken += INSERVICE_POLLING_TIME - sleep INSERVICE_POLLING_TIME + puts "AutoScaling processes #{PROCESSES_TO_SUSPEND} were suspended." + puts "The desired capacity was changed from #{@group.desired_capacity - 1} to #{@group.desired_capacity}." + + if @max_size_change > 0 + puts "The maximum size was changed from #{@group.max_size - @max_size_change} to #{@group.max_size}" end - puts "\nThe new instance was found to be healthy; one old instance will now be removed from the load balancers." - deregister_instance instance.ec2_instance, @group.load_balancers + raise + else + time_taken += INSERVICE_POLLING_TIME + sleep INSERVICE_POLLING_TIME end - rescue Timeout::Error => e - puts "\nDuring the last #{time_taken} seconds, a new AutoScaling instance failed to become healthy." - puts "The following settings were changed and will not be changed back by this script:\n" - - puts "AutoScaling processes #{PROCESSES_TO_SUSPEND} were suspended." - puts "The desired capacity was changed from #{@group.desired_capacity - 1} to #{@group.desired_capacity}." - - if @max_size_change > 0 - puts "The maximum size was changed from #{@group.max_size - @max_size_change} to #{@group.max_size}" - end - - raise end + puts "\nThe new instance was found to be healthy; one old instance will now be removed from the load balancers." + deregister_instance instance.ec2_instance, @group.load_balancers + puts "Sleeping for the ELB Timeout period of #{@opts[:elb_timeout]}" sleep @opts[:elb_timeout] From 8885c14fbe49183e7439633a4d5d3a0a2f9f679c Mon Sep 17 00:00:00 2001 From: Anuj Biyani Date: Mon, 10 Jun 2013 14:38:02 -0700 Subject: [PATCH 2/7] allow multiple new instances to be brought up simultaneously --- .../aws-ha-release/aws-ha-release.rb | 34 +++++++++++-------- .../aws-ha-release/aws-ha-release_spec.rb | 25 ++++++++++++++ 2 files changed, 44 insertions(+), 15 deletions(-) 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 1f6a028..7b608ee 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,4 +1,3 @@ -require 'timeout' require 'optparse' module AwsMissingTools @@ -31,7 +30,8 @@ module AwsMissingTools region: 'us-east-1', elb_timeout: 60, inservice_time_allowed: 300, - min_inservice_time: 30 + min_inservice_time: 30, + num_simultaneous_instances: 1 } OptionParser.new('Usage: aws-ha-release.rb -a [options]', 50) do |opts| @@ -62,6 +62,10 @@ module AwsMissingTools opts.on('-s', '--aws_secret_key AWS_SECRET_KEY', 'AWS Secret Key') do |v| options[:aws_secret_key] = v end + + opts.on('-n', '--num-simultaneous-instances NUM', 'Number of instances to simultaneously bring up per iteration') do |v| + options[:num_simultaneous_instances] = v.to_i + end end.parse!(arguments) raise OptionParser::MissingArgument, 'You must specify the AutoScaling Group Name: aws-ha-release.rb -a ' if options[:as_group_name].nil? @@ -86,15 +90,15 @@ module AwsMissingTools @group.suspend_processes PROCESSES_TO_SUSPEND if @group.max_size == @group.desired_capacity - puts "#{@group.name} has a max-size of #{@group.max_size}. In order to recycle instances max-size will be temporarily increased by 1." - @group.update(max_size: @group.max_size + 1) - @max_size_change = 1 + puts "#{@group.name} has a max-size of #{@group.max_size}. In order to recycle instances max-size will be temporarily increased by #{@opts[:num_simultaneous_instances]}." + @group.update(max_size: @group.max_size + @opts[:num_simultaneous_instances]) + @max_size_change = @opts[:num_simultaneous_instances] end - @group.update(desired_capacity: @group.desired_capacity + 1) + @group.update(desired_capacity: @group.desired_capacity + @opts[:num_simultaneous_instances]) puts "The list of instances in Auto Scaling Group #{@group.name} that will be terminated is:\n#{@group.auto_scaling_instances.map{ |i| i.ec2_instance.id }.to_ary}" - @group.auto_scaling_instances.each do |instance| + @group.auto_scaling_instances.each_slice(@opts[:num_simultaneous_instances]) do |instances| time_taken = 0 until all_instances_inservice_for_time_period?(@group.load_balancers, INSERVICE_POLLING_TIME) @@ -105,7 +109,7 @@ module AwsMissingTools puts "The following settings were changed and will not be changed back by this script:\n" puts "AutoScaling processes #{PROCESSES_TO_SUSPEND} were suspended." - puts "The desired capacity was changed from #{@group.desired_capacity - 1} to #{@group.desired_capacity}." + puts "The desired capacity was changed from #{@group.desired_capacity - @opts[:num_simultaneous_instances]} to #{@group.desired_capacity}." if @max_size_change > 0 puts "The maximum size was changed from #{@group.max_size - @max_size_change} to #{@group.max_size}" @@ -118,19 +122,19 @@ module AwsMissingTools end end - puts "\nThe new instance was found to be healthy; one old instance will now be removed from the load balancers." - deregister_instance instance.ec2_instance, @group.load_balancers + puts "\nThe new instance(s) was/were found to be healthy; #{@opts[:num_simultaneous_instances]} old instance(s) will now be removed from the load balancers." + instances.each { |instance| deregister_instance(instance.ec2_instance, @group.load_balancers) } puts "Sleeping for the ELB Timeout period of #{@opts[:elb_timeout]}" sleep @opts[:elb_timeout] - puts "\nInstance #{instance.id} will now be terminated. By terminating this instance, the actual capacity will be decreased to 1 under desired-capacity." - instance.terminate false + puts "\nInstance(s) #{instances.map{ |i| i.ec2_instance.id }.join(', ')} will now be terminated. By terminating this/these instance(s), the actual capacity will be decreased to #{@opts[:num_simultaneous_instances]} under desired-capacity." + instances.each { |instance| instance.terminate false } end - puts "\n#{@group.name} had its desired-capacity increased temporarily by 1 to a desired-capacity of #{@group.desired_capacity}." - puts "The desired-capacity of #{@group.name} will now be returned to its original desired-capacity of #{@group.desired_capacity - 1}." - @group.update(desired_capacity: @group.desired_capacity - 1) + puts "\n#{@group.name} had its desired-capacity increased temporarily by #{@opts[:num_simultaneous_instances]} to a desired-capacity of #{@group.desired_capacity}." + puts "The desired-capacity of #{@group.name} will now be returned to its original desired-capacity of #{@group.desired_capacity - @opts[:num_simultaneous_instances]}." + @group.update(desired_capacity: @group.desired_capacity - @opts[:num_simultaneous_instances]) if @max_size_change > 0 puts "\n#{@group.name} had its max_size increased temporarily by #{@max_size_change} to a max_size of #{@group.max_size}." 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 233e283..a404ae4 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 @@ -45,6 +45,7 @@ describe 'aws-ha-release' do expect(options[:aws_access_key]).not_to be_nil expect(options[:aws_secret_key]).not_to be_nil expect(options[:min_inservice_time]).not_to be_nil + expect(options[:num_simultaneous_instances]).not_to be_nil end context 'optional params' do @@ -80,6 +81,12 @@ describe 'aws-ha-release' do expect(AwsMissingTools::AwsHaRelease.parse_options(options)[:min_inservice_time]).to eq 30 end end + + it 'number of instances to simultaneously bring up' do + [%w(-a test_group -n 2), %w(-a test_group --num-simultaneous-instances 2)].each do |options| + expect(AwsMissingTools::AwsHaRelease.parse_options(options)[:num_simultaneous_instances]).to eq 2 + end + end end end @@ -116,6 +123,24 @@ describe 'aws-ha-release' do @aws_ha_release.group.should_receive(:update).with(desired_capacity: 1).ordered.and_call_original @aws_ha_release.execute! end + + it 'cycles more than one instance at a time if specified' do + @group.update(max_size: 2, desired_capacity: 2) + + aws_ha_release = AwsMissingTools::AwsHaRelease.new(%w(-a test_group --num-simultaneous-instances 2 -o testaccesskey -s testsecretkey -r test_region -i 1 -t 0 -m 5)) + aws_ha_release.stub!(:all_instances_inservice_for_time_period?).and_return(true) + + aws_ha_release.group.should_receive(:update).with(max_size: 4).ordered.and_call_original + aws_ha_release.group.should_receive(:update).with(desired_capacity: 4).ordered.and_call_original + + aws_ha_release.should_receive(:deregister_instance).twice.ordered.and_call_original + @group.auto_scaling_instances[0].should_receive(:terminate).ordered.and_call_original + @group.auto_scaling_instances[1].should_receive(:terminate).ordered.and_call_original + + aws_ha_release.group.should_receive(:update).with(desired_capacity: 2).ordered.and_call_original + aws_ha_release.group.should_receive(:update).with(max_size: 2).ordered.and_call_original + aws_ha_release.execute! + end end describe 'determining if instances are in service' do From d81c8679dd4411f93917faae0f5568c7d6936f96 Mon Sep 17 00:00:00 2001 From: Anuj Biyani Date: Mon, 10 Jun 2013 15:05:15 -0700 Subject: [PATCH 3/7] extract some logic into a more testable method --- .../aws-ha-release/aws-ha-release.rb | 16 ++++-- .../aws-ha-release/aws-ha-release_spec.rb | 51 ++++++++++++------- 2 files changed, 45 insertions(+), 22 deletions(-) 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 7b608ee..cc48c64 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 @@ -89,10 +89,10 @@ module AwsMissingTools @group.suspend_processes PROCESSES_TO_SUSPEND - if @group.max_size == @group.desired_capacity - puts "#{@group.name} has a max-size of #{@group.max_size}. In order to recycle instances max-size will be temporarily increased by #{@opts[:num_simultaneous_instances]}." - @group.update(max_size: @group.max_size + @opts[:num_simultaneous_instances]) - @max_size_change = @opts[:num_simultaneous_instances] + @max_size_change = determine_max_size_change + if @max_size_change > 0 + puts "#{@group.name} has a max-size of #{@group.max_size}. In order to recycle instances max-size will be temporarily increased by #{@max_size_change}." + @group.update(max_size: @group.max_size + @max_size_change) end @group.update(desired_capacity: @group.desired_capacity + @opts[:num_simultaneous_instances]) @@ -147,6 +147,14 @@ module AwsMissingTools @group.resume_all_processes end + def determine_max_size_change + if @group.max_size - @group.desired_capacity < @opts[:num_simultaneous_instances] + @group.desired_capacity + @opts[:num_simultaneous_instances] - @group.max_size + else + 0 + end + end + def deregister_instance(instance, load_balancers) load_balancers.each do |load_balancer| load_balancer.instances.deregister instance 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 a404ae4..04736b5 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 @@ -123,24 +123,6 @@ describe 'aws-ha-release' do @aws_ha_release.group.should_receive(:update).with(desired_capacity: 1).ordered.and_call_original @aws_ha_release.execute! end - - it 'cycles more than one instance at a time if specified' do - @group.update(max_size: 2, desired_capacity: 2) - - aws_ha_release = AwsMissingTools::AwsHaRelease.new(%w(-a test_group --num-simultaneous-instances 2 -o testaccesskey -s testsecretkey -r test_region -i 1 -t 0 -m 5)) - aws_ha_release.stub!(:all_instances_inservice_for_time_period?).and_return(true) - - aws_ha_release.group.should_receive(:update).with(max_size: 4).ordered.and_call_original - aws_ha_release.group.should_receive(:update).with(desired_capacity: 4).ordered.and_call_original - - aws_ha_release.should_receive(:deregister_instance).twice.ordered.and_call_original - @group.auto_scaling_instances[0].should_receive(:terminate).ordered.and_call_original - @group.auto_scaling_instances[1].should_receive(:terminate).ordered.and_call_original - - aws_ha_release.group.should_receive(:update).with(desired_capacity: 2).ordered.and_call_original - aws_ha_release.group.should_receive(:update).with(max_size: 2).ordered.and_call_original - aws_ha_release.execute! - end end describe 'determining if instances are in service' do @@ -289,4 +271,37 @@ describe 'aws-ha-release' do expect(elb_two.instances).not_to include instance_one end end + + describe '#determine_max_size_change' do + before do + @group = as.groups.create opts[1] + end + + it 'does not change the desired capacity by default' do + @group.update(max_size: 4, desired_capacity: 2) + aws_ha_release = AwsMissingTools::AwsHaRelease.new(opts) + + expect(aws_ha_release.determine_max_size_change).to eq 0 + end + + it 'adjusts the max size when it is equal to the desired capacity' do + @group.update(max_size: 2, desired_capacity: 2) + aws_ha_release = AwsMissingTools::AwsHaRelease.new(opts) + + expect(aws_ha_release.determine_max_size_change).to eq 1 + end + + it 'accounts for num_simultaneous_instances' do + @group.update(max_size: 2, desired_capacity: 2) + aws_ha_release = AwsMissingTools::AwsHaRelease.new(%w(-a test_group --num-simultaneous-instances 2 -o testaccesskey -s testsecretkey -r test_region -i 1 -t 0 -m 5)) + + expect(aws_ha_release.determine_max_size_change).to eq 2 + + @group.update(max_size: 3, desired_capacity: 2) + expect(aws_ha_release.determine_max_size_change).to eq 1 + + @group.update(max_size: 4, desired_capacity: 2) + expect(aws_ha_release.determine_max_size_change).to eq 0 + end + end end From 67a47cac28c1a416fbcd123ece23cab5c634211d Mon Sep 17 00:00:00 2001 From: Anuj Biyani Date: Tue, 21 Jan 2014 16:29:29 -0800 Subject: [PATCH 4/7] force group.auto_scaling_instances into a normal array --- .../aws-ha-release/aws-ha-release.rb | 2 +- spec/support/fake_auto_scaling.rb | 2 +- spec/support/fake_core_data_list.rb | 71 +++++++++++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 spec/support/fake_core_data_list.rb 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 cc48c64..b612984 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 @@ -98,7 +98,7 @@ module AwsMissingTools @group.update(desired_capacity: @group.desired_capacity + @opts[:num_simultaneous_instances]) puts "The list of instances in Auto Scaling Group #{@group.name} that will be terminated is:\n#{@group.auto_scaling_instances.map{ |i| i.ec2_instance.id }.to_ary}" - @group.auto_scaling_instances.each_slice(@opts[:num_simultaneous_instances]) do |instances| + @group.auto_scaling_instances.to_a.each_slice(@opts[:num_simultaneous_instances]) do |instances| time_taken = 0 until all_instances_inservice_for_time_period?(@group.load_balancers, INSERVICE_POLLING_TIME) diff --git a/spec/support/fake_auto_scaling.rb b/spec/support/fake_auto_scaling.rb index 6fe7aa1..30dcae6 100644 --- a/spec/support/fake_auto_scaling.rb +++ b/spec/support/fake_auto_scaling.rb @@ -48,7 +48,7 @@ module AWS end def auto_scaling_instances - @auto_scaling_instances ||= [AWS::FakeAutoScaling::Instance.new(self), AWS::FakeAutoScaling::Instance.new(self)] + @auto_scaling_instances ||= AWS::FakeCore::Data::List.new [AWS::FakeAutoScaling::Instance.new(self), AWS::FakeAutoScaling::Instance.new(self)] end def load_balancers diff --git a/spec/support/fake_core_data_list.rb b/spec/support/fake_core_data_list.rb new file mode 100644 index 0000000..e23c996 --- /dev/null +++ b/spec/support/fake_core_data_list.rb @@ -0,0 +1,71 @@ +module AWS + module FakeCore + class Data + module MethodMissingProxy + + protected + + def method_missing *args, &block + if block_given? + return_value = @data.send(*args) do |*values| + yield(*values.flatten.map{|v| Data.cast(v) }) + end + Data.cast(return_value) + else + Data.cast(@data.send(*args)) + end + end + + end + + include MethodMissingProxy + + def method_missing method_name, *args, &block + if + args.empty? and !block_given? and + key = _remove_question_mark(method_name) and + @data.has_key?(key) + then + Data.cast(@data[key]) + else + super + end + end + + class << self + + # Given a hash, this method returns a {Data} object. Given + # an Array, this method returns a {Data::List} object. Everything + # else is returned as is. + # + # @param [Object] value The value to conditionally wrap. + # + # @return [Data,Data::List,Object] Wraps hashes and lists with + # Data and List objects, all other objects are returned as + # is. + # + def cast value + case value + when Hash then Data.new(value) + when Array then Data::List.new(value) + else value + end + end + + end + + class List + include MethodMissingProxy + + def initialize(array) + @data = array + end + + def to_ary + @data + end + alias_method :to_a, :to_ary + end + end + end +end From 2656707483b9c9d46bd95d334630b23a3b7d0a50 Mon Sep 17 00:00:00 2001 From: Anuj Biyani Date: Tue, 21 Jan 2014 16:29:46 -0800 Subject: [PATCH 5/7] be a bit more strict for gem dependencies --- Gemfile.lock | 4 ++-- aws-missing-tools.gemspec | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index bad00f3..f1d00ba 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ PATH remote: . specs: aws-missing-tools (0.0.1) - aws-sdk + aws-sdk (~> 1.11) GEM remote: https://rubygems.org/ @@ -29,4 +29,4 @@ PLATFORMS DEPENDENCIES aws-missing-tools! - rspec + rspec (~> 2.12) diff --git a/aws-missing-tools.gemspec b/aws-missing-tools.gemspec index f7901d2..b7e5352 100644 --- a/aws-missing-tools.gemspec +++ b/aws-missing-tools.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |gem| gem.require_paths = %w(lib) gem.version = AwsMissingTools::VERSION - gem.add_dependency 'aws-sdk' + gem.add_dependency 'aws-sdk', '~> 1.11' - gem.add_development_dependency 'rspec' + gem.add_development_dependency 'rspec', '~> 2.12' end From 03b826dbe1a2e407dfe8190371dd6e01af6c0650 Mon Sep 17 00:00:00 2001 From: Anuj Biyani Date: Tue, 21 Jan 2014 16:32:09 -0800 Subject: [PATCH 6/7] rename the executable so it doesn't have an extension --- bin/{aws-ha-release.rb => aws-ha-release} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bin/{aws-ha-release.rb => aws-ha-release} (100%) diff --git a/bin/aws-ha-release.rb b/bin/aws-ha-release similarity index 100% rename from bin/aws-ha-release.rb rename to bin/aws-ha-release From 6cc88eb9aa7b0ba8896df2ddada2136588a2c4f1 Mon Sep 17 00:00:00 2001 From: Anuj Biyani Date: Wed, 22 Jan 2014 11:34:39 -0800 Subject: [PATCH 7/7] add a MAX keyword to simply bring up as many instances as are already running --- .../aws-ha-release/aws-ha-release.rb | 5 +++- .../aws-ha-release/aws-ha-release_spec.rb | 30 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) 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 b612984..a436dbf 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 @@ -21,6 +21,8 @@ module AwsMissingTools raise ArgumentError, "The Auto Scaling Group named #{@opts[:as_group_name]} does not exist in #{@opts[:region]}." end + @opts[:num_simultaneous_instances] = Integer(@opts[:num_simultaneous_instances]) rescue @group.auto_scaling_instances.count + @max_size_change = 0 @time_spent_inservice = 0 end @@ -64,7 +66,7 @@ module AwsMissingTools end opts.on('-n', '--num-simultaneous-instances NUM', 'Number of instances to simultaneously bring up per iteration') do |v| - options[:num_simultaneous_instances] = v.to_i + options[:num_simultaneous_instances] = v end end.parse!(arguments) @@ -98,6 +100,7 @@ module AwsMissingTools @group.update(desired_capacity: @group.desired_capacity + @opts[:num_simultaneous_instances]) puts "The list of instances in Auto Scaling Group #{@group.name} that will be terminated is:\n#{@group.auto_scaling_instances.map{ |i| i.ec2_instance.id }.to_ary}" + puts "The number of instances that will be brought up simultaneously is: #{@opts[:num_simultaneous_instances]}" @group.auto_scaling_instances.to_a.each_slice(@opts[:num_simultaneous_instances]) do |instances| time_taken = 0 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 04736b5..94e1be1 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 @@ -28,6 +28,22 @@ describe 'aws-ha-release' do AwsMissingTools::AwsHaRelease.new(opts) }.should raise_error end + + context 'number of simultaneous instances' do + before do + as.groups.create opts[1] + opts.push('--num-simultaneous-instances') + end + it 'with MAX, sets the option to the number of active instances' do + opts.push('MAX') + expect(AwsMissingTools::AwsHaRelease.new(opts).instance_variable_get('@opts')[:num_simultaneous_instances]).to eq 2 + end + + it 'with an integer, sets the option to that integer' do + opts.push('1') + expect(AwsMissingTools::AwsHaRelease.new(opts).instance_variable_get('@opts')[:num_simultaneous_instances]).to eq 1 + end + end end describe '#parse_options' do @@ -82,9 +98,17 @@ describe 'aws-ha-release' do end end - it 'number of instances to simultaneously bring up' do - [%w(-a test_group -n 2), %w(-a test_group --num-simultaneous-instances 2)].each do |options| - expect(AwsMissingTools::AwsHaRelease.parse_options(options)[:num_simultaneous_instances]).to eq 2 + context 'number of instances to simultaneously bring up' do + it 'recognizes integer inputs' do + [%w(-a test_group -n 2), %w(-a test_group --num-simultaneous-instances 2)].each do |options| + expect(AwsMissingTools::AwsHaRelease.parse_options(options)[:num_simultaneous_instances]).to eq '2' + end + end + + it 'recognizes the MAX keyword' do + [%w(-a test_group -n MAX), %w(-a test_group --num-simultaneous-instances MAX)].each do |options| + expect(AwsMissingTools::AwsHaRelease.parse_options(options)[:num_simultaneous_instances]).to eq 'MAX' + end end end end