Skip to content

Commit 34abdf2

Browse files
authored
SQLRS: Fix the SQLRS resource to support the PowerBI RS configuration (#2326)
1 parent 297d6b1 commit 34abdf2

File tree

5 files changed

+63
-10
lines changed

5 files changed

+63
-10
lines changed

CHANGELOG.md

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

121121
### Fixed
122122

123+
- `SqlRS`
124+
- Obtain the Reporting service name from WMI for version 14 and higher.
125+
[issue #2313](https://github.com/dsccommunity/SqlServerDsc/issues/2313)
123126
- `Repair-SqlDscServer`
124127
- Removed the `Features` parameter from the command as SQL Server Repair action
125128
does not accept the `/FEATURES` parameter. SQL Server automatically repairs
@@ -228,6 +231,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
228231

229232
### Changed
230233

234+
- `Restart-ReportingServicesService`
235+
- Add the ServiceName parameter to restart service with the service name specified.
236+
- Introduce parameter sets to maintain backward compatibility with the current
237+
version.
231238
- BREAKING CHANGE: `Set-SqlDscDatabase` has been renamed to `Set-SqlDscDatabaseProperty`
232239
to better reflect its purpose of setting database properties. All existing references
233240
should be updated to use the new name.

source/DSCResources/DSC_SqlRS/DSC_SqlRS.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ function Set-TargetResource
295295
$ReportsVirtualDirectory = 'Reports'
296296
}
297297

298-
$reportingServicesServiceName = 'SQLServerReportingServices'
298+
$reportingServicesServiceName = $reportingServicesData.Configuration.ServiceName
299299
$reportingServicesDatabaseName = 'ReportServer'
300300
}
301301
elseif ( $InstanceName -eq 'MSSQLSERVER' )
@@ -534,7 +534,7 @@ function Set-TargetResource
534534
#>
535535
Write-Verbose -Message $script:localizedData.RestartToFinishInitialization
536536

537-
Restart-ReportingServicesService -InstanceName $InstanceName -WaitTime 30
537+
Restart-ReportingServicesService -ServiceName $reportingServicesServiceName -WaitTime 30
538538

