-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from Atalanta/support-selection-of-private-ip
Support selection of private ip
- Loading branch information
Showing
8 changed files
with
145 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--style-measure 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ gemspec | |
|
||
group :test do | ||
gem 'rake' | ||
gem 'pry' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
require 'kitchen/driver/ec2' | ||
require 'kitchen/provisioner/dummy' | ||
|
||
describe Kitchen::Driver::Ec2 do | ||
|
||
let(:config) do | ||
{} | ||
end | ||
|
||
let(:state) do | ||
{} | ||
end | ||
|
||
let(:server) do | ||
double(:id => "123", | ||
:wait_for => nil, | ||
:dns_name => "server.example.com", | ||
:private_ip_address => '172.13.16.11', | ||
:public_ip_address => '213.225.123.134') | ||
end | ||
|
||
let(:instance) do | ||
Kitchen::Instance.new(:platform => double(:name => "centos-6.4"), | ||
:suite => double(:name => "default"), | ||
:driver => driver, | ||
:provisioner => Kitchen::Provisioner::Dummy.new({}), | ||
:busser => double("busser"), | ||
:state_file => double("state_file")) | ||
end | ||
|
||
let(:driver) do | ||
Kitchen::Driver::Ec2.new(config) | ||
end | ||
|
||
before do | ||
instance | ||
allow(driver).to receive(:create_server).and_return(server) | ||
allow(driver).to receive(:wait_for_sshd) | ||
end | ||
|
||
context 'Interface is set in config' do | ||
|
||
it 'derives hostname from DNS when specified in the .kitchen.yml' do | ||
config[:interface] = 'dns' | ||
driver.create(state) | ||
expect(state[:hostname]).to eql('server.example.com') | ||
end | ||
|
||
it 'derives hostname from public interface when specified in the .kitchen.yml' do | ||
config[:interface] = 'public' | ||
driver.create(state) | ||
expect(state[:hostname]).to eql('213.225.123.134') | ||
end | ||
|
||
it 'derives hostname from private interface when specified in the .kitchen.yml' do | ||
config[:interface] = 'private' | ||
driver.create(state) | ||
expect(state[:hostname]).to eql('172.13.16.11') | ||
end | ||
|
||
it 'throws a nice exception if the config is bogus' do | ||
config[:interface] = 'I am an idiot' | ||
expect { driver.create(state) }.to raise_error(Kitchen::UserError, 'Invalid interface') | ||
end | ||
|
||
end | ||
|
||
context 'Interface is derived automatically' do | ||
|
||
let(:server) do | ||
double(:id => "123", | ||
:wait_for => nil, | ||
:dns_name => nil, | ||
:private_ip_address => nil, | ||
:public_ip_address => nil) | ||
end | ||
|
||
it 'sets hostname to DNS value if DNS value exists' do | ||
allow(server).to receive(:dns_name).and_return('server.example.com') | ||
driver.create(state) | ||
expect(state[:hostname]).to eql('server.example.com') | ||
end | ||
|
||
it 'sets hostname to public value if public value exists' do | ||
allow(server).to receive(:public_ip_address).and_return('213.225.123.134') | ||
driver.create(state) | ||
|
||
expect(state[:hostname]).to eql('213.225.123.134') | ||
end | ||
|
||
it 'sets hostname to private value if private value exists' do | ||
allow(server).to receive(:private_ip_address).and_return('172.13.16.11') | ||
driver.create(state) | ||
expect(state[:hostname]).to eql('172.13.16.11') | ||
end | ||
|
||
it 'sets hostname to DNS if one or more Public/Private values are set' do | ||
allow(server).to receive(:dns_name).and_return('server.example.com') | ||
allow(server).to receive(:public_ip_address).and_return('213.225.123.134') | ||
allow(server).to receive(:private_ip_address).and_return('172.13.16.11') | ||
driver.create(state) | ||
expect(state[:hostname]).to eql('server.example.com') | ||
end | ||
|
||
end | ||
end |