From: Atul Agarwal Date: Sun, 24 Oct 2021 17:05:55 +0000 (+0000) Subject: Resolved bug 1719 - POL hangs waiting for webhook response X-Git-Tag: v11.0.0rc1 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=1780919941680a1144d7a13f215e4c62946583b6;p=osm%2FPOL.git Resolved bug 1719 - POL hangs waiting for webhook response Change-Id: I41552d504d8a4599484ec24166a8ae7b2ef539dd Signed-off-by: Atul Agarwal --- 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")