From 6cc88eb9aa7b0ba8896df2ddada2136588a2c4f1 Mon Sep 17 00:00:00 2001 From: Anuj Biyani Date: Wed, 22 Jan 2014 11:34:39 -0800 Subject: [PATCH] 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