From 85945a2f0adb70e5871ac6510c1b1ab4153025f9 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 17 Nov 2017 19:14:37 +0100 Subject: [PATCH] Changes to SqlServerEndpointState - BREAKING CHANGE: Parameter NodeName has been renamed to ServerName (issue #308). --- CHANGELOG.md | 3 ++ .../MSFT_SqlServerEndpointState.psm1 | 22 +++++----- .../MSFT_SqlServerEndpointState.schema.mof | 2 +- .../1-MakeSureEndpointIsStarted.ps1 | 6 +-- .../2-MakeSureEndpointIsStopped.ps1 | 2 +- .../MSFT_SqlServerEndpointState.Tests.ps1 | 44 ++++++++++--------- 6 files changed, 42 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c7d6bbcb..bd0ee2198 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,9 @@ - Changes to SqlServerEndpointPermission - BREAKING CHANGE: Parameter NodeName has been renamed to ServerName ([issue #308](https://github.com/PowerShell/xSQLServer/issues/)). +- Changes to SqlServerEndpointState + - BREAKING CHANGE: Parameter NodeName has been renamed to ServerName + ([issue #308](https://github.com/PowerShell/xSQLServer/issues/)). - Changes to SqlServerLogin - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed to ServerName and InstanceName respectivly ([issue #308](https://github.com/PowerShell/xSQLServer/issues/)). diff --git a/DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.psm1 b/DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.psm1 index 9e81c222a..b1deecd0c 100644 --- a/DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.psm1 +++ b/DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.psm1 @@ -8,7 +8,7 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER InstanceName The name of the SQL instance to be configured. - .PARAMETER NodeName + .PARAMETER ServerName The host name of the SQL Server to be configured. .PARAMETER Name @@ -26,7 +26,7 @@ function Get-TargetResource [Parameter()] [System.String] - $NodeName = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -37,7 +37,7 @@ function Get-TargetResource try { - $sqlServerObject = Connect-SQL -SQLServer $NodeName -SQLInstanceName $InstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName $endpointObject = $sqlServerObject.Endpoints[$Name] if ($null -ne $endpointObject) @@ -56,7 +56,7 @@ function Get-TargetResource return @{ InstanceName = [System.String] $InstanceName - NodeName = [System.String] $NodeName + ServerName = [System.String] $ServerName Name = [System.String] $Name State = [System.String] $currentState } @@ -69,7 +69,7 @@ function Get-TargetResource .PARAMETER InstanceName The name of the SQL instance to be configured. - .PARAMETER NodeName + .PARAMETER ServerName The host name of the SQL Server to be configured. .PARAMETER Name @@ -89,7 +89,7 @@ function Set-TargetResource [Parameter()] [System.String] - $NodeName = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -103,7 +103,7 @@ function Set-TargetResource $parameters = @{ InstanceName = [System.String] $InstanceName - NodeName = [System.String] $NodeName + ServerName = [System.String] $ServerName Name = [System.String] $Name } @@ -114,7 +114,7 @@ function Set-TargetResource { New-VerboseMessage -Message ('Changing state of endpoint ''{0}''' -f $Name) - $sqlServerObject = Connect-SQL -SQLServer $NodeName -SQLInstanceName $InstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName $endpointObject = $sqlServerObject.Endpoints[$Name] @@ -143,7 +143,7 @@ function Set-TargetResource .PARAMETER InstanceName The name of the SQL instance to be configured. - .PARAMETER NodeName + .PARAMETER ServerName The host name of the SQL Server to be configured. .PARAMETER Name @@ -164,7 +164,7 @@ function Test-TargetResource [Parameter()] [System.String] - $NodeName = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -178,7 +178,7 @@ function Test-TargetResource $parameters = @{ InstanceName = $InstanceName - NodeName = $NodeName + ServerName = $ServerName Name = $Name } diff --git a/DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.schema.mof b/DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.schema.mof index 5e4bd5fc5..61062db7b 100644 --- a/DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.schema.mof +++ b/DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.schema.mof @@ -2,7 +2,7 @@ class MSFT_SqlServerEndpointState : OMI_BaseResource { [Key, Description("The name of the SQL instance to be configured.")] String InstanceName; - [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String NodeName; + [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String ServerName; [Key, Description("The name of the endpoint.")] String Name; [Write, Description("The state of the endpoint. Valid states are Started, Stopped or Disabled. Default value is 'Started'."), ValueMap{"Started","Stopped","Disabled"}, Values{"Started","Stopped","Disabled"}] String State; }; diff --git a/Examples/Resources/SqlServerEndpointState/1-MakeSureEndpointIsStarted.ps1 b/Examples/Resources/SqlServerEndpointState/1-MakeSureEndpointIsStarted.ps1 index 4a7e154a1..21f34abc6 100644 --- a/Examples/Resources/SqlServerEndpointState/1-MakeSureEndpointIsStarted.ps1 +++ b/Examples/Resources/SqlServerEndpointState/1-MakeSureEndpointIsStarted.ps1 @@ -28,7 +28,7 @@ Configuration Example # Start the DefaultMirrorEndpoint in the default instance SqlServerEndpointState StartEndpoint1 { - NodeName = 'SQLNODE01.company.local' + ServerName = 'SQLNODE01.company.local' InstanceName = 'MSSQLSERVER' Name = 'DefaultMirrorEndpoint' State = 'Started' @@ -39,7 +39,7 @@ Configuration Example # Start the HADR in the default instance SqlServerEndpointState StartEndpoint2 { - NodeName = 'SQLNODE01.company.local' + ServerName = 'SQLNODE01.company.local' InstanceName = 'MSSQLSERVER' Name = 'HADR' State = 'Started' @@ -50,7 +50,7 @@ Configuration Example # Start the DefaultMirrorEndpoint in the named instance INSTANCE1 SqlServerEndpointState StartEndpoint3 { - NodeName = 'SQLNODE01.company.local' + ServerName = 'SQLNODE01.company.local' InstanceName = 'INSTANCE1' Name = 'DefaultMirrorEndpoint' State = 'Started' diff --git a/Examples/Resources/SqlServerEndpointState/2-MakeSureEndpointIsStopped.ps1 b/Examples/Resources/SqlServerEndpointState/2-MakeSureEndpointIsStopped.ps1 index 0fd1dac00..882fd32c8 100644 --- a/Examples/Resources/SqlServerEndpointState/2-MakeSureEndpointIsStopped.ps1 +++ b/Examples/Resources/SqlServerEndpointState/2-MakeSureEndpointIsStopped.ps1 @@ -18,7 +18,7 @@ Configuration Example { SqlServerEndpointState StopEndpoint { - NodeName = 'SQLNODE01.company.local' + ServerName = 'SQLNODE01.company.local' InstanceName = 'MSSQLSERVER' Name = 'DefaultMirrorEndpoint' State = 'Stopped' diff --git a/Tests/Unit/MSFT_SqlServerEndpointState.Tests.ps1 b/Tests/Unit/MSFT_SqlServerEndpointState.Tests.ps1 index becb6e759..385aa7f62 100644 --- a/Tests/Unit/MSFT_SqlServerEndpointState.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerEndpointState.Tests.ps1 @@ -1,14 +1,14 @@ -$script:DSCModuleName = 'SqlServerDsc' -$script:DSCResourceName = 'MSFT_SqlServerEndpointState' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlServerEndpointState' #region HEADER # Unit Test Template Version: 1.2.0 $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) } Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force @@ -20,12 +20,14 @@ $TestEnvironment = Initialize-TestEnvironment ` #endregion HEADER -function Invoke-TestSetup { +function Invoke-TestSetup +{ # Loading stub cmdlets Import-Module -Name ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SQLPSStub.psm1 ) -Force -Global } -function Invoke-TestCleanup { +function Invoke-TestCleanup +{ Restore-TestEnvironment -TestEnvironment $TestEnvironment } @@ -49,21 +51,21 @@ try $mockConnectSql = { return New-Object Object | Add-Member -MemberType ScriptProperty -Name 'Endpoints' { - return @( - @{ - # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint - $mockDynamicEndpointName = New-Object Object | - Add-Member -MemberType NoteProperty -Name 'Name' -Value $mockDynamicEndpointName -PassThru | - Add-Member -MemberType NoteProperty -Name 'EndpointState' -Value $mockDynamicEndpointState -PassThru -Force - } - ) - } -PassThru -Force + return @( + @{ + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + $mockDynamicEndpointName = New-Object Object | + Add-Member -MemberType NoteProperty -Name 'Name' -Value $mockDynamicEndpointName -PassThru | + Add-Member -MemberType NoteProperty -Name 'EndpointState' -Value $mockDynamicEndpointState -PassThru -Force + } + ) + } -PassThru -Force } $defaultParameters = @{ InstanceName = $mockInstanceName - NodeName = $mockNodeName - Name = $mockEndpointName + ServerName = $mockNodeName + Name = $mockEndpointName } #endregion Pester Test Initialization @@ -88,7 +90,7 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.NodeName | Should -Be $testParameters.NodeName + $result.ServerName | Should -Be $testParameters.ServerName $result.InstanceName | Should -Be $testParameters.InstanceName $result.Name | Should -Be $testParameters.Name } @@ -109,7 +111,7 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.NodeName | Should -Be $testParameters.NodeName + $result.ServerName | Should -Be $testParameters.ServerName $result.InstanceName | Should -Be $testParameters.InstanceName $result.Name | Should -Be $testParameters.Name } @@ -144,7 +146,7 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.NodeName | Should -Be $testParameters.NodeName + $result.ServerName | Should -Be $testParameters.ServerName $result.InstanceName | Should -Be $testParameters.InstanceName $result.Name | Should -Be $testParameters.Name } @@ -165,7 +167,7 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.NodeName | Should -Be $testParameters.NodeName + $result.ServerName | Should -Be $testParameters.ServerName $result.InstanceName | Should -Be $testParameters.InstanceName $result.Name | Should -Be $testParameters.Name }