vm_shepherd 1.7.2 → 1.7.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6846007d4981d1f09863a0c1efaa73667598060
4
- data.tar.gz: 1e102d3be9b16a9d16ef28795a43b55bb3f2cf56
3
+ metadata.gz: ab0c19467d9811ac4ac4b56875e8155e3299390f
4
+ data.tar.gz: e3441beaa08bde0a2556d68b252f87b5725c213d
5
5
  SHA512:
6
- metadata.gz: 3b03d22cf4c7099442b0130c3ab36c50e2b5443bd00f0dd00f600a5e1f821c782ad69405d87d6aa4fc213776f192622636234174513555c6af79bcab329335eb
7
- data.tar.gz: 19ba79193fcfad0c6c41d3dd3b9d80555f11254ce817d5084e4c3b41b1a26f9800f44f41a2dfd786160b7717f5cc6abd18eb6822ee13b3643f7a80e46ae9b7d4
6
+ metadata.gz: b5fd911a4e52484be279df6cffe69b027fd29e2f4db2e4713cd7f22bd3d9e91c963cdd4eed2e9166b1460f66bc96051b3b28d1e66230d9bafa46059438a47c5b
7
+ data.tar.gz: d38f7542b02454852050272cb487ba02a7a64f35edf4bb031d3b3ded01bb65a51ed4f4de9d64e7d4df6d5347a8cabb61ec14887a5d49aaef1de2f0cc9b29ba4b
@@ -103,7 +103,7 @@ module VmShepherd
103
103
  clear_subnet(aws_subnet_id) if aws_subnet_id
104
104
  end
105
105
 
106
- if (elb_config = env_config[:elb])
106
+ env_config.fetch(:elbs, []).each do |elb_config|
107
107
  delete_elb(elb_config[:name])
108
108
  end
109
109
 
@@ -1,3 +1,3 @@
1
1
  module VmShepherd
2
- VERSION = '1.7.2'.freeze
2
+ VERSION = '1.7.3'.freeze
3
3
  end
@@ -143,72 +143,68 @@ module VmShepherd
143
143
  ]
144
144
  end
145
145
  let(:ec2_client) { double(AWS::EC2::Client) }
146
- let(:create_security_group_response) do
147
- {:group_id => 'elb-security-group'}
146
+ let(:create_security_group_response_1) do
147
+ {group_id: 'elb-1-security-group'}
148
+ end
149
+ let(:create_security_group_response_2) do
150
+ {group_id: 'elb-2-security-group'}
148
151
  end
149
152
  let(:security_groups) do
150
153
  {
151
- 'elb-security-group' => elb_security_group,
154
+ 'elb-1-security-group' => elb_1_security_group,
155
+ 'elb-2-security-group' => elb_2_security_group,
152
156
  }
153
157
  end
154
- let(:elb_security_group) { instance_double(AWS::EC2::SecurityGroup, security_group_id: 'elb-security-group-id') }
158
+ let(:elb_1_security_group) { instance_double(AWS::EC2::SecurityGroup, security_group_id: 'elb-1-security-group-id') }
159
+ let(:elb_2_security_group) { instance_double(AWS::EC2::SecurityGroup, security_group_id: 'elb-2-security-group-id') }
155
160
 
156
161
  before do
157
162
  allow(ec2).to receive(:client).and_return(ec2_client)
158
- allow(ec2_client).to receive(:create_security_group).and_return(create_security_group_response)
163
+ allow(ec2_client).to receive(:create_security_group).with(hash_including(group_name: 'fake-stack-name_elb-1-name')).
164
+ and_return(create_security_group_response_1)
165
+ allow(ec2_client).to receive(:create_security_group).with(hash_including(group_name: 'fake-stack-name_elb-2-name')).
166
+ and_return(create_security_group_response_2)
159
167
  allow(ec2).to receive(:security_groups).and_return(security_groups)
