Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: SQLAlwaysOnService: Get-TargetResource should return Ensure=Absent #1760

Merged
merged 2 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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