257 lines
12 KiB
PowerShell
257 lines
12 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.239",
|
|
[string]$ExpectedNodeAgentImage = "rap-node-agent:0.2.237",
|
|
[string]$ResultPath = "artifacts\c18z54-service-channel-normal-route-access-smoke-result.json"
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$repoRoot = (Resolve-Path (Join-Path $scriptDir "..\..")).ProviderPath
|
|
$runId = "c18z54-" + (Get-Date -Format "yyyyMMdd-HHmmss")
|
|
|
|
function Invoke-Api {
|
|
param(
|
|
[string]$Method,
|
|
[string]$Path,
|
|
[object]$Body = $null
|
|
)
|
|
if ($null -eq $Body) {
|
|
return Invoke-RestMethod -Method $Method -Uri "$ApiBaseUrl$Path" -TimeoutSec 30
|
|
}
|
|
return Invoke-RestMethod -Method $Method -Uri "$ApiBaseUrl$Path" -ContentType "application/json" -Body ($Body | ConvertTo-Json -Depth 80) -TimeoutSec 30
|
|
}
|
|
|
|
function Get-NodeByName {
|
|
param([string]$Name)
|
|
$nodes = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/nodes?actor_user_id=$ActorUserID").nodes
|
|
$node = @($nodes | Where-Object { $_.name -eq $Name }) | Select-Object -First 1
|
|
if ($null -eq $node) {
|
|
throw "Node '$Name' was not found in cluster $ClusterID"
|
|
}
|
|
return $node
|
|
}
|
|
|
|
function New-RouteIntent {
|
|
param(
|
|
[string]$SourceNodeID,
|
|
[string]$DestinationNodeID
|
|
)
|
|
$expiresAt = (Get-Date).ToUniversalTime().AddMinutes(5).ToString("o")
|
|
return Invoke-Api -Method POST -Path "/clusters/$ClusterID/mesh/route-intents" -Body @{
|
|
actor_user_id = $ActorUserID
|
|
source_selector = @{ node_id = $SourceNodeID }
|
|
destination_selector = @{ node_id = $DestinationNodeID }
|
|
service_class = "vpn_packets"
|
|
priority = 2100000000
|
|
policy = @{
|
|
synthetic_enabled = $true
|
|
route_version = "$runId-direct"
|
|
policy_version = "$runId-direct"
|
|
peer_directory_version = "$runId-direct"
|
|
hops = @($SourceNodeID, $DestinationNodeID)
|
|
allowed_channels = @("vpn_packet", "fabric_control")
|
|
max_ttl = 8
|
|
max_hops = 8
|
|
expires_at = $expiresAt
|
|
metadata = @{
|
|
smoke = "c18z54_service_channel_normal_route_access"
|
|
run_id = $runId
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function Send-QualityHeartbeat {
|
|
param(
|
|
[string]$EntryNodeID,
|
|
[string]$RouteID
|
|
)
|
|
$observedAt = (Get-Date).ToUniversalTime().ToString("o")
|
|
return Invoke-Api -Method POST -Path "/clusters/$ClusterID/nodes/$EntryNodeID/heartbeats" -Body @{
|
|
health_status = "healthy"
|
|
reported_version = "0.2.235"
|
|
capabilities = @{
|
|
fabric_service_channel_runtime = $true
|
|
fabric_service_channel_route_manager = $true
|
|
fabric_service_channel_route_quality_feedback = $true
|
|
smoke_feedback_injection = "c18z54"
|
|
}
|
|
service_states = @{ smoke = "c18z54_normal_route_quality_feedback" }
|
|
metadata = @{
|
|
fabric_service_channel_runtime_report = @{
|
|
schema_version = "c18l.fabric_service_channel_runtime_report.v1"
|
|
config_version = "$runId-direct"
|
|
cluster_id = $ClusterID
|
|
local_node_id = $EntryNodeID
|
|
observed_at = $observedAt
|
|
ingress = @{
|
|
flow_scheduler = @{
|
|
schema_version = "rap.fabric_flow_scheduler.v1"
|
|
service_neutral = $true
|
|
service_mode = "application_protocol_agnostic"
|
|
channel_stats = @{
|
|
"c18z54-normal-route" = @{
|
|
last_route_id = $RouteID
|
|
route_generation = "$runId-direct"
|
|
last_send_duration_ms = 11
|
|
consecutive_failures = 0
|
|
stall_count = 0
|
|
route_rebuild_recommended = $false
|
|
degraded_fallback_recommended = $false
|
|
quality_window_sample_count = 6
|
|
quality_window_success_count = 6
|
|
quality_window_failure_count = 0
|
|
quality_window_slow_count = 1
|
|
quality_window_drop_count = 0
|
|
quality_window_avg_latency_ms = 11
|
|
quality_window_last_updated_at = $observedAt
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
smoke = @{
|
|
name = "c18z54_service_channel_normal_route_access"
|
|
run_id = $runId
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$entryNode = Get-NodeByName -Name $EntryNodeName
|
|
$exitNode = Get-NodeByName -Name $ExitNodeName
|
|
$routeID = ""
|
|
$result = $null
|
|
|
|
try {
|
|
$routeIntent = (New-RouteIntent -SourceNodeID $entryNode.id -DestinationNodeID $exitNode.id).route_intent
|
|
$routeID = [string]$routeIntent.id
|
|
[void](Send-QualityHeartbeat -EntryNodeID $entryNode.id -RouteID $routeID)
|
|
|
|
$resourceID = "c18z54-vpn-smoke"
|
|
$lease = (Invoke-Api -Method POST -Path "/clusters/$ClusterID/fabric/service-channels/leases" -Body @{
|
|
actor_user_id = $ActorUserID
|
|
organization_id = "smoke-org"
|
|
user_id = "smoke-user"
|
|
resource_id = $resourceID
|
|
service_class = "vpn_packets"
|
|
entry_node_ids = @([string]$entryNode.id)
|
|
exit_node_ids = @([string]$exitNode.id)
|
|
preferred_entry_node_id = [string]$entryNode.id
|
|
preferred_exit_node_id = [string]$exitNode.id
|
|
allowed_channels = @("vpn_packet", "fabric_control")
|
|
ttl_seconds = 180
|
|
metadata = @{
|
|
smoke = "c18z54_service_channel_normal_route_access"
|
|
run_id = $runId
|
|
}
|
|
}).fabric_service_channel_lease
|
|
|
|
$packetPath = $lease.entry_http.path_template.
|
|
Replace("{cluster_id}", $ClusterID).
|
|
Replace("{channel_id}", [string]$lease.channel_id).
|
|
Replace("{resource_id}", $resourceID)
|
|
$packetUrl = $EntryBaseUrl.TrimEnd("/") + $packetPath
|
|
$headers = @{
|
|
"X-RAP-Service-Channel-Token" = [string]$lease.token.token
|
|
"X-RAP-Fabric-Channel-ID" = [string]$lease.channel_id
|
|
"X-RAP-Service-Class" = "vpn_packets"
|
|
"X-RAP-Channel-Class" = "vpn_packet"
|
|
}
|
|
$response = Invoke-WebRequest -Method Post -Uri $packetUrl -Headers $headers -Body ([System.Text.Encoding]::UTF8.GetBytes("c18z54-normal-route")) -ContentType "application/octet-stream" -TimeoutSec 30
|
|
$acceptedBy = [string]$response.Headers["X-RAP-Service-Channel-Accepted-By"]
|
|
|
|
$accessTelemetry = $null
|
|
$matchingChannel = $null
|
|
for ($i = 0; $i -lt 10; $i++) {
|
|
Start-Sleep -Seconds 3
|
|
$accessTelemetry = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/fabric/service-channels/access-telemetry?actor_user_id=$ActorUserID&limit=20").fabric_service_channel_access_telemetry
|
|
$channels = @()
|
|
if ($accessTelemetry.PSObject.Properties.Name -contains "active_channels") {
|
|
$channels = @($accessTelemetry.active_channels)
|
|
}
|
|
$matchingChannel = $channels | Where-Object { $_.channel_id -eq $lease.channel_id } | Select-Object -First 1
|
|
if ($null -ne $matchingChannel -and [string]$matchingChannel.route_feedback_status -eq "healthy" -and [int]$matchingChannel.route_quality_window_sample_count -ge 6) {
|
|
break
|
|
}
|
|
}
|
|
|
|
$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 = "c18z54.service_channel_normal_route_access_smoke.v1"
|
|
run_id = $runId
|
|
cluster_id = $ClusterID
|
|
route_id = $routeID
|
|
channel_id = [string]$lease.channel_id
|
|
passed = [bool](
|
|
$backendLine.Contains($ExpectedBackendImage) -and
|
|
$nodeLines.Contains($ExpectedNodeAgentImage) -and
|
|
[string]$lease.status -eq "ready" -and
|
|
[string]$lease.primary_route.route_id -eq $routeID -and
|
|
[int]$response.StatusCode -eq 202 -and
|
|
$acceptedBy -eq "introspection" -and
|
|
$null -ne $matchingChannel -and
|
|
[string]$matchingChannel.primary_route_id -eq $routeID -and
|
|
-not [bool]$matchingChannel.force_backend_fallback -and
|
|
[string]$matchingChannel.route_feedback_status -eq "healthy" -and
|
|
[int]$matchingChannel.route_quality_window_sample_count -ge 6
|
|
)
|
|
checks = [ordered]@{
|
|
backend_expected_image_deployed = $backendLine.Contains($ExpectedBackendImage)
|
|
node_agent_expected_image_deployed = $nodeLines.Contains($ExpectedNodeAgentImage)
|
|
lease_ready = ([string]$lease.status -eq "ready")
|
|
lease_selected_normal_route = ([string]$lease.primary_route.route_id -eq $routeID)
|
|
packet_accepted = ([int]$response.StatusCode -eq 202)
|
|
accepted_by_header_is_introspection = ($acceptedBy -eq "introspection")
|
|
active_channel_visible = ($null -ne $matchingChannel)
|
|
active_channel_uses_primary_route = ($null -ne $matchingChannel -and [string]$matchingChannel.primary_route_id -eq $routeID)
|
|
active_channel_not_backend_fallback = ($null -ne $matchingChannel -and -not [bool]$matchingChannel.force_backend_fallback)
|
|
route_quality_correlated = ($null -ne $matchingChannel -and [string]$matchingChannel.route_feedback_status -eq "healthy" -and [int]$matchingChannel.route_quality_window_sample_count -ge 6)
|
|
}
|
|
summary = [ordered]@{
|
|
backend_container = $backendLine.Trim()
|
|
node_containers = $nodeLines.Trim()
|
|
accepted_by = $acceptedBy
|
|
lease_status = [string]$lease.status
|
|
lease_primary_route_id = [string]$lease.primary_route.route_id
|
|
access_status = [string]$accessTelemetry.status
|
|
active_channel_count = [int]$accessTelemetry.active_channel_count
|
|
correlated_route_count = [int]$accessTelemetry.correlated_route_count
|
|
degraded_route_count = [int]$accessTelemetry.degraded_route_count
|
|
matching_channel = $matchingChannel
|
|
}
|
|
}
|
|
$failedChecks = @($result.checks.GetEnumerator() | Where-Object { $_.Value -ne $true })
|
|
if ($failedChecks.Count -gt 0) {
|
|
throw "C18Z54 failed checks: $($failedChecks.Name -join ', ')"
|
|
}
|
|
}
|
|
finally {
|
|
if ($routeID) {
|
|
try { Invoke-Api -Method POST -Path "/clusters/$ClusterID/mesh/route-intents/$routeID/expire" -Body @{ actor_user_id = $ActorUserID } | Out-Null } catch {}
|
|
}
|
|
}
|
|
|
|
$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
|
|
|
|
Write-Host "C18Z54 service-channel normal route access smoke passed. Result: $resultFullPath"
|
|
$result
|
|
|
|
|