summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2016-02-24 20:53:21 -0800
committerJay Mundrawala <jdmundrawala@gmail.com>2016-02-24 21:27:19 -0800
commit8741f64af2120c9bde40e98464e9724130dd9b80 (patch)
treef09edf491d228778534927d1be7d13ab183c3981
parentdf7683d77a25b8a64c683cf14a686d6c41134432 (diff)
downloadchef-8741f64af2120c9bde40e98464e9724130dd9b80.tar.gz
Refactor application/client.rb to use DotD mixin for loading client.d
-rw-r--r--lib/chef/application/client.rb28
-rw-r--r--spec/unit/application/client_spec.rb10
2 files changed, 8 insertions, 30 deletions
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb
index 9d67754325..8f30037ac7 100644
--- a/lib/chef/application/client.rb
+++ b/lib/chef/application/client.rb
@@ -26,9 +26,11 @@ require "chef/config_fetcher"
require "chef/handler/error_report"
require "chef/workstation_config_loader"
require "chef/mixin/shell_out"
+require "chef-config/mixin/dot_d"
class Chef::Application::Client < Chef::Application
include Chef::Mixin::ShellOut
+ include ChefConfig::Mixin::DotD
# Mimic self_pipe sleep from Unicorn to capture signals safely
SELF_PIPE = []
@@ -377,7 +379,7 @@ class Chef::Application::Client < Chef::Application
super
# Load all config files in client.d
- load_config_d_directory
+ load_dot_d(Chef::Config[:client_d_dir]) if Chef::Config[:client_d_dir]
end
def configure_logging
@@ -508,28 +510,4 @@ class Chef::Application::Client < Chef::Application
end
end
end
-
- def load_config_d_directory
- list_config_d_files.sort.each do |conf|
- if File.file?(conf)
- load_config_d_file(conf)
- end
- end
- end
-
- def load_config_d_file(f)
- config_fetcher = Chef::ConfigFetcher.new(f)
- config_fetcher.read_local_config.tap do |config_content|
- apply_config(config_content, f)
- end
- end
-
- def list_config_d_files
- if Chef::Config[:client_d_dir]
- Dir.glob(File.join(Chef::Util::PathHelper.escape_glob_dir(
- Chef::Config[:client_d_dir]), "*.rb"))
- else
- []
- end
- end
end
diff --git a/spec/unit/application/client_spec.rb b/spec/unit/application/client_spec.rb
index 834c7777f0..f742d24e24 100644
--- a/spec/unit/application/client_spec.rb
+++ b/spec/unit/application/client_spec.rb
@@ -278,11 +278,11 @@ Enable chef-client interval runs by setting `:client_fork = true` in your config
File.join(File.dirname(__FILE__), "../../data/client.d_00")) }
it "loads the configuration in order" do
-
- expect(::File).to receive(:read).with(Pathname.new("#{client_d_dir}/00-foo.rb").cleanpath.to_s).and_return("")
- expect(::File).to receive(:read).with(Pathname.new("#{client_d_dir}/01-bar.rb").cleanpath.to_s).and_return("")
- expect(app).to receive(:load_config_d_file).with(Pathname.new("#{client_d_dir}/00-foo.rb").cleanpath.to_s).and_call_original.ordered
- expect(app).to receive(:load_config_d_file).with(Pathname.new("#{client_d_dir}/01-bar.rb").cleanpath.to_s).and_call_original.ordered
+ expect(IO).to receive(:read).with(Pathname.new("#{client_d_dir}/00-foo.rb").cleanpath.to_s).and_return("foo 0")
+ expect(IO).to receive(:read).with(Pathname.new("#{client_d_dir}/01-bar.rb").cleanpath.to_s).and_return("bar 0")
+ allow(app).to receive(:apply_config).with(anything(), Chef::Config.platform_specific_path("/etc/chef/client.rb")).and_call_original.ordered
+ expect(app).to receive(:apply_config).with("foo 0", Pathname.new("#{client_d_dir}/00-foo.rb").cleanpath.to_s).and_call_original.ordered
+ expect(app).to receive(:apply_config).with("bar 0", Pathname.new("#{client_d_dir}/01-bar.rb").cleanpath.to_s).and_call_original.ordered
app.reconfigure
end
end