diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-07-19 14:49:41 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-07-19 14:49:41 -0700 |
commit | bad96f846718685302fec9e627471b68cd9bab8f (patch) | |
tree | 389123e360546449c87ea051d2cc2539d0f2cc01 | |
parent | dc5aa2759006f7cdb58bd085d64e3a6051b3158e (diff) | |
download | chef-bad96f846718685302fec9e627471b68cd9bab8f.tar.gz |
only work around resolver caching on linux
it should be the only O/S which needs it due to the way its glibc
was written. it is the only O/S that we've recieved any bugs for.
-rw-r--r-- | lib/chef/application.rb | 4 | ||||
-rw-r--r-- | lib/chef/provider/file.rb | 3 | ||||
-rw-r--r-- | spec/spec_helper.rb | 1 | ||||
-rw-r--r-- | spec/support/platform_helpers.rb | 4 | ||||
-rw-r--r-- | spec/support/shared/unit/provider/file.rb | 11 |
5 files changed, 19 insertions, 4 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb index f7292d8b38..6c2fc8b11b 100644 --- a/lib/chef/application.rb +++ b/lib/chef/application.rb @@ -29,7 +29,9 @@ require "tmpdir" require "rbconfig" require "chef/application/exit_code" require "resolv" -require "resolv-replace" +# 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 ba08f0f236..bb0762ceb7 100644 --- a/lib/chef/provider/file.rb +++ b/lib/chef/provider/file.rb @@ -447,7 +447,8 @@ class Chef end def do_resolv_conf_fixup - if new_resource.path == "/etc/resolv.conf" + # 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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2f6747c9af..55b0a9c3f6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -152,6 +152,7 @@ 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 :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 0959406583..9f84111eac 100644 --- a/spec/support/shared/unit/provider/file.rb +++ b/spec/support/shared/unit/provider/file.rb @@ -693,13 +693,20 @@ shared_examples_for Chef::Provider::File do end end end - context "when managing /etc/resolv.conf" do + context "when managing /etc/resolv.conf", linux_only: true do let(:resource_path) { "/etc/resolv.conf" } - it "reloads the nameservers" do + 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", linux_only: false 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 |