69 lines
3.5 KiB
PowerShell
69 lines
3.5 KiB
PowerShell
param(
|
|
[ValidateRange(1, 65535)]
|
|
[int]$Port = 8080
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
$previousPort = $env:LAB3_HOST_PORT
|
|
$previousBase = $env:BASE_URL
|
|
$previousUtf8 = $env:PYTHONUTF8
|
|
$previousBytecode = $env:PYTHONDONTWRITEBYTECODE
|
|
function Assert-Success([string]$Step) {
|
|
if ($LASTEXITCODE -ne 0) { throw "$Step failed (exit code $LASTEXITCODE)" }
|
|
}
|
|
function Write-Evidence([string]$Line) {
|
|
Add-Content -LiteralPath $evidence -Value $Line -Encoding UTF8
|
|
Write-Host $Line
|
|
}
|
|
function Run-Python([string[]]$Arguments) {
|
|
Write-Evidence ("python " + ($Arguments -join ' '))
|
|
& python -X utf8 @Arguments | ForEach-Object { Write-Evidence $_ }
|
|
Assert-Success 'Python check'
|
|
}
|
|
Push-Location -LiteralPath (Join-Path $PSScriptRoot '..')
|
|
$state = Join-Path ([IO.Path]::GetTempPath()) ([guid]::NewGuid().ToString() + '.json')
|
|
try {
|
|
$env:PYTHONUTF8 = '1'
|
|
$env:PYTHONDONTWRITEBYTECODE = '1'
|
|
$env:LAB3_HOST_PORT = [string]$Port
|
|
if (!(Test-Path -LiteralPath '.env')) {
|
|
$password = python -X utf8 -c 'import secrets; print(secrets.token_hex(24))'
|
|
Assert-Success 'Local password generation'
|
|
(Get-Content -LiteralPath '.env.example') -replace '^POSTGRES_PASSWORD=.*', "POSTGRES_PASSWORD=$password" |
|
|
Set-Content -LiteralPath '.env' -Encoding Ascii
|
|
}
|
|
$evidence = 'evidence/results-windows.txt'
|
|
Set-Content -LiteralPath $evidence -Value ("Lab 3 verification " + (Get-Date -Format o)) -Encoding UTF8
|
|
docker compose --env-file .env config --quiet
|
|
Assert-Success 'Compose configuration'
|
|
docker compose --env-file .env up -d --build --wait --wait-timeout 90
|
|
Assert-Success 'Compose startup'
|
|
$address = docker compose --env-file .env port lb 8080
|
|
Assert-Success 'LB port lookup'
|
|
if ($address -notmatch '^127\.0\.0\.1:\d+$') { throw 'Expected local LB address' }
|
|
$env:BASE_URL = "http://$address"
|
|
Write-Evidence "PASS: Compose startup, public entrypoint $env:BASE_URL"
|
|
Run-Python @('scripts/check_contract.py')
|
|
Run-Python @('tests/smoke.py', '--base-url', $env:BASE_URL)
|
|
Run-Python @('tests/student_tests.py', '--base-url', $env:BASE_URL)
|
|
Run-Python @('tests/contract_edge_tests.py', '--base-url', $env:BASE_URL)
|
|
Run-Python @('tests/lab3_tests.py', '--base-url', $env:BASE_URL, '--restart-script', 'scripts/restart.cmd')
|
|
Run-Python @('scripts/operator_state.py', '--save', $state)
|
|
Run-Python @('tests/resilience.py', '--mode', 'persistence', '--base-url', $env:BASE_URL, '--action-script', 'scripts/restart.cmd')
|
|
Run-Python @('scripts/operator_state.py', '--compare', $state)
|
|
Run-Python @('tests/resilience.py', '--mode', 'failover', '--base-url', $env:BASE_URL, '--action-script', 'scripts/stop-one.cmd')
|
|
$env:TARGET_INSTANCE_ID = (Get-Content -LiteralPath 'evidence/last-stopped.txt').Trim()
|
|
& powershell -NoProfile -ExecutionPolicy Bypass -File scripts/restore.ps1 | ForEach-Object { Write-Evidence $_ }
|
|
Assert-Success 'Restore after public failover'
|
|
Run-Python @('tests/failover_each.py', '--base-url', $env:BASE_URL, '--action-script', 'scripts/stop-one.cmd', '--restore-script', 'scripts/restore.cmd')
|
|
Run-Python @('tests/smoke.py', '--base-url', $env:BASE_URL)
|
|
Write-Evidence 'PASS: full Lab 3 verification completed'
|
|
}
|
|
finally {
|
|
if (Test-Path -LiteralPath $state) { Remove-Item -LiteralPath $state }
|
|
$env:LAB3_HOST_PORT = $previousPort
|
|
$env:BASE_URL = $previousBase
|
|
$env:PYTHONUTF8 = $previousUtf8
|
|
$env:PYTHONDONTWRITEBYTECODE = $previousBytecode
|
|
Pop-Location
|
|
}
|