Skip to content

Commit

Permalink
Changes to xSQLServerRSConfig
Browse files Browse the repository at this point in the history
- Now the resource will restart the Reporting Services service after
  initializing (issue dsccommunity#592). This will enable the Reports site to work.
  • Loading branch information
johlju committed Sep 20, 2017
1 parent bf7f62b commit f1fb6a8
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
Services has not been initialized ([issue #822](https://github.com/PowerShell/xSQLServer/issues/822)).
- Fixed so that when two Reporting Services are installed for the same major
version the resource does not throw an error ([issue #819](https://github.com/PowerShell/xSQLServer/issues/819)).
- Now the resource will restart the Reporting Services service after
initializing ([issue #592](https://github.com/PowerShell/xSQLServer/issues/592)).
This will enable the Reports site to work.

## 8.1.0.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ function Set-TargetResource
Invoke-Sqlcmd -ServerInstance $reportingServicesConnection -Query $reportingServicesDatabaseRightsScript.Script
$null = $reportingServicesConfiguration.SetDatabaseConnection($reportingServicesConnection, $reportingServicesDatabaseName, 2, '', '')
$null = $reportingServicesConfiguration.InitializeReportServer($reportingServicesConfiguration.InstallationID)

Restart-ReportingServicesService -SQLInstanceName $InstanceName
}

if ( !(Test-TargetResource @PSBoundParameters) )
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/MSFT_xSQLServerRSConfig.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ try
Mock -CommandName Import-SQLPSModule -Verifiable
Mock -CommandName Invoke-Sqlcmd -Verifiable
Mock -CommandName Get-ItemProperty -MockWith $mockGetItemProperty -Verifiable
Mock -CommandName Restart-ReportingServicesService -Verifiable
}

Context 'When the system is not in the desired state' {
Expand Down Expand Up @@ -311,6 +312,7 @@ try

Assert-MockCalled -CommandName Get-WmiObject -Exactly -Times 2 -Scope It
Assert-MockCalled -CommandName Invoke-Sqlcmd -Exactly -Times 2 -Scope It
Assert-MockCalled -CommandName Restart-ReportingServicesService -Exactly -Times 1 -Scope It
}

Context 'When there is no Reporting Services instance after Set-TargetResource has been called' {
Expand Down Expand Up @@ -365,6 +367,7 @@ try

Assert-MockCalled -CommandName Get-WmiObject -Exactly -Times 2 -Scope It
Assert-MockCalled -CommandName Invoke-Sqlcmd -Exactly -Times 2 -Scope It
Assert-MockCalled -CommandName Restart-ReportingServicesService -Exactly -Times 1 -Scope It
}
}
}
Expand Down
64 changes: 64 additions & 0 deletions Tests/Unit/xSQLServerHelper.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1530,4 +1530,68 @@ InModuleScope $script:moduleName {
}
}
}

Describe 'Testing Restart-ReportingServicesService' {
Context 'When restarting a Report Services default instance' {
BeforeAll {
$mockServiceName = 'ReportServer'

Mock -CommandName Restart-Service -Verifiable
Mock -CommandName Start-Service -Verifiable
Mock -CommandName Get-Service -MockWith {
return @{
Name = $mockServiceName
DependentServices = @(
@{
Name = 'DependentService'
Status = 'Running'
DependentServices = @()
}
)
}
}
}

It 'Should restart the service and dependent service' {
{ Restart-ReportingServicesService -SQLInstanceName 'MSSQLSERVER' } | Should Not Throw

Assert-MockCalled -CommandName Get-Service -ParameterFilter {
$Name -eq $mockServiceName
} -Scope It -Exactly -Times 1
Assert-MockCalled -CommandName Restart-Service -Scope It -Exactly -Times 1
Assert-MockCalled -CommandName Start-Service -Scope It -Exactly -Times 1
}
}

Context 'When restarting a Report Services named instance' {
BeforeAll {
$mockServiceName = 'ReportServer$TEST'

Mock -CommandName Restart-Service -Verifiable
Mock -CommandName Start-Service -Verifiable
Mock -CommandName Get-Service -MockWith {
return @{
Name = $mockServiceName
DependentServices = @(
@{
Name = 'DependentService'
Status = 'Running'
DependentServices = @()
}
)
}
}
}

It 'Should restart the service and dependent service' {
{ Restart-ReportingServicesService -SQLInstanceName 'TEST' } | Should Not Throw

Assert-MockCalled -CommandName Get-Service -ParameterFilter {
$Name -eq $mockServiceName
} -Scope It -Exactly -Times 1
Assert-MockCalled -CommandName Restart-Service -Scope It -Exactly -Times 1
Assert-MockCalled -CommandName Start-Service -Scope It -Exactly -Times 1
}
}
}
}
4 changes: 2 additions & 2 deletions en-US/xSQLServerHelper.strings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ ConvertFrom-StringData @'
BringClusterResourcesOffline = Bringing the SQL Server resources {0} offline.
BringSqlServerClusterResourcesOnline = Bringing the SQL Server resource back online.
BringSqlServerAgentClusterResourcesOnline = Bringing the SQL Server Agent resource online.
GetSqlServerService = Getting SQL Server service information.
RestartSqlServerService = SQL Server service restarting.
GetServiceInformation = Getting {0} service information.
RestartService = {0} service restarting.
StartingDependentService = Starting service {0}
ExecuteQueryWithResultsFailed = Executing query with results failed on database '{0}'.
ExecuteNonQueryFailed = Executing non-query failed on database '{0}'.
Expand Down
53 changes: 51 additions & 2 deletions xSQLServerHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ function Restart-SqlService
}
else
{
Write-Verbose -Message ($script:localizedData.GetSqlServerService) -Verbose
Write-Verbose -Message ($script:localizedData.GetServiceInformation -f 'SQL Server') -Verbose
$sqlService = Get-Service -DisplayName "SQL Server ($($serverObject.ServiceName))"

<#
Expand All @@ -829,7 +829,7 @@ function Restart-SqlService
$agentService = $sqlService.DependentServices | Where-Object -FilterScript { $_.Status -eq 'Running' }

# Restart the SQL Server service
Write-Verbose -Message ($script:localizedData.RestartSqlServerService) -Verbose
Write-Verbose -Message ($script:localizedData.RestartService -f 'SQL Server') -Verbose
$sqlService | Restart-Service -Force

# Start dependent services
Expand All @@ -840,6 +840,55 @@ function Restart-SqlService
}
}

