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():
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)
@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")