165 lines
8.6 KiB
PowerShell
165 lines
8.6 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]$ResultPath = "artifacts\c19z33-remote-workspace-readiness-state-matrix-smoke-result.json"
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).ProviderPath
|
|
$sourceResultPath = "artifacts\c19z33-remote-workspace-readiness-state-matrix-source-result.json"
|
|
|
|
function Get-PropertyValue {
|
|
param([object]$Item, [string]$Name, [object]$Default = $null)
|
|
if ($null -eq $Item) { return $Default }
|
|
if ($Item -is [System.Collections.IDictionary]) {
|
|
if ($Item.Contains($Name)) { return $Item[$Name] }
|
|
return $Default
|
|
}
|
|
$property = $Item.PSObject.Properties[$Name]
|
|
if ($null -eq $property) { return $Default }
|
|
return $property.Value
|
|
}
|
|
|
|
function Select-ReadinessMatrixRow {
|
|
param([object]$Observed, [string]$State, [string]$Surface)
|
|
$sink = Get-PropertyValue -Item $Observed -Name "${Surface}_sink" -Default $null
|
|
$readiness = Get-PropertyValue -Item $sink -Name "adapter_runtime_readiness" -Default $null
|
|
$noSessionSummary = Get-PropertyValue -Item $readiness -Name "no_session_summary" -Default $null
|
|
$terminalSummary = Get-PropertyValue -Item $readiness -Name "terminal_session_summary" -Default $null
|
|
return [ordered]@{
|
|
state = $State
|
|
surface = $Surface
|
|
schema_version = [string](Get-PropertyValue -Item $readiness -Name "schema_version" -Default "")
|
|
probe_only = [bool](Get-PropertyValue -Item $readiness -Name "probe_only" -Default $false)
|
|
payload_traffic = [string](Get-PropertyValue -Item $readiness -Name "payload_traffic" -Default "")
|
|
status = [string](Get-PropertyValue -Item $readiness -Name "status" -Default "")
|
|
diagnostic_state = [string](Get-PropertyValue -Item $readiness -Name "diagnostic_state" -Default "")
|
|
ready = [bool](Get-PropertyValue -Item $readiness -Name "ready" -Default $false)
|
|
active_session_count = [int](Get-PropertyValue -Item $readiness -Name "active_session_count" -Default -1)
|
|
terminal_session_count = [int](Get-PropertyValue -Item $readiness -Name "terminal_session_count" -Default -1)
|
|
adapter_session_id = Get-PropertyValue -Item $readiness -Name "adapter_session_id" -Default $null
|
|
last_adapter_session_id = Get-PropertyValue -Item $readiness -Name "last_adapter_session_id" -Default $null
|
|
last_session_state = Get-PropertyValue -Item $readiness -Name "last_session_state" -Default $null
|
|
no_session_summary_present = ($null -ne $noSessionSummary)
|
|
terminal_session_summary_present = ($null -ne $terminalSummary)
|
|
no_session_summary_schema = Get-PropertyValue -Item $noSessionSummary -Name "schema_version" -Default $null
|
|
terminal_session_summary_schema = Get-PropertyValue -Item $terminalSummary -Name "schema_version" -Default $null
|
|
}
|
|
}
|
|
|
|
function Test-MatrixRow {
|
|
param([object]$Row)
|
|
$state = [string](Get-PropertyValue -Item $Row -Name "state" -Default "")
|
|
if ([string](Get-PropertyValue -Item $Row -Name "schema_version" -Default "") -ne "rap.remote_workspace_adapter_runtime_readiness.v1") { return $false }
|
|
if (-not [bool](Get-PropertyValue -Item $Row -Name "probe_only" -Default $false)) { return $false }
|
|
if ([string](Get-PropertyValue -Item $Row -Name "payload_traffic" -Default "") -ne "none") { return $false }
|
|
if ($state -eq "fresh") {
|
|
return (
|
|
[string](Get-PropertyValue -Item $Row -Name "diagnostic_state" -Default "") -eq "waiting_for_session" -and
|
|
[int](Get-PropertyValue -Item $Row -Name "active_session_count" -Default -1) -eq 0 -and
|
|
[int](Get-PropertyValue -Item $Row -Name "terminal_session_count" -Default -1) -eq 0 -and
|
|
[bool](Get-PropertyValue -Item $Row -Name "no_session_summary_present" -Default $false) -and
|
|
-not [bool](Get-PropertyValue -Item $Row -Name "terminal_session_summary_present" -Default $true)
|
|
)
|
|
}
|
|
if ($state -eq "active") {
|
|
return (
|
|
[int](Get-PropertyValue -Item $Row -Name "active_session_count" -Default -1) -eq 1 -and
|
|
-not [string]::IsNullOrWhiteSpace([string](Get-PropertyValue -Item $Row -Name "adapter_session_id" -Default "")) -and
|
|
-not [bool](Get-PropertyValue -Item $Row -Name "no_session_summary_present" -Default $true) -and
|
|
-not [bool](Get-PropertyValue -Item $Row -Name "terminal_session_summary_present" -Default $true)
|
|
)
|
|
}
|
|
if ($state -eq "terminal") {
|
|
return (
|
|
[string](Get-PropertyValue -Item $Row -Name "diagnostic_state" -Default "") -eq "last_session_terminal_or_expired" -and
|
|
[int](Get-PropertyValue -Item $Row -Name "active_session_count" -Default -1) -eq 0 -and
|
|
[int](Get-PropertyValue -Item $Row -Name "terminal_session_count" -Default -1) -ge 1 -and
|
|
-not [bool](Get-PropertyValue -Item $Row -Name "no_session_summary_present" -Default $true) -and
|
|
[bool](Get-PropertyValue -Item $Row -Name "terminal_session_summary_present" -Default $false)
|
|
)
|
|
}
|
|
return $false
|
|
}
|
|
|
|
$source = & powershell -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot "c19z32-remote-workspace-readiness-summary-exclusivity-smoke.ps1") `
|
|
-ApiBaseUrl $ApiBaseUrl `
|
|
-ClusterID $ClusterID `
|
|
-ActorUserID $ActorUserID `
|
|
-EntryNodeName $EntryNodeName `
|
|
-ExitNodeName $ExitNodeName `
|
|
-EntryBaseUrl $EntryBaseUrl `
|
|
-ResultPath $sourceResultPath
|
|
|
|
$sourceFile = Join-Path $repoRoot $sourceResultPath
|
|
$sourceResult = Get-Content -Raw -Path $sourceFile | ConvertFrom-Json
|
|
$observed = Get-PropertyValue -Item $sourceResult -Name "observed" -Default $null
|
|
$freshObserved = Get-PropertyValue -Item $observed -Name "fresh" -Default $null
|
|
$activeObserved = Get-PropertyValue -Item $observed -Name "active" -Default $null
|
|
$terminalObserved = Get-PropertyValue -Item $observed -Name "terminal" -Default $null
|
|
|
|
$matrix = @(
|
|
(Select-ReadinessMatrixRow -Observed $freshObserved -State "fresh" -Surface "workload"),
|
|
(Select-ReadinessMatrixRow -Observed $freshObserved -State "fresh" -Surface "telemetry"),
|
|
(Select-ReadinessMatrixRow -Observed $activeObserved -State "active" -Surface "workload"),
|
|
(Select-ReadinessMatrixRow -Observed $activeObserved -State "active" -Surface "telemetry"),
|
|
(Select-ReadinessMatrixRow -Observed $terminalObserved -State "terminal" -Surface "workload"),
|
|
(Select-ReadinessMatrixRow -Observed $terminalObserved -State "terminal" -Surface "telemetry")
|
|
)
|
|
|
|
$checks = [ordered]@{
|
|
source_smoke_passed = ([bool]$sourceResult.passed)
|
|
matrix_row_count = ($matrix.Count -eq 6)
|
|
all_rows_valid = (@($matrix | Where-Object { -not (Test-MatrixRow -Row $_) }).Count -eq 0)
|
|
workload_rows_present = (@($matrix | Where-Object { $_.surface -eq "workload" }).Count -eq 3)
|
|
telemetry_rows_present = (@($matrix | Where-Object { $_.surface -eq "telemetry" }).Count -eq 3)
|
|
}
|
|
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
|
|
|
|
$result = [ordered]@{
|
|
schema_version = "c19z33.remote_workspace_readiness_state_matrix_smoke.v1"
|
|
source_result_path = $sourceFile
|
|
cluster_id = $ClusterID
|
|
entry_node = Get-PropertyValue -Item $sourceResult -Name "entry_node" -Default $null
|
|
adapter_session_id = Get-PropertyValue -Item $sourceResult -Name "adapter_session_id" -Default $null
|
|
matrix_contract = @(
|
|
"state",
|
|
"surface",
|
|
"schema_version",
|
|
"probe_only",
|
|
"payload_traffic",
|
|
"status",
|
|
"diagnostic_state",
|
|
"ready",
|
|
"active_session_count",
|
|
"terminal_session_count",
|
|
"adapter_session_id",
|
|
"last_adapter_session_id",
|
|
"last_session_state",
|
|
"no_session_summary_present",
|
|
"terminal_session_summary_present"
|
|
)
|
|
matrix = $matrix
|
|
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 20 | Set-Content -Encoding UTF8 -Path $fullResultPath
|
|
|
|
if (-not $result.passed) {
|
|
throw "C19Z33 remote workspace readiness state matrix smoke failed. Result: $fullResultPath Failed: $($failed -join ', ')"
|
|
}
|
|
|
|
Write-Host "C19Z33 remote workspace readiness state matrix smoke passed. Result: $fullResultPath"
|
|
$result
|