summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-07-19 12:37:05 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2016-07-19 12:37:05 -0700
commitdc5aa2759006f7cdb58bd085d64e3a6051b3158e (patch)
treeaf0bc24e8e4e51169593c4e62fdb105b102674d9
parent99c7bbf32fb3dbc1d9e80370a68b256b7e939e0d (diff)
downloadchef-dc5aa2759006f7cdb58bd085d64e3a6051b3158e.tar.gz
replace glibc resolver with ruby resolver
also wires up file providers to reload /etc/reoslv.conf when it changes.
-rw-r--r--lib/chef/application.rb2
-rw-r--r--lib/chef/provider/file.rb7
-rw-r--r--spec/support/shared/unit/provider/file.rb18
3 files changed, 27 insertions, 0 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb
index f8df71f723..f7292d8b38 100644
--- a/lib/chef/application.rb
+++ b/lib/chef/application.rb
@@ -28,6 +28,8 @@ require "mixlib/cli"
require "tmpdir"
require "rbconfig"
require "chef/application/exit_code"
+require "resolv"
+require "resolv-replace"
class Chef
class Application
diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb
index 7f85085eeb..ba08f0f236 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,12 @@ class Chef
end
end
+ def do_resolv_conf_fixup
+ if new_resource.path == "/etc/resolv.conf"
+ 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/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb
index cb539ffbc3..0959406583 100644
--- a/spec/support/shared/unit/provider/file.rb
+++ b/spec/support/shared/unit/provider/file.rb
@@ -683,6 +683,24 @@ 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" do
+ let(:resource_path) { "/etc/resolv.conf" }
+ it "reloads the nameservers" do
+ expect(Resolv::DefaultResolver).to receive(:replace_resolvers)
+ provider.send(:do_resolv_conf_fixup)
+ end
+ end
+ end
end
context "action delete" do