Skip to content
Draft
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
33 changes: 20 additions & 13 deletions .github/scripts/install-dbatools-library.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
Installation scope for PowerShell Gallery installation (CurrentUser or AllUsers).
Defaults to CurrentUser.

.PARAMETER Silent
Suppresses informational output, only errors and warnings will be shown.

.EXAMPLE
.\install-dbatools-library.ps1
Installs the version specified in the JSON config file
Expand All @@ -42,7 +45,8 @@ param(
[string]$ConfigPath = (Join-Path $PSScriptRoot "../dbatools-library-version.json"),
[switch]$Force,
[ValidateSet('CurrentUser', 'AllUsers')]
[string]$Scope = 'CurrentUser'
[string]$Scope = 'CurrentUser',
[switch]$Silent
)

function Write-Log {
Expand All @@ -54,6 +58,9 @@ function Write-Log {
'Success' { 'Green' }
default { 'White' }
}
if ($Silent -and $Level -in 'Success', 'Info') {
return
}
Write-Host "[$timestamp] [$Level] $Message" -ForegroundColor $color
}

Expand Down Expand Up @@ -347,49 +354,49 @@ try {
Write-Log "Verifying installation..."

# Diagnostic: Check PSModulePath before verification
Write-Log "Current PSModulePath before verification:" -Level 'Warning'
Write-Log "Current PSModulePath before verification:"
$env:PSModulePath -split [System.IO.Path]::PathSeparator | ForEach-Object {
Write-Log " $_" -Level 'Warning'
Write-Log " $_"
}

# Diagnostic: Force refresh module cache
Write-Log "Refreshing module cache..." -Level 'Warning'
Write-Log "Refreshing module cache..."
Get-Module -Refresh -ListAvailable | Out-Null

# Diagnostic: Check for any dbatools.library modules first
Write-Log "Searching for any dbatools.library modules..." -Level 'Warning'
Write-Log "Searching for any dbatools.library modules..."
$allDbaModules = Get-Module -ListAvailable | Where-Object { $_.Name -like "*dbatools*" }
if ($allDbaModules) {
Write-Log "Found dbatools-related modules:" -Level 'Warning'
Write-Log "Found dbatools-related modules:"
$allDbaModules | ForEach-Object {
Write-Log " $($_.Name) v$($_.Version) at $($_.ModuleBase)" -Level 'Warning'
Write-Log " $($_.Name) v$($_.Version) at $($_.ModuleBase)"
}
} else {
Write-Log "No dbatools-related modules found at all!" -Level 'Warning'
}

# Diagnostic: Try multiple module discovery approaches
Write-Log "Attempting multiple discovery methods..." -Level 'Warning'
Write-Log "Attempting multiple discovery methods..."

# Method 1: Standard Get-Module
$installedModules = Get-Module -ListAvailable -Name 'dbatools.library'
Write-Log "Method 1 (Get-Module -Name): Found $($installedModules.Count) modules" -Level 'Warning'
Write-Log "Method 1 (Get-Module -Name): Found $($installedModules.Count) modules"

# Method 2: Wildcard search
$wildcardModules = Get-Module -ListAvailable -Name '*dbatools.library*'
Write-Log "Method 2 (Wildcard search): Found $($wildcardModules.Count) modules" -Level 'Warning'
Write-Log "Method 2 (Wildcard search): Found $($wildcardModules.Count) modules"

# Method 3: Direct path check if we have the installation path
if ($finalInstallPath -and (Test-Path $finalInstallPath)) {
Write-Log "Method 3: Checking direct installation path: $finalInstallPath" -Level 'Warning'
Write-Log "Method 3: Checking direct installation path: $finalInstallPath"
$manifestPath = Join-Path $finalInstallPath "dbatools.library.psd1"
if (Test-Path $manifestPath) {
try {
$directModule = Test-ModuleManifest -Path $manifestPath -ErrorAction Stop
Write-Log "Method 3 (Direct path): Found module version $($directModule.Version)" -Level 'Warning'
Write-Log "Method 3 (Direct path): Found module version $($directModule.Version)"
# Try to import it directly to see if it works
$importedModule = Import-Module $manifestPath -PassThru -Force -ErrorAction Stop
Write-Log "Method 3 (Direct import): Successfully imported version $($importedModule.Version)" -Level 'Warning'
Write-Log "Method 3 (Direct import): Successfully imported version $($importedModule.Version)"
Remove-Module $importedModule -Force -ErrorAction SilentlyContinue
} catch {
Write-Log "Method 3 (Direct path): Failed - $($_.Exception.Message)" -Level 'Warning'
Expand Down
40 changes: 17 additions & 23 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# See http://www.appveyor.com/docs/appveyor-yml for many more options
image: Previous Visual Studio 2015
image: Previous Visual Studio 2022
configuration: "Debug"

# skip PR builds when there's already a push build
Expand Down Expand Up @@ -47,41 +47,35 @@ environment:
appveyor_rdp_password: 2odCuiKmYiem

matrix:
- scenario: 2008R2
main_instance: localhost\SQL2008R2SP2
setup_scripts: \tests\appveyor.SQL2008R2SP2.ps1
- scenario: 2016
main_instance: localhost\SQL2016
setup_scripts: \tests\appveyor.SQL2016.ps1
- scenario: 2016_2017
main_instance: localhost\SQL2017,localhost\SQL2016
setup_scripts: \tests\appveyor.SQL2017.ps1,\tests\appveyor.SQL2016.ps1
- scenario: SINGLE
main_instance: localhost\SQL2017
setup_scripts: \tests\appveyor.SQL2017.ps1
main_instance: localhost\SQL2019
setup_scripts: \tests\appveyor.SQL2019.ps1
- scenario: MULTI
main_instance: localhost\SQL2017,localhost\SQL2016
setup_scripts: \tests\appveyor.SQL2017.ps1,\tests\appveyor.SQL2016.ps1
main_instance: localhost\SQL2017,localhost\SQL2019
setup_scripts: \tests\appveyor.SQL2017.ps1,\tests\appveyor.SQL2019.ps1
- scenario: COPY
main_instance: localhost\SQL2017,localhost\SQL2016
setup_scripts: \tests\appveyor.SQL2017.ps1,\tests\appveyor.SQL2016.ps1
main_instance: localhost\SQL2017,localhost\SQL2019
setup_scripts: \tests\appveyor.SQL2017.ps1,\tests\appveyor.SQL2019.ps1
- scenario: HADR
main_instance: localhost\SQL2017
setup_scripts: \tests\appveyor.SQL2017.ps1
main_instance: localhost\SQL2019
setup_scripts: \tests\appveyor.SQL2019.ps1
- scenario: RESTART
main_instance: localhost\SQL2017
setup_scripts: \tests\appveyor.SQL2017.ps1
main_instance: localhost\SQL2019
setup_scripts: \tests\appveyor.SQL2019.ps1
- scenario: Legacy1
main_instance: localhost\SQL2019
setup_scripts: \tests\appveyor.SQL2019.ps1
- scenario: default
main_instance: localhost\SQL2008R2SP2,localhost\SQL2016
setup_scripts: \tests\appveyor.SQL2008R2SP2.ps1,\tests\appveyor.SQL2016.ps1
main_instance: localhost\SQL2017,localhost\SQL2019
setup_scripts: \tests\appveyor.SQL2017.ps1,\tests\appveyor.SQL2019.ps1

# Set alternative clone folder
clone_folder: c:\github\dbatools

before_test:
# turn tests directory (at least) to CRLF, as it's faster to do this on the zipball rather than checking out the repo
- cmd: pushd C:\github\dbatools\tests & unix2dos -q *.ps1 & popd
# don't clown -- for some reason it's just not installing the library
# don't clone -- for some reason it's just not installing the library
# dbatools.library is now installed via centralized method in appveyor.prep.ps1
# grab appveyor lab files and needed requirements for tests in CI
- ps: .\Tests\appveyor.prep.ps1
Expand Down
18 changes: 10 additions & 8 deletions private/testing/Get-TestConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ function Get-TestConfig {
# This configuration is used for the automated test on AppVeyor
$config['DbaToolsCi_Computer'] = "$(hostname)"

$config['Instance1'] = "$(hostname)\sql2008r2sp2"
$config['Instance2'] = "$(hostname)\sql2016"
$config['InstanceSingle'] = "$(hostname)\sql2017"
$config['InstanceMulti1'] = "$(hostname)\sql2016"
$config['Instance1'] = "$(hostname)\sql2019"
$config['Instance2'] = "$(hostname)\sql2017"
$config['Instance3'] = "$(hostname)\sql2019"
$config['Instances'] = @($config['Instance1'], $config['Instance2'])
$config['InstanceSingle'] = "$(hostname)\sql2019"
$config['InstanceMulti1'] = "$(hostname)\sql2019"
$config['InstanceMulti2'] = "$(hostname)\sql2017"
$config['InstanceCopy1'] = "$(hostname)\sql2016"
$config['InstanceCopy2'] = "$(hostname)\sql2017"
$config['InstanceHadr'] = "$(hostname)\sql2017"
$config['InstanceRestart'] = "$(hostname)\sql2017"
$config['InstanceCopy1'] = "$(hostname)\sql2017"
$config['InstanceCopy2'] = "$(hostname)\sql2019"
$config['InstanceHadr'] = "$(hostname)\sql2019"
$config['InstanceRestart'] = "$(hostname)\sql2019"

$config['SQLUserName'] = $null # placeholders for -SqlCredential testing
$config['SQLPassword'] = $null
Expand Down
28 changes: 0 additions & 28 deletions tests/appveyor.SQL2008R2SP2.ps1

This file was deleted.

28 changes: 0 additions & 28 deletions tests/appveyor.SQL2016.ps1

This file was deleted.

20 changes: 10 additions & 10 deletions tests/appveyor.SQL2017.ps1
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
$indent = '...'
Write-Host -Object "$indent Running $PSCommandPath" -ForegroundColor DarkGreen

# This script spins up the 2016 instance and the relative setup
# This script spins up the 2017 instance and the relative setup

$sqlinstance = "localhost\SQL2017"
$instance = "SQL2017"
$port = "14334"

Write-Host -Object "$indent Setting up AppVeyor Services" -ForegroundColor DarkGreen
Set-Service -Name SQLBrowser -StartupType Automatic
Set-Service -Name "SQLAgent`$$instance" -StartupType Automatic
Start-Service -Name SQLBrowser -ErrorAction SilentlyContinue

Write-Host -Object "$indent Changing the port on $instance to $port" -ForegroundColor DarkGreen
$null = Set-DbaNetworkConfiguration -SqlInstance $sqlinstance -StaticPortForIPAll $port -EnableException -Confirm:$false -WarningAction SilentlyContinue

Write-Host -Object "$indent Starting $instance" -ForegroundColor DarkGreen
Restart-Service "MSSQL`$$instance" -Force
Restart-Service "SQLAgent`$$instance" -Force
Start-Service -Name "MSSQL`$$instance" -WarningAction SilentlyContinue
Start-Service -Name "SQLAgent`$$instance" -WarningAction SilentlyContinue

Write-Host -Object "$indent Configuring $instance" -ForegroundColor DarkGreen
$null = Set-DbaSpConfigure -SqlInstance $sqlinstance -Name ExtensibleKeyManagementEnabled -Value $true -EnableException
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE CRYPTOGRAPHIC PROVIDER dbatoolsci_AKV FROM FILE = 'C:\github\appveyor-lab\keytests\ekm\Microsoft.AzureKeyVaultService.EKM.dll'" -EnableException
$null = Enable-DbaAgHadr -SqlInstance $sqlinstance -Force -EnableException -Confirm:$false
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<StrongPassword>'" -EnableException
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE CERTIFICATE dbatoolsci_AGCert WITH SUBJECT = 'AG Certificate'" -EnableException

$loginName = "$env:COMPUTERNAME\$env:USERNAME"
$login = Get-DbaLogin -SqlInstance $sqlinstance -Login $loginName
if (-not $login) {
Write-Host -Object "$indent Creating login $env:COMPUTERNAME\$env:USERNAME on $instance" -ForegroundColor DarkGreen
$null = New-DbaLogin -SqlInstance $sqlinstance -Name $loginName -EnableException
}
29 changes: 29 additions & 0 deletions tests/appveyor.SQL2019.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
$indent = '...'
Write-Host -Object "$indent Running $PSCommandPath" -ForegroundColor DarkGreen

# This script spins up the 2019 instance and the relative setup

$sqlinstance = "localhost\SQL2019"
$instance = "SQL2019"
$port = "1433"

Write-Host -Object "$indent Changing the port on $instance to $port" -ForegroundColor DarkGreen
$null = Set-DbaNetworkConfiguration -SqlInstance $sqlinstance -StaticPortForIPAll $port -EnableException -Confirm:$false -WarningAction SilentlyContinue

Write-Host -Object "$indent Starting $instance" -ForegroundColor DarkGreen
Start-Service -Name "MSSQL`$$instance" -WarningAction SilentlyContinue
Start-Service -Name "SQLAgent`$$instance" -WarningAction SilentlyContinue

Write-Host -Object "$indent Configuring $instance" -ForegroundColor DarkGreen
$null = Set-DbaSpConfigure -SqlInstance $sqlinstance -Name ExtensibleKeyManagementEnabled -Value $true -EnableException
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE CRYPTOGRAPHIC PROVIDER dbatoolsci_AKV FROM FILE = 'C:\github\appveyor-lab\keytests\ekm\Microsoft.AzureKeyVaultService.EKM.dll'" -EnableException
$null = Enable-DbaAgHadr -SqlInstance $sqlinstance -Force -EnableException -Confirm:$false
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<StrongPassword>'" -EnableException
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE CERTIFICATE dbatoolsci_AGCert WITH SUBJECT = 'AG Certificate'" -EnableException

$loginName = "$env:COMPUTERNAME\$env:USERNAME"
$login = Get-DbaLogin -SqlInstance $sqlinstance -Login $loginName
if (-not $login) {
Write-Host -Object "$indent Creating login $env:COMPUTERNAME\$env:USERNAME on $instance" -ForegroundColor DarkGreen
$null = New-DbaLogin -SqlInstance $sqlinstance -Name $loginName -EnableException
}
4 changes: 2 additions & 2 deletions tests/appveyor.common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,14 @@ function Get-TestsForBuildScenario {
$AllScenarioTests = $AllTests
}
if (-not($Silent)) {
Write-Host -ForegroundColor DarkGreen "Test Groups : Reduced to $($AllScenarioTests.Count) out of $($AllDbatoolsTests.Count) tests"
Write-Host -ForegroundColor DarkGreen "Test Groups: Reduced to $($AllScenarioTests.Count) out of $($AllDbatoolsTests.Count) tests"
}
# do we have a part ? (1/2, 2/2, etc)
if ($env:PART) {
try {
[int]$num, [int]$denom = $env:PART.Split('/')
if (-not($Silent)) {
Write-Host -ForegroundColor DarkGreen "Test Parts : part $($env:PART) on total $($AllScenarioTests.Count)"
Write-Host -ForegroundColor DarkGreen "Test Parts: part $($env:PART) on total $($AllScenarioTests.Count)"
}
#shuffle things a bit (i.e. with natural sorting most of the *get* fall into the first part, all the *set* in the last, etc)
$AllScenarioTestsShuffled = $AllScenarioTests | Sort-Object -Property @{Expression = { $_.Name.Split('-')[-1].Replace('Dba', '') }; Ascending = $true }
Expand Down
7 changes: 6 additions & 1 deletion tests/appveyor.pester.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,12 @@ if (-not $Finalize) {
}
$errorMessageDetail = $failedTestsList -join " | "

Update-AppveyorTest -Name $appvTestName -Framework NUnit -FileName $f.FullName -Outcome "Failed" -Duration $PesterRun.Duration.TotalMilliseconds -ErrorMessage $errorMessageDetail
if ($trialNo -le 3) {
Write-Host -Object "appveyor.pester: Test failed with $($PesterRun.FailedCount) failed tests. Retrying (attempt $trialNo of 3)..." -ForegroundColor Yellow
} else {
Write-Host -Object "appveyor.pester: Test failed with $($PesterRun.FailedCount) failed tests. No more retries left." -ForegroundColor Red
Update-AppveyorTest -Name $appvTestName -Framework NUnit -FileName $f.FullName -Outcome "Failed" -Duration $PesterRun.Duration.TotalMilliseconds -ErrorMessage $errorMessageDetail
}

# Add to summary
$allTestsSummary.TestRuns += @{
Expand Down
Loading