From 22bf3dc0a562f2b21130736b26c1f7e31bf4024d Mon Sep 17 00:00:00 2001
From: kpoulakakis <kpoulakakis@ubitech.eu>
Date: Thu, 3 Oct 2024 17:02:37 +0300
Subject: [PATCH] Automation: make more dynamic the thresholds criteria.

---
 src/automation/service/AutomationServiceServicerImpl.py     | 4 +++-
 src/tests/hackfest3/tests/test_functional_create_service.py | 4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/automation/service/AutomationServiceServicerImpl.py b/src/automation/service/AutomationServiceServicerImpl.py
index 27af8db95..fa079b7b7 100644
--- a/src/automation/service/AutomationServiceServicerImpl.py
+++ b/src/automation/service/AutomationServiceServicerImpl.py
@@ -153,7 +153,9 @@ class AutomationServiceServicerImpl(AutomationServiceServicer):
             analyzer.input_kpi_ids.append(kpi_id_tx)
             analyzer.output_kpi_ids.append(kpi_id_lat)
 
-            _threshold_dict = {'min_latency_E2E': (0, service.service_constraints[0].sla_latency.e2e_latency_ms)}
+            thresholdStr = service.service_constraints[0].custom.constraint_type
+
+            _threshold_dict = {thresholdStr: (0, int(service.service_constraints[0].custom.constraint_value))}
             analyzer.parameters['thresholds'] = json.dumps(_threshold_dict)
             analyzer.parameters['window_size'] = "60s"
             analyzer.parameters['window_slider'] = "30s"
diff --git a/src/tests/hackfest3/tests/test_functional_create_service.py b/src/tests/hackfest3/tests/test_functional_create_service.py
index acded924d..a358c4c02 100644
--- a/src/tests/hackfest3/tests/test_functional_create_service.py
+++ b/src/tests/hackfest3/tests/test_functional_create_service.py
@@ -28,7 +28,7 @@ from service.client.ServiceClient import ServiceClient
 from .Objects import CONTEXT_ID, CONTEXTS, DEVICES, LINKS, TOPOLOGIES, SERVICES
 from common.proto.context_pb2 import ConfigActionEnum, Device, DeviceId,\
     DeviceOperationalStatusEnum
-from common.tools.object_factory.Constraint import json_constraint_sla_latency
+from common.tools.object_factory.Constraint import json_constraint_custom
 
 LOGGER = logging.getLogger(__name__)
 LOGGER.setLevel(logging.DEBUG)
@@ -63,5 +63,5 @@ def test_rules_entry(
         service_p4 = copy.deepcopy(service)
         service_client.CreateService(Service(**service_p4))
         service_p4['service_endpoint_ids'].extend(endpoints)
-        service_p4['service_constraints'].extend([json_constraint_sla_latency(3)])
+        service_p4['service_constraints'].extend([json_constraint_custom('min_latency_E2E','2')])
         service_client.UpdateService(Service(**service_p4))
-- 
GitLab