SIENTIAPDE-1974: feat(read): slot v2 reads via SubscriptionEngine, OPC cert from MinIO
Swaps the legacy OpcManager read path for the gateway's SubscriptionEngine over the shared OpcConnectionPool. The OPC client certificate now always comes from MinIO + Mongo (CertProvider, Basic256Sha256) — no more certs/ shipped in the Gitea repository, so a new version branch no longer breaks the reads. - io/slots.py: parse_slot accepts slot v2 (names[]) and converts the legacy v1 (tag_name + topics; cert_path => use_security, path dropped), so gateway and Orchestrator can be deployed in any order. - managers/server_reader.py: new per-server reader with the OpcManager interface the IngestorManager already drives (connect, create_subscription, subscribe, unsubscribe, check_cycles, check_opc_listenning, shutdown). - IngestorManager owns the read path: lazy-MinIO CertProvider, the pool and a read DataSink, built without touching the network. Slots from Redis are normalized on lease and refresh; a malformed slot is notified and the last good config is kept. - GatewayRuntime borrows the pool (writes/gRPC) instead of building it, and no longer closes it on stop: a Postgres/NATS failure can't stop the reads. - pool: pin/unpin per active subscription so release_idle never evicts a subscribed connection; public evict() for lost servers / changed config. - SubscriptionEngine pins on subscribe, unpins on unsubscribe, and drops a subscription locally even when the server-side delete fails. - DataSink: model_id only written when the name has one, keeping v1 documents identical to the legacy ones. - config: CERT_BUCKET default is the legacy streamlit-connectors bucket (D7). - Removes OpcManager, its tests and scripts/generate-and-push-opc-cert.sh; README/CLAUDE.md document the MinIO certificate and the slot v2 format. Tests: 218 unit tests pass; ruff check/format clean. Local end-to-end against an asyncua server: v1 slot with two topics -> one doc per collection, legacy doc shape, idle sweep keeps the subscription, lost-server shutdown and re-initialization work. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -201,3 +201,57 @@ async def test_check_opc_listenning_triggers_reconnect_at_15():
|
||||
|
||||
assert result is True
|
||||
assert eng.send_notification_async.call_count == 2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_subscription_pins_pool_connection():
|
||||
eng = make_engine()
|
||||
eng.pool = MagicMock(get=AsyncMock(return_value=AsyncMock()))
|
||||
|
||||
await eng.create_subscription('1', {'subscription_period_ms': 500}, 'slot1')
|
||||
|
||||
eng.pool.pin.assert_called_once_with('1')
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_subscription_failure_does_not_pin():
|
||||
eng = make_engine()
|
||||
client = AsyncMock()
|
||||
client.create_subscription.side_effect = RuntimeError('boom')
|
||||
eng.pool = MagicMock(get=AsyncMock(return_value=client))
|
||||
|
||||
with pytest.raises(RuntimeError):
|
||||
await eng.create_subscription('1', {'subscription_period_ms': 500}, 'slot1')
|
||||
|
||||
eng.pool.pin.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_unsubscribe_unpins_pool_connection():
|
||||
eng = make_engine()
|
||||
eng.pool = MagicMock(get=AsyncMock(return_value=AsyncMock()))
|
||||
await eng.create_subscription('1', {'subscription_period_ms': 500}, 'slot1')
|
||||
|
||||
await eng.unsubscribe('slot1')
|
||||
|
||||
eng.pool.unpin.assert_called_once_with('1')
|
||||
assert 'slot1' not in eng.subscriptions
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_unsubscribe_tolerates_dead_connection():
|
||||
"""A lost server's subscription can't be deleted on the server side; it must
|
||||
still be dropped locally (and unpinned) so the slot can be re-subscribed."""
|
||||
eng = make_engine()
|
||||
sub = AsyncMock()
|
||||
sub.delete.side_effect = ConnectionError('closed')
|
||||
client = AsyncMock()
|
||||
client.create_subscription.return_value = sub
|
||||
eng.pool = MagicMock(get=AsyncMock(return_value=client))
|
||||
await eng.create_subscription('1', {'subscription_period_ms': 500}, 'slot1')
|
||||
|
||||
await eng.unsubscribe('slot1') # must not raise
|
||||
|
||||
assert 'slot1' not in eng.subscriptions
|
||||
eng.pool.unpin.assert_called_once_with('1')
|
||||
eng.logger.warning.assert_called_once()
|
||||
|
||||
Reference in New Issue
Block a user