diff --git a/CHANGELOG.md b/CHANGELOG.md index a87cfd0..590dfee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ - Changed the code to be more aligned with the style guideline. - Updated parameter description in the schema.mof. - Resolved Script Analyzer warnings ([issue #54](https://github.com/PowerShell/xFailOverCluster/issues/54)). + - Enabled localization for all strings ([issue #88](https://github.com/PowerShell/xFailOverCluster/issues/88)). - Changes to xClusterQuorum - Refactored the unit test for this resource to use stubs and increase coverage ([issue #77](https://github.com/PowerShell/xFailOverCluster/issues/77)). diff --git a/DSCResources/MSFT_xWaitForCluster/MSFT_xWaitForCluster.psm1 b/DSCResources/MSFT_xWaitForCluster/MSFT_xWaitForCluster.psm1 index 34d3b0a..eb23baf 100644 --- a/DSCResources/MSFT_xWaitForCluster/MSFT_xWaitForCluster.psm1 +++ b/DSCResources/MSFT_xWaitForCluster/MSFT_xWaitForCluster.psm1 @@ -1,3 +1,8 @@ +Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) ` +-ChildPath 'CommonResourceHelper.psm1') + +$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_xWaitForCluster' + <# .SYNOPSIS Get the values for which failover cluster and for how long to wait for the @@ -31,6 +36,8 @@ function Get-TargetResource $RetryCount = 50 ) + Write-Verbose -Message $script:localizedData.ReturnParameterValues + @{ Name = $Name RetryIntervalSec = $RetryIntervalSec @@ -71,7 +78,7 @@ function Set-TargetResource ) $clusterFound = $false - Write-Verbose -Message "Checking for the existance of failover cluster $Name." + Write-Verbose -Message ($script:localizedData.CheckClusterPresent -f $Name) for ($count = 0; $count -lt $RetryCount; $count++) { @@ -80,7 +87,7 @@ function Set-TargetResource $computerObject = Get-CimInstance -ClassName Win32_ComputerSystem if ($null -eq $computerObject -or $null -eq $computerObject.Domain) { - Write-Verbose -Message "Can't find machine's domain name" + Write-Verbose -Message $script:localizedData.TargetNodeDomainMissing break } @@ -88,23 +95,24 @@ function Set-TargetResource if ($null -ne $cluster) { - Write-Verbose -Message "Found failover cluster $Name" + Write-Verbose -Message ($script:localizedData.ClusterPresent -f $Name) $clusterFound = $true break } } catch { - Write-Verbose -Message "Failover cluster $Name not found. Will retry again after $RetryIntervalSec sec" + Write-Verbose -Message ($script:localizedData.ClusterAbsent -f $Name, $RetryIntervalSec) } - Write-Verbose -Message "Failover cluster $Name not found. Will retry again after $RetryIntervalSec sec" + Write-Verbose -Message ($script:localizedData.ClusterAbsent -f $Name, $RetryIntervalSec) Start-Sleep -Seconds $RetryIntervalSec } - if (! $clusterFound) + if (-not $clusterFound) { - throw "Failover cluster $Name not found after $count attempts with $RetryIntervalSec sec interval" + $errorMessage = $script:localizedData.ClusterAbsentAfterTimeOut -f $Name, $count, $RetryIntervalSec + New-InvalidOperationException -Message $errorMessage } } @@ -140,7 +148,7 @@ function Test-TargetResource $RetryCount = 50 ) - Write-Verbose -Message "Checking for Cluster $Name ..." + Write-Verbose -Message ($script:localizedData.EvaluatingClusterPresent -f $Name) $testTargetResourceReturnValue = $false @@ -149,25 +157,25 @@ function Test-TargetResource $computerObject = Get-CimInstance -ClassName Win32_ComputerSystem if ($null -eq $computerObject -or $null -eq $computerObject.Domain) { - Write-Verbose -Message "Can't find machine's domain name" + Write-Verbose -Message $script:localizedData.TargetNodeDomainMissing } else { $cluster = Get-Cluster -Name $Name -Domain $computerObject.Domain if ($null -eq $cluster) { - Write-Verbose -Message "Cluster $Name not found in domain $computerObject.Domain" + Write-Verbose -Message ($script:localizedData.ClusterAbsentWithDomain -f $Name, $computerObject.Domain) } else { - Write-Verbose -Message "Found cluster $Name" + Write-Verbose -Message ($script:localizedData.ClusterPresent -f $Name) $testTargetResourceReturnValue = $true } } } catch { - Write-Verbose -Message "Cluster $Name not found" + Write-Verbose -Message ($script:localizedData.ClusterAbsentWithError -f $Name, $_.Message) } $testTargetResourceReturnValue diff --git a/DSCResources/MSFT_xWaitForCluster/en-US/MSFT_xWaitForCluster.strings.psd1 b/DSCResources/MSFT_xWaitForCluster/en-US/MSFT_xWaitForCluster.strings.psd1 new file mode 100644 index 0000000..60e652f --- /dev/null +++ b/DSCResources/MSFT_xWaitForCluster/en-US/MSFT_xWaitForCluster.strings.psd1 @@ -0,0 +1,13 @@ +# Localized resources for xWaitForCluster + +ConvertFrom-StringData @' + ReturnParameterValues = Returning the values passed as parameters. + CheckClusterPresent = Checking if cluster {0} is present. + TargetNodeDomainMissing = Can't find the target node's domain name. + ClusterPresent = Cluster {0} is present. + ClusterAbsent = Cluster {0} is NOT present. Will retry again after {1} seconds. + ClusterAbsentWithDomain = Cluster {0} is NOT present in Active Directory domain '{1}'. + ClusterAbsentWithError = Cluster {0} is NOT present with error: {1} + ClusterAbsentAfterTimeOut = Failover cluster {0} was not found after {1} attempts with {2} seconds interval. + EvaluatingClusterPresent = Evaluating if cluster {0} is present. +'@ diff --git a/Tests/Unit/MSFT_xWaitForCluster.Tests.ps1 b/Tests/Unit/MSFT_xWaitForCluster.Tests.ps1 index 6e55407..3497d85 100644 --- a/Tests/Unit/MSFT_xWaitForCluster.Tests.ps1 +++ b/Tests/Unit/MSFT_xWaitForCluster.Tests.ps1 @@ -93,7 +93,8 @@ try It 'Should throw the correct error message' { Mock -CommandName Get-CimInstance -MockWith $mockGetCimInstance -ParameterFilter $mockCimInstance_ParameterFilter -Verifiable - { Set-TargetResource @mockDefaultParameters } | Should Throw ('Failover cluster {0} not found after {1} attempts with {2} sec interval' -f $mockClusterName, ($mockRetryCount-1), $mockRetryIntervalSec) + $mockCorrectErrorRecord = Get-InvalidOperationRecord -Message ($script:localizedData.ClusterAbsentAfterTimeOut -f $mockClusterName, ($mockRetryCount-1), $mockRetryIntervalSec) + { Set-TargetResource @mockDefaultParameters } | Should Throw $mockCorrectErrorRecord } } @@ -114,7 +115,8 @@ try $mockDynamicDomainName = $mockDomainName It 'Should throw the correct error message' { - { Set-TargetResource @mockDefaultParameters } | Should Throw ('Failover cluster {0} not found after {1} attempts with {2} sec interval' -f $mockClusterName, $mockRetryCount, $mockRetryIntervalSec) + $mockCorrectErrorRecord = Get-InvalidOperationRecord -Message ($script:localizedData.ClusterAbsentAfterTimeOut -f $mockClusterName, $mockRetryCount, $mockRetryIntervalSec) + { Set-TargetResource @mockDefaultParameters } | Should Throw $mockCorrectErrorRecord } Assert-VerifiableMocks