Files
rdp-proxy/scripts/fabric/c19z28-remote-workspace-no-session-summary-smoke.ps1
2026-05-14 23:30:34 +03:00

136 lines
6.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]$EntryNodeName = "test-1",
[string]$ResultPath = "artifacts\c19z28-remote-workspace-no-session-summary-smoke-result.json"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).ProviderPath
function Invoke-Api {
param([string]$Method, [string]$Path, [object]$Body = $null)
$uri = "$ApiBaseUrl$Path"
if ($null -eq $Body) { return Invoke-RestMethod -Method $Method -Uri $uri -TimeoutSec 30 }
return Invoke-RestMethod -Method $Method -Uri $uri -ContentType "application/json" -Body ($Body | ConvertTo-Json -Depth 80) -TimeoutSec 30
}
function Get-PropertyValue {
param([object]$Item, [string]$Name, [object]$Default = $null)
if ($null -eq $Item) { return $Default }
$property = $Item.PSObject.Properties[$Name]
if ($null -eq $property) { return $Default }
return $property.Value
}
function Test-ContractItem {
param([object]$Items, [string]$Want)
foreach ($item in @($Items)) {
if ([string]$item -eq $Want) { return $true }
}
return $false
}
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 Get-RemoteWorkspaceSinkReports {
param([string]$NodeID)
$statuses = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/nodes/$NodeID/workloads/status?actor_user_id=$ActorUserID").workload_statuses
$workloadStatus = @($statuses | Where-Object { $_.service_type -eq "rdp-worker" } | Select-Object -First 1)
$workloadSink = $null
if ($null -ne $workloadStatus) {
$workloadSink = Get-PropertyValue -Item $workloadStatus.status_payload -Name "remote_workspace_adapter_sink" -Default $null
}
$telemetryItems = @((Invoke-Api -Method GET -Path "/clusters/$ClusterID/nodes/$NodeID/telemetry?actor_user_id=$ActorUserID&limit=10").telemetry)
$telemetry = $telemetryItems | Select-Object -First 1
$telemetrySink = $null
if ($null -ne $telemetry) {
$telemetryPayload = Get-PropertyValue -Item $telemetry -Name "payload" -Default $null
$telemetrySink = Get-PropertyValue -Item $telemetryPayload -Name "remote_workspace_adapter_sink_report" -Default $null
}
return [ordered]@{
workload_status = $workloadStatus
workload_sink = $workloadSink
telemetry = $telemetry
telemetry_sink = $telemetrySink
}
}
function Test-NoSessionSummary {
param([object]$Sink)
if ($null -eq $Sink) { return $false }
$readiness = Get-PropertyValue -Item $Sink -Name "adapter_runtime_readiness" -Default $null
if ($null -eq $readiness) { return $false }
$summary = Get-PropertyValue -Item $readiness -Name "no_session_summary" -Default $null
if ($null -eq $summary) { return $false }
$contract = Get-PropertyValue -Item $summary -Name "summary_contract" -Default @()
return (
[string](Get-PropertyValue -Item $readiness -Name "diagnostic_state" -Default "") -eq "waiting_for_session" -and
[int](Get-PropertyValue -Item $readiness -Name "active_session_count" -Default -1) -eq 0 -and
[int](Get-PropertyValue -Item $readiness -Name "terminal_session_count" -Default -1) -eq 0 -and
[string](Get-PropertyValue -Item $summary -Name "schema_version" -Default "") -eq "rap.remote_workspace_adapter_no_session_summary.v1" -and
(Test-ContractItem -Items $contract -Want "status") -and
(Test-ContractItem -Items $contract -Want "diagnostic_state") -and
(Test-ContractItem -Items $contract -Want "active_session_count") -and
(Test-ContractItem -Items $contract -Want "terminal_session_count") -and
[string](Get-PropertyValue -Item $summary -Name "status" -Default "") -eq "idle" -and
[string](Get-PropertyValue -Item $summary -Name "diagnostic_state" -Default "") -eq "waiting_for_session" -and
[int](Get-PropertyValue -Item $summary -Name "active_session_count" -Default -1) -eq 0 -and
[int](Get-PropertyValue -Item $summary -Name "terminal_session_count" -Default -1) -eq 0
)
}
$entryNode = Get-NodeByName -Name $EntryNodeName
$observed = $null
$deadline = (Get-Date).AddSeconds(60)
while ((Get-Date) -lt $deadline) {
Start-Sleep -Seconds 5
$observed = Get-RemoteWorkspaceSinkReports -NodeID $entryNode.id
if (
(Test-NoSessionSummary -Sink $observed.workload_sink) -and
(Test-NoSessionSummary -Sink $observed.telemetry_sink)
) {
break
}
}
if ($null -eq $observed) {
$observed = Get-RemoteWorkspaceSinkReports -NodeID $entryNode.id
}
$checks = [ordered]@{
workload_no_session_summary_visible = (Test-NoSessionSummary -Sink $observed.workload_sink)
telemetry_no_session_summary_visible = (Test-NoSessionSummary -Sink $observed.telemetry_sink)
}
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
$result = [ordered]@{
schema_version = "c19z28.remote_workspace_no_session_summary_smoke.v1"
cluster_id = $ClusterID
entry_node = [ordered]@{ id = $entryNode.id; name = $entryNode.name }
observed = $observed
checks = $checks
failed_checks = $failed
passed = ($failed.Count -eq 0)
}
$fullResultPath = Join-Path $repoRoot $ResultPath
$resultDir = Split-Path -Parent $fullResultPath
if ($resultDir) { New-Item -ItemType Directory -Force -Path $resultDir | Out-Null }
$result | ConvertTo-Json -Depth 100 | Set-Content -Encoding UTF8 -Path $fullResultPath
if (-not $result.passed) {
throw "C19Z28 remote workspace no-session summary smoke failed. Result: $fullResultPath Failed: $($failed -join ', ')"
}
Write-Host "C19Z28 remote workspace no-session summary smoke passed. Result: $fullResultPath"
$result