SIENTIAPDE-1163

SIENTIAPDE-1163
Refactor Ingestor and DataManager classes to enhance metadata handling

- Updated Ingestor class to include additional metadata fields: 'workflow_name' and 'schema_name'.
- Modified DataManager to accept metadata during initialization.
- Adjusted unit tests to validate the new metadata structure and ensure proper functionality across various managers.
- Removed unused logger initialization in tests for cleaner code.
This commit is contained in:
vitor-aignosi
2025-07-17 14:27:13 -03:00
parent 1dba4f5604
commit 9309d7591e
7 changed files with 203 additions and 94 deletions

View File

@@ -33,6 +33,15 @@ tags = {
},
}
metadata = {
"metadata": {
"model_id": "test_model",
"model_name": "test_model",
"workflow_name": "test_workflow",
"schema_name": "test_schedule",
},
}
@fixture
def raw_opc_manager():
@@ -44,6 +53,7 @@ def raw_opc_manager():
"opc.tcp://localhost:4840",
MagicMock(),
"localhost",
metadata=metadata["metadata"],
)
@@ -53,6 +63,7 @@ def opc_manager(raw_opc_manager):
raw_opc_manager.cert_path = "cert.pem"
raw_opc_manager.private_key_path = "private_key.pem"
raw_opc_manager.server_cert_path = "server_cert.pem"
raw_opc_manager.send_notification = MagicMock()
return raw_opc_manager
@@ -414,7 +425,6 @@ def test_check_cycles_no_notification(opc_manager):
"cycle_rule": {"cycle_increment": 1.0, "cycle_count": 3.0},
}
}
opc_manager.notification_handler.build_and_send_notification = MagicMock()
opc_manager.check_cycles()
@@ -422,7 +432,7 @@ def test_check_cycles_no_notification(opc_manager):
assert opc_manager.nodes["ns=3;i=1001"]["cycle_rule"][
"cycle_count"
] == pytest.approx(4.0)
opc_manager.notification_handler.build_and_send_notification.assert_not_called()
opc_manager.send_notification.assert_not_called()
def test_check_cycles_triggers_notification(opc_manager):
@@ -441,11 +451,12 @@ def test_check_cycles_triggers_notification(opc_manager):
assert opc_manager.nodes["ns=3;i=1001"]["cycle_rule"][
"cycle_count"
] == pytest.approx(5.5)
opc_manager.notification_handler.build_and_send_notification.assert_called_once_with(
opc_manager.send_notification.assert_called_once_with(
notification_id="TAG_ns=3;i=1001:Counter_LISTENNING_STOPPED",
message="5.5 cycles without receive from ns=3;i=1001:Counter",
block="opc_manager",
level=NotificationLevel.WARNING,
metadata=metadata["metadata"],
)
@@ -473,16 +484,16 @@ def test_check_opc_listenning_no_notification(metrics, opc_manager):
def test_check_opc_listenning_warning_notification(opc_manager):
opc_manager.non_receive_count = 4
opc_manager.notification_handler.build_and_send_notification = MagicMock()
result = opc_manager.check_opc_listenning()
assert opc_manager.non_receive_count == 5
opc_manager.notification_handler.build_and_send_notification.assert_called_once_with(
opc_manager.send_notification.assert_called_once_with(
notification_id=f"OPC_LISTENNING_STOPPED__{opc_manager.name}",
message=f"5 cycles without receive from OPC {opc_manager.name}. Tags: {json.dumps(opc_manager.nodes)}",
block="opc_manager",
level=NotificationLevel.ERROR,
metadata=metadata["metadata"],
)
assert result is False
@@ -498,14 +509,15 @@ def test_check_opc_listenning_error_notification_and_retry(metrics, opc_manager)
assert opc_manager.non_receive_count == 15
# Should be called twice: once for 5, once for 15
assert opc_manager.notification_handler.build_and_send_notification.call_count == 2
calls = opc_manager.notification_handler.build_and_send_notification.call_args_list
assert opc_manager.send_notification.call_count == 2
calls = opc_manager.send_notification.call_args_list
# First call: 5 cycles warning
assert calls[0].kwargs == dict(
notification_id=f"OPC_LISTENNING_STOPPED__{opc_manager.name}",
message=f"15 cycles without receive from OPC {opc_manager.name}. Tags: {json.dumps(opc_manager.nodes)}",
block="opc_manager",
level=NotificationLevel.ERROR,
metadata=metadata["metadata"],
)
# Second call: 15 cycles retry
assert calls[1].kwargs == dict(
@@ -513,6 +525,7 @@ def test_check_opc_listenning_error_notification_and_retry(metrics, opc_manager)
message=f"Retrying to connect to server {opc_manager.name}",
block="opc_manager",
level=NotificationLevel.ERROR,
metadata=metadata["metadata"],
)
assert result is True
@@ -540,6 +553,7 @@ def test_init_metrics_calls_correct_metric_methods(mock_metrics):
server_uri="opc.tcp://init.test:4840/uri",
notification_handler=MagicMock(),
pod_id="init_pod_localhost",
metadata=metadata["metadata"],
)
mock_metrics.OPC_CONNECTION_STATUS.labels.assert_called_once_with(