539539
<#
540540
Wait for the service to be fully ready after restart before attempting
@@ -836,7 +836,7 @@ function Set-TargetResource
836836
elseif ( $restartReportingService -and (-not $SuppressRestart) )
837837
{
838838
Write-Verbose -Message $script:localizedData.Restart
839-
Restart-ReportingServicesService -InstanceName $InstanceName -WaitTime 30
839+
Restart-ReportingServicesService -ServiceName $reportingServicesServiceName -WaitTime 30
840840

841841
<#
842842
Wait for the service to be fully ready after restart before attempting

source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,19 +1103,26 @@ function Restart-SqlClusterService
11031103
Name of the instance to be restarted. Default is 'MSSQLSERVER'
11041104
(the default instance).
11051105
1106+
.PARAMETER ServiceName
1107+
Name of the service to be restarted.
1108+
11061109
.PARAMETER WaitTime
11071110
Number of seconds to wait between service stop and service start.
11081111
Default value is 0 seconds.
11091112
#>
11101113
function Restart-ReportingServicesService
11111114
{
1112-
[CmdletBinding()]
1115+
[CmdletBinding(DefaultParameterSetName = 'InstanceName')]
11131116
param
11141117
(
1115-
[Parameter()]
1118+
[Parameter(ParameterSetName = 'InstanceName')]
11161119
[System.String]
11171120
$InstanceName = 'MSSQLSERVER',
11181121

1122+
[Parameter(ParameterSetName = 'ServiceName', Mandatory = $true)]
1123+
[System.String]
1124+
$ServiceName,
1125+
11191126
[Parameter()]
11201127
[System.UInt16]
11211128
$WaitTime = 0
@@ -1130,6 +1137,12 @@ function Restart-ReportingServicesService
11301137
$reportingServicesService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
11311138
}
11321139

1140+
if ($PSCmdlet.ParameterSetName -eq 'ServiceName')
1141+
{
1142+
Write-Verbose -Message ($script:localizedData.GetServiceInformation -f $ServiceName) -Verbose
1143+
$reportingServicesService = Get-Service -Name $ServiceName
1144+
}
1145+
11331146
if ($null -eq $reportingServicesService)
11341147
{
11351148
$ServiceName = 'ReportServer'

tests/Unit/DSC_SqlRS.Tests.ps1

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Describe 'SqlRS\Get-TargetResource' -Tag 'Get' {
8787
$mockReportServerApplicationUrl = 'http://+:80'
8888
$mockVirtualDirectoryReportManagerName = 'Reports_SQL2016'
8989
$mockVirtualDirectoryReportServerName = 'ReportServer_SQL2016'
90+
$mockReportingServicesServiceName = 'SQLServerReportingServices'
9091

9192
$mockInvokeRsCimMethod_ListReservedUrls = {
9293
return New-Object -TypeName Object |
@@ -115,7 +116,8 @@ Describe 'SqlRS\Get-TargetResource' -Tag 'Get' {
115116
Add-Member -MemberType NoteProperty -Name 'InstanceName' -Value $mockNamedInstanceName -PassThru |
116117
Add-Member -MemberType NoteProperty -Name 'VirtualDirectoryReportServer' -Value $mockVirtualDirectoryReportServerName -PassThru |
117118
Add-Member -MemberType NoteProperty -Name 'VirtualDirectoryReportManager' -Value $mockVirtualDirectoryReportManagerName -PassThru |
118-
Add-Member -MemberType NoteProperty -Name 'SecureConnectionLevel' -Value $mockDynamicSecureConnectionLevel -PassThru -Force
119+
Add-Member -MemberType NoteProperty -Name 'SecureConnectionLevel' -Value $mockDynamicSecureConnectionLevel -PassThru -Force |
120+
Add-Member -MemberType NoteProperty -Name 'ServiceName' -Value $mockReportingServicesServiceName -PassThru -Force
119121
),
120122
(
121123
# Array is a regression test for issue #819.
@@ -136,7 +138,8 @@ Describe 'SqlRS\Get-TargetResource' -Tag 'Get' {
136138
Add-Member -MemberType NoteProperty -Name 'InstanceName' -Value $mockDefaultInstanceName -PassThru |
137139
Add-Member -MemberType NoteProperty -Name 'VirtualDirectoryReportServer' -Value '' -PassThru |
138140
Add-Member -MemberType NoteProperty -Name 'VirtualDirectoryReportManager' -Value '' -PassThru -Force |
139-
Add-Member -MemberType NoteProperty -Name 'SecureConnectionLevel' -Value $mockDynamicSecureConnectionLevel -PassThru -Force
141+
Add-Member -MemberType NoteProperty -Name 'SecureConnectionLevel' -Value $mockDynamicSecureConnectionLevel -PassThru -Force |
142+
Add-Member -MemberType NoteProperty -Name 'ServiceName' -Value $mockReportingServicesServiceName -PassThru -Force
140143
}
141144

142145
Mock -CommandName Invoke-RsCimMethod -MockWith $mockInvokeRsCimMethod_ListReservedUrls -ParameterFilter {
@@ -418,6 +421,7 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' {
418421
$mockReportServerApplicationUrl = 'http://+:80'
419422
$mockVirtualDirectoryReportManagerName = 'Reports_SQL2016'
420423
$mockVirtualDirectoryReportServerName = 'ReportServer_SQL2016'
424+
$mockReportingServicesServiceName = 'SQLServerReportingServices'
421425

422426
$mockInvokeCimMethod = {
423427
throw 'Should not call Invoke-CimMethod directly, should call the wrapper Invoke-RsCimMethod.'
@@ -462,7 +466,8 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' {
462466
Add-Member -MemberType NoteProperty -Name 'InstanceName' -Value $mockNamedInstanceName -PassThru |
463467
Add-Member -MemberType NoteProperty -Name 'VirtualDirectoryReportServer' -Value $mockVirtualDirectoryReportServerName -PassThru |
464468
Add-Member -MemberType NoteProperty -Name 'VirtualDirectoryReportManager' -Value $mockVirtualDirectoryReportManagerName -PassThru |
465-
Add-Member -MemberType NoteProperty -Name 'SecureConnectionLevel' -Value $mockDynamicSecureConnectionLevel -PassThru -Force
469+
Add-Member -MemberType NoteProperty -Name 'SecureConnectionLevel' -Value $mockDynamicSecureConnectionLevel -PassThru -Force |
470+
Add-Member -MemberType NoteProperty -Name 'ServiceName' -Value $mockReportingServicesServiceName -PassThru -Force
466471
),
467472
(
468473
# Array is a regression test for issue #819.
@@ -483,7 +488,8 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' {
483488
Add-Member -MemberType NoteProperty -Name 'InstanceName' -Value $mockDefaultInstanceName -PassThru |
484489
Add-Member -MemberType NoteProperty -Name 'VirtualDirectoryReportServer' -Value '' -PassThru |
485490
Add-Member -MemberType NoteProperty -Name 'VirtualDirectoryReportManager' -Value '' -PassThru -Force |
486-
Add-Member -MemberType NoteProperty -Name 'SecureConnectionLevel' -Value $mockDynamicSecureConnectionLevel -PassThru -Force
491+
Add-Member -MemberType NoteProperty -Name 'SecureConnectionLevel' -Value $mockDynamicSecureConnectionLevel -PassThru -Force |
492+
Add-Member -MemberType NoteProperty -Name 'ServiceName' -Value $mockReportingServicesServiceName -PassThru -Force
487493
}
488494

489495
$mockGetCimInstance_ConfigurationSetting_ParameterFilter = {
@@ -985,7 +991,8 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' {
985991
Add-Member -MemberType NoteProperty -Name 'InstanceName' -Value $mockNamedInstanceName -PassThru |
986992
Add-Member -MemberType NoteProperty -Name 'VirtualDirectoryReportServer' -Value $mockVirtualDirectoryReportServerName -PassThru |
987993
Add-Member -MemberType NoteProperty -Name 'VirtualDirectoryReportManager' -Value $mockVirtualDirectoryReportManagerName -PassThru |
988-
Add-Member -MemberType NoteProperty -Name 'SecureConnectionLevel' -Value $script:mockDynamicSecureConnectionLevel -PassThru -Force
994+
Add-Member -MemberType NoteProperty -Name 'SecureConnectionLevel' -Value $script:mockDynamicSecureConnectionLevel -PassThru -Force |
995+
Add-Member -MemberType NoteProperty -Name 'ServiceName' -Value $mockReportingServicesServiceName -PassThru -Force
989996
ReportsApplicationName = 'ReportServerWebApp'
990997
SqlVersion = $sqlVersion.Version
991998
}

tests/Unit/SqlServerDsc.Common.Tests.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,6 +2917,32 @@ Describe 'SqlServerDsc.Common\Restart-ReportingServicesService' -Tag 'RestartRep
29172917
Should -Invoke -CommandName Start-Sleep -Scope It -Exactly -Times 1
29182918
}
29192919
}
2920+
2921+
Context 'When restarting a Report Services service name is supplied' {
2922+
BeforeAll {
2923+
$mockServiceName = 'ReportServer'
2924+
$mockDependedServiceName = 'DependentService'
2925+
2926+
$mockDynamicServiceName = $mockServiceName
2927+
$mockDynamicDependedServiceName = $mockDependedServiceName
2928+
$mockDynamicServiceDisplayName = 'Reporting Services (MSSQLSERVER)'
2929+
2930+
Mock -CommandName Stop-Service
2931+
Mock -CommandName Start-Service
2932+
Mock -CommandName Get-Service -MockWith $mockGetService
2933+
}
2934+
2935+
It 'Should restart the service and dependent service' {
2936+
$null = Restart-ReportingServicesService -ServiceName 'ReportServer'
2937+
2938+
Should -Invoke -CommandName Get-Service -ParameterFilter {
2939+
$Name -eq $mockServiceName
2940+
} -Scope It -Exactly -Times 1
2941+
Should -Invoke -CommandName Stop-Service -Scope It -Exactly -Times 1
2942+
Should -Invoke -CommandName Start-Service -Scope It -Exactly -Times 2
2943+
}
2944+
2945+
}
29202946
}
29212947

29222948
Describe 'SqlServerDsc.Common\Test-ActiveNode' -Tag 'TestActiveNode' {

0 commit comments

Comments
 (0)