167 lines
10 KiB
Markdown
167 lines
10 KiB
Markdown
# 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:
|
||
|
||
```bash
|
||
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.
|
||
|
||
## 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:
|
||
|
||
```bash
|
||
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.
|