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 4827ac5..d104d4b 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,6 @@ class AwsHaRelease + attr_reader :max_size_change + def initialize(opts) AWS.config(access_key_id: opts[:aws_access_key], secret_access_key: opts[:aws_secret_key], region: opts[:region]) @@ -8,9 +10,16 @@ class AwsHaRelease if @group.nil? raise ArgumentError, "The Auto Scaling Group named #{opts[:as_group_name]} does not exist in #{opts[:region]}." end + + @max_size_change = 0 end def execute! @group.suspend_processes 'ReplaceUnhealthy', 'AlarmNotification', 'ScheduledActions', 'AZRebalance' + + if @group.max_size == @group.desired_capacity + @group.update(max_size: @group.max_size + 1) + @max_size_change += 1 + end end end 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 1473900..4cc7663 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 @@ -34,7 +34,7 @@ describe 'aws-ha-release' do describe '#execute!' do before do - as.groups.create opts[:as_group_name] + @group = as.groups.create opts[:as_group_name] @aws_ha_release = AwsHaRelease.new(opts) end @@ -43,5 +43,15 @@ describe 'aws-ha-release' do .with('ReplaceUnhealthy', 'AlarmNotification', 'ScheduledActions', 'AZRebalance') @aws_ha_release.execute! end + + it 'adjusts the maximum size if the desired capacity is equal to it' do + @group.update(max_size: 1, desired_capacity: 1) + expect(@aws_ha_release.max_size_change).to eq 0 + + AWS::FakeAutoScaling::Group.any_instance.should_receive(:update).with({ max_size: 2 }) + @aws_ha_release.execute! + + expect(@aws_ha_release.max_size_change).to eq 1 + end end end diff --git a/spec/support/fake_auto_scaling.rb b/spec/support/fake_auto_scaling.rb index aad62e0..460b772 100644 --- a/spec/support/fake_auto_scaling.rb +++ b/spec/support/fake_auto_scaling.rb @@ -22,11 +22,13 @@ module AWS end class Group - attr_reader :name + attr_reader :name, :max_size, :desired_capacity def initialize(name) @name = name @suspended_processes = {} + @max_size = 2 + @desired_capacity = 1 end def suspend_processes(*processes) @@ -34,6 +36,12 @@ module AWS @suspended_processes[process] = 'test' end end + + def update(options = {}) + options.each do |key, value| + self.instance_variable_set "@#{key}", value + end + end end end end