summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2016-11-23 11:52:10 -0500
committerGitHub <noreply@github.com>2016-11-23 11:52:10 -0500
commit92041a5853cc9cc9b05c9f46f8becba4c5ba3656 (patch)
tree8510b793bb731054982b14edecfb9190f94b1c90
parentd072af9f1d64981130bf9c16339f19057f20662f (diff)
parent63a6d5e5f24e26662d520b366b8604b81b757c3a (diff)
downloadchef-92041a5853cc9cc9b05c9f46f8becba4c5ba3656.tar.gz
Merge pull request #5502 from MsysTechnologiesllc/dheeraj/configurable_log_details
Knife Bootstrap: Passing config_log_level and config_log_location from config.rb
-rw-r--r--lib/chef/knife/core/bootstrap_context.rb26
-rw-r--r--spec/unit/knife/core/bootstrap_context_spec.rb60
2 files changed, 80 insertions, 6 deletions
diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb
index b2670f196b..ceb067d48d 100644
--- a/lib/chef/knife/core/bootstrap_context.rb
+++ b/lib/chef/knife/core/bootstrap_context.rb
@@ -67,12 +67,36 @@ class Chef
@trusted_certs ||= trusted_certs_content
end
+ def get_log_location
+ if !(@chef_config[:config_log_location].class == IO ) && (@chef_config[:config_log_location].nil? || @chef_config[:config_log_location].to_s.empty?)
+ "STDOUT"
+ elsif @chef_config[:config_log_location].equal?(:win_evt)
+ raise "The value :win_evt is not supported for config_log_location on Linux Platforms \n"
+ elsif @chef_config[:config_log_location].equal?(:syslog)
+ ":syslog"
+ elsif @chef_config[:config_log_location].equal?(STDOUT)
+ "STDOUT"
+ elsif @chef_config[:config_log_location].equal?(STDERR)
+ "STDERR"
+ elsif @chef_config[:config_log_location]
+ %Q{"#{@chef_config[:config_log_location]}"}
+ else
+ "STDOUT"
+ end
+ end
+
def config_content
client_rb = <<-CONFIG
-log_location STDOUT
chef_server_url "#{@chef_config[:chef_server_url]}"
validation_client_name "#{@chef_config[:validation_client_name]}"
CONFIG
+
+ if !(@chef_config[:config_log_level].nil? || @chef_config[:config_log_level].empty?)
+ client_rb << %Q{log_level :#{@chef_config[:config_log_level]}\n}
+ end
+
+ client_rb << "log_location #{get_log_location}\n"
+
if @config[:chef_node_name]
client_rb << %Q{node_name "#{@config[:chef_node_name]}"\n}
else
diff --git a/spec/unit/knife/core/bootstrap_context_spec.rb b/spec/unit/knife/core/bootstrap_context_spec.rb
index 6465e18ac9..515381cf6e 100644
--- a/spec/unit/knife/core/bootstrap_context_spec.rb
+++ b/spec/unit/knife/core/bootstrap_context_spec.rb
@@ -30,6 +30,8 @@ describe Chef::Knife::Core::BootstrapContext do
let(:run_list) { Chef::RunList.new("recipe[tmux]", "role[base]") }
let(:chef_config) do
{
+ :config_log_level => "info",
+ :config_log_location => "/tmp/log",
:validation_key => File.join(CHEF_SPEC_DATA, "ssl", "private_key.pem"),
:chef_server_url => "http://chef.example.com:4444",
:validation_client_name => "chef-validator-testing",
@@ -68,18 +70,15 @@ describe Chef::Knife::Core::BootstrapContext do
it "generates the config file data" do
expected = <<-EXPECTED
-log_location STDOUT
chef_server_url "http://chef.example.com:4444"
validation_client_name "chef-validator-testing"
+log_level :info
+log_location "/tmp/log"
# Using default node name (fqdn)
EXPECTED
expect(bootstrap_context.config_content).to eq expected
end
- it "does not set a default log_level" do
- expect(bootstrap_context.config_content).not_to match(/log_level/)
- end
-
describe "alternate chef-client path" do
let(:chef_config) { { :chef_client_path => "/usr/local/bin/chef-client" } }
it "runs chef-client from another path when specified" do
@@ -254,4 +253,55 @@ EXPECTED
end
end
+ describe "#config_log_location" do
+ context "when config_log_location is nil" do
+ let(:chef_config) { { :config_log_location => nil } }
+ it "sets the default config_log_location in the client.rb" do
+ expect(bootstrap_context.get_log_location).to eq "STDOUT"
+ end
+ end
+
+ context "when config_log_location is empty" do
+ let(:chef_config) { { :config_log_location => "" } }
+ it "sets the default config_log_location in the client.rb" do
+ expect(bootstrap_context.get_log_location).to eq "STDOUT"
+ end
+ end
+
+ context "when config_log_location is :win_evt" do
+ let(:chef_config) { { :config_log_location => :win_evt } }
+ it "raise error when config_log_location is :win_evt " do
+ expect { bootstrap_context.get_log_location }.to raise_error("The value :win_evt is not supported for config_log_location on Linux Platforms \n")
+ end
+ end
+
+ context "when config_log_location is :syslog" do
+ let(:chef_config) { { :config_log_location => :syslog } }
+ it "sets the config_log_location value as :syslog in the client.rb" do
+ expect(bootstrap_context.get_log_location).to eq ":syslog"
+ end
+ end
+
+ context "When config_log_location is STDOUT" do
+ let(:chef_config) { { :config_log_location => STDOUT } }
+ it "Sets the config_log_location value as STDOUT in the client.rb" do
+ expect(bootstrap_context.get_log_location).to eq "STDOUT"
+ end
+ end
+
+ context "when config_log_location is STDERR" do
+ let(:chef_config) { { :config_log_location => STDERR } }
+ it "sets the config_log_location value as STDERR in the client.rb" do
+ expect(bootstrap_context.get_log_location).to eq "STDERR"
+ end
+ end
+
+ context "when config_log_location is a path" do
+ let(:chef_config) { { :config_log_location => "/tmp/ChefLogFile" } }
+ it "sets the config_log_location path in the client.rb" do
+ expect(bootstrap_context.get_log_location).to eq "\"/tmp/ChefLogFile\""
+ end
+ end
+
+ end
end