Skip to content

CHEF-27761: Add pre-upgrade package validation for Windows - #261

Merged
Stromweld merged 10 commits into
chef-cookbooks:mainfrom
tpowell-progress:chef-27761-pre-upgrade-validation
Jul 8, 2026
Merged

Stromweld merged 10 commits into
chef-cookbooks:mainfrom
tpowell-progress:chef-27761-pre-upgrade-validation

Conversation

@tpowell-progress

@tpowell-progress tpowell-progress commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem

During CDN propagation windows, Windows upgrades can fail after backup and move operations have already run — leaving the system without a working Chef client.

Solution

Add pre-upgrade package availability validation that checks the artifact URL exists (via HTTP HEAD + exponential backoff) before any destructive operations run. On failure, the cookbook exits gracefully so other cookbooks in the run continue unaffected.

Changes

  • libraries/chef_client_updater_helper.rb — validate_package_availability returns false (warn + skip) instead of raising; validate_windows_package_availability does the same on network failure
  • providers/default.rb — return early from the action when validation returns false, before converge_by runs
  • spec/ — unit tests updated to assert false return + warn log on failure cases

Behavior

  • Artifact unavailable → logs a warning, exits this cookbook action early, other cookbooks continue
  • Artifact available → proceeds with upgrade as before

Fixes: CHEF-27761

@tpowell-progress
tpowell-progress force-pushed the chef-27761-pre-upgrade-validation branch from 22df82f to 4bf1934 Compare June 15, 2026 19:19
Comment thread libraries/chef_client_updater_helper.rb Resolved
Comment thread libraries/chef_client_updater_helper.rb Resolved
@tpowell-progress
tpowell-progress force-pushed the chef-27761-pre-upgrade-validation branch 2 times, most recently from 08330b8 to 807b413 Compare July 6, 2026 14:26
tpowell-progress and others added 7 commits July 6, 2026 13:04
…allations

This change addresses CHEF-27761 by adding validation of package availability
before performing destructive upgrade operations on Windows systems. This prevents
systems from being left in a broken state if packages aren't available on CDN.

Features:
- Added validate_package_availability() method to check package readiness
- Added validate_windows_package_availability() with retry logic for Windows
- Integrated validation into upgrade action before destructive operations
- Implements exponential backoff retry (2s, 4s, 8s)
- 3 retries maximum, clear error messages
- Prevents directory moves/backups if validation fails

The validation is integrated seamlessly into the existing upgrade flow and requires
no user code changes - it's automatic on every upgrade attempt.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Thomas Powell <104777878+tpowell-progress@users.noreply.github.com>
Add focused specs for CHEF-27761 validation behavior:
- validate_package_availability success path and failure cases
- windows validation delegation behavior
- validate_windows_package_availability success and retry exhaustion

These tests cover the newly added guardrails that prevent destructive
upgrade operations when package URLs are unavailable.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Thomas Powell <104777878+tpowell-progress@users.noreply.github.com>
The refactor now sleeps between retry attempts, so the failure-path spec
should expect two sleeps for three attempts instead of three sleeps.

This keeps the test aligned with the more idiomatic max_retries.times loop
while preserving the same retry behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Thomas Powell <104777878+tpowell-progress@users.noreply.github.com>
Use a max_retries.times loop for the Windows package validation retry path,
with a guard-clause style availability check in validate_package_availability.
Behavior is unchanged; the code is just clearer and more Ruby-like.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Thomas Powell <104777878+tpowell-progress@users.noreply.github.com>
Signed-off-by: Thomas Powell <104777878+tpowell-progress@users.noreply.github.com>
Return false from validate_package_availability instead of raising,
so a missing/unavailable artifact logs a warning and exits the action
early without failing the entire Chef run. Other cookbooks continue.

- validate_package_availability: raise -> return false + warn
- validate_windows_package_availability: explicit true/false returns
- providers/default.rb: return early before converge_by on false
- specs: updated to assert false return + warn, not raise_error

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Thomas Powell <104777878+tpowell-progress@users.noreply.github.com>
- SECURITY.md: wrap bare URL, remove extra blank line
- libraries/matchers.rb: remove ChefSpec matchers (auto-generated in 7.1+)
- metadata.rb: remove respond_to?/defined? guards no longer needed in Chef 12.15+
- providers/default.rb: fix redundant return, use .last, remove redundant to_s in interpolation

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Thomas Powell <104777878+tpowell-progress@users.noreply.github.com>
@tpowell-progress
tpowell-progress force-pushed the chef-27761-pre-upgrade-validation branch from 807b413 to dcd688d Compare July 6, 2026 17:04
tpowell-progress and others added 3 commits July 8, 2026 08:48
Signed-off-by: Thomas Powell <104777878+tpowell-progress@users.noreply.github.com>
@Stromweld
Stromweld merged commit d041d9f into chef-cookbooks:main Jul 8, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants