summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2020-03-11 19:12:34 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2020-03-11 19:12:34 -0700
commit34a1d7eec7206029c663d56097ba738a63608c31 (patch)
treea9d56b7a31a9a14688fc5d3e5d169b9caec8fdc8
parentdfd018cb04a2eae78e5cd8f7569dff4919e3769a (diff)
downloadchef-34a1d7eec7206029c663d56097ba738a63608c31.tar.gz
fix ruby 2.7 encoding bug and add --always-dump-stacktrace option
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--chef-config/lib/chef-config/config.rb5
-rw-r--r--kitchen-tests/kitchen.yml9
-rw-r--r--lib/chef/application.rb8
-rw-r--r--lib/chef/application/apply.rb6
-rw-r--r--lib/chef/application/base.rb8
-rw-r--r--lib/chef/provider/file.rb4
6 files changed, 30 insertions, 10 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb
index a0b37a05ee..8d6d6e8923 100644
--- a/chef-config/lib/chef-config/config.rb
+++ b/chef-config/lib/chef-config/config.rb
@@ -4,7 +4,7 @@
# Author:: AJ Christensen (<aj@chef.io>)
# Author:: Mark Mzyk (<mmzyk@chef.io>)
# Author:: Kyle Goodwin (<kgoodwin@primerevenue.com>)
-# Copyright:: Copyright 2008-2019, Chef Software Inc.
+# Copyright:: Copyright 2008-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -400,6 +400,9 @@ module ChefConfig
# Using `force_logger` causes chef to default to logger output when STDOUT is a tty
default :force_logger, false
+ # When set to true always print the stacktrace even if we haven't done -l debug
+ default :always_dump_stacktrace, false
+
# Using 'stream_execute_output' will have Chef always stream the execute output
default :stream_execute_output, false
diff --git a/kitchen-tests/kitchen.yml b/kitchen-tests/kitchen.yml
index 4e182db958..8a8e749b84 100644
--- a/kitchen-tests/kitchen.yml
+++ b/kitchen-tests/kitchen.yml
@@ -12,21 +12,22 @@ provisioner:
name: dokken
client_rb:
diff_disabled: true
+ always_dump_stacktrace: true
chef_license: "accept-no-persist"
lifecycle:
pre_converge:
- remote: echo "Chef container's Chef / Ohai release:"
- - remote: /opt/chef/embedded/bin/chef-client -v
- - remote: /opt/chef/embedded/bin/ohai -v
+ - remote: /opt/chef/bin/chef-client -v
+ - remote: /opt/chef/bin/ohai -v
- remote: /opt/chef/embedded/bin/rake --version
- remote: /opt/chef/embedded/bin/bundle -v
- remote: /opt/chef/embedded/bin/gem install appbundler appbundle-updater --no-doc
- remote: /opt/chef/embedded/bin/appbundle-updater chef ohai <%= File.readlines('../Gemfile.lock', File.expand_path(File.dirname(__FILE__))).find { |l| l =~ /^\s+ohai \((\d+\.\d+\.\d+)\)/ }; 'v' + $1 %> --tarball --github chef/ohai
- remote: /opt/chef/embedded/bin/appbundle-updater chef chef <%= ENV['BUILDKITE_COMMIT'] || %x(git rev-parse HEAD).chomp %> --tarball --github chef/chef
- remote: echo "Installed Chef / Ohai release:"
- - remote: /opt/chef/embedded/bin/chef-client -v
- - remote: /opt/chef/embedded/bin/ohai -v
+ - remote: /opt/chef/bin/chef-client -v
+ - remote: /opt/chef/bin/ohai -v
verifier:
name: inspec
diff --git a/lib/chef/application.rb b/lib/chef/application.rb
index 197ae20c6d..02d4a4bacb 100644
--- a/lib/chef/application.rb
+++ b/lib/chef/application.rb
@@ -1,7 +1,7 @@
#
# Author:: AJ Christensen (<aj@chef.io>)
# Author:: Mark Mzyk (mmzyk@chef.io)
-# Copyright:: Copyright 2008-2019, Chef Software Inc.
+# Copyright:: Copyright 2008-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -392,7 +392,11 @@ class Chef
Chef::FileCache.store("#{Chef::Dist::SHORT}-stacktrace.out", chef_stacktrace_out)
logger.fatal("Stacktrace dumped to #{Chef::FileCache.load("#{Chef::Dist::SHORT}-stacktrace.out", false)}")
logger.fatal("Please provide the contents of the stacktrace.out file if you file a bug report")
- logger.debug(message)
+ if Chef::Config[:always_dump_stacktrace]
+ logger.fatal(message)
+ else
+ logger.debug(message)
+ end
true
end
diff --git a/lib/chef/application/apply.rb b/lib/chef/application/apply.rb
index 35aefc949d..4718e8750b 100644
--- a/lib/chef/application/apply.rb
+++ b/lib/chef/application/apply.rb
@@ -76,6 +76,12 @@ class Chef::Application::Apply < Chef::Application
description: "Set the log level (trace, debug, info, warn, error, fatal).",
proc: lambda { |l| l.to_sym }
+ option :always_dump_stacktrace,
+ long: "--[no-]always-dump-stacktrace",
+ boolean: true,
+ default: false,
+ description: "Always dump the stacktrace regardless of the log_level setting."
+
option :help,
short: "-h",
long: "--help",
diff --git a/lib/chef/application/base.rb b/lib/chef/application/base.rb
index c5bff9874e..bdc6055c31 100644
--- a/lib/chef/application/base.rb
+++ b/lib/chef/application/base.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2008-2019, Chef Software Inc.
+# Copyright:: Copyright 2008-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -100,6 +100,12 @@ class Chef::Application::Base < Chef::Application
description: "Set the log file location, defaults to STDOUT - recommended for daemonizing.",
proc: nil
+ option :always_dump_stacktrace,
+ long: "--[no-]always-dump-stacktrace",
+ boolean: true,
+ default: false,
+ description: "Always dump the stacktrace regardless of the log_level setting."
+
option :help,
short: "-h",
long: "--help",
diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb
index 9d9980d2fb..449ab49c90 100644
--- a/lib/chef/provider/file.rb
+++ b/lib/chef/provider/file.rb
@@ -1,7 +1,7 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
# Author:: Lamont Granquist (<lamont@chef.io>)
-# Copyright:: Copyright 2008-2017, Chef Software Inc.
+# Copyright:: Copyright 2008-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -381,7 +381,7 @@ class Chef
def update_file_contents
do_backup unless needs_creating?
- deployment_strategy.deploy(tempfile.path, ::File.realpath(new_resource.path))
+ deployment_strategy.deploy(tempfile.path, ::File.realpath(new_resource.path).force_encoding(Chef::Config[:ruby_encoding]))
logger.info("#{new_resource} updated file contents #{new_resource.path}")
if managing_content?
# save final checksum for reporting.