From 10e97a4c9c59e906d04ca1894972da3dcaf027ae Mon Sep 17 00:00:00 2001 From: Atul Agarwal Date: Sun, 24 Oct 2021 17:05:55 +0000 Subject: [PATCH] Resolved bug 1719 - POL hangs waiting for webhook response Change-Id: I41552d504d8a4599484ec24166a8ae7b2ef539dd Signed-off-by: Atul Agarwal --- osm_policy_module/alarming/service.py | 5 +++-- osm_policy_module/core/pol.yaml | 5 ++++- .../tests/unit/alarming/test_alarming_service.py | 7 ++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/osm_policy_module/alarming/service.py b/osm_policy_module/alarming/service.py index 13433ba..a938234 100644 --- a/osm_policy_module/alarming/service.py +++ b/osm_policy_module/alarming/service.py @@ -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) diff --git a/osm_policy_module/core/pol.yaml b/osm_policy_module/core/pol.yaml index 4e07cf8..5117260 100644 --- a/osm_policy_module/core/pol.yaml +++ b/osm_policy_module/core/pol.yaml @@ -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 diff --git a/osm_policy_module/tests/unit/alarming/test_alarming_service.py b/osm_policy_module/tests/unit/alarming/test_alarming_service.py index 67956eb..e897cd9 100644 --- a/osm_policy_module/tests/unit/alarming/test_alarming_service.py +++ b/osm_policy_module/tests/unit/alarming/test_alarming_service.py @@ -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") -- 2.25.1