test: validate grpc data connections with local docker and opcua cli
This commit is contained in:
@@ -1,71 +1,166 @@
|
||||
# gRPC data local fixture scaffold
|
||||
# Standalone gRPC data integration rig
|
||||
|
||||
This directory contains the **preparation** for the P10 gate. The standalone
|
||||
Compose file describes six Host processes in three independent two-node pairs:
|
||||
CONTROL (admin and deployment), SOURCE, and CONSUMER. Each process has its own
|
||||
LocalDb/secrets volume. SOURCE and CONSUMER have pair-local LocalDb replication.
|
||||
The SQL Server and Modbus simulator are run-local services; exposed host ports
|
||||
use Docker's dynamic allocation on `127.0.0.1`.
|
||||
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.
|
||||
|
||||
The fixture is **not ready for integration execution**. P07's dedicated TLS
|
||||
listener, client trust options, target-issued credential provisioner, and
|
||||
production seeding/deployment path are still in progress. The certificate
|
||||
mounts reserve `/run/grpc-data/tls` on the four data nodes, but no guessed P07
|
||||
option names or TLS activation are included. The existing `rig.py` currently
|
||||
provides pure safety/polling boundaries, not `up`, `seed`, or `deploy` behavior.
|
||||
The presence of this Compose file does not establish a healthy cluster, a
|
||||
deployed catalog, or passing D01–D14 scenarios.
|
||||
From the repository root:
|
||||
|
||||
## Run-owned inputs for later rig integration
|
||||
```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
|
||||
```
|
||||
|
||||
The future `rig.py up` must generate a restricted run directory and inject all
|
||||
required Compose variables. `GRPC_DATA_PROJECT`, `GRPC_DATA_RUN_ID`,
|
||||
`GRPC_DATA_IMAGE`, `GRPC_DATA_MIGRATOR_IMAGE`, and `GRPC_DATA_DEVICE_IMAGE` must
|
||||
identify the run uniquely. `SOURCE_REVISION` must be the current source SHA,
|
||||
including a dirty marker when applicable. `GRPC_DATA_CERT_DIR` must contain
|
||||
per-node SAN certificates and private keys under `source-1`, `source-2`,
|
||||
`consumer-1`, and `consumer-2`; their common trust material belongs in the same
|
||||
restricted run directory. The rig must generate `GRPC_DATA_SQL_PASSWORD`,
|
||||
`GRPC_DATA_APIKEY_PEPPER`, `GRPC_DATA_JWT_KEY`, `GRPC_DATA_DEPLOY_KEY`,
|
||||
`GRPC_DATA_SECRETS_KEK`, `GRPC_DATA_CONFIG_KEY`, `GRPC_DATA_TELEMETRY_KEY`,
|
||||
three `GRPC_DATA_MESH_PSK_*` values, and both `GRPC_DATA_SYNC_KEY_*` values.
|
||||
None has a tracked default. The rig should pass them from a `0600` environment
|
||||
file without writing values to logs or a public manifest.
|
||||
`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.
|
||||
|
||||
The current Compose image build follows the repository's Host publish graph and
|
||||
requires a nonempty `SourceRevisionId`. The future coordinator must build the
|
||||
runtime and migrator images for the current checkout before starting nodes,
|
||||
inspect Docker's allocated loopback ports, and record the exact run-owned
|
||||
resource IDs and labels. A separate production-path seeder must create the
|
||||
CONTROL/SOURCE/CONSUMER cluster rows, author source and mapping configuration,
|
||||
provision every eligible consumer, and deploy through `/api/deployments` before
|
||||
any readiness or CLI assertion is meaningful. No node should use a shared-host
|
||||
endpoint or another node's OPC UA endpoint as its source driver.
|
||||
`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
|
||||
|
||||
`device/server.py` uses the Python standard library. Modbus TCP unit 1 listens
|
||||
on container port 5020. Holding register 0 is a counter changed only by the
|
||||
fixture control action `{"action":"advance","steps":N}` (1–1000). Registers
|
||||
10–12 start at `[7, 11, 13]`; registers 20–63 are writable uint16 values.
|
||||
FC03/FC04 reads and FC06/FC16 writes are supported. Unmapped spans return
|
||||
exception 02, malformed values/counts return 03, and unsupported functions
|
||||
(including FC23) return 01 so callers can retry using FC16. The fixture's
|
||||
unknown-unit policy returns target-unavailable exception 0B with the unit echoed.
|
||||
Validly framed refusals keep the stream open; invalid MBAP framing closes it.
|
||||
Total requests, read attempts (including refusals), rejected writes, and committed
|
||||
effects have separate bounded ledgers with monotonic totals. Records contain
|
||||
structural numeric metadata and bounded fixture write values, never raw payloads.
|
||||
Invalid/truncated frames count as requests; clean stream EOF does not. Read and
|
||||
rejected-write records share the total-request sequence. The HTTP control
|
||||
listener on container port 8080 offers `GET /state` and `POST /control`, with
|
||||
`advance`, bounded `set`, and `drop_next_write_response` actions. The last
|
||||
action closes one Modbus write connection after applying and recording the
|
||||
effect, so D08 can distinguish an ambiguous response from a second effect.
|
||||
The control listener is fixture-only and its allocated host port is loopback
|
||||
bound; it must never be wired into the production Host.
|
||||
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.
|
||||
|
||||
Unit tests in `tests/test_device.py`, `tests/test_device_wire.py`, and
|
||||
`tests/test_compose_fixture.py` are pure. The wire tests drive the actual handler
|
||||
through memory streams. They do not start a socket, container, migration, or
|
||||
network client.
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user