From 56920cbedc740f52477fe9eae032ca406fbba0f9 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Thu, 25 Apr 2019 14:20:14 +0200 Subject: [PATCH] Changes to SqlServerEndpoint - Added en-US localization (issue #611). --- CHANGELOG.md | 2 + .../MSFT_SqlServerEndpoint.psm1 | 75 +++++++++++++++---- .../en-US/MSFT_SqlServerEndpoint.strings.psd1 | 16 ++++ .../en-US/DscResource.Common.strings.psd1 | 2 - .../sv-SE/DscResource.Common.strings.psd1 | 2 - Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1 | 10 +-- 6 files changed, 82 insertions(+), 25 deletions(-) create mode 100644 DSCResources/MSFT_SqlServerEndpoint/en-US/MSFT_SqlServerEndpoint.strings.psd1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 0aa6a88987..30af2c2c73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,8 @@ - Added en-US localization ([issue #625](https://github.com/PowerShell/SqlServerDsc/issues/625)). - Changes to SqlServerPermission - Added en-US localization ([issue #619](https://github.com/PowerShell/SqlServerDsc/issues/619)). +- Changes to SqlServerEndpoint + - Added en-US localization ([issue #611](https://github.com/PowerShell/SqlServerDsc/issues/611)). - Changes to SqlServerEndpointState - Added en-US localization ([issue #613](https://github.com/PowerShell/SqlServerDsc/issues/613)). diff --git a/DSCResources/MSFT_SqlServerEndpoint/MSFT_SqlServerEndpoint.psm1 b/DSCResources/MSFT_SqlServerEndpoint/MSFT_SqlServerEndpoint.psm1 index 927d250f2a..bb5d977702 100644 --- a/DSCResources/MSFT_SqlServerEndpoint/MSFT_SqlServerEndpoint.psm1 +++ b/DSCResources/MSFT_SqlServerEndpoint/MSFT_SqlServerEndpoint.psm1 @@ -7,6 +7,8 @@ Import-Module -Name (Join-Path -Path $script:localizationModulePath -ChildPath ' $script:resourceHelperModulePath = Join-Path -Path $script:modulesFolderPath -ChildPath 'DscResource.Common' Import-Module -Name (Join-Path -Path $script:resourceHelperModulePath -ChildPath 'DscResource.Common.psm1') +$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlServerEndpoint' + <# .SYNOPSIS Returns the current state of the endpoint. @@ -39,6 +41,10 @@ function Get-TargetResource $InstanceName ) + Write-Verbose -Message ( + $script:localizedData.GetEndpoint -f $EndpointName, $InstanceName + ) + $getTargetResourceReturnValues = @{ ServerName = $ServerName InstanceName = $InstanceName @@ -52,16 +58,17 @@ function Get-TargetResource $sqlServerObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName if ($sqlServerObject) { - Write-Verbose -Message ('Connected to {0}\{1}' -f $ServerName, $InstanceName) + Write-Verbose -Message ( + $script:localizedData.ConnectedToInstance -f $ServerName, $InstanceName + ) $endpointObject = $sqlServerObject.Endpoints[$EndpointName] if ($endpointObject.Name -eq $EndpointName) { if ($sqlServerObject.Endpoints[$EndPointName].EndpointType -ne 'DatabaseMirroring') { - throw New-TerminatingError -ErrorType EndpointFoundButWrongType ` - -FormatArgs @($EndpointName) ` - -ErrorCategory InvalidOperation + $errorMessage = $script:localizedData.EndpointFoundButWrongType -f $EndpointName + New-InvalidOperationException -Message $errorMessage } $getTargetResourceReturnValues.Ensure = 'Present' @@ -81,9 +88,8 @@ function Get-TargetResource } else { - throw New-TerminatingError -ErrorType NotConnectedToInstance ` - -FormatArgs @($ServerName, $InstanceName) ` - -ErrorCategory InvalidOperation + $errorMessage = $script:localizedData.NotConnectedToInstance -f $ServerName, $InstanceName + New-InvalidOperationException -Message $errorMessage } return $getTargetResourceReturnValues @@ -156,7 +162,9 @@ function Set-TargetResource { if ($Ensure -eq 'Present' -and $getTargetResourceResult.Ensure -eq 'Absent') { - Write-Verbose -Message ('Creating endpoint {0}.' -f $EndpointName) + Write-Verbose -Message ( + $script:localizedData.CreateEndpoint -f $EndpointName, $InstanceName + ) $endpointObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Endpoint -ArgumentList $sqlServerObject, $EndpointName $endpointObject.EndpointType = [Microsoft.SqlServer.Management.Smo.EndpointType]::DatabaseMirroring @@ -177,34 +185,48 @@ function Set-TargetResource } elseif ($Ensure -eq 'Present' -and $getTargetResourceResult.Ensure -eq 'Present') { + Write-Verbose -Message ( + $script:localizedData.SetEndpoint -f $EndpointName, $InstanceName + ) + # The endpoint already exist, verifying supported endpoint properties so they are in desired state. $endpointObject = $sqlServerObject.Endpoints[$EndpointName] if ($endpointObject) { if ($endpointObject.Protocol.Tcp.ListenerIPAddress -ne $IpAddress) { - Write-Verbose -Message ('Updating endpoint {0} IP address to {1}.' -f $EndpointName, $IpAddress) + Write-Verbose -Message ( + $script:localizedData.UpdatingEndpointIPAddress -f $IpAddress + ) + $endpointObject.Protocol.Tcp.ListenerIPAddress = $IpAddress $endpointObject.Alter() } if ($endpointObject.Protocol.Tcp.ListenerPort -ne $Port) { - Write-Verbose -Message ('Updating endpoint {0} port to {1}.' -f $EndpointName, $Port) + Write-Verbose -Message ( + $script:localizedData.UpdatingEndpointPort -f $Port + ) + $endpointObject.Protocol.Tcp.ListenerPort = $Port $endpointObject.Alter() } if ($endpointObject.Owner -ne $Owner) { - Write-Verbose -Message ('Updating endpoint {0} Owner to {1}.' -f $EndpointName, $Owner) + Write-Verbose -Message ( + $script:localizedData.UpdatingEndpointOwner -f $Owner + ) + $endpointObject.Owner = $Owner $endpointObject.Alter() } } else { - throw New-TerminatingError -ErrorType EndpointNotFound -FormatArgs @($EndpointName) -ErrorCategory ObjectNotFound + $errorMessage = $script:localizedData.EndpointNotFound -f $EndpointName + New-ObjectNotFoundException -Message $errorMessage } } elseif ($Ensure -eq 'Absent' -and $getTargetResourceResult.Ensure -eq 'Present') @@ -214,19 +236,23 @@ function Set-TargetResource $endpointObject = $sqlServerObject.Endpoints[$EndpointName] if ($endpointObject) { + Write-Verbose -Message ( + $script:localizedData.DropEndpoint -f $EndpointName, $InstanceName + ) + $endpointObject.Drop() } else { - throw New-TerminatingError -ErrorType EndpointNotFound -FormatArgs @($EndpointName) -ErrorCategory ObjectNotFound + $errorMessage = $script:localizedData.EndpointNotFound -f $EndpointName + New-ObjectNotFoundException -Message $errorMessage } } } else { - throw New-TerminatingError -ErrorType NotConnectedToInstance ` - -FormatArgs @($ServerName, $InstanceName) ` - -ErrorCategory InvalidOperation + $errorMessage = $script:localizedData.NotConnectedToInstance -f $ServerName, $InstanceName + New-InvalidOperationException -Message $errorMessage } } @@ -291,6 +317,10 @@ function Test-TargetResource $Owner ) + Write-Verbose -Message ( + $script:localizedData.TestingConfiguration -f $EndpointName, $InstanceName + ) + $getTargetResourceResult = Get-TargetResource -EndpointName $EndpointName -ServerName $ServerName -InstanceName $InstanceName if ($getTargetResourceResult.Ensure -eq $Ensure) { @@ -317,6 +347,19 @@ function Test-TargetResource $result = $false } + if ($result) + { + Write-Verbose -Message ( + $script:localizedData.InDesiredState -f $EndpointName + ) + } + else + { + Write-Verbose -Message ( + $script:localizedData.NotInDesiredState -f $EndpointName + ) + } + return $result } diff --git a/DSCResources/MSFT_SqlServerEndpoint/en-US/MSFT_SqlServerEndpoint.strings.psd1 b/DSCResources/MSFT_SqlServerEndpoint/en-US/MSFT_SqlServerEndpoint.strings.psd1 new file mode 100644 index 0000000000..fc20c5c6f7 --- /dev/null +++ b/DSCResources/MSFT_SqlServerEndpoint/en-US/MSFT_SqlServerEndpoint.strings.psd1 @@ -0,0 +1,16 @@ +ConvertFrom-StringData @' + GetEndpoint = Getting the current values of the endpoint with the name '{0}' for the instance '{1}'. + EndpointFoundButWrongType = Endpoint '{0}' does exist, but it is not of type 'DatabaseMirroring'. + ConnectedToInstance = Connect to the instance '{0}\\{1}'. + NotConnectedToInstance = Was unable to connect to the instance '{0}\\{1}'. + SetEndpoint = Changing the values of the endpoint with the name '{0}' for the instance '{1}'. + CreateEndpoint = Creating the endpoint '{0}' on the instance '{1}'. + UpdatingEndpointIPAddress = Updating the endpoint IP address to '{0}'. + UpdatingEndpointPort = Updating the endpoint port to '{0}'. + UpdatingEndpointOwner = Updating the endpoint owner to '{0}'. + EndpointNotFound = The endpoint with the name '{0}' does not exist. + DropEndpoint = Removing the endpoint '{0}' on the instance '{1}'. + TestingConfiguration = Determines if the endpoint with the name '{0}' for the instance '{1}' is in desired state. + InDesiredState = The endpoint '{0}' is the desired state. + NotInDesiredState = The endpoint '{0}' is not in the desired state. +'@ diff --git a/Modules/DscResource.Common/en-US/DscResource.Common.strings.psd1 b/Modules/DscResource.Common/en-US/DscResource.Common.strings.psd1 index 803740be06..534c323493 100644 --- a/Modules/DscResource.Common/en-US/DscResource.Common.strings.psd1 +++ b/Modules/DscResource.Common/en-US/DscResource.Common.strings.psd1 @@ -69,7 +69,6 @@ ConvertFrom-StringData @' RemoteConnectionFailed = Remote PowerShell connection to Server '{0}' failed. TODO = ToDo. Work not implemented at this time. UnexpectedErrorFromGet = Got unexpected result from Get-TargetResource. No change is made. - NotConnectedToInstance = Was unable to connect to the instance '{0}\\{1}' AlterAvailabilityGroupFailed = Failed to alter the availability group '{0}'. HadrNotEnabled = HADR is not enabled. AvailabilityGroupNotFound = Unable to locate the availability group '{0}' on the instance '{1}'. @@ -97,7 +96,6 @@ ConvertFrom-StringData @' # Endpoint EndpointNotFound = Endpoint '{0}' does not exist EndpointErrorVerifyExist = Unexpected result when trying to verify existence of endpoint '{0}'. - EndpointFoundButWrongType = Endpoint '{0}' does exist, but it is not of type 'DatabaseMirroring'. # AlwaysOnService AlterAlwaysOnServiceFailed = Failed to ensure Always On is {0} on the instance '{1}'. diff --git a/Modules/DscResource.Common/sv-SE/DscResource.Common.strings.psd1 b/Modules/DscResource.Common/sv-SE/DscResource.Common.strings.psd1 index fc258473a9..43936a09ee 100644 --- a/Modules/DscResource.Common/sv-SE/DscResource.Common.strings.psd1 +++ b/Modules/DscResource.Common/sv-SE/DscResource.Common.strings.psd1 @@ -58,7 +58,6 @@ ConvertFrom-StringData @' RemoteConnectionFailed = Remote PowerShell connection to Server '{0}' failed. TODO = ToDo. Work not implemented at this time. UnexpectedErrorFromGet = Got unexpected result from Get-TargetResource. No change is made. - NotConnectedToInstance = Was unable to connect to the instance '{0}\\{1}' AlterAvailabilityGroupFailed = Failed to alter the availability group '{0}'. HadrNotEnabled = HADR is not enabled. AvailabilityGroupNotFound = Unable to locate the availability group '{0}' on the instance '{1}'. @@ -86,7 +85,6 @@ ConvertFrom-StringData @' # Endpoint EndpointNotFound = Endpoint '{0}' does not exist EndpointErrorVerifyExist = Unexpected result when trying to verify existence of endpoint '{0}'. - EndpointFoundButWrongType = Endpoint '{0}' does exist, but it is not of type 'DatabaseMirroring'. # Configuration ConfigurationOptionNotFound = Specified option '{0}' could not be found. diff --git a/Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1 b/Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1 index 86843d44bf..3cbec6c3e8 100644 --- a/Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1 @@ -227,7 +227,7 @@ try Context 'When endpoint exist but with wrong endpoint type' { It 'Should throw the correct error' { - { Get-TargetResource @testParameters } | Should -Throw 'Endpoint ''DefaultEndpointMirror'' does exist, but it is not of type ''DatabaseMirroring''.' + { Get-TargetResource @testParameters } | Should -Throw ($script:localizedData.EndpointFoundButWrongType -f $testParameters.EndpointName) } } @@ -241,7 +241,7 @@ try return $null } - { Get-TargetResource @testParameters } | Should -Throw 'Was unable to connect to the instance ''localhost\INSTANCE1''' + { Get-TargetResource @testParameters } | Should -Throw ($script:localizedData.NotConnectedToInstance -f $testParameters.ServerName, $testParameters.InstanceName) } } @@ -583,7 +583,7 @@ try } } -Verifiable - { Set-TargetResource @testParameters } | Should -Throw 'Endpoint ''DefaultEndpointMirror'' does not exist' + { Set-TargetResource @testParameters } | Should -Throw ($script:localizedData.EndpointNotFound -f $testParameters.EndpointName) } } @@ -600,7 +600,7 @@ try $testParameters.Add('Ensure', 'Absent') - { Set-TargetResource @testParameters } | Should -Throw 'Endpoint ''DefaultEndpointMirror'' does not exist' + { Set-TargetResource @testParameters } | Should -Throw ($script:localizedData.EndpointNotFound -f $testParameters.EndpointName) } } @@ -611,7 +611,7 @@ try return $null } - { Set-TargetResource @testParameters } | Should -Throw 'Was unable to connect to the instance ''localhost\INSTANCE1''' + { Set-TargetResource @testParameters } | Should -Throw ($script:localizedData.NotConnectedToInstance -f $testParameters.ServerName, $testParameters.InstanceName) } } }