test(grpc-data): A4 live scenarios part 1 harness — run-owned opc-plc --alm, native alarm + 2 referencing equipment + 3 condition mappings, UNS-only origin principal, no-grant consumer principal; probe condition-records; node-probe alert-transitions; conditions_scenarios.py (A01/A02/A04/A05/A08)
This commit is contained in:
@@ -26,7 +26,7 @@ try
|
||||
using var manifest = JsonDocument.Parse(await File.ReadAllTextAsync(manifestPath));
|
||||
var root = manifest.RootElement;
|
||||
var scenario = arguments.GetValueOrDefault("--scenario", "all");
|
||||
if (scenario is not ("all" or "D13" or "wire" or "history" or "conditions")) throw new ArgumentException("Unsupported wire scenario.");
|
||||
if (scenario is not ("all" or "D13" or "wire" or "history" or "conditions" or "condition-records")) throw new ArgumentException("Unsupported wire scenario.");
|
||||
var nodes = root.GetProperty("nodes");
|
||||
var endpoints = root.GetProperty("endpoints");
|
||||
var keyPath = root.GetProperty("credentials").GetProperty("data_key_files").GetProperty("source").GetString()!;
|
||||
@@ -395,7 +395,74 @@ try
|
||||
if (primary && flipped) await SetScalar(150); // restore for the other node
|
||||
}
|
||||
}
|
||||
if (scenario is not ("D13" or "history" or "conditions"))
|
||||
if (scenario == "condition-records")
|
||||
{
|
||||
// A4 (A04): one root-scoped condition item, opened on ONE named SOURCE listener under a NAMED principal's data key
|
||||
// (`--key-name` = a manifest data_key_files alias), returning its complete snapshot records (placements included).
|
||||
// `--forbid` must occur nowhere in the records (a UNS-only principal: no RawPath); `--expect` must occur (positive control).
|
||||
failurePhase = ProbeFailurePhase.WireOperation;
|
||||
var name = arguments["--node"];
|
||||
if (name is not ("source-1" or "source-2")) throw new ArgumentException("SOURCE listener required.");
|
||||
failureTarget = name;
|
||||
var principalKeyPath = root.GetProperty("credentials").GetProperty("data_key_files").GetProperty(arguments["--key-name"]).GetString()!;
|
||||
Restricted(principalKeyPath);
|
||||
var principalKey = (await File.ReadAllTextAsync(principalKeyPath)).Trim();
|
||||
var realmName = arguments["--realm"];
|
||||
var realm = realmName == "raw" ? DataRealm.Raw : realmName == "uns" ? DataRealm.Uns : throw new ArgumentException("realm");
|
||||
var view = new W.View { Address = new() { OriginClusterId = "SOURCE", IdentifierKind = "string", Identifier = arguments["--identifier"],
|
||||
NamespaceUri = root.GetProperty("fixture").GetProperty("namespace_uris").GetProperty(realmName).GetString()! },
|
||||
Realm = (int)realm, Subject = arguments["--subject"] };
|
||||
var nodeId = sourceNodes.Single(item => item.Name == name).Value.GetProperty("node_id").GetString()!;
|
||||
var headers = Headers(principalKey, "Node", nodeId);
|
||||
headers.Add("x-otopcua-data-features", "conditions");
|
||||
using var handler = security.Handler(name);
|
||||
using var channel = GrpcChannel.ForAddress($"https://{name}:4057", new() { HttpHandler = handler });
|
||||
var client = new W.DataConnectionService.DataConnectionServiceClient(channel);
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(45));
|
||||
using var call = client.Subscribe(headers, cancellationToken: cts.Token);
|
||||
var open = new W.SubscriptionCommand { SubscriptionId = "records-" + Guid.NewGuid().ToString("N")[..8], StreamEpoch = 1, CommandId = "open-1",
|
||||
AcknowledgementTimeoutTicks = TimeSpan.FromSeconds(10).Ticks, Open = new() { SessionLifetimeTicks = TimeSpan.FromMinutes(5).Ticks,
|
||||
SnapshotBudget = new() { TimeoutTicks = TimeSpan.FromSeconds(20).Ticks, MaxItems = 64, MaxBytes = 4 * 1024 * 1024 } } };
|
||||
open.Open.Items.Add(new W.SubscriptionItem { ClientItemId = "records", View = view, Settings = new() { Trigger = 2 }, ConditionScope = new() { IncludeInfo = true } });
|
||||
await call.RequestStream.WriteAsync(open);
|
||||
int? ackStatus = null, total = null;
|
||||
var snapshot = new List<W.ConditionState>();
|
||||
var complete = false;
|
||||
string? ended = null;
|
||||
try
|
||||
{
|
||||
while (await call.ResponseStream.MoveNext(cts.Token))
|
||||
{
|
||||
var frame = call.ResponseStream.Current;
|
||||
if (frame.Ack is { } ack) { ackStatus = ack.Items.Single().Status; if (ackStatus != 1) break; continue; }
|
||||
if (frame.ConditionStates is not { IsSnapshot: true } states) continue;
|
||||
if (states.HasTotal) { total = states.Total; snapshot.Clear(); }
|
||||
snapshot.AddRange(states.Items);
|
||||
if (states.SnapshotComplete) { complete = true; break; }
|
||||
}
|
||||
}
|
||||
catch (RpcException error) { ended = error.StatusCode.ToString(); }
|
||||
await cts.CancelAsync();
|
||||
var records = snapshot.Select(r => (object)new
|
||||
{
|
||||
key = r.ConditionKey, r.StateKnown, r.Active, r.Acknowledged, r.Severity, r.Message,
|
||||
info = r.Info is null ? null : new { r.Info.ConditionType, r.Info.ConditionName, r.Info.SourceKind,
|
||||
placements = r.Info.Placements.Select(p => new { realm = p.Realm, ns = p.Address.NamespaceUri, id = p.Address.Identifier, subject = p.Subject }).ToArray() },
|
||||
raw = r.ToString(),
|
||||
}).ToArray();
|
||||
var text = JsonSerializer.Serialize(records);
|
||||
var forbid = arguments.GetValueOrDefault("--forbid");
|
||||
var expect = arguments.GetValueOrDefault("--expect");
|
||||
var forbidden = forbid is not null && text.Contains(forbid, StringComparison.Ordinal);
|
||||
var expected = expect is null || text.Contains(expect, StringComparison.Ordinal);
|
||||
results.Add(new("condition-records-" + name, "condition-records", ackStatus == 1 && complete && snapshot.Count >= 1 && !forbidden && expected, 4, new()
|
||||
{
|
||||
["principal"] = arguments["--key-name"], ["realm"] = realmName, ["subject"] = view.Subject, ["ackStatus"] = ackStatus, ["total"] = total,
|
||||
["snapshotComplete"] = complete, ["ended"] = ended, ["records"] = records, ["forbid"] = forbid, ["forbiddenFound"] = forbidden,
|
||||
["expect"] = expect, ["expectedFound"] = expected,
|
||||
}));
|
||||
}
|
||||
if (scenario is not ("D13" or "history" or "conditions" or "condition-records"))
|
||||
{
|
||||
var fixture = root.GetProperty("fixture");
|
||||
var rawUri = fixture.GetProperty("namespace_uris").GetProperty("raw").GetString()!;
|
||||
|
||||
Reference in New Issue
Block a user