Add commands for Start/Stop Report Server#2412
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughAdds four public cmdlets to start/stop SQL Server Reporting Services and Power BI Report Server Windows and Web services through the WMI SetServiceState method, a private Get-RSServiceState helper, localized strings, unit and integration tests, and CI pipeline entries to run the new integration tests. Changes
Sequence Diagram(s)sequenceDiagram
participant User as User/Cmdlet
participant Cmd as Start/Stop<br/>Cmdlet
participant Helper as Get-RSServiceState
participant Invoker as Invoke-RsCimMethod
participant WMI as SetServiceState<br/>(WMI)
participant Service as RS Service
User->>Cmd: Invoke with Configuration (and optional -Force)
Cmd->>Cmd: ShouldProcess / confirmation
Cmd->>Helper: Get-RSServiceState (Enable/Disable switch)
Helper-->>Cmd: Hashtable (EnableWindowsService, EnableWebService,...)
Cmd->>Invoker: Invoke-RsCimMethod MethodName='SetServiceState' with args
Invoker->>WMI: CIM method call
WMI->>Service: Start/Stop Windows or Web service
Service-->>WMI: Operation result
WMI-->>Invoker: Return result
Invoker-->>Cmd: Success or throw
Cmd-->>User: Complete or terminate with error
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2412 +/- ##
=====================================
- Coverage 94% 94% -1%
=====================================
Files 218 223 +5
Lines 10981 11071 +90
=====================================
+ Hits 10358 10432 +74
- Misses 623 639 +16
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@CHANGELOG.md`:
- Line 10: Condense and wrap the long changelog bullet into a short, wrapped
entry (<=80 chars per line) for the Unreleased "Added" list: replace the current
sentence with a concise line that groups the four commands and their purpose,
e.g. mention the commands Start-SqlDscRSWindowsService,
Stop-SqlDscRSWindowsService, Start-SqlDscRSWebService, Stop-SqlDscRSWebService
and that they manage Reporting Services Windows/web services via
SetServiceState; keep it one brief bullet and hard-wrap to 80 characters.
In `@tests/Unit/Public/Start-SqlDscRSWebService.Tests.ps1`:
- Around line 89-90: Replace the Should -Not -Throw pattern by invoking
Start-SqlDscRSWebService directly and discarding its output into $null;
specifically, update the test cases that call Start-SqlDscRSWebService (e.g.,
the block currently using "{ $mockCimInstance | Start-SqlDscRSWebService
-Confirm:$false } | Should -Not -Throw") to call "$null = $mockCimInstance |
Start-SqlDscRSWebService -Confirm:$false" (and do the same for the other
occurrences around the other test cases referencing Start-SqlDscRSWebService) so
the command runs directly without using Should -Not -Throw per test guidelines.
- Around line 46-64: Add a new unit test after the parameter set assertions for
Start-SqlDscRSWebService that validates key parameter attributes: use
Get-Command -Name 'Start-SqlDscRSWebService' to retrieve the command, then
inspect its .Parameters['Configuration'] (and other params like 'Force') and
assert their attributes (e.g., Mandatory, ValueFromPipeline) match expectations;
implement a table-driven It block that iterates expected parameter names and
expected attribute values and uses Should assertions to compare the actual
parameter.Attributes properties to the expected Mandatory/ValueFromPipeline
settings.
🧹 Nitpick comments (9)
source/Private/Get-RSServiceState.ps1 (1)
31-52: Missing.INPUTSsection in comment-based help.As per coding guidelines, comment-based help must include an
.INPUTSsection. Since this function does not accept pipeline input, specifyNone..📝 Proposed fix
.OUTPUTS System.Collections.Hashtable Returns a hashtable with the following keys: - EnableWindowsService: Boolean value for the Windows service state. - EnableWebService: Boolean value for the web service state. - EnableReportManager: Boolean value (deprecated, always matches EnableWebService). + .INPUTS + None. + .EXAMPLEtests/Unit/Public/Stop-SqlDscRSWebService.Tests.ps1 (3)
89-100: AvoidShould -Not -Throw; invoke commands directly.Per coding guidelines, tests should invoke commands directly and let Pester report any unexpected failures naturally rather than wrapping in
Should -Not -Throw.♻️ Proposed fix
It 'Should stop web service without errors' { - { $mockCimInstance | Stop-SqlDscRSWebService -Confirm:$false } | Should -Not -Throw + $null = $mockCimInstance | Stop-SqlDscRSWebService -Confirm:$false Should -Invoke -CommandName Get-RSServiceState -ParameterFilter { $DisableWebService -eq $true } -Exactly -Times 1 Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'SetServiceState' -and $Arguments.EnableWebService -eq $false } -Exactly -Times 1 }
132-136: AvoidShould -Not -Throw.♻️ Proposed fix
It 'Should stop web service without confirmation' { - { $mockCimInstance | Stop-SqlDscRSWebService -Force } | Should -Not -Throw + $null = $mockCimInstance | Stop-SqlDscRSWebService -Force Should -Invoke -CommandName Invoke-RsCimMethod -Exactly -Times 1 }
182-186: AvoidShould -Not -Throw.♻️ Proposed fix
It 'Should stop web service' { - { Stop-SqlDscRSWebService -Configuration $mockCimInstance -Confirm:$false } | Should -Not -Throw + $null = Stop-SqlDscRSWebService -Configuration $mockCimInstance -Confirm:$false Should -Invoke -CommandName Invoke-RsCimMethod -Exactly -Times 1 }tests/Integration/Commands/Start-SqlDscRSWindowsService.Integration.Tests.ps1 (1)
36-52: AvoidShould -Not -Throw; invoke commands directly.Per coding guidelines, integration tests should invoke commands directly. The pattern repeats across all contexts in this file.
♻️ Proposed fix for all test cases
It 'Should start Windows service using pipeline' { $config = Get-SqlDscRSConfiguration -InstanceName 'SSRS' - { $config | Start-SqlDscRSWindowsService -Force -ErrorAction 'Stop' } | Should -Not -Throw + $null = $config | Start-SqlDscRSWindowsService -Force -ErrorAction 'Stop' # Verify Windows service is started $verifyConfig = Get-SqlDscRSConfiguration -InstanceName 'SSRS' $verifyConfig.IsWindowsServiceEnabled | Should -BeTrue } It 'Should be idempotent when Windows service is already started' { $config = Get-SqlDscRSConfiguration -InstanceName 'SSRS' - { $config | Start-SqlDscRSWindowsService -Force -ErrorAction 'Stop' } | Should -Not -Throw + $null = $config | Start-SqlDscRSWindowsService -Force -ErrorAction 'Stop' # Verify Windows service is still started $verifyConfig = Get-SqlDscRSConfiguration -InstanceName 'SSRS' $verifyConfig.IsWindowsServiceEnabled | Should -BeTrue }Apply the same pattern to all remaining contexts (SQL2019_RS, SQL2022_RS, PowerBI).
tests/Integration/Commands/Stop-SqlDscRSWindowsService.Integration.Tests.ps1 (1)
36-52: AvoidShould -Not -Throw; invoke commands directly.Same pattern as the Start tests. Apply the fix across all contexts.
♻️ Proposed fix for all test cases
It 'Should stop Windows service using pipeline' { $config = Get-SqlDscRSConfiguration -InstanceName 'SSRS' - { $config | Stop-SqlDscRSWindowsService -Force -ErrorAction 'Stop' } | Should -Not -Throw + $null = $config | Stop-SqlDscRSWindowsService -Force -ErrorAction 'Stop' # Verify Windows service is stopped $verifyConfig = Get-SqlDscRSConfiguration -InstanceName 'SSRS' $verifyConfig.IsWindowsServiceEnabled | Should -BeFalse } It 'Should be idempotent when Windows service is already stopped' { $config = Get-SqlDscRSConfiguration -InstanceName 'SSRS' - { $config | Stop-SqlDscRSWindowsService -Force -ErrorAction 'Stop' } | Should -Not -Throw + $null = $config | Stop-SqlDscRSWindowsService -Force -ErrorAction 'Stop' # Verify Windows service is still stopped $verifyConfig = Get-SqlDscRSConfiguration -InstanceName 'SSRS' $verifyConfig.IsWindowsServiceEnabled | Should -BeFalse }Apply to all remaining contexts (SQL2019_RS, SQL2022_RS, PowerBI).
tests/Unit/Public/Start-SqlDscRSWindowsService.Tests.ps1 (3)
89-100: AvoidShould -Not -Throw- invoke commands directly.Per coding guidelines,
Should -Not -Throwshould not be used. Instead, invoke the command directly. If the command throws, the test will fail naturally.♻️ Suggested refactor
It 'Should start Windows service without errors' { - { $mockCimInstance | Start-SqlDscRSWindowsService -Confirm:$false } | Should -Not -Throw + $null = $mockCimInstance | Start-SqlDscRSWindowsService -Confirm:$false Should -Invoke -CommandName Get-RSServiceState -ParameterFilter { $EnableWindowsService -eq $true } -Exactly -Times 1 Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'SetServiceState' -and $Arguments.EnableWindowsService -eq $true } -Exactly -Times 1 }
132-136: AvoidShould -Not -Throw- invoke commands directly.Same issue as above. Invoke the command directly instead of using
Should -Not -Throw.♻️ Suggested refactor
It 'Should start Windows service without confirmation' { - { $mockCimInstance | Start-SqlDscRSWindowsService -Force } | Should -Not -Throw + $null = $mockCimInstance | Start-SqlDscRSWindowsService -Force Should -Invoke -CommandName Invoke-RsCimMethod -Exactly -Times 1 }
182-186: AvoidShould -Not -Throw- invoke commands directly.Same pattern as the other contexts. Invoke the command directly.
♻️ Suggested refactor
It 'Should start Windows service' { - { Start-SqlDscRSWindowsService -Configuration $mockCimInstance -Confirm:$false } | Should -Not -Throw + $null = Start-SqlDscRSWindowsService -Configuration $mockCimInstance -Confirm:$false Should -Invoke -CommandName Invoke-RsCimMethod -Exactly -Times 1 }
Pull Request (PR) description
Start-SqlDscRSWindowsService,Stop-SqlDscRSWindowsService,Start-SqlDscRSWebService, andStop-SqlDscRSWebServiceto manage Reporting Services Windows and web services using theSetServiceStateWMI method.This Pull Request (PR) fixes the following issues
None.
Task list
file CHANGELOG.md. Entry should say what was changed and how that
affects users (if applicable), and reference the issue being resolved
(if applicable).
This change is