Files
lmxopcua/scripts/validation/grpc-data/README.md
T

18 KiB
Raw Blame History

Standalone gRPC data integration rig

This fixture builds the current checkout and runs six Host processes in three independent Akka pairs: CONTROL, SOURCE and CONSUMER. Its SQL Server, writable Modbus device, private CA, images, network, volumes and secrets belong to one explicit run. It never inherits docker-dev configuration. Run it against a local Unix Docker socket or Windows named pipe; SSH and TCP contexts are rejected. Docker and .NET 10 must be installed. SQL Server uses Docker's amd64 emulation on ARM hosts. openssl is required for the ephemeral CA and service SAN certificates.

From the repository root:

python3 scripts/validation/grpc-data/rig.py preflight
python3 scripts/validation/grpc-data/rig.py up --run-id grpc-data-local
python3 scripts/validation/grpc-data/rig.py seed --run-id grpc-data-local
python3 scripts/validation/grpc-data/rig.py deploy --run-id grpc-data-local
python3 scripts/validation/grpc-data/rig.py status --run-id grpc-data-local
python3 scripts/validation/grpc-data/rig.py down --run-id grpc-data-local

up generates restricted run files, validates resolved Compose endpoints, builds run-specific images, applies EF migrations to the owned SQL container, starts the pairs and waits for ready health plus exactly one active role per pair. Docker allocates every published port on 127.0.0.1; the manifest records the actual bindings. Each node has a separate persistent LocalDb/secrets volume. SOURCE and CONSUMER use pair-local LocalDb sync. LDAP is disabled through its actual startup option and the local machine deploy API requires a generated key.

seed uses the production EF model, ApiKeyAdminService, DraftValidator and cluster topology validator. SOURCE gets a local Modbus driver, Raw tags and UNS references to those same tags, export grants and a target-issued data key. CONSUMER gets a scoped outbound connection and both realm mappings. No source uses another Host's OPC UA endpoint as a driver. Data keys and the CLI key are written directly to restricted files, never printed or put in the manifest.

deploy sends only {"createdBy":"grpc-data-local-gate"} to the normal machine API. Its acceptance callback reads the exact GZip deployment artifact and scope version, then atomically provisions each node's actual credential/trust bundle. The Host's P07 loader imports those files into its encrypted local store. The gate follows the returned Location and requires the same revision and a successful apply outcome on every intended node. It rejects degraded outcomes, unexpected nodes, duplicate nodes, remote redirects and in-flight triggers. It also waits for each required data node to acknowledge the exact committed credential and trust scope/entry versions. Pending durable retirement or notification work cannot satisfy this barrier; its observations contain numeric versions and state flags, without secret payloads. After an owned restart, the harness re-inspects the affected nodes' actual loopback ports and updates the manifest before reconnecting. Finally, real Client.Shared OPC UA sessions read NamespaceArray, verify expected application identities, browse the deployed trees and resolve/read fixture leaves. This avoids assuming namespace indexes. A run becomes ready only after these checks. Readiness does not stand in for the D01–D14 scenario evidence.

Mapped positive CLI reads use --max-age 5000 and retry only an explicit BadWaitingForInitialData response within the scenario deadline. The CLI default remains zero, which schedules asynchronous refresh rather than waiting under the SDK lock. Read and subscription timestamps retain the SDK timestamp's full UTC precision. Every running Host build stamp is checked against the recorded compiled-input hash before scenario mutations; published tools record their own binary hash and the same source identity. The Modbus device image has a separate hash over its protocol/ledger source and Dockerfile, checked against the running container before scenarios or workloads.

The restricted manifest is artifacts/grpc-data/runs/<run-id>/manifest.json (schema version 1). It contains:

  • endpoints: keys such as source-1.data, consumer-1.opcua, control-1.admin, device.modbus and device.control. Every row records scheme, host/container host, host/container port and the allocated loopback URL.
  • nodes: service names mapped to cluster, node_id (source-1:4053) and unique application URI. deployment records the exact ID, hash, scope and node outcomes.
  • tls.ca_file, credentials.cli_key_file, credentials.data_key_files.source and node_probe_dirs: paths only. Presented secrets remain in 0600 files.
  • fixture.namespace_uris, fixture.origin_paths and resolved_nodes: canonical URI identities, source Raw/UNS aliases and per-node resolved NodeIds.
  • resources: exact Docker object IDs and exact run/project labels. Both the Git revision and a SHA256 of actual checkout file contents are recorded; the image also contains /app/grpc-data-source.json, so pending source changes are covered.

