Skip to content

Commit

Permalink
dsccommunity#1759 SQLAlwaysOnService: Get-TargetResource should retur…
Browse files Browse the repository at this point in the history
…n Ensure=Absent

Remove IsHadrEnabled and return the state in Ensure.
Update Test-TargetResource to look at Ensure instead of IsHadrEnabled.
Update Tests to match.
  • Loading branch information
jrdbarnes committed Jun 23, 2022
1 parent c71947e commit e338a4d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- SqlDatabaseRole
- `Test-TargetResource` returns true if the `IsUpdateable` property of the
database is `$false` to resolve issue #1750.
- SqlAlwaysOnService
- BREAKING CHANGE: The parameter `IsHadrEnabled` is no longer returned by
`Get-TargetResource`. The `Ensure` parameter now returns `Present` if
Always On HADR is enabled and `Absent` if it is disabled.

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ function Get-TargetResource
if ($isAlwaysOnEnabled -eq $true)
{
$statusString = 'enabled'
$EnsureStatus = 'Present'
}
elseif ($isAlwaysOnEnabled -eq $false)
{
$statusString = 'disabled'
$EnsureStatus = 'Absent'
}

Write-Verbose -Message (
Expand All @@ -74,10 +76,9 @@ function Get-TargetResource

return @{
InstanceName = $InstanceName
Ensure = $Ensure
Ensure = $EnsureStatus
ServerName = $ServerName
RestartTimeout = $RestartTimeout
IsHadrEnabled = $isAlwaysOnEnabled
}
}

Expand Down Expand Up @@ -244,7 +245,7 @@ function Test-TargetResource

$isInDesiredState = $true

if ($state.IsHadrEnabled)
if ($state.Ensure -eq 'Present')
{
if ($Ensure -eq 'Present')
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ class DSC_SqlAlwaysOnService : OMI_BaseResource
[Required, Description("An enumerated value that describes if the _SQL Server_ should have _Always On High Availability and Disaster Recovery_ (HADR) property enabled (`'Present'`) or disabled (`'Absent'`)."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
[Write, Description("The hostname of the _SQL Server_ to be configured. Default value is the current computer name.")] String ServerName;
[Write, Description("The length of time, in seconds, to wait for the service to restart. Default value is `120` seconds.")] UInt32 RestartTimeout;
[Read, Description("Returns the status of _AlwaysOn High Availability and Disaster Recovery_ (HADR).")] Boolean IsHadrEnabled;
};
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag 'Skip' {
-and $_.ResourceId -eq $resourceId
}

$resourceCurrentState.IsHadrEnabled | Should -Be $true
$resourceCurrentState.Ensure | Should -Be 'Present'
}

It 'Should return $true when Test-DscConfiguration is run' {
Expand Down Expand Up @@ -196,7 +196,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag 'Skip' {
-and $_.ResourceId -eq $resourceId
}

$resourceCurrentState.IsHadrEnabled | Should -Be $false
$resourceCurrentState.Ensure | Should -Be 'Absent'
}

It 'Should return $true when Test-DscConfiguration is run' {
Expand Down
10 changes: 3 additions & 7 deletions tests/Unit/DSC_SqlAlwaysOnService.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Describe 'SqlAlwaysOnService\Get-TargetResource' {

$result = Get-TargetResource @mockGetTargetResourceParameters

$result.IsHadrEnabled | Should -BeFalse
$result.Ensure | Should -Be 'Absent'
}

Should -Invoke -CommandName Connect-SQL -Scope It -Times 1 -Exactly
Expand Down Expand Up @@ -166,7 +166,7 @@ Describe 'SqlAlwaysOnService\Get-TargetResource' {

$result = Get-TargetResource @mockGetTargetResourceParameters

$result.IsHadrEnabled | Should -BeTrue
$result.Ensure | Should -Be 'Present'
}

Should -Invoke -CommandName Connect-SQL -Scope It -Times 1 -Exactly
Expand Down Expand Up @@ -230,7 +230,7 @@ Describe 'SqlAlwaysOnService\Get-TargetResource' {
# Get the current state
$result = Get-TargetResource @mockGetTargetResourceParameters

$result.IsHadrEnabled | Should -BeFalse
$result.Ensure | Should -Be 'Absent'
}

Should -Invoke -CommandName Connect-SQL -Scope It -Times 1 -Exactly
Expand Down Expand Up @@ -275,7 +275,6 @@ Describe 'SqlAlwaysOnService\Test-TargetResource' {
Ensure = 'Absent'
ServerName = 'Server01'
RestartTimeout = 120
IsHadrEnabled = $false
}
}
}
Expand Down Expand Up @@ -304,7 +303,6 @@ Describe 'SqlAlwaysOnService\Test-TargetResource' {
Ensure = 'Present'
ServerName = 'Server01'
RestartTimeout = 120
IsHadrEnabled = $true
}
}
}
Expand Down Expand Up @@ -346,7 +344,6 @@ Describe 'SqlAlwaysOnService\Test-TargetResource' {
Ensure = 'Present'
ServerName = 'Server01'
RestartTimeout = 120
IsHadrEnabled = $true
}
}
}
Expand Down Expand Up @@ -375,7 +372,6 @@ Describe 'SqlAlwaysOnService\Test-TargetResource' {
Ensure = 'Absent'
ServerName = 'Server01'
RestartTimeout = 120
IsHadrEnabled = $false
}
}
}
Expand Down

0 comments on commit e338a4d

Please sign in to comment.