diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-07-19 18:46:39 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-19 18:46:39 -0500 |
commit | e8877cd363642ed6757c48d1ed5ab35509d87e22 (patch) | |
tree | 52b1b692f10cf1b47c97ad24c02e5791aea0d276 | |
parent | 162d988d3bcfce2773ef2831fa33e416f53731f6 (diff) | |
parent | 98008c673829d3dd361cc8f0a59dbe51e4a19f9d (diff) | |
download | chef-e8877cd363642ed6757c48d1ed5ab35509d87e22.tar.gz |
Merge pull request #5123 from chef/lcg/resolv-replace
replace glibc resolver with ruby resolver
-rw-r--r-- | lib/chef/application.rb | 4 | ||||
-rw-r--r-- | lib/chef/provider/file.rb | 8 | ||||
-rw-r--r-- | spec/spec_helper.rb | 2 | ||||
-rw-r--r-- | spec/support/platform_helpers.rb | 4 | ||||
-rw-r--r-- | spec/support/shared/unit/provider/file.rb | 25 |
5 files changed, 43 insertions, 0 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb index f8df71f723..6c2fc8b11b 100644 --- a/lib/chef/application.rb +++ b/lib/chef/application.rb @@ -28,6 +28,10 @@ require "mixlib/cli" require "tmpdir" require "rbconfig" require "chef/application/exit_code" +require "resolv" +# on linux, we replace the glibc resolver with the ruby resolv library, which +# supports reloading. +require "resolv-replace" if RbConfig::CONFIG["host_os"] =~ /linux/ class Chef class Application diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb index 7f85085eeb..bb0762ceb7 100644 --- a/lib/chef/provider/file.rb +++ b/lib/chef/provider/file.rb @@ -154,6 +154,7 @@ class Chef do_contents_changes do_acl_changes do_selinux + do_resolv_conf_fixup load_resource_attributes_from_file(@new_resource) end @@ -445,6 +446,13 @@ class Chef end end + def do_resolv_conf_fixup + # reload /etc/resolv.conf after we edit it -- only on linux -- and see lib/chef/application.rb + if new_resource.path == "/etc/resolv.conf" && RbConfig::CONFIG["host_os"] =~ /linux/ + Resolv::DefaultResolver.replace_resolvers [Resolv::DNS.new("/etc/resolv.conf")] + end + end + def do_acl_changes if access_controls.requires_changes? converge_by(access_controls.describe_changes) do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2f6747c9af..44a599436c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -152,6 +152,8 @@ RSpec.configure do |config| config.filter_run_excluding :unix_only => true unless unix? config.filter_run_excluding :aix_only => true unless aix? config.filter_run_excluding :debian_family_only => true unless debian_family? + config.filter_run_excluding :linux_only => true unless linux? + config.filter_run_excluding :non_linux_only => true if linux? config.filter_run_excluding :supports_cloexec => true unless supports_cloexec? config.filter_run_excluding :selinux_only => true unless selinux_enabled? config.filter_run_excluding :requires_root => true unless root? diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb index 9ba56a15e3..783429161a 100644 --- a/spec/support/platform_helpers.rb +++ b/spec/support/platform_helpers.rb @@ -138,6 +138,10 @@ def freebsd? !!(RUBY_PLATFORM =~ /freebsd/) end +def linux? + !!(RUBY_PLATFORM =~ /linux/) +end + def debian_family? !!(ohai[:platform_family] == "debian") end diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb index cb539ffbc3..ee3438da70 100644 --- a/spec/support/shared/unit/provider/file.rb +++ b/spec/support/shared/unit/provider/file.rb @@ -683,6 +683,31 @@ shared_examples_for Chef::Provider::File do end end + context "do_resolv_conf_fixup" do + %w{/resolv.conf /etc/resolv.con /etc/foo/resolv.conf /c/resolv.conf}.each do |path| + context "when managing #{path}" do + let(:resource_path) { path } + it "does not reload the nameservers" do + expect(Resolv::DefaultResolver).not_to receive(:replace_resolvers) + provider.send(:do_resolv_conf_fixup) + end + end + end + context "when managing /etc/resolv.conf", linux_only: true do + let(:resource_path) { "/etc/resolv.conf" } + it "reloads the nameservers on linux" do + expect(Resolv::DefaultResolver).to receive(:replace_resolvers) + provider.send(:do_resolv_conf_fixup) + end + end + context "when managing /etc/resolv.conf", non_linux_only: true do + let(:resource_path) { "/etc/resolv.conf" } + it "does not reload the nameservers on non-linux" do + expect(Resolv::DefaultResolver).not_to receive(:replace_resolvers) + provider.send(:do_resolv_conf_fixup) + end + end + end end context "action delete" do |