Permalink
Browse files

[bosh_agent] removing dhcp dns discovery in favor of resolv.conf

* Updated bosh.yml.erb to use AWS DNS and MicroBosh PowerDNS
  • Loading branch information...
1 parent 0404772 commit f14cb82af9cd9f8bc9f41b39146e4f2f35b17501 Jeffrey Peckham and Vinicius Fuentes committed Mar 29, 2013
@@ -9,18 +9,16 @@ def initialize(template_dir)
@config = Bosh::Agent::Config
@infrastructure = @config.infrastructure
@logger = @config.logger
- @networks = []
- @dns = []
end
def setup_networking
case @config.infrastructure_name
when "vsphere"
setup_networking_from_settings
when "aws"
- setup_dhcp_from_settings
+ write_resolv_conf
when "openstack"
- setup_dhcp_from_settings
+ write_resolv_conf
else
raise Bosh::Agent::FatalError, "Setup networking failed, unsupported infrastructure #{Bosh::Agent::Config.infrastructure_name}"
end
@@ -53,12 +51,6 @@ def setup_networking_from_settings
gratuitous_arp
end
- def setup_dhcp_from_settings
- unless dns.empty?
- write_dhcp_conf
- end
- end
-
def dns
default_dns_network = networks.values.detect do |settings|
settings.fetch('default', []).include?('dns') && settings.has_key?("dns")
@@ -94,7 +86,7 @@ def gratuitous_arp
# after networking has been reconfigured.
Thread.new do
6.times do
- @networks.each do |name, network|
+ networks.values.each do |network|
until File.exist?("/sys/class/net/#{network['interface']}")
sleep 0.1
end
@@ -118,9 +110,9 @@ def write_dhcp_conf
def load_erb(file)
path = File.expand_path(file, @template_dir)
- File.open(path) do |f|
- f.read
- end
+ template_content = File.read(path)
+
+ ERB.new(template_content, 0, '%<>-')
end
end
end
@@ -6,7 +6,7 @@ module Bosh::Agent
class Platform::Rhel::Logrotate < Platform::Linux::Logrotate
def initialize
- super(File.join File.dirname(__FILE__), 'templates')
+ super(File.join(File.dirname(__FILE__), 'templates'))
end
end
@@ -11,8 +11,8 @@ def initialize
end
def write_network_interfaces
- template = ERB.new(load_erb("rhel-ifcfg.erb"), 0, '%<>-')
- networks.each do |name, network|
+ template = load_erb("rhel-ifcfg.erb")
+ networks.each do |name, network| #network is used inside the template
result = template.result(binding)
Bosh::Agent::Util::update_file(result, "/etc/sysconfig/network-scripts/ifcfg-#{name}")
end
@@ -23,21 +23,5 @@ def restart_networking_service
@logger.info("Restarting network")
sh "service network restart"
end
-
- def write_dhcp_conf
- template = ERB.new(load_erb("dhclient_conf.erb"), 0, '%<>-')
- result = template.result(binding)
- updated = Bosh::Agent::Util::update_file(result, '/etc/dhclient.conf')
- if updated
- @logger.info("Updated dhclient.conf")
- restart_dhclient
- end
- end
-
- def restart_dhclient
- @logger.info("Restarting network to restart dhclient")
- sh "service network restart"
- end
-
end
end
@@ -1,56 +0,0 @@
-# Configuration file for /sbin/dhclient, which is included in Debian's
-# dhcp3-client package.
-#
-# This is a sample configuration file for dhclient. See dhclient.conf's
-# man page for more information about the syntax of this file
-# and a more comprehensive list of the parameters understood by
-# dhclient.
-#
-# Normally, if the DHCP server provides reasonable information and does
-# not leave anything out (like the domain name, for example), then
-# few changes must be made to this file, if any.
-#
-
-option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
-
-send host-name "<hostname>";
-#send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;
-#send dhcp-lease-time 3600;
-#supersede domain-name "fugue.com home.vix.com";
-request subnet-mask, broadcast-address, time-offset, routers,
- domain-name, domain-name-servers, domain-search, host-name,
- netbios-name-servers, netbios-scope, interface-mtu,
- rfc3442-classless-static-routes, ntp-servers;
-<% dns.reverse.each do |server| -%>
-prepend domain-name-servers <%= server %>;
-<% end -%>
-
-#require subnet-mask, domain-name-servers;
-#timeout 60;
-#retry 60;
-#reboot 10;
-#select-timeout 5;
-#initial-interval 2;
-#script "/etc/dhcp3/dhclient-script";
-#media "-link0 -link1 -link2", "link0 link1";
-#reject 192.33.137.209;
-
-#alias {
-# interface "eth0";
-# fixed-address 192.5.5.213;
-# option subnet-mask 255.255.255.255;
-#}
-
-#lease {
-# interface "eth0";
-# fixed-address 192.33.137.200;
-# medium "link0 link1";
-# option host-name "andare.swiftmedia.com";
-# option subnet-mask 255.255.255.0;
-# option broadcast-address 192.33.137.255;
-# option routers 192.33.137.250;
-# option domain-name-servers 127.0.0.1;
-# renew 2 2000/1/12 00:00:01;
-# rebind 2 2000/1/12 00:00:01;
-# expire 2 2000/1/12 00:00:01;
-#}
@@ -11,7 +11,7 @@ def initialize
end
def write_network_interfaces
- template = ERB.new(load_erb("interfaces.erb"), 0, '%<>-')
+ template = load_erb("interfaces.erb")
result = template.result(binding)
network_updated = Bosh::Agent::Util::update_file(result, '/etc/network/interfaces')
if network_updated
@@ -22,40 +22,13 @@ def write_network_interfaces
def restart_networking_service
# ubuntu 10.04 networking startup/upstart stuff is quite borked
- networks.each do |k, v|
+ networks.values.each do |v|
interface = v['interface']
@logger.info("Restarting #{interface}")
output = sh("service network-interface stop INTERFACE=#{interface}").output
output += sh("service network-interface start INTERFACE=#{interface}").output
@logger.info("Restarted networking: #{output}")
end
end
-
- def write_dhcp_conf
- template = ERB.new(load_erb("dhclient_conf.erb"), 0, '%<>-')
- result = template.result(binding)
- updated = Bosh::Agent::Util::update_file(result, '/etc/dhcp3/dhclient.conf')
- if updated
- @logger.info("Updated dhclient.conf")
- restart_dhclient
- end
- end
-
- # Executing /sbin/dhclient starts another dhclient process, so it'll cause
- # a conflict with the existing system dhclient process and dns changes will
- # be flip floping each lease time. So in order to refresh dhclient
- # configuration we need to restart networking.
- #
- # If dhclient3 cannot release a lease because it collides with a network
- # restart (message "receive_packet failed on eth0: Network is down"
- # appears at /var/log/syslog) then the old dhclient3 process won't be
- # killed (see bug LP #38140), and there will be two dhclient3 process
- # running (and dns changes will be flip floping each lease time). So
- # before restarting the network, we first kill all dhclient3 process.
- def restart_dhclient
- sh("pkill dhclient3", :on_error => :return)
- sh("/etc/init.d/networking restart", :on_error => :return)
- end
-
end
end
@@ -1,7 +1,7 @@
auto lo
iface lo inet loopback
-<% networks.each do |name, n| -%>
+<% networks.values.each do |n| -%>
auto <%= n["interface"] %>
iface <%= n["interface"] %> inet static
address <%= n["ip"]%>
@@ -106,26 +106,6 @@ def write_network_interfaces
end
end
- context "dhcp network settings" do
- context "when there's a single network" do
- it "sets network settings" do
- network_wrapper.setup_dhcp_from_settings
- network_wrapper.wrote_dhcp_conf.should be_true
- network_wrapper.dns.should == ["172.30.22.153", "172.30.22.154"]
- end
- end
-
- context "when there are multiple networks" do
- it "picks the dns from the 'default' network" do
- Bosh::Agent::Config.settings["networks"].merge!(partial_settings["networks"])
- Bosh::Agent::Config.settings["networks"]["network_a"].delete("default")
- network_wrapper.setup_dhcp_from_settings
- network_wrapper.wrote_dhcp_conf.should be_true
- network_wrapper.dns.should == ["1.2.3.4", "5.6.7.8"]
- end
- end
- end
-
context "Unsupported Infrastructure" do
before do
Bosh::Agent::Config.infrastructure_name = "something not supported"
@@ -138,11 +118,24 @@ def write_network_interfaces
end
end
+ shared_examples_for "network interfaces with resolv.conf" do
+ it "should update the resolv.conf file" do
+ Bosh::Agent::Util.should_receive(:update_file) do |result, file_path|
+ result.should == "nameserver 172.30.22.153\nnameserver 172.30.22.154\n"
+ file_path.should == '/etc/resolv.conf'
+ end
+ network_wrapper.setup_networking
+ end
+ end
+
context "vSphere" do
before do
+ Bosh::Agent::Config.infrastructure_name = "vsphere"
network_wrapper.stub(:detect_mac_addresses).and_return({"00:50:56:89:17:70" => "eth0"})
end
+ it_behaves_like "network interfaces with resolv.conf"
+
it "should fail when the mac address in the spec does not match the instance" do
complete_network["mac"] = "foobar"
expect {
@@ -161,37 +154,21 @@ def write_network_interfaces
network_wrapper.setup_networking
network_wrapper.wrote_network_interfaces.should be_true
end
-
- it "should update the resolv.conf file" do
- Bosh::Agent::Util.should_receive(:update_file) do |result, file_path|
- result.should == "nameserver 172.30.22.153\nnameserver 172.30.22.154\n"
- file_path.should == '/etc/resolv.conf'
- end
- network_wrapper.setup_networking
- end
end
context "AWS" do
- it "should delegate DHCP configuration to platform implementation" do
+ before do
Bosh::Agent::Config.infrastructure_name = "aws"
- Bosh::Agent::Config.instance_variable_set :@infrastructure, nil
- Bosh::Agent::Config.infrastructure.stub(:load_settings).and_return(partial_settings)
- Bosh::Agent::Config.settings = partial_settings
-
- network_wrapper.setup_networking
- network_wrapper.wrote_dhcp_conf.should be_true
end
+
+ it_behaves_like "network interfaces with resolv.conf"
end
context "OpenStack" do
- it "should delegate DHCP configuration to platform implementation" do
+ before do
Bosh::Agent::Config.infrastructure_name = "openstack"
- Bosh::Agent::Config.instance_variable_set :@infrastructure, nil
- Bosh::Agent::Config.infrastructure.stub(:load_settings).and_return(partial_settings)
- Bosh::Agent::Config.settings = partial_settings
-
- network_wrapper.setup_networking
- network_wrapper.wrote_dhcp_conf.should be_true
end
+
+ it_behaves_like "network interfaces with resolv.conf"
end
end
@@ -31,54 +31,5 @@
network_wrapper.setup_networking
end
-
- end
-
- context "AWS" do
- let(:partial_settings) do
- json = %q[{"networks":{"default":{"dns":["1.2.3.4","5.6.7.8"],"default":["gateway","dns"]}}]
- Yajl::Parser.new.parse(json)
- end
-
- before do
- Bosh::Agent::Config.infrastructure_name = "aws"
- Bosh::Agent::Config.instance_variable_set :@infrastructure, nil
- Bosh::Agent::Config.infrastructure.stub(load_settings: partial_settings)
- Bosh::Agent::Config.settings = partial_settings
- end
-
- it "should configure dhcp with dns server prepended" do
- Bosh::Agent::Util.should_receive(:update_file) do |contents, file|
- contents.should match /^prepend domain-name-servers 5\.6\.7\.8;\nprepend domain-name-servers 1\.2\.3\.4;$/
- file.should == "/etc/dhclient.conf"
- true # fake a change
- end
- network_wrapper.should_receive(:restart_dhclient)
-
- network_wrapper.setup_networking
- end
- end
-
- context "OpenStack" do
- let (:partial_settings) do
- json = %q[{"networks":{"default":{"dns":["1.2.3.4"],"default":["gateway","dns"]}}]
- Yajl::Parser.new.parse(json)
- end
-
- it "should configure dhcp with dns server prepended" do
- Bosh::Agent::Config.infrastructure_name = "openstack"
- Bosh::Agent::Config.instance_variable_set :@infrastructure, nil
- Bosh::Agent::Config.infrastructure.stub(load_settings: partial_settings)
- Bosh::Agent::Config.settings = partial_settings
-
- Bosh::Agent::Util.should_receive(:update_file) do |contents, file|
- contents.should match /^prepend domain-name-servers 1\.2\.3\.4;$/
- file.should == "/etc/dhclient.conf"
- true # fake a change
- end
- network_wrapper.should_receive(:restart_dhclient)
-
- network_wrapper.setup_networking
- end
end
end
Oops, something went wrong.

0 comments on commit f14cb82

Please sign in to comment.