loop through each instance, wait for a new one to come up, then deregister and terminate the old one
This commit is contained in:
parent
9273f748c2
commit
b463901f98
|
@ -12,6 +12,7 @@ class AwsHaRelease
|
||||||
end
|
end
|
||||||
|
|
||||||
@max_size_change = 0
|
@max_size_change = 0
|
||||||
|
@inservice_polling_time = 10
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute!
|
def execute!
|
||||||
|
@ -23,6 +24,30 @@ class AwsHaRelease
|
||||||
end
|
end
|
||||||
|
|
||||||
@group.update(desired_capacity: @group.desired_capacity + 1)
|
@group.update(desired_capacity: @group.desired_capacity + 1)
|
||||||
|
|
||||||
|
@group.ec2_instances.each do |instance|
|
||||||
|
until all_instances_inservice?(@group.load_balancers)
|
||||||
|
sleep @inservice_polling_time
|
||||||
|
end
|
||||||
|
|
||||||
|
deregister_instance instance, @group.load_balancers
|
||||||
|
sleep opts[:elb_timeout]
|
||||||
|
instance.terminate false
|
||||||
|
end
|
||||||
|
|
||||||
|
@group.update(desired_capacity: @group.desired_capacity - 1)
|
||||||
|
|
||||||
|
if @max_size_change > 0
|
||||||
|
@group.update(max_size: @group.max_size - @max_size_change)
|
||||||
|
end
|
||||||
|
|
||||||
|
@group.resume_all_processes
|
||||||
|
end
|
||||||
|
|
||||||
|
def deregister_instance(instance, load_balancers)
|
||||||
|
load_balancers.each do |load_balancer|
|
||||||
|
load_balancer.instances.deregister instance
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def instances_inservice?(load_balancer)
|
def instances_inservice?(load_balancer)
|
||||||
|
|
|
@ -13,7 +13,6 @@ describe 'aws-ha-release' do
|
||||||
let(:as) { AWS::FakeAutoScaling.new }
|
let(:as) { AWS::FakeAutoScaling.new }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
AWS.stub(:config)
|
|
||||||
AWS::AutoScaling.stub(:new).and_return(as)
|
AWS::AutoScaling.stub(:new).and_return(as)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -101,4 +100,30 @@ describe 'aws-ha-release' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#deregister_instance' do
|
||||||
|
before do
|
||||||
|
@group = as.groups.create opts[:as_group_name]
|
||||||
|
@aws_ha_release = AwsHaRelease.new(opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'deregisters an instance across all load balancers' do
|
||||||
|
instance_one = AWS::FakeEC2::Instance.new
|
||||||
|
instance_two = AWS::FakeEC2::Instance.new
|
||||||
|
|
||||||
|
elb_one = AWS::FakeELB::LoadBalancer.new 'test_load_balancer_01'
|
||||||
|
elb_two = AWS::FakeELB::LoadBalancer.new 'test_load_balancer_02'
|
||||||
|
|
||||||
|
elb_one.instances.register instance_one
|
||||||
|
elb_one.instances.register instance_two
|
||||||
|
|
||||||
|
elb_two.instances.register instance_one
|
||||||
|
elb_two.instances.register instance_two
|
||||||
|
|
||||||
|
@aws_ha_release.deregister_instance instance_one, [elb_one, elb_two]
|
||||||
|
|
||||||
|
expect(elb_one.instances).not_to include instance_one
|
||||||
|
expect(elb_two.instances).not_to include instance_one
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,4 +5,8 @@ Dir['spec/support/**/*.rb'].each { |f| require File.expand_path(f) }
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.order = 'random'
|
config.order = 'random'
|
||||||
|
|
||||||
|
config.before do
|
||||||
|
AWS.stub!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -42,6 +42,10 @@ module AWS
|
||||||
self.instance_variable_set "@#{key}", value
|
self.instance_variable_set "@#{key}", value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ec2_instances
|
||||||
|
[]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,10 +12,20 @@ module AWS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class InstanceCollection
|
class InstanceCollection < Array
|
||||||
def initialize
|
def initialize
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def register(*instances)
|
||||||
|
self.concat instances
|
||||||
|
end
|
||||||
|
|
||||||
|
def deregister(*instances)
|
||||||
|
instances.each do |i|
|
||||||
|
self.delete i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def health
|
def health
|
||||||
@health ||= [
|
@health ||= [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user