Skip to content

Commit 4143879

Browse files
authored
SqlRs: Add RestartTimeout parameter (#2297)
1 parent 0940d79 commit 4143879

File tree

7 files changed

+75
-0
lines changed

7 files changed

+75
-0
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
130130

131131
### Fixed
132132

133+
- `DSC_SqlRS`
134+
- Fixed intermittent initialization failures on resource-constrained systems
135+
(particularly Windows Server 2025 in CI) by adding an optional `RestartTimeout`
136+
parameter that allows specifying a wait period (in seconds) after service
137+
restart to allow Reporting Services to fully initialize before attempting
138+
to get configuration data or run initialization methods. The timeout is applied
139+
both after the initial service restart and before calling `InitializeReportServer()`
140+
if needed, giving the WMI provider sufficient time to be ready. When not specified,
141+
no additional wait time is applied, maintaining backward compatibility.
133142
- `New-SqlDscAudit`
134143
- Fixed parameter validation to prevent the `ReserveDiskSpace` parameter from
135144
being used with the `FileWithMaxFiles` parameter set (when only `MaximumFiles`

source/DSCResources/DSC_SqlRS/DSC_SqlRS.psm1

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ function Get-TargetResource
180180
settings change. If this parameter is set to $true, Reporting Services
181181
will not be restarted, even after initialization.
182182
183+
.PARAMETER RestartTimeout
184+
The number of seconds to wait after restarting Reporting Services before
185+
continuing with configuration. This is useful on resource-constrained
186+
systems where the service may take longer to fully initialize. If not
187+
specified, no additional wait time is applied after service restart.
188+
183189
.PARAMETER Encrypt
184190
Specifies how encryption should be enforced. There are currently no
185191
difference between using `Mandatory` or `Strict`.
@@ -263,6 +269,10 @@ function Set-TargetResource
263269
[System.Boolean]
264270
$SuppressRestart,
265271

272+
[Parameter()]
273+
[System.UInt32]
274+
$RestartTimeout,
275+
266276
[Parameter()]
267277
[ValidateSet('Mandatory', 'Optional', 'Strict')]
268278
[System.String]
@@ -526,6 +536,18 @@ function Set-TargetResource
526536

527537
Restart-ReportingServicesService -InstanceName $InstanceName -WaitTime 30
528538

539+
<#
540+
Wait for the service to be fully ready after restart before attempting
541+
to get reporting services data or initialize. This is especially important
542+
on resource-constrained systems where the service may take longer to
543+
fully initialize (e.g., Windows Server 2025 in CI environments).
544+
#>
545+
if ($PSBoundParameters.ContainsKey('RestartTimeout'))
546+
{
547+
Write-Verbose -Message ($script:localizedData.WaitingForServiceReady -f $RestartTimeout)
548+
Start-Sleep -Seconds $RestartTimeout
549+
}
550+
529551
$restartReportingService = $false
530552

531553
$reportingServicesData = Get-ReportingServicesData -InstanceName $InstanceName
@@ -540,6 +562,17 @@ function Set-TargetResource
540562
{
541563
Write-Verbose -Message "Did not help restarting the Reporting Services service, running the CIM method to initialize report server on $DatabaseServerName\$DatabaseInstanceName for instance ID '$($reportingServicesData.Configuration.InstallationID)'."
542564

565+
<#
566+
Add an additional wait before calling InitializeReportServer to give
567+
the WMI provider more time to be fully ready. This is especially
568+
important on resource-constrained systems.
569+
#>
570+
if ($PSBoundParameters.ContainsKey('RestartTimeout'))
571+
{
572+
Write-Verbose -Message ($script:localizedData.WaitingForServiceReady -f $RestartTimeout)
573+
Start-Sleep -Seconds $RestartTimeout
574+
}
575+
543576
$restartReportingService = $true
544577

545578
$invokeRsCimMethodParameters = @{
@@ -804,6 +837,17 @@ function Set-TargetResource
804837
{
805838
Write-Verbose -Message $script:localizedData.Restart
806839
Restart-ReportingServicesService -InstanceName $InstanceName -WaitTime 30
840+
841+
<#
842+
Wait for the service to be fully ready after restart before attempting
843+
to test the configuration. This is especially important on resource-constrained
844+
systems where the service may take longer to fully initialize.
845+
#>
846+
if ($PSBoundParameters.ContainsKey('RestartTimeout'))
847+
{
848+
Write-Verbose -Message ($script:localizedData.WaitingForServiceReady -f $RestartTimeout)
849+
Start-Sleep -Seconds $RestartTimeout
850+
}
807851
}
808852
}
809853

@@ -851,6 +895,9 @@ function Set-TargetResource
851895
settings change. If this parameter is set to $true, Reporting Services
852896
will not be restarted, even after initialization.
853897
898+
.PARAMETER RestartTimeout
899+
Not used in Test-TargetResource.
900+
854901
.PARAMETER Encrypt
855902
Specifies how encryption should be enforced. There are currently no
856903
difference between using `Mandatory` or `Strict`.
@@ -898,6 +945,10 @@ function Test-TargetResource
898945
[System.Boolean]
899946
$SuppressRestart,
900947

948+
[Parameter()]
949+
[System.UInt32]
950+
$RestartTimeout,
951+
901952
[Parameter()]
902953
[ValidateSet('Mandatory', 'Optional', 'Strict')]
903954
[System.String]

source/DSCResources/DSC_SqlRS/DSC_SqlRS.schema.mof

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class DSC_SqlRS : OMI_BaseResource
1010
[Write, Description("_Report Manager_ or _Report Web App_ URL reservations. Optional. If not specified, `'http://+:80'` URL reservation will be used.")] String ReportsReservedUrl[];
1111
[Write, Description("If connections to the _Reporting Services_ must use SSL. If this parameter is not assigned a value, the default is that _Reporting Services_ does not use SSL.")] Boolean UseSsl;
1212
[Write, Description("_Reporting Services_ need to be restarted after initialization or settings change. If this parameter is set to `$true`, _Reporting Services_ will not be restarted, even after initialization.")] Boolean SuppressRestart;
13+
[Write, Description("The number of seconds to wait after restarting _Reporting Services_ before continuing with configuration. This is useful on resource-constrained systems where the service may take longer to fully initialize. If not specified, no additional wait time is applied after service restart.")] UInt32 RestartTimeout;
1314
[Write, Description("Specifies how encryption should be enforced when using command `Invoke-SqlCmd`. When not specified, the default value is `Mandatory`."), ValueMap{"Mandatory","Optional","Strict"}, Values{"Mandatory","Optional","Strict"}] String Encrypt;
1415
[Read, Description("Returns if the _Reporting Services_ instance initialized or not.")] Boolean IsInitialized;
1516
};

source/DSCResources/DSC_SqlRS/en-US/DSC_SqlRS.strings.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ ConvertFrom-StringData @'
55
ReportingServicesNotFound = SQL Reporting Services instance '{0}' does not exist.
66
GetConfiguration = Get the current reporting services configuration for the instance '{0}'.
77
RestartToFinishInitialization = Restarting Reporting Services to finish initialization.
8+
WaitingForServiceReady = Waiting {0} seconds for Reporting Services to be fully ready after restart. (DSC_SQLRS0001)
89
'@

tests/Integration/Resources/DSC_SqlRS.config.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ Configuration DSC_SqlRS_ConfigureReportingServices_Config
187187

188188
ReportServerReservedUrl = @('http://+:80')
189189

190+
<#
191+
Adding a restart timeout to help with intermittent failures
192+
on resource-constrained CI systems (especially Windows Server 2025).
193+
#>
194+
RestartTimeout = 30
195+
190196
PsDscRunAsCredential = New-Object `
191197
-TypeName System.Management.Automation.PSCredential `
192198
-ArgumentList @(

tests/Integration/Resources/DSC_SqlRS_Default.config.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ Configuration DSC_SqlRS_ConfigureReportingServices_Config
185185
DatabaseInstanceName = $Node.DatabaseInstanceName
186186
Encrypt = 'Optional'
187187

188+
<#
189+
Adding a restart timeout to help with intermittent failures
190+
on resource-constrained CI systems (especially Windows Server 2025).
191+
#>
192+
RestartTimeout = 30
193+
188194
PsDscRunAsCredential = New-Object `
189195
-TypeName System.Management.Automation.PSCredential `
190196
-ArgumentList @(

tests/Unit/DSC_SqlRS.Tests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' {
513513
Mock -CommandName Import-SqlDscPreferredModule
514514
Mock -CommandName Invoke-SqlDscQuery
515515
Mock -CommandName Restart-ReportingServicesService
516+
Mock -CommandName Start-Sleep
516517
Mock -CommandName Invoke-RsCimMethod
517518
Mock -CommandName Invoke-RsCimMethod -MockWith $mockInvokeRsCimMethod_GenerateDatabaseCreationScript -ParameterFilter {
518519
$MethodName -eq 'GenerateDatabaseCreationScript'

0 commit comments

Comments
 (0)