Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions providers/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,19 @@ def execute_install_script(install_script)

Write-Output "Running product install script..."
try {
# Reset $LASTEXITCODE to $null before invoking the install script so that any
# non-zero exit code left behind by #{uninstall_if_necessary} (e.g. msiexec /x)
# does not produce a false positive on the check below.
$LASTEXITCODE = $null
#{install_script}
# PowerShell's try/catch only catches *terminating* errors. External programs
# such as msiexec.exe signal failure via a non-zero exit code, not by throwing
# an exception, so a failed install would otherwise silently fall through and
# leave the node in an indeterminate state. Explicitly convert a non-zero exit
# code into a terminating error so the catch block fires and the rollback runs.
if ($LASTEXITCODE -ne $null -and $LASTEXITCODE -ne 0) {
throw "Install script exited with non-zero exit code: $LASTEXITCODE"
}
}
catch {
Write-Output "An error occurred while trying to install product"
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/providers/default_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
require 'spec_helper'

# NOTE: The Windows upgrade path in execute_install_script (the powershell_script resource
# rendered via .run_action(:run)) cannot be meaningfully unit tested here because ChefSpec
# does not intercept immediate run_action calls. Behavioral coverage for the Windows
# $LASTEXITCODE exit-code check and rollback path requires a Windows Test Kitchen suite
# that converges with a mock install script that exits non-zero and then asserts the
# backup directory was restored. See kitchen.yml for the existing Linux suites.

describe 'chef_client_updater provider' do
platform 'ubuntu', '22.04'

Expand Down
Loading