74 lines
3.4 KiB
PowerShell
74 lines
3.4 KiB
PowerShell
param(
|
|
[string]$ApiBaseUrl = "http://192.168.200.61:18121/api/v1",
|
|
[string]$ClusterID = "cfc0743d-d960-49fb-9de8-96e063d5e4aa",
|
|
[string]$ActorUserID = "f67d943f-5397-4b3a-a229-695fe67ad700",
|
|
[string]$DockerSSH = "test-docker",
|
|
[string]$ExpectedBackendImage = "rap-backend:fabric-service-channel-0.2.228",
|
|
[string]$ResultPath = "artifacts\c18z46-service-channel-rebuild-snapshot-health-smoke-result.json"
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$repoRoot = (Resolve-Path (Join-Path $scriptDir "..\..")).ProviderPath
|
|
|
|
function Invoke-ApiGet {
|
|
param([string]$Path, [int]$TimeoutSec = 30)
|
|
Invoke-RestMethod -Method Get -Uri "$ApiBaseUrl$Path" -TimeoutSec $TimeoutSec
|
|
}
|
|
|
|
function Get-Prop {
|
|
param([object]$Object, [string]$Name)
|
|
if ($null -eq $Object) { return $null }
|
|
$prop = $Object.PSObject.Properties[$Name]
|
|
if ($null -eq $prop) { return $null }
|
|
return $prop.Value
|
|
}
|
|
|
|
$schemaStatus = (Invoke-ApiGet -Path "/clusters/$ClusterID/fabric/service-channels/schema-status?actor_user_id=$ActorUserID" -TimeoutSec 15).fabric_service_channel_schema_status
|
|
$health = (Invoke-ApiGet -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-snapshots/health?actor_user_id=$ActorUserID&limit=50&min_age_seconds=60&heartbeat_threshold=2" -TimeoutSec 30).rebuild_snapshot_health
|
|
$backendLine = (& ssh $DockerSSH "docker ps --format '{{.Names}} {{.Image}} {{.Status}}' | grep '^rap_test_backend '") | Out-String
|
|
|
|
$result = [ordered]@{
|
|
schema_version = "c18z46.service_channel_rebuild_snapshot_health_smoke.v1"
|
|
cluster_id = $ClusterID
|
|
passed = [bool](
|
|
$backendLine.Contains($ExpectedBackendImage) -and
|
|
[string](Get-Prop $schemaStatus "status") -ne "" -and
|
|
[string](Get-Prop $health "status") -ne "" -and
|
|
[int](Get-Prop $health "window_limit") -eq 50 -and
|
|
[int](Get-Prop $health "heartbeat_threshold") -eq 2 -and
|
|
[int](Get-Prop $health "recent_attempt_count") -ge 0 -and
|
|
[int](Get-Prop $health "auto_warmup_event_count") -ge 0
|
|
)
|
|
checks = [ordered]@{
|
|
backend_expected_image_deployed = $backendLine.Contains($ExpectedBackendImage)
|
|
schema_status_present = ([string](Get-Prop $schemaStatus "status") -ne "")
|
|
health_status_present = ([string](Get-Prop $health "status") -ne "")
|
|
health_window_limit_honored = ([int](Get-Prop $health "window_limit") -eq 50)
|
|
health_heartbeat_threshold_honored = ([int](Get-Prop $health "heartbeat_threshold") -eq 2)
|
|
health_recent_attempt_count_present = ([int](Get-Prop $health "recent_attempt_count") -ge 0)
|
|
health_auto_warmup_count_present = ([int](Get-Prop $health "auto_warmup_event_count") -ge 0)
|
|
}
|
|
summary = [ordered]@{
|
|
backend_container = $backendLine.Trim()
|
|
schema_status = $schemaStatus
|
|
snapshot_health = $health
|
|
}
|
|
}
|
|
|
|
$resultFullPath = Join-Path $repoRoot $ResultPath
|
|
$resultDir = Split-Path -Parent $resultFullPath
|
|
if (-not (Test-Path $resultDir)) {
|
|
New-Item -ItemType Directory -Path $resultDir | Out-Null
|
|
}
|
|
$result | ConvertTo-Json -Depth 100 | Set-Content -Path $resultFullPath -Encoding UTF8
|
|
|
|
if (-not $result.passed) {
|
|
throw "C18Z46 service-channel rebuild snapshot health smoke failed. Result: $resultFullPath"
|
|
}
|
|
|
|
Write-Host "C18Z46 service-channel rebuild snapshot health smoke passed. Result: $resultFullPath"
|
|
$result
|