91 lines
4.0 KiB
PowerShell
91 lines
4.0 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.225",
|
|
[string]$ResultPath = "artifacts\c18z43-service-channel-schema-preflight-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-Api {
|
|
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-Api -Path "/clusters/$ClusterID/fabric/service-channels/schema-status?actor_user_id=$ActorUserID" -TimeoutSec 15).fabric_service_channel_schema_status
|
|
$readiness = (Invoke-Api -Path "/clusters/$ClusterID/fabric/service-channels/readiness?actor_user_id=$ActorUserID&limit=5" -TimeoutSec 30).fabric_service_channel_readiness
|
|
$health = (Invoke-Api -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-health?actor_user_id=$ActorUserID&limit=5" -TimeoutSec 30).rebuild_health
|
|
$backendLine = (& ssh $DockerSSH "docker ps --format '{{.Names}} {{.Image}} {{.Status}}' | grep '^rap_test_backend '") | Out-String
|
|
|
|
$missingChecksValue = Get-Prop $schemaStatus "missing_checks"
|
|
$requiredChecksValue = Get-Prop $schemaStatus "required_checks"
|
|
$missingChecks = @()
|
|
if ($null -ne $missingChecksValue) {
|
|
$missingChecks = @($missingChecksValue)
|
|
}
|
|
$requiredChecks = @()
|
|
if ($null -ne $requiredChecksValue) {
|
|
$requiredChecks = @($requiredChecksValue)
|
|
}
|
|
|
|
$result = [ordered]@{
|
|
schema_version = "c18z43.service_channel_schema_preflight_smoke.v1"
|
|
cluster_id = $ClusterID
|
|
passed = [bool](
|
|
$backendLine.Contains($ExpectedBackendImage) -and
|
|
[string]$schemaStatus.status -eq "ready" -and
|
|
[string]$schemaStatus.reason -eq "schema_ready" -and
|
|
[int]$schemaStatus.missing_check_count -eq 0 -and
|
|
$missingChecks.Count -eq 0 -and
|
|
$requiredChecks.Count -ge 20 -and
|
|
[string]$readiness.status -ne "" -and
|
|
[int]$health.total_attempts -ge 0
|
|
)
|
|
checks = [ordered]@{
|
|
backend_expected_image_deployed = $backendLine.Contains($ExpectedBackendImage)
|
|
schema_ready = ([string]$schemaStatus.status -eq "ready")
|
|
reason_ready = ([string]$schemaStatus.reason -eq "schema_ready")
|
|
no_missing_checks = ([int]$schemaStatus.missing_check_count -eq 0 -and $missingChecks.Count -eq 0)
|
|
required_checks_present = ($requiredChecks.Count -ge 20)
|
|
readiness_available = ([string]$readiness.status -ne "")
|
|
rebuild_health_available = ([int]$health.total_attempts -ge 0)
|
|
}
|
|
summary = [ordered]@{
|
|
backend_container = $backendLine.Trim()
|
|
required_migration = [string]$schemaStatus.required_migration
|
|
required_check_count = [int]$schemaStatus.required_check_count
|
|
passed_check_count = [int]$schemaStatus.passed_check_count
|
|
missing_check_count = [int]$schemaStatus.missing_check_count
|
|
readiness_status = [string]$readiness.status
|
|
rebuild_health_total_attempts = [int]$health.total_attempts
|
|
}
|
|
}
|
|
|
|
$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 "C18Z43 service-channel schema preflight smoke failed. Result: $resultFullPath"
|
|
}
|
|
|
|
Write-Host "C18Z43 service-channel schema preflight smoke passed. Result: $resultFullPath"
|
|
$result
|