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 support for looking up Private DNS Name for hostname #197

Merged
merged 5 commits into from
Feb 16, 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
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,21 @@ If you don't set this it will default to whatever DHCP address EC2 hands out.

### interface

The place from which to derive the hostname for communicating with the instance. May be `dns`, `public` or `private`. If this is unset, the driver will derive the hostname by failing back in the following order:
The place from which to derive the hostname for communicating with the instance. May be `dns`, `public`, `private` or `private_dns`. If this is unset, the driver will derive the hostname by failing back in the following order:

1. DNS Name
2. Public IP Address
3. Private IP Address
4. Private DNS Name

The default is unset.
The default is unset. Under normal circumstances, the lookup will return the `Private IP Address`.

If the `Private DNS Name` is preferred over the private IP, it must be specified in the `.kitchen.yml` file

```ruby
driver:
interface: private_dns
```

### ssh\_key

Expand Down
3 changes: 2 additions & 1 deletion lib/kitchen/driver/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ def amis
{
"dns" => "public_dns_name",
"public" => "public_ip_address",
"private" => "private_ip_address"
"private" => "private_ip_address",
"private_dns" => "private_dns_name"
}

#
Expand Down
25 changes: 25 additions & 0 deletions spec/kitchen/driver/ec2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@

describe "#hostname" do
let(:public_dns_name) { nil }
let(:private_dns_name) { nil }
let(:public_ip_address) { nil }
let(:private_ip_address) { nil }
let(:server) {
double("server",
:public_dns_name => public_dns_name,
:private_dns_name => private_dns_name,
:public_ip_address => public_ip_address,
:private_ip_address => private_ip_address
)
Expand All @@ -122,9 +124,23 @@
it "returns private_ip_address when requested" do
expect(driver.hostname(server, "private")).to eq(private_ip_address)
end
it "returns private_dns_name when requested" do
expect(driver.hostname(server, "private_dns")).to eq(private_dns_name)
end
end

context "private_dns_name is populated" do
let(:private_dns_name) { "private_dns_name" }

it "returns the private_dns_name" do
expect(driver.hostname(server)).to eq(private_dns_name)
end

include_examples "an interface type provided"
end

context "private_ip_address is populated" do
let(:private_dns_name) { "private_dns_name" }
let(:private_ip_address) { "10.0.0.1" }

it "returns the private_ip_address" do
Expand All @@ -135,6 +151,7 @@
end

context "public_ip_address is populated" do
let(:private_dns_name) { "private_dns_name" }
let(:private_ip_address) { "10.0.0.1" }
let(:public_ip_address) { "127.0.0.1" }

Expand All @@ -146,6 +163,7 @@
end

context "public_dns_name is populated" do
let(:private_dns_name) { "private_dns_name" }
let(:private_ip_address) { "10.0.0.1" }
let(:public_ip_address) { "127.0.0.1" }
let(:public_dns_name) { "public_dns_name" }
Expand All @@ -168,6 +186,13 @@
it "returns the private_ip_address" do
expect(driver.hostname(server)).to eq(private_ip_address)
end

context "and private_dns_name is populated" do
let(:private_dns_name) { "private_dns_name" }
it "returns the private_ip_address" do
expect(driver.hostname(server)).to eq(private_ip_address)
end
end
end
end
end
Expand Down