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:
@@ -327,6 +327,7 @@ try
|
||||
return 0;
|
||||
}
|
||||
if (args[0] != "seed") return 2;
|
||||
var pumpEquipment = new Dictionary<string, string>(StringComparer.Ordinal); // A4: pump equipment name → EquipmentId
|
||||
await using (var db = await factory.CreateDbContextAsync())
|
||||
{
|
||||
if (await db.ServerClusters.AnyAsync()) throw new InvalidOperationException("fixture seed requires empty owned database");
|
||||
@@ -382,6 +383,27 @@ try
|
||||
SourceHash = Convert.ToHexString(System.Security.Cryptography.SHA256.HashData(System.Text.Encoding.UTF8.GetBytes(predicate))) });
|
||||
db.ScriptedAlarms.Add(new() { ScriptedAlarmRowId = Guid.NewGuid(), ScriptedAlarmId = "source-scalar-high", EquipmentId = equipment,
|
||||
Name = "ScalarHigh", AlarmType = "AlarmCondition", MessageTemplate = "scalar high", PredicateScriptId = "source-scalar-high" });
|
||||
// A4 live scenarios (A02/A04): an OpcUaClient driver against the run-owned opc-plc `--alm` container (compose.conditions.yml),
|
||||
// one native alarm tag bound 1:1 to the upstream CONDITION node EastTank?Red (several conditions share the EastTank source,
|
||||
// so the source node would fold them; docs/drivers/OpcUaClient.md "Native alarms"), and a value control tag. The alarm tag is
|
||||
// referenced by two NEW equipment (pumpa, pumpb) so the A2a/A3 smokes' `plc` equipment view is unchanged.
|
||||
db.DriverInstances.Add(new() { DriverInstanceRowId = Guid.NewGuid(), DriverInstanceId = "source-opcua", ClusterId = "SOURCE", Name = "opcua", DriverType = "OpcUaClient",
|
||||
DriverConfig = """{"SecurityPolicy":"None","SecurityMode":"None","AuthType":"Anonymous","AutoAcceptCertificates":true}""" });
|
||||
db.Devices.Add(new() { DeviceRowId = Guid.NewGuid(), DeviceId = "source-opcplc", DriverInstanceId = "source-opcua", Name = "opcplc",
|
||||
DeviceConfig = """{"EndpointUrl":"opc.tcp://opcplc:50000"}""" });
|
||||
db.Tags.Add(new() { TagRowId = Guid.NewGuid(), TagId = "source-opcua-fast", DeviceId = "source-opcplc", Name = "FastUInt1", DataType = "UInt32",
|
||||
AccessLevel = TagAccessLevel.Read, WriteIdempotent = false, TagConfig = """{"nodeId":"ns=3;s=FastUInt1"}""" });
|
||||
db.Tags.Add(new() { TagRowId = Guid.NewGuid(), TagId = "source-opcua-red", DeviceId = "source-opcplc", Name = "EastTankRed", DataType = "Boolean",
|
||||
AccessLevel = TagAccessLevel.Read, WriteIdempotent = false,
|
||||
TagConfig = """{"nodeId":"ns=6;s=1:Colours/EastTank?Red","alarm":{"alarmType":"AlarmCondition","severity":500}}""" });
|
||||
foreach (var pump in new[] { "pumpa", "pumpb" })
|
||||
{
|
||||
var pumpUuid = Guid.NewGuid();
|
||||
var pumpId = DraftValidator.DeriveEquipmentId(pumpUuid);
|
||||
pumpEquipment[pump] = pumpId;
|
||||
db.Equipment.Add(new() { EquipmentRowId = Guid.NewGuid(), EquipmentId = pumpId, EquipmentUuid = pumpUuid, UnsLineId = "source-line", Name = pump, MachineCode = "fixture-" + pump });
|
||||
db.UnsTagReferences.Add(new() { UnsTagReferenceRowId = Guid.NewGuid(), UnsTagReferenceId = "ref-" + pump + "-red", EquipmentId = pumpId, TagId = "source-opcua-red" });
|
||||
}
|
||||
}
|
||||
db.NodeAcls.Add(new() { NodeAclRowId = Guid.NewGuid(), NodeAclId = "source-peer", ClusterId = "SOURCE", Principal = "fixture-consumer",
|
||||
ScopeKind = NodeAclScopeKind.Cluster, PermissionFlags = NodePermissions.Admin });
|
||||
@@ -415,6 +437,31 @@ try
|
||||
db.NodeAcls.Add(new() { NodeAclRowId = Guid.NewGuid(), NodeAclId = "cli-history-map-" + name, ClusterId = "CONSUMER", Principal = "fixture-cli",
|
||||
ScopeKind = NodeAclScopeKind.RemoteNamespaceMapping, ScopeId = "map-" + name, PermissionFlags = NodePermissions.Browse | NodePermissions.HistoryRead });
|
||||
}
|
||||
if (conditions)
|
||||
{
|
||||
// A4: exports + CONSUMER mappings for the native alarm's three placements — the Raw opc-plc device and the two
|
||||
// UNS equipment that reference it (A04: one consumer condition, three notifiers). Distinct branch names.
|
||||
var conditionOps = operations | DataOperationSets.ConditionGrants;
|
||||
foreach (var (id, realm, rootKind, entity, identifier) in new[] {
|
||||
("opc", DataRealm.Raw, "RawDevice", "source-opcplc", "opcua/opcplc"),
|
||||
("pumpa", DataRealm.Uns, "Equipment", pumpEquipment["pumpa"], pumpEquipment["pumpa"]),
|
||||
("pumpb", DataRealm.Uns, "Equipment", pumpEquipment["pumpb"], pumpEquipment["pumpb"]) })
|
||||
{
|
||||
db.DataExports.Add(new() { DataExportRowId = Guid.NewGuid(), DataExportId = "export-" + id, ClusterId = "SOURCE", Enabled = true,
|
||||
Realm = realm, RootKind = rootKind, RootEntityId = entity, PrincipalId = "fixture-consumer", AllowedOperations = conditionOps });
|
||||
db.RemoteNamespaceMappings.Add(new() { RemoteNamespaceMappingRowId = Guid.NewGuid(), RemoteNamespaceMappingId = "map-" + id,
|
||||
ClusterId = "CONSUMER", DataConnectionId = "consumer-source", Enabled = true, ConsumerNodeIds = ["consumer-1:4053", "consumer-2:4053"],
|
||||
Realm = realm, RemoteRealm = realm, LocalParentKind = "Cluster", LocalParentId = "CONSUMER", BranchName = "remote-" + id,
|
||||
RemoteRootEntityId = entity, RemoteNamespaceUri = realm == DataRealm.Raw ? V3NodeIds.RawNamespaceUri : V3NodeIds.UnsNamespaceUri,
|
||||
RemoteIdentifierKind = "string", RemoteIdentifier = identifier, AllowedOperations = conditionOps, WriteThrough = false });
|
||||
}
|
||||
// A04: a UNS-ONLY origin principal (one UNS export, no Raw export) — its condition records must carry no RawPath.
|
||||
db.DataExports.Add(new() { DataExportRowId = Guid.NewGuid(), DataExportId = "export-pumpa-unsonly", ClusterId = "SOURCE", Enabled = true,
|
||||
Realm = DataRealm.Uns, RootKind = "Equipment", RootEntityId = pumpEquipment["pumpa"], PrincipalId = "fixture-unsonly", AllowedOperations = conditionOps });
|
||||
db.NodeAcls.Add(new() { NodeAclRowId = Guid.NewGuid(), NodeAclId = "source-peer-unsonly", ClusterId = "SOURCE", Principal = "fixture-unsonly",
|
||||
ScopeKind = NodeAclScopeKind.Cluster, PermissionFlags = NodePermissions.Admin });
|
||||
// A05: the CONSUMER-local principal `fixture-cli-nogrant` deliberately has NO NodeAcl row (no mapping grant).
|
||||
}
|
||||
if (history)
|
||||
// The second principal's origin ACL also lacks HistoryRead: with its export's HistoryRead off the RPC is refused
|
||||
// (PermissionDenied, like v1 Read); granting the export bit then leaves the per-node ACL denial (BadHistoryOperationUnsupported).
|
||||
@@ -425,6 +472,11 @@ try
|
||||
var seedAdmin = new ApiKeyAdminService(factory, pepper);
|
||||
await SaveText("cli.key", await seedAdmin.CreateAsync("fixture-cli", "fixture-cli", null, "owned local fixture", default));
|
||||
await SaveText("source.key", await seedAdmin.CreateAsync("source-issued-consumer", "fixture-consumer", null, "SOURCE grants for CONSUMER", default));
|
||||
if (conditions)
|
||||
{
|
||||
await SaveText("source-unsonly.key", await seedAdmin.CreateAsync("source-issued-unsonly", "fixture-unsonly", null, "SOURCE UNS-only export (A04)", default));
|
||||
await SaveText("cli-nogrant.key", await seedAdmin.CreateAsync("fixture-cli-nogrant", "fixture-cli-nogrant", null, "CONSUMER principal without a mapping grant (A05)", default));
|
||||
}
|
||||
if (history)
|
||||
await SaveText("source-nohistory.key", await seedAdmin.CreateAsync("source-issued-nohistory", "fixture-nohistory", null, "SOURCE export without HistoryRead", default));
|
||||
string unsBrowseRoot;
|
||||
@@ -433,7 +485,7 @@ try
|
||||
var snapshot = await DraftSnapshotFactory.FromConfigDbAsync(db);
|
||||
var errors = DraftValidator.Validate(snapshot).Concat(snapshot.ServerClusters.SelectMany(cluster => DraftValidator.ValidateClusterTopology(cluster, snapshot.ClusterNodes.Where(node => node.ClusterId == cluster.ClusterId).ToList()))).ToList();
|
||||
if (errors.Count != 0) throw new InvalidOperationException("production validator rejected fixture");
|
||||
unsBrowseRoot = await db.Equipment.Select(item => item.EquipmentId).SingleAsync();
|
||||
unsBrowseRoot = await db.Equipment.Where(item => item.Name == "plc").Select(item => item.EquipmentId).SingleAsync();
|
||||
}
|
||||
await Save("fixture.json", new { connection_id = "consumer-source", mapping_ids = new[] { "map-raw", "map-uns" },
|
||||
namespace_uris = new { raw = V3NodeIds.RawNamespaceUri, uns = V3NodeIds.UnsNamespaceUri, mapped_raw = ProjectedDataIds.RawNamespaceUri, mapped_uns = ProjectedDataIds.UnsNamespaceUri },
|
||||
@@ -441,7 +493,13 @@ try
|
||||
browse_subjects = new { raw = "modbus/plc", uns = "area/line/plc" },
|
||||
origin_paths = new { raw = "modbus/plc/scalar", uns = "area/line/plc/scalar", raw_array = "modbus/plc/vector", uns_array = "area/line/plc/vector", raw_string = "modbus/plc/text", uns_string = "area/line/plc/text" }, aliases = new[] { "raw", "uns" },
|
||||
history = history ? new { historized = new { raw = "modbus/plc/counter", uns = "area/line/plc/counter" }, unhistorized = new { raw = "modbus/plc/scalar", uns = "area/line/plc/scalar" },
|
||||
historized_string = new { raw = "modbus/plc/text", uns = "area/line/plc/text" } } : null });
|
||||
historized_string = new { raw = "modbus/plc/text", uns = "area/line/plc/text" } } : null,
|
||||
// A4 live scenarios: where the native alarm lives (origin RawPath + equipment) and which consumer mappings place it.
|
||||
conditions = conditions ? new { scripted = new { condition = "ScalarHigh", origin_id = "source-scalar-high", mapping = "map-uns", branch = "remote-source" },
|
||||
native = new { condition = "EastTankRed", raw_path = "opcua/opcplc/EastTankRed", upstream = "ns=6;s=1:Colours/EastTank?Red",
|
||||
equipment = pumpEquipment, subjects = new { pumpa = "area/line/pumpa", pumpb = "area/line/pumpb" }, raw_root = "opcua/opcplc",
|
||||
mappings = new { raw = "map-opc", pumpa = "map-pumpa", pumpb = "map-pumpb" },
|
||||
branches = new { raw = "remote-opc", pumpa = "remote-pumpa", pumpb = "remote-pumpb" } } } : null });
|
||||
return 0;
|
||||
}
|
||||
catch (Exception error)
|
||||
|
||||
Reference in New Issue
Block a user