aerosol 0.5.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/aerosol.gemspec +1 -1
- data/lib/aerosol/auto_scaling.rb +56 -129
- data/lib/aerosol/aws.rb +6 -15
- data/lib/aerosol/aws_model.rb +10 -10
- data/lib/aerosol/connection.rb +1 -1
- data/lib/aerosol/deploy.rb +18 -4
- data/lib/aerosol/instance.rb +19 -16
- data/lib/aerosol/launch_configuration.rb +42 -39
- data/lib/aerosol/rake_task.rb +12 -6
- data/lib/aerosol/runner.rb +15 -15
- data/lib/aerosol/version.rb +1 -1
- data/lib/aerosol.rb +14 -2
- data/spec/aerosol/auto_scaling_spec.rb +207 -113
- data/spec/aerosol/connection_spec.rb +21 -2
- data/spec/aerosol/deploy_spec.rb +3 -3
- data/spec/aerosol/instance_spec.rb +51 -30
- data/spec/aerosol/launch_configuration_spec.rb +174 -105
- data/spec/aerosol/runner_spec.rb +191 -71
- data/spec/spec_helper.rb +2 -4
- metadata +40 -57
- data/spec/fixtures/Procfile +0 -1
- data/spec/fixtures/Rakefile +0 -17
- data/spec/fixtures/not_a_tar-2.txt +0 -1
- data/spec/fixtures/not_a_tar.txt +0 -1
- data/spec/fixtures/tar-2.tar +0 -0
- data/spec/fixtures/test-1.tar +0 -0
- data/spec/fixtures/test-2.tar.gz +0 -0
- data/spec/vcr/Deployz_Docker/_fetch_import/when_both_import_and_name_are_present_present/and_it_points_to_a_non-S3_url/pulls_the_file.yml +0 -214
data/lib/aerosol/rake_task.rb
CHANGED
@@ -59,8 +59,14 @@ namespace :aerosol do
|
|
59
59
|
|
60
60
|
Aerosol.deploys.values.each do |inst|
|
61
61
|
namespace :"#{inst.name}" do
|
62
|
+
desc "Assumes a role if necessary"
|
63
|
+
task :assume_role => 'aerosol:load' do |name|
|
64
|
+
Thread.current[:rake_task] = name
|
65
|
+
inst.perform_role_assumption
|
66
|
+
end
|
67
|
+
|
62
68
|
desc "Runs the ActiveRecord migration through the SSH connection given"
|
63
|
-
task :run_migration =>
|
69
|
+
task :run_migration => "aerosol:#{inst.name}:assume_role" do |name|
|
64
70
|
Thread.current[:rake_task] = name
|
65
71
|
Aerosol::Runner.new.with_deploy(inst.name) do |runner|
|
66
72
|
runner.run_migration
|
@@ -71,7 +77,7 @@ namespace :aerosol do
|
|
71
77
|
task :create_auto_scaling_group => "aerosol:auto_scaling:#{inst.auto_scaling.name}"
|
72
78
|
|
73
79
|
desc "Waits for instances of the new autoscaling groups to start up"
|
74
|
-
task :wait_for_new_instances =>
|
80
|
+
task :wait_for_new_instances => "aerosol:#{inst.name}:assume_role" do |name|
|
75
81
|
Thread.current[:rake_task] = name
|
76
82
|
Aerosol::Runner.new.with_deploy(inst.name) do |runner|
|
77
83
|
runner.wait_for_new_instances
|
@@ -79,7 +85,7 @@ namespace :aerosol do
|
|
79
85
|
end
|
80
86
|
|
81
87
|
desc "Runs command to shut down the application on the old instances instead of just terminating"
|
82
|
-
task :stop_old_app =>
|
88
|
+
task :stop_old_app => "aerosol:#{inst.name}:assume_role" do |name|
|
83
89
|
Thread.current[:rake_task] = name
|
84
90
|
Aerosol::Runner.new.with_deploy(inst.name) do |runner|
|
85
91
|
runner.stop_app
|
@@ -87,7 +93,7 @@ namespace :aerosol do
|
|
87
93
|
end
|
88
94
|
|
89
95
|
desc "Terminates instances with the current tag and different git hash"
|
90
|
-
task :destroy_old_auto_scaling_groups =>
|
96
|
+
task :destroy_old_auto_scaling_groups => "aerosol:#{inst.name}:assume_role" do |name|
|
91
97
|
Thread.current[:rake_task] = name
|
92
98
|
Aerosol::Runner.new.with_deploy(inst.name) do |runner|
|
93
99
|
runner.destroy_old_auto_scaling_groups
|
@@ -95,7 +101,7 @@ namespace :aerosol do
|
|
95
101
|
end
|
96
102
|
|
97
103
|
desc "Terminates instances with the current tag and current git hash"
|
98
|
-
task :destroy_new_auto_scaling_groups =>
|
104
|
+
task :destroy_new_auto_scaling_groups => "aerosol:#{inst.name}:assume_role" do |name|
|
99
105
|
Thread.current[:rake_task] = name
|
100
106
|
Aerosol::Runner.new.with_deploy(inst.name) do |runner|
|
101
107
|
runner.destroy_new_auto_scaling_groups
|
@@ -103,7 +109,7 @@ namespace :aerosol do
|
|
103
109
|
end
|
104
110
|
|
105
111
|
desc "Runs a post deploy command"
|
106
|
-
task :run_post_deploy =>
|
112
|
+
task :run_post_deploy => "aerosol:#{inst.name}:assume_role" do |name|
|
107
113
|
Thread.current[:rake_task] = name
|
108
114
|
inst.run_post_deploy
|
109
115
|
end
|
data/lib/aerosol/runner.rb
CHANGED
@@ -70,8 +70,8 @@ class Aerosol::Runner
|
|
70
70
|
current_instances = new_instances
|
71
71
|
remaining_instances = current_instances - live_instances
|
72
72
|
info "waiting for instances to be live (#{remaining_instances.count} remaining)"
|
73
|
-
debug "current instances: #{current_instances.map(&:
|
74
|
-
debug "live instances: #{live_instances.map(&:
|
73
|
+
debug "current instances: #{current_instances.map(&:instance_id)}"
|
74
|
+
debug "live instances: #{live_instances.map(&:instance_id)}"
|
75
75
|
live_instances.concat(remaining_instances.select { |instance| healthy?(instance) })
|
76
76
|
break if (current_instances - live_instances).empty?
|
77
77
|
debug 'sleeping for 10 seconds'
|
@@ -94,18 +94,18 @@ class Aerosol::Runner
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def healthy?(instance)
|
97
|
-
debug "Checking if #{instance.
|
97
|
+
debug "Checking if #{instance.instance_id} is healthy"
|
98
98
|
|
99
99
|
unless instance.live?
|
100
|
-
debug "#{instance.
|
100
|
+
debug "#{instance.instance_id} is not live"
|
101
101
|
return false
|
102
102
|
end
|
103
103
|
|
104
|
-
debug "trying to SSH to #{instance.
|
104
|
+
debug "trying to SSH to #{instance.instance_id}"
|
105
105
|
success = false
|
106
106
|
ssh.with_connection(instance) do |session|
|
107
|
-
start_tailing_logs(ssh, instance) if log_pids[instance.
|
108
|
-
debug "checking if #{instance.
|
107
|
+
start_tailing_logs(ssh, instance) if log_pids[instance.instance_id].nil?
|
108
|
+
debug "checking if #{instance.instance_id} is healthy"
|
109
109
|
success = if is_alive?.nil?
|
110
110
|
debug 'Using default site live check'
|
111
111
|
check_site_live(session)
|
@@ -116,13 +116,13 @@ class Aerosol::Runner
|
|
116
116
|
end
|
117
117
|
|
118
118
|
if success
|
119
|
-
debug "#{instance.
|
119
|
+
debug "#{instance.instance_id} is healthy"
|
120
120
|
else
|
121
|
-
debug "#{instance.
|
121
|
+
debug "#{instance.instance_id} is not healthy"
|
122
122
|
end
|
123
123
|
success
|
124
124
|
rescue => ex
|
125
|
-
debug "#{instance.
|
125
|
+
debug "#{instance.instance_id} is not healthy: #{ex.message}"
|
126
126
|
false
|
127
127
|
end
|
128
128
|
|
@@ -149,7 +149,7 @@ class Aerosol::Runner
|
|
149
149
|
'sudo', 'tail', '-f', *log_files
|
150
150
|
].join(' ')
|
151
151
|
|
152
|
-
log_pids[instance.
|
152
|
+
log_pids[instance.instance_id] ||= ssh_fork(command, ssh, instance)
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
@@ -168,7 +168,7 @@ class Aerosol::Runner
|
|
168
168
|
ssh_exec!(session, command) do |stream, data|
|
169
169
|
data.lines.each do |line|
|
170
170
|
if line.end_with?($/)
|
171
|
-
debug "[#{instance.
|
171
|
+
debug "[#{instance.instance_id}] #{stream}: #{buffer + line}"
|
172
172
|
buffer = ''
|
173
173
|
else
|
174
174
|
buffer = line
|
@@ -278,15 +278,15 @@ class Aerosol::Runner
|
|
278
278
|
private
|
279
279
|
|
280
280
|
def stop_one_app(instance)
|
281
|
-
debug "attempting to stop app on: #{instance.
|
281
|
+
debug "attempting to stop app on: #{instance.address}"
|
282
282
|
ssh.with_connection(instance) do |session|
|
283
283
|
session.exec!(stop_command)
|
284
284
|
session.loop
|
285
285
|
end
|
286
|
-
info "successfully stopped app on: #{instance.
|
286
|
+
info "successfully stopped app on: #{instance.address}"
|
287
287
|
true
|
288
288
|
rescue => ex
|
289
|
-
warn "stop app failed on #{instance.
|
289
|
+
warn "stop app failed on #{instance.address} due to: #{ex}"
|
290
290
|
false
|
291
291
|
end
|
292
292
|
|
data/lib/aerosol/version.rb
CHANGED
data/lib/aerosol.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require 'yaml'
|
2
|
+
require 'aws-sdk'
|
2
3
|
require 'dockly/util'
|
4
|
+
require 'base64'
|
5
|
+
|
6
|
+
Aws.config.update({ region: 'us-east-1' }) if Aws.config[:region].nil?
|
3
7
|
|
4
8
|
module Aerosol
|
5
9
|
require 'aerosol/aws'
|
@@ -41,6 +45,14 @@ module Aerosol
|
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
48
|
+
def region(value = nil)
|
49
|
+
if value.nil?
|
50
|
+
Aws.config[:region]
|
51
|
+
else
|
52
|
+
Aws.config.update(region: value)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
44
56
|
def setup
|
45
57
|
{
|
46
58
|
:auto_scalings => Aerosol::AutoScaling.instances,
|
@@ -76,7 +88,7 @@ module Aerosol
|
|
76
88
|
module_function :inst, :load_inst, :setup, :load_file, :load_file=,
|
77
89
|
:auto_scaling, :launch_configuration, :deploy, :ssh, :git_sha,
|
78
90
|
:auto_scalings, :launch_configurations, :deploys, :sshs,
|
79
|
-
:namespace, :env, :envs
|
91
|
+
:namespace, :env, :envs, :region
|
80
92
|
end
|
81
93
|
|
82
94
|
require 'aerosol/runner'
|
@@ -1,30 +1,42 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'fog/aws'
|
3
2
|
|
4
3
|
describe Aerosol::AutoScaling do
|
5
|
-
let
|
4
|
+
let(:launch_configuration_setup) do
|
6
5
|
Aerosol::LaunchConfiguration.new! do
|
7
6
|
name :my_launch_config_for_auto_scaling
|
8
|
-
|
7
|
+
image_id 'ami :) :) :)'
|
9
8
|
instance_type 'm1.large'
|
10
9
|
stub(:sleep)
|
11
|
-
end
|
10
|
+
end
|
12
11
|
end
|
13
12
|
|
14
|
-
|
15
|
-
|
13
|
+
let(:launch_configuration) do
|
14
|
+
launch_configuration_setup.tap(&:create)
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
subject { described_class.new!(&block) }
|
18
|
+
let(:previous_launch_configurations) { [] }
|
19
|
+
let(:previous_auto_scaling_groups) { [] }
|
20
|
+
|
21
|
+
before do
|
22
|
+
subject.stub(:sleep)
|
23
|
+
Aerosol::AWS.auto_scaling.stub_responses(:describe_launch_configurations, {
|
24
|
+
launch_configurations: previous_launch_configurations, next_token: nil
|
25
|
+
})
|
26
|
+
Aerosol::AWS.auto_scaling.stub_responses(:describe_auto_scaling_groups, {
|
27
|
+
auto_scaling_groups: previous_auto_scaling_groups, next_token: nil
|
28
|
+
})
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:block) { Proc.new { } }
|
32
|
+
|
33
|
+
describe "#auto_scaling_group_name" do
|
34
|
+
let(:block) { Proc.new { name :my_auto_scaling } }
|
23
35
|
|
24
36
|
context "with no namespace set" do
|
25
37
|
let(:identifier) { "my_auto_scaling-#{Aerosol::Util.git_sha}" }
|
26
38
|
it "returns a normal identifier" do
|
27
|
-
expect(subject.
|
39
|
+
expect(subject.auto_scaling_group_name).to eq(identifier)
|
28
40
|
end
|
29
41
|
end
|
30
42
|
|
@@ -36,7 +48,7 @@ describe Aerosol::AutoScaling do
|
|
36
48
|
after { Aerosol.instance_variable_set(:"@namespace", nil) }
|
37
49
|
|
38
50
|
it "returns a namespaced identifier" do
|
39
|
-
expect(subject.
|
51
|
+
expect(subject.auto_scaling_group_name).to eq(identifier)
|
40
52
|
end
|
41
53
|
end
|
42
54
|
end
|
@@ -57,18 +69,12 @@ describe Aerosol::AutoScaling do
|
|
57
69
|
end
|
58
70
|
|
59
71
|
context 'when all of the required options are set' do
|
60
|
-
let!(:launch_configuration) do
|
61
|
-
Aerosol::LaunchConfiguration.new! do
|
62
|
-
ami 'fake_ami'
|
63
|
-
instance_type 'm1.large'
|
64
|
-
stub(:sleep)
|
65
|
-
end
|
66
|
-
end
|
67
72
|
let(:availability_zone) { 'US' }
|
68
73
|
let(:min_size) { 1 }
|
69
74
|
let(:max_size) { 10 }
|
70
75
|
let(:options) {
|
71
|
-
{
|
76
|
+
{
|
77
|
+
:name => :my_group,
|
72
78
|
:launch_configuration => launch_configuration.name,
|
73
79
|
:availability_zones => [availability_zone],
|
74
80
|
:min_size => 1,
|
@@ -88,16 +94,9 @@ describe Aerosol::AutoScaling do
|
|
88
94
|
end
|
89
95
|
|
90
96
|
context 'when the launch configuration is known' do
|
91
|
-
before do
|
92
|
-
launch_configuration.create!
|
93
|
-
end
|
94
|
-
|
95
97
|
it 'creates an auto-scaling group' do
|
96
98
|
expect(subject.tags).to include('Deploy' => 'my_group')
|
97
|
-
|
98
|
-
.to change { subject.send(:conn).data[:auto_scaling_groups][subject.aws_identifier].class.to_s }
|
99
|
-
.from('NilClass')
|
100
|
-
.to('Hash')
|
99
|
+
subject.create!
|
101
100
|
end
|
102
101
|
|
103
102
|
context "when there is a namespace" do
|
@@ -117,30 +116,29 @@ describe Aerosol::AutoScaling do
|
|
117
116
|
end
|
118
117
|
|
119
118
|
describe '#destroy!' do
|
120
|
-
let(:aws_identifier) { subject.aws_identifier }
|
121
119
|
subject { Aerosol::AutoScaling.new }
|
122
120
|
|
123
121
|
context 'when there is no such auto-scaling group' do
|
124
122
|
it 'raises an error' do
|
125
|
-
|
126
|
-
|
123
|
+
Aerosol::AWS.auto_scaling.stub_responses(
|
124
|
+
:delete_auto_scaling_group,
|
125
|
+
Aws::AutoScaling::Errors::ValidationError.new(nil, nil)
|
126
|
+
)
|
127
|
+
|
128
|
+
expect { subject.destroy! }.to raise_error(Aws::AutoScaling::Errors::ValidationError)
|
127
129
|
end
|
128
130
|
end
|
129
131
|
|
130
132
|
context 'when the auto-scaling group exists' do
|
131
|
-
before { subject.send(:conn).data[:auto_scaling_groups][aws_identifier] = aws_identifier }
|
132
|
-
|
133
133
|
it 'deletes the auto-scaling group' do
|
134
|
-
|
135
|
-
|
136
|
-
.from(aws_identifier)
|
137
|
-
.to(nil)
|
134
|
+
Aerosol::AWS.auto_scaling.stub_responses(:delete_auto_scaling_group, {})
|
135
|
+
expect { subject.destroy! }.to_not raise_error
|
138
136
|
end
|
139
137
|
end
|
140
138
|
end
|
141
139
|
|
142
140
|
describe '#create' do
|
143
|
-
context 'when the
|
141
|
+
context 'when the auto_scaling_group_name is nil' do
|
144
142
|
subject { described_class.new!(:name => 'nonsense') }
|
145
143
|
|
146
144
|
it 'raises an error' do
|
@@ -148,7 +146,7 @@ describe Aerosol::AutoScaling do
|
|
148
146
|
end
|
149
147
|
end
|
150
148
|
|
151
|
-
context 'when the
|
149
|
+
context 'when the auto_scaling_group_name is present' do
|
152
150
|
subject { described_class.new!(:name => 'nonsense2') }
|
153
151
|
|
154
152
|
context 'when the model already exists' do
|
@@ -197,19 +195,22 @@ describe Aerosol::AutoScaling do
|
|
197
195
|
subject { described_class }
|
198
196
|
|
199
197
|
context 'when the argument exists' do
|
200
|
-
let!(:existing) {
|
201
|
-
conf = launch_config
|
202
|
-
subject.new! do
|
203
|
-
min_size 1
|
204
|
-
max_size 3
|
205
|
-
availability_zones 'us-east-1'
|
206
|
-
launch_configuration conf.name
|
207
|
-
stub(:sleep)
|
208
|
-
end.tap(&:create)
|
209
|
-
}
|
210
|
-
|
211
198
|
it 'returns true' do
|
212
|
-
|
199
|
+
Aerosol::AWS.auto_scaling.stub_responses(:describe_auto_scaling_groups, {
|
200
|
+
auto_scaling_groups: [{
|
201
|
+
auto_scaling_group_name: 'test',
|
202
|
+
launch_configuration_name: 'test',
|
203
|
+
min_size: 1,
|
204
|
+
max_size: 1,
|
205
|
+
desired_capacity: 1,
|
206
|
+
default_cooldown: 300,
|
207
|
+
availability_zones: ['us-east-1a'],
|
208
|
+
health_check_type: 'EC2',
|
209
|
+
created_time: Time.at(1)
|
210
|
+
}],
|
211
|
+
next_token: nil
|
212
|
+
})
|
213
|
+
subject.exists?('test').should be_true
|
213
214
|
end
|
214
215
|
end
|
215
216
|
|
@@ -217,7 +218,7 @@ describe Aerosol::AutoScaling do
|
|
217
218
|
before do
|
218
219
|
described_class.new! do
|
219
220
|
name :exists_test_name
|
220
|
-
|
221
|
+
auto_scaling_group_name 'does-not-exist'
|
221
222
|
stub(:sleep)
|
222
223
|
end.destroy! rescue nil
|
223
224
|
end
|
@@ -230,18 +231,63 @@ describe Aerosol::AutoScaling do
|
|
230
231
|
|
231
232
|
describe '.request_all' do
|
232
233
|
describe 'repeats until no NextToken' do
|
233
|
-
before do
|
234
|
-
allow(Aerosol::AutoScaling).to receive(:request_all_for_token).with(nil) do
|
235
|
-
{ 'AutoScalingGroups' => [1, 4], 'NextToken' => 'token' }
|
236
|
-
end
|
237
|
-
|
238
|
-
allow(Aerosol::AutoScaling).to receive(:request_all_for_token).with('token') do
|
239
|
-
{ 'AutoScalingGroups' => [2, 3], 'NextToken' => nil }
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
234
|
it 'should include both autoscaling groups lists' do
|
244
|
-
|
235
|
+
Aerosol::AWS.auto_scaling.stub_responses(:describe_auto_scaling_groups, [
|
236
|
+
{
|
237
|
+
auto_scaling_groups: [
|
238
|
+
{
|
239
|
+
auto_scaling_group_name: '1',
|
240
|
+
launch_configuration_name: '1',
|
241
|
+
min_size: 1,
|
242
|
+
max_size: 1,
|
243
|
+
desired_capacity: 1,
|
244
|
+
default_cooldown: 300,
|
245
|
+
availability_zones: ['us-east-1a'],
|
246
|
+
health_check_type: 'EC2',
|
247
|
+
created_time: Time.at(1)
|
248
|
+
}, {
|
249
|
+
auto_scaling_group_name: '4',
|
250
|
+
launch_configuration_name: '4',
|
251
|
+
min_size: 1,
|
252
|
+
max_size: 1,
|
253
|
+
desired_capacity: 1,
|
254
|
+
default_cooldown: 300,
|
255
|
+
availability_zones: ['us-east-1a'],
|
256
|
+
health_check_type: 'EC2',
|
257
|
+
created_time: Time.at(1)
|
258
|
+
}
|
259
|
+
],
|
260
|
+
next_token: 'token'
|
261
|
+
},
|
262
|
+
{
|
263
|
+
auto_scaling_groups: [
|
264
|
+
{
|
265
|
+
auto_scaling_group_name: '2',
|
266
|
+
launch_configuration_name: '2',
|
267
|
+
min_size: 1,
|
268
|
+
max_size: 1,
|
269
|
+
desired_capacity: 1,
|
270
|
+
default_cooldown: 300,
|
271
|
+
availability_zones: ['us-east-1a'],
|
272
|
+
health_check_type: 'EC2',
|
273
|
+
created_time: Time.at(1)
|
274
|
+
}, {
|
275
|
+
auto_scaling_group_name: '3',
|
276
|
+
launch_configuration_name: '3',
|
277
|
+
min_size: 1,
|
278
|
+
max_size: 1,
|
279
|
+
desired_capacity: 1,
|
280
|
+
default_cooldown: 300,
|
281
|
+
availability_zones: ['us-east-1a'],
|
282
|
+
health_check_type: 'EC2',
|
283
|
+
created_time: Time.at(1)
|
284
|
+
}
|
285
|
+
],
|
286
|
+
next_token: nil
|
287
|
+
}
|
288
|
+
])
|
289
|
+
|
290
|
+
expect(Aerosol::AutoScaling.request_all.map(&:auto_scaling_group_name)).to eq(['1','4','2','3'])
|
245
291
|
end
|
246
292
|
end
|
247
293
|
end
|
@@ -249,51 +295,60 @@ describe Aerosol::AutoScaling do
|
|
249
295
|
describe '.all' do
|
250
296
|
subject { described_class }
|
251
297
|
|
252
|
-
def destroy_all
|
253
|
-
Aerosol::AutoScaling.instances.values.each do |instance|
|
254
|
-
instance.destroy! rescue nil
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
after { destroy_all }
|
259
|
-
|
260
298
|
context 'when there are no auto scaling groups' do
|
261
|
-
before
|
262
|
-
|
299
|
+
before do
|
300
|
+
Aerosol::AWS.auto_scaling.stub_responses(:describe_auto_scaling_groups, [
|
301
|
+
{ auto_scaling_groups: [], next_token: nil }
|
302
|
+
])
|
303
|
+
end
|
263
304
|
its(:all) { should be_empty }
|
264
305
|
end
|
265
306
|
|
266
307
|
context 'when there are auto scaling groups' do
|
267
|
-
|
268
|
-
let!(:insts) do
|
308
|
+
let(:insts) {
|
269
309
|
[
|
270
310
|
{
|
271
|
-
:
|
272
|
-
:
|
273
|
-
:
|
274
|
-
:
|
311
|
+
auto_scaling_group_name: 'test',
|
312
|
+
min_size: 1,
|
313
|
+
max_size: 3,
|
314
|
+
availability_zones: ['us-east-1'],
|
315
|
+
launch_configuration_name: launch_configuration.name.to_s,
|
316
|
+
desired_capacity: 1,
|
317
|
+
default_cooldown: 300,
|
318
|
+
health_check_type: 'EC2',
|
319
|
+
created_time: Time.at(1)
|
275
320
|
},
|
276
321
|
{
|
277
|
-
:
|
278
|
-
:
|
279
|
-
:
|
280
|
-
:
|
281
|
-
:
|
322
|
+
auto_scaling_group_name: 'test2',
|
323
|
+
min_size: 2,
|
324
|
+
max_size: 4,
|
325
|
+
availability_zones: ['us-east-2'],
|
326
|
+
launch_configuration_name: launch_configuration.name.to_s,
|
327
|
+
desired_capacity: 1,
|
328
|
+
default_cooldown: 300,
|
329
|
+
health_check_type: 'EC2',
|
330
|
+
created_time: Time.at(1),
|
331
|
+
tags: [{ key: 'my_tag', value: 'is_sweet' }]
|
282
332
|
}
|
283
|
-
]
|
284
|
-
|
333
|
+
]
|
334
|
+
}
|
285
335
|
|
286
336
|
it 'returns each of them' do
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
337
|
+
Aerosol::AWS.auto_scaling.stub_responses(:describe_auto_scaling_groups, {
|
338
|
+
auto_scaling_groups: insts,
|
339
|
+
next_token: nil
|
340
|
+
})
|
341
|
+
instances = subject.all
|
342
|
+
instances.map(&:min_size).should == [1, 2]
|
343
|
+
instances.map(&:max_size).should == [3, 4]
|
344
|
+
instances.map(&:tags).should == [{
|
345
|
+
'GitSha' => Aerosol::Util.git_sha,
|
346
|
+
'Deploy' => instances.first.name.to_s
|
292
347
|
},
|
293
348
|
{
|
294
|
-
|
295
|
-
|
296
|
-
|
349
|
+
'GitSha' => Aerosol::Util.git_sha,
|
350
|
+
'Deploy' => instances.last.name.to_s,
|
351
|
+
'my_tag' => 'is_sweet'
|
297
352
|
}
|
298
353
|
]
|
299
354
|
end
|
@@ -306,18 +361,22 @@ describe Aerosol::AutoScaling do
|
|
306
361
|
|
307
362
|
let(:hash) do
|
308
363
|
{
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
364
|
+
auto_scaling_group_name: 'test-auto-scaling',
|
365
|
+
availability_zones: ['us-east-1'],
|
366
|
+
launch_configuration_name: launch_configuration.launch_configuration_name,
|
367
|
+
min_size: 1,
|
368
|
+
max_size: 2,
|
369
|
+
desired_capacity: 1,
|
370
|
+
default_cooldown: 300,
|
371
|
+
health_check_type: 'EC2',
|
372
|
+
created_time: Time.at(1),
|
314
373
|
}
|
315
374
|
end
|
316
375
|
|
317
376
|
it 'creates a new auto scaling group with the specified values' do
|
318
|
-
auto_scaling.
|
319
|
-
auto_scaling.availability_zones.should == 'us-east-1'
|
320
|
-
auto_scaling.launch_configuration.should ==
|
377
|
+
auto_scaling.auto_scaling_group_name.should == 'test-auto-scaling'
|
378
|
+
auto_scaling.availability_zones.should == ['us-east-1']
|
379
|
+
auto_scaling.launch_configuration.should == launch_configuration
|
321
380
|
auto_scaling.min_size.should == 1
|
322
381
|
auto_scaling.max_size.should == 2
|
323
382
|
end
|
@@ -330,17 +389,17 @@ describe Aerosol::AutoScaling do
|
|
330
389
|
context 'when the auto scaling group has already been initialized' do
|
331
390
|
let(:old_hash) do
|
332
391
|
{
|
333
|
-
|
334
|
-
|
392
|
+
auto_scaling_group_name: 'this-aws-id-abc-123',
|
393
|
+
min_size: 16
|
335
394
|
}
|
336
395
|
end
|
337
|
-
let(:new_hash) { old_hash.merge(
|
396
|
+
let(:new_hash) { old_hash.merge(max_size: 40) }
|
338
397
|
let!(:existing) { described_class.from_hash(old_hash) }
|
339
398
|
let(:new) { described_class.from_hash(new_hash) }
|
340
399
|
|
341
|
-
it '
|
400
|
+
it 'makes a new instance' do
|
342
401
|
expect { new }.to change { described_class.instances.length }.by(1)
|
343
|
-
new.
|
402
|
+
new.auto_scaling_group_name.should == 'this-aws-id-abc-123'
|
344
403
|
new.min_size.should == 16
|
345
404
|
new.max_size.should == 40
|
346
405
|
end
|
@@ -405,12 +464,47 @@ describe Aerosol::AutoScaling do
|
|
405
464
|
:availability_zones => [],
|
406
465
|
:max_size => 10,
|
407
466
|
:min_size => 4,
|
408
|
-
:launch_configuration =>
|
467
|
+
:launch_configuration => launch_configuration.name
|
409
468
|
)
|
410
469
|
}
|
411
|
-
|
412
|
-
|
413
|
-
|
470
|
+
let(:previous_auto_scaling_groups) {
|
471
|
+
[{
|
472
|
+
auto_scaling_group_name: 'all_instances_asg',
|
473
|
+
availability_zones: ['us-east-1'],
|
474
|
+
launch_configuration_name: launch_configuration.name.to_s,
|
475
|
+
min_size: 1,
|
476
|
+
max_size: 2,
|
477
|
+
desired_capacity: 1,
|
478
|
+
default_cooldown: 300,
|
479
|
+
health_check_type: 'EC2',
|
480
|
+
created_time: Time.at(1),
|
481
|
+
instances: [{
|
482
|
+
instance_id: 'i-1239013',
|
483
|
+
availability_zone: 'us-east-1a',
|
484
|
+
lifecycle_state: 'InService',
|
485
|
+
health_status: 'GOOD',
|
486
|
+
launch_configuration_name: launch_configuration.name.to_s
|
487
|
+
}, {
|
488
|
+
instance_id: 'i-1239014',
|
489
|
+
availability_zone: 'us-east-1a',
|
490
|
+
lifecycle_state: 'InService',
|
491
|
+
health_status: 'GOOD',
|
492
|
+
launch_configuration_name: launch_configuration.name.to_s
|
493
|
+
}, {
|
494
|
+
instance_id: 'i-1239015',
|
495
|
+
availability_zone: 'us-east-1a',
|
496
|
+
lifecycle_state: 'InService',
|
497
|
+
health_status: 'GOOD',
|
498
|
+
launch_configuration_name: launch_configuration.name.to_s
|
499
|
+
}, {
|
500
|
+
instance_id: 'i-1239016',
|
501
|
+
availability_zone: 'us-east-1a',
|
502
|
+
lifecycle_state: 'InService',
|
503
|
+
health_status: 'GOOD',
|
504
|
+
launch_configuration_name: launch_configuration.name.to_s
|
505
|
+
}]
|
506
|
+
}]
|
507
|
+
}
|
414
508
|
|
415
509
|
it 'returns a list of instances associated with the group' do
|
416
510
|
auto_scaling.all_instances.length.should == 4
|