Skip to content

Commit

Permalink
Issue vagrant-landrush#176 Making solution for skipping of reverse DN…
Browse files Browse the repository at this point in the history
…S entry creation for CNAMES more readable. Adding tests.
  • Loading branch information
hferentschik committed Jul 1, 2016
1 parent 4e421a0 commit 20db122
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
9 changes: 9 additions & 0 deletions features/dns_resolution.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ Feature: dns_resolution
And the hostname "my-host.landrush-acceptance-test" should resolve to "10.10.10.123" on the host
And the hostname "my-host.landrush-acceptance-test" should resolve to "10.10.10.123" on the guest

When I successfully run `bundle exec vagrant landrush set my-static-host.landrush-acceptance-test 42.42.42.42`
Then the hostname "my-static-host.landrush-acceptance-test" should resolve to "42.42.42.42" on the internal DNS server
And the hostname "my-static-host.landrush-acceptance-test" should resolve to "42.42.42.42" on the host
And the hostname "my-static-host.landrush-acceptance-test" should resolve to "42.42.42.42" on the guest

When I successfully run `bundle exec vagrant landrush set my-static-cname-host.landrush-acceptance-test my-static-host.landrush-acceptance-test`
Then the hostname "my-static-cname-host.landrush-acceptance-test" should resolve to "42.42.42.42" on the internal DNS server
And the hostname "my-static-cname-host.landrush-acceptance-test" should resolve to "42.42.42.42" on the host

Examples:
| box | provider |
| debian/jessie64 | virtualbox |
Expand Down
1 change: 0 additions & 1 deletion landrush.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ Gem::Specification.new do |spec|

spec.add_dependency 'rubydns', '0.8.5'
spec.add_dependency 'win32-process'
spec.add_dependency 'json'
spec.add_dependency 'landrush-ip', '~> 0.2.3'
end
24 changes: 13 additions & 11 deletions lib/landrush/action/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def call(env)
post_boot_setup if enabled?
end

def host_ip_address
static_private_network_ip || machine.guest.capability(:read_host_visible_ip_address)
end

private

def pre_boot_setup
record_dependent_vm
add_prerequisite_network_interface
Expand Down Expand Up @@ -67,19 +73,19 @@ def setup_static_dns
config.hosts.each do |hostname, dns_value|
dns_value ||= host_ip_address
unless Store.hosts.has?(hostname, dns_value)
info "adding static entry: #{hostname} => #{dns_value}"
info "adding static DNS entry: #{hostname} => #{dns_value}"
Store.hosts.set hostname, dns_value
unless static_dns_ip_address(dns_value).nil?
Store.hosts.set(IPAddr.new(dns_value).reverse, hostname)
if ip_address?(dns_value)
reverse_dns = IPAddr.new(dns_value).reverse
info "adding static reverse DNS entry: #{reverse_dns} => #{dns_value}"
Store.hosts.set(reverse_dns, hostname)
end
end
end
end

def static_dns_ip_address(dns_value)
return IPAddr.new(dns_value)
rescue StandardError
return nil
def ip_address?(value)
!(value =~ Resolv::IPv4::Regex).nil?
end

def record_machine_dns_entry
Expand All @@ -97,10 +103,6 @@ def record_machine_dns_entry
end
end

def host_ip_address
static_private_network_ip || machine.guest.capability(:read_host_visible_ip_address)
end

def private_network_exists?
machine.config.vm.networks.any? { |type, _| type == :private_network }
end
Expand Down
18 changes: 9 additions & 9 deletions test/landrush/action/setup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,32 @@ module Action
env[:machine].config.vm.network :private_network, ip: '42.42.42.42'

setup.call(env)
setup.static_private_network_ip.must_equal '42.42.42.42'
Store.hosts.get('somehost.vagrant.test').must_equal '42.42.42.42'
end

it "for multiple private network IPs host visible IP cannot be retrieved w/o starting the VM" do
it "for multiple private network IPs host visible IP cant be retrieved if host_ip_address is set" do
skip('Not working on Windows, since it will also do the network config') if Vagrant::Util::Platform.windows?
app = proc {}
setup = Setup.new(app, nil)
env = fake_environment

env[:machine].config.vm.network :private_network, ip: '42.42.42.41'
env[:machine].config.vm.network :private_network, ip: '42.42.42.42'

env[:machine].config.landrush.host_ip_address = '42.42.42.42'
setup.call(env)
setup.static_private_network_ip.must_be_nil
Store.hosts.get('somehost.vagrant.test').must_equal '42.42.42.42'
end

it "for multiple private network IPs host visible IP cant be retrieved if host_ip_address is set" do
it "is possible to add cnames via the config.landrush.host configuration option" do
skip('Not working on Windows, since it will also do the network config') if Vagrant::Util::Platform.windows?
app = proc {}
setup = Setup.new(app, nil)
env = fake_environment

env[:machine].config.vm.network :private_network, ip: '42.42.42.41'
env[:machine].config.vm.network :private_network, ip: '42.42.42.42'
env[:machine].config.landrush.host_ip_address = '42.42.42.42'
env[:machine].config.landrush.host 'foo', 'bar'
setup.call(env)
setup.static_private_network_ip.must_equal '42.42.42.42'

Store.hosts.get('foo').must_equal 'bar'
end

describe 'after boot' do
Expand Down

0 comments on commit 20db122

Please sign in to comment.