Skip to content

Commit

Permalink
BREAKING CHANGE: SQLAlwaysOnService: Get-TargetResource should return…
Browse files Browse the repository at this point in the history
… Ensure=Absent (#1760)

- 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.
jrdbarnes authored Jul 28, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 183b163 commit eb65b8f
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
@@ -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

Original file line number Diff line number Diff line change
@@ -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 (
@@ -74,10 +76,9 @@ function Get-TargetResource

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

@@ -244,7 +245,7 @@ function Test-TargetResource

$isInDesiredState = $true

if ($state.IsHadrEnabled)
if ($state.Ensure -eq 'Present')
{
if ($Ensure -eq 'Present')
{
Original file line number Diff line number Diff line change
@@ -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
@@ -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' {
@@ -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' {
10 changes: 3 additions & 7 deletions tests/Unit/DSC_SqlAlwaysOnService.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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
@@ -275,7 +275,6 @@ Describe 'SqlAlwaysOnService\Test-TargetResource' {
Ensure = 'Absent'
ServerName = 'Server01'
RestartTimeout = 120
IsHadrEnabled = $false
}
}
}
@@ -304,7 +303,6 @@ Describe 'SqlAlwaysOnService\Test-TargetResource' {
Ensure = 'Present'
ServerName = 'Server01'
RestartTimeout = 120
IsHadrEnabled = $true
}
}
}
@@ -346,7 +344,6 @@ Describe 'SqlAlwaysOnService\Test-TargetResource' {
Ensure = 'Present'
ServerName = 'Server01'
RestartTimeout = 120
IsHadrEnabled = $true
}
}
}
@@ -375,7 +372,6 @@ Describe 'SqlAlwaysOnService\Test-TargetResource' {
Ensure = 'Absent'
ServerName = 'Server01'
RestartTimeout = 120
IsHadrEnabled = $false
}
}
}

0 comments on commit eb65b8f

Please sign in to comment.