Skip to content

Commit 5fc846c

Browse files
Merge branch 'development' into b4
2 parents 2d8168e + e68c4a8 commit 5fc846c

File tree

4 files changed

+58
-196
lines changed

4 files changed

+58
-196
lines changed

.aitools/module/Repair-PullRequestTest.ps1

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ function Repair-PullRequestTest {
2626
from the development branch to the current branch, without running Update-PesterTest
2727
or committing any changes.
2828
29+
.PARAMETER Pattern
30+
Pattern to filter test files. Only files matching this pattern will be processed.
31+
Supports wildcards (e.g., "*Login*" to match files containing "Login").
32+
2933
.NOTES
3034
Tags: Testing, Pester, PullRequest, CI
3135
Author: dbatools team
@@ -53,7 +57,8 @@ function Repair-PullRequestTest {
5357
[switch]$AutoCommit,
5458
[int]$MaxPRs = 5,
5559
[int]$BuildNumber,
56-
[switch]$CopyOnly
60+
[switch]$CopyOnly,
61+
[string]$Pattern
5762
)
5863

5964
begin {
@@ -269,7 +274,14 @@ function Repair-PullRequestTest {
269274
$fileErrorPath = @()
270275
$testdirectory = Join-Path $script:ModulePath "tests"
271276

272-
foreach ($test in $allFailedTestsAcrossPRs) {
277+
# Apply Pattern filter first if specified
278+
$filteredTests = if ($Pattern) {
279+
$allFailedTestsAcrossPRs | Where-Object { [System.IO.Path]::GetFileName($_.TestFile) -match $Pattern }
280+
} else {
281+
$allFailedTestsAcrossPRs
282+
}
283+
284+
foreach ($test in $filteredTests) {
273285
$fileName = [System.IO.Path]::GetFileName($test.TestFile)
274286
# ONLY include files that are actually in the PR changes
275287
if ($allRelevantTestFiles.Count -eq 0 -or $fileName -in $allRelevantTestFiles) {
@@ -284,7 +296,11 @@ function Repair-PullRequestTest {
284296
}
285297
}
286298
$fileErrorPath = $fileErrorPath | Sort-Object -Unique
287-
Write-Verbose "Found failures in $($fileErrorMap.Keys.Count) unique test files (filtered to PR changes only)"
299+
$filterMessage = "filtered to PR changes only"
300+
if ($Pattern) {
301+
$filterMessage += " and pattern '$Pattern'"
302+
}
303+
Write-Verbose "Found failures in $($fileErrorMap.Keys.Count) unique test files ($filterMessage)"
288304
foreach ($fileName in $fileErrorMap.Keys) {
289305
Write-Verbose " ${fileName} - $($fileErrorMap[$fileName].Count) failures"
290306
Write-Verbose " Paths: $fileErrorPath"

tests/appveyor.SQL2008R2SP2.ps1

Lines changed: 10 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,5 @@
1-
2-
3-
4-
Function Install-ADAuthenticationLibraryforSQLServer {
5-
# from https://bzzzt.io/post/2018-05-25-horrible-adalsql-issue/
6-
$workingFolder = Join-Path $Env:TEMP ([System.IO.Path]::GetRandomFileName())
7-
New-Item -ItemType Directory -Force -Path $workingFolder
8-
9-
$Installer = 'C:\github\appveyor-lab\azure\adalsql.msi'
10-
11-
If (!(Test-Path $Installer)) {
12-
Throw "$Installer does not exist"
13-
}
14-
try {
15-
#Write-Host "attempting to uninstall..."
16-
#Write-Host "Running MsiExec.exe /uninstall {4EE99065-01C6-49DD-9EC6-E08AA5B13491} /quiet"
17-
Start-Process -FilePath "MsiExec.exe" -ArgumentList "/uninstall {4EE99065-01C6-49DD-9EC6-E08AA5B13491} /quiet" -Wait -NoNewWindow
18-
} catch {
19-
#Write-Host "oh dear install did not work"
20-
$fail = $_.Exception
21-
Write-Error $fail
22-
Throw
23-
}
24-
try {
25-
$DataStamp = get-date -Format yyyyMMddTHHmmss
26-
$logFile = '{0}-{1}.log' -f $Installer, $DataStamp
27-
$MSIArguments = @(
28-
"/i"
29-
('"{0}"' -f $Installer)
30-
"/qn"
31-
"/norestart"
32-
"/L*v"
33-
$logFile
34-
)
35-
#Write-Host "Attempting to install.."
36-
#Write-Host " Running msiexec.exe $($MSIArguments)"
37-
Start-Process "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow
38-
} catch {
39-
$fail = $_.Exception
40-
Write-Error $fail
41-
Throw
42-
}
43-
}
44-
45-
$null = Install-ADAuthenticationLibraryforSQLServer
46-
471
$indent = '...'
482
Write-Host -Object "$indent Running $PSCommandpath" -ForegroundColor DarkGreen
49-
Import-Module C:\github\dbatools\dbatools.psm1 -Force
50-
$null = Set-DbatoolsInsecureConnection
513

524
# This script spins up the 2008R2SP2 instance and the relative setup
535

@@ -56,46 +8,20 @@ $instance = "SQL2008R2SP2"
568
$port = "1433"
579

5810
Write-Host -Object "$indent Setting up AppVeyor Services" -ForegroundColor DarkGreen
59-
Set-Service -Name SQLBrowser -StartupType Automatic -WarningAction SilentlyContinue
60-
Start-Service SQLBrowser -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
11+
Set-Service -Name SQLBrowser -StartupType Automatic
12+
Start-Service -Name SQLBrowser
6113

6214

6315
Write-Host -Object "$indent Changing the port on $instance to $port" -ForegroundColor DarkGreen
64-
$wmi = New-Object Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer
65-
$uri = "ManagedComputer[@Name='$env:COMPUTERNAME']/ServerInstance[@Name='$instance']/ServerProtocol[@Name='Tcp']"
66-
$Tcp = $wmi.GetSmoObject($uri)
67-
foreach ($ipAddress in $Tcp.IPAddresses) {
68-
$ipAddress.IPAddressProperties["TcpDynamicPorts"].Value = ""
69-
$ipAddress.IPAddressProperties["TcpPort"].Value = $port
70-
}
71-
$Tcp.Alter()
72-
73-
$uri = "ManagedComputer[@Name='$env:COMPUTERNAME']/ServerInstance[@Name='$instance']/ServerProtocol[@Name='Np']"
74-
$Np = $wmi.GetSmoObject($uri)
75-
$Np.IsEnabled = $true
76-
$Np.Alter()
16+
$null = Set-DbaNetworkConfiguration -SqlInstance $sqlinstance -StaticPortForIPAll $port -EnableException -Confirm:$false -WarningAction SilentlyContinue
7717

78-
Write-Host -Object "$indent Starting $instance" -ForegroundColor DarkGreen
79-
Restart-Service "MSSQL`$$instance" -WarningAction SilentlyContinue -Force
80-
$server = Connect-DbaInstance -SqlInstance $sqlinstance
81-
$server.Configuration.RemoteDacConnectionsEnabled.ConfigValue = $true
82-
$server.Configuration.Alter()
83-
$null = Set-DbaStartupParameter -SqlInstance $sqlinstance -TraceFlagOverride -TraceFlag 7806 -Confirm:$false -ErrorAction SilentlyContinue -EnableException
84-
Restart-Service "MSSQL`$SQL2008R2SP2" -WarningAction SilentlyContinue -Force
85-
$server = Connect-DbaInstance -SqlInstance $sqlinstance
86-
$server.Configuration.RemoteDacConnectionsEnabled.ConfigValue = $true
87-
$server.Configuration.Alter()
18+
Restart-Service -Name "MSSQL`$SQL2008R2SP2" -Force
8819

89-
do {
90-
Start-Sleep 1
91-
$null = (& sqlcmd -S "$sqlinstance" -b -Q "select 1" -d master)
92-
}
93-
while ($lastexitcode -ne 0 -and $t++ -lt 10)
9420

95-
Write-Host -Object "$indent Executing startup scripts for SQL Server 2008" -ForegroundColor DarkGreen
96-
# Add some jobs to the sql2008r2sp2 instance (1433 = default)
97-
foreach ($file in (Get-ChildItem C:\github\appveyor-lab\sql2008-startup\*.sql -Recurse -ErrorAction SilentlyContinue)) {
98-
Invoke-DbaQuery -SqlInstance $sqlinstance -InputFile $file
99-
}
21+
Write-Host -Object "$indent Configuring $sqlinstance" -ForegroundColor DarkGreen
10022

101-
Import-Module C:\github\dbatools\dbatools.psm1 -Force
23+
$null = Set-DbaNetworkConfiguration -SqlInstance $sqlinstance -EnableProtocol NamedPipes -RestartService -EnableException -Confirm:$false
24+
$null = Set-DbaSpConfigure -SqlInstance $sqlinstance -Name RemoteDacConnectionsEnabled -Value $true -EnableException
25+
# To conserve resources, SQL Server Express doesn't listen on the DAC port unless started with a trace flag 7806.
26+
$null = Set-DbaStartupParameter -SqlInstance $sqlinstance -TraceFlagOverride -TraceFlag 7806 -EnableException -Confirm:$false
27+
Restart-Service -Name "MSSQL`$SQL2008R2SP2" -Force

tests/appveyor.SQL2016.ps1

Lines changed: 13 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,27 @@
11
$indent = '...'
22
Write-Host -Object "Running $PSCommandpath" -ForegroundColor DarkGreen
3-
$dbatools_serialimport = $true
4-
Import-Module C:\github\dbatools\dbatools.psd1
5-
Start-Sleep 5
6-
$null = Set-DbatoolsInsecureConnection
3+
74
# This script spins up the 2016 instance and the relative setup
85

96
$sqlinstance = "localhost\SQL2016"
107
$instance = "SQL2016"
118
$port = "14333"
129

1310
Write-Host -Object "$indent Setting up AppVeyor Services" -ForegroundColor DarkGreen
14-
Set-Service -Name SQLBrowser -StartupType Automatic -WarningAction SilentlyContinue
15-
Set-Service -Name "SQLAgent`$$instance" -StartupType Automatic -WarningAction SilentlyContinue
16-
Start-Service SQLBrowser -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
17-
11+
Set-Service -Name SQLBrowser -StartupType Automatic
12+
Set-Service -Name "SQLAgent`$$instance" -StartupType Automatic
13+
Start-Service -Name SQLBrowser -ErrorAction SilentlyContinue
1814

1915
Write-Host -Object "$indent Changing the port on $instance to $port" -ForegroundColor DarkGreen
20-
$wmi = New-Object Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer
21-
$uri = "ManagedComputer[@Name='$env:COMPUTERNAME']/ ServerInstance[@Name='$instance']/ServerProtocol[@Name='Tcp']"
22-
$Tcp = $wmi.GetSmoObject($uri)
23-
foreach ($ipAddress in $Tcp.IPAddresses) {
24-
$ipAddress.IPAddressProperties["TcpDynamicPorts"].Value = ""
25-
$ipAddress.IPAddressProperties["TcpPort"].Value = $port
26-
}
27-
$Tcp.Alter()
28-
Write-Host -Object "$indent Starting $instance" -ForegroundColor DarkGreen
29-
Restart-Service "MSSQL`$$instance" -WarningAction SilentlyContinue -Force
30-
Restart-Service "SQLAgent`$$instance" -WarningAction SilentlyContinue -Force
16+
$null = Set-DbaNetworkConfiguration -SqlInstance $sqlinstance -StaticPortForIPAll $port -EnableException -Confirm:$false -WarningAction SilentlyContinue
3117

32-
do {
33-
Start-Sleep 1
34-
$null = (& sqlcmd -S "$sqlinstance" -b -Q "select 1" -d master)
35-
}
36-
while ($lastexitcode -ne 0 -and $t++ -lt 10)
37-
38-
# Agent sometimes takes a moment to start
39-
do {
40-
Write-Host -Object "$indent Waiting for SQL Agent to start" -ForegroundColor DarkGreen
41-
Start-Sleep 1
42-
}
43-
while ((Get-Service "SQLAgent`$$instance").Status -ne 'Running' -and $z++ -lt 10)
44-
45-
# Whatever, just sleep an extra 5
46-
Start-Sleep 5
18+
Write-Host -Object "$indent Starting $instance" -ForegroundColor DarkGreen
19+
Restart-Service "MSSQL`$$instance" -Force
20+
Restart-Service "SQLAgent`$$instance" -Force
4721

48-
# this needs to be moved out. Tests that require these things need to run this in a BeforeAll stanza and remove the cruft in an AfterAll one
49-
# so everybody can run tests without needing this too (which should be used strictly as appveyor-setup-related activities)
50-
# when this fails for resource contention, the whole build stops for no reason. At most, it should fail only tests that are in the need of the reqs
51-
Write-Host -Object "$indent Executing startup scripts for SQL Server 2016" -ForegroundColor DarkGreen
52-
$sql2016Startup = 0
53-
foreach ($file in (Get-ChildItem C:\github\appveyor-lab\sql2016-startup\*.sql -Recurse -ErrorAction SilentlyContinue)) {
54-
try {
55-
Invoke-DbaQuery -SqlInstance $sqlinstance -InputFile $file -ErrorAction Stop
56-
} catch {
57-
$sql2016Startup = 1
58-
}
59-
}
60-
try {
22+
# Sometimes enabling ExtensibleKeyManagement failes, so try this:
23+
Start-Sleep -Seconds 5
6124

62-
$null = Set-DbaSpConfigure -SqlInstance $sqlinstance -Name ExtensibleKeyManagementEnabled -Value $true
63-
$sql = "CREATE CRYPTOGRAPHIC PROVIDER dbatoolsci_AKV FROM FILE = 'C:\github\appveyor-lab\keytests\ekm\Microsoft.AzureKeyVaultService.EKM.dll'"
64-
Invoke-DbaQuery -SqlInstance $sqlinstance -Query $sql
65-
} catch {
66-
$sql2016Startup = 1
67-
}
68-
if ($sql2016Startup -eq 1) {
69-
Write-Host -Object "$indent something went wrong with startup scripts" -ForegroundColor DarkGreen
70-
}
25+
Write-Host -Object "$indent Configuring $instance" -ForegroundColor DarkGreen
26+
$null = Set-DbaSpConfigure -SqlInstance $sqlinstance -Name ExtensibleKeyManagementEnabled -Value $true -EnableException
27+
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE CRYPTOGRAPHIC PROVIDER dbatoolsci_AKV FROM FILE = 'C:\github\appveyor-lab\keytests\ekm\Microsoft.AzureKeyVaultService.EKM.dll'" -EnableException

tests/appveyor.SQL2017.ps1

Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,27 @@
11
$indent = '...'
2-
Write-Host -Object "Running $PSCommandpath" -ForegroundColor DarkGreen
3-
$dbatools_serialimport = $true
4-
Import-Module C:\github\dbatools\dbatools.psd1
5-
Start-Sleep 5
6-
$null = Set-DbatoolsInsecureConnection
2+
Write-Host -Object "$indent Running $PSCommandpath" -ForegroundColor DarkGreen
3+
74
# This script spins up the 2016 instance and the relative setup
85

96
$sqlinstance = "localhost\SQL2017"
107
$instance = "SQL2017"
118
$port = "14334"
129

1310
Write-Host -Object "$indent Setting up AppVeyor Services" -ForegroundColor DarkGreen
14-
Set-Service -Name SQLBrowser -StartupType Automatic -WarningAction SilentlyContinue
15-
Set-Service -Name "SQLAgent`$$instance" -StartupType Automatic -WarningAction SilentlyContinue
16-
Start-Service SQLBrowser -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
11+
Set-Service -Name SQLBrowser -StartupType Automatic
12+
Set-Service -Name "SQLAgent`$$instance" -StartupType Automatic
13+
Start-Service -Name SQLBrowser -ErrorAction SilentlyContinue
1714

1815
Write-Host -Object "$indent Changing the port on $instance to $port" -ForegroundColor DarkGreen
19-
$wmi = New-Object Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer
20-
$uri = "ManagedComputer[@Name='$env:COMPUTERNAME']/ ServerInstance[@Name='$instance']/ServerProtocol[@Name='Tcp']"
21-
$Tcp = $wmi.GetSmoObject($uri)
22-
foreach ($ipAddress in $Tcp.IPAddresses) {
23-
$ipAddress.IPAddressProperties["TcpDynamicPorts"].Value = ""
24-
$ipAddress.IPAddressProperties["TcpPort"].Value = $port
25-
}
26-
$Tcp.Alter()
27-
Write-Host -Object "$indent Starting $instance" -ForegroundColor DarkGreen
28-
#Restart-Service "MSSQL`$$instance" -WarningAction SilentlyContinue -Force
29-
#Restart-Service "SQLAgent`$$instance" -WarningAction SilentlyContinue -Force
30-
31-
$null = Enable-DbaAgHadr -SqlInstance $sqlinstance -Confirm:$false -Force
32-
33-
do {
34-
Start-Sleep 1
35-
$null = (& sqlcmd -S "$sqlinstance" -b -Q "select 1" -d master)
36-
}
37-
while ($lastexitcode -ne 0 -and $t++ -lt 10)
38-
39-
# Agent sometimes takes a moment to start
40-
do {
41-
Write-Host -Object "$indent Waiting for SQL Agent to start" -ForegroundColor DarkGreen
42-
Start-Sleep 1
43-
}
44-
while ((Get-Service "SQLAgent`$$instance").Status -ne 'Running' -and $z++ -lt 10)
16+
$null = Set-DbaNetworkConfiguration -SqlInstance $sqlinstance -StaticPortForIPAll $port -EnableException -Confirm:$false -WarningAction SilentlyContinue
4517

46-
47-
$server = Connect-DbaInstance -SqlInstance $sqlinstance
48-
$computername = $server.NetName
49-
$servicename = $server.ServiceName
50-
if ($servicename -eq 'MSSQLSERVER') {
51-
$instancename = "$computername"
52-
} else {
53-
$instancename = "$computername\$servicename"
54-
}
55-
56-
$server = Connect-DbaInstance -SqlInstance $sqlinstance
57-
$server.Query("IF NOT EXISTS (select * from sys.symmetric_keys where name like '%DatabaseMasterKey%') CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<StrongPassword>'")
58-
$server.Query("IF EXISTS ( SELECT * FROM sys.tcp_endpoints WHERE name = 'End_Mirroring') DROP ENDPOINT endpoint_mirroring")
59-
$server.Query("CREATE CERTIFICATE dbatoolsci_AGCert WITH SUBJECT = 'AG Certificate'")
60-
61-
62-
$null = Set-DbaSpConfigure -SqlInstance $sqlinstance -Name ExtensibleKeyManagementEnabled -Value $true
63-
$sql = "CREATE CRYPTOGRAPHIC PROVIDER dbatoolsci_AKV FROM FILE = 'C:\github\appveyor-lab\keytests\ekm\Microsoft.AzureKeyVaultService.EKM.dll'"
64-
Invoke-DbaQuery -SqlInstance $sqlinstance -Query $sql
18+
Write-Host -Object "$indent Starting $instance" -ForegroundColor DarkGreen
19+
Restart-Service "MSSQL`$$instance" -Force
20+
Restart-Service "SQLAgent`$$instance" -Force
21+
22+
Write-Host -Object "$indent Configuring $instance" -ForegroundColor DarkGreen
23+
$null = Set-DbaSpConfigure -SqlInstance $sqlinstance -Name ExtensibleKeyManagementEnabled -Value $true -EnableException
24+
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE CRYPTOGRAPHIC PROVIDER dbatoolsci_AKV FROM FILE = 'C:\github\appveyor-lab\keytests\ekm\Microsoft.AzureKeyVaultService.EKM.dll'" -EnableException
25+
$null = Enable-DbaAgHadr -SqlInstance $sqlinstance -Force -EnableException -Confirm:$false
26+
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<StrongPassword>'" -EnableException
27+
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE CERTIFICATE dbatoolsci_AGCert WITH SUBJECT = 'AG Certificate'" -EnableException

0 commit comments

Comments
 (0)