Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADDomain: Add Get-ADDomain Additional Retry Exceptions #577

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md)
- ADOrganizationalUnit
- Fixed issue where Get-DscConfiguration / Test-DscConfiguration throw an exception when parent path does not yet exist
([issue #553](https://github.com/dsccommunity/ActiveDirectoryDsc/issues/553))
- ADDomain
- Added additional Get-ADDomain retry exceptions
([issue #574](https://github.com/dsccommunity/ActiveDirectoryDsc/issues/574)).

### Changed

Expand Down
42 changes: 42 additions & 0 deletions Tests/Unit/MSFT_ADDomain.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,48 @@ try
}
}

Context 'When Get-ADDomain throws an AuthenticationException until timeout' {
BeforeAll {
Mock -CommandName Get-AdDomain `
-MockWith { throw New-Object -TypeName 'System.Security.Authentication.AuthenticationException' }
Mock -CommandName Start-Sleep
}

It 'Should throw the correct exception' {
{ Get-TargetResource @mockGetTargetResourceParameters } |
Should -Throw ($script:localizedData.MaxDomainRetriesReachedError -f $mockDomainFQDN)
}

It 'Should call the expected mocks' {
Assert-MockCalled -CommandName Get-ADDomain `
-ParameterFilter { $Identity -eq $mockDomainFQDN } `
-Exactly -Times $maxRetries
Assert-MockCalled -CommandName Start-Sleep `
-Exactly -Times $maxRetries
}
}

Context 'When Get-ADDomain throws an InvalidOperationException until timeout' {
BeforeAll {
Mock -CommandName Get-AdDomain `
-MockWith { throw New-Object -TypeName 'System.InvalidOperationException' }
Mock -CommandName Start-Sleep
}

It 'Should throw the correct exception' {
{ Get-TargetResource @mockGetTargetResourceParameters } |
Should -Throw ($script:localizedData.MaxDomainRetriesReachedError -f $mockDomainFQDN)
}

It 'Should call the expected mocks' {
Assert-MockCalled -CommandName Get-ADDomain `
-ParameterFilter { $Identity -eq $mockDomainFQDN } `
-Exactly -Times $maxRetries
Assert-MockCalled -CommandName Start-Sleep `
-Exactly -Times $maxRetries
}
}

Context 'When Get-ADForest throws an unexpected error' {
BeforeAll {
Mock -CommandName Get-AdForest `
Expand Down
6 changes: 4 additions & 2 deletions source/DSCResources/MSFT_ADDomain/MSFT_ADDomain.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ function Get-TargetResource
{
$domain = Get-ADDomain -Identity $domainFQDN -Server localhost -ErrorAction Stop
}
catch [Microsoft.ActiveDirectory.Management.ADServerDownException]
catch [Microsoft.ActiveDirectory.Management.ADServerDownException], `
[System.Security.Authentication.AuthenticationException], `
[System.InvalidOperationException]
{
Write-Verbose ($script:localizedData.ADServerDown -f $domainFQDN)
Write-Verbose ($script:localizedData.ADServerNotReady -f $domainFQDN)
$domainFound = $false
# will fall into the retry mechanism.
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# culture="en-US"
ConvertFrom-StringData @'
QueryDomain = Querying for domain '{0}'. (ADD0001)
ADServerDown = The AD Server for domain '{0}' is currently down. (ADD0002)
ADServerNotReady = The AD Server for domain '{0}' is currently not ready. (ADD0002)
DomainFound = Active Directory domain '{0}' found. (ADD0003)
CreatingChildDomain = Creating domain '{0}' as a child of domain '{1}'. (ADD0004)
CreatedChildDomain = Child domain '{0}' created. (ADD0005)
Expand Down