Resolved bug 1719 - POL hangs waiting for webhook response 87/11287/6 release-v11.0-start v11.0.0 v11.0.0rc1 v11.0.0rc2
authorAtul Agarwal <Atul.Agarwal@Altran.com>
Sun, 24 Oct 2021 17:05:55 +0000 (17:05 +0000)
committerAtul Agarwal <Atul.Agarwal@Altran.com>
Tue, 26 Oct 2021 07:54:21 +0000 (07:54 +0000)
Change-Id: I41552d504d8a4599484ec24166a8ae7b2ef539dd
Signed-off-by: Atul Agarwal <Atul.Agarwal@Altran.com>
osm_policy_module/alarming/service.py
osm_policy_module/core/pol.yaml
osm_policy_module/tests/unit/alarming/test_alarming_service.py

index 13433ba..a938234 100644 (file)
@@ -218,6 +218,7 @@ class AlarmingService:
             database.db.close()
 
     async def handle_alarm(self, alarm_uuid: str, status: str, payload: dict):
+        alert_timeout = int(self.conf.get('alert', 'timeout'))
         database.db.connect()
         try:
             with database.db.atomic():
@@ -234,9 +235,9 @@ class AlarmingService:
                             status,
                         )
                         try:
-                            requests.post(url=action.url, json=json.dumps(payload))
+                            requests.post(url=action.url, json=json.dumps(payload), timeout=alert_timeout)
                         except RequestException as e:
-                            log.info("Error connecting to url %s", action.url)
+                            log.info("Error: RequestException while connecting to url %s", action.url)
                             log.debug("RequestException %s", e)
                         except ConnectionError:
                             log.exception("Error connecting to url %s", action.url)
index 4e07cf8..5117260 100644 (file)
@@ -35,4 +35,7 @@ message:
   group_id: pol-consumer
 
 sql:
-  database_uri: sqlite:///policy_module.db
\ No newline at end of file
+  database_uri: sqlite:///policy_module.db
+
+alert:
+  timeout: 10 # timeout in secs
index 67956eb..e897cd9 100644 (file)
@@ -44,23 +44,24 @@ class TestAlarmingService(TestCase):
     @mock.patch("requests.post")
     @mock.patch("osm_policy_module.core.database.db")
     def test_handle_alarm(self, database, requests_post, get_alarm):
+        alert_timeout = int(self.config.get('alert', 'timeout'))
         mock_alarm = self._build_mock_alarm("test_id")
         get_alarm.return_value = mock_alarm
 
         service = AlarmingService(self.config)
         self.loop.run_until_complete(service.handle_alarm("test_id", "alarm", {}))
-        requests_post.assert_called_once_with(json="{}", url="http://alarm-url/")
+        requests_post.assert_called_once_with(json="{}", url="http://alarm-url/", timeout=alert_timeout)
 
         requests_post.reset_mock()
         self.loop.run_until_complete(service.handle_alarm("test_id", "ok", {}))
-        requests_post.assert_called_once_with(json="{}", url="http://ok-url/")
+        requests_post.assert_called_once_with(json="{}", url="http://ok-url/", timeout=alert_timeout)
 
         requests_post.reset_mock()
         self.loop.run_until_complete(
             service.handle_alarm("test_id", "insufficient-data", {})
         )
         requests_post.assert_called_once_with(
-            json="{}", url="http://insufficient-data-url/"
+            json="{}", url="http://insufficient-data-url/", timeout=alert_timeout
         )
 
     @mock.patch.object(VnfAlarmRepository, "get")