1
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
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\c19z37-remote-workspace-real-adapter-config-projection-smoke-result.json"
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).ProviderPath
|
||||
$forbiddenProjectionFields = @("command", "args_json", "workdir", "command_path", "raw_command", "raw_args_json", "raw_workdir")
|
||||
|
||||
function Invoke-Api {
|
||||
param([string]$Method, [string]$Path)
|
||||
return Invoke-RestMethod -Method $Method -Uri "$ApiBaseUrl$Path" -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 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-RdpWorkerStatus {
|
||||
param([string]$NodeID)
|
||||
$statuses = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/nodes/$NodeID/workloads/status?actor_user_id=$ActorUserID").workload_statuses
|
||||
return @($statuses | Where-Object { $_.service_type -eq "rdp-worker" } | Select-Object -First 1)
|
||||
}
|
||||
|
||||
function Test-NoRawProjectionFields {
|
||||
param([object]$Projection)
|
||||
if ($null -eq $Projection) { return $false }
|
||||
foreach ($field in $forbiddenProjectionFields) {
|
||||
if ($null -ne $Projection.PSObject.Properties[$field]) { return $false }
|
||||
}
|
||||
return $true
|
||||
}
|
||||
|
||||
function Test-ConfigProjection {
|
||||
param([object]$Status)
|
||||
if ($null -eq $Status) { return $false }
|
||||
$payload = Get-PropertyValue -Item $Status -Name "status_payload" -Default $null
|
||||
$contract = Get-PropertyValue -Item $payload -Name "real_adapter_supervision" -Default $null
|
||||
$projection = Get-PropertyValue -Item $contract -Name "config_projection" -Default $null
|
||||
if ($null -eq $projection) { return $false }
|
||||
return (
|
||||
[string](Get-PropertyValue -Item $payload -Name "execution_mode" -Default "") -eq "contract_probe" -and
|
||||
[string](Get-PropertyValue -Item $payload -Name "traffic" -Default "") -eq "none" -and
|
||||
[string](Get-PropertyValue -Item $contract -Name "schema_version" -Default "") -eq "rap.remote_workspace_real_adapter_supervision.v1" -and
|
||||
-not [bool](Get-PropertyValue -Item $contract -Name "enabled" -Default $true) -and
|
||||
[string](Get-PropertyValue -Item $contract -Name "activation_state" -Default "") -eq "disabled_until_real_runtime_stage" -and
|
||||
[string](Get-PropertyValue -Item $contract -Name "payload_traffic" -Default "") -eq "none" -and
|
||||
[string](Get-PropertyValue -Item $projection -Name "schema_version" -Default "") -eq "rap.remote_workspace_real_adapter_config_projection.v1" -and
|
||||
[bool](Get-PropertyValue -Item $projection -Name "enabled_requested" -Default $false) -and
|
||||
-not [bool](Get-PropertyValue -Item $projection -Name "activation_allowed" -Default $true) -and
|
||||
[bool](Get-PropertyValue -Item $projection -Name "command_present" -Default $false) -and
|
||||
[bool](Get-PropertyValue -Item $projection -Name "args_json_present" -Default $false) -and
|
||||
[string](Get-PropertyValue -Item $projection -Name "args_json_shape" -Default "") -eq "json_array" -and
|
||||
[bool](Get-PropertyValue -Item $projection -Name "workdir_present" -Default $false) -and
|
||||
[bool](Get-PropertyValue -Item $projection -Name "raw_values_redacted" -Default $false) -and
|
||||
(Test-NoRawProjectionFields -Projection $projection)
|
||||
)
|
||||
}
|
||||
|
||||
$entryNode = Get-NodeByName -Name $EntryNodeName
|
||||
$status = $null
|
||||
$deadline = (Get-Date).AddSeconds(70)
|
||||
while ((Get-Date) -lt $deadline) {
|
||||
Start-Sleep -Seconds 5
|
||||
$status = Get-RdpWorkerStatus -NodeID $entryNode.id
|
||||
if (Test-ConfigProjection -Status $status) { break }
|
||||
}
|
||||
if ($null -eq $status) {
|
||||
$status = Get-RdpWorkerStatus -NodeID $entryNode.id
|
||||
}
|
||||
|
||||
$payload = Get-PropertyValue -Item $status -Name "status_payload" -Default $null
|
||||
$contract = Get-PropertyValue -Item $payload -Name "real_adapter_supervision" -Default $null
|
||||
$projection = Get-PropertyValue -Item $contract -Name "config_projection" -Default $null
|
||||
|
||||
$checks = [ordered]@{
|
||||
rdp_worker_status_present = ($null -ne $status)
|
||||
contract_probe_remains_active = ([string](Get-PropertyValue -Item $payload -Name "execution_mode" -Default "") -eq "contract_probe")
|
||||
real_adapter_stays_disabled = (-not [bool](Get-PropertyValue -Item $contract -Name "enabled" -Default $true))
|
||||
payload_traffic_none = ([string](Get-PropertyValue -Item $contract -Name "payload_traffic" -Default "") -eq "none")
|
||||
config_projection_visible = ($null -ne $projection)
|
||||
enabled_request_projected = ([bool](Get-PropertyValue -Item $projection -Name "enabled_requested" -Default $false))
|
||||
activation_still_blocked = (-not [bool](Get-PropertyValue -Item $projection -Name "activation_allowed" -Default $true))
|
||||
command_presence_projected = ([bool](Get-PropertyValue -Item $projection -Name "command_present" -Default $false))
|
||||
args_presence_projected = ([bool](Get-PropertyValue -Item $projection -Name "args_json_present" -Default $false))
|
||||
args_shape_projected = ([string](Get-PropertyValue -Item $projection -Name "args_json_shape" -Default "") -eq "json_array")
|
||||
workdir_presence_projected = ([bool](Get-PropertyValue -Item $projection -Name "workdir_present" -Default $false))
|
||||
raw_values_redacted = ([bool](Get-PropertyValue -Item $projection -Name "raw_values_redacted" -Default $false) -and (Test-NoRawProjectionFields -Projection $projection))
|
||||
projection_contract_passed = (Test-ConfigProjection -Status $status)
|
||||
}
|
||||
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
|
||||
|
||||
$result = [ordered]@{
|
||||
schema_version = "c19z37.remote_workspace_real_adapter_config_projection_smoke.v1"
|
||||
cluster_id = $ClusterID
|
||||
entry_node = [ordered]@{ id = $entryNode.id; name = $entryNode.name }
|
||||
forbidden_projection_fields = $forbiddenProjectionFields
|
||||
real_adapter_supervision = $contract
|
||||
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 "C19Z37 remote workspace real-adapter config projection smoke failed. Result: $fullResultPath Failed: $($failed -join ', ')"
|
||||
}
|
||||
|
||||
Write-Host "C19Z37 remote workspace real-adapter config projection smoke passed. Result: $fullResultPath"
|
||||
$result
|
||||
Reference in New Issue
Block a user