160
- allow(elb_security_group).to receive(:authorize_ingress)
168
+ allow(elb_1_security_group).to receive(:authorize_ingress)
169
+ allow(elb_2_security_group).to receive(:authorize_ingress)
161
170
  allow(elb_client).to receive(:create_load_balancer)
162
171
  end
163
172
 
164
- it 'creates and attaches a security group for the first ELB' do
165
- security_group_args = {
173
+ it 'creates and attaches a security group for the ELBs' do
174
+ elb_1_security_group_args = {
166
175
  group_name: 'fake-stack-name_elb-1-name',
167
176
  description: 'ELB Security Group',
168
177
  vpc_id: 'fake-vpc-id',
169
178
  }
170
- expect(ec2_client).to receive(:create_security_group).with(security_group_args).and_return(create_security_group_response)
171
- expect(elb_security_group).to receive(:authorize_ingress).with(:tcp, 1111, '0.0.0.0/0')
172
-
173
- ami_manager.prepare_environment(cloudformation_template_file.path)
174
- end
179
+ expect(ec2_client).to receive(:create_security_group).with(elb_1_security_group_args).and_return(create_security_group_response_1)
180
+ expect(elb_1_security_group).to receive(:authorize_ingress).with(:tcp, 1111, '0.0.0.0/0')
175
181
 
176
- it 'attaches an elb with the name of the stack for the first ELB' do
177
- elb_params = {
178
- load_balancer_name: 'elb-1-name',
179
- listeners: [
180
- {protocol: 'TCP', load_balancer_port: 1111, instance_protocol: 'TCP', instance_port: 11},
181
- ],
182
- subnets: ['fake-subnet-id'],
183
- security_groups: ['elb-security-group-id']
184
- }
185
- expect(elb_client).to receive(:create_load_balancer).with(elb_params)
186
-
187
- ami_manager.prepare_environment(cloudformation_template_file.path)
188
- end
189
-
190
- it 'creates and attaches a security group for the second ELB' do
191
- security_group_args = {
182
+ elb_2_security_group_args = {
192
183
  group_name: 'fake-stack-name_elb-2-name',
193
184
  description: 'ELB Security Group',
194
185
  vpc_id: 'fake-vpc-id',
195
186
  }
196
- expect(ec2_client).to receive(:create_security_group).with(security_group_args).and_return(create_security_group_response)
197
- expect(elb_security_group).to receive(:authorize_ingress).with(:tcp, 2222, '0.0.0.0/0')
187
+ expect(ec2_client).to receive(:create_security_group).with(elb_2_security_group_args).and_return(create_security_group_response_2)
188
+ expect(elb_2_security_group).to receive(:authorize_ingress).with(:tcp, 2222, '0.0.0.0/0')
198
189
 
199
190
  ami_manager.prepare_environment(cloudformation_template_file.path)
200
191
  end
201
192
 
202
- it 'attaches an elb with the name of the stack for the second ELB' do
203
- elb_params = {
204
- load_balancer_name: 'elb-2-name',
205
- listeners: [
206
- {protocol: 'TCP', load_balancer_port: 2222, instance_protocol: 'TCP', instance_port: 22},
207
- ],
193
+ it 'attaches an elb with the name of the stack for the ELBs' do
194
+ elb_1_params = {
195
+ load_balancer_name: 'elb-1-name',
196
+ listeners: [{protocol: 'TCP', load_balancer_port: 1111, instance_protocol: 'TCP', instance_port: 11}],
208
197
  subnets: ['fake-subnet-id'],
209
- security_groups: ['elb-security-group-id']
198
+ security_groups: ['elb-1-security-group-id']
210
199
  }
211
- expect(elb_client).to receive(:create_load_balancer).with(elb_params)
200
+ expect(elb_client).to receive(:create_load_balancer).with(elb_1_params)
201
+ elb_2_params = {
202
+ load_balancer_name: 'elb-2-name',
203
+ listeners: [{protocol: 'TCP', load_balancer_port: 2222, instance_protocol: 'TCP', instance_port: 22}],
204
+ subnets: ['fake-subnet-id'],
205
+ security_groups: ['elb-2-security-group-id']
206
+ }
207
+ expect(elb_client).to receive(:create_load_balancer).with(elb_2_params)
212
208
 
213
209
  ami_manager.prepare_environment(cloudformation_template_file.path)
214
210
  end
@@ -426,69 +422,118 @@ module VmShepherd
426
422
  context 'when an elb is configured' do
427
423
  let(:extra_configs) do
428
424
  {
429
- elb: {
430
- name: 'elb-name',
431
- stack_output_keys: {
432
- subnet_id: 'private_subnet',
433
- },
434
- },
425
+ elbs: [
426
+ {
427
+ name: 'elb-1-name',
428
+ port_mappings: [[1111, 11]],
429
+ stack_output_keys: {
430
+ vpc_id: 'vpc_id',
431
+ subnet_id: 'private_subnet',
432
+ },
433
+ },
434
+ {
435
+ name: 'elb-2-name',
436
+ port_mappings: [[2222, 22]],
437
+ stack_output_keys: {
438
+ vpc_id: 'vpc_id',
439
+ subnet_id: 'private_subnet',
440
+ },
441
+ }
442
+ ],
435
443
  }
436
444
  end
437
445
 
438
- let(:elb) { instance_double(AWS::ELB, load_balancers: [load_balancer_to_delete, other_load_balancer]) }
439
- let(:load_balancer_to_delete) do
446
+ let(:elb) { instance_double(AWS::ELB, load_balancers: [load_balancer_1_to_delete, load_balancer_2_to_delete, other_load_balancer]) }
447
+ let(:load_balancer_1_to_delete) do
448
+ instance_double(AWS::ELB::LoadBalancer,
449
+ name: 'elb-1-name',
450
+ security_groups: [elb_1_security_group],
451
+ exists?: false,
452
+ )
453
+ end
454
+ let(:load_balancer_2_to_delete) do
440
455
  instance_double(AWS::ELB::LoadBalancer,
441
- name: 'elb-name',
442
- security_groups: [elb_security_group],
456
+ name: 'elb-2-name',
457
+ security_groups: [elb_2_security_group],
443
458
  exists?: false,
444
459
  )
445
460
  end
446
461
  let(:other_load_balancer) { instance_double(AWS::ELB::LoadBalancer, name: 'other-elb-name') }
447
- let(:elb_security_group) { instance_double(AWS::EC2::SecurityGroup, name: 'elb-security-group', id: 'sg-id') }
448
- let(:network_interface_1) do
462
+ let(:elb_1_security_group) { instance_double(AWS::EC2::SecurityGroup, name: 'elb-1-security-group', id: 'sg-elb-1-id') }
463
+ let(:elb_2_security_group) { instance_double(AWS::EC2::SecurityGroup, name: 'elb-2-security-group', id: 'sg-elb-2-id') }
464
+ let(:network_interface_1_elb_1) do
465
+ instance_double(AWS::EC2::NetworkInterface,
466
+ security_groups: [elb_1_security_group],
467
+ exists?: false,
468
+ )
469
+ end
470
+ let(:network_interface_2_elb_1) do
471
+ instance_double(AWS::EC2::NetworkInterface,
472
+ security_groups: [elb_1_security_group],
473
+ exists?: false,
474
+ )
475
+ end
476
+ let(:network_interface_1_elb_2) do
449
477
  instance_double(AWS::EC2::NetworkInterface,
450
- security_groups: [elb_security_group],
478
+ security_groups: [elb_2_security_group],
451
479
  exists?: false,
452
480
  )
453
481
  end
454
- let(:network_interface_2) do
482
+ let(:network_interface_2_elb_2) do
455
483
  instance_double(AWS::EC2::NetworkInterface,
456
- security_groups: [elb_security_group],
484
+ security_groups: [elb_2_security_group],
457
485
  exists?: false,
458
486
  )
459
487
  end
460
488
 
461
489
  before do
462
490
  allow(AWS::ELB).to receive(:new).and_return(elb)
463
- allow(ec2).to receive(:network_interfaces).and_return([network_interface_1, network_interface_2])
464
- allow(load_balancer_to_delete).to receive(:delete)
465
- allow(elb_security_group).to receive(:delete)
491
+ allow(ec2).to receive(:network_interfaces).and_return(
492
+ [
493
+ network_interface_1_elb_1,
494
+ network_interface_2_elb_1,
495
+ network_interface_1_elb_2,
496
+ network_interface_2_elb_2,
497
+ ]
498
+ )
499
+ allow(load_balancer_1_to_delete).to receive(:delete)
500
+ allow(load_balancer_2_to_delete).to receive(:delete)
501
+ allow(elb_1_security_group).to receive(:delete)
502
+ allow(elb_2_security_group).to receive(:delete)
466
503
  end
467
504
 
468
- it 'waits for the elb to be deleted' do
469
- expect(load_balancer_to_delete).to receive(:exists?).and_return(true).
505
+ it 'waits for the ELBs to be deleted' do
506
+ expect(load_balancer_1_to_delete).to receive(:exists?).and_return(true).
470
507
  exactly(10).times
508
+ expect(load_balancer_2_to_delete).not_to receive(:exists?)
471
509
 
472
- expect(elb_security_group).not_to receive(:delete).ordered
510
+ expect(elb_1_security_group).not_to receive(:delete).ordered
511
+ expect(elb_2_security_group).not_to receive(:delete).ordered
473
512
  expect { ami_manager.clean_environment }.to raise_error(AwsManager::RetryLimitExceeded)
474
513
  end
475
514
 
476
515
  it 'waits for the network interfaces to be deleted' do
477
- allow(load_balancer_to_delete).to receive(:exists?).and_return(false)
516
+ allow(load_balancer_1_to_delete).to receive(:exists?).and_return(false)
517
+ allow(load_balancer_2_to_delete).to receive(:exists?).and_return(false)
478
518
 
479
- expect(network_interface_1).to receive(:exists?).and_return(false).
519
+ expect(network_interface_1_elb_1).to receive(:exists?).and_return(false).
480
520
  exactly(10).times
481
-
482
- expect(network_interface_2).to receive(:exists?).and_return(true).
521
+ expect(network_interface_2_elb_1).to receive(:exists?).and_return(true).
483
522
  exactly(10).times
523
+ expect(network_interface_1_elb_2).not_to receive(:exists?)
524
+ expect(network_interface_2_elb_2).not_to receive(:exists?)
484
525
 
485
- expect(elb_security_group).not_to receive(:delete).ordered
526
+ expect(elb_1_security_group).not_to receive(:delete).ordered
527
+ expect(elb_2_security_group).not_to receive(:delete).ordered
486
528
  expect { ami_manager.clean_environment }.to raise_error(AwsManager::RetryLimitExceeded)
487
529
  end
488
530
 
489
- it 'terminates the ELB then removes the security group' do
490
- expect(load_balancer_to_delete).to receive(:delete).ordered
491
- expect(elb_security_group).to receive(:delete).ordered
531
+ it 'terminates the ELBs then removes the security group' do
532
+ expect(load_balancer_1_to_delete).to receive(:delete).ordered
533
+ expect(elb_1_security_group).to receive(:delete).ordered
534
+
535
+ expect(load_balancer_2_to_delete).to receive(:delete).ordered
536
+ expect(elb_2_security_group).to receive(:delete).ordered
492
537
 
493
538
  ami_manager.clean_environment
494
539
  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: 1.7.2
4
+ version: 1.7.3
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: 2015-06-23 00:00:00.000000000 Z
11
+ date: 2015-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-v1