update max size if equal to desired capacity

This commit is contained in:
Anuj Biyani 2013-05-31 15:16:41 -07:00
parent 6f74b5c511
commit 67c907aa04
3 changed files with 29 additions and 2 deletions

View File

@ -1,4 +1,6 @@
class AwsHaRelease class AwsHaRelease
attr_reader :max_size_change
def initialize(opts) def initialize(opts)
AWS.config(access_key_id: opts[:aws_access_key], secret_access_key: opts[:aws_secret_key], region: opts[:region]) 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? if @group.nil?
raise ArgumentError, "The Auto Scaling Group named #{opts[:as_group_name]} does not exist in #{opts[:region]}." raise ArgumentError, "The Auto Scaling Group named #{opts[:as_group_name]} does not exist in #{opts[:region]}."
end end
@max_size_change = 0
end end
def execute! def execute!
@group.suspend_processes 'ReplaceUnhealthy', 'AlarmNotification', 'ScheduledActions', 'AZRebalance' @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
end end

View File

@ -34,7 +34,7 @@ describe 'aws-ha-release' do
describe '#execute!' do describe '#execute!' do
before do before do
as.groups.create opts[:as_group_name] @group = as.groups.create opts[:as_group_name]
@aws_ha_release = AwsHaRelease.new(opts) @aws_ha_release = AwsHaRelease.new(opts)
end end
@ -43,5 +43,15 @@ describe 'aws-ha-release' do
.with('ReplaceUnhealthy', 'AlarmNotification', 'ScheduledActions', 'AZRebalance') .with('ReplaceUnhealthy', 'AlarmNotification', 'ScheduledActions', 'AZRebalance')
@aws_ha_release.execute! @aws_ha_release.execute!
end 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
end end

View File

@ -22,11 +22,13 @@ module AWS
end end
class Group class Group
attr_reader :name attr_reader :name, :max_size, :desired_capacity
def initialize(name) def initialize(name)
@name = name @name = name
@suspended_processes = {} @suspended_processes = {}
@max_size = 2
@desired_capacity = 1
end end
def suspend_processes(*processes) def suspend_processes(*processes)
@ -34,6 +36,12 @@ module AWS
@suspended_processes[process] = 'test' @suspended_processes[process] = 'test'
end end
end end
def update(options = {})
options.each do |key, value|
self.instance_variable_set "@#{key}", value
end
end
end end
end end
end end