<#
.SYNOPSIS
Restarts a SQL Server instance and associated services
.PARAMETER SQLServer
Hostname of the SQL Server to be configured
.PARAMETER SQLInstanceName
Name of the SQL instance to be configured. Default is 'MSSQLSERVER'
#>
function Restart-ReportingServicesService
{
[CmdletBinding()]
param
(
[Parameter()]
[System.String]
$SQLInstanceName = 'MSSQLSERVER'
)

$ServiceName = 'ReportServer'

if (-not ($SQLInstanceName -eq 'MSSQLSERVER'))
{
$ServiceName += '${0}' -f $SQLInstanceName
}

Write-Verbose -Message ($script:localizedData.GetServiceInformation -f 'Reporting Services') -Verbose
$reportingServicesService = Get-Service -Name $ServiceName

<#
Get all dependent services that are running.
There are scenarios where an automatic service is stopped and should
not be restarted automatically.
#>
$dependentService = $reportingServicesService.DependentServices | Where-Object -FilterScript {
$_.Status -eq 'Running'
}

Write-Verbose -Message ($script:localizedData.RestartService -f 'Reporting Services') -Verbose
$reportingServicesService | Restart-Service -Force

# Start dependent services
$dependentService | ForEach-Object {
Write-Verbose -Message ($script:localizedData.StartingDependentService -f $_.DisplayName) -Verbose
$_ | Start-Service
}
}

<#
.SYNOPSIS
Executes a query on the specified database.
Expand Down

0 comments on commit f1fb6a8

Please sign in to comment.