aerosol 0.5.1 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -111,82 +111,142 @@ describe Aerosol::Runner do
111
111
  end
112
112
 
113
113
  describe '#old_instances' do
114
- let!(:asg1) do
115
- Aerosol::AutoScaling.new! do
116
- name :old_instances_asg_1
117
- availability_zones 'us-east-1'
118
- min_size 5
119
- max_size 5
120
- tag 'Deploy' => 'old_instances_deploy', 'GitSha' => 1
121
- launch_configuration do
122
- ami 'fake-ami'
123
- instance_type 'm1.large'
124
- stub(:sleep)
125
- end
126
- stub(:sleep)
127
- end.tap(&:create)
128
- end
129
- let!(:asg2) do
130
- Aerosol::AutoScaling.new! do
131
- name :old_instances_asg_2
132
- availability_zones 'us-east-1'
133
- min_size 5
134
- max_size 5
135
- launch_configuration do
136
- ami 'fake-ami'
137
- instance_type 'm1.large'
138
- stub(:sleep)
139
- end
140
- tag 'Deploy' => 'old_instances_deploy', 'GitSha' => 2
141
- stub(:sleep)
142
- end.tap(&:create)
143
- end
144
- let!(:asg3) do
145
- Aerosol::AutoScaling.new! do
146
- name :old_instances_asg_3
147
- availability_zones 'us-east-1'
148
- min_size 5
149
- max_size 5
150
- tag 'Deploy' => 'old_instances_deploy', 'GitSha' => 3
151
- launch_configuration do
152
- ami 'fake-ami'
153
- instance_type 'm1.large'
154
- stub(:sleep)
155
- end
156
- stub(:sleep)
157
- end.tap(&:create)
158
- end
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 :old_instances_asg_1
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
- before(:all) { Aerosol::AutoScaling.all.map(&:destroy) }
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
- subject.old_instances.map(&:id).sort.should ==
172
- (asg2.launch_configuration.all_instances + asg3.launch_configuration.all_instances).map(&:id).sort
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
- subject.old_instances.map(&:id).include?(inst.id)
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
- Aerosol::Instance.all.map(&:id).sort.should ==
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(&:id).sort.should == asg1.all_instances.map(&:id).sort
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
- ami 'fake-ami-how-scandalous'
258
+ image_id 'fake-ami-how-scandalous'
199
259
  instance_type 'm1.large'
200
260
  stub(:sleep)
201
- end.tap(&:create)
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.tap(&:create)
271
+ end
212
272
  end
213
273
  let!(:instance1) do
214
274
  Aerosol::Instance.from_hash(
215
275
  {
216
- 'InstanceId' => 'z0',
217
- 'LaunchConfigurationName' => lc7.aws_identifier
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(:aws_identifier => 'lc7-8891022'))
282
+ double(:launch_configuration => double(:launch_configuration_name => 'lc7-8891022'))
223
283
  end
224
284
  let!(:instance3) do
225
- double(:launch_configuration => double(:aws_identifier => 'lc0-8891022'))
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
- :id => "test#{i}")
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(:instance, id: '2') }
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.id] = old_log_fork
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(:instance, id: '1', public_hostname: 'localhost') }
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
- ami 'stop-app-ami-123'
452
+ image_id 'stop-app-ami-123'
392
453
  instance_type 'm1.large'
393
454
  stub(:sleep)
394
- end.tap(&:create)
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.tap(&:create)
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
- Fog.mock!
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|