update max size if equal to desired capacity
This commit is contained in:
parent
6f74b5c511
commit
67c907aa04
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user