Skip to content

Commit 2aacbac

Browse files
committed
fix: restore powershell_wmf reboot delay
1 parent 33f83de commit 2aacbac

5 files changed

Lines changed: 53 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Standardise files with files in sous-chefs/repo-management
88
## Unreleased
99

1010
* Migrate the cookbook to custom resources and modernize Windows CI/test coverage
11+
* Reimplement reboot-delay support on the `powershell_wmf` resource
1112

1213
## [7.0.0](https://github.com/sous-chefs/powershell/compare/v6.4.21...v7.0.0) (2026-04-20)
1314

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ Install WMF 5.1 when the target platform needs it:
3737
powershell_wmf '5.1'
3838
```
3939

40+
Request a delayed reboot after installation:
41+
42+
```ruby
43+
powershell_wmf '4.0' do
44+
reboot_mode 'delayed_reboot'
45+
reboot_delay_mins 5
46+
end
47+
```
48+
4049
Prepare WinRM for DSC with an HTTPS listener:
4150

4251
```ruby

documentation/powershell_wmf.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Installs a legacy Windows Management Framework release when the target platform
1919
| `timeout` | Integer | computed | Override the installer timeout |
2020
| `dotnet_version` | String | computed | .NET Framework version requested from `ms_dotnet` |
2121
| `reboot_mode` | String | `'no_reboot'` | Reboot strategy after installation |
22+
| `reboot_delay_mins` | Integer | `0` | Delay, in minutes, for `delayed_reboot` requests |
2223
| `reboot_timeout_seconds` | Integer | `10` | Delay used for delayed reboot requests |
2324

2425
## Examples
@@ -30,5 +31,6 @@ powershell_wmf '5.1'
3031
```ruby
3132
powershell_wmf '4.0' do
3233
reboot_mode 'delayed_reboot'
34+
reboot_delay_mins 5
3335
end
3436
```

resources/powershell_wmf.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
property :timeout, Integer
1111
property :dotnet_version, String
1212
property :reboot_mode, String, default: 'no_reboot', equal_to: %w(no_reboot immediate_reboot delayed_reboot)
13+
property :reboot_delay_mins, Integer, default: 0
1314
property :reboot_timeout_seconds, Integer, default: 10
1415

1516
default_action :install
@@ -58,7 +59,7 @@ def declare_reboot_resource
5859

5960
reboot 'powershell reboot' do
6061
reason "PowerShell #{new_resource.version} installation requires a reboot"
61-
delay_mins [(new_resource.reboot_timeout_seconds / 60.0).ceil, 1].max
62+
delay_mins effective_reboot_delay_mins
6263
action :nothing
6364
end
6465
end
@@ -72,6 +73,13 @@ def maybe_notify_reboot(installer)
7273
def unsupported_message
7374
"PowerShell #{new_resource.version} is not supported or already bundled on Windows #{node['platform_version']}"
7475
end
76+
77+
def effective_reboot_delay_mins
78+
return new_resource.reboot_delay_mins if new_resource.property_is_set?(:reboot_delay_mins)
79+
return 0 if new_resource.reboot_timeout_seconds.to_i <= 0
80+
81+
[(new_resource.reboot_timeout_seconds / 60.0).ceil, 1].max
82+
end
7583
end
7684

7785
action :install do

spec/unit/resources/powershell_wmf_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,38 @@
8484
end
8585
end
8686

87+
context 'when requesting a delayed reboot with an explicit delay' do
88+
platform 'windows', '2012'
89+
90+
recipe do
91+
node.automatic['platform_version'] = '6.1'
92+
powershell_wmf '5.1' do
93+
reboot_mode 'delayed_reboot'
94+
reboot_delay_mins 5
95+
end
96+
end
97+
98+
it do
99+
expect(chef_run.reboot('powershell reboot').delay_mins).to eq(5)
100+
end
101+
end
102+
103+
context 'when using the legacy reboot timeout override' do
104+
platform 'windows', '2012'
105+
106+
recipe do
107+
node.automatic['platform_version'] = '6.1'
108+
powershell_wmf '5.1' do
109+
reboot_mode 'delayed_reboot'
110+
reboot_timeout_seconds 120
111+
end
112+
end
113+
114+
it do
115+
expect(chef_run.reboot('powershell reboot').delay_mins).to eq(2)
116+
end
117+
end
118+
87119
context 'when PowerShell 5.1 is already bundled with the platform' do
88120
platform 'windows', '2019'
89121

0 commit comments

Comments
 (0)