Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix input schema validation for RebootPending resource #488

Merged
merged 11 commits into from
Sep 26, 2024
38 changes: 25 additions & 13 deletions reboot_pending/reboot_pending.dsc.resource.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
{
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/bundled/resource/manifest.json",
"description": "Returns info about pending reboot.",
"type": "Microsoft.Windows/RebootPending",
"version": "0.1.0",
"get": {
"executable": "powershell",
"args": [
"-NoLogo",
"-NonInteractive",
"-NoProfile",
"-Command",
"reboot_pending.resource.ps1"
]
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/bundled/resource/manifest.json",
"description": "Returns info about pending reboot.",
"type": "Microsoft.Windows/RebootPending",
"version": "0.1.0",
"get": {
"executable": "powershell",
"args": [
"-NoLogo",
"-NonInteractive",
"-NoProfile",
"-Command",
"reboot_pending.resource.ps1"
]
},
"schema": {
"embedded": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "null",
"properties": {
"rebootPending": {
"type": "boolean",
"readOnly": true
}
}
}
}
}
10 changes: 5 additions & 5 deletions reboot_pending/reboot_pending.resource.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Reg keys are documented here: https://learn.microsoft.com/en-us/mem/configmgr/core/servers/deploy/install/list-of-prerequisite-checks#pending-system-restart
if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -EA Ignore) { return @{ RebootPending = $true } | ConvertTo-Json -Compress }
if (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -EA Ignore) { return @{ RebootPending = $true } | ConvertTo-Json -Compress }
if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -EA Ignore) { return @{ RebootPending = $true } | ConvertTo-Json -Compress }
if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -EA Ignore) { return @{ rebootPending = $true } | ConvertTo-Json -Compress }
if (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -EA Ignore) { return @{ rebootPending = $true } | ConvertTo-Json -Compress }
if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -EA Ignore) { return @{ rebootPending = $true } | ConvertTo-Json -Compress }
try {
$util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities"
$status = $util.DetermineIfRebootPending()
if(($status -ne $null) -and $status.RebootPending){
return @{ RebootPending = $true } | ConvertTo-Json -Compress
return @{ rebootPending = $true } | ConvertTo-Json -Compress
}
}catch{}

return @{ RebootPending = $false } | ConvertTo-Json -Compress
return @{ rebootPending = $false } | ConvertTo-Json -Compress
4 changes: 4 additions & 0 deletions reboot_pending/tests/reboot_pending.dsc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: Pending reboot status
type: Microsoft.Windows/RebootPending
17 changes: 17 additions & 0 deletions reboot_pending/tests/reboot_pending.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

Describe 'reboot_pending resource tests' {
It 'should get reboot_pending' -Skip:(!$IsWindows) {
$out = dsc resource get -r Microsoft.Windows/RebootPending | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0
$out.actualState.rebootPending | Should -Not -BeNullOrEmpty
}

It 'reboot_pending works in a config' -Skip:(!$IsWindows) {
$ConfigPath = Resolve-Path "$PSScriptRoot/reboot_pending.dsc.yaml"
$out = dsc config get --path $ConfigPath | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0
$out.results.result.actualState.rebootPending | Should -Not -BeNullOrEmpty
}
}
Loading