summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNaomi Reeves <nreeves@fb.com>2020-08-12 14:17:54 -0700
committerNaomi Reeves <NaomiReeves@users.noreply.github.com>2020-08-20 22:05:09 -0700
commitfa84abaedf07d8d5aed8ee7509b3370140797835 (patch)
treea828ff8b02b44ad2791812202893bedd8778d0d4
parent529a36c63ca8fdc1d58b02b4faa86a4e89e5b738 (diff)
downloadchef-fa84abaedf07d8d5aed8ee7509b3370140797835.tar.gz
define unique exit code for configuration failures and handle correctly
Signed-off-by: Naomi Reeves <NaomiReeves@users.noreply.github.com>
-rw-r--r--lib/chef/application/exit_code.rb9
-rw-r--r--spec/unit/application/exit_code_spec.rb10
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/chef/application/exit_code.rb b/lib/chef/application/exit_code.rb
index 3235bfadeb..ee0621f5ce 100644
--- a/lib/chef/application/exit_code.rb
+++ b/lib/chef/application/exit_code.rb
@@ -36,6 +36,7 @@ class Chef
REBOOT_NEEDED: 37,
REBOOT_FAILED: 41,
# 42 was used by audit mode and should not be reused
+ CONFIG_FAILURE: 43,
CLIENT_UPGRADED: 213,
}.freeze
@@ -79,6 +80,8 @@ class Chef
VALID_RFC_062_EXIT_CODES[:REBOOT_NEEDED]
elsif reboot_failed?(exception)
VALID_RFC_062_EXIT_CODES[:REBOOT_FAILED]
+ elsif configuration_failure?(exception)
+ VALID_RFC_062_EXIT_CODES[:CONFIG_FAILURE]
elsif client_upgraded?(exception)
VALID_RFC_062_EXIT_CODES[:CLIENT_UPGRADED]
else
@@ -104,6 +107,12 @@ class Chef
end
end
+ def configuration_failure?(exception)
+ resolve_exception_array(exception).any? do |e|
+ e.is_a? Chef::Exceptions::ConfigurationError
+ end
+ end
+
def client_upgraded?(exception)
resolve_exception_array(exception).any? do |e|
e.is_a? Chef::Exceptions::ClientUpgraded
diff --git a/spec/unit/application/exit_code_spec.rb b/spec/unit/application/exit_code_spec.rb
index 6b025938a6..7ede9fb86d 100644
--- a/spec/unit/application/exit_code_spec.rb
+++ b/spec/unit/application/exit_code_spec.rb
@@ -61,6 +61,10 @@ describe Chef::Application::ExitCode do
expect(valid_rfc_exit_codes.include?(41)).to eq(true)
end
+ it "validates a CONFIG_FAILURE return code of 43" do
+ expect(valid_rfc_exit_codes.include?(43)).to eq(true)
+ end
+
it "validates a CLIENT_UPGRADED return code of 213" do
expect(valid_rfc_exit_codes.include?(213)).to eq(true)
end
@@ -113,6 +117,12 @@ describe Chef::Application::ExitCode do
expect(exit_codes.normalize_exit_code(runtime_error)).to eq(37)
end
+ it "returns CONFIG_FAILURE when a configuration exception is specified" do
+ config_error = Chef::Exceptions::ConfigurationError.new("BOOM")
+ runtime_error = Chef::Exceptions::RunFailedWrappingError.new(config_error)
+ expect(exit_codes.normalize_exit_code(runtime_error)).to eq(43)
+ end
+
it "returns CLIENT_UPGRADED when the client was upgraded during converge" do
client_upgraded_error = Chef::Exceptions::ClientUpgraded.new("BOOM")
runtime_error = Chef::Exceptions::RunFailedWrappingError.new(client_upgraded_error)