From e338a4d4990164643b80b69420e40e202400c7d5 Mon Sep 17 00:00:00 2001 From: John Barnes <31294925+jrdbarnes@users.noreply.github.com> Date: Thu, 23 Jun 2022 11:12:40 +0100 Subject: [PATCH] #1759 SQLAlwaysOnService: Get-TargetResource should return Ensure=Absent Remove IsHadrEnabled and return the state in Ensure. Update Test-TargetResource to look at Ensure instead of IsHadrEnabled. Update Tests to match. --- CHANGELOG.md | 4 ++++ .../DSC_SqlAlwaysOnService/DSC_SqlAlwaysOnService.psm1 | 7 ++++--- .../DSC_SqlAlwaysOnService.schema.mof | 1 - .../DSC_SqlAlwaysOnService.Integration.Tests.ps1 | 4 ++-- tests/Unit/DSC_SqlAlwaysOnService.Tests.ps1 | 10 +++------- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ab36284d..66ef70812 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/source/DSCResources/DSC_SqlAlwaysOnService/DSC_SqlAlwaysOnService.psm1 b/source/DSCResources/DSC_SqlAlwaysOnService/DSC_SqlAlwaysOnService.psm1 index 4c87a7889..043ae8c39 100644 --- a/source/DSCResources/DSC_SqlAlwaysOnService/DSC_SqlAlwaysOnService.psm1 +++ b/source/DSCResources/DSC_SqlAlwaysOnService/DSC_SqlAlwaysOnService.psm1 @@ -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') { diff --git a/source/DSCResources/DSC_SqlAlwaysOnService/DSC_SqlAlwaysOnService.schema.mof b/source/DSCResources/DSC_SqlAlwaysOnService/DSC_SqlAlwaysOnService.schema.mof index dc7edafd0..27bc084ca 100644 --- a/source/DSCResources/DSC_SqlAlwaysOnService/DSC_SqlAlwaysOnService.schema.mof +++ b/source/DSCResources/DSC_SqlAlwaysOnService/DSC_SqlAlwaysOnService.schema.mof @@ -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; }; diff --git a/tests/Integration/DSC_SqlAlwaysOnService.Integration.Tests.ps1 b/tests/Integration/DSC_SqlAlwaysOnService.Integration.Tests.ps1 index 0036c2039..fa33eb18b 100644 --- a/tests/Integration/DSC_SqlAlwaysOnService.Integration.Tests.ps1 +++ b/tests/Integration/DSC_SqlAlwaysOnService.Integration.Tests.ps1 @@ -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' { diff --git a/tests/Unit/DSC_SqlAlwaysOnService.Tests.ps1 b/tests/Unit/DSC_SqlAlwaysOnService.Tests.ps1 index 3ed0f5abe..8cc925410 100644 --- a/tests/Unit/DSC_SqlAlwaysOnService.Tests.ps1 +++ b/tests/Unit/DSC_SqlAlwaysOnService.Tests.ps1 @@ -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 } } }