down refreshes the exact run-label inventory, verifies labels again, and removes only those exact container/network/volume/image IDs. It never calls Compose down, prune or prefix-based deletion. Interrupted setup leaves a restricted ownership journal that enables the same cleanup. Run files are retained for evidence; use a new run ID for another run.

H2 history profile (opt-in)

rig.py up --run-id <id> --history adds compose.history.yml. SOURCE gets a SqlServer historian (schema hist in the run's SQL container) and continuous historization. The seeder's history profile historizes Raw counter, adds HistoryRead to the consumer's connection and exports, and seeds a second principal fixture-nohistory. That principal gets its own key (credentials.data_key_files.source_nohistory), exports without HistoryRead and an origin ACL without HistoryRead. python3 scripts/validation/grpc-data/history_smoke.py --run-id <id> runs the H2 smoke. It advances the counter, then exercises the probe's --scenario history origin RPCs, the CLI historyread and the CONSUMER history node-probe operation, and checks value parity. Without --history the rig, the seed and every D-scenario are unchanged.

A2a conditions profile (opt-in)

rig.py up --run-id <id> --conditions adds compose.conditions.yml: the seeder grants AlarmSubscribe on both SOURCE exports and adds one scripted alarm, ScalarHigh (modbus/plc/scalar > 100), on the SOURCE equipment. The dev DataConnections__ConditionKeySecret is already set on both source-* services. python3 scripts/validation/grpc-data/conditions_smoke.py --run-id <id> raises the alarm through the device control API (register 20 := 150), then runs the probe's --scenario conditions on both SOURCE listeners: the Primary must stream a snapshot (total, the active record, snapshot_complete) and, after the probe clears the alarm, a delta; the Secondary must refuse the condition item (Unavailable, Primary-only). Without --conditions the rig, the seed and every D-scenario are unchanged.

A4 live scenarios (part 1). The conditions profile also starts a run-owned opcplc container (opc-plc:2.14.10 --alm, no published port; the rig's endpoint guard admits run-owned service DNS only, so the shared 10.100.0.35:50000 fixture is not used) and seeds a SOURCE OpcUaClient driver opcua → device opcplc with a native alarm tag EastTankYellow (nodeId = the upstream condition node ns=6;s=1:Colours/EastTank?Yellow, which cycles Active/Inactive by itself) plus a FastUInt1 value tag; two equipment pumpa/pumpb reference the alarm tag; exports + CONSUMER mappings map-opc (Raw), map-pumpa, map-pumpb (UNS) place it three times; an origin principal fixture-unsonly holds one UNS export only; a CONSUMER principal fixture-cli-nogrant has no NodeAcl row. python3 scripts/validation/grpc-data/conditions_scenarios.py --run-id <id> [--only A01,A02,A04,A05,A08] runs the scenarios (results evidence/A4S-<id>.json, A4S-results.{json,md}); see docs/plans/evidence/grpc-data-ext/A4.md "Live scenarios (part 1)". conditions_a3_smoke.py still passes on this profile. --only A09 (#927) is the driver-failure ack revert: it docker compose pauses the run-owned opcplc just before a remote ack of EastTankYellow, so the OpcUaClient driver's upstream Acknowledge times out and DriverHostActor reverts the condition; it unpauses in its own finally (and again in the per-scenario restore). See docs/plans/evidence/grpc-data-ext/A3-927.md.

H3 projected-history gate (opt-in)

rig.py up --run-id <id> --history [--history-backend sqlserver|questdb] — questdb layers compose.history.questdb.yml: SOURCE historizes into a run-owned QuestDB container (labelled, removed by down) instead of the run's SQL container. The H3 seed profile also: grants HistoryRead on both mappings; gives the CLI principal its CONSUMER HistoryRead only through RemoteNamespaceMapping-scoped grants (cli-history-map-raw|uns; the cluster grant is Admin minus HistoryRead); historizes text (a String node, for the per-type aggregate refusal); and accepts the mutation acl_permissions: {node_acl_id, permission_flags} (one ACL row's flags; the baseline restore reverts it).

python3 scripts/validation/grpc-data/rig.py up --run-id h3-sql --history --timeout 900
python3 scripts/validation/grpc-data/rig.py seed --run-id h3-sql
sleep 75   # CONTROL's ClusterNode contact refresh before the first deploy
python3 scripts/validation/grpc-data/rig.py deploy --run-id h3-sql --timeout 300
python3 scripts/validation/grpc-data/history_gate.py --run-id h3-sql          # H01..H06, or --scenario H04
python3 scripts/validation/grpc-data/rig.py down --run-id h3-sql

history_gate.py accumulates counter history, resolves the projected NodeIds by a CLI browse from the shared root (leaves under the remote-source anchors; never constructed p1. ids), then runs each scenarios.json → history_scenarios row through the Client CLI historyread on CONSUMER and compares with the same read on the SOURCE primary. The continuation scenarios use the CLI's hand-paged mode (--page-size, --pause-after-page, --abandon-after-page, --held-marker-file); the origin's open continuations come from the topology node probe (originAccounting.historyOpenContinuations). Every scenario restores the baseline. Results: evidence/H3-history-<backend>-results.json.

Pinned pre-H2 SOURCE — H05 against a real v1 origin (#921, opt-in)

rig.py up --run-id <id> --history --source-revision 0c86edc1 builds the SOURCE pair from a pinned commit; CONTROL and CONSUMER stay on this checkout. The revision must contain X0 (a15912539, tolerant readers — a pre-X0 node rejects the whole data-connection snapshot once a newer bit is authored) and must not contain H2 (ef938b435); its data_connection.proto must have no HistoryRead RPC. 0c86edc1 (the #918 merge, between H1 and H2) passes. The rig git archives that commit into the run folder (pinned-source/), copies in one rig file — node-probe/WireTap.cs, ASP.NET Core only — and builds it with the pinned tree's own Dockerfile (compose.source-pinned.yml, image otopcua-grpc-data-source-pinned:<run-id>, run-labelled, removed by down). The manifest records source_pinned (revision, export hash); verify_candidate checks the SOURCE stamps against it and the export against its recorded hash, and everything else against this checkout.

The wire tap (GRPC_DATA_WIRE_TAP=1, set only by that overlay) appends to the node's restricted probe directory (probe/source-N/wire-tap.jsonl) one line per data-listener request at arrival (gRPC path, x-otopcua-data-features value, remote address) and one at completion (gRPC status). No credential or body is recorded.

python3 scripts/validation/grpc-data/rig.py up --run-id h05v1 --history --source-revision 0c86edc1 --timeout 1500
python3 scripts/validation/grpc-data/rig.py seed --run-id h05v1
sleep 75
python3 scripts/validation/grpc-data/rig.py deploy --run-id h05v1 --timeout 300
python3 scripts/validation/grpc-data/history_v1_origin_gate.py --run-id h05v1     # evidence/H05V1-results.json
python3 scripts/validation/grpc-data/rig.py down --run-id h05v1

history_v1_origin_gate.py asserts the plan §4.3 row "new consumer → v1 origin": projected counter (Raw and UNS) Historizing False and no HistoryRead AccessLevel bit (Client.CLI read --attribute), historyread ⇒ BadHistoryOperationUnsupported, the consumer page "Negotiated features none (v1 behaviour) · origin history not advertised", and — from the tap — no consumer call but the capability probe carries the feature header and no HistoryRead/CallConditionMethod reaches the origin. Controls: the origin's own counter is historizing and its historyread returns rows; the consumer's v1 calls are in the same tap window; the probe's --scenario history-v1-origin sends new-shape calls (capabilities with the header are byte-identical to without; HistoryRead ⇒ UNIMPLEMENTED) and the tap records them.

Scenario authoring and node probes

The seeder is available through LocalRig.seed_helper(action, *arguments). Its snapshot action writes a restricted seed/baseline.json and baseline presented key; restore restores mutable fixture rows transactionally through EF and production validation, then restores key enabled state through ApiKeyAdminService. Call normal deploy after authoring changes. scope <deployment-id> <revision> reads the exact artifact; resolve writes seed/resolved.json from real sessions.

For mutate, atomically write seed/mutation.json and invoke seed_helper("mutate"). Supported snake_case fields are connection_id (default consumer-source), target_mode (Node/Cluster), target_node_id, consistency, consumer_node_ids, connection_enabled, connection_allowed_operations, mapping_enabled, write_through, allowed_operations (mapping operations), export_enabled, export_allowed_operations, source_redundancy_mode, consumer_redundancy_mode, rename_tag: {tag_id,name}, disable_feature, key_action (rotate, rotate_staged, retire_old, revoke, expire) and key_expiry_seconds. upsert_connection, upsert_mapping, upsert_export and upsert_tag accept the corresponding production entity's PascalCase JSON fields, with numeric enum values; remove_mapping_id deletes an authored mapping; remove_tag_id removes a tag and its UNS references. Unknown mutation fields are rejected. Validator refusals write stable codes to restricted seed/rejection.json and roll back the EF transaction. All authored gRPC endpoints must name a run-owned service over HTTPS. Mutations use an EF transaction and the production validator. A scope/key change still requires deployment and local bundle publication; neither a SQL row nor a mutation return code makes it active.

For negative scenarios call deploy(require_catalog=False) after normal authoring and deployment, then assert the expected closed capability/read behavior through the real probe. credential_action(action, node=None) accepts remove_consumer_secret, provision_consumer_secret and reload_stale_bundle. It publishes actual P07 tombstones or active bundles; omitting the node targets both consumers. Bundle generation high-watermarks survive stale-file replay. trust_action("stage_new"), trust_action("rotate_server") and trust_action("retire_old") implement a second local CA, overlapping trust, actual service certificate replacement/restarts and retirement. restore_security() restores original certificates/CA after baseline authoring restore; the next normal deployment provisions its authoritative scope. These controls publish changes; scenario assertions still wait for and inspect actual runtime behavior.

D07 restores the maintenance flag in SQL before allowing 65 seconds for CONTROL to refresh its dispatch targets. It then issues one normal baseline deployment and verifies all six acknowledgements and the baseline catalog. The wait is part of teardown and does not extend D07's live failover observation.

Only this Dockerfile packages the rig-only GrpcDataNodeProbe hosting-startup assembly, and only this Compose file enables it. Per-node restricted mounted command directories allow the scenario runner to call the actual Host caller DI graph. The ordinary Host image/configuration does not enable this fixture.

Device fixture

The standard-library Python fixture listens on Modbus TCP unit 1, container port 5020. Holding register 0 is a deterministic counter; 10–12 start at [7,11,13]; 20–63 are writable uint16 registers. Raw/UNS scalar both reach register 20; counter reaches 0 and array0–array2 expose the fixed samples as individual scalar registers. No unsupported array representation is invented by the seeder. FC03/FC04 reads and FC06/FC16 writes are supported. Unmapped spans return exception 02, malformed values/counts 03, unsupported functions 01 and unknown units 0B.

The fixture-only HTTP API on container port 8080 has GET /state and POST /control. Actions are {"action":"advance","steps":1}, {"action":"set","address":20,"value":42}, and {"action":"drop_next_write_response"}. The last commits and records one write before closing its response connection. Bounded ledgers distinguish total requests, read attempts, rejected writes and committed effects. The control API is never registered in production Host.

Focused verification

The coordinator runs these commands; they do not bring up Docker:

python3 -m unittest discover -s scripts/validation/grpc-data/tests -p 'test_rig.py'
python3 -m unittest discover -s scripts/validation/grpc-data/tests -p 'test_credentials.py'
python3 -m unittest discover -s scripts/validation/grpc-data/tests -p 'test_compose_fixture.py'
python3 -m unittest discover -s scripts/validation/grpc-data/tests -p 'test_device.py'
python3 -m unittest discover -s scripts/validation/grpc-data/tests -p 'test_device_wire.py'

C# seed/probe compilation and actual migrations, deploys, TLS and scenario runs are integration checks. A checked-in fixture implementation is not passing evidence.