diff --git a/bin/aws-ha-release.rb b/bin/aws-ha-release.rb index 4f6539a..11f2d6b 100755 --- a/bin/aws-ha-release.rb +++ b/bin/aws-ha-release.rb @@ -27,4 +27,4 @@ if opts[:aws_access_key].nil? || opts[:aws_secret_key].nil? end require 'aws-missing-tools' -AwsHaRelease.new(opts) +AwsHaRelease.new(opts).execute! 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 39c47b7..4827ac5 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 @@ -9,4 +9,8 @@ class AwsHaRelease raise ArgumentError, "The Auto Scaling Group named #{opts[:as_group_name]} does not exist in #{opts[:region]}." end end + + def execute! + @group.suspend_processes 'ReplaceUnhealthy', 'AlarmNotification', 'ScheduledActions', 'AZRebalance' + 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 4a05871..1473900 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 @@ -19,7 +19,7 @@ describe 'aws-ha-release' do describe '#initialize' do it 'initializes the AWS connection' do - as.groups.create 'test_group' + as.groups.create opts[:as_group_name] AWS.should_receive(:config).with(access_key_id: 'testaccesskey', secret_access_key: 'testsecretkey', region: 'test-region') AwsHaRelease.new(opts) @@ -31,4 +31,17 @@ describe 'aws-ha-release' do }.should raise_error end end + + describe '#execute!' do + before do + as.groups.create opts[:as_group_name] + @aws_ha_release = AwsHaRelease.new(opts) + end + + it 'suspends certain autoscaling processes' do + AWS::FakeAutoScaling::Group.any_instance.should_receive(:suspend_processes) + .with('ReplaceUnhealthy', 'AlarmNotification', 'ScheduledActions', 'AZRebalance') + @aws_ha_release.execute! + end + end end diff --git a/spec/support/fake_auto_scaling.rb b/spec/support/fake_auto_scaling.rb index d1ef401..aad62e0 100644 --- a/spec/support/fake_auto_scaling.rb +++ b/spec/support/fake_auto_scaling.rb @@ -26,6 +26,13 @@ module AWS def initialize(name) @name = name + @suspended_processes = {} + end + + def suspend_processes(*processes) + processes.each do |process| + @suspended_processes[process] = 'test' + end end end end