fix: skip default restart check when custom restart_check_command is provided - #13654
fix: skip default restart check when custom restart_check_command is provided#13654AruneshDwivedi wants to merge 1 commit into
Conversation
|
Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement Learn more about why HashiCorp requires a CLA and what the CLA includes Have you signed the CLA already but the status is still pending? Recheck it. |
|
/check-cla |
| err := cmdRestartCheck.RunWithUi(ctx, p.comm, p.ui) | ||
| if err != nil { | ||
| log.Printf("Communication connection err: %s", err) | ||
| continue | ||
| } | ||
| log.Printf("Connected to machine") | ||
| runCustomRestartCheck = false | ||
| // User provided a custom check — skip the default PowerShell | ||
| // module-load check to avoid breaking Constrained Language Mode. | ||
| break |
There was a problem hiding this comment.
@AruneshDwivedi A command that connects fine but exits non-zero (wrong script, bad logic) still hits break and Packer proceeds as if the machine is ready.
Before this, the default check acted as an accidental silent safety net for that case. After this PR that net is gone (intentionally), which is correct, but it exposes the underlying gap.
Can we update the err check condition to:
err := cmdRestartCheck.RunWithUi(ctx, p.comm, p.ui)
if err != nil || cmdRestartCheck.ExitStatus() != 0 {
log.Printf("Communication connection err: %s (exit status: %d)", err, cmdRestartCheck.ExitStatus())
continue
}
log.Printf("Connected to machine")
break
…provided When a user provides a custom restart_check_command to the windows-restart provisioner, the DefaultRestartCheckCommand (which uses [System.Net.Dns]::GetHostName()) was still being executed afterward. This breaks Windows Constrained Language Mode because that .NET call is not allowed in constrained mode. Fix: when a custom restart_check_command is provided, skip the default PowerShell module-load check entirely. The user's custom command is sufficient to verify the restart. Fixes hashicorp#13643
e26f273 to
46a5aad
Compare
The windows-restart provisioner runs
DefaultRestartCheckCommand([System.Net.Dns]::GetHostName()) even when the user provides a customrestart_check_command. This breaks Windows Constrained Language Mode because the .NET call isn't allowed.The fix adds a
breakafter running the custom restart check, so the default check is skipped when a custom one is provided.Fixes #13654