From fc1cd056afa658fbbde977837a57f3ae89b22066 Mon Sep 17 00:00:00 2001 From: vitor-aignosi Date: Wed, 11 Jun 2025 17:55:27 -0300 Subject: [PATCH 1/7] Refactor error handling in Gates and OPC activities; update OPC_NAME to OPC_ID in values.yaml --- laborious/activities/gates.py | 7 +++++-- laborious/activities/opc.py | 2 +- values.yaml | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/laborious/activities/gates.py b/laborious/activities/gates.py index 4b183a0..9d1b252 100644 --- a/laborious/activities/gates.py +++ b/laborious/activities/gates.py @@ -94,6 +94,7 @@ class Gates(BaseActivity): level=NotificationLevel.ERROR, attachment_content=trace ) + raise e for path_flag in path_priority: if path_flag in filter_output: @@ -157,6 +158,7 @@ class Gates(BaseActivity): level=NotificationLevel.ERROR, attachment_content=trace ) + raise e for path_flag in path_priority: if path_flag in filter_output: @@ -218,6 +220,7 @@ class Gates(BaseActivity): level=NotificationLevel.ERROR, attachment_content=trace ) + raise e for path_flag in path_priority: if path_flag in filter_output: @@ -229,7 +232,7 @@ class Gates(BaseActivity): return None, 0, "" @activity.defn(name="format_prediction") - async def format_prediction(self, input_data: dict[str, Any]) -> dict[str, Any]: + async def format_prediction(self, input_data: dict[str, Any]) -> dict[Any, Any]: """ Formats the prediction data. Args: @@ -254,7 +257,7 @@ class Gates(BaseActivity): return data.to_dict() @activity.defn(name="format_default_prediction") - async def format_default_prediction(self, input_data: dict[str, Any]) -> dict[str, Any]: + async def format_default_prediction(self, input_data: dict[str, Any]) -> dict[Any, Any]: """ Creates and formats the default prediction data, with zero value in prediction, and usefull information in the other fields. diff --git a/laborious/activities/opc.py b/laborious/activities/opc.py index 11cd77c..ee3b905 100644 --- a/laborious/activities/opc.py +++ b/laborious/activities/opc.py @@ -63,7 +63,7 @@ class OPC(BaseActivity): level=NotificationLevel.ERROR, attachment_content=trace ) - self.logger.error(trace) + raise e @activity.defn(name='write_opc_data') async def write_opc_data(self, input_data: dict[str, Any]): diff --git a/values.yaml b/values.yaml index bd46925..00b531c 100644 --- a/values.yaml +++ b/values.yaml @@ -152,7 +152,7 @@ env: - name: MLFLOW_PASSWORD value: "aignosi" - - name: OPC_NAME + - name: OPC_ID value: "server-1" - name: OPC_URL value: "opc.tcp://sientia-opc-simulator.sientia.svc.cluster.local:4840" From fd9131bdd80e47854952df38f7a8584afc6c0256 Mon Sep 17 00:00:00 2001 From: vitor-aignosi Date: Wed, 11 Jun 2025 17:56:58 -0300 Subject: [PATCH 2/7] testing commit message --- values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/values.yaml b/values.yaml index 00b531c..ba03752 100644 --- a/values.yaml +++ b/values.yaml @@ -183,4 +183,4 @@ ssh: # kubectl create secret generic git-ssh-key-sientia-laborious-worker \ # --namespace sientia \ # --from-file=ssh-privatekey=git_key \ -# --type=kubernetes.io/ssh-auth \ No newline at end of file +# --type=kubernetes.io/ssh-auth From 72876e35987a55cf238c3dc908804e944aaeb0fc Mon Sep 17 00:00:00 2001 From: vitor-aignosi Date: Wed, 11 Jun 2025 17:59:38 -0300 Subject: [PATCH 3/7] [SIENTIAPDE-1100] Fix formatting in values.yaml by ensuring consistent comment style for SSH secret creation --- values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/values.yaml b/values.yaml index ba03752..00b531c 100644 --- a/values.yaml +++ b/values.yaml @@ -183,4 +183,4 @@ ssh: # kubectl create secret generic git-ssh-key-sientia-laborious-worker \ # --namespace sientia \ # --from-file=ssh-privatekey=git_key \ -# --type=kubernetes.io/ssh-auth +# --type=kubernetes.io/ssh-auth \ No newline at end of file From ba576636a067112b09ff81693fdf218656223f4b Mon Sep 17 00:00:00 2001 From: vitor-aignosi Date: Wed, 11 Jun 2025 18:00:38 -0300 Subject: [PATCH 4/7] SIENTIAPDE-1100 Fix formatting in values.yaml by adding a newline at the end of the SSH secret creation comment --- values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/values.yaml b/values.yaml index 00b531c..ba03752 100644 --- a/values.yaml +++ b/values.yaml @@ -183,4 +183,4 @@ ssh: # kubectl create secret generic git-ssh-key-sientia-laborious-worker \ # --namespace sientia \ # --from-file=ssh-privatekey=git_key \ -# --type=kubernetes.io/ssh-auth \ No newline at end of file +# --type=kubernetes.io/ssh-auth From e8afa2673e199e4e491565f37bbe24cacdb22516 Mon Sep 17 00:00:00 2001 From: vitor-aignosi Date: Thu, 12 Jun 2025 08:56:10 -0300 Subject: [PATCH 5/7] SIENTIAPDE-1100 Refactor error handling in Gates and OPC activities; replace raise statements with logging for better traceability --- laborious/activities/gates.py | 3 --- laborious/activities/opc.py | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/laborious/activities/gates.py b/laborious/activities/gates.py index 9d1b252..d744578 100644 --- a/laborious/activities/gates.py +++ b/laborious/activities/gates.py @@ -94,7 +94,6 @@ class Gates(BaseActivity): level=NotificationLevel.ERROR, attachment_content=trace ) - raise e for path_flag in path_priority: if path_flag in filter_output: @@ -158,7 +157,6 @@ class Gates(BaseActivity): level=NotificationLevel.ERROR, attachment_content=trace ) - raise e for path_flag in path_priority: if path_flag in filter_output: @@ -220,7 +218,6 @@ class Gates(BaseActivity): level=NotificationLevel.ERROR, attachment_content=trace ) - raise e for path_flag in path_priority: if path_flag in filter_output: diff --git a/laborious/activities/opc.py b/laborious/activities/opc.py index ee3b905..11cd77c 100644 --- a/laborious/activities/opc.py +++ b/laborious/activities/opc.py @@ -63,7 +63,7 @@ class OPC(BaseActivity): level=NotificationLevel.ERROR, attachment_content=trace ) - raise e + self.logger.error(trace) @activity.defn(name='write_opc_data') async def write_opc_data(self, input_data: dict[str, Any]): From 1057db1d73397eca4f2aa400ad69724be9b711da Mon Sep 17 00:00:00 2001 From: vitor-aignosi Date: Thu, 12 Jun 2025 09:06:31 -0300 Subject: [PATCH 6/7] SIENTIAPDE-1100 Improve error handling in OPC activities; raise exceptions instead of logging errors and add data type validation in OpcRepository --- laborious/activities/opc.py | 2 +- laborious/utils/repository/opc_repository.py | 9 +++++++ tests/laborious/activities/test_opc.py | 26 ++++++++++++-------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/laborious/activities/opc.py b/laborious/activities/opc.py index 11cd77c..ee3b905 100644 --- a/laborious/activities/opc.py +++ b/laborious/activities/opc.py @@ -63,7 +63,7 @@ class OPC(BaseActivity): level=NotificationLevel.ERROR, attachment_content=trace ) - self.logger.error(trace) + raise e @activity.defn(name='write_opc_data') async def write_opc_data(self, input_data: dict[str, Any]): diff --git a/laborious/utils/repository/opc_repository.py b/laborious/utils/repository/opc_repository.py index cafcc41..4f46b71 100644 --- a/laborious/utils/repository/opc_repository.py +++ b/laborious/utils/repository/opc_repository.py @@ -218,6 +218,15 @@ class OpcRepository(): self.error_count += 1 return + if data_type not in data_type_map: + self.notification_handler.build_and_send_notification( + notification_id=f"OPC_WRITE_DATA_TYPE_ERROR_{self.name}", + message=f"Unsupported data type: {data_type}", + block="opc_repository", + level=NotificationLevel.ERROR + ) + return + data = data_type_map[data_type]['converter'](value) self.logger.info(f'Writing {data} - {type(data)} to {node}') ua_data = DataValue( diff --git a/tests/laborious/activities/test_opc.py b/tests/laborious/activities/test_opc.py index d012778..3c50733 100644 --- a/tests/laborious/activities/test_opc.py +++ b/tests/laborious/activities/test_opc.py @@ -112,16 +112,22 @@ def test_write_data_success(opc, tag, data_type, data): def test_write_data_exception(opc): opc.opc_repository['server1'].write_data.side_effect = Exception( "Test error") - opc.write_data(server='server1', tag='tag1', data=50, - data_type='int', tag_type='prediction') - opc.notification_handler.build_and_send_notification.assert_called_once_with( - notification_id="WRITE_OPC_PREDICTION_ERROR", - message="Error writing data to OPC server: Test error", - block="write_opc_data", - level=NotificationLevel.ERROR, - attachment_content=ANY - ) - opc.logger.error.assert_called_once() + + try: + opc.write_data(server='server1', tag='tag1', data=50, + data_type='int', tag_type='prediction') + + except Exception: + opc.notification_handler.build_and_send_notification.assert_called_once_with( + notification_id="WRITE_OPC_PREDICTION_ERROR", + message="Error writing data to OPC server: Test error", + block="write_opc_data", + level=NotificationLevel.ERROR, + attachment_content=ANY + ) + + else: + assert False, "Expected an exception to be raised" @mark.asyncio From 7c4f3936e85e5e2d55013d7f0cf0daf81058955e Mon Sep 17 00:00:00 2001 From: vitor-aignosi Date: Thu, 12 Jun 2025 09:14:15 -0300 Subject: [PATCH 7/7] SIENTIAPDE-1100 Add test for handling invalid data type in write_data method --- .../utils/repository/test_opc_repository.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/laborious/utils/repository/test_opc_repository.py b/tests/laborious/utils/repository/test_opc_repository.py index ae9dd89..7369496 100644 --- a/tests/laborious/utils/repository/test_opc_repository.py +++ b/tests/laborious/utils/repository/test_opc_repository.py @@ -224,6 +224,24 @@ def test_write_data_get_node_failed(opc_repository): assert opc_repository.error_count == 1 +def test_write_data_invalid_data_type(opc_repository, mock_client): + opc_repository.validate_connection = MagicMock(return_value=True) + opc_repository.client = mock_client + mock_node = MagicMock() + mock_client.get_node.return_value = mock_node + + opc_repository.write_data("ns=2;s=TestNode", 42.0, "invalid_type") + opc_repository.validate_connection.assert_called_once() + mock_client.get_node.assert_called_once_with("ns=2;s=TestNode") + + opc_repository.notification_handler.build_and_send_notification.assert_called_once_with( + notification_id=f"OPC_WRITE_DATA_TYPE_ERROR_{opc_repository.name}", + message="Unsupported data type: invalid_type", + block="opc_repository", + level=NotificationLevel.ERROR + ) + + def test_write_data(opc_repository, mock_client): opc_repository.validate_connection = MagicMock(return_value=True) opc_repository.client = mock_client