vm_shepherd 3.3.1 → 3.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vm_shepherd/aws_manager.rb +16 -0
- data/lib/vm_shepherd/version.rb +1 -1
- data/spec/vm_shepherd/aws_manager_spec.rb +23 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25a49a93d04e9d20815c0e49f6d1a59b0dcfec95
|
4
|
+
data.tar.gz: 0884c51e7c2c8fee2a9211fb401eac3c07786bb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3771e8eae943ca778bde5c58ad09a751a0f5d1d53e893f0bea4d4f397851b1067aa77b36eb598eef374799e5f1b720f2d9d66f89af562e52cd9deb0253978e14
|
7
|
+
data.tar.gz: 5f43ab61a483e64fda40436bd49945803522a1d24e39aca8b33465f993fd27f18a77aef8d0384c83b249b0c9e29258085b2b0075c7be78b743c1b85490970a45
|
@@ -189,7 +189,9 @@ module VmShepherd
|
|
189
189
|
logger.info("Clearing contents of subnet: #{subnet_id}")
|
190
190
|
subnet = AWS.ec2.subnets[subnet_id]
|
191
191
|
volumes = []
|
192
|
+
instance_ids = []
|
192
193
|
subnet.instances.each do |instance|
|
194
|
+
instance_ids.push instance.id
|
193
195
|
instance.attachments.each do |_, attachment|
|
194
196
|
volumes.push(attachment.volume) unless attachment.delete_on_termination
|
195
197
|
end
|
@@ -197,6 +199,7 @@ module VmShepherd
|
|
197
199
|
instance.terminate
|
198
200
|
end
|
199
201
|
destroy_volumes(volumes)
|
202
|
+
ensure_instances_terminated(instance_ids)
|
200
203
|
end
|
201
204
|
|
202
205
|
def destroy_volumes(volumes)
|
@@ -317,5 +320,18 @@ module VmShepherd
|
|
317
320
|
def read_ami_id(ami_file_path)
|
318
321
|
YAML.load_file(ami_file_path)[env_config.fetch('region')]
|
319
322
|
end
|
323
|
+
|
324
|
+
def ensure_instances_terminated(instance_ids)
|
325
|
+
instances = instance_ids.collect {|instance_id| AWS.ec2.instances[instance_id] }
|
326
|
+
instances.each do |instance|
|
327
|
+
while instance.status == :shutting_down
|
328
|
+
sleep VmShepherd::RetryHelper::RETRY_INTERVAL
|
329
|
+
end
|
330
|
+
|
331
|
+
if instance.status != :terminated
|
332
|
+
raise "Expected instance: #{instance.id} to be terminated, but was #{instance.status}"
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
320
336
|
end
|
321
337
|
end
|
data/lib/vm_shepherd/version.rb
CHANGED
@@ -412,8 +412,8 @@ module VmShepherd
|
|
412
412
|
let(:subnets) { instance_double(AWS::EC2::SubnetCollection) }
|
413
413
|
let(:subnet1) { instance_double(AWS::EC2::Subnet, instances: subnet1_instances) }
|
414
414
|
let(:subnet2) { instance_double(AWS::EC2::Subnet, instances: subnet2_instances) }
|
415
|
-
let(:instance1) { instance_double(AWS::EC2::Instance, tags: {}, id: 'instance1') }
|
416
|
-
let(:instance2) { instance_double(AWS::EC2::Instance, tags: {}, id: 'instance2') }
|
415
|
+
let(:instance1) { instance_double(AWS::EC2::Instance, tags: {}, id: 'instance1', status: :terminated) }
|
416
|
+
let(:instance2) { instance_double(AWS::EC2::Instance, tags: {}, id: 'instance2', status: :terminated) }
|
417
417
|
let(:subnet1_instances) { [instance1] }
|
418
418
|
let(:subnet2_instances) { [instance2] }
|
419
419
|
let(:cfn) { instance_double(AWS::CloudFormation, stacks: stack_collection) }
|
@@ -444,6 +444,8 @@ module VmShepherd
|
|
444
444
|
|
445
445
|
allow(AWS::S3).to receive(:new).and_return(s3_client)
|
446
446
|
allow(buckets).to receive(:[]).and_return(instance_double(AWS::S3::Bucket, exists?: false))
|
447
|
+
|
448
|
+
allow(ec2).to receive_message_chain(:instances, :[]).and_return(instance1, instance2)
|
447
449
|
end
|
448
450
|
|
449
451
|
it 'terminates all VMs in the subnet' do
|
@@ -453,8 +455,24 @@ module VmShepherd
|
|
453
455
|
ami_manager.clean_environment
|
454
456
|
end
|
455
457
|
|
458
|
+
it 'ensures the instances are terminated' do
|
459
|
+
expect(instance1).to receive(:status).and_return(:shutting_down, :shutting_down, :terminated)
|
460
|
+
expect(instance2).to receive(:status).and_return(:terminated)
|
461
|
+
|
462
|
+
ami_manager.clean_environment
|
463
|
+
end
|
464
|
+
|
465
|
+
it 'raises if any vms do not terminate' do
|
466
|
+
allow(ec2).to receive_message_chain(:instances, :[]).and_return(instance1, instance2)
|
467
|
+
|
468
|
+
expect(instance1).to receive(:status).and_return(:terminated).twice
|
469
|
+
expect(instance2).to receive(:status).and_return(:running).exactly(3).times
|
470
|
+
|
471
|
+
expect { ami_manager.clean_environment }.to raise_error("Expected instance: #{instance2.id} to be terminated, but was running")
|
472
|
+
end
|
473
|
+
|
456
474
|
it 'polls the status every 30' do
|
457
|
-
expect(ami_manager).to receive(:retry_until).with(retry_limit:
|
475
|
+
expect(ami_manager).to receive(:retry_until).with(retry_limit: 90, retry_interval: 30)
|
458
476
|
|
459
477
|
ami_manager.clean_environment
|
460
478
|
end
|
@@ -471,9 +489,9 @@ module VmShepherd
|
|
471
489
|
ami_manager.clean_environment
|
472
490
|
end
|
473
491
|
|
474
|
-
it 'stops retrying after
|
492
|
+
it 'stops retrying after 90 times' do
|
475
493
|
expect(stack).to receive(:status).and_return('DELETE_IN_PROGRESS').
|
476
|
-
exactly(
|
494
|
+
exactly(90).times
|
477
495
|
|
478
496
|
expect { ami_manager.clean_environment }.to raise_error(AwsManager::RetryLimitExceeded)
|
479
497
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vm_shepherd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ops Manager Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-v1
|