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

SqlAgDatabase: Typo in resource for fix for #1492 #1666

Merged
merged 43 commits into from
Jan 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
69ebf57
Initial version of new resource SqlTraceFlag
Fiander Nov 26, 2020
e1cc2da
small change to trigger pipline
Fiander Nov 26, 2020
f7cab74
Change Schema friendliname
Fiander Nov 26, 2020
105dd1b
schema change
Fiander Nov 26, 2020
c5346a2
some HQRM fixes
Fiander Nov 26, 2020
a676c66
initial test
Fiander Nov 27, 2020
708fce6
second push
Fiander Nov 27, 2020
8125732
first batch of fixes
Fiander Nov 27, 2020
a404e96
save keepings
Fiander Nov 27, 2020
5ff9a87
Removed to much
Fiander Nov 27, 2020
7e92280
Style guideline fixes and move change log entries
johlju Nov 27, 2020
a7fbcf3
Fix examples
johlju Nov 27, 2020
e8f27db
Merge pull request #1 from johlju/traceflag-styleguideline
Fiander Nov 27, 2020
06d505d
Removed "Envorce" also in all tests
Fiander Nov 28, 2020
8cd6970
Remove Ensure from examples
Fiander Nov 28, 2020
ba872f2
first batch of fixes.
Fiander Nov 29, 2020
ca65655
removed readonly parameters, changed to Restart-SqlService, adjusted …
Fiander Dec 3, 2020
08bcd6d
some more tests added
Fiander Dec 4, 2020
36eb33c
last fixes ( i hope )
Fiander Dec 4, 2020
2b55bba
added readme and changelog for fix #1492
Fiander Dec 4, 2020
c300577
removed one newline
Fiander Dec 5, 2020
68c488f
BackupPath is still required
Fiander Dec 5, 2020
8b603c3
last fixes
Fiander Dec 5, 2020
ba5ff81
Last changes. ( i hope ;-) )
Fiander Dec 5, 2020
bd76c22
mised a RestartService
Fiander Dec 5, 2020
281d19b
Adden to SqlServerDsc and SqlTraceFlag get missed a return value
Fiander Dec 5, 2020
9808962
removed try catch from code logic
Fiander Dec 5, 2020
45d9418
Merge pull request #2 from dsccommunity/master
Fiander Dec 7, 2020
23546de
Updating ChangeLog since v15.0.0 +semver:skip (#1643)
dscbot Dec 7, 2020
be7157e
Merge pull request #3 from dsccommunity/master
Fiander Dec 11, 2020
72edbe8
merge
Fiander Dec 11, 2020
fb32d24
Merge pull request #4 from dsccommunity/master
Fiander Dec 12, 2020
8bc7b2e
Merge remote-tracking branch 'origin/master'
Fiander Dec 12, 2020
2880bd0
rebase AGDatabase
Fiander Dec 12, 2020
3accf96
minor changes for readability
Fiander Dec 12, 2020
e61138d
small changelog fixes
Fiander Dec 13, 2020
eaeaade
Merge branch 'master' into SqlAgDatabase
johlju Dec 13, 2020
136e2b1
merge root
Fiander Jan 8, 2021
6f24cfd
small typo in resource
Fiander Jan 8, 2021
885ff2b
added changelog
Fiander Jan 8, 2021
8dd4a64
fixed the test for only backup with automatic seeding
Fiander Jan 8, 2021
d4b4dac
typo
Fiander Jan 9, 2021
a367dca
Merge branch 'main' into SqlAgDatabase
johlju Jan 9, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
at all replicas of an availability group. When automatic seeding is found, it will use that.
- Lots of extra tests to check AutomaticSeeding.
- The parameter `BackupPath` is still needed just in case a database never has been backuped before.
- Fixed a typo.
- SqlMaxDop
- Fixes ([issue #396](https://github.com/dsccommunity/SqlServerDsc/issues/396)).
Added three return values in Get-Target resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ function Set-TargetResource
#>
if ( $primaryServerObject.Databases[$databaseToAddToAvailabilityGroup].CreateDate -gt $primaryServerObject.Databases[$databaseToAddToAvailabilityGroup].LastBackupDate)
{
$needsBackup = $true
$backupNeeded = $true
}
}

Expand Down
24 changes: 15 additions & 9 deletions tests/Unit/DSC_SqlAGDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,6 @@ REVERT'
$mockDatabaseEncryptionKeyObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.DatabaseEncryptionKey
$mockDatabaseEncryptionKeyObject.EncryptorName = 'TDE Cert'
$mockDatabaseEncryptionKeyObject.Thumbprint = $mockThumbprint1

#endregion Certificate Mocks

#region Database File Mocks
Expand Down Expand Up @@ -1834,7 +1833,6 @@ REVERT'

#endregion Invoke Query Mock


Mock -CommandName Get-PrimaryReplicaServerObject -MockWith { return $mockServerObject } -Verifiable -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' }
Mock -CommandName Get-PrimaryReplicaServerObject -MockWith { return $mockServer2Object } -Verifiable -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' }
Mock -CommandName Import-SQLPSModule -Verifiable
Expand Down Expand Up @@ -1873,7 +1871,7 @@ REVERT'
}

Context 'When Ensure is Present' {
It 'Should add the specified databases to the availability group' {
It 'Should add the specified databases to the availability group.' {
{ Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw

Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' }
Expand Down Expand Up @@ -2280,16 +2278,17 @@ REVERT'
}

It 'Should add the specified databases to the availability group when the database has not been previously backed up' {
$mockServerObject.Databases['DB1'].LastBackupDate = 0
$mockServerObject.Databases['DB1'].CreateDate = '2020-10-20 10:00:00'
$mockServerObject.Databases['DB1'].LastBackupDate = '2020-10-10 10:00:00'

{ Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw

Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' }
Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' }
Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 0 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server2' -and $InputObject.LocalReplicaRole -eq 'Primary' }
Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 0 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server2' -and $InputObject.LocalReplicaRole -eq 'Secondary' }
Assert-MockCalled -CommandName Backup-SqlDatabase -Scope It -Times 0 -Exactly -ParameterFilter { $BackupAction -eq 'Database' }
Assert-MockCalled -CommandName Backup-SqlDatabase -Scope It -Times 0 -Exactly -ParameterFilter { $BackupAction -eq 'Log' }
Assert-MockCalled -CommandName Backup-SqlDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $BackupAction -eq 'Database' }
Assert-MockCalled -CommandName Backup-SqlDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $BackupAction -eq 'Log' }
Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 1 -Exactly -ParameterFilter { $ServerName -eq 'Server1' -and $InstanceName -eq 'MSSQLSERVER' }
Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 1 -Exactly -ParameterFilter { $ServerName -eq 'Server1' }
Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 3 -Exactly -ParameterFilter { $ServerName -eq 'Server2' }
Expand All @@ -2299,11 +2298,15 @@ REVERT'
Assert-MockCalled -CommandName Invoke-Query -Scope It -Times 2 -Exactly -ParameterFilter { $Query -like 'EXEC master.dbo.xp_fileexist *' }
Assert-MockCalled -CommandName Invoke-Query -Scope It -Times 0 -Exactly -ParameterFilter $mockInvokeQueryParameterRestoreDatabase
Assert-MockCalled -CommandName Invoke-Query -Scope It -Times 0 -Exactly -ParameterFilter $mockInvokeQueryParameterRestoreDatabaseWithExecuteAs
Assert-MockCalled -CommandName Join-Path -Scope It -Times 0 -Exactly -ParameterFilter { $ChildPath -like '*_Full_*.bak' }
Assert-MockCalled -CommandName Join-Path -Scope It -Times 0 -Exactly -ParameterFilter { $ChildPath -like '*_Log_*.trn' }
Assert-MockCalled -CommandName Remove-Item -Scope It -Times 0 -Exactly
Assert-MockCalled -CommandName Join-Path -Scope It -Times 1 -Exactly -ParameterFilter { $ChildPath -like '*_Full_*.bak' }
Assert-MockCalled -CommandName Join-Path -Scope It -Times 1 -Exactly -ParameterFilter { $ChildPath -like '*_Log_*.trn' }
Assert-MockCalled -CommandName Remove-Item -Scope It -Times 1 -Exactly
Assert-MockCalled -CommandName Remove-SqlAvailabilityDatabase -Scope It -Times 0 -Exactly
Assert-MockCalled -CommandName Test-ImpersonatePermissions -Scope It -Times 1 -Exactly

#reset so others will not trip. Fix for pester 5
$mockServerObject.Databases['DB1'].CreateDate = '2020-10-10 10:00:00'
$mockServerObject.Databases['DB1'].LastBackupDate = '2020-10-20 10:00:00'
}

It 'Should throw the correct error when it fails to add the database to the primary replica' {
Expand Down Expand Up @@ -2730,6 +2733,8 @@ REVERT'
Mock -CommandName Test-ActiveNode -MockWith {
return -not $mockProcessOnlyOnActiveNode
} -Verifiable


}

BeforeEach {
Expand All @@ -2744,6 +2749,7 @@ REVERT'
MatchDatabaseOwner = $false
ProcessOnlyOnActiveNode = $false
}

}

Context 'When Ensure is Present' {
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Stubs/SMO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ public class Database
public string AvailabilityGroupName = "";
public Certificate[] Certificates;
public string ContainmentType = "None";
public DateTime CreateDate;
public DatabaseEncryptionKey DatabaseEncryptionKey;
public string DefaultFileStreamFileGroup;
public bool EncryptionEnabled = false;
Expand Down