Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the ability to set the network property 'source/destination check' #38

Merged
merged 2 commits into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/bosh_aws_cpi/lib/cloud/aws/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def disassociate_elastic_ip
@aws_instance.disassociate_elastic_ip
end

def source_dest_check=(state)
@aws_instance.source_dest_check = state
end

def wait_for_running
# If we time out, it is because the instance never gets from state running to started,
# so we signal the director that it is ok to retry the operation. At the moment this
Expand Down
1 change: 1 addition & 0 deletions src/bosh_aws_cpi/lib/cloud/aws/instance_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def create(agent_id, stemcell_id, resource_pool, networks_spec, disk_locality, e
instance.wait_for_running
instance.attach_to_load_balancers(resource_pool['elbs'] || [])
instance.update_routing_tables(resource_pool['advertised_routes'] || [])
instance.source_dest_check = resource_pool.fetch('source_dest_check', true)
rescue => e
@logger.warn("Failed to configure instance '#{instance.id}': #{e.inspect}")
begin
Expand Down
3 changes: 2 additions & 1 deletion src/bosh_aws_cpi/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def mock_cloud_options
'region' => 'us-east-1',
'default_key_name' => 'sesame',
'default_security_groups' => [],
'max_retries' => 8
'max_retries' => 8,
'source_dest_check' => false
},
'registry' => {
'endpoint' => 'localhost:42288',
Expand Down
10 changes: 8 additions & 2 deletions src/bosh_aws_cpi/spec/unit/instance_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ module Bosh::AwsCloud
let(:stemcell_id) { 'stemcell-id' }
let(:resource_pool) { {
'instance_type' => 'm1.small',
'availability_zone' => 'us-east-1a'
'availability_zone' => 'us-east-1a',
'source_dest_check' => false
} }
let(:networks_spec) do
{
Expand Down Expand Up @@ -90,6 +91,7 @@ module Bosh::AwsCloud
it 'should ask AWS to create an instance in the given region, with parameters built up from the given arguments' do
instance_manager = InstanceManager.new(ec2, registry, elb, param_mapper, block_device_manager, logger)
allow(instance_manager).to receive(:get_created_instance_id).with("run-instances-response").and_return('i-12345678')
allow(aws_instance).to receive(:source_dest_check=).with(false)

expect(aws_client).to receive(:run_instances).with({ fake: 'instance-params', min_count: 1, max_count: 1 }).and_return("run-instances-response")
instance_manager.create(
Expand All @@ -111,6 +113,7 @@ module Bosh::AwsCloud

it 'should ask AWS to create a SPOT instance in the given region, when resource_pool includes spot_bid_price' do
allow(ec2).to receive(:client).and_return(aws_client)
allow(aws_instance).to receive(:source_dest_check=).with(true)

# need to translate security group names to security group ids
sg1 = instance_double('AWS::EC2::SecurityGroup', id:'sg-baz-1234')
Expand Down Expand Up @@ -193,6 +196,7 @@ module Bosh::AwsCloud
end

it 'creates an on demand instance' do
allow(aws_instance).to receive(:source_dest_check=).with(true)
expect(aws_client).to receive(:run_instances)
.with({ fake: 'instance-params', min_count: 1, max_count: 1 })

Expand All @@ -209,6 +213,7 @@ module Bosh::AwsCloud

it 'does not log a warning' do
expect(logger).to_not receive(:warn)
allow(aws_instance).to receive(:source_dest_check=).with(true)

instance_manager.create(
agent_id,
Expand All @@ -233,6 +238,7 @@ module Bosh::AwsCloud
expect(aws_client).to receive(:run_instances).with({ fake: 'instance-params', min_count: 1, max_count: 1 }).and_return("run-instances-response")

allow(ResourceWait).to receive(:for_instance).with(instance: aws_instance, state: :running)
allow(aws_instance).to receive(:source_dest_check=).with(false)
expect(logger).to receive(:warn).with(/IP address was in use/).once

instance_manager.create(
Expand All @@ -246,7 +252,7 @@ module Bosh::AwsCloud
)
end

context 'when waiting it to become running fails' do
context 'when waiting for the instance to be running fails' do
let(:instance) { instance_double('Bosh::AwsCloud::Instance', id: 'fake-instance-id') }
let(:create_err) { StandardError.new('fake-err') }

Expand Down
12 changes: 12 additions & 0 deletions src/bosh_aws_cpi/spec/unit/instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ module Bosh::AwsCloud
end
end

describe '#source_dest_check=' do
it 'propagates source_dest_check= true' do
expect(aws_instance).to receive(:source_dest_check=).with(false)
instance.source_dest_check = false
end

it 'propagates source_dest_check= false' do
expect(aws_instance).to receive(:source_dest_check=).with(true)
instance.source_dest_check = true
end
end

describe '#attach_to_load_balancers' do
before { allow(elb).to receive(:load_balancers).and_return(load_balancers) }
let(:load_balancers) { { 'fake-lb1-id' => load_balancer1, 'fake-lb2-id' => load_balancer2 } }
Expand Down