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/spec/aerosol/runner_spec.rb
CHANGED
@@ -111,82 +111,142 @@ describe Aerosol::Runner do
|
|
111
111
|
end
|
112
112
|
|
113
113
|
describe '#old_instances' do
|
114
|
-
|
115
|
-
Aerosol::
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
114
|
+
before do
|
115
|
+
allow(Aerosol::Util).to receive(:git_sha).and_return('1')
|
116
|
+
Aerosol::AWS.auto_scaling.stub_responses(:describe_launch_configurations, {
|
117
|
+
launch_configurations: [
|
118
|
+
{
|
119
|
+
launch_configuration_name: 'launch_config-1',
|
120
|
+
image_id: 'ami-1234567',
|
121
|
+
instance_type: 'm1.large',
|
122
|
+
created_time: Time.at(1)
|
123
|
+
},
|
124
|
+
{
|
125
|
+
launch_configuration_name: 'launch_config-2',
|
126
|
+
image_id: 'ami-1234567',
|
127
|
+
instance_type: 'm1.large',
|
128
|
+
created_time: Time.at(1)
|
129
|
+
},
|
130
|
+
{
|
131
|
+
launch_configuration_name: 'launch_config-3',
|
132
|
+
image_id: 'ami-1234567',
|
133
|
+
instance_type: 'm1.large',
|
134
|
+
created_time: Time.at(1)
|
135
|
+
}
|
136
|
+
],
|
137
|
+
next_token: nil
|
138
|
+
})
|
139
|
+
Aerosol::AWS.auto_scaling.stub_responses(:describe_auto_scaling_groups, {
|
140
|
+
auto_scaling_groups: [
|
141
|
+
{
|
142
|
+
auto_scaling_group_name: 'auto_scaling_group-1',
|
143
|
+
launch_configuration_name: 'launch_config-1',
|
144
|
+
min_size: 1,
|
145
|
+
max_size: 1,
|
146
|
+
desired_capacity: 1,
|
147
|
+
default_cooldown: 300,
|
148
|
+
availability_zones: ['us-east-1a'],
|
149
|
+
health_check_type: 'EC2',
|
150
|
+
created_time: Time.new(2015, 01, 01, 01, 01, 01),
|
151
|
+
tags: [{ key: 'Deploy', value: 'auto_scaling_group'}, { key: 'GitSha', value: '1' }]
|
152
|
+
},
|
153
|
+
{
|
154
|
+
auto_scaling_group_name: 'auto_scaling_group-2',
|
155
|
+
launch_configuration_name: 'launch_config-2',
|
156
|
+
min_size: 1,
|
157
|
+
max_size: 1,
|
158
|
+
desired_capacity: 1,
|
159
|
+
default_cooldown: 300,
|
160
|
+
availability_zones: ['us-east-1a'],
|
161
|
+
health_check_type: 'EC2',
|
162
|
+
created_time: Time.new(2015, 01, 01, 01, 01, 01),
|
163
|
+
tags: [{ key: 'Deploy', value: 'auto_scaling_group'}, { key: 'GitSha', value: '2'}]
|
164
|
+
},
|
165
|
+
{
|
166
|
+
auto_scaling_group_name: 'auto_scaling_group-3',
|
167
|
+
launch_configuration_name: 'launch_config-3',
|
168
|
+
min_size: 1,
|
169
|
+
max_size: 1,
|
170
|
+
desired_capacity: 1,
|
171
|
+
default_cooldown: 300,
|
172
|
+
availability_zones: ['us-east-1a'],
|
173
|
+
health_check_type: 'EC2',
|
174
|
+
created_time: Time.new(2015, 01, 01, 01, 01, 01),
|
175
|
+
tags: [{ key: 'Deploy', value: 'auto_scaling_group'}, { key: 'GitSha', value: '3'}]
|
176
|
+
}
|
177
|
+
],
|
178
|
+
next_token: nil
|
179
|
+
})
|
180
|
+
|
181
|
+
Aerosol::AWS.auto_scaling.stub_responses(:describe_auto_scaling_instances, {
|
182
|
+
auto_scaling_instances: 3.times.map do |i|
|
183
|
+
{
|
184
|
+
instance_id: "i-#{123456+i}",
|
185
|
+
auto_scaling_group_name: "auto_scaling_group-#{i+1}",
|
186
|
+
launch_configuration_name: "launch_config-#{i+1}",
|
187
|
+
availability_zone: 'us-east-1a',
|
188
|
+
lifecycle_state: 'InService',
|
189
|
+
health_status: 'Healthy'
|
190
|
+
}
|
191
|
+
end,
|
192
|
+
next_token: nil
|
193
|
+
})
|
159
194
|
|
160
|
-
let!(:deploy) do
|
161
195
|
Aerosol::Deploy.new! do
|
162
196
|
name :old_instances_deploy
|
163
|
-
auto_scaling
|
197
|
+
auto_scaling do
|
198
|
+
name :auto_scaling_group
|
199
|
+
min_size 1
|
200
|
+
max_size 1
|
201
|
+
|
202
|
+
launch_configuration do
|
203
|
+
name :launch_config
|
204
|
+
image_id 'fake-ami'
|
205
|
+
instance_type 'm1.large'
|
206
|
+
end
|
207
|
+
end
|
164
208
|
end
|
165
209
|
end
|
166
210
|
|
167
|
-
|
211
|
+
let!(:all_lcs) { Aerosol::LaunchConfiguration.all }
|
212
|
+
let!(:all_asgs) { Aerosol::AutoScaling.all }
|
213
|
+
|
214
|
+
let(:all_instance_ids) { Aerosol::Instance.all.map(&:instance_id).sort }
|
215
|
+
let(:old_instance_ids) { subject.old_instances.map(&:instance_id).sort }
|
216
|
+
|
217
|
+
let(:asg1) { all_asgs[0] }
|
218
|
+
let(:asg2) { all_asgs[1] }
|
219
|
+
let(:asg3) { all_asgs[2] }
|
220
|
+
let(:asg1_instances) { asg1.launch_configuration.all_instances.map(&:instance_id) }
|
221
|
+
let(:combined_instances) {
|
222
|
+
asg2.launch_configuration.all_instances + asg3.launch_configuration.all_instances
|
223
|
+
}
|
224
|
+
let(:combined_instance_ids) { combined_instances.map(&:instance_id).sort }
|
225
|
+
|
226
|
+
let(:all_asgs_instances) {
|
227
|
+
[asg1, asg2, asg3].map(&:launch_configuration).map(&:all_instances).flatten
|
228
|
+
}
|
229
|
+
let(:all_asgs_instance_ids) { all_asgs_instances.map(&:instance_id).sort }
|
168
230
|
|
169
231
|
it 'returns each instance that is not a member of the current auto scaling group' do
|
170
232
|
subject.with_deploy :old_instances_deploy do
|
171
|
-
|
172
|
-
|
173
|
-
subject.old_instances.length.should == 10
|
233
|
+
expect(old_instance_ids).to eq(combined_instance_ids)
|
234
|
+
subject.old_instances.length.should == 2
|
174
235
|
end
|
175
236
|
end
|
176
237
|
|
177
238
|
it 'does not include any of the current auto scaling group\'s instances' do
|
178
239
|
subject.with_deploy :old_instances_deploy do
|
179
240
|
asg1.launch_configuration.all_instances.should be_none { |inst|
|
180
|
-
|
241
|
+
old_instance_ids.include?(inst.instance_id)
|
181
242
|
}
|
182
243
|
end
|
183
244
|
end
|
184
245
|
|
185
246
|
it 'does not modify the existing instances' do
|
186
|
-
|
187
|
-
[asg1, asg2, asg3].map(&:launch_configuration).map(&:all_instances).flatten.map(&:id).sort
|
247
|
+
expect(all_instance_ids).to eq(all_asgs_instance_ids)
|
188
248
|
subject.with_deploy :old_instances_deploy do
|
189
|
-
subject.new_instances.map(&:
|
249
|
+
expect(subject.new_instances.map(&:instance_id).sort).to eq(asg1_instances.sort)
|
190
250
|
end
|
191
251
|
end
|
192
252
|
end
|
@@ -195,10 +255,10 @@ describe Aerosol::Runner do
|
|
195
255
|
let!(:lc7) do
|
196
256
|
Aerosol::LaunchConfiguration.new! do
|
197
257
|
name :lc7
|
198
|
-
|
258
|
+
image_id 'fake-ami-how-scandalous'
|
199
259
|
instance_type 'm1.large'
|
200
260
|
stub(:sleep)
|
201
|
-
end
|
261
|
+
end
|
202
262
|
end
|
203
263
|
let!(:asg7) do
|
204
264
|
Aerosol::AutoScaling.new! do
|
@@ -208,21 +268,21 @@ describe Aerosol::Runner do
|
|
208
268
|
max_size 3
|
209
269
|
launch_configuration :lc7
|
210
270
|
stub(:sleep)
|
211
|
-
end
|
271
|
+
end
|
212
272
|
end
|
213
273
|
let!(:instance1) do
|
214
274
|
Aerosol::Instance.from_hash(
|
215
275
|
{
|
216
|
-
|
217
|
-
|
276
|
+
instance_id: 'z0',
|
277
|
+
launch_configuration_name: lc7.launch_configuration_name
|
218
278
|
}
|
219
279
|
)
|
220
280
|
end
|
221
281
|
let!(:instance2) do
|
222
|
-
double(:launch_configuration => double(:
|
282
|
+
double(:launch_configuration => double(:launch_configuration_name => 'lc7-8891022'))
|
223
283
|
end
|
224
284
|
let!(:instance3) do
|
225
|
-
double(:launch_configuration => double(:
|
285
|
+
double(:launch_configuration => double(:launch_configuration_name => 'lc0-8891022'))
|
226
286
|
end
|
227
287
|
|
228
288
|
let!(:deploy) do
|
@@ -235,6 +295,7 @@ describe Aerosol::Runner do
|
|
235
295
|
before do
|
236
296
|
Aerosol::Instance.stub(:all).and_return([instance1, instance2, instance3])
|
237
297
|
end
|
298
|
+
|
238
299
|
it 'returns each instance that is a member of the current launch config' do
|
239
300
|
subject.with_deploy :new_instances_deploy do
|
240
301
|
subject.new_instances.should == [instance1]
|
@@ -247,7 +308,7 @@ describe Aerosol::Runner do
|
|
247
308
|
3.times.map do |i|
|
248
309
|
double(:instance,
|
249
310
|
:public_hostname => 'not-a-real-hostname',
|
250
|
-
:
|
311
|
+
:instance_id => "test#{i}")
|
251
312
|
end
|
252
313
|
end
|
253
314
|
let(:timeout_length) { 0.01 }
|
@@ -304,7 +365,7 @@ describe Aerosol::Runner do
|
|
304
365
|
|
305
366
|
describe '#start_tailing_logs' do
|
306
367
|
let(:ssh) { double(:ssh) }
|
307
|
-
let(:instance) { double(
|
368
|
+
let(:instance) { double(Aerosol::Instance, instance_id: '2') }
|
308
369
|
let(:command) { 'sudo tail -f /var/log/syslog' }
|
309
370
|
let(:tail_logs) { true }
|
310
371
|
let(:log_files) { ['/var/log/syslog'] }
|
@@ -319,7 +380,7 @@ describe Aerosol::Runner do
|
|
319
380
|
let(:old_log_fork) { double(:old_log_fork) }
|
320
381
|
|
321
382
|
it 'keeps the old one' do
|
322
|
-
subject.log_pids[instance.
|
383
|
+
subject.log_pids[instance.instance_id] = old_log_fork
|
323
384
|
expect(subject.start_tailing_logs(ssh, instance)).to be(old_log_fork)
|
324
385
|
end
|
325
386
|
end
|
@@ -355,7 +416,7 @@ describe Aerosol::Runner do
|
|
355
416
|
|
356
417
|
describe '#ssh_fork', :local do
|
357
418
|
let(:ssh) { Aerosol::Connection.new(user: `whoami`.strip, host: 'www.doesntusethis.com') }
|
358
|
-
let(:instance) { double(
|
419
|
+
let(:instance) { double(Aerosol::Instance, instance_id: '1', address: 'localhost') }
|
359
420
|
let(:ssh_fork) {
|
360
421
|
subject.ssh_fork(command, ssh, instance)
|
361
422
|
}
|
@@ -388,10 +449,10 @@ describe Aerosol::Runner do
|
|
388
449
|
let!(:lc) do
|
389
450
|
Aerosol::LaunchConfiguration.new! do
|
390
451
|
name :stop_app_launch_config
|
391
|
-
|
452
|
+
image_id 'stop-app-ami-123'
|
392
453
|
instance_type 'm1.large'
|
393
454
|
stub(:sleep)
|
394
|
-
end
|
455
|
+
end
|
395
456
|
end
|
396
457
|
let!(:asg) do
|
397
458
|
Aerosol::AutoScaling.new! do
|
@@ -401,13 +462,13 @@ describe Aerosol::Runner do
|
|
401
462
|
max_size 5
|
402
463
|
launch_configuration :stop_app_launch_config
|
403
464
|
stub(:sleep)
|
404
|
-
end
|
465
|
+
end
|
405
466
|
end
|
406
|
-
let!(:instances) { Aerosol::Instance.all.select { |instance| instance.ami == lc.ami } }
|
407
467
|
let!(:session) { double(:session) }
|
408
468
|
let!(:deploy) do
|
409
469
|
s = session
|
410
470
|
Aerosol::Deploy.new! do
|
471
|
+
auto_scaling :stop_app_auto_scaling_group
|
411
472
|
name :stop_app_deploy
|
412
473
|
ssh :stop_app_ssh do
|
413
474
|
user 'dad'
|
@@ -418,9 +479,68 @@ describe Aerosol::Runner do
|
|
418
479
|
end
|
419
480
|
|
420
481
|
it 'sshs into each old instance and calls the stop command' do
|
482
|
+
Aerosol::AWS.auto_scaling.stub_responses(:describe_launch_configurations, {
|
483
|
+
launch_configurations: [
|
484
|
+
{
|
485
|
+
launch_configuration_name: 'stop_app_launch_config-123456',
|
486
|
+
image_id: 'stop-app-ami-123',
|
487
|
+
instance_type: 'm1.large',
|
488
|
+
created_time: Time.at(1)
|
489
|
+
}
|
490
|
+
],
|
491
|
+
next_token: nil
|
492
|
+
})
|
493
|
+
Aerosol::AWS.auto_scaling.stub_responses(:describe_auto_scaling_groups, {
|
494
|
+
auto_scaling_groups: [
|
495
|
+
{
|
496
|
+
auto_scaling_group_name: 'stop_app_auto_scaling_group-123456',
|
497
|
+
min_size: 5,
|
498
|
+
max_size: 5,
|
499
|
+
desired_capacity: 5,
|
500
|
+
default_cooldown: 300,
|
501
|
+
availability_zones: ['us-east-1a'],
|
502
|
+
health_check_type: 'EC2',
|
503
|
+
created_time: Time.at(1),
|
504
|
+
launch_configuration_name: 'stop_app_launch_config-123456',
|
505
|
+
tags: [
|
506
|
+
{
|
507
|
+
key: 'GitSha',
|
508
|
+
value: '123456',
|
509
|
+
},
|
510
|
+
{
|
511
|
+
key: 'Deploy',
|
512
|
+
value: 'stop_app_auto_scaling_group'
|
513
|
+
}
|
514
|
+
]
|
515
|
+
}
|
516
|
+
],
|
517
|
+
next_token: nil
|
518
|
+
})
|
519
|
+
Aerosol::AWS.auto_scaling.stub_responses(:describe_auto_scaling_instances, {
|
520
|
+
auto_scaling_instances: 5.times.map do |n|
|
521
|
+
{
|
522
|
+
launch_configuration_name: 'stop_app_launch_config-123456',
|
523
|
+
instance_id: "i-#{1234567+n}",
|
524
|
+
auto_scaling_group_name: 'stop_app_launch_config-123456',
|
525
|
+
availability_zone: 'us-east-1a',
|
526
|
+
lifecycle_state: 'InService',
|
527
|
+
health_status: 'Running'
|
528
|
+
}
|
529
|
+
end
|
530
|
+
})
|
531
|
+
Aerosol::AWS.compute.stub_responses(:describe_instances, {
|
532
|
+
reservations: [
|
533
|
+
{
|
534
|
+
instances: [
|
535
|
+
{
|
536
|
+
public_dns_name: 'test'
|
537
|
+
}
|
538
|
+
]
|
539
|
+
}
|
540
|
+
]
|
541
|
+
})
|
421
542
|
session.should_receive(:exec!).with(deploy.stop_command).exactly(5).times
|
422
543
|
session.should_receive(:loop).exactly(5).times
|
423
|
-
subject.stub(:old_instances).and_return(instances)
|
424
544
|
subject.with_deploy :stop_app_deploy do
|
425
545
|
subject.stop_app
|
426
546
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,10 +8,8 @@ require 'aerosol'
|
|
8
8
|
# and its subdirectories.
|
9
9
|
#Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
Aerosol::AWS.aws_access_key_id = 'MOCK_KEY'
|
14
|
-
Aerosol::AWS.aws_secret_access_key = 'MOCK_SECRET'
|
11
|
+
Aerosol::AWS.credentials = Aws::Credentials.new('MOCK_KEY', 'MOCK_SECRET')
|
12
|
+
Aerosol::AWS.stub_responses = true
|
15
13
|
Dockly::Util::Logger.disable! unless ENV['ENABLE_LOGGER'] == 'true'
|
16
14
|
|
17
15
|
RSpec.configure do |config|
|