Skip to content

Commit fe35edd

Browse files
authored
Fixing Get-TargetResource is reporting error when cluster is not found (#284)
- Cluster - Fixed Get-TargetResource is reporting error when cluster is not found (issue #283).
1 parent 5425f0d commit fe35edd

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md)
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Cluster
13+
- Fixed Get-TargetResource is reporting error when cluster is not found ([issue #283](https://github.com/dsccommunity/FailOverClusterDsc/issues/283)).
14+
1015
### Changed
1116

1217
- FailoverClusterDsc

source/DSCResources/DSC_Cluster/DSC_Cluster.psm1

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ function Get-TargetResource
7575
$cluster = Get-Cluster -Name $Name -Domain $computerInformation.Domain
7676
if ($null -eq $cluster)
7777
{
78-
$errorMessage = $script:localizedData.ClusterNameNotFound -f $Name
79-
New-ObjectNotFoundException -Message $errorMessage
78+
Write-Verbose -Message ($script:localizedData.ClusterNameNotFound -f $Name)
79+
# Future improvement: Manage Ensure state.
80+
}
81+
else
82+
{
83+
# This will return the IP address regardless if using Static IP or DHCP.
84+
$address = Get-ClusterResource -Cluster $Name -Name 'Cluster IP Address' | Get-ClusterParameter -Name 'Address'
8085
}
81-
82-
# This will return the IP address regardless if using Static IP or DHCP.
83-
$address = Get-ClusterResource -Cluster $Name -Name 'Cluster IP Address' | Get-ClusterParameter -Name 'Address'
8486
}
8587
finally
8688
{

tests/Unit/DSC_Cluster.Tests.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,16 @@ foreach ($moduleVersion in @('2012', '2016'))
182182
}
183183

184184
Context 'When the cluster cannot be found' {
185-
It 'Should throw the correct error message' {
185+
It 'Should returns the cluster name' {
186186
$mockDynamicDomainName = $mockDomainName
187187
$mockDynamicServerName = $mockServerName
188188

189189
Mock -CommandName Get-Cluster -Verifiable
190190
Mock -CommandName Get-CimInstance -MockWith $mockGetCimInstance -ParameterFilter $mockGetCimInstance_ParameterFilter -Verifiable
191191

192-
$mockCorrectErrorRecord = Get-ObjectNotFoundException -Message ($script:localizedData.ClusterNameNotFound -f $mockClusterName)
193-
{ Get-TargetResource @mockGetTargetResourceParameters } | Should -Throw $mockCorrectErrorRecord
192+
$getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters
193+
194+
$getTargetResourceResult.Name | Should -Be $mockDefaultParameters.Name
194195
}
195196
}
196197

0 commit comments

Comments
 (0)