made the backup update script fail faster
This commit is contained in:
@@ -31,10 +31,10 @@ try {
|
||||
}
|
||||
}
|
||||
# Substitute only discovery of the installed product in the downloaded core.
|
||||
$discovery = Find-TestFunction $core 'Get-CloudBackupAgent'
|
||||
$coreSource = $core.Extent.Text.Replace($discovery.Extent.Text, 'function Get-CloudBackupAgent { Get-FixtureAgent }')
|
||||
$discovery = Find-TestFunction $core 'Get-CloudBackupInstallation'
|
||||
$coreSource = $core.Extent.Text.Replace($discovery.Extent.Text, 'function Get-CloudBackupInstallation { Get-FixtureInstallation }')
|
||||
$toolsAst = Read-TestAst (Join-Path $repo 'Tools.ps1')
|
||||
$shimTools = (@('Run-Script','Get-EmberkomCloudBackupRelease','Save-EmberkomCloudBackupInstaller') |
|
||||
$shimTools = (@('Run-Script','Get-EmberkomCloudBackupReleases','Get-EmberkomCloudBackupRelease','Save-EmberkomCloudBackupInstaller') |
|
||||
ForEach-Object { (Find-TestFunction $toolsAst $_).Extent.Text }) -join [Environment]::NewLine
|
||||
$fixtureBytes = [byte[]](1,2,3)
|
||||
$sha = [Security.Cryptography.SHA256]::Create()
|
||||
@@ -60,7 +60,10 @@ try {
|
||||
$client | Add-Member ScriptMethod DownloadString { param($url)
|
||||
if ($url -like '*/Tools.ps1') { return $shimTools }
|
||||
if ($url -like '*/Update-EmberkomCloudBackup.ps1') { return $coreSource }
|
||||
if ($url -like '*/resources/EmberkomCloudBackup.json') { return ($manifest | ConvertTo-Json) }
|
||||
if ($url -like '*/resources/EmberkomCloudBackup.json') {
|
||||
$record.ManifestReads++
|
||||
return ($manifest | ConvertTo-Json)
|
||||
}
|
||||
throw "Unexpected URL"
|
||||
}
|
||||
$client | Add-Member ScriptMethod DownloadFile { param($url,$path)
|
||||
@@ -74,13 +77,21 @@ try {
|
||||
$client | Add-Member ScriptMethod Dispose {}
|
||||
return $client
|
||||
}
|
||||
function Get-FixtureAgent {
|
||||
function Get-FixtureInstallation {
|
||||
if ($scenario -eq 'absent') { return }
|
||||
$v = '8.9.1.177'
|
||||
if ($scenario -eq 'current' -or ($record.Installs -and $scenario -ne 'unverified')) { $v = '8.10.1.177' }
|
||||
if ($scenario -in @('current','only VM newer','VM needs update','incomplete Windows')) { $v = '8.10.1.177' }
|
||||
if ($record.Installs -and $scenario -ne 'unverified') { $v = $manifest.$kind.Version }
|
||||
if ($scenario -eq 'newer') { $v = '8.11.0.1' }
|
||||
if ($scenario -eq 'already updated' -and $record.Downloads) { $v = '8.10.1.177' }
|
||||
[pscustomobject]@{ Version=[version]$v; Build=$kind; Service='Fixture Service' }
|
||||
[pscustomobject]@{ Version=[version]$v; Cli='Get-FixtureCli' }
|
||||
}
|
||||
function Get-FixtureCli($Command) {
|
||||
if ($Command -ne 'ver') { throw 'Unexpected agent command' }
|
||||
$record.CliCalls++
|
||||
$global:LASTEXITCODE = 0
|
||||
if ($kind -eq 'VM') { 'Backup Agent Edition: VMware' } else { 'Backup Agent Edition: DesktopIBB' }
|
||||
'Service name: Fixture Service'
|
||||
}
|
||||
function Get-Date {
|
||||
if ($scenario -eq 'window ended' -and $record.Downloads) { return [datetime]'2026-01-01T13:00' }
|
||||
@@ -88,6 +99,7 @@ try {
|
||||
}
|
||||
function Get-CimInstance {
|
||||
param($ClassName,$Filter,$Property,$ErrorAction)
|
||||
$record.PlanChecks++
|
||||
if ($ClassName -ne 'Win32_Process' -or $Filter -ne "Name = 'CBBackupPlan.exe'") { throw 'Unexpected worker query' }
|
||||
if ($scenario -eq 'query failure') { throw 'Cannot enumerate processes' }
|
||||
if ($scenario -eq 'busy' -or ($record.Downloads -and $scenario -eq 'late plan')) { [pscustomobject]@{ ProcessId=42 } }
|
||||
@@ -110,6 +122,7 @@ try {
|
||||
}
|
||||
foreach ($case in @(
|
||||
@('absent',0,0,0), @('current',0,0,0), @('newer',0,0,0),
|
||||
@('only VM newer',0,0,0), @('VM needs update',0,1,1), @('incomplete Windows',1,0,0),
|
||||
@('busy',0,0,0), @('late plan',0,1,0), @('query failure',1,0,0),
|
||||
@('download failure',1,1,0), @('already updated',0,1,0), @('window ended',0,1,0),
|
||||
@('bad window',1,0,0), @('corrupt',1,1,0), @('success',0,1,1),
|
||||
@@ -117,17 +130,24 @@ try {
|
||||
@('service down',1,1,1), @('reboot',3010,1,1)
|
||||
)) {
|
||||
$scenario,$expected,$expectedDownloads,$expectedInstalls = $case
|
||||
$kind = if ($scenario -eq 'VM') { 'VM' } else { 'Windows' }
|
||||
$kind = if ($scenario -in @('VM','VM needs update')) { 'VM' } else { 'Windows' }
|
||||
$manifest.VM.Version = if ($scenario -in @('only VM newer','VM needs update')) { '8.11.1.177' } else { '8.10.1.177' }
|
||||
$manifest.Windows.SHA256 = if ($scenario -eq 'incomplete Windows') { '' } else { $hash }
|
||||
$MSP360UpdateWindow = switch ($scenario) {
|
||||
'bad window' { '25:00-26:00' }
|
||||
'window ended' { '12:00-13:00' }
|
||||
default { '' }
|
||||
}
|
||||
$record = @{ Downloads=0; Installs=0; Staged=$null }
|
||||
$record = @{ Downloads=0; Installs=0; Staged=$null; ManifestReads=0; CliCalls=0; PlanChecks=0 }
|
||||
$messages = & (Join-Path $repo 'rmm/Update-EmberkomCloudBackup.ps1') *>&1
|
||||
if ($LASTEXITCODE -ne $expected -or $record.Downloads -ne $expectedDownloads -or $record.Installs -ne $expectedInstalls) {
|
||||
throw "$scenario failed. Exit=$LASTEXITCODE Downloads=$($record.Downloads) Installs=$($record.Installs). $messages"
|
||||
}
|
||||
if ($scenario -in @('current','newer','only VM newer')) {
|
||||
$expectedCliCalls = if ($scenario -eq 'only VM newer') { 1 } else { 0 }
|
||||
if ($record.ManifestReads -ne 1 -or $record.CliCalls -ne $expectedCliCalls -or $record.PlanChecks -ne 0 -or
|
||||
($messages -join ' ') -notmatch 'No update needed') { throw "$scenario did not take the expected early exit" }
|
||||
}
|
||||
if ($record.Staged -and (Test-Path -LiteralPath $record.Staged)) { throw "$scenario left staged media" }
|
||||
Write-Host "PASS $scenario"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user