117 lines
5.5 KiB
PowerShell
117 lines
5.5 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]$EntryNodeName = "test-1",
|
|
[string]$ExitNodeName = "test-2",
|
|
[string]$EntryBaseUrl = "http://192.168.200.61:19131",
|
|
[string]$DockerSSH = "test-docker",
|
|
[string]$ExpectedBackendImage = "rap-backend:fabric-service-channel-0.2.214",
|
|
[string]$ExpectedNodeAgentImage = "rap-node-agent:0.2.208",
|
|
[string]$ResultPath = "artifacts\c18z33-service-channel-rebuild-guard-smoke-result.json"
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$repoRoot = (Resolve-Path (Join-Path $scriptDir "..\..")).ProviderPath
|
|
$baseResultPath = "artifacts\c18z33-base-rebuild-ledger-smoke-result.json"
|
|
|
|
& (Join-Path $scriptDir "c18z31-service-channel-rebuild-ledger-smoke.ps1") `
|
|
-ApiBaseUrl $ApiBaseUrl `
|
|
-ClusterID $ClusterID `
|
|
-ActorUserID $ActorUserID `
|
|
-EntryNodeName $EntryNodeName `
|
|
-ExitNodeName $ExitNodeName `
|
|
-EntryBaseUrl $EntryBaseUrl `
|
|
-DockerSSH $DockerSSH `
|
|
-ExpectedBackendImage $ExpectedBackendImage `
|
|
-ExpectedNodeAgentImage $ExpectedNodeAgentImage `
|
|
-ResultPath $baseResultPath | Out-Null
|
|
|
|
$baseResult = Get-Content (Join-Path $repoRoot $baseResultPath) -Raw | ConvertFrom-Json
|
|
$entryNodeID = [string]$baseResult.entry_node.id
|
|
$primaryRouteID = [string]$baseResult.primary_route_id
|
|
$alternateRouteID = [string]$baseResult.alternate_route_id
|
|
|
|
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
|
|
}
|
|
|
|
$ledger = (Invoke-RestMethod -Method Get -Uri "$ApiBaseUrl/clusters/$ClusterID/fabric/service-channels/rebuild-attempts?actor_user_id=$ActorUserID&reporter_node_id=$entryNodeID&route_id=$primaryRouteID&replacement_route_id=$alternateRouteID&limit=20&enrichment=deep" -TimeoutSec 30).rebuild_attempts
|
|
$matching = @($ledger | Where-Object {
|
|
$_.route_id -eq $primaryRouteID -and
|
|
$_.replacement_route_id -eq $alternateRouteID -and
|
|
$_.rebuild_status -eq "applied" -and
|
|
(Get-Prop $_ "node_transition_matched") -eq $true -and
|
|
(Get-Prop $_ "node_route_generation_matched") -eq $true -and
|
|
(Get-Prop $_ "post_rebuild_selected_route_id") -and
|
|
[string](Get-Prop $_ "guard_status") -eq "ok"
|
|
})
|
|
$sample = $matching | Select-Object -First 1
|
|
$timelineStages = @()
|
|
if ($null -ne $sample -and $null -ne $sample.timeline) {
|
|
$timelineStages = @($sample.timeline | ForEach-Object { [string]$_.stage })
|
|
}
|
|
|
|
$backendLine = (& ssh $DockerSSH "docker ps --format '{{.Names}} {{.Image}} {{.Status}}' | grep '^rap_test_backend '") | Out-String
|
|
$nodeLines = (& ssh $DockerSSH "docker ps --format '{{.Names}} {{.Image}} {{.Status}}' | grep '^rap_test_node_test_'") | Out-String
|
|
|
|
$result = [ordered]@{
|
|
schema_version = "c18z33.service_channel_rebuild_guard_smoke.v1"
|
|
cluster_id = $ClusterID
|
|
primary_route_id = $primaryRouteID
|
|
alternate_route_id = $alternateRouteID
|
|
passed = [bool](
|
|
$backendLine.Contains($ExpectedBackendImage) -and
|
|
$nodeLines.Contains($ExpectedNodeAgentImage) -and
|
|
$matching.Count -ge 1 -and
|
|
$timelineStages -contains "backend_decision" -and
|
|
$timelineStages -contains "node_route_manager_transition" -and
|
|
$timelineStages -contains "node_route_generation_apply" -and
|
|
$timelineStages -contains "post_rebuild_traffic" -and
|
|
[string]$sample.node_transition_status -eq "applied_rebuild" -and
|
|
[string]$sample.post_rebuild_selected_route_id -eq $alternateRouteID -and
|
|
[string]$sample.guard_status -eq "ok" -and
|
|
[string]$sample.guard_severity -eq "good"
|
|
)
|
|
checks = [ordered]@{
|
|
backend_expected_image_deployed = $backendLine.Contains($ExpectedBackendImage)
|
|
node_agent_expected_image_deployed = $nodeLines.Contains($ExpectedNodeAgentImage)
|
|
timeline_has_backend_decision = ($timelineStages -contains "backend_decision")
|
|
timeline_has_node_route_manager_transition = ($timelineStages -contains "node_route_manager_transition")
|
|
timeline_has_node_route_generation_apply = ($timelineStages -contains "node_route_generation_apply")
|
|
timeline_has_post_rebuild_traffic = ($timelineStages -contains "post_rebuild_traffic")
|
|
node_transition_applied_rebuild = ([string]$sample.node_transition_status -eq "applied_rebuild")
|
|
post_rebuild_uses_replacement = ([string]$sample.post_rebuild_selected_route_id -eq $alternateRouteID)
|
|
guard_status_ok = ([string]$sample.guard_status -eq "ok")
|
|
guard_severity_good = ([string]$sample.guard_severity -eq "good")
|
|
}
|
|
summary = [ordered]@{
|
|
backend_container = $backendLine.Trim()
|
|
node_containers = $nodeLines.Trim()
|
|
matching_count = $matching.Count
|
|
sample = $sample
|
|
base_smoke_result = (Join-Path $repoRoot $baseResultPath)
|
|
}
|
|
}
|
|
|
|
$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 "C18Z33 service-channel rebuild guard smoke failed. Result: $resultFullPath"
|
|
}
|
|
|
|
Write-Host "C18Z33 service-channel rebuild guard smoke passed. Result: $resultFullPath"
|
|
$result
|